Re: [Qemu-devel] [PATCH v2 1/1] virtio-console: Prevent abort()s in case of host chardev close

2011-07-20 Thread Markus Armbruster
Amit Shah  writes:

> A host chardev could close just before the guest sends some data to be
> written.  This will cause an -EPIPE error.  This shouldn't be propagated
> to virtio-serial-bus.
>
> Ideally we should close the port once -EPIPE is received, but since the
> chardev interface doesn't return such meaningful values to its users,
> all we get is -1 for any kind of error.  Just return 0 for now and wait
> for chardevs to return better error messages to act better on the return
> messages.
>
> Signed-off-by: Amit Shah 

Besides qemu_chr_write() returning meaningful errors, it would be nice
to have less harsh error handing in do_flush_queued_data(), wouldn't it?

Short of that, we can either suppress real write errors, or turn a
perfectly normal condition into an error.  This patch does the latter,
because it's a much lesser evil.

Reviewed-by: Markus Armbruster 



Re: [Qemu-devel] [V4 Patch 3/4 - Updated]Qemu: Command "block_set" for dynamic block params change

2011-07-20 Thread Supriya Kannery

On 07/13/2011 06:37 PM, Supriya Kannery wrote:

Updated "block_set" command to accept multiple -drive parameters.
Also, added code for re-opening of device file with original flags,
incase opening file using changed hostcache setting fails.

--
New command "block_set" added for dynamically changing any of the block
device parameters. For now, dynamic setting of hostcache params using this
command is implemented. Other block device parameters, can be integrated
in similar lines.

Signed-off-by: Supriya Kannery 

---
block.c | 60 
block.h | 2 +
blockdev.c | 60 
blockdev.h | 1
hmp-commands.hx | 14 +
qemu-config.c | 13 
qemu-option.c | 25 +++
qemu-option.h | 2 +
qmp-commands.hx | 28 ++
9 files changed, 205 insertions(+)

Index: qemu/block.c
===
--- qemu.orig/block.c
+++ qemu/block.c
@@ -651,6 +651,40 @@ unlink_and_fail:
return ret;
}

+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags)
+{
+ BlockDriver *drv = bs->drv;
+ int ret = 0;
+
+ /* Quiesce IO for the given block device */
+ qemu_aio_flush();
+ if (bdrv_flush(bs)) {
+ qerror_report(QERR_DATA_SYNC_FAILED, bs->device_name);
+ return ret;
+ }
+ bdrv_close(bs);
+
+
+ ret = bdrv_open(bs, bs->filename, bdrv_flags, drv);
+ if (ret < 0) {
+ /* Reopen failed. Try to open with original flags */
+ error_report("Opening file with changed flags...");
+ qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+
+ ret = bdrv_open(bs, bs->filename, bs->open_flags, drv);
+ if (ret < 0) {
+ /*
+ * Reopen failed with orig and modified flags
+ */
+ error_report("Opening file with original flags...");
+ qerror_report(QERR_REOPEN_FILE_FAILED, bs->filename);
+ abort();
+ }
+ }
+
+ return ret;
+}
+
void bdrv_close(BlockDriverState *bs)
{
if (bs->drv) {
@@ -691,6 +725,32 @@ void bdrv_close_all(void)
}
}

+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache)
+{
+ int bdrv_flags = bs->open_flags;
+
+ /* set hostcache flags (without changing WCE/flush bits) */
+ if (enable_host_cache) {
+ bdrv_flags &= ~BDRV_O_NOCACHE;
+ } else {
+ bdrv_flags |= BDRV_O_NOCACHE;
+ }
+
+ /* If no change in flags, no need to reopen */
+ if (bdrv_flags == bs->open_flags) {
+ return 0;
+ }
+
+ if (bdrv_is_inserted(bs)) {
+ /* Reopen file with changed set of flags */
+ return bdrv_reopen(bs, bdrv_flags);
+ } else {
+ /* Save hostcache change for future use */
+ bs->open_flags = bdrv_flags;
+ return 0;
+ }
+}
+
/* make a BlockDriverState anonymous by removing from bdrv_state list.
Also, NULL terminate the device_name to prevent double remove */
void bdrv_make_anon(BlockDriverState *bs)
Index: qemu/block.h
===
--- qemu.orig/block.h
+++ qemu/block.h
@@ -71,6 +71,7 @@ void bdrv_delete(BlockDriverState *bs);
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int
flags);
int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *drv);
+int bdrv_reopen(BlockDriverState *bs, int bdrv_flags);
void bdrv_close(BlockDriverState *bs);
int bdrv_attach(BlockDriverState *bs, DeviceState *qdev);
void bdrv_detach(BlockDriverState *bs, DeviceState *qdev);
@@ -96,6 +97,7 @@ void bdrv_commit_all(void);
int bdrv_change_backing_file(BlockDriverState *bs,
const char *backing_file, const char *backing_fmt);
void bdrv_register(BlockDriver *bdrv);
+int bdrv_change_hostcache(BlockDriverState *bs, bool enable_host_cache);


typedef struct BdrvCheckResult {
Index: qemu/blockdev.c
===
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -793,3 +793,63 @@ int do_block_resize(Monitor *mon, const

return 0;
}
+
+
+/*
+ * Handle changes to block device settings, like hostcache,
+ * while guest is running.
+*/
+int do_block_set(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+ BlockDriverState *bs = NULL;
+ QemuOpts *opts;
+ int enable;
+ const char *device, *driver;
+ int ret;
+
+ /* Validate device */
+ device = qdict_get_str(qdict, "device");
+ bs = bdrv_find(device);
+ if (!bs) {
+ qerror_report(QERR_DEVICE_NOT_FOUND, device);
+ return -1;
+ }
+
+ opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict);
+ if (opts == NULL) {
+ return -1;
+ }
+
+ /* If input not in "param=value" format, display error */
+ driver = qemu_opt_get(opts, "driver");
+ if (driver != NULL) {
+ error_report("Invalid parameter %s", driver);
+ return -1;
+ }
+
+ /* Before validating parameters, remove "device" option */
+ ret = qemu_opt_delete(opts, "device");
+ if (ret == 1) {
+ error_report("Specify parameter to be changed");
+ error_report("Usage: block_set device [prop=value][,...]");
+ return 0;
+ }
+
+ /* Validate parameters with "-drive" parameter list */
+ re

Re: [Qemu-devel] External COW format for raw images

2011-07-20 Thread Robert Wang
On Tue, 2011-07-19 at 16:39 +0200, Frediano Ziglio wrote:
> 2011/7/19 Robert Wang :
> > As you known, raw image is very popular,but the raw image format does
> > NOT support Copy-On-Write,a raw image file can NOT be used as a copy
> > destination, then image streaming/Live Block Copy will NOT work.
> >
> > To fix this, we need to add a new block driver raw-cow to QEMU. If
> > finished, we can use qemu-img like this:
> > qemu-img create -f raw-cow -o backing_file=ubuntu.img,raw_file=my_vm.img
> > my_vm.raw-cow
> >
> > 1) ubuntu.img is the backing file, my_vm.img is a raw file,
> > my_vm.raw-cow stores a COW bitmap related to my_vm.img.
> >
> > 2) If the entire COW bitmap is set to dirty flag then we can get all
> > information from my_vm.img and can ignore ubuntu.img and my_vm.raw-cow
> > from now.
> >
> > To implement this, I think I can follow these steps:
> > 1) Add a new member to BlockDriverState struct:
> > char raw_file[1024];
> > This member will track raw_file parameter related to raw-cow file from
> > command line.
> >
> > 2)  * Create a new file block/raw-cow.c. It will be much more like the
> > mixture of block/cow.c and block/raw.c.
> >
> > So I will change some functions in cow.c and raw.c to none-static, then
> > raw-cow.c can re-use them. When read operation occurs, determine whether
> > dirty flag in raw-cow image is set. If true, read directly from the raw
> > file. After write operation, set related dirty flag in raw-cow image.
> > And other functions might also be modified.
> >
> >* Of course, format_name member of BlockDriver struct will be 
> > "raw-cow".
> > And in order to keep relationship with raw file( like my_vm.img) ,
> > raw_cow_header struct should be
> > struct raw_cow_header {
> > uint32_t magic;
> > uint32_t version;
> > char backing_file[1024];
> > char raw_file[1024];/* added*/
> > int32_t mtime;
> > uint64_t size;
> > uint32_t sectorsize;
> > };
> >* Struct raw_cow_create_options should be one member plus based on
> > cow_create_options:
> > {
> > .name = BLOCK_OPT_RAW_FILE,
> > .type = OPT_STRING,
> > .help = "Raw file name"
> > },
> >
> > 3) Add bdrv_get_raw_filename in img_info function of qemu-img.c. In
> > bdrv_get_raw_filename, if the format of the image file is "raw-cow",
> > print the related raw file.
> >
> > Do you think my approach is right?
> > Thank you.
> >
> 
> I don't understand if you mean just a way to track clusters/sectors
> changed or a new way to implement snapshotting, something that writing
> data just store original to cow like like:
> 
> 
> normal backfile
> 
> is allocated on image
>   write to image
> else
>   allocate on image
>   copy from backing to image
>   write to image (patch before previous write)
> 
> cow-raw (inverse backfile)
> 
> is allocated on image
>   write to backing
> else
>   allocate on image
>   copy from backing to image
>   write to backing
> 
> 
> that is
> 
> 
> is not allocated on image
>   allocate on image
>   copy from backing to image
> is normal backing
>   write to image
> else
>   write to backing
> 
> 
> Frediano
> 
Frediano, it mainly is to track clusters/sectors changes, not a new way
to implement snapshotting.




Re: [Qemu-devel] [V4 Patch 4/4 - Updated]Qemu: Add commandline -drive option 'hostcache'

2011-07-20 Thread Supriya Kannery

On 07/05/2011 04:35 PM, Supriya Kannery wrote:

Updated patch to use qemu_opt_get_bool() instead of qemu_opt_get()
to read 'hostcache'

---
qemu command option 'hostcache' added to -drive for block devices.
While starting a VM from qemu commandline, this option can be used
for setting host cache usage for block data access. It is not
allowed to specify both 'hostcache' and 'cache' options in the same
commandline. User has to specify only one among these.

Signed-off-by: Supriya Kannery 

---
blockdev.c | 13 +
qemu-config.c | 4 
qemu-options.hx | 2 +-
3 files changed, 18 insertions(+), 1 deletion(-)

Index: qemu/blockdev.c
===
--- qemu.orig/blockdev.c
+++ qemu/blockdev.c
@@ -238,6 +238,7 @@ DriveInfo *drive_init(QemuOpts *opts, in
DriveInfo *dinfo;
int snapshot = 0;
int ret;
+ int hostcache = 0;

translation = BIOS_ATA_TRANSLATION_AUTO;

@@ -324,7 +325,19 @@ DriveInfo *drive_init(QemuOpts *opts, in
}
}

+ if ((hostcache = qemu_opt_get_bool(opts, "hostcache", -1)) != -1) {
+ if (!hostcache) {
+ bdrv_flags |= BDRV_O_NOCACHE;
+ } else {
+ bdrv_flags &= ~BDRV_O_NOCACHE;
+ }
+ }
+
if ((buf = qemu_opt_get(opts, "cache")) != NULL) {
+ if (hostcache != -1) {
+ error_report("'hostcache' and 'cache' cannot co-exist");
+ return NULL;
+ }
if (!strcmp(buf, "off") || !strcmp(buf, "none")) {
bdrv_flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
} else if (!strcmp(buf, "writeback")) {
Index: qemu/qemu-options.hx
===
--- qemu.orig/qemu-options.hx
+++ qemu/qemu-options.hx
@@ -120,7 +120,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
" [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
" [,cache=writethrough|writeback|none|unsafe][,format=f]\n"
" [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
- " [,readonly=on|off]\n"
+ " [,readonly=on|off][,hostcache=on|off]\n"
" use 'file' as a drive image\n", QEMU_ARCH_ALL)
STEXI
@item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
Index: qemu/qemu-config.c
===
--- qemu.orig/qemu-config.c
+++ qemu/qemu-config.c
@@ -78,6 +78,10 @@ static QemuOptsList qemu_drive_opts = {
},{
.name = "readonly",
.type = QEMU_OPT_BOOL,
+ },{
+ .name = "hostcache",
+ .type = QEMU_OPT_BOOL,
+ .help = "set or reset hostcache (on/off)"
},
{ /* end of list */ }
},


Please review..



Re: [Qemu-devel] [V4 Patch 1/4 -Updated]Qemu: Enhance "info block" to display host cache setting

2011-07-20 Thread Supriya Kannery

On 07/05/2011 04:19 PM, Supriya Kannery wrote:


Updated patch to display hostcache = 1/0 instead of true/false
in monitor.

---
Enhance "info block" to display hostcache setting for each
block device.

Example:
(qemu) info block
ide0-hd0: type=hd removable=0 file=../rhel6-32.qcow2 ro=0 drv=qcow2
encrypted=0

Enhanced to display "hostcache" setting:
(qemu) info block
ide0-hd0: type=hd removable=0 hostcache=true file=../rhel6-32.qcow2
ro=0 drv=qcow2 encrypted=0

Signed-off-by: Supriya Kannery 

---
block.c | 21 +
qmp-commands.hx | 2 ++
2 files changed, 19 insertions(+), 4 deletions(-)

Index: qemu/block.c
===
--- qemu.orig/block.c
+++ qemu/block.c
@@ -1694,6 +1694,14 @@ static void bdrv_print_dict(QObject *obj
monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
}

+ if (qdict_haskey(bs_dict, "open_flags")) {
+ int open_flags = qdict_get_int(bs_dict, "open_flags");
+ if (open_flags & BDRV_O_NOCACHE)
+ monitor_printf(mon, " hostcache=0");
+ else
+ monitor_printf(mon, " hostcache=1");
+ }
+
if (qdict_haskey(bs_dict, "inserted")) {
QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));

@@ -1730,13 +1738,18 @@ void bdrv_info(Monitor *mon, QObject **r
QObject *bs_obj;

bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
- "'removable': %i, 'locked': %i }",
- bs->device_name, bs->removable,
- bs->locked);
+ "'removable': %i, 'locked': %i, "
+ "'hostcache': %s }",
+ bs->device_name, bs->removable,
+ bs->locked,
+ (bs->open_flags & BDRV_O_NOCACHE) ?
+ "false" : "true");
+
+ QDict *bs_dict = qobject_to_qdict(bs_obj);
+ qdict_put(bs_dict, "open_flags", qint_from_int(bs->open_flags));

if (bs->drv) {
QObject *obj;
- QDict *bs_dict = qobject_to_qdict(bs_obj);

obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
"'encrypted': %i }",
Index: qemu/qmp-commands.hx
===
--- qemu.orig/qmp-commands.hx
+++ qemu/qmp-commands.hx
@@ -1070,6 +1070,7 @@ Each json-object contain the following:
- Possible values: "unknown"
- "removable": true if the device is removable, false otherwise (json-bool)
- "locked": true if the device is locked, false otherwise (json-bool)
+- "hostcache": true if hostcache enabled, false otherwise (json-bool)
- "inserted": only present if the device is inserted, it is a json-object
containing the following:
- "file": device file name (json-string)
@@ -1091,6 +1092,7 @@ Example:
{
"device":"ide0-hd0",
"locked":false,
+ "hostcache":false,
"removable":false,
"inserted":{
"ro":false,


Pls review..



[Qemu-devel] [RFC PATCH 2/5] use more stack

2011-07-20 Thread Frediano Ziglio

Signed-off-by: Frediano Ziglio 
---
 block/qcow.c |  133 +++---
 1 files changed, 62 insertions(+), 71 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index d19ef04..cd1f9e3 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -487,20 +487,12 @@ static int qcow_read(BlockDriverState *bs, int64_t 
sector_num,
 #endif
 
 typedef struct QCowAIOCB {
-BlockDriverAIOCB common;
+BlockDriverState *bs;
 int64_t sector_num;
 QEMUIOVector *qiov;
 uint8_t *buf;
 void *orig_buf;
 int nb_sectors;
-int n;
-uint64_t cluster_offset;
-uint8_t *cluster_data;
-struct iovec hd_iov;
-bool is_write;
-QEMUBH *bh;
-QEMUIOVector hd_qiov;
-BlockDriverAIOCB *hd_aiocb;
 } QCowAIOCB;
 
 static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
@@ -508,11 +500,9 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 int is_write, QCowAIOCB *acb)
 {
 memset(acb, 0, sizeof(*acb));
-acb->common.bs = bs;
-acb->hd_aiocb = NULL;
+acb->bs = bs;
 acb->sector_num = sector_num;
 acb->qiov = qiov;
-acb->is_write = is_write;
 
 if (qiov->niov > 1) {
 acb->buf = acb->orig_buf = qemu_blockalign(bs, qiov->size);
@@ -522,37 +512,36 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 acb->buf = (uint8_t *)qiov->iov->iov_base;
 }
 acb->nb_sectors = nb_sectors;
-acb->n = 0;
-acb->cluster_offset = 0;
 return acb;
 }
 
 static int qcow_aio_read_cb(QCowAIOCB *acb)
 {
-BlockDriverState *bs = acb->common.bs;
+BlockDriverState *bs = acb->bs;
 BDRVQcowState *s = bs->opaque;
 int index_in_cluster;
-int ret;
-
-acb->hd_aiocb = NULL;
+int ret, n = 0;
+uint64_t cluster_offset = 0;
+struct iovec hd_iov;
+QEMUIOVector hd_qiov;
 
  redo:
 /* post process the read buffer */
-if (!acb->cluster_offset) {
+if (!cluster_offset) {
 /* nothing to do */
-} else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) {
+} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
 /* nothing to do */
 } else {
 if (s->crypt_method) {
 encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
-acb->n, 0,
+n, 0,
 &s->aes_decrypt_key);
 }
 }
 
-acb->nb_sectors -= acb->n;
-acb->sector_num += acb->n;
-acb->buf += acb->n * 512;
+acb->nb_sectors -= n;
+acb->sector_num += n;
+acb->buf += n * 512;
 
 if (acb->nb_sectors == 0) {
 /* request completed */
@@ -560,57 +549,57 @@ static int qcow_aio_read_cb(QCowAIOCB *acb)
 }
 
 /* prepare next AIO request */
-acb->cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
+cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
  0, 0, 0, 0);
 index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
-acb->n = s->cluster_sectors - index_in_cluster;
-if (acb->n > acb->nb_sectors)
-acb->n = acb->nb_sectors;
+n = s->cluster_sectors - index_in_cluster;
+if (n > acb->nb_sectors)
+n = acb->nb_sectors;
 
-if (!acb->cluster_offset) {
+if (!cluster_offset) {
 if (bs->backing_hd) {
 /* read from the base image */
-acb->hd_iov.iov_base = (void *)acb->buf;
-acb->hd_iov.iov_len = acb->n * 512;
-qemu_iovec_init_external(&acb->hd_qiov, &acb->hd_iov, 1);
+hd_iov.iov_base = (void *)acb->buf;
+hd_iov.iov_len = n * 512;
+qemu_iovec_init_external(&hd_qiov, &hd_iov, 1);
 qemu_co_mutex_unlock(&s->lock);
 ret = bdrv_co_readv(bs->backing_hd, acb->sector_num,
-acb->n, &acb->hd_qiov);
+n, &hd_qiov);
 qemu_co_mutex_lock(&s->lock);
 if (ret < 0) {
 return -EIO;
 }
 } else {
 /* Note: in this case, no need to wait */
-memset(acb->buf, 0, 512 * acb->n);
+memset(acb->buf, 0, 512 * n);
 goto redo;
 }
-} else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) {
+} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
 /* add AIO support for compressed blocks ? */
-if (decompress_cluster(bs, acb->cluster_offset) < 0) {
+if (decompress_cluster(bs, cluster_offset) < 0) {
 return -EIO;
 }
 memcpy(acb->buf,
-   s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
+   s->cluster_cache + index_in_cluster * 512, 512 * n);
 goto redo;
 } else {
-if ((acb->cluster_offset & 511) != 0) {
+if ((cluster_offset & 511) != 0) {
 return -EIO;
 }
-acb->hd_iov.iov_base = (void *)acb->buf;
-acb->hd_iov.iov_len = acb->n * 512;
-qe

[Qemu-devel] [RFC PATCH 5/5] qemu_aio_get used to clear all allocated buffer

2011-07-20 Thread Frediano Ziglio

Signed-off-by: Frediano Ziglio 
---
 block/qcow.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 007fb57..8fd1ee5 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -499,7 +499,6 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
 int is_write, QCowAIOCB *acb)
 {
-memset(acb, 0, sizeof(*acb));
 acb->bs = bs;
 acb->sector_num = sector_num;
 acb->qiov = qiov;
@@ -509,6 +508,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 if (is_write)
 qemu_iovec_to_buffer(qiov, acb->buf);
 } else {
+acb->orig_buf = NULL;
 acb->buf = (uint8_t *)qiov->iov->iov_base;
 }
 acb->nb_sectors = nb_sectors;
-- 
1.7.1




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Markus Armbruster
"Daniel P. Berrange"  writes:

> On Tue, Jul 19, 2011 at 04:14:27PM +0100, Stefan Hajnoczi wrote:
>> On Tue, Jul 19, 2011 at 3:30 PM, Jes Sorensen  
>> wrote:
>> > On 07/19/11 16:24, Eric Blake wrote:
>> >> [adding the libvir-list]
>> >> On 07/19/2011 08:09 AM, Jes Sorensen wrote:
>> >>> Urgh, libvirt parsing image files is really unfortunate, it really
>> >>> doesn't give me warm fuzzy feelings :( libvirt really should not know
>> >>> about internals of image formats.
>> >>
>> >> But even if you add new features to qemu to avoid needing this in the
>> >> future, it doesn't change the past - libvirt will always have to know
>> >> how to parse image files understood by older qemu, and so as long as
>> >> libvirt already knows how to do that parsing, we might as well take
>> >> advantage of it.
>> >
>> > What has been done here in the past is plain wrong. Continuing to do it
>> > isn't the right thing to do here.
>> >
>> >> Besides, I feel that having a well-documented file format, so that
>> >> independent applications can both parse the same file with the same
>> >> semantics by obeying the file format specification, is a good design goal.
>> >
>> > We all know that documentation is rarely uptodate, new features may not
>> > get added and libvirt will never be able to keep up. The driver for a
>> > file format belongs in QEMU and nowhere else.
>> 
>> It should be a goal to avoid dependencies in multiple layers of the
>> stack because it becomes are to add new features - they require
>> coordinated changes in multiple layers.  Having both QEMU and libvirt
>> know the internals of image files is such a multi-dependency.  If I
>> want to add a new format or change an existing format I have to touch
>> both layers.
>> 
>> For fd-passing perhaps we have an opportunity to use a callback
>> mechanism (QEMU request: filename -> libvirt response: fd) and do all
>> the image format parsing in QEMU.
>
> The reason why libvirt does the parsing of file headers to determine
> backing files is to maintain the trust boundary. Everything run from
> the exec() of QEMU onwards is considered untrusted code. So having
> QEMU parsing the file headers & passing back open() requests to libvirt
> is breaking the trust boundary.

Exactly.

The block drivers form a tree.  Each driver opens its children.  For
convenience, some of them have information on how to open their children
encoded in their image (e.g. COW backing images).  Others receive it as
configuration, encoded in their "filename" string (e.g. blkdebug).

Thus, we have direct control only over the root block driver.  We can
pass it fds easily.

We control the non-root block drivers only indirectly, through the block
drivers along the path from the root.  We don't have a way to pass them
fds.

If we had a way to construct the tree bottom-up, we could directly
control all the block drivers.

Requires knowing the number of children, and extracting child
configuration from images where applicable.

[...]



[Qemu-devel] [RFC PATCH 3/5] more stack work

2011-07-20 Thread Frediano Ziglio

Signed-off-by: Frediano Ziglio 
---
 block/qcow.c |   53 ++---
 1 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index cd1f9e3..8ccd7d7 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -520,35 +520,18 @@ static int qcow_aio_read_cb(QCowAIOCB *acb)
 BlockDriverState *bs = acb->bs;
 BDRVQcowState *s = bs->opaque;
 int index_in_cluster;
-int ret, n = 0;
-uint64_t cluster_offset = 0;
+int ret, n;
+uint64_t cluster_offset;
 struct iovec hd_iov;
 QEMUIOVector hd_qiov;
 
  redo:
-/* post process the read buffer */
-if (!cluster_offset) {
-/* nothing to do */
-} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
-/* nothing to do */
-} else {
-if (s->crypt_method) {
-encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
-n, 0,
-&s->aes_decrypt_key);
-}
-}
-
-acb->nb_sectors -= n;
-acb->sector_num += n;
-acb->buf += n * 512;
-
 if (acb->nb_sectors == 0) {
 /* request completed */
 return 0;
 }
 
-/* prepare next AIO request */
+/* prepare next request */
 cluster_offset = get_cluster_offset(bs, acb->sector_num << 9,
  0, 0, 0, 0);
 index_in_cluster = acb->sector_num & (s->cluster_sectors - 1);
@@ -572,7 +555,6 @@ static int qcow_aio_read_cb(QCowAIOCB *acb)
 } else {
 /* Note: in this case, no need to wait */
 memset(acb->buf, 0, 512 * n);
-goto redo;
 }
 } else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
 /* add AIO support for compressed blocks ? */
@@ -581,7 +563,6 @@ static int qcow_aio_read_cb(QCowAIOCB *acb)
 }
 memcpy(acb->buf,
s->cluster_cache + index_in_cluster * 512, 512 * n);
-goto redo;
 } else {
 if ((cluster_offset & 511) != 0) {
 return -EIO;
@@ -599,6 +580,23 @@ static int qcow_aio_read_cb(QCowAIOCB *acb)
 }
 }
 
+/* post process the read buffer */
+if (!cluster_offset) {
+/* nothing to do */
+} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
+/* nothing to do */
+} else {
+if (s->crypt_method) {
+encrypt_sectors(s, acb->sector_num, acb->buf, acb->buf,
+n, 0,
+&s->aes_decrypt_key);
+}
+}
+
+acb->nb_sectors -= n;
+acb->sector_num += n;
+acb->buf += n * 512;
+
 goto redo;
 }
 
@@ -630,16 +628,12 @@ static int qcow_aio_write_cb(QCowAIOCB *acb)
 int index_in_cluster;
 uint64_t cluster_offset;
 const uint8_t *src_buf;
-int ret, n = 0;
+int ret, n;
 uint8_t *cluster_data = NULL;
 struct iovec hd_iov;
 QEMUIOVector hd_qiov;
 
   redo:
-acb->nb_sectors -= n;
-acb->sector_num += n;
-acb->buf += n * 512;
-
 if (acb->nb_sectors == 0) {
 /* request completed */
 return 0;
@@ -681,6 +675,11 @@ static int qcow_aio_write_cb(QCowAIOCB *acb)
 if (ret < 0) {
 return ret;
 }
+
+acb->nb_sectors -= n;
+acb->sector_num += n;
+acb->buf += n * 512;
+
 goto redo;
 }
 
-- 
1.7.1




[Qemu-devel] [RFC PATCH 0/5] Coroutines cleanup

2011-07-20 Thread Frediano Ziglio
These patches mostly cleanup some AIO code using coroutines.
These patches apply to Kevin's repository, branch coroutine-block.
Mostly they use stack instead of allocated AIO structure.

Frediano Ziglio (5):
  allocate AIO on stack
  use more stack
  more stack work
  avoid dandling pointers
  qemu_aio_get used to clear all allocated buffer

 block/qcow.c  |  210 +
 block/qcow2.c |   38 +++---
 2 files changed, 102 insertions(+), 146 deletions(-)




Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Avi Kivity

On 07/19/2011 11:51 PM, Anthony Liguori wrote:

On 07/19/2011 11:10 AM, Avi Kivity wrote:

On 07/19/2011 07:05 PM, Avi Kivity wrote:

On 07/19/2011 05:50 PM, Anthony Liguori wrote:




There's bits I don't like about the interface


Which bits are these?


Nothing I haven't already commented on. I think there's too much in
the generic level. I don't think coalesced I/O belongs here. It's a
concept that doesn't fit. I think a side-band API would be nicer.


Well, it's impossible to do it in a side band. When a range that has
coalesced mmio is exposed is completely orthogonal to programming the
BAR register - it can happen, for example, due to another BAR being
removed or the bridge window being programmed. You can also have a
coalesced mmio region being partially clipped.


Of course, it's not really impossible, just clumsy.


There are exactly two devices that use coalesced I/O: VGA and e1000.

VGA does coalesced I/O over the legacy VGA region (0xa ... 
0xc).  This region is very special in the PC and is directly 
routed by the I440FX to the appropriate first PCI graphics card.


The VGA device knows exactly where this region is mapped.


The VGA device doesn't know *if* it is mapped.  It can be obstructed by 
the chipset and by SMM.  Other chipsets we emulate may support multiple 
VGA cards.




The e1000 does coalesced I/O for it's memory registers.  But it's 
dubious how much this actually matters anymore.  The original claim 
was a 10% boost with iperf.


The e1000 is not performance competitive with virtio-net though so it 
certainly is reasonable to assume that noone would notice if we 
removed coalesced I/O from the e1000.


The e1000 NIC is the best we have for guests that don't support virtio.  
It's not reasonable to reduce its performance.




The point is, it's so incredibly special cased that having it as part 
of such a general purpose API seems wrong.  Of the hundreds of 
devices, we only have one device that we know for sure really needs it 
and it could easily be done independent of the memory API for that 
device.




We either support coalesced mmio well, or not at all.  Even if the API 
has only one user, that doesn't excuse doing it badly.


--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Avi Kivity

On 07/20/2011 09:10 AM, Sasha Levin wrote:

On Tue, 2011-07-19 at 21:53 -0500, Anthony Liguori wrote:
>  QEMU does use it and it's quite important.  Coalesced MMIO is really
>  about write caching MMIO exits.  It only works with devices that have
>  registers where writing has no side effects.  Moreover, it only really
>  works well when there are lots and lots of writes to these registers
>  simultaneously.
>
>  Couple that with the fact that the buffer is a fixed size and it's
>  really not flexible enough to be useful for a wide variety of devices.
>
>  But for VGA planar mode writes, it works wonders.  It would be terrible
>  to totally lose it.  That said, I'm not at all convinced it's useful for
>  much other than VGA planar mode.

Why was the coalesced approach taken in the first place? When I tried
using it for VGA in /tools/kvm it just seemed to me like a builtin
virtio-memory transport.

Thats why I think planar VGA would be fine if we deprecate coalesced
mmio in favor of either socket ioeventfds or a new virtio-memory device.



virtio is guest visible.  coealesced mmio is transparent to the guest.  
socket ioeventds also do coalescing, but they are more expensive to 
synchronize - you have to poll the socket whenever a synchronization 
event happens.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] [RFC PATCH 1/5] allocate AIO on stack

2011-07-20 Thread Frediano Ziglio

Signed-off-by: Frediano Ziglio 
---
 block/qcow.c  |   52 
 block/qcow2.c |   38 +++---
 2 files changed, 27 insertions(+), 63 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 6447c2a..d19ef04 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -503,28 +503,12 @@ typedef struct QCowAIOCB {
 BlockDriverAIOCB *hd_aiocb;
 } QCowAIOCB;
 
-static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
-{
-QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
-if (acb->hd_aiocb)
-bdrv_aio_cancel(acb->hd_aiocb);
-qemu_aio_release(acb);
-}
-
-static AIOPool qcow_aio_pool = {
-.aiocb_size = sizeof(QCowAIOCB),
-.cancel = qcow_aio_cancel,
-};
-
 static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
-int is_write)
+int is_write, QCowAIOCB *acb)
 {
-QCowAIOCB *acb;
-
-acb = qemu_aio_get(&qcow_aio_pool, bs, NULL, NULL);
-if (!acb)
-return NULL;
+memset(acb, 0, sizeof(*acb));
+acb->common.bs = bs;
 acb->hd_aiocb = NULL;
 acb->sector_num = sector_num;
 acb->qiov = qiov;
@@ -543,9 +527,8 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
 return acb;
 }
 
-static int qcow_aio_read_cb(void *opaque)
+static int qcow_aio_read_cb(QCowAIOCB *acb)
 {
-QCowAIOCB *acb = opaque;
 BlockDriverState *bs = acb->common.bs;
 BDRVQcowState *s = bs->opaque;
 int index_in_cluster;
@@ -634,29 +617,27 @@ static int qcow_co_readv(BlockDriverState *bs, int64_t 
sector_num,
  int nb_sectors, QEMUIOVector *qiov)
 {
 BDRVQcowState *s = bs->opaque;
-QCowAIOCB *acb;
+QCowAIOCB acb;
 int ret;
 
-acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 0);
+qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 0, &acb);
 
 qemu_co_mutex_lock(&s->lock);
 do {
-ret = qcow_aio_read_cb(acb);
+ret = qcow_aio_read_cb(&acb);
 } while (ret > 0);
 qemu_co_mutex_unlock(&s->lock);
 
-if (acb->qiov->niov > 1) {
-qemu_iovec_from_buffer(acb->qiov, acb->orig_buf, acb->qiov->size);
-qemu_vfree(acb->orig_buf);
+if (acb.qiov->niov > 1) {
+qemu_iovec_from_buffer(acb.qiov, acb.orig_buf, acb.qiov->size);
+qemu_vfree(acb.orig_buf);
 }
-qemu_aio_release(acb);
 
 return ret;
 }
 
-static int qcow_aio_write_cb(void *opaque)
+static int qcow_aio_write_cb(QCowAIOCB *acb)
 {
-QCowAIOCB *acb = opaque;
 BlockDriverState *bs = acb->common.bs;
 BDRVQcowState *s = bs->opaque;
 int index_in_cluster;
@@ -714,23 +695,22 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t 
sector_num,
   int nb_sectors, QEMUIOVector *qiov)
 {
 BDRVQcowState *s = bs->opaque;
-QCowAIOCB *acb;
+QCowAIOCB acb;
 int ret;
 
 s->cluster_cache_offset = -1; /* disable compressed cache */
 
-acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 1);
+qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 1, &acb);
 
 qemu_co_mutex_lock(&s->lock);
 do {
-ret = qcow_aio_write_cb(acb);
+ret = qcow_aio_write_cb(&acb);
 } while (ret > 0);
 qemu_co_mutex_unlock(&s->lock);
 
-if (acb->qiov->niov > 1) {
-qemu_vfree(acb->orig_buf);
+if (acb.qiov->niov > 1) {
+qemu_vfree(acb.orig_buf);
 }
-qemu_aio_release(acb);
 
 return ret;
 }
diff --git a/block/qcow2.c b/block/qcow2.c
index f07d550..edc068e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -388,17 +388,6 @@ typedef struct QCowAIOCB {
 QLIST_ENTRY(QCowAIOCB) next_depend;
 } QCowAIOCB;
 
-static void qcow2_aio_cancel(BlockDriverAIOCB *blockacb)
-{
-QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
-qemu_aio_release(acb);
-}
-
-static AIOPool qcow2_aio_pool = {
-.aiocb_size = sizeof(QCowAIOCB),
-.cancel = qcow2_aio_cancel,
-};
-
 /*
  * Returns 0 when the request is completed successfully, 1 when there is still
  * a part left to do and -errno in error cases.
@@ -528,13 +517,10 @@ static int qcow2_aio_read_cb(QCowAIOCB *acb)
 static QCowAIOCB *qcow2_aio_setup(BlockDriverState *bs, int64_t sector_num,
   QEMUIOVector *qiov, int nb_sectors,
   BlockDriverCompletionFunc *cb,
-  void *opaque, int is_write)
+  void *opaque, int is_write, QCowAIOCB *acb)
 {
-QCowAIOCB *acb;
-
-acb = qemu_aio_get(&qcow2_aio_pool, bs, cb, opaque);
-if (!acb)
-return NULL;
+memset(acb, 0, sizeof(*acb));
+acb->common.bs = bs;
 acb->sector_num = sector_num;
 acb->qiov = qiov;
 acb->is_write = is_write;
@@ -554,19 +540,18 @@ static int qcow2_co_readv(BlockDriverState *bs, int64_t 
sector_num,
   int nb_sectors, QEMUIOVe

Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Avi Kivity

On 07/19/2011 08:30 PM, Jan Kiszka wrote:

>  Rebasing is already not so fun for me with 78 patches and counting.
>  Let's drop yours and focus of getting mine in shape, since it's a superset.

The patches series are widely orthogonal except for both killing the
obsolete start/stop logging logic.

But I don't mind rebasing over yours - if something is finally merged at
all.


If you post patches I'll incorporate them in my patchset.  They're 
available in qemu-kvm.git branch memory-region.


--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] [PATCH 0/2] netdev fixes

2011-07-20 Thread Mark McLoughlin
On Wed, 2011-07-20 at 11:19 +0300, Michael S. Tsirkin wrote:
> On Tue, Jul 19, 2011 at 07:52:39PM +0200, Jan Kiszka wrote:
> > On 2011-07-19 14:10, Michael S. Tsirkin wrote:
> > > On Thu, Jun 16, 2011 at 06:45:35PM +0200, Markus Armbruster wrote:
> > >> Markus Armbruster (2):
> > >>   Fix automatically assigned network names for netdev
> > >>   Fix netdev name lookup in -device, device_add, netdev_del
> > >>
> > >>  net.c |   19 +++
> > >>  1 files changed, 15 insertions(+), 4 deletions(-)
> > > 
> > > Thanks, applied.
> > > I think going forward we should bring more order into ways we assign
> > > IDs.
> > 
> > Did you take over net subsystem integration?
> 
> No, Markus just asked me to look at his patches, and I took interest.
> I applied the patches to my tree, from there pull requests go to Anthony
> who is a maintainer for net/ so I think that's all right.
> 
> Also, it's just my tree, pull request won't go out before
> Thursday at the earliest, so if someone objects
> (or wants to merge them himself), there's plenty of time.
> 
> > Or who should initially receive related patches now?
> > 
> > Jan
> 
> I think running ./scripts/get_maintainer.pl is generally
> a good idea. For net you'd get:
> 
> [qemu]$ ./scripts/get_maintainer.pl -f net.c net/
> Anthony Liguori  (maintainer:Network device 
> layer,commit_signer:4/16=25%)
> Mark McLoughlin  (maintainer:Network device layer)

This is clearly out of date - feel free to remove it

Cheers,
Mark.





[Qemu-devel] [RFC PATCH 4/5] avoid dandling pointers

2011-07-20 Thread Frediano Ziglio

Signed-off-by: Frediano Ziglio 
---
 block/qcow.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 8ccd7d7..007fb57 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -616,6 +616,7 @@ static int qcow_co_readv(BlockDriverState *bs, int64_t 
sector_num,
 if (acb.qiov->niov > 1) {
 qemu_iovec_from_buffer(acb.qiov, acb.orig_buf, acb.qiov->size);
 qemu_vfree(acb.orig_buf);
+acb.orig_buf = NULL;
 }
 
 return ret;
@@ -700,6 +701,7 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t 
sector_num,
 
 if (acb.qiov->niov > 1) {
 qemu_vfree(acb.orig_buf);
+acb.orig_buf = NULL;
 }
 
 return ret;
-- 
1.7.1




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Jes Sorensen
On 07/19/11 18:46, Daniel P. Berrange wrote:
> On Tue, Jul 19, 2011 at 04:14:27PM +0100, Stefan Hajnoczi wrote:
>> For fd-passing perhaps we have an opportunity to use a callback
>> mechanism (QEMU request: filename -> libvirt response: fd) and do all
>> the image format parsing in QEMU.
> 
> The reason why libvirt does the parsing of file headers to determine
> backing files is to maintain the trust boundary. Everything run from
> the exec() of QEMU onwards is considered untrusted code. So having
> QEMU parsing the file headers & passing back open() requests to libvirt
> is breaking the trust boundary.

Pardon, but I fail to see the issue here. If QEMU passes a filename back
to libvirt, libvirt still gets to make the decision whether or not it is
legitimate for QEMU to get that file descriptor or not. It doesn't
change anything wrt who actually opens the file, hence the 'trust' is
unchanged.

> NB, i'm not happy about libvirt having to have knowledge of file format
> headers, but we needed something more efficient & reliable than invoking
> qemu-img info & parsing the output. Ideally QEMU (or something else)
> would provide a library libblockformat.so with stable APIs for at least
> reading metadata about image formats. If it had APIs for image creation,
> etc too that would be a bonus, but we're more or less ok spawning qemu-img
> for those cases currently.

Even having a library for libvirt to link against is suboptimal here.
Two processes shouldn't be fighting over the internals of metadata, the
ownership of the metadata belongs solely with QEMU. In addition you have
the constant issue of dependencies there, hence if QEMU is updated and
it provides a newer block format library, it may prevent libvirt from
running forcing an update of libvirt as well. That is not acceptable for
development.

Cheers,
Jes



Re: [Qemu-devel] [PATCH 0/2] netdev fixes

2011-07-20 Thread Michael S. Tsirkin
On Tue, Jul 19, 2011 at 07:52:39PM +0200, Jan Kiszka wrote:
> On 2011-07-19 14:10, Michael S. Tsirkin wrote:
> > On Thu, Jun 16, 2011 at 06:45:35PM +0200, Markus Armbruster wrote:
> >> Markus Armbruster (2):
> >>   Fix automatically assigned network names for netdev
> >>   Fix netdev name lookup in -device, device_add, netdev_del
> >>
> >>  net.c |   19 +++
> >>  1 files changed, 15 insertions(+), 4 deletions(-)
> > 
> > Thanks, applied.
> > I think going forward we should bring more order into ways we assign
> > IDs.
> 
> Did you take over net subsystem integration?

No, Markus just asked me to look at his patches, and I took interest.
I applied the patches to my tree, from there pull requests go to Anthony
who is a maintainer for net/ so I think that's all right.

Also, it's just my tree, pull request won't go out before
Thursday at the earliest, so if someone objects
(or wants to merge them himself), there's plenty of time.

> Or who should initially receive related patches now?
> 
> Jan

I think running ./scripts/get_maintainer.pl is generally
a good idea. For net you'd get:

[qemu]$ ./scripts/get_maintainer.pl -f net.c net/
Anthony Liguori  (maintainer:Network device 
layer,commit_signer:4/16=25%)
Mark McLoughlin  (maintainer:Network device layer)
Aurelien Jarno  (commit_signer:6/16=38%)
"Michael S. Tsirkin"  (commit_signer:5/16=31%)
Jason Wang  (commit_signer:4/16=25%)
Peter Maydell  (commit_signer:4/16=25%)


> -- 
> Siemens AG, Corporate Technology, CT T DE IT 1
> Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [RFC 1/4] A separate thread for the VM migration

2011-07-20 Thread Avi Kivity

On 07/20/2011 06:56 AM, Umesh Deshpande wrote:



Please give each patch a separate, meaningful title and post them in 
their own thread.


See

   git format-patches --cover-letter
   git send-email

--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] [PATCH v2 1/1] virtio-console: Prevent abort()s in case of host chardev close

2011-07-20 Thread Amit Shah
On (Wed) 20 Jul 2011 [09:10:41], Markus Armbruster wrote:
> Amit Shah  writes:
> 
> > A host chardev could close just before the guest sends some data to be
> > written.  This will cause an -EPIPE error.  This shouldn't be propagated
> > to virtio-serial-bus.
> >
> > Ideally we should close the port once -EPIPE is received, but since the
> > chardev interface doesn't return such meaningful values to its users,
> > all we get is -1 for any kind of error.  Just return 0 for now and wait
> > for chardevs to return better error messages to act better on the return
> > messages.
> >
> > Signed-off-by: Amit Shah 
> 
> Besides qemu_chr_write() returning meaningful errors, it would be nice
> to have less harsh error handing in do_flush_queued_data(), wouldn't it?

I wanted to keep the interfaces cleanly separated: virtio-console.c
deals with errors from chardevs.  virtio-serial-bus is only a
transport between the host and guest; and shouldn't have to deal with
chardev errors.  It can at most throttle the guest if the host can't
consume any more data (which is what it now does on errors).

> Short of that, we can either suppress real write errors, or turn a
> perfectly normal condition into an error.  This patch does the latter,
> because it's a much lesser evil.
> 
> Reviewed-by: Markus Armbruster 

Thanks; Anthony merged this yesterday.

Amit



[Qemu-devel] [PATCH 4/7] virtio-balloon: Separate status handling into separate function

2011-07-20 Thread Amit Shah
Separate out the code to retrieve balloon info from the code that sets
balloon values.

This will be used to separate the two callbacks from balloon.c and help
cope with 'balloon 0' on the monitor.  Currently, 'balloon 0' causes a
segfault in monitor_resume().

Signed-off-by: Amit Shah 
---
 hw/virtio-balloon.c |   51 +++
 1 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 70a8710..2f371f2 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -199,36 +199,47 @@ static uint32_t virtio_balloon_get_features(VirtIODevice 
*vdev, uint32_t f)
 return f;
 }
 
+static void virtio_balloon_stat(void *opaque, MonitorCompletion cb,
+void *cb_data)
+{
+VirtIOBalloon *dev = opaque;
+
+/* For now, only allow one request at a time.  This restriction can be
+ * removed later by queueing callback and data pairs.
+ */
+if (dev->stats_callback != NULL) {
+return;
+}
+dev->stats_callback = cb;
+dev->stats_opaque_callback_data = cb_data;
+
+if (ENABLE_GUEST_STATS
+&& (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) {
+virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
+virtio_notify(&dev->vdev, dev->svq);
+return;
+}
+
+/* Stats are not supported.  Clear out any stale values that might
+ * have been set by a more featureful guest kernel.
+ */
+reset_stats(dev);
+complete_stats_request(dev);
+}
+
 static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
  MonitorCompletion cb, void *cb_data)
 {
 VirtIOBalloon *dev = opaque;
 
-if (target > ram_size)
+if (target > ram_size) {
 target = ram_size;
-
+}
 if (target) {
 dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
 virtio_notify_config(&dev->vdev);
 } else {
-/* For now, only allow one request at a time.  This restriction can be
- * removed later by queueing callback and data pairs.
- */
-if (dev->stats_callback != NULL) {
-return;
-}
-dev->stats_callback = cb;
-dev->stats_opaque_callback_data = cb_data; 
-if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << 
VIRTIO_BALLOON_F_STATS_VQ))) {
-virtqueue_push(dev->svq, &dev->stats_vq_elem, 
dev->stats_vq_offset);
-virtio_notify(&dev->vdev, dev->svq);
-} else {
-/* Stats are not supported.  Clear out any stale values that might
- * have been set by a more featureful guest kernel.
- */
-reset_stats(dev);
-complete_stats_request(dev);
-}
+virtio_balloon_stat(opaque, cb, cb_data);
 }
 }
 
-- 
1.7.6




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Jes Sorensen
On 07/19/11 18:14, Anthony Liguori wrote:
>>> As nice as that sentiment is, it will never fly, because it would be a
>>> regression in current behavior.  The whole reason that the virt_use_nfs
>>> SELinux bool exists is that some people are willing to make the partial
>>> security tradeoff.  Besides, the use of sVirt via SELinux is more than
>>> just open() protection - while the current virt_use_nfs bool makes NFS
>>> less secure than otherwise possible, it still gives some nice guarantees
>>> to the rest of the qemu process such as passthrough accesses to local
>>> pci devices.
>>
>> Well leaving things at status quo is not making it worse, it just leaves
>> an evil in place.
> 
> NFS and SELinux is a fundamental problem with SELinux and NFS.  We can
> piss and moan as much as we want about it but it's reality.  SELinux
> fundamentally requires extended attributes.  By the time NFS adds
> extended attribute support, we'll all be flying around in hover cars.
> 
> As terrible as NFS is, people use it all of the time.
> 
> It would be nice if libvirt had the ability to make better use of DAC to
> support isolation.  The fact that MAC is the only way you can do
> isolation between guests is pretty unfortunate.  If I could assign
> specific UIDs to a guest and use that to enforce isolation, it would go
> a long ways to solving this problem.

Right, we're stuck with the two horros of NFS and selinux, so we need
something that gets around the problem. In a sane world we would simply
say 'no NFS, no selinux', but as you say that will never happen.

My suggestion of a callback mechanism where libvirt registers the
callback with QEMU for open() calls, allowing libvirt to perform the
open and return the open file descriptor would get around this problem.

Jes



Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Jes Sorensen
On 07/19/11 18:47, Daniel P. Berrange wrote:
> On Tue, Jul 19, 2011 at 04:30:19PM +0200, Jes Sorensen wrote:
>> On 07/19/11 16:24, Eric Blake wrote:
>>> Besides, I feel that having a well-documented file format, so that
>>> independent applications can both parse the same file with the same
>>> semantics by obeying the file format specification, is a good design goal.
>>
>> We all know that documentation is rarely uptodate, new features may not
>> get added and libvirt will never be able to keep up. The driver for a
>> file format belongs in QEMU and nowhere else.
> 
> This would be possible if QEMU to provide a libblockformat.so library
> which allowed apps to extract metadata from file formats using a stable
> API.

There is no reason for libvirt or any external process to mess about
with the internals of image files. You have the same problem if the
image file is encrypted.

Jes




[Qemu-devel] [PATCH 1/7] balloon: Make functions, local vars static

2011-07-20 Thread Amit Shah
balloon.h had function declarations for a couple of functions that are
local to balloon.c.  Make them static.

Drop the 'qemu_' prefix for balloon.c-local variables, and make them
static.

Signed-off-by: Amit Shah 
---
 balloon.c |   22 +++---
 balloon.h |4 
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/balloon.c b/balloon.c
index 248c1b5..f9bcf07 100644
--- a/balloon.c
+++ b/balloon.c
@@ -31,30 +31,30 @@
 #include "trace.h"
 
 
-static QEMUBalloonEvent *qemu_balloon_event;
-void *qemu_balloon_event_opaque;
+static QEMUBalloonEvent *balloon_event_fn;
+static void *balloon_opaque;
 
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
 {
-qemu_balloon_event = func;
-qemu_balloon_event_opaque = opaque;
+balloon_event_fn = func;
+balloon_opaque = opaque;
 }
 
-int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
+static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
 {
-if (qemu_balloon_event) {
-trace_balloon_event(qemu_balloon_event_opaque, target);
-qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque);
+if (balloon_event_fn) {
+trace_balloon_event(balloon_opaque, target);
+balloon_event_fn(balloon_opaque, target, cb, opaque);
 return 1;
 } else {
 return 0;
 }
 }
 
-int qemu_balloon_status(MonitorCompletion cb, void *opaque)
+static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (qemu_balloon_event) {
-qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);
+if (balloon_event_fn) {
+balloon_event_fn(balloon_opaque, 0, cb, opaque);
 return 1;
 } else {
 return 0;
diff --git a/balloon.h b/balloon.h
index d478e28..06a8a46 100644
--- a/balloon.h
+++ b/balloon.h
@@ -21,10 +21,6 @@ typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t 
target,
 
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque);
 
-int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque);
-
-int qemu_balloon_status(MonitorCompletion cb, void *opaque);
-
 void monitor_print_balloon(Monitor *mon, const QObject *data);
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque);
 int do_balloon(Monitor *mon, const QDict *params,
-- 
1.7.6




[Qemu-devel] [PATCH 0/7] balloon: cleanups, fix segfault

2011-07-20 Thread Amit Shah
'balloon 0' in the monitor causes a segfault.  This happens because
the function that handles change in balloon values is also tasked with
handling stats retrieval from the guest, and it does the retrieval
when the balloon target is '0'.

Silly API, replace it.  Also do a few cleanups along the way.

Amit Shah (7):
  balloon: Make functions, local vars static
  balloon: Add braces around if statements
  balloon: Simplify code flow
  virtio-balloon: Separate status handling into separate function
  balloon: Separate out stat and balloon handling
  balloon: Fix header comment; add Copyright
  virtio-balloon: Fix header comment; add Copyright

 balloon.c   |   47 +--
 balloon.h   |   12 --
 hw/virtio-balloon.c |   60 +-
 3 files changed, 65 insertions(+), 54 deletions(-)

-- 
1.7.6




[Qemu-devel] [PATCH 5/7] balloon: Separate out stat and balloon handling

2011-07-20 Thread Amit Shah
Passing on '0' as ballooning target to indicate retrieval of stats is
bad API.  It also makes 'balloon 0' in the monitor cause a segfault.
Have two different functions handle the different functionality instead.

Reported-by: Mike Cao 
Signed-off-by: Amit Shah 
---
 balloon.c   |   17 ++---
 balloon.h   |8 +---
 hw/virtio-balloon.c |7 ++-
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/balloon.c b/balloon.c
index d40be39..8be3812 100644
--- a/balloon.c
+++ b/balloon.c
@@ -32,30 +32,33 @@
 
 
 static QEMUBalloonEvent *balloon_event_fn;
+static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
-void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
+void qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
+  QEMUBalloonStatus *stat_func, void *opaque)
 {
-balloon_event_fn = func;
+balloon_event_fn = event_func;
+balloon_stat_fn = stat_func;
 balloon_opaque = opaque;
 }
 
-static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
+static int qemu_balloon(ram_addr_t target)
 {
 if (!balloon_event_fn) {
 return 0;
 }
 trace_balloon_event(balloon_opaque, target);
-balloon_event_fn(balloon_opaque, target, cb, opaque);
+balloon_event_fn(balloon_opaque, target);
 return 1;
 }
 
 static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (!balloon_event_fn) {
+if (!balloon_stat_fn) {
 return 0;
 }
-balloon_event_fn(balloon_opaque, 0, cb, opaque);
+balloon_stat_fn(balloon_opaque, cb, opaque);
 return 1;
 }
 
@@ -135,7 +138,7 @@ int do_balloon(Monitor *mon, const QDict *params,
 return -1;
 }
 
-ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque);
+ret = qemu_balloon(qdict_get_int(params, "value"));
 if (ret == 0) {
 qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
 return -1;
diff --git a/balloon.h b/balloon.h
index 06a8a46..a6c31d5 100644
--- a/balloon.h
+++ b/balloon.h
@@ -16,10 +16,12 @@
 
 #include "monitor.h"
 
-typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target,
-MonitorCompletion cb, void *cb_data);
+typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target);
+typedef void (QEMUBalloonStatus)(void *opaque, MonitorCompletion cb,
+ void *cb_data);
 
-void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque);
+void qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
+  QEMUBalloonStatus *stat_func, void *opaque);
 
 void monitor_print_balloon(Monitor *mon, const QObject *data);
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque);
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 2f371f2..40b43b0 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -227,8 +227,7 @@ static void virtio_balloon_stat(void *opaque, 
MonitorCompletion cb,
 complete_stats_request(dev);
 }
 
-static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
- MonitorCompletion cb, void *cb_data)
+static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
 {
 VirtIOBalloon *dev = opaque;
 
@@ -238,8 +237,6 @@ static void virtio_balloon_to_target(void *opaque, 
ram_addr_t target,
 if (target) {
 dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
 virtio_notify_config(&dev->vdev);
-} else {
-virtio_balloon_stat(opaque, cb, cb_data);
 }
 }
 
@@ -284,7 +281,7 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev)
 s->svq = virtio_add_queue(&s->vdev, 128, virtio_balloon_receive_stats);
 
 reset_stats(s);
-qemu_add_balloon_handler(virtio_balloon_to_target, s);
+qemu_add_balloon_handler(virtio_balloon_to_target, virtio_balloon_stat, s);
 
 register_savevm(dev, "virtio-balloon", -1, 1,
 virtio_balloon_save, virtio_balloon_load, s);
-- 
1.7.6




Re: [Qemu-devel] External COW format for raw images

2011-07-20 Thread Stefan Hajnoczi
2011/7/19 Anthony Liguori :
> On 07/19/2011 04:25 AM, Robert Wang wrote:
>> As you known, raw image is very popular,but the raw image format does
>> NOT support Copy-On-Write,a raw image file can NOT be used as a copy
>> destination, then image streaming/Live Block Copy will NOT work.
>>
>> To fix this, we need to add a new block driver raw-cow to QEMU. If
>> finished, we can use qemu-img like this:
>> qemu-img create -f raw-cow -o backing_file=ubuntu.img,raw_file=my_vm.img
>> my_vm.raw-cow
>>
>> 1) ubuntu.img is the backing file, my_vm.img is a raw file,
>> my_vm.raw-cow stores a COW bitmap related to my_vm.img.
>>
>> 2) If the entire COW bitmap is set to dirty flag then we can get all
>> information from my_vm.img and can ignore ubuntu.img and my_vm.raw-cow
>> from now.
>>
>> To implement this, I think I can follow these steps:
>> 1) Add a new member to BlockDriverState struct:
>> char raw_file[1024];
>> This member will track raw_file parameter related to raw-cow file from
>> command line.
>>
>> 2)    * Create a new file block/raw-cow.c. It will be much more like the
>> mixture of block/cow.c and block/raw.c.
>>
>> So I will change some functions in cow.c and raw.c to none-static, then
>> raw-cow.c can re-use them. When read operation occurs, determine whether
>> dirty flag in raw-cow image is set. If true, read directly from the raw
>> file. After write operation, set related dirty flag in raw-cow image.
>> And other functions might also be modified.
>>
>>       * Of course, format_name member of BlockDriver struct will be 
>> "raw-cow".
>> And in order to keep relationship with raw file( like my_vm.img) ,
>> raw_cow_header struct should be
>> struct raw_cow_header {
>> uint32_t magic;
>> uint32_t version;
>> char backing_file[1024];
>> char raw_file[1024];/* added*/
>> int32_t mtime;
>> uint64_t size;
>> uint32_t sectorsize;
>> };
>
> I'd suggest that doing an image format is the wrong approach here.  Why
> not just have a image format where you can pass it the location of a
> bitmap?  That let's you compose arbitrarily complex backing file chains
> and avoids the introduce of a new bitmap.
>
> The bitmap format is also useful for implementing things like dirty
> tracking.

Are you describing something like -drive
file=bitmap:raw.img:backing.img:dirty.bmap?

Stefan



Re: [Qemu-devel] [PATCH] Add missing documentation for qemu-img -p

2011-07-20 Thread Kevin Wolf
Am 19.07.2011 15:01, schrieb jes.soren...@redhat.com:
> From: Jes Sorensen 
> 
> Signed-off-by: Jes Sorensen 

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PATCH 2/7] balloon: Add braces around if statements

2011-07-20 Thread Amit Shah
Signed-off-by: Amit Shah 
---
 balloon.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/balloon.c b/balloon.c
index f9bcf07..86f629e 100644
--- a/balloon.c
+++ b/balloon.c
@@ -65,9 +65,10 @@ static void print_balloon_stat(const char *key, QObject 
*obj, void *opaque)
 {
 Monitor *mon = opaque;
 
-if (strcmp(key, "actual"))
+if (strcmp(key, "actual")) {
 monitor_printf(mon, ",%s=%" PRId64, key,
qint_get_int(qobject_to_qint(obj)));
+}
 }
 
 void monitor_print_balloon(Monitor *mon, const QObject *data)
@@ -75,9 +76,9 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)
 QDict *qdict;
 
 qdict = qobject_to_qdict(data);
-if (!qdict_haskey(qdict, "actual"))
+if (!qdict_haskey(qdict, "actual")) {
 return;
-
+}
 monitor_printf(mon, "balloon: actual=%" PRId64,
qdict_get_int(qdict, "actual") >> 20);
 qdict_iter(qdict, print_balloon_stat, mon);
-- 
1.7.6




Re: [Qemu-devel] [PATCH] Remove debugging messages.

2011-07-20 Thread Richard W.M. Jones
On Tue, Jul 19, 2011 at 04:56:24PM -0500, Anthony Liguori wrote:
> Can't libguestfs just ignore the messages?

It does, but they get printed to stderr which confuses users and has
caused several bug reports in the past.  We'll probably have to
redirect them somewhere.

> >$ qemu -nographic -device \?
> >KVM not supported for this target
> >No accelerator found!
> 
> Hrm, what's your HEAD because mine doesn't exhibit this behavior.

Right.  This seems to be a problem specific to Fedora's package.  I
also can't reproduce it with upstream.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/



[Qemu-devel] [PATCH v7 01/11] spice: add worker wrapper functions.

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Add wrapper functions for all spice worker calls.

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl-render.c|4 +-
 hw/qxl.c   |   32 +-
 ui/spice-display.c |   95 ---
 ui/spice-display.h |   22 
 4 files changed, 129 insertions(+), 24 deletions(-)

diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index 1316066..bef5f14 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -124,8 +124,8 @@ void qxl_render_update(PCIQXLDevice *qxl)
 update.bottom = qxl->guest_primary.surface.height;
 
 memset(dirty, 0, sizeof(dirty));
-qxl->ssd.worker->update_area(qxl->ssd.worker, 0, &update,
- dirty, ARRAY_SIZE(dirty), 1);
+qemu_spice_update_area(&qxl->ssd, 0, &update,
+   dirty, ARRAY_SIZE(dirty), 1);
 
 for (i = 0; i < ARRAY_SIZE(dirty); i++) {
 if (qemu_spice_rect_is_empty(dirty+i)) {
diff --git a/hw/qxl.c b/hw/qxl.c
index 919ec91..545074d 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -690,8 +690,8 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)
 dprint(d, 1, "%s: start%s\n", __FUNCTION__,
loadvm ? " (loadvm)" : "");
 
-d->ssd.worker->reset_cursor(d->ssd.worker);
-d->ssd.worker->reset_image_cache(d->ssd.worker);
+qemu_spice_reset_cursor(&d->ssd);
+qemu_spice_reset_image_cache(&d->ssd);
 qxl_reset_surfaces(d);
 qxl_reset_memslots(d);
 
@@ -796,7 +796,7 @@ static void qxl_add_memslot(PCIQXLDevice *d, uint32_t 
slot_id, uint64_t delta)
__FUNCTION__, memslot.slot_id,
memslot.virt_start, memslot.virt_end);
 
-d->ssd.worker->add_memslot(d->ssd.worker, &memslot);
+qemu_spice_add_memslot(&d->ssd, &memslot);
 d->guest_slots[slot_id].ptr = (void*)memslot.virt_start;
 d->guest_slots[slot_id].size = memslot.virt_end - memslot.virt_start;
 d->guest_slots[slot_id].delta = delta;
@@ -806,14 +806,14 @@ static void qxl_add_memslot(PCIQXLDevice *d, uint32_t 
slot_id, uint64_t delta)
 static void qxl_del_memslot(PCIQXLDevice *d, uint32_t slot_id)
 {
 dprint(d, 1, "%s: slot %d\n", __FUNCTION__, slot_id);
-d->ssd.worker->del_memslot(d->ssd.worker, MEMSLOT_GROUP_HOST, slot_id);
+qemu_spice_del_memslot(&d->ssd, MEMSLOT_GROUP_HOST, slot_id);
 d->guest_slots[slot_id].active = 0;
 }
 
 static void qxl_reset_memslots(PCIQXLDevice *d)
 {
 dprint(d, 1, "%s:\n", __FUNCTION__);
-d->ssd.worker->reset_memslots(d->ssd.worker);
+qemu_spice_reset_memslots(&d->ssd);
 memset(&d->guest_slots, 0, sizeof(d->guest_slots));
 }
 
@@ -821,7 +821,7 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
 {
 dprint(d, 1, "%s:\n", __FUNCTION__);
 d->mode = QXL_MODE_UNDEFINED;
-d->ssd.worker->destroy_surfaces(d->ssd.worker);
+qemu_spice_destroy_surfaces(&d->ssd);
 memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
 }
 
@@ -875,7 +875,7 @@ static void qxl_create_guest_primary(PCIQXLDevice *qxl, int 
loadvm)
 
 qxl->mode = QXL_MODE_NATIVE;
 qxl->cmdflags = 0;
-qxl->ssd.worker->create_primary_surface(qxl->ssd.worker, 0, &surface);
+qemu_spice_create_primary_surface(&qxl->ssd, 0, &surface);
 
 /* for local rendering */
 qxl_render_resize(qxl);
@@ -890,7 +890,7 @@ static void qxl_destroy_primary(PCIQXLDevice *d)
 dprint(d, 1, "%s\n", __FUNCTION__);
 
 d->mode = QXL_MODE_UNDEFINED;
-d->ssd.worker->destroy_primary_surface(d->ssd.worker, 0);
+qemu_spice_destroy_primary_surface(&d->ssd, 0);
 }
 
 static void qxl_set_mode(PCIQXLDevice *d, int modenr, int loadvm)
@@ -962,15 +962,15 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 case QXL_IO_UPDATE_AREA:
 {
 QXLRect update = d->ram->update_area;
-d->ssd.worker->update_area(d->ssd.worker, d->ram->update_surface,
-   &update, NULL, 0, 0);
+qemu_spice_update_area(&d->ssd, d->ram->update_surface,
+   &update, NULL, 0, 0);
 break;
 }
 case QXL_IO_NOTIFY_CMD:
-d->ssd.worker->wakeup(d->ssd.worker);
+qemu_spice_wakeup(&d->ssd);
 break;
 case QXL_IO_NOTIFY_CURSOR:
-d->ssd.worker->wakeup(d->ssd.worker);
+qemu_spice_wakeup(&d->ssd);
 break;
 case QXL_IO_UPDATE_IRQ:
 qxl_set_irq(d);
@@ -984,7 +984,7 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 break;
 }
 d->oom_running = 1;
-d->ssd.worker->oom(d->ssd.worker);
+qemu_spice_oom(&d->ssd);
 d->oom_running = 0;
 break;
 case QXL_IO_SET_MODE:
@@ -1022,10 +1022,10 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 qxl_destroy_primary(d);
 break;
 case QXL_IO_DESTROY_SURFACE_WAIT:
-d->ssd.worker->destroy_surface_wait(d->ssd.worker, val);
+qemu_spice_destroy_surface_wait(&d->ssd, val);
 

[Qemu-devel] [PATCH] xen: fix xen-mapcache build on non-Xen capable targets

2011-07-20 Thread Avi Kivity
Signed-off-by: Avi Kivity 
---
 xen-mapcache.h |   32 
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/xen-mapcache.h b/xen-mapcache.h
index 606b8af..da874ca 100644
--- a/xen-mapcache.h
+++ b/xen-mapcache.h
@@ -9,6 +9,10 @@
 #ifndef XEN_MAPCACHE_H
 #define XEN_MAPCACHE_H
 
+#include 
+
+#ifdef CONFIG_XEN
+
 void xen_map_cache_init(void);
 uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
uint8_t lock);
@@ -16,4 +20,32 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr);
 void xen_invalidate_map_cache_entry(uint8_t *buffer);
 void xen_invalidate_map_cache(void);
 
+#else
+
+static inline void xen_map_cache_init(void)
+{
+}
+
+static inline uint8_t *xen_map_cache(target_phys_addr_t phys_addr,
+ target_phys_addr_t size,
+ uint8_t lock)
+{
+abort();
+}
+
+static inline ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
+{
+abort();
+}
+
+static inline void xen_invalidate_map_cache_entry(uint8_t *buffer)
+{
+}
+
+static inline void xen_invalidate_map_cache(void)
+{
+}
+
+#endif
+
 #endif /* !XEN_MAPCACHE_H */
-- 
1.7.5.3




[Qemu-devel] [PATCH 3/7] balloon: Simplify code flow

2011-07-20 Thread Amit Shah
Replace:
  if (foo) {
...
  } else {
return 0;
  }

by

  if (!foo) {
return 0;
  }
  ...

Signed-off-by: Amit Shah 
---
 balloon.c |   16 +++-
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/balloon.c b/balloon.c
index 86f629e..d40be39 100644
--- a/balloon.c
+++ b/balloon.c
@@ -42,23 +42,21 @@ void qemu_add_balloon_handler(QEMUBalloonEvent *func, void 
*opaque)
 
 static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
 {
-if (balloon_event_fn) {
-trace_balloon_event(balloon_opaque, target);
-balloon_event_fn(balloon_opaque, target, cb, opaque);
-return 1;
-} else {
+if (!balloon_event_fn) {
 return 0;
 }
+trace_balloon_event(balloon_opaque, target);
+balloon_event_fn(balloon_opaque, target, cb, opaque);
+return 1;
 }
 
 static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (balloon_event_fn) {
-balloon_event_fn(balloon_opaque, 0, cb, opaque);
-return 1;
-} else {
+if (!balloon_event_fn) {
 return 0;
 }
+balloon_event_fn(balloon_opaque, 0, cb, opaque);
+return 1;
 }
 
 static void print_balloon_stat(const char *key, QObject *obj, void *opaque)
-- 
1.7.6




[Qemu-devel] [PATCH v7 06/11] qxl: error handling fixes and cleanups.

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Add qxl_guest_bug() function which is supposed to be called in case
sanity checks of guest requests fail.  It raises an error IRQ and
logs a message in case guest debugging is enabled.

Make PANIC_ON() abort instead of exit.  That macro should be used
for qemu bugs only, any guest-triggerable stuff should use the new
qxl_guest_bug() function instead.

Convert a few easy cases from PANIC_ON() to qxl_guest_bug() to
show intended usage.

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl.c |   34 ++
 hw/qxl.h |3 ++-
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 7d8b312..68ce409 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -125,6 +125,16 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
 
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg)
+{
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+qxl_send_events(qxl, QXL_INTERRUPT_ERROR);
+#endif
+if (qxl->guestdebug) {
+fprintf(stderr, "qxl-%d: guest bug: %s\n", qxl->id, msg);
+}
+}
+
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
struct QXLRect *area, struct QXLRect *dirty_rects,
@@ -1097,22 +1107,38 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 qxl_hard_reset(d, 0);
 break;
 case QXL_IO_MEMSLOT_ADD:
-PANIC_ON(val >= NUM_MEMSLOTS);
-PANIC_ON(d->guest_slots[val].active);
+if (val >= NUM_MEMSLOTS) {
+qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: val out of range");
+break;
+}
+if (d->guest_slots[val].active) {
+qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: memory slot already active");
+break;
+}
 d->guest_slots[val].slot = d->ram->mem_slot;
 qxl_add_memslot(d, val, 0);
 break;
 case QXL_IO_MEMSLOT_DEL:
+if (val >= NUM_MEMSLOTS) {
+qxl_guest_bug(d, "QXL_IO_MEMSLOT_DEL: val out of range");
+break;
+}
 qxl_del_memslot(d, val);
 break;
 case QXL_IO_CREATE_PRIMARY:
-PANIC_ON(val != 0);
+if (val != 0) {
+qxl_guest_bug(d, "QXL_IO_CREATE_PRIMARY: val != 0");
+break;
+}
 dprint(d, 1, "QXL_IO_CREATE_PRIMARY\n");
 d->guest_primary.surface = d->ram->create_surface;
 qxl_create_guest_primary(d, 0);
 break;
 case QXL_IO_DESTROY_PRIMARY:
-PANIC_ON(val != 0);
+if (val != 0) {
+qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY: val != 0");
+break;
+}
 dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (%s)\n", 
qxl_mode_to_string(d->mode));
 qxl_destroy_primary(d);
 break;
diff --git a/hw/qxl.h b/hw/qxl.h
index 5d0e85e..5db9aae 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -86,7 +86,7 @@ typedef struct PCIQXLDevice {
 
 #define PANIC_ON(x) if ((x)) { \
 printf("%s: PANIC %s failed\n", __FUNCTION__, #x); \
-exit(-1);  \
+abort();   \
 }
 
 #define dprint(_qxl, _level, _fmt, ...) \
@@ -99,6 +99,7 @@ typedef struct PCIQXLDevice {
 
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg);
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
struct QXLRect *area, struct QXLRect *dirty_rects,
-- 
1.7.6




[Qemu-devel] [PATCH v7 02/11] spice: add qemu_spice_display_init_common

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Factor out SimpleSpiceDisplay initialization into
qemu_spice_display_init_common() and call it from
both qxl.c (for vga mode) and spice-display.c

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl.c   |7 +--
 ui/spice-display.c |   17 +++--
 ui/spice-display.h |1 +
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 545074d..2d46814 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1321,12 +1321,7 @@ static int qxl_init_primary(PCIDevice *dev)
 
 vga->ds = graphic_console_init(qxl_hw_update, qxl_hw_invalidate,
qxl_hw_screen_dump, qxl_hw_text_update, 
qxl);
-qxl->ssd.ds = vga->ds;
-qemu_mutex_init(&qxl->ssd.lock);
-qxl->ssd.mouse_x = -1;
-qxl->ssd.mouse_y = -1;
-qxl->ssd.bufsize = (16 * 1024 * 1024);
-qxl->ssd.buf = qemu_malloc(qxl->ssd.bufsize);
+qemu_spice_display_init_common(&qxl->ssd, vga->ds);
 
 qxl0 = qxl;
 register_displaychangelistener(vga->ds, &display_listener);
diff --git a/ui/spice-display.c b/ui/spice-display.c
index 1e6a38f..93e25bf 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -286,6 +286,16 @@ void qemu_spice_vm_change_state_handler(void *opaque, int 
running, int reason)
 ssd->running = running;
 }
 
+void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds)
+{
+ssd->ds = ds;
+qemu_mutex_init(&ssd->lock);
+ssd->mouse_x = -1;
+ssd->mouse_y = -1;
+ssd->bufsize = (16 * 1024 * 1024);
+ssd->buf = qemu_malloc(ssd->bufsize);
+}
+
 /* display listener callbacks */
 
 void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
@@ -499,12 +509,7 @@ static DisplayChangeListener display_listener = {
 void qemu_spice_display_init(DisplayState *ds)
 {
 assert(sdpy.ds == NULL);
-sdpy.ds = ds;
-qemu_mutex_init(&sdpy.lock);
-sdpy.mouse_x = -1;
-sdpy.mouse_y = -1;
-sdpy.bufsize = (16 * 1024 * 1024);
-sdpy.buf = qemu_malloc(sdpy.bufsize);
+qemu_spice_display_init_common(&sdpy, ds);
 register_displaychangelistener(ds, &display_listener);
 
 sdpy.qxl.base.sif = &dpy_interface.base;
diff --git a/ui/spice-display.h b/ui/spice-display.h
index 5b06b11..eb7a573 100644
--- a/ui/spice-display.h
+++ b/ui/spice-display.h
@@ -75,6 +75,7 @@ void qemu_spice_create_host_memslot(SimpleSpiceDisplay *ssd);
 void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd);
 void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd);
 void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason);
+void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds);
 
 void qemu_spice_display_update(SimpleSpiceDisplay *ssd,
int x, int y, int w, int h);
-- 
1.7.6




[Qemu-devel] [PATCH v7 04/11] qxl: fix surface tracking & locking

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Surface tracking needs proper locking since it is used from vcpu and spice
worker threads, add it.  Also reset the surface counter when zapping all
surfaces.

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl.c |   13 -
 hw/qxl.h |2 ++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 29094a9..e832d00 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -137,7 +137,12 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t 
surface_id,
 
 void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id)
 {
+qemu_mutex_lock(&qxl->track_lock);
+PANIC_ON(id >= NUM_SURFACES);
 qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
+qxl->guest_surfaces.cmds[id] = 0;
+qxl->guest_surfaces.count--;
+qemu_mutex_unlock(&qxl->track_lock);
 }
 
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
@@ -158,7 +163,11 @@ void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
 
 void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl)
 {
+qemu_mutex_lock(&qxl->track_lock);
 qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
+memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
+qxl->guest_surfaces.count = 0;
+qemu_mutex_unlock(&qxl->track_lock);
 }
 
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
@@ -317,6 +326,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct 
QXLCommandExt *ext)
 QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
 uint32_t id = le32_to_cpu(cmd->surface_id);
 PANIC_ON(id >= NUM_SURFACES);
+qemu_mutex_lock(&qxl->track_lock);
 if (cmd->type == QXL_SURFACE_CMD_CREATE) {
 qxl->guest_surfaces.cmds[id] = ext->cmd.data;
 qxl->guest_surfaces.count++;
@@ -327,6 +337,7 @@ static void qxl_track_command(PCIQXLDevice *qxl, struct 
QXLCommandExt *ext)
 qxl->guest_surfaces.cmds[id] = 0;
 qxl->guest_surfaces.count--;
 }
+qemu_mutex_unlock(&qxl->track_lock);
 break;
 }
 case QXL_CMD_CURSOR:
@@ -869,7 +880,6 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
 dprint(d, 1, "%s:\n", __FUNCTION__);
 d->mode = QXL_MODE_UNDEFINED;
 qxl_spice_destroy_surfaces(d);
-memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
 }
 
 /* called from spice server thread context only */
@@ -1289,6 +1299,7 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 qxl->generation = 1;
 qxl->num_memslots = NUM_MEMSLOTS;
 qxl->num_surfaces = NUM_SURFACES;
+qemu_mutex_init(&qxl->track_lock);
 
 switch (qxl->revision) {
 case 1: /* spice 0.4 -- qxl-1 */
diff --git a/hw/qxl.h b/hw/qxl.h
index e62b9d0..5d0e85e 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -55,6 +55,8 @@ typedef struct PCIQXLDevice {
 } guest_surfaces;
 QXLPHYSICALguest_cursor;
 
+QemuMutex  track_lock;
+
 /* thread signaling */
 pthread_t  main;
 intpipe[2];
-- 
1.7.6




[Qemu-devel] [PATCH 6/7] balloon: Fix header comment; add Copyright

2011-07-20 Thread Amit Shah
Signed-off-by: Amit Shah 
---
 balloon.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/balloon.c b/balloon.c
index 8be3812..a938475 100644
--- a/balloon.c
+++ b/balloon.c
@@ -1,7 +1,9 @@
 /*
- * QEMU System Emulator
+ * Generic Balloon handlers and management
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Amit Shah 
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal
@@ -30,7 +32,6 @@
 #include "balloon.h"
 #include "trace.h"
 
-
 static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
-- 
1.7.6




[Qemu-devel] [PATCH v7 03/11] spice/qxl: move worker wrappers

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Move the wrapper functions which are used by qxl only to qxl.c.
Rename them from qemu_spice_* to qxl_spice_*.  Also pass in a
qxl state pointer instead of a SimpleSpiceDisplay pointer.

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl-render.c|4 +-
 hw/qxl.c   |   67 ---
 hw/qxl.h   |   13 ++
 ui/spice-display.c |   46 ---
 ui/spice-display.h |   12 -
 5 files changed, 72 insertions(+), 70 deletions(-)

diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index bef5f14..60b822d 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -124,8 +124,8 @@ void qxl_render_update(PCIQXLDevice *qxl)
 update.bottom = qxl->guest_primary.surface.height;
 
 memset(dirty, 0, sizeof(dirty));
-qemu_spice_update_area(&qxl->ssd, 0, &update,
-   dirty, ARRAY_SIZE(dirty), 1);
+qxl_spice_update_area(qxl, 0, &update,
+  dirty, ARRAY_SIZE(dirty), 1);
 
 for (i = 0; i < ARRAY_SIZE(dirty); i++) {
 if (qemu_spice_rect_is_empty(dirty+i)) {
diff --git a/hw/qxl.c b/hw/qxl.c
index 2d46814..29094a9 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -125,6 +125,53 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
 
+
+void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
+   struct QXLRect *area, struct QXLRect *dirty_rects,
+   uint32_t num_dirty_rects,
+   uint32_t clear_dirty_region)
+{
+qxl->ssd.worker->update_area(qxl->ssd.worker, surface_id, area, 
dirty_rects,
+ num_dirty_rects, clear_dirty_region);
+}
+
+void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id)
+{
+qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
+}
+
+void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
+   uint32_t count)
+{
+qxl->ssd.worker->loadvm_commands(qxl->ssd.worker, ext, count);
+}
+
+void qxl_spice_oom(PCIQXLDevice *qxl)
+{
+qxl->ssd.worker->oom(qxl->ssd.worker);
+}
+
+void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
+{
+qxl->ssd.worker->reset_memslots(qxl->ssd.worker);
+}
+
+void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl)
+{
+qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
+}
+
+void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
+{
+qxl->ssd.worker->reset_image_cache(qxl->ssd.worker);
+}
+
+void qxl_spice_reset_cursor(PCIQXLDevice *qxl)
+{
+qxl->ssd.worker->reset_cursor(qxl->ssd.worker);
+}
+
+
 static inline uint32_t msb_mask(uint32_t val)
 {
 uint32_t mask;
@@ -690,8 +737,8 @@ static void qxl_hard_reset(PCIQXLDevice *d, int loadvm)
 dprint(d, 1, "%s: start%s\n", __FUNCTION__,
loadvm ? " (loadvm)" : "");
 
-qemu_spice_reset_cursor(&d->ssd);
-qemu_spice_reset_image_cache(&d->ssd);
+qxl_spice_reset_cursor(d);
+qxl_spice_reset_image_cache(d);
 qxl_reset_surfaces(d);
 qxl_reset_memslots(d);
 
@@ -813,7 +860,7 @@ static void qxl_del_memslot(PCIQXLDevice *d, uint32_t 
slot_id)
 static void qxl_reset_memslots(PCIQXLDevice *d)
 {
 dprint(d, 1, "%s:\n", __FUNCTION__);
-qemu_spice_reset_memslots(&d->ssd);
+qxl_spice_reset_memslots(d);
 memset(&d->guest_slots, 0, sizeof(d->guest_slots));
 }
 
@@ -821,7 +868,7 @@ static void qxl_reset_surfaces(PCIQXLDevice *d)
 {
 dprint(d, 1, "%s:\n", __FUNCTION__);
 d->mode = QXL_MODE_UNDEFINED;
-qemu_spice_destroy_surfaces(&d->ssd);
+qxl_spice_destroy_surfaces(d);
 memset(&d->guest_surfaces.cmds, 0, sizeof(d->guest_surfaces.cmds));
 }
 
@@ -962,8 +1009,8 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 case QXL_IO_UPDATE_AREA:
 {
 QXLRect update = d->ram->update_area;
-qemu_spice_update_area(&d->ssd, d->ram->update_surface,
-   &update, NULL, 0, 0);
+qxl_spice_update_area(d, d->ram->update_surface,
+  &update, NULL, 0, 0);
 break;
 }
 case QXL_IO_NOTIFY_CMD:
@@ -984,7 +1031,7 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 break;
 }
 d->oom_running = 1;
-qemu_spice_oom(&d->ssd);
+qxl_spice_oom(d);
 d->oom_running = 0;
 break;
 case QXL_IO_SET_MODE:
@@ -1022,10 +1069,10 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 qxl_destroy_primary(d);
 break;
 case QXL_IO_DESTROY_SURFACE_WAIT:
-qemu_spice_destroy_surface_wait(&d->ssd, val);
+qxl_spice_destroy_surface_wait(d, val);
 break;
 case QXL_IO_DESTROY_ALL_SURFACES:
-qemu_spice_destroy_surfaces(&d->ssd);
+qxl_spice_destroy_surfaces(d);
 break;
 default:
 fprintf(stderr,

[Qemu-devel] [PATCH v7 09/11] qxl: async io support using new spice api

2011-07-20 Thread Alon Levy
Some of the QXL port i/o commands are waiting for the spice server to
complete certain actions.  Add async versions for these commands, so we
don't block the vcpu while the spice server processses the command.
Instead the qxl device will raise an IRQ when done.

The async command processing relies on an added QXLInterface::async_complete
and added QXLWorker::*_async additions, in spice server qxl >= 3.1

Signed-off-by: Gerd Hoffmann 
Signed-off-by: Alon Levy 
---
 hw/qxl-render.c|2 +-
 hw/qxl.c   |  240 
 hw/qxl.h   |   16 +++-
 ui/spice-display.c |   47 --
 ui/spice-display.h |   23 +-
 5 files changed, 274 insertions(+), 54 deletions(-)

diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index 60b822d..643ff2d 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -125,7 +125,7 @@ void qxl_render_update(PCIQXLDevice *qxl)
 
 memset(dirty, 0, sizeof(dirty));
 qxl_spice_update_area(qxl, 0, &update,
-  dirty, ARRAY_SIZE(dirty), 1);
+  dirty, ARRAY_SIZE(dirty), 1, QXL_SYNC);
 
 for (i = 0; i < ARRAY_SIZE(dirty); i++) {
 if (qemu_spice_rect_is_empty(dirty+i)) {
diff --git a/hw/qxl.c b/hw/qxl.c
index b946942..9d6c059 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -120,7 +120,7 @@ static QXLMode qxl_modes[] = {
 static PCIQXLDevice *qxl0;
 
 static void qxl_send_events(PCIQXLDevice *d, uint32_t events);
-static void qxl_destroy_primary(PCIQXLDevice *d);
+static int qxl_destroy_primary(PCIQXLDevice *d, qxl_async_io async);
 static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
@@ -144,22 +144,47 @@ void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, 
...)
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
struct QXLRect *area, struct QXLRect *dirty_rects,
uint32_t num_dirty_rects,
-   uint32_t clear_dirty_region)
+   uint32_t clear_dirty_region,
+   qxl_async_io async)
 {
-qxl->ssd.worker->update_area(qxl->ssd.worker, surface_id, area, 
dirty_rects,
- num_dirty_rects, clear_dirty_region);
+if (async == QXL_SYNC) {
+qxl->ssd.worker->update_area(qxl->ssd.worker, surface_id, area,
+dirty_rects, num_dirty_rects, clear_dirty_region);
+} else {
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+spice_qxl_update_area_async(&qxl->ssd.qxl, surface_id, area,
+clear_dirty_region, 0);
+#else
+abort();
+#endif
+}
 }
 
-void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id)
+static void qxl_spice_destroy_surface_wait_complete(PCIQXLDevice *qxl,
+uint32_t id)
 {
 qemu_mutex_lock(&qxl->track_lock);
-PANIC_ON(id >= NUM_SURFACES);
-qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
 qxl->guest_surfaces.cmds[id] = 0;
 qxl->guest_surfaces.count--;
 qemu_mutex_unlock(&qxl->track_lock);
 }
 
+static void qxl_spice_destroy_surface_wait(PCIQXLDevice *qxl, uint32_t id,
+   qxl_async_io async)
+{
+if (async) {
+#if SPICE_INTERFACE_QXL_MINOR < 1
+abort();
+#else
+spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id,
+(uint64_t)id);
+#endif
+} else {
+qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
+qxl_spice_destroy_surface_wait_complete(qxl, id);
+}
+}
+
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
uint32_t count)
 {
@@ -176,15 +201,28 @@ void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
 qxl->ssd.worker->reset_memslots(qxl->ssd.worker);
 }
 
-void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl)
+static void qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
 {
 qemu_mutex_lock(&qxl->track_lock);
-qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
 memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
 qxl->guest_surfaces.count = 0;
 qemu_mutex_unlock(&qxl->track_lock);
 }
 
+static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async)
+{
+if (async) {
+#if SPICE_INTERFACE_QXL_MINOR < 1
+abort();
+#else
+spice_qxl_destroy_surfaces_async(&qxl->ssd.qxl, 0);
+#endif
+} else {
+qxl->ssd.worker->destroy_surfaces(qxl->ssd.worker);
+qxl_spice_destroy_surfaces_complete(qxl);
+}
+}
+
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
 {
 qxl->ssd.worker->reset_image_cache(qxl->ssd.worker);
@@ -689,6 +727,38 @@ static int interface_flush_resources(QXLInstance *sin)
 return ret;
 }
 
+static void qxl_create_guest_primary_complete(PCIQXLDevice *d);

[Qemu-devel] [PATCH 7/7] virtio-balloon: Fix header comment; add Copyright

2011-07-20 Thread Amit Shah
Signed-off-by: Amit Shah 
---
 hw/virtio-balloon.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 40b43b0..2ba7e95 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -1,7 +1,9 @@
 /*
- * Virtio Block Device
+ * Virtio Balloon Device
  *
  * Copyright IBM, Corp. 2008
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Amit Shah 
  *
  * Authors:
  *  Anthony Liguori   
-- 
1.7.6




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Daniel P. Berrange
On Wed, Jul 20, 2011 at 10:26:49AM +0200, Jes Sorensen wrote:
> On 07/19/11 18:47, Daniel P. Berrange wrote:
> > On Tue, Jul 19, 2011 at 04:30:19PM +0200, Jes Sorensen wrote:
> >> On 07/19/11 16:24, Eric Blake wrote:
> >>> Besides, I feel that having a well-documented file format, so that
> >>> independent applications can both parse the same file with the same
> >>> semantics by obeying the file format specification, is a good design goal.
> >>
> >> We all know that documentation is rarely uptodate, new features may not
> >> get added and libvirt will never be able to keep up. The driver for a
> >> file format belongs in QEMU and nowhere else.
> > 
> > This would be possible if QEMU to provide a libblockformat.so library
> > which allowed apps to extract metadata from file formats using a stable
> > API.
> 
> There is no reason for libvirt or any external process to mess about
> with the internals of image files. You have the same problem if the
> image file is encrypted.

Just repeating "libvirt doesn't need todo this" many times doesn't make
it true. I have described why we need to read the disk image to determine
its backing files ahead of QEMU being launched quite clearly.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH v7 11/11] qxl: bump pci rev

2011-07-20 Thread Alon Levy
From: Gerd Hoffmann 

Inform guest drivers about the new features I/O commands we have
now (async commands, S3 support) if building with newer spice, i.e.
if SPICE_INTERFACE_QXL_MINOR >= 1.

sneaked in some 81+ column line spliting.

Signed-off-by: Gerd Hoffmann 
Signed-off-by: Alon Levy 
---
 hw/qxl.c |   25 ++---
 hw/qxl.h |6 ++
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 07bd1ae..66ebdfa 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1572,9 +1572,14 @@ static int qxl_init_common(PCIQXLDevice *qxl)
 pci_device_rev = QXL_REVISION_STABLE_V04;
 break;
 case 2: /* spice 0.6 -- qxl-2 */
-default:
 pci_device_rev = QXL_REVISION_STABLE_V06;
 break;
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+case 3: /* qxl-3 */
+#endif
+default:
+pci_device_rev = QXL_DEFAULT_REVISION;
+break;
 }
 
 pci_set_byte(&config[PCI_REVISION_ID], pci_device_rev);
@@ -1836,9 +1841,12 @@ static PCIDeviceInfo qxl_info_primary = {
 .device_id= QXL_DEVICE_ID_STABLE,
 .class_id = PCI_CLASS_DISPLAY_VGA,
 .qdev.props = (Property[]) {
-DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size, 64 * 1024 
* 1024),
-DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size, 64 * 1024 * 
1024),
-DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision, 2),
+DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size,
+   64 * 1024 * 1024),
+DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size,
+   64 * 1024 * 1024),
+DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision,
+   QXL_DEFAULT_REVISION),
 DEFINE_PROP_UINT32("debug", PCIQXLDevice, debug, 0),
 DEFINE_PROP_UINT32("guestdebug", PCIQXLDevice, guestdebug, 0),
 DEFINE_PROP_UINT32("cmdlog", PCIQXLDevice, cmdlog, 0),
@@ -1857,9 +1865,12 @@ static PCIDeviceInfo qxl_info_secondary = {
 .device_id= QXL_DEVICE_ID_STABLE,
 .class_id = PCI_CLASS_DISPLAY_OTHER,
 .qdev.props = (Property[]) {
-DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size, 64 * 1024 
* 1024),
-DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size, 64 * 1024 * 
1024),
-DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision, 2),
+DEFINE_PROP_UINT32("ram_size", PCIQXLDevice, vga.vram_size,
+   64 * 1024 * 1024),
+DEFINE_PROP_UINT32("vram_size", PCIQXLDevice, vram_size,
+   64 * 1024 * 1024),
+DEFINE_PROP_UINT32("revision", PCIQXLDevice, revision,
+   QXL_DEFAULT_REVISION),
 DEFINE_PROP_UINT32("debug", PCIQXLDevice, debug, 0),
 DEFINE_PROP_UINT32("guestdebug", PCIQXLDevice, guestdebug, 0),
 DEFINE_PROP_UINT32("cmdlog", PCIQXLDevice, cmdlog, 0),
diff --git a/hw/qxl.h b/hw/qxl.h
index 1046205..4bcf7e1 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -102,6 +102,12 @@ typedef struct PCIQXLDevice {
 }   \
 } while (0)
 
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V10
+#else
+#define QXL_DEFAULT_REVISION QXL_REVISION_STABLE_V06
+#endif
+
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
 void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...);
-- 
1.7.6




[Qemu-devel] [PATCH v7 07/11] qxl: make qxl_guest_bug take variable arguments

2011-07-20 Thread Alon Levy
Signed-off-by: Alon Levy 
---
 hw/qxl.c |9 +++--
 hw/qxl.h |2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 68ce409..d645c87 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -125,13 +125,18 @@ static void qxl_reset_memslots(PCIQXLDevice *d);
 static void qxl_reset_surfaces(PCIQXLDevice *d);
 static void qxl_ring_set_dirty(PCIQXLDevice *qxl);
 
-void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg)
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...)
 {
 #if SPICE_INTERFACE_QXL_MINOR >= 1
 qxl_send_events(qxl, QXL_INTERRUPT_ERROR);
 #endif
 if (qxl->guestdebug) {
-fprintf(stderr, "qxl-%d: guest bug: %s\n", qxl->id, msg);
+va_list ap;
+va_start(ap, msg);
+fprintf(stderr, "qxl-%d: guest bug: ", qxl->id);
+vfprintf(stderr, msg, ap);
+fprintf(stderr, "\n");
+va_end(ap);
 }
 }
 
diff --git a/hw/qxl.h b/hw/qxl.h
index 5db9aae..32ca5a0 100644
--- a/hw/qxl.h
+++ b/hw/qxl.h
@@ -99,7 +99,7 @@ typedef struct PCIQXLDevice {
 
 /* qxl.c */
 void *qxl_phys2virt(PCIQXLDevice *qxl, QXLPHYSICAL phys, int group_id);
-void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg);
+void qxl_guest_bug(PCIQXLDevice *qxl, const char *msg, ...);
 
 void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t surface_id,
struct QXLRect *area, struct QXLRect *dirty_rects,
-- 
1.7.6




Re: [Qemu-devel] [PATCH] virtio-9p: Fix syntax error in debug code

2011-07-20 Thread Aneesh Kumar K.V
On Wed, 20 Jul 2011 08:27:28 +0200, Stefan Weil  wrote:
> This error was reported by cppcheck:
> 
> qemu/hw/9pfs/virtio-9p-debug.c:342:
> error: Invalid number of character ({) when these macros are defined:
> 'DEBUG_DATA'.
> 
> Cc: Aneesh Kumar K.V 
> Signed-off-by: Stefan Weil 
> ---
>  hw/9pfs/virtio-9p-debug.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-debug.c b/hw/9pfs/virtio-9p-debug.c
> index 4636ad5..96925f0 100644
> --- a/hw/9pfs/virtio-9p-debug.c
> +++ b/hw/9pfs/virtio-9p-debug.c
> @@ -295,7 +295,7 @@ static void pprint_data(V9fsPDU *pdu, int rx, size_t 
> *offsetp, const char *name)
> 
>  if (rx) {
>  count = pdu->elem.in_num;
> -} else
> +} else {
>  count = pdu->elem.out_num;
>  }
> 

Applied.

We also need to update virtio-9p-debug w.r.t the new co-routine
series. With co-routine we can have multiple 9p handler started
simultaneously.

-aneesh



Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Daniel P. Berrange
On Wed, Jul 20, 2011 at 10:23:12AM +0200, Jes Sorensen wrote:
> On 07/19/11 18:46, Daniel P. Berrange wrote:
> > On Tue, Jul 19, 2011 at 04:14:27PM +0100, Stefan Hajnoczi wrote:
> >> For fd-passing perhaps we have an opportunity to use a callback
> >> mechanism (QEMU request: filename -> libvirt response: fd) and do all
> >> the image format parsing in QEMU.
> > 
> > The reason why libvirt does the parsing of file headers to determine
> > backing files is to maintain the trust boundary. Everything run from
> > the exec() of QEMU onwards is considered untrusted code. So having
> > QEMU parsing the file headers & passing back open() requests to libvirt
> > is breaking the trust boundary.
> 
> Pardon, but I fail to see the issue here. If QEMU passes a filename back
> to libvirt, libvirt still gets to make the decision whether or not it is
> legitimate for QEMU to get that file descriptor or not. It doesn't
> change anything wrt who actually opens the file, hence the 'trust' is
> unchanged.

To make the decision whether the filename from QEMU is valid, we have
to parse the master image header data to see if the filename actually
matches the backing file required by the image assigned to the guest.

> > NB, i'm not happy about libvirt having to have knowledge of file format
> > headers, but we needed something more efficient & reliable than invoking
> > qemu-img info & parsing the output. Ideally QEMU (or something else)
> > would provide a library libblockformat.so with stable APIs for at least
> > reading metadata about image formats. If it had APIs for image creation,
> > etc too that would be a bonus, but we're more or less ok spawning qemu-img
> > for those cases currently.
> 
> Even having a library for libvirt to link against is suboptimal here.
> Two processes shouldn't be fighting over the internals of metadata, the
> ownership of the metadata belongs solely with QEMU. In addition you have
> the constant issue of dependencies there, hence if QEMU is updated and
> it provides a newer block format library, it may prevent libvirt from
> running forcing an update of libvirt as well. That is not acceptable for
> development.

We're not fighting over the internals of metadata. We just need to know
ahead of launching QEMU, what backing files an image has & what format
they are in. We do that by reading at the metadata headers of the disk
images. We never attempt to write to the disk images. Either someone
provides a library todo that, or we write the probing code for each
file format in libvirt. Currently we have the latter.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH v7 00/11] async + suspend reworked

2011-07-20 Thread Alon Levy
v7 changes:
 use updated spice api (spice_qxl_update_area_async etc.)

Alon Levy (5):
  qxl: add io_port_to_string
  qxl: make qxl_guest_bug take variable arguments
  qxl: only disallow specific io's in vga mode
  qxl: async io support using new spice api
  qxl: add QXL_IO_FLUSH_{SURFACES,RELEASE} for guest S3&S4 support

Gerd Hoffmann (6):
  spice: add worker wrapper functions.
  spice: add qemu_spice_display_init_common
  spice/qxl: move worker wrappers
  qxl: fix surface tracking & locking
  qxl: error handling fixes and cleanups.
  qxl: bump pci rev

 hw/qxl-render.c|4 +-
 hw/qxl.c   |  438 +---
 hw/qxl.h   |   34 -
 ui/spice-display.c |   93 ++--
 ui/spice-display.h |   28 
 5 files changed, 528 insertions(+), 69 deletions(-)

-- 
1.7.6




[Qemu-devel] [PATCH 5/9] usb storage: first migration support bits.

2011-07-20 Thread Gerd Hoffmann
Tag vmstate as unmigratable for the time being,
to be removed when mgration support is finished.

Signed-off-by: Gerd Hoffmann 
---
 hw/usb-msd.c |   12 
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 86582cc..8ed8594 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -623,11 +623,23 @@ static USBDevice *usb_msd_init(const char *filename)
 return dev;
 }
 
+static const VMStateDescription vmstate_usb_msd = {
+.name = "usb-storage",
+.unmigratable = 1, /* FIXME: handle transactions which are in flight */
+.version_id = 1,
+.minimum_version_id = 1,
+.fields = (VMStateField []) {
+VMSTATE_USB_DEVICE(dev, MSDState),
+VMSTATE_END_OF_LIST()
+}
+};
+
 static struct USBDeviceInfo msd_info = {
 .product_desc   = "QEMU USB MSD",
 .qdev.name  = "usb-storage",
 .qdev.fw_name  = "storage",
 .qdev.size  = sizeof(MSDState),
+.qdev.vmsd  = &vmstate_usb_msd,
 .usb_desc   = &desc,
 .init   = usb_msd_initfn,
 .handle_packet  = usb_generic_handle_packet,
-- 
1.7.1




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Kevin Wolf
Am 19.07.2011 18:46, schrieb Daniel P. Berrange:
> On Tue, Jul 19, 2011 at 04:14:27PM +0100, Stefan Hajnoczi wrote:
>> On Tue, Jul 19, 2011 at 3:30 PM, Jes Sorensen  
>> wrote:
>>> On 07/19/11 16:24, Eric Blake wrote:
 [adding the libvir-list]
 On 07/19/2011 08:09 AM, Jes Sorensen wrote:
> Urgh, libvirt parsing image files is really unfortunate, it really
> doesn't give me warm fuzzy feelings :( libvirt really should not know
> about internals of image formats.

 But even if you add new features to qemu to avoid needing this in the
 future, it doesn't change the past - libvirt will always have to know
 how to parse image files understood by older qemu, and so as long as
 libvirt already knows how to do that parsing, we might as well take
 advantage of it.
>>>
>>> What has been done here in the past is plain wrong. Continuing to do it
>>> isn't the right thing to do here.
>>>
 Besides, I feel that having a well-documented file format, so that
 independent applications can both parse the same file with the same
 semantics by obeying the file format specification, is a good design goal.
>>>
>>> We all know that documentation is rarely uptodate, new features may not
>>> get added and libvirt will never be able to keep up. The driver for a
>>> file format belongs in QEMU and nowhere else.
>>
>> It should be a goal to avoid dependencies in multiple layers of the
>> stack because it becomes are to add new features - they require
>> coordinated changes in multiple layers.  Having both QEMU and libvirt
>> know the internals of image files is such a multi-dependency.  If I
>> want to add a new format or change an existing format I have to touch
>> both layers.
>>
>> For fd-passing perhaps we have an opportunity to use a callback
>> mechanism (QEMU request: filename -> libvirt response: fd) and do all
>> the image format parsing in QEMU.
> 
> The reason why libvirt does the parsing of file headers to determine
> backing files is to maintain the trust boundary. Everything run from
> the exec() of QEMU onwards is considered untrusted code. So having
> QEMU parsing the file headers & passing back open() requests to libvirt
> is breaking the trust boundary.
> 
> NB, i'm not happy about libvirt having to have knowledge of file format
> headers, but we needed something more efficient & reliable than invoking
> qemu-img info & parsing the output. 

What's the real problem with this approach? Parsing the data meant for
humans, from an interface that is potentially unstable? If this is it,
it should be easy enough to add a JSON output mode to qemu-img info.

> Ideally QEMU (or something else)
> would provide a library libblockformat.so with stable APIs for at least
> reading metadata about image formats. If it had APIs for image creation,
> etc too that would be a bonus, but we're more or less ok spawning qemu-img
> for those cases currently.

I'm afraid the block drivers have too many dependencies on the qemu core
for this to be an option without investing a lot of effort.

Kevin



[Qemu-devel] [PATCH 3/9] ahci doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/ide/ich.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index 054e073..d241ea8 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -72,6 +72,11 @@
 #include 
 #include 
 
+static const VMStateDescription vmstate_ahci = {
+.name = "ahci",
+.unmigratable = 1,
+};
+
 static int pci_ich9_ahci_init(PCIDevice *dev)
 {
 struct AHCIPCIState *d;
@@ -123,6 +128,7 @@ static PCIDeviceInfo ich_ahci_info[] = {
 .qdev.name= "ich9-ahci",
 .qdev.alias   = "ahci",
 .qdev.size= sizeof(AHCIPCIState),
+.qdev.vmsd= &vmstate_ahci,
 .init = pci_ich9_ahci_init,
 .exit = pci_ich9_uninit,
 .config_write = pci_ich9_write_config,
-- 
1.7.1




[Qemu-devel] [PATCH v7 05/11] qxl: add io_port_to_string

2011-07-20 Thread Alon Levy
Signed-off-by: Alon Levy 
---
 hw/qxl.c |   40 +++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index e832d00..7d8b312 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -409,6 +409,43 @@ static const char *qxl_mode_to_string(int mode)
 return "INVALID";
 }
 
+static const char *io_port_to_string(uint32_t io_port)
+{
+if (io_port >= QXL_IO_RANGE_SIZE) {
+return "out of range";
+}
+static const char *io_port_to_string[QXL_IO_RANGE_SIZE + 1] = {
+[QXL_IO_NOTIFY_CMD] = "QXL_IO_NOTIFY_CMD",
+[QXL_IO_NOTIFY_CURSOR]  = "QXL_IO_NOTIFY_CURSOR",
+[QXL_IO_UPDATE_AREA]= "QXL_IO_UPDATE_AREA",
+[QXL_IO_UPDATE_IRQ] = "QXL_IO_UPDATE_IRQ",
+[QXL_IO_NOTIFY_OOM] = "QXL_IO_NOTIFY_OOM",
+[QXL_IO_RESET]  = "QXL_IO_RESET",
+[QXL_IO_SET_MODE]   = "QXL_IO_SET_MODE",
+[QXL_IO_LOG]= "QXL_IO_LOG",
+[QXL_IO_MEMSLOT_ADD]= "QXL_IO_MEMSLOT_ADD",
+[QXL_IO_MEMSLOT_DEL]= "QXL_IO_MEMSLOT_DEL",
+[QXL_IO_DETACH_PRIMARY] = "QXL_IO_DETACH_PRIMARY",
+[QXL_IO_ATTACH_PRIMARY] = "QXL_IO_ATTACH_PRIMARY",
+[QXL_IO_CREATE_PRIMARY] = "QXL_IO_CREATE_PRIMARY",
+[QXL_IO_DESTROY_PRIMARY]= "QXL_IO_DESTROY_PRIMARY",
+[QXL_IO_DESTROY_SURFACE_WAIT]   = "QXL_IO_DESTROY_SURFACE_WAIT",
+[QXL_IO_DESTROY_ALL_SURFACES]   = "QXL_IO_DESTROY_ALL_SURFACES",
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+[QXL_IO_UPDATE_AREA_ASYNC]  = "QXL_IO_UPDATE_AREA_ASYNC",
+[QXL_IO_MEMSLOT_ADD_ASYNC]  = "QXL_IO_MEMSLOT_ADD_ASYNC",
+[QXL_IO_CREATE_PRIMARY_ASYNC]   = "QXL_IO_CREATE_PRIMARY_ASYNC",
+[QXL_IO_DESTROY_PRIMARY_ASYNC]  = "QXL_IO_DESTROY_PRIMARY_ASYNC",
+[QXL_IO_DESTROY_SURFACE_ASYNC]  = "QXL_IO_DESTROY_SURFACE_ASYNC",
+[QXL_IO_DESTROY_ALL_SURFACES_ASYNC]
+= "QXL_IO_DESTROY_ALL_SURFACES_ASYNC",
+[QXL_IO_FLUSH_SURFACES_ASYNC]   = "QXL_IO_FLUSH_SURFACES_ASYNC",
+[QXL_IO_FLUSH_RELEASE]  = "QXL_IO_FLUSH_RELEASE",
+#endif
+};
+return io_port_to_string[io_port];
+}
+
 /* called from spice server thread context only */
 static int interface_get_command(QXLInstance *sin, struct QXLCommandExt *ext)
 {
@@ -1011,7 +1048,8 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 default:
 if (d->mode == QXL_MODE_NATIVE || d->mode == QXL_MODE_COMPAT)
 break;
-dprint(d, 1, "%s: unexpected port 0x%x in vga mode\n", __FUNCTION__, 
io_port);
+dprint(d, 1, "%s: unexpected port 0x%x (%s) in vga mode\n",
+__func__, io_port, io_port_to_string(io_port));
 return;
 }
 
-- 
1.7.6




[Qemu-devel] [PATCH 8/9] usb-net doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb-net.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/usb-net.c b/hw/usb-net.c
index 9be709f..4212e5b 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1414,11 +1414,17 @@ static USBDevice *usb_net_init(const char *cmdline)
 return dev;
 }
 
+static const VMStateDescription vmstate_usb_net = {
+.name = "usb-net",
+.unmigratable = 1,
+};
+
 static struct USBDeviceInfo net_info = {
 .product_desc   = "QEMU USB Network Interface",
 .qdev.name  = "usb-net",
 .qdev.fw_name= "network",
 .qdev.size  = sizeof(USBNetState),
+.qdev.vmsd  = &vmstate_usb_net,
 .usb_desc   = &desc_net,
 .init   = usb_net_initfn,
 .handle_packet  = usb_generic_handle_packet,
-- 
1.7.1




[Qemu-devel] [PATCH 6/9] usb-wacom doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb-wacom.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 9d348e1..d76ee97 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -349,6 +349,11 @@ static int usb_wacom_initfn(USBDevice *dev)
 return 0;
 }
 
+static const VMStateDescription vmstate_usb_wacom = {
+.name = "usb-wacom",
+.unmigratable = 1,
+};
+
 static struct USBDeviceInfo wacom_info = {
 .product_desc   = "QEMU PenPartner Tablet",
 .qdev.name  = "usb-wacom-tablet",
@@ -356,6 +361,7 @@ static struct USBDeviceInfo wacom_info = {
 .usbdevice_name = "wacom-tablet",
 .usb_desc   = &desc_wacom,
 .qdev.size  = sizeof(USBWacomState),
+.qdev.vmsd  = &vmstate_usb_wacom,
 .init   = usb_wacom_initfn,
 .handle_packet  = usb_generic_handle_packet,
 .handle_reset   = usb_wacom_handle_reset,
-- 
1.7.1




Re: [Qemu-devel] error "kvm: virtio: trying to map MMIO memory"

2011-07-20 Thread Stéphanie Ouillon

Thank you for your help, I have been able to see where was the bug !
Indeed, I was losing some address values along the way in a callback 
function whereas I thought they were kept memorized.



Regards

Stéphanie



[Qemu-devel] [PATCH v7 08/11] qxl: only disallow specific io's in vga mode

2011-07-20 Thread Alon Levy
Since the driver is still in operation even after moving to UNDEFINED, i.e.
by destroying primary in any way.

Signed-off-by: Alon Levy 
---
 hw/qxl.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index d645c87..b946942 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1061,8 +1061,9 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 case QXL_IO_LOG:
 break;
 default:
-if (d->mode == QXL_MODE_NATIVE || d->mode == QXL_MODE_COMPAT)
+if (d->mode != QXL_MODE_VGA) {
 break;
+}
 dprint(d, 1, "%s: unexpected port 0x%x (%s) in vga mode\n",
 __func__, io_port, io_port_to_string(io_port));
 return;
-- 
1.7.6




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Daniel P. Berrange
On Wed, Jul 20, 2011 at 11:50:53AM +0200, Kevin Wolf wrote:
> Am 19.07.2011 18:46, schrieb Daniel P. Berrange:
> > On Tue, Jul 19, 2011 at 04:14:27PM +0100, Stefan Hajnoczi wrote:
> >> On Tue, Jul 19, 2011 at 3:30 PM, Jes Sorensen  
> >> wrote:
> >>> On 07/19/11 16:24, Eric Blake wrote:
>  [adding the libvir-list]
>  On 07/19/2011 08:09 AM, Jes Sorensen wrote:
> > Urgh, libvirt parsing image files is really unfortunate, it really
> > doesn't give me warm fuzzy feelings :( libvirt really should not know
> > about internals of image formats.
> 
>  But even if you add new features to qemu to avoid needing this in the
>  future, it doesn't change the past - libvirt will always have to know
>  how to parse image files understood by older qemu, and so as long as
>  libvirt already knows how to do that parsing, we might as well take
>  advantage of it.
> >>>
> >>> What has been done here in the past is plain wrong. Continuing to do it
> >>> isn't the right thing to do here.
> >>>
>  Besides, I feel that having a well-documented file format, so that
>  independent applications can both parse the same file with the same
>  semantics by obeying the file format specification, is a good design 
>  goal.
> >>>
> >>> We all know that documentation is rarely uptodate, new features may not
> >>> get added and libvirt will never be able to keep up. The driver for a
> >>> file format belongs in QEMU and nowhere else.
> >>
> >> It should be a goal to avoid dependencies in multiple layers of the
> >> stack because it becomes are to add new features - they require
> >> coordinated changes in multiple layers.  Having both QEMU and libvirt
> >> know the internals of image files is such a multi-dependency.  If I
> >> want to add a new format or change an existing format I have to touch
> >> both layers.
> >>
> >> For fd-passing perhaps we have an opportunity to use a callback
> >> mechanism (QEMU request: filename -> libvirt response: fd) and do all
> >> the image format parsing in QEMU.
> > 
> > The reason why libvirt does the parsing of file headers to determine
> > backing files is to maintain the trust boundary. Everything run from
> > the exec() of QEMU onwards is considered untrusted code. So having
> > QEMU parsing the file headers & passing back open() requests to libvirt
> > is breaking the trust boundary.
> > 
> > NB, i'm not happy about libvirt having to have knowledge of file format
> > headers, but we needed something more efficient & reliable than invoking
> > qemu-img info & parsing the output. 
> 
> What's the real problem with this approach? Parsing the data meant for
> humans, from an interface that is potentially unstable? If this is it,
> it should be easy enough to add a JSON output mode to qemu-img info.

It is a really heavyweight solution to have to spawn qemu-img every
time we need to access this data, when it can be done with a trivial
open+read+close sequence. In addition the output data format is not
entirely pleasant for machine reading (some fields only have data
rounded up to MB, not the raw byte count). Finally, we also wanted
to be able to extract some basic metdata about disk image formats on
non-QEMU hosts, for our storage management APIs which are used on Xen
or VMWare hosts where many of these same disk image formats are also
used. A JSON output mode would be helpful, but unfortunately can't
really address the other issues.

> > Ideally QEMU (or something else)
> > would provide a library libblockformat.so with stable APIs for at least
> > reading metadata about image formats. If it had APIs for image creation,
> > etc too that would be a bonus, but we're more or less ok spawning qemu-img
> > for those cases currently.
> 
> I'm afraid the block drivers have too many dependencies on the qemu core
> for this to be an option without investing a lot of effort.

That's why I sort of think there is value in having someone provide a
standalone  library API for querying some core set of block format
metadata. QEMU is but one project with virtual disk formats, there are
plenty of others out there in existance, so while reusing QEMU block
code would be nice, it isn't leading to any significant reduction in
copies of block format parsing code amongst all the virt projects in
existance.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] [PATCH] SPARC64: treat UA2007 ASI_BLK_* as translating ASIs.

2011-07-20 Thread Artyom Tarasenko
On Mon, Jul 18, 2011 at 7:32 AM, Tsuneo Saito  wrote:
> UA2007 ASI_BLK_* should be added in is_translating_asi().
>
> Signed-off-by: Tsuneo Saito 

The comment "Ultrasparc IIi translating asi" has to be adjusted too.
Otherwise
Acked-by: Artyom Tarasenko 

The other patches - fcmp and fmovd  - pass my tests, but Blue may want
to review them himself.



[Qemu-devel] [PATCH 9/9] usb-serial doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb-serial.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 59cb0fb..70d694d 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -566,10 +566,16 @@ static USBDevice *usb_braille_init(const char *unused)
 return dev;
 }
 
+static const VMStateDescription vmstate_usb_serial = {
+.name = "usb-serial",
+.unmigratable = 1,
+};
+
 static struct USBDeviceInfo serial_info = {
 .product_desc   = "QEMU USB Serial",
 .qdev.name  = "usb-serial",
 .qdev.size  = sizeof(USBSerialState),
+.qdev.vmsd  = &vmstate_usb_serial,
 .usb_desc   = &desc_serial,
 .init   = usb_serial_initfn,
 .handle_packet  = usb_generic_handle_packet,
@@ -589,6 +595,7 @@ static struct USBDeviceInfo braille_info = {
 .product_desc   = "QEMU USB Braille",
 .qdev.name  = "usb-braille",
 .qdev.size  = sizeof(USBSerialState),
+.qdev.vmsd  = &vmstate_usb_serial,
 .usb_desc   = &desc_braille,
 .init   = usb_serial_initfn,
 .handle_packet  = usb_generic_handle_packet,
-- 
1.7.1




[Qemu-devel] [PATCH v7 10/11] qxl: add QXL_IO_FLUSH_{SURFACES, RELEASE} for guest S3&S4 support

2011-07-20 Thread Alon Levy
Add two new IOs.
 QXL_IO_FLUSH_SURFACES - equivalent to update area for all surfaces, used
  to reduce vmexits from NumSurfaces to 1 on guest S3, S4 and resolution change 
(windows
  driver implementation is such that this is done on each of those occasions).
 QXL_IO_FLUSH_RELEASE - used to ensure anything on last_release is put on the 
release ring
  for the client to free.

Signed-off-by: Yonit Halperin 
Signed-off-by: Alon Levy 
---
 hw/qxl.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 9d6c059..07bd1ae 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -185,6 +185,13 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice 
*qxl, uint32_t id,
 }
 }
 
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+static void qxl_spice_flush_surfaces_async(PCIQXLDevice *qxl)
+{
+spice_qxl_flush_surfaces_async(&qxl->ssd.qxl, 0);
+}
+#endif
+
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
uint32_t count)
 {
@@ -1190,6 +1197,8 @@ static void ioport_write(void *opaque, uint32_t addr, 
uint32_t val)
 goto async_common;
 case QXL_IO_DESTROY_ALL_SURFACES_ASYNC:
 io_port = QXL_IO_DESTROY_ALL_SURFACES;
+goto async_common;
+case QXL_IO_FLUSH_SURFACES_ASYNC:
 async_common:
 async = QXL_ASYNC;
 qemu_mutex_lock(&d->async_lock);
@@ -1302,6 +1311,27 @@ async_common:
 }
 qxl_spice_destroy_surface_wait(d, val, async);
 break;
+#if SPICE_INTERFACE_QXL_MINOR >= 1
+case QXL_IO_FLUSH_RELEASE: {
+QXLReleaseRing *ring = &d->ram->release_ring;
+if (ring->prod - ring->cons + 1 == ring->num_items) {
+fprintf(stderr,
+"ERROR: no flush, full release ring [p%d,%dc]\n",
+ring->prod, ring->cons);
+}
+qxl_push_free_res(d, 1 /* flush */);
+dprint(d, 1, "QXL_IO_FLUSH_RELEASE exit (%s, s#=%d, res#=%d,%p)\n",
+qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+d->num_free_res, d->last_release);
+break;
+}
+case QXL_IO_FLUSH_SURFACES_ASYNC:
+dprint(d, 1, "QXL_IO_FLUSH_SURFACES_ASYNC (%d) (%s, s#=%d, res#=%d)\n",
+   val, qxl_mode_to_string(d->mode), d->guest_surfaces.count,
+   d->num_free_res);
+qxl_spice_flush_surfaces_async(d);
+break;
+#endif
 case QXL_IO_DESTROY_ALL_SURFACES:
 d->mode = QXL_MODE_UNDEFINED;
 qxl_spice_destroy_surfaces(d, async);
-- 
1.7.6




[Qemu-devel] [PATCH 01/10] slirp: Fix restricted mode

2011-07-20 Thread Jan Kiszka
This aligns the code to what the documentation claims: Allow everything
but requests that would have to be routed outside of the virtual LAN.

So we need to drop the unneeded IP-level filter, allow TFTP requests,
and add the missing protocol-level filter to ICMP.

CC: Gleb Natapov 
Signed-off-by: Jan Kiszka 
---
 slirp/ip_icmp.c  |2 ++
 slirp/ip_input.c |   21 -
 slirp/udp.c  |8 
 3 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 751a8e2..0cd129c 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -101,6 +101,8 @@ icmp_input(struct mbuf *m, int hlen)
 ip->ip_len += hlen; /* since ip_input subtracts this */
 if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) {
   icmp_reflect(m);
+} else if (slirp->restricted) {
+goto freeit;
 } else {
   struct socket *so;
   struct sockaddr_in addr;
diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 768ab0c..2ff6adb 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -118,27 +118,6 @@ ip_input(struct mbuf *m)
goto bad;
}
 
-if (slirp->restricted) {
-if ((ip->ip_dst.s_addr & slirp->vnetwork_mask.s_addr) ==
-slirp->vnetwork_addr.s_addr) {
-if (ip->ip_dst.s_addr == 0x && ip->ip_p != IPPROTO_UDP)
-goto bad;
-} else {
-uint32_t inv_mask = ~slirp->vnetwork_mask.s_addr;
-struct ex_list *ex_ptr;
-
-if ((ip->ip_dst.s_addr & inv_mask) == inv_mask) {
-goto bad;
-}
-for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
-if (ex_ptr->ex_addr.s_addr == ip->ip_dst.s_addr)
-break;
-
-if (!ex_ptr)
-goto bad;
-}
-}
-
/* Should drop packet if mbuf too long? hmmm... */
if (m->m_len > ip->ip_len)
   m_adj(m, ip->ip_len - m->m_len);
diff --git a/slirp/udp.c b/slirp/udp.c
index 02b3793..f1a9a10 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -125,10 +125,6 @@ udp_input(register struct mbuf *m, int iphlen)
 goto bad;
 }
 
-if (slirp->restricted) {
-goto bad;
-}
-
 /*
  *  handle TFTP
  */
@@ -137,6 +133,10 @@ udp_input(register struct mbuf *m, int iphlen)
 goto bad;
 }
 
+if (slirp->restricted) {
+goto bad;
+}
+
/*
 * Locate pcb for datagram.
 */
-- 
1.7.3.4




[Qemu-devel] [PATCH 7/9] usb-bt doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb-bt.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index e364513..4557802 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -548,10 +548,16 @@ USBDevice *usb_bt_init(HCIInfo *hci)
 return dev;
 }
 
+static const VMStateDescription vmstate_usb_bt = {
+.name = "usb-bt",
+.unmigratable = 1,
+};
+
 static struct USBDeviceInfo bt_info = {
 .product_desc   = "QEMU BT dongle",
 .qdev.name  = "usb-bt-dongle",
 .qdev.size  = sizeof(struct USBBtState),
+.qdev.vmsd  = &vmstate_usb_bt,
 .usb_desc   = &desc_bluetooth,
 .init   = usb_bt_initfn,
 .handle_packet  = usb_generic_handle_packet,
-- 
1.7.1




Re: [Qemu-devel] live snapshot wiki updated

2011-07-20 Thread Kevin Wolf
Am 20.07.2011 10:25, schrieb Jes Sorensen:
> On 07/19/11 18:14, Anthony Liguori wrote:
 As nice as that sentiment is, it will never fly, because it would be a
 regression in current behavior.  The whole reason that the virt_use_nfs
 SELinux bool exists is that some people are willing to make the partial
 security tradeoff.  Besides, the use of sVirt via SELinux is more than
 just open() protection - while the current virt_use_nfs bool makes NFS
 less secure than otherwise possible, it still gives some nice guarantees
 to the rest of the qemu process such as passthrough accesses to local
 pci devices.
>>>
>>> Well leaving things at status quo is not making it worse, it just leaves
>>> an evil in place.
>>
>> NFS and SELinux is a fundamental problem with SELinux and NFS.  We can
>> piss and moan as much as we want about it but it's reality.  SELinux
>> fundamentally requires extended attributes.  By the time NFS adds
>> extended attribute support, we'll all be flying around in hover cars.
>>
>> As terrible as NFS is, people use it all of the time.
>>
>> It would be nice if libvirt had the ability to make better use of DAC to
>> support isolation.  The fact that MAC is the only way you can do
>> isolation between guests is pretty unfortunate.  If I could assign
>> specific UIDs to a guest and use that to enforce isolation, it would go
>> a long ways to solving this problem.
> 
> Right, we're stuck with the two horros of NFS and selinux, so we need
> something that gets around the problem. In a sane world we would simply
> say 'no NFS, no selinux', but as you say that will never happen.
> 
> My suggestion of a callback mechanism where libvirt registers the
> callback with QEMU for open() calls, allowing libvirt to perform the
> open and return the open file descriptor would get around this problem.

To me this sounds more like a problem than a solution. It basically
means that during an open (which may even be initiated by a monitor
command), you need monitor interaction. It basically means that open
becomes asynchronous, and requires clients to deal with that, which
sounds at least "interesting"... Also you have to add some magic to all
places opening something.

I think if libvirt wants qemu to use an fd instead of a file name, it
shouldn't pass a file name but an fd in the first place. Which means
that the two that we need are support for an fd: protocol (patches on
the list, need review), and a way for libvirt to override the backing
file of an image.

Kevin



Re: [Qemu-devel] [PATCH] xen: fix xen-mapcache build on non-Xen capable targets

2011-07-20 Thread Alexander Graf
Oh, did the code that break this make it upstream already? I'll send a new pull 
request with my patches to fix all the regressions I've encountered ASAP.

Alex


On 20.07.2011, at 11:14, Avi Kivity wrote:

> Signed-off-by: Avi Kivity 
> ---
> xen-mapcache.h |   32 
> 1 files changed, 32 insertions(+), 0 deletions(-)
> 
> diff --git a/xen-mapcache.h b/xen-mapcache.h
> index 606b8af..da874ca 100644
> --- a/xen-mapcache.h
> +++ b/xen-mapcache.h
> @@ -9,6 +9,10 @@
> #ifndef XEN_MAPCACHE_H
> #define XEN_MAPCACHE_H
> 
> +#include 
> +
> +#ifdef CONFIG_XEN
> +
> void xen_map_cache_init(void);
> uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
>uint8_t lock);
> @@ -16,4 +20,32 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr);
> void xen_invalidate_map_cache_entry(uint8_t *buffer);
> void xen_invalidate_map_cache(void);
> 
> +#else
> +
> +static inline void xen_map_cache_init(void)
> +{
> +}
> +
> +static inline uint8_t *xen_map_cache(target_phys_addr_t phys_addr,
> + target_phys_addr_t size,
> + uint8_t lock)
> +{
> +abort();
> +}
> +
> +static inline ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
> +{
> +abort();
> +}
> +
> +static inline void xen_invalidate_map_cache_entry(uint8_t *buffer)
> +{
> +}
> +
> +static inline void xen_invalidate_map_cache(void)
> +{
> +}
> +
> +#endif
> +
> #endif /* !XEN_MAPCACHE_H */
> -- 
> 1.7.5.3
> 




[Qemu-devel] [PATCH 05/10] slirp: Put forked exec into separate process group

2011-07-20 Thread Jan Kiszka
Recent smb daemons tend to terminate themselves via a process group
SIGTERM. If the daemon is still in qemu's group by that time, qemu will
die as well. Avoid this by always pushing fork_exec processes into a
group of their own, not just (unused) type 2 execs.

Signed-off-by: Jan Kiszka 
---
 slirp/misc.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/slirp/misc.c b/slirp/misc.c
index 08eba6a..34179e2 100644
--- a/slirp/misc.c
+++ b/slirp/misc.c
@@ -153,11 +153,12 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
return 0;
 
 case 0:
+setsid();
+
/* Set the DISPLAY */
if (do_pty == 2) {
(void) close(master);
 #ifdef TIOCSCTTY /* X */
-   (void) setsid();
ioctl(s, TIOCSCTTY, (char *)NULL);
 #endif
} else {
-- 
1.7.3.4




[Qemu-devel] [PATCH 04/10] slirp: Replace m_freem with m_free

2011-07-20 Thread Jan Kiszka
Remove this pointless wrapping.

Signed-off-by: Jan Kiszka 
---
 slirp/ip_icmp.c   |6 +++---
 slirp/ip_input.c  |8 
 slirp/ip_output.c |4 ++--
 slirp/mbuf.h  |3 ---
 slirp/tcp_input.c |   10 +-
 slirp/tcp_subr.c  |2 +-
 slirp/udp.c   |2 +-
 7 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 0cd129c..4f10826 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -81,7 +81,7 @@ icmp_input(struct mbuf *m, int hlen)
*/
   if (icmplen < ICMP_MINLEN) {  /* min 8 bytes payload */
   freeit:
-m_freem(m);
+m_free(m);
 goto end_error;
   }
 
@@ -155,11 +155,11 @@ icmp_input(struct mbuf *m, int hlen)
   case ICMP_TSTAMP:
   case ICMP_MASKREQ:
   case ICMP_REDIRECT:
-m_freem(m);
+m_free(m);
 break;
 
   default:
-m_freem(m);
+m_free(m);
   } /* swith */
 
 end_error:
diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 2ff6adb..46c60b0 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -204,7 +204,7 @@ ip_input(struct mbuf *m)
}
return;
 bad:
-   m_freem(m);
+   m_free(m);
return;
 }
 
@@ -297,7 +297,7 @@ ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
break;
}
q = q->ipf_next;
-   m_freem(dtom(slirp, q->ipf_prev));
+   m_free(dtom(slirp, q->ipf_prev));
ip_deq(q->ipf_prev);
}
 
@@ -363,7 +363,7 @@ insert:
return ip;
 
 dropfrag:
-   m_freem(m);
+   m_free(m);
 return NULL;
 }
 
@@ -379,7 +379,7 @@ ip_freef(Slirp *slirp, struct ipq *fp)
for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link; q = 
p) {
p = q->ipf_next;
ip_deq(q);
-   m_freem(dtom(slirp, q));
+   m_free(dtom(slirp, q));
}
remque(&fp->ip_link);
(void) m_free(dtom(slirp, fp));
diff --git a/slirp/ip_output.c b/slirp/ip_output.c
index 542f318..c82830f 100644
--- a/slirp/ip_output.c
+++ b/slirp/ip_output.c
@@ -159,7 +159,7 @@ sendorfree:
if (error == 0)
if_output(so, m);
else
-   m_freem(m);
+   m_free(m);
}
 }
 
@@ -167,6 +167,6 @@ done:
return (error);
 
 bad:
-   m_freem(m0);
+   m_free(m0);
goto done;
 }
diff --git a/slirp/mbuf.h b/slirp/mbuf.h
index 97729e2..b74544b 100644
--- a/slirp/mbuf.h
+++ b/slirp/mbuf.h
@@ -33,9 +33,6 @@
 #ifndef _MBUF_H_
 #define _MBUF_H_
 
-#define m_freem m_free
-
-
 #define MINCSIZE 4096  /* Amount to increase mbuf if too small */
 
 /*
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index e4a7731..c1214c0 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -136,7 +136,7 @@ tcp_reass(register struct tcpcb *tp, register struct 
tcpiphdr *ti,
i = q->ti_seq + q->ti_len - ti->ti_seq;
if (i > 0) {
if (i >= ti->ti_len) {
-   m_freem(m);
+   m_free(m);
/*
 * Try to present any queued data
 * at the left window edge to the user.
@@ -170,7 +170,7 @@ tcp_reass(register struct tcpcb *tp, register struct 
tcpiphdr *ti,
q = tcpiphdr_next(q);
m = tcpiphdr_prev(q)->ti_mbuf;
remque(tcpiphdr2qlink(tcpiphdr_prev(q)));
-   m_freem(m);
+   m_free(m);
}
 
/*
@@ -197,7 +197,7 @@ present:
m = ti->ti_mbuf;
ti = tcpiphdr_next(ti);
if (so->so_state & SS_FCANTSENDMORE)
-   m_freem(m);
+   m_free(m);
else {
if (so->so_emu) {
if (tcp_emu(so,m)) sbappend(so, m);
@@ -451,7 +451,7 @@ findso:
acked = ti->ti_ack - tp->snd_una;
sbdrop(&so->so_snd, acked);
tp->snd_una = ti->ti_ack;
-   m_freem(m);
+   m_free(m);
 
/*
 * If all outstanding data are acked, stop
@@ -1260,7 +1260,7 @@ dropafterack:
 */
if (tiflags & TH_RST)
goto drop;
-   m_freem(m);
+   m_free(m);
tp->t_flags |= TF_ACKNOW;
(void) tcp_output(tp);
return;
diff --git a/slirp/tcp_subr.c b/slirp/tcp_subr.c
index b661d26..61079b1 100644
--- a/slirp/tcp_subr.c
+++ b/slirp/tcp_subr.c
@@ -250,7 +250,7 @@ tcp_close(struct tcpcb *tp)
t = tcpiphdr_next(t);
m = tcpiphdr_prev(t)->ti_mbuf;
remque(tcpiphdr2qlink(tcpiphdr_prev(t)));
-   m_freem(m);
+   m_free(m);
}
 

[Qemu-devel] [PATCH 4/9] ehci doesn't support migration

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/usb-ehci.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index a4758f9..8b0dcc3 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -2244,6 +2244,11 @@ static USBBusOps ehci_bus_ops = {
 .register_companion = ehci_register_companion,
 };
 
+static const VMStateDescription vmstate_ehci = {
+.name = "ehci",
+.unmigratable = 1,
+};
+
 static Property ehci_properties[] = {
 DEFINE_PROP_UINT32("freq",  EHCIState, freq, FRAME_TIMER_FREQ),
 DEFINE_PROP_UINT32("maxframes", EHCIState, maxframes, 128),
@@ -2254,6 +2259,7 @@ static PCIDeviceInfo ehci_info[] = {
 {
 .qdev.name= "usb-ehci",
 .qdev.size= sizeof(EHCIState),
+.qdev.vmsd= &vmstate_ehci,
 .init = usb_ehci_initfn,
 .vendor_id= PCI_VENDOR_ID_INTEL,
 .device_id= PCI_DEVICE_ID_INTEL_82801D, /* ich4 */
@@ -2263,6 +2269,7 @@ static PCIDeviceInfo ehci_info[] = {
 },{
 .qdev.name= "ich9-usb-ehci1",
 .qdev.size= sizeof(EHCIState),
+.qdev.vmsd= &vmstate_ehci,
 .init = usb_ehci_initfn,
 .vendor_id= PCI_VENDOR_ID_INTEL,
 .device_id= PCI_DEVICE_ID_INTEL_82801I_EHCI1,
-- 
1.7.1




[Qemu-devel] [PATCH 08/10] net: Refactor net_client_types

2011-07-20 Thread Jan Kiszka
Position entries of net_client_types according to the corresponding
values of NET_CLIENT_TYPE_*. The array size is now defined by
NET_CLIENT_TYPE_MAX. This will allow to obtain entries based on type
value in later patches.

At this chance rename NET_CLIENT_TYPE_SLIRP to NET_CLIENT_TYPE_USER for
the sake of consistency.

CC: Markus Armbruster 
Signed-off-by: Jan Kiszka 
---
 net.c   |   30 ++
 net.h   |6 --
 net/slirp.c |2 +-
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/net.c b/net.c
index 43627ad..05fc685 100644
--- a/net.c
+++ b/net.c
@@ -830,14 +830,15 @@ static const struct {
 const char *type;
 net_client_init_func init;
 QemuOptDesc desc[NET_MAX_DESC];
-} net_client_types[] = {
-{
+} net_client_types[NET_CLIENT_TYPE_MAX] = {
+[NET_CLIENT_TYPE_NONE] = {
 .type = "none",
 .desc = {
 NET_COMMON_PARAMS_DESC,
 { /* end of list */ }
 },
-}, {
+},
+[NET_CLIENT_TYPE_NIC] = {
 .type = "nic",
 .init = net_init_nic,
 .desc = {
@@ -866,8 +867,9 @@ static const struct {
 },
 { /* end of list */ }
 },
+},
 #ifdef CONFIG_SLIRP
-}, {
+[NET_CLIENT_TYPE_USER] = {
 .type = "user",
 .init = net_init_slirp,
 .desc = {
@@ -927,8 +929,9 @@ static const struct {
 },
 { /* end of list */ }
 },
+},
 #endif
-}, {
+[NET_CLIENT_TYPE_TAP] = {
 .type = "tap",
 .init = net_init_tap,
 .desc = {
@@ -975,7 +978,8 @@ static const struct {
 #endif /* _WIN32 */
 { /* end of list */ }
 },
-}, {
+},
+[NET_CLIENT_TYPE_SOCKET] = {
 .type = "socket",
 .init = net_init_socket,
 .desc = {
@@ -1003,8 +1007,9 @@ static const struct {
 },
 { /* end of list */ }
 },
+},
 #ifdef CONFIG_VDE
-}, {
+[NET_CLIENT_TYPE_VDE] = {
 .type = "vde",
 .init = net_init_vde,
 .desc = {
@@ -1028,8 +1033,9 @@ static const struct {
 },
 { /* end of list */ }
 },
+},
 #endif
-}, {
+[NET_CLIENT_TYPE_DUMP] = {
 .type = "dump",
 .init = net_init_dump,
 .desc = {
@@ -1046,7 +1052,6 @@ static const struct {
 { /* end of list */ }
 },
 },
-{ /* end of list */ }
 };
 
 int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
@@ -1094,8 +1099,9 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int 
is_netdev)
 name = qemu_opt_get(opts, "name");
 }
 
-for (i = 0; net_client_types[i].type != NULL; i++) {
-if (!strcmp(net_client_types[i].type, type)) {
+for (i = 0; i < NET_CLIENT_TYPE_MAX; i++) {
+if (net_client_types[i].type != NULL &&
+!strcmp(net_client_types[i].type, type)) {
 VLANState *vlan = NULL;
 int ret;
 
@@ -1330,7 +1336,7 @@ void net_check_clients(void)
 case NET_CLIENT_TYPE_NIC:
 has_nic = 1;
 break;
-case NET_CLIENT_TYPE_SLIRP:
+case NET_CLIENT_TYPE_USER:
 case NET_CLIENT_TYPE_TAP:
 case NET_CLIENT_TYPE_SOCKET:
 case NET_CLIENT_TYPE_VDE:
diff --git a/net.h b/net.h
index 5b883a9..4fdd942 100644
--- a/net.h
+++ b/net.h
@@ -31,11 +31,13 @@ typedef struct NICConf {
 typedef enum {
 NET_CLIENT_TYPE_NONE,
 NET_CLIENT_TYPE_NIC,
-NET_CLIENT_TYPE_SLIRP,
+NET_CLIENT_TYPE_USER,
 NET_CLIENT_TYPE_TAP,
 NET_CLIENT_TYPE_SOCKET,
 NET_CLIENT_TYPE_VDE,
-NET_CLIENT_TYPE_DUMP
+NET_CLIENT_TYPE_DUMP,
+
+NET_CLIENT_TYPE_MAX
 } net_client_type;
 
 typedef void (NetPoll)(VLANClientState *, bool enable);
diff --git a/net/slirp.c b/net/slirp.c
index 71e2577..157b80a 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -128,7 +128,7 @@ static void net_slirp_cleanup(VLANClientState *nc)
 }
 
 static NetClientInfo net_slirp_info = {
-.type = NET_CLIENT_TYPE_SLIRP,
+.type = NET_CLIENT_TYPE_USER,
 .size = sizeof(SlirpState),
 .receive = net_slirp_receive,
 .cleanup = net_slirp_cleanup,
-- 
1.7.3.4




[Qemu-devel] [PATCH 09/10] net: Dump client type 'info network'

2011-07-20 Thread Jan Kiszka
Include the client type name into the output of 'info network'. The
result looks like this:

(qemu) info network
VLAN 0 devices:
  rtl8139.0: type=nic,model=rtl8139,macaddr=52:54:00:12:34:57
Devices not on any VLAN:
  virtio-net-pci.0: type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:56
   \ network1: type=tap,fd=5

CC: Markus Armbruster 
Signed-off-by: Jan Kiszka 
---
 net.c |   15 ---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/net.c b/net.c
index 05fc685..12701af 100644
--- a/net.c
+++ b/net.c
@@ -1227,6 +1227,12 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 return 0;
 }
 
+static void print_net_client(Monitor *mon, VLANClientState *vc)
+{
+monitor_printf(mon, "%s: type=%s,%s\n", vc->name,
+   net_client_types[vc->info->type].type, vc->info_str);
+}
+
 void do_info_network(Monitor *mon)
 {
 VLANState *vlan;
@@ -1237,7 +1243,8 @@ void do_info_network(Monitor *mon)
 monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
 
 QTAILQ_FOREACH(vc, &vlan->clients, next) {
-monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+monitor_printf(mon, "  ");
+print_net_client(mon, vc);
 }
 }
 monitor_printf(mon, "Devices not on any VLAN:\n");
@@ -1245,10 +1252,12 @@ void do_info_network(Monitor *mon)
 peer = vc->peer;
 type = vc->info->type;
 if (!peer || type == NET_CLIENT_TYPE_NIC) {
-monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+monitor_printf(mon, "  ");
+print_net_client(mon, vc);
 } /* else it's a netdev connected to a NIC, printed with the NIC */
 if (peer && type == NET_CLIENT_TYPE_NIC) {
-monitor_printf(mon, "   \\ %s: %s\n", peer->name, peer->info_str);
+monitor_printf(mon, "   \\ ");
+print_net_client(mon, peer);
 }
 }
 }
-- 
1.7.3.4




[Qemu-devel] [libvirt] Re: live snapshot wiki updated

2011-07-20 Thread Nicolas Sebrecht
The 20/07/11, Daniel P. Berrange wrote:

> To make the decision whether the filename from QEMU is valid, we have
> to parse the master image header data to see if the filename actually
> matches the backing file required by the image assigned to the guest.

Actually, libvirt should not have to worry if the filename provided by
QEMU is valid. I think it should trust QEMU. If QEMU doesn't provide
information others can trust; it should be fixed at QEMU side.

> We're not fighting over the internals of metadata. We just need to know
> ahead of launching QEMU, what backing files an image has & what format
> they are in. We do that by reading at the metadata headers of the disk
> images. We never attempt to write to the disk images. Either someone
> provides a library todo that, or we write the probing code for each
> file format in libvirt. Currently we have the latter.

This is what I would call "fighting with QEMU internals". How do you
prevent from concurrency access and modifications? Ideally speacking
libvirt should be able to co-exist with foreign implementations, all
requesting QEMU.

-- 
Nicolas Sebrecht



[Qemu-devel] [PATCH 10/10] net: Consistently use qemu_macaddr_default_if_unset

2011-07-20 Thread Jan Kiszka
Drop the open-coded MAC assignment from net_init_nic and replace it with
standard qemu_macaddr_default_if_unset which is also used by qdev. That
avoid creating colliding MACs when instantiating NICs via different
mechanisms.

This change requires to store the MAC as MACAddr in NICInfo, and the
remaining nd_table users need to be updated.

Based on suggestion by Peter Maydell.

CC: Markus Armbruster 
CC: Peter Maydell 
Signed-off-by: Jan Kiszka 
---
 hw/dp8393x.c   |2 +-
 hw/etraxfs_eth.c   |2 +-
 hw/mcf_fec.c   |2 +-
 hw/mipsnet.c   |2 +-
 hw/qdev.c  |2 +-
 hw/stellaris.c |2 +-
 hw/xen_devconfig.c |4 ++--
 net.c  |   10 ++
 net.h  |2 +-
 9 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/hw/dp8393x.c b/hw/dp8393x.c
index c332dd5..1bcd8ee 100644
--- a/hw/dp8393x.c
+++ b/hw/dp8393x.c
@@ -898,7 +898,7 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int 
it_shift,
 s->watchdog = qemu_new_timer_ns(vm_clock, dp8393x_watchdog, s);
 s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
 
-memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(s->conf.macaddr));
+s->conf.macaddr = nd->macaddr;
 s->conf.vlan = nd->vlan;
 s->conf.peer = nd->netdev;
 
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 6aa4007..dff5f55 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -602,7 +602,7 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t 
base, int phyaddr)
   DEVICE_NATIVE_ENDIAN);
cpu_register_physical_memory (base, 0x5c, eth->ethregs);
 
-   memcpy(eth->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+   eth->conf.macaddr = nd->macaddr;
eth->conf.vlan = nd->vlan;
eth->conf.peer = nd->netdev;
 
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 21035da..5477e0e 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -471,7 +471,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, 
qemu_irq *irq)
DEVICE_NATIVE_ENDIAN);
 cpu_register_physical_memory(base, 0x400, s->mmio_index);
 
-memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+s->conf.macaddr = nd->macaddr;
 s->conf.vlan = nd->vlan;
 s->conf.peer = nd->netdev;
 
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 26aad51..0db3ba7 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -258,7 +258,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
 s->irq = irq;
 
 if (nd) {
-memcpy(s->conf.macaddr.a, nd->macaddr, sizeof(nd->macaddr));
+s->conf.macaddr = nd->macaddr;
 s->conf.vlan = nd->vlan;
 s->conf.peer = nd->netdev;
 
diff --git a/hw/qdev.c b/hw/qdev.c
index 292b52f..a0fcd06 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -459,7 +459,7 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, 
qemu_irq pin)
 
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
-qdev_prop_set_macaddr(dev, "mac", nd->macaddr);
+qdev_prop_set_macaddr(dev, "mac", nd->macaddr.a);
 if (nd->vlan)
 qdev_prop_set_vlan(dev, "vlan", nd->vlan);
 if (nd->netdev)
diff --git a/hw/stellaris.c b/hw/stellaris.c
index ac9fcc1..b8a7ceb 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -1230,7 +1230,7 @@ static void stellaris_init(const char *kernel_filename, 
const char *cpu_model,
 }
 }
 
-stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr);
+stellaris_sys_init(0x400fe000, pic[28], board, nd_table[0].macaddr.a);
 
 for (i = 0; i < 7; i++) {
 if (board->dc4 & (1 << i)) {
diff --git a/hw/xen_devconfig.c b/hw/xen_devconfig.c
index 3a92155..6926c54 100644
--- a/hw/xen_devconfig.c
+++ b/hw/xen_devconfig.c
@@ -126,8 +126,8 @@ int xen_config_dev_nic(NICInfo *nic)
 char mac[20];
 
 snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
-nic->macaddr[0], nic->macaddr[1], nic->macaddr[2],
-nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]);
+ nic->macaddr.a[0], nic->macaddr.a[1], nic->macaddr.a[2],
+ nic->macaddr.a[3], nic->macaddr.a[4], nic->macaddr.a[5]);
 xen_be_printf(NULL, 1, "config nic %d: mac=\"%s\"\n", nic->vlan->id, mac);
 xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe));
 
diff --git a/net.c b/net.c
index 12701af..31c2338 100644
--- a/net.c
+++ b/net.c
@@ -776,18 +776,12 @@ static int net_init_nic(QemuOpts *opts,
 nd->devaddr = qemu_strdup(qemu_opt_get(opts, "addr"));
 }
 
-nd->macaddr[0] = 0x52;
-nd->macaddr[1] = 0x54;
-nd->macaddr[2] = 0x00;
-nd->macaddr[3] = 0x12;
-nd->macaddr[4] = 0x34;
-nd->macaddr[5] = 0x56 + idx;
-
 if (qemu_opt_get(opts, "macaddr") &&
-net_parse_macaddr(nd->macaddr, qemu_opt_get(opts, "macaddr")) < 0) {
+net_parse_macaddr(nd->macaddr.a, qemu_opt_get(opts, "macaddr")) < 0) {
 error_report("invalid syntax for eth

[Qemu-devel] [PATCH 2/2] usb-uhci: fix irq handling on error.

2011-07-20 Thread Gerd Hoffmann
Spec on UHCI_STS_USBERR: "If the TD on which the error interrupt
occurred also had its IOC bit set, both this bit and Bit 0 are set."

Make UHCI emulation do that.

Signed-off-by: Gerd Hoffmann 
---
 hw/usb-uhci.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 2ef4c5b..da74c57 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -730,6 +730,9 @@ out:
 td->ctrl |= TD_CTRL_STALL;
 td->ctrl &= ~TD_CTRL_ACTIVE;
 s->status |= UHCI_STS_USBERR;
+if (td->ctrl & TD_CTRL_IOC) {
+*int_mask |= 0x01;
+}
 uhci_update_irq(s);
 return 1;
 
@@ -737,6 +740,9 @@ out:
 td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL;
 td->ctrl &= ~TD_CTRL_ACTIVE;
 s->status |= UHCI_STS_USBERR;
+if (td->ctrl & TD_CTRL_IOC) {
+*int_mask |= 0x01;
+}
 uhci_update_irq(s);
 /* frame interrupted */
 return -1;
-- 
1.7.1




[Qemu-devel] [PATCH 2/9] vmstate: complain about devices without vmstate

2011-07-20 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 hw/hw.h   |2 ++
 hw/qdev.c |7 ++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index df6ca65..d839af1 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -336,6 +336,8 @@ struct VMStateDescription {
 const VMStateSubsection *subsections;
 };
 
+#define VMSD_NONE ((const VMStateDescription*)1)
+
 extern const VMStateInfo vmstate_info_bool;
 
 extern const VMStateInfo vmstate_info_int8;
diff --git a/hw/qdev.c b/hw/qdev.c
index 292b52f..fafbbae 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -283,7 +283,12 @@ int qdev_init(DeviceState *dev)
 qdev_free(dev);
 return rc;
 }
-if (dev->info->vmsd) {
+if (dev->info->vmsd == NULL) {
+/* TODO: fixup qemu source code, then make this an assert() */
+error_report("WARNING: device %s has no vmstate\n", dev->info->name);
+} else if (dev->info->vmsd == VMSD_NONE) {
+/* device doesn't need vmstate */;
+} else {
 vmstate_register_with_alias_id(dev, -1, dev->info->vmsd, dev,
dev->instance_id_alias,
dev->alias_required_for_version);
-- 
1.7.1




[Qemu-devel] [PATCH 07/10] net: Improve layout of 'info network'

2011-07-20 Thread Jan Kiszka
Improve the layout when listing non-vlan clients via 'info network'. The
result looks like this:

(qemu) info network
Devices not on any VLAN:
  orphan: net=10.0.2.0, restricted=n
  virtio-net-pci.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56
   \ network2: fd=5
  e1000.0: model=e1000,macaddr=52:54:00:12:34:57
   \ network1: net=10.0.2.0, restricted=n
  rtl8139.0: model=rtl8139,macaddr=52:54:00:12:34:58

ie. peers are grouped, orphans are listed as before.

CC: Markus Armbruster 
Signed-off-by: Jan Kiszka 
---
 net.c |   14 +-
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/net.c b/net.c
index 66123ad..43627ad 100644
--- a/net.c
+++ b/net.c
@@ -1224,7 +1224,8 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 void do_info_network(Monitor *mon)
 {
 VLANState *vlan;
-VLANClientState *vc;
+VLANClientState *vc, *peer;
+net_client_type type;
 
 QTAILQ_FOREACH(vlan, &vlans, next) {
 monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
@@ -1235,11 +1236,14 @@ void do_info_network(Monitor *mon)
 }
 monitor_printf(mon, "Devices not on any VLAN:\n");
 QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
-monitor_printf(mon, "  %s: %s", vc->name, vc->info_str);
-if (vc->peer) {
-monitor_printf(mon, " peer=%s", vc->peer->name);
+peer = vc->peer;
+type = vc->info->type;
+if (!peer || type == NET_CLIENT_TYPE_NIC) {
+monitor_printf(mon, "  %s: %s\n", vc->name, vc->info_str);
+} /* else it's a netdev connected to a NIC, printed with the NIC */
+if (peer && type == NET_CLIENT_TYPE_NIC) {
+monitor_printf(mon, "   \\ %s: %s\n", peer->name, peer->info_str);
 }
-monitor_printf(mon, "\n");
 }
 }
 
-- 
1.7.3.4




[Qemu-devel] [PATCH 06/10] slirp: Forward ICMP echo requests via unprivileged sockets

2011-07-20 Thread Jan Kiszka
Linux 3.0 gained support for unprivileged ICMP ping sockets. Use this
feature to forward guest pings to the outer world. The host admin has to
set the ping_group_range in order to grant access to those sockets. To
allow ping for the users group (GID 100):

echo 100 100 > /proc/sys/net/ipv4/ping_group_range

Signed-off-by: Jan Kiszka 
---
 slirp/ip_icmp.c  |   87 +-
 slirp/ip_icmp.h  |3 ++
 slirp/ip_input.c |1 +
 slirp/misc.c |   13 
 slirp/slirp.c|   37 +++
 slirp/slirp.h|5 +++
 slirp/socket.c   |2 +
 7 files changed, 147 insertions(+), 1 deletions(-)

diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c
index 4f10826..14a5312 100644
--- a/slirp/ip_icmp.c
+++ b/slirp/ip_icmp.c
@@ -60,6 +60,52 @@ static const int icmp_flush[19] = {
 /* ADDR MASK REPLY (18) */ 0
 };
 
+void icmp_init(Slirp *slirp)
+{
+slirp->icmp.so_next = slirp->icmp.so_prev = &slirp->icmp;
+slirp->icmp_last_so = &slirp->icmp;
+}
+
+static int icmp_send(struct socket *so, struct mbuf *m, int hlen)
+{
+struct ip *ip = mtod(m, struct ip *);
+struct sockaddr_in addr;
+
+so->s = qemu_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
+if (so->s == -1) {
+return -1;
+}
+
+so->so_m = m;
+so->so_faddr = ip->ip_dst;
+so->so_laddr = ip->ip_src;
+so->so_iptos = ip->ip_tos;
+so->so_type = IPPROTO_ICMP;
+so->so_state = SS_ISFCONNECTED;
+so->so_expire = curtime + SO_EXPIRE;
+
+addr.sin_family = AF_INET;
+addr.sin_addr = so->so_faddr;
+
+insque(so, &so->slirp->icmp);
+
+if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0,
+   (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+DEBUG_MISC((dfd, "icmp_input icmp sendto tx errno = %d-%s\n",
+errno, strerror(errno)));
+icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno));
+icmp_detach(so);
+}
+
+return 0;
+}
+
+void icmp_detach(struct socket *so)
+{
+closesocket(so->s);
+sofree(so);
+}
+
 /*
  * Process a received ICMP message.
  */
@@ -97,7 +143,6 @@ icmp_input(struct mbuf *m, int hlen)
   DEBUG_ARG("icmp_type = %d", icp->icmp_type);
   switch (icp->icmp_type) {
   case ICMP_ECHO:
-icp->icmp_type = ICMP_ECHOREPLY;
 ip->ip_len += hlen; /* since ip_input subtracts this */
 if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) {
   icmp_reflect(m);
@@ -107,6 +152,9 @@ icmp_input(struct mbuf *m, int hlen)
   struct socket *so;
   struct sockaddr_in addr;
   if ((so = socreate(slirp)) == NULL) goto freeit;
+  if (icmp_send(so, m, hlen) == 0) {
+return;
+  }
   if(udp_attach(so) == -1) {
DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n",
errno,strerror(errno)));
@@ -321,6 +369,7 @@ icmp_reflect(struct mbuf *m)
   m->m_len -= hlen;
   icp = mtod(m, struct icmp *);
 
+  icp->icmp_type = ICMP_ECHOREPLY;
   icp->icmp_cksum = 0;
   icp->icmp_cksum = cksum(m, ip->ip_len - hlen);
 
@@ -351,3 +400,39 @@ icmp_reflect(struct mbuf *m)
 
   (void ) ip_output((struct socket *)NULL, m);
 }
+
+void icmp_receive(struct socket *so)
+{
+struct mbuf *m = so->so_m;
+struct ip *ip = mtod(m, struct ip *);
+int hlen = ip->ip_hl << 2;
+u_char error_code;
+struct icmp *icp;
+int id, len;
+
+m->m_data += hlen;
+m->m_len -= hlen;
+icp = mtod(m, struct icmp *);
+
+id = icp->icmp_id;
+len = recv(so->s, icp, m->m_len, 0);
+icp->icmp_id = id;
+
+m->m_data -= hlen;
+m->m_len += hlen;
+
+if (len == -1 || len == 0) {
+if (errno == ENETUNREACH) {
+error_code = ICMP_UNREACH_NET;
+} else {
+error_code = ICMP_UNREACH_HOST;
+}
+DEBUG_MISC((dfd, " udp icmp rx errno = %d-%s\n", errno,
+strerror(errno)));
+icmp_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno));
+} else {
+icmp_reflect(so->so_m);
+so->so_m = NULL; /* Don't m_free() it again! */
+}
+icmp_detach(so);
+}
diff --git a/slirp/ip_icmp.h b/slirp/ip_icmp.h
index 2692822..b3da1f2 100644
--- a/slirp/ip_icmp.h
+++ b/slirp/ip_icmp.h
@@ -153,9 +153,12 @@ struct icmp {
(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
 
+void icmp_init(Slirp *slirp);
 void icmp_input(struct mbuf *, int);
 void icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
 const char *message);
 void icmp_reflect(struct mbuf *);
+void icmp_receive(struct socket *so);
+void icmp_detach(struct socket *so);
 
 #endif
diff --git a/slirp/ip_input.c b/slirp/ip_input.c
index 46c60b0..5e67631 100644
--- a/slirp/ip_input.c
+++ b/slirp/ip_input.c
@@ -58,6 +58,7 @@ ip_init(Slirp *slirp)
 slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link;
 udp_init(slirp);
 tcp_init(slirp);

[Qemu-devel] [PULL] usb patch queue

2011-07-20 Thread Gerd Hoffmann
  Hi,

Tiny usb patch queue with two small fixes.

please pull for 0.15,
  Gerd

The following changes since commit 03ff09580ef6cbc4a893b6e3e6bbff33180ec70a:

  Merge remote-tracking branch 'agraf/xen-next' into staging (2011-07-19 
08:04:35 -0500)

are available in the git repository at:

  git://git.kraxel.org/qemu usb.20

Gerd Hoffmann (2):
  usb-hid: fixup changed tracking.
  usb-uhci: fix irq handling on error.

 hw/usb-hid.c  |9 -
 hw/usb-uhci.c |6 ++
 2 files changed, 10 insertions(+), 5 deletions(-)



[Qemu-devel] [PATCH 1/9] vmstate: add no_migrate flag to VMStateDescription

2011-07-20 Thread Gerd Hoffmann
This allows to easily tag devices as non-migratable,
so any attempt to migrate a virtual machine with the
device in question active will make migration fail.

Signed-off-by: Gerd Hoffmann 
---
 hw/hw.h  |1 +
 savevm.c |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 9dd7096..df6ca65 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -324,6 +324,7 @@ typedef struct VMStateSubsection {
 
 struct VMStateDescription {
 const char *name;
+int unmigratable;
 int version_id;
 int minimum_version_id;
 int minimum_version_id_old;
diff --git a/savevm.c b/savevm.c
index 8139bc7..1c5abe2 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1234,6 +1234,7 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
instance_id,
 se->opaque = opaque;
 se->vmsd = vmsd;
 se->alias_id = alias_id;
+se->no_migrate = vmsd->unmigratable;
 
 if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) {
 char *id = dev->parent_bus->info->get_dev_path(dev);
-- 
1.7.1




[Qemu-devel] [PATCH 03/10] slirp: Strictly associate DHCP/BOOTP and TFTP with virtual host

2011-07-20 Thread Jan Kiszka
Instead of accepting every DHCP/BOOTP and TFTP packet, only invoke the
built-in servers if the target is the virtual host.

Signed-off-by: Jan Kiszka 
---
 slirp/udp.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/slirp/udp.c b/slirp/udp.c
index f1a9a10..cefd50b 100644
--- a/slirp/udp.c
+++ b/slirp/udp.c
@@ -120,15 +120,18 @@ udp_input(register struct mbuf *m, int iphlen)
 /*
  *  handle DHCP/BOOTP
  */
-if (ntohs(uh->uh_dport) == BOOTP_SERVER) {
-bootp_input(m);
-goto bad;
-}
+if (ntohs(uh->uh_dport) == BOOTP_SERVER &&
+(ip->ip_dst.s_addr == slirp->vhost_addr.s_addr ||
+ ip->ip_dst.s_addr == 0x)) {
+bootp_input(m);
+goto bad;
+}
 
 /*
  *  handle TFTP
  */
-if (ntohs(uh->uh_dport) == TFTP_SERVER) {
+if (ntohs(uh->uh_dport) == TFTP_SERVER &&
+ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) {
 tftp_input(m);
 goto bad;
 }
-- 
1.7.3.4




[Qemu-devel] [PATCH 1/2] usb-hid: fixup changed tracking.

2011-07-20 Thread Gerd Hoffmann
Remove leftover calls to usb_hid_changed().

Take care to update the changed flag after delivering a event via
GET_REPORT like we do when sending events via interrupt endpoint.

Signed-off-by: Gerd Hoffmann 
---
 hw/usb-hid.c |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index d711b5c..b812da2 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -531,18 +531,15 @@ static void usb_keyboard_process_keycode(USBHIDState *hs)
 case 0xe0:
 if (s->modifiers & (1 << 9)) {
 s->modifiers ^= 3 << 8;
-usb_hid_changed(hs);
 return;
 }
 case 0xe1 ... 0xe7:
 if (keycode & (1 << 7)) {
 s->modifiers &= ~(1 << (hid_code & 0x0f));
-usb_hid_changed(hs);
 return;
 }
 case 0xe8 ... 0xef:
 s->modifiers |= 1 << (hid_code & 0x0f);
-usb_hid_changed(hs);
 return;
 }
 
@@ -769,10 +766,12 @@ static int usb_hid_handle_control(USBDevice *dev, 
USBPacket *p,
 }
 break;
 case GET_REPORT:
-if (s->kind == USB_MOUSE || s->kind == USB_TABLET)
+if (s->kind == USB_MOUSE || s->kind == USB_TABLET) {
 ret = usb_pointer_poll(s, data, length);
-else if (s->kind == USB_KEYBOARD)
+} else if (s->kind == USB_KEYBOARD) {
 ret = usb_keyboard_poll(s, data, length);
+}
+s->changed = s->n > 0;
 break;
 case SET_REPORT:
 if (s->kind == USB_KEYBOARD)
-- 
1.7.1




[Qemu-devel] [PATCH 4/6] exec.c: Use ram_addr_t in cpu_physical_memory_rw(...).

2011-07-20 Thread Alexander Graf
From: Anthony PERARD 

As the variable pd and addr1 inside the function cpu_physical_memory_rw
are mean to handle a RAM address, they should be of the ram_addr_t type
instead of unsigned long.

Signed-off-by: Anthony PERARD 
Acked-by: Paolo Bonzini 
Signed-off-by: Alexander Graf 
---
 exec.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index 8277900..8ef290e 100644
--- a/exec.c
+++ b/exec.c
@@ -3858,7 +3858,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, 
uint8_t *buf,
 uint8_t *ptr;
 uint32_t val;
 target_phys_addr_t page;
-unsigned long pd;
+ram_addr_t pd;
 PhysPageDesc *p;
 
 while (len > 0) {
@@ -3898,7 +3898,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, 
uint8_t *buf,
 l = 1;
 }
 } else {
-unsigned long addr1;
+ram_addr_t addr1;
 addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
 /* RAM case */
 ptr = qemu_get_ram_ptr(addr1);
-- 
1.6.0.2




[Qemu-devel] [PULL] non-migratable devices

2011-07-20 Thread Gerd Hoffmann
  Hi,

This patch series adds an easy way to tag devices as non-migratable
and puts it into use for ahci, ehci and a number of usb devices.

cheers,
  Gerd

The following changes since commit 03ff09580ef6cbc4a893b6e3e6bbff33180ec70a:

  Merge remote-tracking branch 'agraf/xen-next' into staging (2011-07-19 
08:04:35 -0500)

are available in the git repository at:

  git://git.kraxel.org/qemu migration.1

Gerd Hoffmann (9):
  vmstate: add no_migrate flag to VMStateDescription
  vmstate: complain about devices without vmstate
  ahci doesn't support migration
  ehci doesn't support migration
  usb storage: first migration support bits.
  usb-wacom doesn't support migration
  usb-bt doesn't support migration
  usb-net doesn't support migration
  usb-serial doesn't support migration

 hw/hw.h |3 +++
 hw/ide/ich.c|6 ++
 hw/qdev.c   |7 ++-
 hw/usb-bt.c |6 ++
 hw/usb-ehci.c   |7 +++
 hw/usb-msd.c|   12 
 hw/usb-net.c|6 ++
 hw/usb-serial.c |7 +++
 hw/usb-wacom.c  |6 ++
 savevm.c|1 +
 10 files changed, 60 insertions(+), 1 deletions(-)



[Qemu-devel] [PATCH 00/10] [RESEND] Various net and slirp fixes & enhancements

2011-07-20 Thread Jan Kiszka
Almost just a reposting of the previously sent series. No patch
modified, but a nifty (IMO) new one: ping forwarding for slirp using
the unprivileged ICMP sockets of Linux 3.0. See commit log for a simple
how-to.

CC: Gleb Natapov 
CC: Markus Armbruster 
CC: Peter Maydell 

Jan Kiszka (10):
  slirp: Fix restricted mode
  slirp: Canonicalize restrict syntax
  slirp: Strictly associate DHCP/BOOTP and TFTP with virtual host
  slirp: Replace m_freem with m_free
  slirp: Put forked exec into separate process group
  slirp: Forward ICMP echo requests via unprivileged sockets
  net: Improve layout of 'info network'
  net: Refactor net_client_types
  net: Dump client type 'info network'
  net: Consistently use qemu_macaddr_default_if_unset

 hw/dp8393x.c   |2 +-
 hw/etraxfs_eth.c   |2 +-
 hw/mcf_fec.c   |2 +-
 hw/mipsnet.c   |2 +-
 hw/qdev.c  |2 +-
 hw/stellaris.c |2 +-
 hw/xen_devconfig.c |4 +-
 net.c  |   65 +--
 net.h  |8 +++--
 net/slirp.c|   23 +
 qemu-options.hx|4 +-
 slirp/ip_icmp.c|   95 +--
 slirp/ip_icmp.h|3 ++
 slirp/ip_input.c   |   30 +++--
 slirp/ip_output.c  |4 +-
 slirp/mbuf.h   |3 --
 slirp/misc.c   |   16 -
 slirp/slirp.c  |   37 
 slirp/slirp.h  |5 +++
 slirp/socket.c |2 +
 slirp/tcp_input.c  |   10 +++---
 slirp/tcp_subr.c   |2 +-
 slirp/udp.c|   23 +++-
 23 files changed, 249 insertions(+), 97 deletions(-)

-- 
1.7.3.4




[Qemu-devel] [PATCH 0/6] Xen patch queue 2011-07-20

2011-07-20 Thread Alexander Graf
Hi Anthony,

This is my current patch queue for Xen stuff that fixes even more regressions
introduced by recent Xen patches. I hope this time we're regression-free.

Please pull.

Alex

The following changes since commit 03ff09580ef6cbc4a893b6e3e6bbff33180ec70a:
  Anthony Liguori (1):
Merge remote-tracking branch 'agraf/xen-next' into staging

are available in the git repository at:

  git://repo.or.cz/qemu/agraf.git xen-next

Alexander Graf (3):
  xen: add mapcache stubs
  xen: remove CONFIG_XEN_MAPCACHE
  xen: make xen_enabled even more clever

Anthony PERARD (3):
  xen: introduce xen_change_state_handler
  xen: Fix xen_enabled().
  exec.c: Use ram_addr_t in cpu_physical_memory_rw(...).

 configure  |8 +---
 exec.c |4 ++--
 hw/xen.h   |2 +-
 xen-all.c  |   25 ++---
 xen-stub.c |   26 ++
 5 files changed, 52 insertions(+), 13 deletions(-)




Re: [Qemu-devel] [libvirt] Re: live snapshot wiki updated

2011-07-20 Thread Daniel P. Berrange
On Wed, Jul 20, 2011 at 12:15:02PM +0200, Nicolas Sebrecht wrote:
> The 20/07/11, Daniel P. Berrange wrote:
> 
> > To make the decision whether the filename from QEMU is valid, we have
> > to parse the master image header data to see if the filename actually
> > matches the backing file required by the image assigned to the guest.
> 
> Actually, libvirt should not have to worry if the filename provided by
> QEMU is valid. I think it should trust QEMU. If QEMU doesn't provide
> information others can trust; it should be fixed at QEMU side.

The security goal of libvirt is to protect the host from a compromised
QEMU, therefore QEMU is, by definition, untrusted.

> > We're not fighting over the internals of metadata. We just need to know
> > ahead of launching QEMU, what backing files an image has & what format
> > they are in. We do that by reading at the metadata headers of the disk
> > images. We never attempt to write to the disk images. Either someone
> > provides a library todo that, or we write the probing code for each
> > file format in libvirt. Currently we have the latter.
> 
> This is what I would call "fighting with QEMU internals". How do you
> prevent from concurrency access and modifications? Ideally speacking
> libvirt should be able to co-exist with foreign implementations, all
> requesting QEMU.

QEMU is *not* yet running at the time libvirt reads the file metadata.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH 02/10] slirp: Canonicalize restrict syntax

2011-07-20 Thread Jan Kiszka
All other boolean arguments accept on|off - except for slirp's restrict.
Fix that while still accepting the formerly allowed yes|y|no|n, but
reject everything else. This avoids accidentally allowing external
connections because syntax errors were so far interpreted as
'restrict=no'.

CC: Gleb Natapov 
Signed-off-by: Jan Kiszka 
---
 net/slirp.c |   21 +++--
 qemu-options.hx |4 ++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/net/slirp.c b/net/slirp.c
index e057a14..71e2577 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -240,7 +240,8 @@ static int net_slirp_init(VLANState *vlan, const char 
*model,
 nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name);
 
 snprintf(nc->info_str, sizeof(nc->info_str),
- "net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
+ "net=%s,restrict=%s", inet_ntoa(net),
+ restricted ? "on" : "off");
 
 s = DO_UPCAST(SlirpState, nc, nc);
 
@@ -689,6 +690,7 @@ int net_init_slirp(QemuOpts *opts,
 const char *bootfile;
 const char *smb_export;
 const char *vsmbsrv;
+const char *restrict_opt;
 char *vnet = NULL;
 int restricted = 0;
 int ret;
@@ -702,6 +704,18 @@ int net_init_slirp(QemuOpts *opts,
 smb_export  = qemu_opt_get(opts, "smb");
 vsmbsrv = qemu_opt_get(opts, "smbserver");
 
+restrict_opt = qemu_opt_get(opts, "restrict");
+if (restrict_opt) {
+if (!strcmp(restrict_opt, "on") ||
+!strcmp(restrict_opt, "yes") || !strcmp(restrict_opt, "y")) {
+restricted = 1;
+} else if (strcmp(restrict_opt, "off") &&
+strcmp(restrict_opt, "no") && strcmp(restrict_opt, "n")) {
+error_report("invalid option: 'restrict=%s'", restrict_opt);
+return -1;
+}
+}
+
 if (qemu_opt_get(opts, "ip")) {
 const char *ip = qemu_opt_get(opts, "ip");
 int l = strlen(ip) + strlen("/24") + 1;
@@ -720,11 +734,6 @@ int net_init_slirp(QemuOpts *opts,
 vnet = qemu_strdup(qemu_opt_get(opts, "net"));
 }
 
-if (qemu_opt_get(opts, "restrict") &&
-qemu_opt_get(opts, "restrict")[0] == 'y') {
-restricted = 1;
-}
-
 qemu_opt_foreach(opts, net_init_slirp_configs, NULL, 0);
 
 ret = net_slirp_init(vlan, "user", name, restricted, vnet, vhost,
diff --git a/qemu-options.hx b/qemu-options.hx
index e6d7adc..0f58e27 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1092,7 +1092,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
 "-net 
nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n"
 "create a new Network Interface Card and connect it to 
VLAN 'n'\n"
 #ifdef CONFIG_SLIRP
-"-net 
user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=y|n]\n"
+"-net 
user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off]\n"
 " 
[,hostname=host][,dhcpstart=addr][,dns=addr][,tftp=dir][,bootfile=f]\n"
 " [,hostfwd=rule][,guestfwd=rule]"
 #ifndef _WIN32
@@ -1185,7 +1185,7 @@ either in the form a.b.c.d or as number of valid top-most 
bits. Default is
 Specify the guest-visible address of the host. Default is the 2nd IP in the
 guest network, i.e. x.x.x.2.
 
-@item restrict=y|yes|n|no
+@item restrict=on|off
 If this option is enabled, the guest will be isolated, i.e. it will not be
 able to contact the host and no guest IP packets will be routed over the host
 to the outside. This option does not affect any explicitly set forwarding 
rules.
-- 
1.7.3.4




[Qemu-devel] [PATCH 3/6] xen: Fix xen_enabled().

2011-07-20 Thread Alexander Graf
From: Anthony PERARD 

Use the "host" CONFIG_ define instead of the "target" one.

Signed-off-by: Anthony PERARD 
Acked-by: Paolo Bonzini 
Signed-off-by: Alexander Graf 
---
 hw/xen.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/xen.h b/hw/xen.h
index e432705..43b95d6 100644
--- a/hw/xen.h
+++ b/hw/xen.h
@@ -24,7 +24,7 @@ extern int xen_allowed;
 
 static inline int xen_enabled(void)
 {
-#ifdef CONFIG_XEN
+#ifdef CONFIG_XEN_BACKEND
 return xen_allowed;
 #else
 return 0;
-- 
1.6.0.2




[Qemu-devel] [PULL] spice patch queue

2011-07-20 Thread Gerd Hoffmann
  Hi,

Two small spice fixes for 0.15.

please pull,
  Gerd

The following changes since commit 03ff09580ef6cbc4a893b6e3e6bbff33180ec70a:

  Merge remote-tracking branch 'agraf/xen-next' into staging (2011-07-19 
08:04:35 -0500)

are available in the git repository at:

  git://anongit.freedesktop.org/spice/qemu spice.v39

Gerd Hoffmann (1):
  spice: add sanity check for spice ports

Yonit Halperin (1):
  qxl: upon reset, if spice worker is stopped, the command rings can be not 
empty

 hw/qxl.c|4 ++--
 ui/spice-core.c |   11 ++-
 2 files changed, 12 insertions(+), 3 deletions(-)



[Qemu-devel] [PATCH 1/6] xen: introduce xen_change_state_handler

2011-07-20 Thread Alexander Graf
From: Anthony PERARD 

Remove the call to xenstore_record_dm_state from xen_main_loop_prepare
that is HVM specific.
Add a new vm_change_state_handler shared between xen_pv and xen_hvm
machines to record the VM state to xenstore.

Signed-off-by: Anthony PERARD 
Signed-off-by: Stefano Stabellini 
Signed-off-by: Alexander Graf 
---
 xen-all.c |   25 ++---
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/xen-all.c b/xen-all.c
index 8105c83..5fa92ae 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -797,12 +797,17 @@ void xenstore_store_pv_console_info(int i, 
CharDriverState *chr)
 }
 }
 
-static void xenstore_record_dm_state(XenIOState *s, const char *state)
+static void xenstore_record_dm_state(struct xs_handle *xs, const char *state)
 {
 char path[50];
 
+if (xs == NULL) {
+fprintf(stderr, "xenstore connection not initialized\n");
+exit(1);
+}
+
 snprintf(path, sizeof (path), "/local/domain/0/device-model/%u/state", 
xen_domid);
-if (!xs_write(s->xenstore, XBT_NULL, path, state, strlen(state))) {
+if (!xs_write(xs, XBT_NULL, path, state, strlen(state))) {
 fprintf(stderr, "error recording dm state\n");
 exit(1);
 }
@@ -823,15 +828,20 @@ static void xen_main_loop_prepare(XenIOState *state)
 if (evtchn_fd != -1) {
 qemu_set_fd_handler(evtchn_fd, cpu_handle_ioreq, NULL, state);
 }
-
-/* record state running */
-xenstore_record_dm_state(state, "running");
 }
 
 
 /* Initialise Xen */
 
-static void xen_vm_change_state_handler(void *opaque, int running, int reason)
+static void xen_change_state_handler(void *opaque, int running, int reason)
+{
+if (running) {
+/* record state running */
+xenstore_record_dm_state(xenstore, "running");
+}
+}
+
+static void xen_hvm_change_state_handler(void *opaque, int running, int reason)
 {
 XenIOState *state = opaque;
 if (running) {
@@ -854,6 +864,7 @@ int xen_init(void)
 xen_be_printf(NULL, 0, "can't open xen interface\n");
 return -1;
 }
+qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
 return 0;
 }
@@ -915,7 +926,7 @@ int xen_hvm_init(void)
 xen_map_cache_init();
 xen_ram_init(ram_size);
 
-qemu_add_vm_change_state_handler(xen_vm_change_state_handler, state);
+qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state);
 
 state->client = xen_cpu_phys_memory_client;
 QLIST_INIT(&state->physmap);
-- 
1.6.0.2




[Qemu-devel] [PATCH 5/6] xen: remove CONFIG_XEN_MAPCACHE

2011-07-20 Thread Alexander Graf
We were still exporting CONFIG_XEN_MAPCACHE, even though it's completely
unused by now. Remove it.

Signed-off-by: Alexander Graf 
---
 configure |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index e57efb1..f537130 100755
--- a/configure
+++ b/configure
@@ -3235,9 +3235,6 @@ case "$target_arch2" in
 if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
   target_phys_bits=64
   echo "CONFIG_XEN=y" >> $config_target_mak
-  if test "$cpu" = "i386" -o "$cpu" = "x86_64"; then
-  echo "CONFIG_XEN_MAPCACHE=y" >> $config_target_mak
-  fi
 fi
 esac
 case "$target_arch2" in
-- 
1.6.0.2




[Qemu-devel] [PATCH 22/23] qcow2: Use Qcow2Cache in writeback mode during loadvm/savevm

2011-07-20 Thread Kevin Wolf
In snapshotting there is no guest involved, so we can safely use a writeback
mode and do the flushes in the right place (i.e. at the very end). This
improves the time that creating/restoring an internal snapshot takes with an
image in writethrough mode.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cache.c|   12 
 block/qcow2-refcount.c |   38 +++---
 block/qcow2.h  |2 ++
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 3824739..8408847 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -312,3 +312,15 @@ found:
 c->entries[i].dirty = true;
 }
 
+bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
+bool enable)
+{
+bool old = c->writethrough;
+
+if (!old && enable) {
+qcow2_cache_flush(bs, c);
+}
+
+c->writethrough = enable;
+return old;
+}
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index ac95b88..14b2f67 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -705,8 +705,15 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 BDRVQcowState *s = bs->opaque;
 uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, l1_allocated;
 int64_t old_offset, old_l2_offset;
-int i, j, l1_modified, nb_csectors, refcount;
+int i, j, l1_modified = 0, nb_csectors, refcount;
 int ret;
+bool old_l2_writethrough, old_refcount_writethrough;
+
+/* Switch caches to writeback mode during update */
+old_l2_writethrough =
+qcow2_cache_set_writethrough(bs, s->l2_table_cache, false);
+old_refcount_writethrough =
+qcow2_cache_set_writethrough(bs, s->refcount_block_cache, false);
 
 l2_table = NULL;
 l1_table = NULL;
@@ -720,7 +727,11 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 l1_allocated = 1;
 if (bdrv_pread(bs->file, l1_table_offset,
l1_table, l1_size2) != l1_size2)
+{
+ret = -EIO;
 goto fail;
+}
+
 for(i = 0;i < l1_size; i++)
 be64_to_cpus(&l1_table[i]);
 } else {
@@ -729,7 +740,6 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 l1_allocated = 0;
 }
 
-l1_modified = 0;
 for(i = 0; i < l1_size; i++) {
 l2_offset = l1_table[i];
 if (l2_offset) {
@@ -773,6 +783,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 }
 
 if (refcount < 0) {
+ret = -EIO;
 goto fail;
 }
 }
@@ -803,6 +814,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 refcount = get_refcount(bs, l2_offset >> s->cluster_bits);
 }
 if (refcount < 0) {
+ret = -EIO;
 goto fail;
 } else if (refcount == 1) {
 l2_offset |= QCOW_OFLAG_COPIED;
@@ -813,6 +825,18 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 }
 }
 }
+
+ret = 0;
+fail:
+if (l2_table) {
+qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
+}
+
+/* Enable writethrough cache mode again */
+qcow2_cache_set_writethrough(bs, s->l2_table_cache, old_l2_writethrough);
+qcow2_cache_set_writethrough(bs, s->refcount_block_cache,
+old_refcount_writethrough);
+
 if (l1_modified) {
 for(i = 0; i < l1_size; i++)
 cpu_to_be64s(&l1_table[i]);
@@ -824,15 +848,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 }
 if (l1_allocated)
 qemu_free(l1_table);
-return 0;
- fail:
-if (l2_table) {
-qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
-}
-
-if (l1_allocated)
-qemu_free(l1_table);
-return -EIO;
+return ret;
 }
 
 
diff --git a/block/qcow2.h b/block/qcow2.h
index e1ae3e8..6a0a21b 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -228,6 +228,8 @@ int qcow2_read_snapshots(BlockDriverState *bs);
 Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables,
 bool writethrough);
 int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache *c);
+bool qcow2_cache_set_writethrough(BlockDriverState *bs, Qcow2Cache *c,
+bool enable);
 
 void qcow2_cache_entry_mark_dirty(Qcow2Cache *c, void *table);
 int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
-- 
1.7.6




[Qemu-devel] [PATCH 2/6] xen: add mapcache stubs

2011-07-20 Thread Alexander Graf
During the transition to get rid of CONFIG_XEN_MAPCACHE we lost the mapcache
stubs along the way. Nobody realized it because the commands were guarded by
if (xen_enabled()) clauses that made gcc optimize out the respective calls.

This patch adds the stubs again - this time in the generic xen-stubs.c

Signed-off-by: Alexander Graf 
---
 xen-stub.c |   26 ++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/xen-stub.c b/xen-stub.c
index efe2ab5..76d80e9 100644
--- a/xen-stub.c
+++ b/xen-stub.c
@@ -8,6 +8,7 @@
 
 #include "qemu-common.h"
 #include "hw/xen.h"
+#include "xen-mapcache.h"
 
 void xenstore_store_pv_console_info(int i, CharDriverState *chr)
 {
@@ -43,3 +44,28 @@ int xen_init(void)
 {
 return -ENOSYS;
 }
+
+/*** mapcache stubs ***/
+
+void xen_map_cache_init(void)
+{
+}
+
+uint8_t *xen_map_cache(target_phys_addr_t phys_addr, target_phys_addr_t size,
+   uint8_t lock)
+{
+return qemu_get_ram_ptr(phys_addr);
+}
+
+ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
+{
+return -1;
+}
+
+void xen_invalidate_map_cache(void)
+{
+}
+
+void xen_invalidate_map_cache_entry(uint8_t *buffer)
+{
+}
-- 
1.6.0.2




[Qemu-devel] [PATCH 2/2] qxl: upon reset, if spice worker is stopped, the command rings can be not empty

2011-07-20 Thread Gerd Hoffmann
From: Yonit Halperin 

Spice worker does no longer process commands when it is stopped.
Otherwise, it might crash during migration when attempting to process
commands while the guest is not completely loaded.

Cc: Alon Levy 

Signed-off-by: Gerd Hoffmann 
---
 hw/qxl.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 0b9a4c7..a6fb7f0 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -656,8 +656,8 @@ static void qxl_reset_state(PCIQXLDevice *d)
 QXLRam *ram = d->ram;
 QXLRom *rom = d->rom;
 
-assert(SPICE_RING_IS_EMPTY(&ram->cmd_ring));
-assert(SPICE_RING_IS_EMPTY(&ram->cursor_ring));
+assert(!d->ssd.running || SPICE_RING_IS_EMPTY(&ram->cmd_ring));
+assert(!d->ssd.running || SPICE_RING_IS_EMPTY(&ram->cursor_ring));
 d->shadow_rom.update_id = cpu_to_le32(0);
 *rom = d->shadow_rom;
 qxl_rom_set_dirty(d);
-- 
1.7.1




Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Jan Kiszka
On 2011-07-20 10:13, Avi Kivity wrote:
> On 07/19/2011 08:30 PM, Jan Kiszka wrote:
>>>  Rebasing is already not so fun for me with 78 patches and counting.
>>>  Let's drop yours and focus of getting mine in shape, since it's a superset.
>>
>> The patches series are widely orthogonal except for both killing the
>> obsolete start/stop logging logic.
>>
>> But I don't mind rebasing over yours - if something is finally merged at
>> all.
> 
> If you post patches I'll incorporate them in my patchset.  They're 
> available in qemu-kvm.git branch memory-region.

Is that branch up-to-date? It spits out tons of debug messages, making
it unusable for any test.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



[Qemu-devel] [PATCH 23/23] Add missing documentation for qemu-img -p

2011-07-20 Thread Kevin Wolf
From: Jes Sorensen 

Signed-off-by: Jes Sorensen 
Signed-off-by: Kevin Wolf 
---
 qemu-img-cmds.hx |4 ++--
 qemu-img.texi|6 --
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 2b70618..1299e83 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -30,7 +30,7 @@ ETEXI
 DEF("convert", img_convert,
 "convert [-c] [-p] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s 
snapshot_name] filename [filename2 [...]] output_filename")
 STEXI
-@item convert [-c] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-s 
@var{snapshot_name}] @var{filename} [@var{filename2} [...]] 
@var{output_filename}
+@item convert [-c] [-p] [-f @var{fmt}] [-O @var{output_fmt}] [-o 
@var{options}] [-s @var{snapshot_name}] @var{filename} [@var{filename2} [...]] 
@var{output_filename}
 ETEXI
 
 DEF("info", img_info,
@@ -48,7 +48,7 @@ ETEXI
 DEF("rebase", img_rebase,
 "rebase [-f fmt] [-t cache] [-p] [-u] -b backing_file [-F backing_fmt] 
filename")
 STEXI
-@item rebase [-f @var{fmt}] [-u] -b @var{backing_file} [-F @var{backing_fmt}] 
@var{filename}
+@item rebase [-f @var{fmt}] [-p] [-u] -b @var{backing_file} [-F 
@var{backing_fmt}] @var{filename}
 ETEXI
 
 DEF("resize", img_resize,
diff --git a/qemu-img.texi b/qemu-img.texi
index 526474c..495a1b6 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -38,6 +38,8 @@ by the used format or see the format descriptions below for 
details.
 indicates that target image must be compressed (qcow format only)
 @item -h
 with or without a command shows help and lists the supported formats
+@item -p
+display progress bar (convert and rebase commands only)
 @end table
 
 Parameters to snapshot subcommand:
@@ -84,7 +86,7 @@ it doesn't need to be specified separately in this case.
 
 Commit the changes recorded in @var{filename} in its base image.
 
-@item convert [-c] [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] [-s 
@var{snapshot_name}] @var{filename} [@var{filename2} [...]] 
@var{output_filename}
+@item convert [-c] [-p] [-f @var{fmt}] [-O @var{output_fmt}] [-o 
@var{options}] [-s @var{snapshot_name}] @var{filename} [@var{filename2} [...]] 
@var{output_filename}
 
 Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to 
disk image @var{output_filename}
 using format @var{output_fmt}. It can be optionally compressed (@code{-c}
@@ -114,7 +116,7 @@ they are displayed too.
 
 List, apply, create or delete snapshots in image @var{filename}.
 
-@item rebase [-f @var{fmt}] [-u] -b @var{backing_file} [-F @var{backing_fmt}] 
@var{filename}
+@item rebase [-f @var{fmt}] [-p] [-u] -b @var{backing_file} [-F 
@var{backing_fmt}] @var{filename}
 
 Changes the backing file of an image. Only the formats @code{qcow2} and
 @code{qed} support changing the backing file.
-- 
1.7.6




[Qemu-devel] [PATCH 6/6] xen: make xen_enabled even more clever

2011-07-20 Thread Alexander Graf
When using xen_enabled() we're currently only checking if xen is enabled
at all during the build. But what if you want to build multiple targets
out of which only one can potentially run xen code?

That means that for generic code we'll still have to fall back to the
variable and potentially slow the code down, but it's not as important as
that is mostly xen device emulation which is not touched for non-xen targets.

The target specific code however can with this patch see that it's unable to
ever execute xen code. We can thus always return 0 on xen_enabled(), giving
gcc enough hints to evict the mapcache code from the target memory management
code.

Signed-off-by: Alexander Graf 
Acked-by: Anthony PERARD 
---
 configure |5 +
 hw/xen.h  |2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index f537130..f79b23b 100755
--- a/configure
+++ b/configure
@@ -3235,7 +3235,12 @@ case "$target_arch2" in
 if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
   target_phys_bits=64
   echo "CONFIG_XEN=y" >> $config_target_mak
+else
+  echo "CONFIG_NO_XEN=y" >> $config_target_mak
 fi
+;;
+  *)
+echo "CONFIG_NO_XEN=y" >> $config_target_mak
 esac
 case "$target_arch2" in
   i386|x86_64|ppcemb|ppc|ppc64|s390x)
diff --git a/hw/xen.h b/hw/xen.h
index 43b95d6..2162111 100644
--- a/hw/xen.h
+++ b/hw/xen.h
@@ -24,7 +24,7 @@ extern int xen_allowed;
 
 static inline int xen_enabled(void)
 {
-#ifdef CONFIG_XEN_BACKEND
+#if defined(CONFIG_XEN_BACKEND) && !defined(CONFIG_NO_XEN)
 return xen_allowed;
 #else
 return 0;
-- 
1.6.0.2




Re: [Qemu-devel] [libvirt] live snapshot wiki updated

2011-07-20 Thread Stefan Hajnoczi
On Wed, Jul 20, 2011 at 11:28 AM, Daniel P. Berrange
 wrote:
> On Wed, Jul 20, 2011 at 12:15:02PM +0200, Nicolas Sebrecht wrote:
>> The 20/07/11, Daniel P. Berrange wrote:
>>
>> > To make the decision whether the filename from QEMU is valid, we have
>> > to parse the master image header data to see if the filename actually
>> > matches the backing file required by the image assigned to the guest.
>>
>> Actually, libvirt should not have to worry if the filename provided by
>> QEMU is valid. I think it should trust QEMU. If QEMU doesn't provide
>> information others can trust; it should be fixed at QEMU side.
>
> The security goal of libvirt is to protect the host from a compromised
> QEMU, therefore QEMU is, by definition, untrusted.

This is a very reasonable goal.  QEMU is constantly dealing with the
untrusted guest.  The whole point of SELinux isolation of QEMU is to
contain any compromise to a single VM and reduce the capabilities of
that process to the minimum.

libvirt needs to help set the boundaries of what the QEMU process can do.

Stefan



[Qemu-devel] [PULL v2 00/23] Block patches

2011-07-20 Thread Kevin Wolf
(Reposting only changed or new patches)

The following changes since commit 89b9ba661bd2d6155308f895ec075d813f0e129b:

  Fix signal handling of SIG_IPI when io-thread is enabled (2011-07-16 19:43:00 
+)

are available in the git repository at:
  git://repo.or.cz/qemu/kevin.git for-anthony

Devin Nakamura (2):
  qemu-io: Fix formatting
  qemu-io: Fix if scoping bug

Fam Zheng (12):
  VMDK: introduce VmdkExtent
  VMDK: bugfix, align offset to cluster in get_whole_cluster
  VMDK: probe for monolithicFlat images
  VMDK: separate vmdk_open by format version
  VMDK: add field BDRVVmdkState.desc_offset
  VMDK: flush multiple extents
  VMDK: move 'static' cid_update flag to bs field
  VMDK: change get_cluster_offset return type
  VMDK: open/read/write for monolithicFlat image
  VMDK: create different subformats
  VMDK: fix coding style
  block: add bdrv_get_allocated_file_size() operation

Hannes Reinecke (4):
  iov: Update parameter usage in iov_(to|from)_buf()
  scsi: Add 'hba_private' to SCSIRequest
  scsi-disk: Fixup debugging statement
  scsi-disk: Mask out serial number EVPD

Jes Sorensen (1):
  Add missing documentation for qemu-img -p

Kevin Wolf (1):
  qcow2: Use Qcow2Cache in writeback mode during loadvm/savevm

Luiz Capitulino (2):
  qemu-options.hx: Document missing -drive options
  qemu-config: Document -drive options

MORITA Kazutaka (1):
  sheepdog: add full data preallocation support

 block.c|   19 +
 block.h|1 +
 block/qcow2-cache.c|   12 +
 block/qcow2-refcount.c |   38 +-
 block/qcow2.h  |2 +
 block/raw-posix.c  |   21 +
 block/raw-win32.c  |   29 +
 block/sheepdog.c   |   71 ++-
 block/vmdk.c   | 1297 
 block_int.h|2 +
 hw/esp.c   |2 +-
 hw/lsi53c895a.c|   22 +-
 hw/scsi-bus.c  |9 +-
 hw/scsi-disk.c |   21 +-
 hw/scsi-generic.c  |5 +-
 hw/scsi.h  |   10 +-
 hw/spapr_vscsi.c   |   28 +-
 hw/usb-msd.c   |9 +-
 hw/virtio-net.c|2 +-
 hw/virtio-serial-bus.c |2 +-
 iov.c  |   49 +-
 iov.h  |   10 +-
 qemu-config.c  |6 +
 qemu-img-cmds.hx   |4 +-
 qemu-img.c |   31 +-
 qemu-img.texi  |6 +-
 qemu-io.c  | 2653 
 qemu-options.hx|8 +
 28 files changed, 2509 insertions(+), 1860 deletions(-)



[Qemu-devel] [PATCH 1/2] spice: add sanity check for spice ports

2011-07-20 Thread Gerd Hoffmann
Make sure at least one port (port=.. or tls-port=...)
is specified.  Also apply range checks to the port numbers.

Signed-off-by: Gerd Hoffmann 
---
 ui/spice-core.c |   11 ++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index e142452..1100417 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -480,7 +480,16 @@ void qemu_spice_init(void)
 port = qemu_opt_get_number(opts, "port", 0);
 tls_port = qemu_opt_get_number(opts, "tls-port", 0);
 if (!port && !tls_port) {
-return;
+fprintf(stderr, "neither port nor tls-port specified for spice.");
+exit(1);
+}
+if (port < 0 || port > 65535) {
+fprintf(stderr, "spice port is out of range");
+exit(1);
+}
+if (tls_port < 0 || tls_port > 65535) {
+fprintf(stderr, "spice tls-port is out of range");
+exit(1);
 }
 password = qemu_opt_get(opts, "password");
 
-- 
1.7.1




Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Jan Kiszka
On 2011-07-20 10:13, Avi Kivity wrote:
> On 07/19/2011 08:30 PM, Jan Kiszka wrote:
>>>  Rebasing is already not so fun for me with 78 patches and counting.
>>>  Let's drop yours and focus of getting mine in shape, since it's a superset.
>>
>> The patches series are widely orthogonal except for both killing the
>> obsolete start/stop logging logic.
>>
>> But I don't mind rebasing over yours - if something is finally merged at
>> all.
> 
> If you post patches I'll incorporate them in my patchset.  They're 
> available in qemu-kvm.git branch memory-region.

Thanks, looking into this ATM.

To allow building of that branch, this needs to be folded on one of the
patches:

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index a75a5a9..92ba3c9 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -161,7 +161,8 @@ static int 
virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
 {
 VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
 EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
-int r;
+int r = 0;
+
 if (assign) {
 r = event_notifier_init(notifier, 1);
 if (r < 0) {

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [RFC v4 00/58] Memory API

2011-07-20 Thread Anthony Liguori

On 07/20/2011 01:10 AM, Sasha Levin wrote:

On Tue, 2011-07-19 at 21:53 -0500, Anthony Liguori wrote:

QEMU does use it and it's quite important.  Coalesced MMIO is really
about write caching MMIO exits.  It only works with devices that have
registers where writing has no side effects.  Moreover, it only really
works well when there are lots and lots of writes to these registers
simultaneously.

Couple that with the fact that the buffer is a fixed size and it's
really not flexible enough to be useful for a wide variety of devices.

But for VGA planar mode writes, it works wonders.  It would be terrible
to totally lose it.  That said, I'm not at all convinced it's useful for
much other than VGA planar mode.


Why was the coalesced approach taken in the first place? When I tried
using it for VGA in /tools/kvm it just seemed to me like a builtin
virtio-memory transport.


I'm not really sure what you mean by that.  Coalesced I/O is old.  It 
predates the ioeventfd.


I think using a pipe/socket makes a bit more sense.

Regards,

Anthony Liguori



Thats why I think planar VGA would be fine if we deprecate coalesced
mmio in favor of either socket ioeventfds or a new virtio-memory device.






[Qemu-devel] [PATCH 05/23] scsi: Add 'hba_private' to SCSIRequest

2011-07-20 Thread Kevin Wolf
From: Hannes Reinecke 

'tag' is just an abstraction to identify the command
from the driver. So we should make that explicit by
replacing 'tag' with a driver-defined pointer 'hba_private'.
This saves the lookup for driver handling several commands
in parallel.
'tag' is still being kept for tracing purposes.

Signed-off-by: Hannes Reinecke 
Acked-by: Paolo Bonzini 
Signed-off-by: Kevin Wolf 
---
 hw/esp.c  |2 +-
 hw/lsi53c895a.c   |   22 --
 hw/scsi-bus.c |9 ++---
 hw/scsi-disk.c|4 ++--
 hw/scsi-generic.c |5 +++--
 hw/scsi.h |   10 +++---
 hw/spapr_vscsi.c  |   28 +---
 hw/usb-msd.c  |9 +
 8 files changed, 37 insertions(+), 52 deletions(-)

diff --git a/hw/esp.c b/hw/esp.c
index aa50800..9ddd637 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -244,7 +244,7 @@ static void do_busid_cmd(ESPState *s, uint8_t *buf, uint8_t 
busid)
 
 DPRINTF("do_busid_cmd: busid 0x%x\n", busid);
 lun = busid & 7;
-s->current_req = scsi_req_new(s->current_dev, 0, lun);
+s->current_req = scsi_req_new(s->current_dev, 0, lun, NULL);
 datalen = scsi_req_enqueue(s->current_req, buf);
 s->ti_size = datalen;
 if (datalen != 0) {
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index 940b43a..69eec1d 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -661,7 +661,7 @@ static lsi_request *lsi_find_by_tag(LSIState *s, uint32_t 
tag)
 static void lsi_request_cancelled(SCSIRequest *req)
 {
 LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
-lsi_request *p;
+lsi_request *p = req->hba_private;
 
 if (s->current && req == s->current->req) {
 scsi_req_unref(req);
@@ -670,7 +670,6 @@ static void lsi_request_cancelled(SCSIRequest *req)
 return;
 }
 
-p = lsi_find_by_tag(s, req->tag);
 if (p) {
 QTAILQ_REMOVE(&s->queue, p, next);
 scsi_req_unref(req);
@@ -680,18 +679,12 @@ static void lsi_request_cancelled(SCSIRequest *req)
 
 /* Record that data is available for a queued command.  Returns zero if
the device was reselected, nonzero if the IO is deferred.  */
-static int lsi_queue_tag(LSIState *s, uint32_t tag, uint32_t len)
+static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len)
 {
-lsi_request *p;
-
-p = lsi_find_by_tag(s, tag);
-if (!p) {
-BADF("IO with unknown tag %d\n", tag);
-return 1;
-}
+lsi_request *p = req->hba_private;
 
 if (p->pending) {
-BADF("Multiple IO pending for tag %d\n", tag);
+BADF("Multiple IO pending for request %p\n", p);
 }
 p->pending = len;
 /* Reselect if waiting for it, or if reselection triggers an IRQ
@@ -743,9 +736,9 @@ static void lsi_transfer_data(SCSIRequest *req, uint32_t 
len)
 LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent);
 int out;
 
-if (s->waiting == 1 || !s->current || req->tag != s->current->tag ||
+if (s->waiting == 1 || !s->current || req->hba_private != s->current ||
 (lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON))) {
-if (lsi_queue_tag(s, req->tag, len)) {
+if (lsi_queue_req(s, req, len)) {
 return;
 }
 }
@@ -789,7 +782,8 @@ static void lsi_do_command(LSIState *s)
 assert(s->current == NULL);
 s->current = qemu_mallocz(sizeof(lsi_request));
 s->current->tag = s->select_tag;
-s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun);
+s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun,
+   s->current);
 
 n = scsi_req_enqueue(s->current->req, buf);
 if (n) {
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index ad6a730..8b1a412 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -131,7 +131,8 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
 return res;
 }
 
-SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t 
lun)
+SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag,
+uint32_t lun, void *hba_private)
 {
 SCSIRequest *req;
 
@@ -141,14 +142,16 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, 
uint32_t tag, uint32_t l
 req->dev = d;
 req->tag = tag;
 req->lun = lun;
+req->hba_private = hba_private;
 req->status = -1;
 trace_scsi_req_alloc(req->dev->id, req->lun, req->tag);
 return req;
 }
 
-SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun)
+SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
+  void *hba_private)
 {
-return d->info->alloc_req(d, tag, lun);
+return d->info->alloc_req(d, tag, lun, hba_private);
 }
 
 uint8_t *scsi_req_get_buf(SCSIRequest *req)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a8c7372..c2a99fe 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -81,13 +81,13 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, 
int type)

Re: [Qemu-devel] [PATCH] pci: Length-align config space accesses

2011-07-20 Thread Isaku Yamahata
Hi. This clean up looks good basically.
But when conventional pci device is accessed via MMCONFIG area,
addr &= addr_mask doesn't work as expected.
The config area of [256, 4K) of conventional pci should have no effect.

thanks,

On Tue, Jul 19, 2011 at 11:39:02PM +0200, Jan Kiszka wrote:
> From: Jan Kiszka 
> 
> Introduce pci_config_read/write helpers to split up config space
> accesses that are not length-aligned. This particularly avoids that each
> and every device needs to check for config space overruns. Also move the
> access length assertion to the new helpers.
> 
> Signed-off-by: Jan Kiszka 
> ---
> 
> This will also simplify my cap refactorings for the device-assignment
> code in qemu-kvm.
> 
>  hw/pci.c   |   43 +++
>  hw/pci.h   |5 +
>  hw/pci_host.c  |   14 ++
>  hw/pcie_host.c |   12 ++--
>  4 files changed, 56 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index b904a4e..6957ece 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1104,12 +1104,48 @@ static void pci_update_irq_disabled(PCIDevice *d, int 
> was_irq_disabled)
>  }
>  }
>  
> +void pci_config_write(PCIDevice *pci_dev, uint32_t addr, uint32_t addr_mask,
> +  uint32_t val, uint32_t len)
> +{
> +assert(len == 1 || len == 2 || len == 4);
> +
> +addr &= addr_mask;
> +
> +if (addr & (len - 1)) {
> +len >>= 1;
> +pci_config_write(pci_dev, addr, addr_mask, val, len);
> +pci_config_write(pci_dev, addr + len, addr_mask,
> + val >> (len * 8), len);
> +} else {
> +pci_dev->config_write(pci_dev, addr, val, len);
> +}
> +}
> +
> +uint32_t pci_config_read(PCIDevice *pci_dev, uint32_t addr, uint32_t 
> addr_mask,
> + uint32_t len)
> +{
> +uint32_t val;
> +
> +assert(len == 1 || len == 2 || len == 4);
> +
> +addr &= addr_mask;
> +
> +if (addr & (len - 1)) {
> +len >>= 1;
> +val = pci_config_read(pci_dev, addr, addr_mask, len);
> +val |= pci_config_read(pci_dev, addr + len,
> +   addr_mask, len) << (len * 8);
> +} else {
> +val = pci_dev->config_read(pci_dev, addr, len);
> +}
> +return val;
> +}
> +
>  uint32_t pci_default_read_config(PCIDevice *d,
>   uint32_t address, int len)
>  {
>  uint32_t val = 0;
> -assert(len == 1 || len == 2 || len == 4);
> -len = MIN(len, pci_config_size(d) - address);
> +
>  memcpy(&val, d->config + address, len);
>  return le32_to_cpu(val);
>  }
> @@ -1117,9 +1153,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
>  void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int 
> l)
>  {
>  int i, was_irq_disabled = pci_irq_disabled(d);
> -uint32_t config_size = pci_config_size(d);
>  
> -for (i = 0; i < l && addr + i < config_size; val >>= 8, ++i) {
> +for (i = 0; i < l; val >>= 8, ++i) {
>  uint8_t wmask = d->wmask[addr + i];
>  uint8_t w1cmask = d->w1cmask[addr + i];
>  assert(!(wmask & w1cmask));
> diff --git a/hw/pci.h b/hw/pci.h
> index c220745..3d5b39c 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -482,4 +482,9 @@ static inline uint32_t pci_config_size(const PCIDevice *d)
>  return pci_is_express(d) ? PCIE_CONFIG_SPACE_SIZE : 
> PCI_CONFIG_SPACE_SIZE;
>  }
>  
> +void pci_config_write(PCIDevice *pci_dev, uint32_t addr, uint32_t addr_mask,
> +  uint32_t val, uint32_t len);
> +uint32_t pci_config_read(PCIDevice *pci_dev, uint32_t addr, uint32_t 
> addr_mask,
> + uint32_t len);
> +
>  #endif
> diff --git a/hw/pci_host.c b/hw/pci_host.c
> index 728e2d4..db888fb 100644
> --- a/hw/pci_host.c
> +++ b/hw/pci_host.c
> @@ -50,30 +50,28 @@ static inline PCIDevice *pci_dev_find_by_addr(PCIBus 
> *bus, uint32_t addr)
>  void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len)
>  {
>  PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr);
> -uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1);
>  
> -if (!pci_dev)
> +if (!pci_dev) {
>  return;
> +}
>  
>  PCI_DPRINTF("%s: %s: addr=%02" PRIx32 " val=%08" PRIx32 " len=%d\n",
> -__func__, pci_dev->name, config_addr, val, len);
> -pci_dev->config_write(pci_dev, config_addr, val, len);
> +__func__, pci_dev->name, addr, val, len);
> +pci_config_write(pci_dev, addr, PCI_CONFIG_SPACE_SIZE - 1, val, len);
>  }
>  
>  uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len)
>  {
>  PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr);
> -uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1);
>  uint32_t val;
>  
> -assert(len == 1 || len == 2 || len == 4);
>  if (!pci_dev) {
>  return ~0x0;
>  }
>  
> -val = pci_dev->config_read(pci_dev, config_addr, len);
> +val = pci_config_read(pci_dev, addr, PCI_C

  1   2   3   4   >