[Qemu-devel] PC value translation from guest VA to host VA.

2014-02-11 Thread Gaurav Sharma
Can anyone point it out to me where is the pc value translated from guest
virtual address to host virtual address ?

Thanks,
Gaurav


Re: [Qemu-devel] [Qemu-ppc] PowerPC Decimal Floating Point

2014-02-11 Thread Alexander Graf

On 11.02.2014, at 18:14, Tom Musta  wrote:

> QEMU is currently lacking support for the Decimal Floating Point category of 
> instructions
> (see Power ISA V2.07 Chapter 6).  I intend to add this support.
> 
> Has this topic been investigated before and if so can anyone point me to that 
> discussion?
> A Google search came up empty for me.
> 
> My proposal is to incorporate the libdecnumber component of libdfp
> (http://www.eglibc.org/cgi-bin/viewvc.cgi/libdfp/trunk/) in a manner 
> analogous to how
> softfloat is used for binary floating point.  So, for example, the helper for 
> the dadd
> instruction would look something like the following:
> 
>   - map FPSCR state to a decContext.
>   - convert the contents of the source FPRs to decNumbers (decimal64ToNumber).
>   - call decNumberAdd
>   - convert the resultant decNumber to DPD (decimal64FromNumber)
>   - update FPSCR per the decContext.status and result.
> 
> Comments?

I think that approach makes a lot of sense, but let's ask Richard and Peter as 
well.


Alex




Re: [Qemu-devel] Ping for patch "linux-user: add binfmt wrapper for argv[0] handling"

2014-02-11 Thread Alexander Graf

On 12.02.2014, at 03:30, Dennis Lan (dlan)  wrote:

> Hi Folks:
>   Any chance to get this patch accepted into master branch?
> I found it useful when chroot into another system. Origianl post can
> be found here[1], would be quite easy to forward port to latest code.
> 
> [1] https://lists.gnu.org/archive/html/qemu-devel/2011-09/msg03841.html

CC'ed Riku.


Alex




[Qemu-devel] [PATCH v20 07/26] cow.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
cow.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/cow.c |   46 ++
 1 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 85c2971..0d06781 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -323,7 +323,7 @@ static void cow_close(BlockDriverState *bs)
 {
 }
 
-static int cow_create(const char *filename, QEMUOptionParameter *options,
+static int cow_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 struct cow_header_v2 cow_header;
@@ -335,16 +335,10 @@ static int cow_create(const char *filename, 
QEMUOptionParameter *options,
 BlockDriverState *cow_bs;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_sectors = options->value.n / 512;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-image_filename = options->value.s;
-}
-options++;
-}
+image_sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
 
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (ret < 0) {
 qerror_report_err(local_err);
 error_free(local_err);
@@ -393,18 +387,22 @@ exit:
 return ret;
 }
 
-static QEMUOptionParameter cow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{ NULL }
+static QemuOptsList cow_create_opts = {
+.name = "cow-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_cow = {
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
 .bdrv_probe = cow_probe,
 .bdrv_open  = cow_open,
 .bdrv_close = cow_close,
-.bdrv_create= cow_create,
+.bdrv_create2= cow_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_read  = cow_co_read,
 .bdrv_write = cow_co_write,
 .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-.create_options = cow_create_options,
+.create_opts   = &cow_create_opts,
 };
 
 static void bdrv_cow_init(void)
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 26/26] change back to original name from bdrv_create2 to bdrv_create

2014-02-11 Thread Chunyan Liu
Rename the new driver callback bdrv_create2 to the old name bdrv_create.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block.c   |4 ++--
 block/cow.c   |2 +-
 block/gluster.c   |8 
 block/iscsi.c |2 +-
 block/qcow.c  |2 +-
 block/qcow2.c |2 +-
 block/qed.c   |2 +-
 block/raw-posix.c |   10 +-
 block/raw-win32.c |2 +-
 block/raw_bsd.c   |2 +-
 block/rbd.c   |2 +-
 block/sheepdog.c  |6 +++---
 block/ssh.c   |2 +-
 block/vdi.c   |2 +-
 block/vhdx.c  |2 +-
 block/vmdk.c  |2 +-
 block/vpc.c   |2 +-
 include/block/block_int.h |2 +-
 18 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/block.c b/block.c
index 56b6d06..14a9e29 100644
--- a/block.c
+++ b/block.c
@@ -420,7 +420,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 CreateCo *cco = opaque;
 assert(cco->drv);
 
-ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+ret = cco->drv->bdrv_create(cco->filename, cco->opts, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(&cco->err, local_err);
 }
@@ -441,7 +441,7 @@ int bdrv_create(BlockDriver *drv, const char* filename,
 .err = NULL,
 };
 
-if (!drv->bdrv_create2) {
+if (!drv->bdrv_create) {
 error_setg(errp, "Driver '%s' does not support image creation", 
drv->format_name);
 ret = -ENOTSUP;
 goto out;
diff --git a/block/cow.c b/block/cow.c
index 012a6b4..f4f0fb7 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -412,7 +412,7 @@ static BlockDriver bdrv_cow = {
 .bdrv_probe = cow_probe,
 .bdrv_open  = cow_open,
 .bdrv_close = cow_close,
-.bdrv_create2= cow_create,
+.bdrv_create= cow_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_read  = cow_co_read,
diff --git a/block/gluster.c b/block/gluster.c
index edac27e..896230f 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -620,7 +620,7 @@ static BlockDriver bdrv_gluster = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create2 = qemu_gluster_create,
+.bdrv_create = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -644,7 +644,7 @@ static BlockDriver bdrv_gluster_tcp = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create2 = qemu_gluster_create,
+.bdrv_create = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -668,7 +668,7 @@ static BlockDriver bdrv_gluster_unix = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create2 = qemu_gluster_create,
+.bdrv_create = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -692,7 +692,7 @@ static BlockDriver bdrv_gluster_rdma = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create2 = qemu_gluster_create,
+.bdrv_create  = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
diff --git a/block/iscsi.c b/block/iscsi.c
index f94f935..3b5e8cd 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1450,7 +1450,7 @@ static BlockDriver bdrv_iscsi = {
 .bdrv_needs_filename = true,
 .bdrv_file_open  = iscsi_open,
 .bdrv_close  = iscsi_close,
-.bdrv_create2= iscsi_create,
+.bdrv_create = iscsi_create,
 .create_opts = iscsi_create_opts,
 .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
diff --git a/block/qcow.c b/block/qcow.c
index a9a30d9..4a8630b 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -905,7 +905,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_open = qcow_open,
 .bdrv_close= qcow_close,
 .bdrv_reopen_prepare

[Qemu-devel] [PATCH v20 25/26] cleanup QEMUOptionParameter

2014-02-11 Thread Chunyan Liu
Now all places using QEMUOptionParameter could use QemuOpts too, remove
QEMUOptionParameter related code.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block.c   |   57 ++-
 block/cow.c   |2 +-
 block/qcow.c  |2 +-
 block/qcow2.c |2 +-
 block/qed.c   |2 +-
 block/raw_bsd.c   |2 +-
 block/vhdx.c  |2 +-
 block/vmdk.c  |4 +-
 block/vvfat.c |2 +-
 include/block/block.h |4 +-
 include/block/block_int.h |3 -
 include/qemu/option.h |   37 
 qemu-img.c|   39 +
 util/qemu-option.c|  405 -
 14 files changed, 30 insertions(+), 533 deletions(-)

diff --git a/block.c b/block.c
index d6ddbd0..56b6d06 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,6 @@ BlockDriver *bdrv_find_whitelisted_format(const char 
*format_name,
 typedef struct CreateCo {
 BlockDriver *drv;
 char *filename;
-QEMUOptionParameter *options;
 QemuOpts *opts;
 int ret;
 Error *err;
@@ -421,11 +420,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 CreateCo *cco = opaque;
 assert(cco->drv);
 
-if (cco->drv->bdrv_create2) {
-ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
-} else {
-ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
-}
+ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(&cco->err, local_err);
 }
@@ -433,7 +428,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
+QemuOpts *opts, Error **errp)
 {
 int ret;
 
@@ -441,13 +436,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
 CreateCo cco = {
 .drv = drv,
 .filename = g_strdup(filename),
-.options = options,
 .opts = opts,
 .ret = NOT_DONE,
 .err = NULL,
 };
 
-if (!drv->bdrv_create && !drv->bdrv_create2) {
+if (!drv->bdrv_create2) {
 error_setg(errp, "Driver '%s' does not support image creation", 
drv->format_name);
 ret = -ENOTSUP;
 goto out;
@@ -478,7 +472,7 @@ out:
 return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
+int bdrv_create_file(const char *filename,
  QemuOpts *opts, Error **errp)
 {
 BlockDriver *drv;
@@ -491,7 +485,7 @@ int bdrv_create_file(const char* filename, 
QEMUOptionParameter *options,
 return -ENOENT;
 }
 
-ret = bdrv_create(drv, filename, options, opts, &local_err);
+ret = bdrv_create(drv, filename, opts, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(errp, local_err);
 }
@@ -1252,7 +1246,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
QDict *options,
 BlockDriverState *bs1;
 int64_t total_size;
 BlockDriver *bdrv_qcow2;
-QEMUOptionParameter *create_options = NULL;
 QemuOpts *opts = NULL;
 QDict *snapshot_options;
 
@@ -1280,20 +1273,11 @@ int bdrv_open(BlockDriverState *bs, const char 
*filename, QDict *options,
 }
 
 bdrv_qcow2 = bdrv_find_format("qcow2");
-if (bdrv_qcow2->bdrv_create2) {
-opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
-&error_abort);
-qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
-} else {
-create_options =
-parse_option_parameters("", bdrv_qcow2->create_options, NULL);
-set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
- total_size);
-}
+opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
+&error_abort);
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
 
-ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
-  &local_err);
-free_option_parameters(create_options);
+ret = bdrv_create(bdrv_qcow2, tmp_filename, opts, &local_err);
 qemu_opts_del(opts);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not create temporary overlay "
@@ -5211,7 +5195,6 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
  char *options, uint64_t img_size, int flags,
  Error **errp, bool quiet)
 {
-QEMUOptionParameter *param = NULL, *create_options = NULL;
 QemuOptsList *create_opts = NULL;
 QemuOpts *opts = NULL;
 const char *backing_fmt, *backing_file;
@@ -5234,16 +5217,8 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 return;
 }
 
-if (

[Qemu-devel] [PATCH v20 20/26] vdi.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
vdi.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/vdi.c |   71 --
 1 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 2d7490f..e5494a0 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -646,7 +646,7 @@ static int vdi_co_write(BlockDriverState *bs,
 return ret;
 }
 
-static int vdi_create(const char *filename, QEMUOptionParameter *options,
+static int vdi_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 int fd;
@@ -662,25 +662,17 @@ static int vdi_create(const char *filename, 
QEMUOptionParameter *options,
 logout("\n");
 
 /* Read out options. */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-bytes = options->value.n;
+bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
 #if defined(CONFIG_VDI_BLOCK_SIZE)
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
-block_size = options->value.n;
-}
+block_size = qemu_opt_get_size_del(opts,
+   BLOCK_OPT_CLUSTER_SIZE,
+   DEFAULT_CLUSTER_SIZE);
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
-} else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-if (options->value.n) {
-image_type = VDI_TYPE_STATIC;
-}
-#endif
-}
-options++;
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_STATIC, false)) {
+image_type = VDI_TYPE_STATIC;
 }
+#endif
 
 fd = qemu_open(filename,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
@@ -760,29 +752,34 @@ static void vdi_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static QEMUOptionParameter vdi_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
+static QemuOptsList vdi_create_opts = {
+.name = "vdi-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(vdi_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
 #if defined(CONFIG_VDI_BLOCK_SIZE)
-{
-.name = BLOCK_OPT_CLUSTER_SIZE,
-.type = OPT_SIZE,
-.help = "VDI cluster (block) size",
-.value = { .n = DEFAULT_CLUSTER_SIZE },
-},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "VDI cluster (block) size",
+.def_value_str = stringify(DEFAULT_CLUSTER_SIZE)
+},
 #endif
 #if defined(CONFIG_VDI_STATIC_IMAGE)
-{
-.name = BLOCK_OPT_STATIC,
-.type = OPT_FLAG,
-.help = "VDI static (pre-allocated) image"
-},
+{
+.name = BLOCK_OPT_STATIC,
+.type = QEMU_OPT_BOOL,
+.help = "VDI static (pre-allocated) image",
+.def_value_str = "off"
+},
 #endif
-/* TODO: An additional option to set UUID values might be useful. */
-{ NULL }
+/* TODO: An additional option to set UUID values might be useful. */
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_vdi = {
@@ -792,7 +789,7 @@ static BlockDriver bdrv_vdi = {
 .bdrv_open = vdi_open,
 .bdrv_close = vdi_close,
 .bdrv_reopen_prepare = vdi_reopen_prepare,
-.bdrv_create = vdi_create,
+.bdrv_create2 = vdi_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_co_get_block_status = vdi_co_get_block_status,
 .bdrv_make_empty = vdi_make_empty,
@@ -804,7 +801,7 @@ static BlockDriver bdrv_vdi = {
 
 .bdrv_get_info = vdi_get_info,
 
-.create_options = vdi_create_options,
+.create_opts = &vdi_create_opts,
 .bdrv_check = vdi_check,
 };
 
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 18/26] sheepdog.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
sheepdog.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/sheepdog.c |  101 +-
 1 files changed, 47 insertions(+), 54 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 672b9c9..ca9adc3 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1625,12 +1625,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const 
char *opt)
 return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
+static int sd_create(const char *filename, QemuOpts *opts,
  Error **errp)
 {
 int ret = 0;
 uint32_t vid = 0;
-char *backing_file = NULL;
+const char *backing_file = NULL;
+const char *buf = NULL;
 BDRVSheepdogState *s;
 char tag[SD_MAX_VDI_TAG_LEN];
 uint32_t snapid;
@@ -1649,31 +1650,26 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options,
 goto out;
 }
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-s->inode.vdi_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
-if (!options->value.s || !strcmp(options->value.s, "off")) {
-prealloc = false;
-} else if (!strcmp(options->value.s, "full")) {
-prealloc = true;
-} else {
-error_report("Invalid preallocation mode: '%s'",
- options->value.s);
-ret = -EINVAL;
-goto out;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_REDUNDANCY)) {
-if (options->value.s) {
-ret = parse_redundancy(s, options->value.s);
-if (ret < 0) {
-goto out;
-}
-}
+s->inode.vdi_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+if (!buf || !strcmp(buf, "off")) {
+prealloc = false;
+} else if (!strcmp(buf, "full")) {
+prealloc = true;
+} else {
+error_report("Invalid preallocation mode: '%s'", buf);
+ret = -EINVAL;
+goto out;
+}
+
+buf = NULL;
+buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+if (buf) {
+ret = parse_redundancy(s, buf);
+if (ret < 0) {
+goto out;
 }
-options++;
 }
 
 if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -2487,28 +2483,27 @@ static int64_t 
sd_get_allocated_file_size(BlockDriverState *bs)
 return size;
 }
 
-static QEMUOptionParameter sd_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_PREALLOC,
-.type = OPT_STRING,
-.help = "Preallocation mode (allowed values: off, full)"
-},
-{
-.name = BLOCK_OPT_REDUNDANCY,
-.type = OPT_STRING,
-.help = "Redundancy of the image"
-},
-{ NULL }
+static QemuOptsList sd_create_opts = {
+.name = "sheepdog-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = QEMU_OPT_STRING,
+.help = "Preallocation mode (allowed values: off, full)"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2518,7 +2513,7 @@ static BlockDriver bdrv_sheepdog = {
 .bdrv_needs_filename = true,
 .bdrv_file_open = sd_open,
 .bdrv_close = sd_close,
-.bdrv_create= sd_create,
+.bdrv_create2   = sd_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_getlength = sd_getlength,
 .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -2538,7 +2533,7 @@ static BlockDriver bdrv_sheepdog = {
 .bdrv_save_vmstate  = sd_save_vmstate,
 .bdrv_load_vmstate  = sd_load_vmstate,
 
-.create_options = sd_create_options,
+.create_opts   = &sd_create_opts,
 };
 
 static BlockDriver bdrv_sheepdog_tcp = {
@@ -2548,7 +2543,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
 .bdrv_needs_filename = true,
 .bdrv_file_open = sd_open,
 .bdrv_close = sd_close,
-.bdrv_create= sd_create,
+.bdrv_create

[Qemu-devel] [PATCH v20 22/26] vpc.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
vpc.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/vpc.c |   52 +++-
 1 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 1d326cb..f77f4a5 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -713,12 +713,12 @@ static int create_fixed_disk(int fd, uint8_t *buf, 
int64_t total_size)
 return ret;
 }
 
-static int vpc_create(const char *filename, QEMUOptionParameter *options,
+static int vpc_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 uint8_t buf[1024];
 VHDFooter *footer = (VHDFooter *) buf;
-QEMUOptionParameter *disk_type_param;
+const char *disk_type_param;
 int fd, i;
 uint16_t cyls = 0;
 uint8_t heads = 0;
@@ -729,13 +729,12 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 int ret = -EIO;
 
 /* Read out options */
-total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
-
-disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT);
-if (disk_type_param && disk_type_param->value.s) {
-if (!strcmp(disk_type_param->value.s, "dynamic")) {
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+if (disk_type_param) {
+if (!strcmp(disk_type_param, "dynamic")) {
 disk_type = VHD_DYNAMIC;
-} else if (!strcmp(disk_type_param->value.s, "fixed")) {
+} else if (!strcmp(disk_type_param, "fixed")) {
 disk_type = VHD_FIXED;
 } else {
 return -EINVAL;
@@ -841,20 +840,24 @@ static void vpc_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static QEMUOptionParameter vpc_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
-"Type of virtual hard disk format. Supported formats are "
-"{dynamic (default) | fixed} "
-},
-{ NULL }
+static QemuOptsList vpc_create_opts = {
+.name = "vpc-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help =
+"Type of virtual hard disk format. Supported formats are "
+"{dynamic (default) | fixed} "
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_vpc = {
@@ -865,14 +868,13 @@ static BlockDriver bdrv_vpc = {
 .bdrv_open  = vpc_open,
 .bdrv_close = vpc_close,
 .bdrv_reopen_prepare= vpc_reopen_prepare,
-.bdrv_create= vpc_create,
-
+.bdrv_create2   = vpc_create,
 .bdrv_read  = vpc_co_read,
 .bdrv_write = vpc_co_write,
 
 .bdrv_get_info  = vpc_get_info,
 
-.create_options = vpc_create_options,
+.create_opts= &vpc_create_opts,
 .bdrv_has_zero_init = vpc_has_zero_init,
 };
 
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 16/26] raw_bsd.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
raw_bsd.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/raw_bsd.c |   27 ---
 1 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 297e03f..4ae12dd 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -29,13 +29,17 @@
 #include "block/block_int.h"
 #include "qemu/option.h"
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{ 0 }
+static QemuOptsList raw_create_opts = {
+.name = "raw-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ /* end of list */ }
+}
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -133,19 +137,20 @@ static int raw_has_zero_init(BlockDriverState *bs)
 return bdrv_has_zero_init(bs->file);
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 Error *local_err = NULL;
 int ret;
 
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(errp, local_err);
 }
 return ret;
 }
 
+
 static int raw_open(BlockDriverState *bs, QDict *options, int flags,
 Error **errp)
 {
@@ -172,7 +177,7 @@ static BlockDriver bdrv_raw = {
 .bdrv_reopen_prepare  = &raw_reopen_prepare,
 .bdrv_open= &raw_open,
 .bdrv_close   = &raw_close,
-.bdrv_create  = &raw_create,
+.bdrv_create2 = &raw_create,
 .bdrv_co_readv= &raw_co_readv,
 .bdrv_co_writev   = &raw_co_writev,
 .bdrv_co_write_zeroes = &raw_co_write_zeroes,
@@ -188,7 +193,7 @@ static BlockDriver bdrv_raw = {
 .bdrv_lock_medium = &raw_lock_medium,
 .bdrv_ioctl   = &raw_ioctl,
 .bdrv_aio_ioctl   = &raw_aio_ioctl,
-.create_options   = &raw_create_options[0],
+.create_opts  = &raw_create_opts,
 .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 21/26] vmdk.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
vmdk.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/vmdk.c |  109 +
 1 files changed, 55 insertions(+), 54 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 97e6608..7188649 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1641,7 +1641,7 @@ static int filename_decompose(const char *filename, char 
*path, char *prefix,
 return VMDK_OK;
 }
 
-static int vmdk_create(const char *filename, QEMUOptionParameter *options,
+static int vmdk_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int idx = 0;
@@ -1691,22 +1691,17 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 goto exit;
 }
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_ADAPTER_TYPE)) {
-adapter_type = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_COMPAT6)) {
-flags |= options->value.n ? BLOCK_FLAG_COMPAT6 : 0;
-} else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
-fmt = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_ZEROED_GRAIN)) {
-zeroed_grain |= options->value.n;
-}
-options++;
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
+flags |= BLOCK_FLAG_COMPAT6;
+}
+fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
+zeroed_grain = true;
 }
+
 if (!adapter_type) {
 adapter_type = "ide";
 } else if (strcmp(adapter_type, "ide") &&
@@ -1825,7 +1820,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 if (!split && !flat) {
 desc_offset = 0x200;
 } else {
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not create image file");
 goto exit;
@@ -2020,41 +2015,47 @@ static ImageInfoSpecific 
*vmdk_get_specific_info(BlockDriverState *bs)
 return spec_info;
 }
 
-static QEMUOptionParameter vmdk_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_ADAPTER_TYPE,
-.type = OPT_STRING,
-.help = "Virtual adapter type, can be one of "
-"ide (default), lsilogic, buslogic or legacyESX"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_COMPAT6,
-.type = OPT_FLAG,
-.help = "VMDK version 6 image"
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
-"VMDK flat extent format, can be one of "
-"{monolithicSparse (default) | monolithicFlat | 
twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} "
-},
-{
-.name = BLOCK_OPT_ZEROED_GRAIN,
-.type = OPT_FLAG,
-.help = "Enable efficient zero writes using the zeroed-grain GTE 
feature"
-},
-{ NULL }
+static QemuOptsList vmdk_create_opts = {
+.name = "vmdk-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(vmdk_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_ADAPTER_TYPE,
+.type = QEMU_OPT_STRING,
+.help = "Virtual adapter type, can be one of "
+"ide (default), lsilogic, buslogic or legacyESX"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_COMPAT6,
+.type = QEMU_OPT_BOOL,
+.help = "VMDK version 6 image",
+.def_value_str = "off"
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help =
+"VMDK flat extent format, can be one of "
+"{monolithicSparse (default) | monolithicFlat | 
twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} "
+},
+{
+.name = BLOCK_

[Qemu-devel] [PATCH v20 19/26] ssh.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
ssh.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/ssh.c |   31 +++
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..8fd2175 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -642,16 +642,20 @@ static int ssh_file_open(BlockDriverState *bs, QDict 
*options, int bdrv_flags,
 return ret;
 }
 
-static QEMUOptionParameter ssh_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{ NULL }
+static QemuOptsList ssh_create_opts = {
+.name = "ssh-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ /* end of list */ }
+}
 };
 
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
+static int ssh_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 int r, ret;
@@ -665,12 +669,7 @@ static int ssh_create(const char *filename, 
QEMUOptionParameter *options,
 ssh_state_init(&s);
 
 /* Get desired file size. */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n;
-}
-options++;
-}
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
 DPRINTF("total_size=%" PRIi64, total_size);
 
 uri_options = qdict_new();
@@ -1044,14 +1043,14 @@ static BlockDriver bdrv_ssh = {
 .instance_size= sizeof(BDRVSSHState),
 .bdrv_parse_filename  = ssh_parse_filename,
 .bdrv_file_open   = ssh_file_open,
-.bdrv_create  = ssh_create,
+.bdrv_create2 = ssh_create,
 .bdrv_close   = ssh_close,
 .bdrv_has_zero_init   = ssh_has_zero_init,
 .bdrv_co_readv= ssh_co_readv,
 .bdrv_co_writev   = ssh_co_writev,
 .bdrv_getlength   = ssh_getlength,
 .bdrv_co_flush_to_disk= ssh_co_flush,
-.create_options   = ssh_create_options,
+.create_opts  = &ssh_create_opts,
 };
 
 static void bdrv_ssh_init(void)
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 17/26] rbd.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
rbd.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/rbd.c |   63 +--
 1 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index 121fae2..b23fe7b 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,7 +282,7 @@ static int qemu_rbd_set_conf(rados_t cluster, const char 
*conf)
 return ret;
 }
 
-static int qemu_rbd_create(const char *filename, QEMUOptionParameter *options,
+static int qemu_rbd_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int64_t bytes = 0;
@@ -306,24 +306,18 @@ static int qemu_rbd_create(const char *filename, 
QEMUOptionParameter *options,
 }
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-bytes = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-objsize = options->value.n;
-if ((objsize - 1) & objsize) {/* not a power of 2? */
-error_report("obj size needs to be power of 2");
-return -EINVAL;
-}
-if (objsize < 4096) {
-error_report("obj size too small");
-return -EINVAL;
-}
-obj_order = ffs(objsize) - 1;
-}
+bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+if (objsize) {
+if ((objsize - 1) & objsize) {/* not a power of 2? */
+error_report("obj size needs to be power of 2");
+return -EINVAL;
+}
+if (objsize < 4096) {
+error_report("obj size too small");
+return -EINVAL;
 }
-options++;
+obj_order = ffs(objsize) - 1;
 }
 
 clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -900,18 +894,23 @@ static BlockDriverAIOCB* 
qemu_rbd_aio_discard(BlockDriverState *bs,
 }
 #endif
 
-static QEMUOptionParameter qemu_rbd_create_options[] = {
-{
- .name = BLOCK_OPT_SIZE,
- .type = OPT_SIZE,
- .help = "Virtual disk size"
-},
-{
- .name = BLOCK_OPT_CLUSTER_SIZE,
- .type = OPT_SIZE,
- .help = "RBD object size"
-},
-{NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+.name = "rbd-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "RBD object size",
+.def_value_str = stringify(0),
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_rbd = {
@@ -920,10 +919,10 @@ static BlockDriver bdrv_rbd = {
 .bdrv_needs_filename = true,
 .bdrv_file_open = qemu_rbd_open,
 .bdrv_close = qemu_rbd_close,
-.bdrv_create= qemu_rbd_create,
+.bdrv_create2   = qemu_rbd_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_get_info  = qemu_rbd_getinfo,
-.create_options = qemu_rbd_create_options,
+.create_opts= qemu_rbd_create_opts,
 .bdrv_getlength = qemu_rbd_getlength,
 .bdrv_truncate  = qemu_rbd_truncate,
 .protocol_name  = "rbd",
-- 
1.6.0.2




[Qemu-devel] [PATCH v10 13/13] dump: add 'query-dump-guest-memory-capability' command

2014-02-11 Thread Qiao Nuohan

'query-dump-guest-memory-capability' is used to query the available formats for
'dump-guest-memory'. The output of the command will be like:

-> { "execute": "query-dump-guest-memory-capability" }
<- { "return": { "formats":
["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }

Signed-off-by: Qiao Nuohan 
---
 dump.c   |   33 +
 qapi-schema.json |   23 +++
 qmp-commands.hx  |   20 
 3 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/dump.c b/dump.c
index 2ebbb23..3a8d55e 100644
--- a/dump.c
+++ b/dump.c
@@ -1788,3 +1788,36 @@ void qmp_dump_guest_memory(bool paging, const char *file, 
bool has_begin,


 g_free(s);
 }
+
+DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
+{
+DumpGuestMemoryFormatList *item;
+DumpGuestMemoryCapability *cap =
+  g_malloc0(sizeof(DumpGuestMemoryCapability));
+
+/* elf is always available */
+item = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+cap->formats = item;
+item->value = DUMP_GUEST_MEMORY_FORMAT_ELF;
+
+/* kdump-zlib is always available */
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
+
+/* add new item if kdump-lzo is available */
+#ifdef CONFIG_LZO
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
+#endif
+
+/* add new item if kdump-snappy is available */
+#ifdef CONFIG_SNAPPY
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
+#endif
+
+return cap;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 7f62007..a097e6c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2783,6 +2783,29 @@
 '*length': 'int', '*format': 'DumpGuestMemoryFormat' } }

 ##
+# @DumpGuestMemoryCapability:
+#
+# A list of the available formats for dump-guest-memory
+#
+# Since: 2.0
+##
+{ 'type': 'DumpGuestMemoryCapability',
+  'data': {
+  'formats': ['DumpGuestMemoryFormat'] } }
+
+##
+# @query-dump-guest-memory-capability:
+#
+# Returns the available formats for dump-guest-memory
+#
+# Returns:  A @DumpGuestMemoryCapability object listing available formats for
+#   dump-guest-memory
+#
+# Since: 2.0
+##
+{ 'command': 'query-dump-guest-memory-capability', 'returns': 
'DumpGuestMemoryCapability' }

+
+##
 # @netdev_add:
 #
 # Add a network backend.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 019dde6..029cb3d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -829,6 +829,26 @@ Notes:
 EQMP

 {
+.name   = "query-dump-guest-memory-capability",
+.args_type  = "",
+.mhandler.cmd_new = 
qmp_marshal_input_query_dump_guest_memory_capability,
+},
+
+SQMP
+query-dump-guest-memory-capability
+--
+
+Show available formats for 'dump-guest-memory'
+
+Example:
+
+-> { "execute": "query-dump-guest-memory-capability" }
+<- { "return": { "formats":
+["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }
+
+EQMP
+
+{
 .name   = "netdev_add",
 .args_type  = "netdev:O",
 .mhandler.cmd_new = qmp_netdev_add,
--
1.7.1



[Qemu-devel] [PATCH v20 13/26] qed.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
qed.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/qed.c |   89 +--
 block/qed.h |3 +-
 2 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index 243c539..1d37519 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -619,7 +619,8 @@ out:
 return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
+
+static int bdrv_qed_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 uint64_t image_size = 0;
@@ -628,24 +629,14 @@ static int bdrv_qed_create(const char *filename, 
QEMUOptionParameter *options,
 const char *backing_file = NULL;
 const char *backing_fmt = NULL;
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
-backing_fmt = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-cluster_size = options->value.n;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_TABLE_SIZE)) {
-if (options->value.n) {
-table_size = options->value.n;
-}
-}
-options++;
-}
+image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+cluster_size = qemu_opt_get_size_del(opts,
+ BLOCK_OPT_CLUSTER_SIZE,
+ QED_DEFAULT_CLUSTER_SIZE);
+table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE,
+   QED_DEFAULT_TABLE_SIZE);
 
 if (!qed_is_cluster_size_valid(cluster_size)) {
 fprintf(stderr, "QED cluster size must be within range [%u, %u] and 
power of 2\n",
@@ -1573,43 +1564,51 @@ static int bdrv_qed_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return qed_check(s, result, !!fix);
 }
 
-static QEMUOptionParameter qed_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size (in bytes)"
-}, {
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-}, {
-.name = BLOCK_OPT_BACKING_FMT,
-.type = OPT_STRING,
-.help = "Image format of the base image"
-}, {
-.name = BLOCK_OPT_CLUSTER_SIZE,
-.type = OPT_SIZE,
-.help = "Cluster size (in bytes)",
-.value = { .n = QED_DEFAULT_CLUSTER_SIZE },
-}, {
-.name = BLOCK_OPT_TABLE_SIZE,
-.type = OPT_SIZE,
-.help = "L1/L2 table size (in clusters)"
-},
-{ /* end of list */ }
+static QemuOptsList qed_create_opts = {
+.name = "qed-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = "Image format of the base image"
+},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Cluster size (in bytes)",
+.def_value_str = stringify(QED_DEFAULT_CLUSTER_SIZE)
+},
+{
+.name = BLOCK_OPT_TABLE_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "L1/L2 table size (in clusters)"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_qed = {
 .format_name  = "qed",
 .instance_size= sizeof(BDRVQEDState),
-.create_options   = qed_create_options,
+.create_opts  = &qed_create_opts,
 
 .bdrv_probe   = bdrv_qed_probe,
 .bdrv_rebind  = bdrv_qed_rebind,
 .bdrv_open= bdrv_qed_open,
 .bdrv_close   = bdrv_qed_close,
 .bdrv_reopen_prepare  = bdrv_qed_reopen_prepare,
-.bdrv_create  = bdrv_qed_create,
+.bdrv_create2 = bdrv_qed_create,
 .bdrv_has_zero_init   = bdrv_has_zero_init_1,
 .bdrv_co_get_block_status = bdrv_qed_co_get_block_status,
 .bdrv_aio_readv   = bdrv_qed_aio_readv,
diff --git a/block/qed.h b/block/qed.h
index 5d65bea..b024751 100644
--- a/block/qed.h
++

[Qemu-devel] [PATCH v20 14/26] raw-posix.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
raw-posix.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/raw-posix.c |   58 
 1 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 126a634..e6af4ce 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1223,7 +1223,7 @@ static int64_t 
raw_get_allocated_file_size(BlockDriverState *bs)
 return (int64_t)st.st_blocks * 512;
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 int fd;
@@ -1231,12 +1231,8 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 int64_t total_size = 0;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-}
-options++;
-}
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -1397,13 +1393,17 @@ static int raw_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{ NULL }
+static QemuOptsList raw_create_opts = {
+.name = "raw-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_file = {
@@ -1417,7 +1417,7 @@ static BlockDriver bdrv_file = {
 .bdrv_reopen_commit = raw_reopen_commit,
 .bdrv_reopen_abort = raw_reopen_abort,
 .bdrv_close = raw_close,
-.bdrv_create = raw_create,
+.bdrv_create2 = raw_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_co_get_block_status = raw_co_get_block_status,
 .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1434,7 +1434,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_opts = &raw_create_opts,
 };
 
 /***/
@@ -1746,7 +1746,7 @@ static coroutine_fn int 
hdev_co_write_zeroes(BlockDriverState *bs,
 return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
+static int hdev_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int fd;
@@ -1755,12 +1755,8 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options,
 int64_t total_size = 0;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-}
-options++;
-}
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
 fd = qemu_open(filename, O_WRONLY | O_BINARY);
 if (fd < 0) {
@@ -1796,8 +1792,8 @@ static BlockDriver bdrv_host_device = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = &raw_create_opts,
 .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
 .bdrv_aio_readv= raw_aio_readv,
@@ -1930,8 +1926,8 @@ static BlockDriver bdrv_host_floppy = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = &raw_create_opts,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2041,8 +2037,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = &raw_create_opts,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2171,8 +2167,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reope

[Qemu-devel] [PATCH v20 15/26] raw-win32.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
raw-win32.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/raw-win32.c |   33 +
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index beb7f23..15ad3ad 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -464,19 +464,15 @@ static int64_t 
raw_get_allocated_file_size(BlockDriverState *bs)
 return st.st_size;
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
+static int raw_create(const char *filename, QemuOpts *opts,
   Error **errp)
 {
 int fd;
 int64_t total_size = 0;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / 512;
-}
-options++;
-}
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -490,13 +486,18 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{ NULL }
+
+static QemuOptsList raw_create_opts = {
+.name = "raw-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_file = {
@@ -506,7 +507,7 @@ static BlockDriver bdrv_file = {
 .bdrv_needs_filename = true,
 .bdrv_file_open= raw_open,
 .bdrv_close= raw_close,
-.bdrv_create   = raw_create,
+.bdrv_create2   = raw_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_aio_readv = raw_aio_readv,
@@ -518,7 +519,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_opts= &raw_create_opts,
 };
 
 /***/
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 24/26] vvfat.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
vvfat.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/vvfat.c |   10 +-
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index c59cbdb..81733bc 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2910,7 +2910,7 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
 BlockDriver *bdrv_qcow;
-QEMUOptionParameter *options;
+QemuOpts *opts;
 Error *local_err = NULL;
 int ret;
 int size = sector2cluster(s, s->sector_count);
@@ -2925,11 +2925,11 @@ static int enable_write_target(BDRVVVFATState *s)
 }
 
 bdrv_qcow = bdrv_find_format("qcow");
-options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
-set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
-set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
+opts = qemu_opts_create(bdrv_qcow->create_opts, NULL, 0, &error_abort);
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s->sector_count * 512);
+qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, "fat:");
 
-ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, NULL, &local_err);
+ret = bdrv_create(bdrv_qcow, s->qcow_filename, NULL, opts, &local_err);
 if (ret < 0) {
 qerror_report_err(local_err);
 error_free(local_err);
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 09/26] iscsi.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
iscsi.c: replace QEMUOptionParamter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/iscsi.c |   31 +++
 1 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 6f4af72..f94f935 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1377,13 +1377,8 @@ static int iscsi_create(const char *filename, 
QEMUOptionParameter *options,
 bs = bdrv_new("");
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-}
-options++;
-}
-
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 bs->opaque = g_malloc0(sizeof(struct IscsiLun));
 iscsilun = bs->opaque;
 
@@ -1434,13 +1429,17 @@ static int iscsi_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-static QEMUOptionParameter iscsi_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{ NULL }
+static QemuOptsList iscsi_create_opts = {
+.name = "iscsi-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_iscsi = {
@@ -1451,8 +1450,8 @@ static BlockDriver bdrv_iscsi = {
 .bdrv_needs_filename = true,
 .bdrv_file_open  = iscsi_open,
 .bdrv_close  = iscsi_close,
-.bdrv_create = iscsi_create,
-.create_options  = iscsi_create_options,
+.bdrv_create2= iscsi_create,
+.create_opts = iscsi_create_opts,
 .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
 .bdrv_getlength  = iscsi_getlength,
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 23/26] vhdx.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
vhdx.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/vhdx.c |   93 +++--
 block/vhdx.h |1 +
 2 files changed, 45 insertions(+), 49 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 23efc71..4815210 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1711,7 +1711,7 @@ exit:
  *. ~ --- ~  ~  ~ ---.
  *   1MB
  */
-static int vhdx_create(const char *filename, QEMUOptionParameter *options,
+static int vhdx_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int ret = 0;
@@ -1729,20 +1729,11 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 VHDXImageType image_type;
 Error *local_err = NULL;
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-image_size = options->value.n;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_LOG_SIZE)) {
-log_size = options->value.n;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_BLOCK_SIZE)) {
-block_size = options->value.n;
-} else if (!strcmp(options->name, BLOCK_OPT_SUBFMT)) {
-type = options->value.s;
-} else if (!strcmp(options->name, VHDX_BLOCK_OPT_ZERO)) {
-use_zero_blocks = options->value.n != 0;
-}
-options++;
-}
+image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, 0);
 
 if (image_size > VHDX_MAX_IMAGE_SIZE) {
 error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1791,7 +1782,7 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 block_size = block_size > VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
 block_size;
 
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
 goto exit;
@@ -1871,37 +1862,41 @@ static int vhdx_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return 0;
 }
 
-static QEMUOptionParameter vhdx_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size; max of 64TB."
-},
-{
-.name = VHDX_BLOCK_OPT_LOG_SIZE,
-.type = OPT_SIZE,
-.value.n = 1 * MiB,
-.help = "Log size; min 1MB."
-},
-{
-.name = VHDX_BLOCK_OPT_BLOCK_SIZE,
-.type = OPT_SIZE,
-.value.n = 0,
-.help = "Block Size; min 1MB, max 256MB. " \
-"0 means auto-calculate based on image size."
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
-"Default is 'dynamic'."
-},
-{
-.name = VHDX_BLOCK_OPT_ZERO,
-.type = OPT_FLAG,
-.help = "Force use of payload blocks of type 'ZERO'.  Non-standard."
-},
-{ NULL }
+static QemuOptsList vhdx_create_opts = {
+.name = "vhdx-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head),
+.desc = {
+{
+   .name = BLOCK_OPT_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .help = "Virtual disk size; max of 64TB."
+   },
+   {
+   .name = VHDX_BLOCK_OPT_LOG_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .def_value_str = stringify(DEFAULT_LOG_SIZE),
+   .help = "Log size; min 1MB."
+   },
+   {
+   .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .def_value_str = stringify(0),
+   .help = "Block Size; min 1MB, max 256MB. " \
+   "0 means auto-calculate based on image size."
+   },
+   {
+   .name = BLOCK_OPT_SUBFMT,
+   .type = QEMU_OPT_STRING,
+   .help = "VHDX format type, can be either 'dynamic' or 'fixed'. "\
+   "Default is 'dynamic'."
+   },
+   {
+   .name = VHDX_BLOCK_OPT_ZERO,
+   .type = QEMU_OPT_BOOL,
+   .help = "Force use of payload blocks of type 'ZERO'.  Non-standard."
+   },
+   { NULL }
+}
 };
 
 static BlockDriver bdrv_vhdx = {
@@ -1913,11 +1908,11 @@ static BlockDriver bdrv_vhdx = {
 .bdrv_reopen_prepare= vhdx_reopen_prepare,
 .bdrv_co_readv  = vhdx_co_readv,
 .bdrv_co_writev = vhdx_co_writev,
-.bdrv_create= vhdx_create,
+.bdrv_create2   = vhdx_create,
 .bdrv_get_info  = vhdx_

[Qemu-devel] [PATCH v20 12/26] qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options

2014-02-11 Thread Chunyan Liu
qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img amend'

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block.c   |4 +-
 block/qcow2.c |   90 
 include/block/block.h |2 +-
 include/block/block_int.h |2 +-
 qemu-img.c|   17 
 5 files changed, 53 insertions(+), 62 deletions(-)

diff --git a/block.c b/block.c
index 69cec2f..d6ddbd0 100644
--- a/block.c
+++ b/block.c
@@ -5382,12 +5382,12 @@ void bdrv_add_before_write_notifier(BlockDriverState 
*bs,
 notifier_with_return_list_add(&bs->before_write_notifiers, notifier);
 }
 
-int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
+int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts)
 {
 if (bs->drv->bdrv_amend_options == NULL) {
 return -ENOTSUP;
 }
-return bs->drv->bdrv_amend_options(bs, options);
+return bs->drv->bdrv_amend_options(bs, opts);
 }
 
 /* Used to recurse on single child block filters.
diff --git a/block/qcow2.c b/block/qcow2.c
index cab7097..a3afacb 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2045,65 +2045,57 @@ static int qcow2_downgrade(BlockDriverState *bs, int 
target_version)
 }
 
 static int qcow2_amend_options(BlockDriverState *bs,
-   QEMUOptionParameter *options)
+   QemuOpts *opts)
 {
 BDRVQcowState *s = bs->opaque;
 int old_version = s->qcow_version, new_version = old_version;
 uint64_t new_size = 0;
 const char *backing_file = NULL, *backing_format = NULL;
 bool lazy_refcounts = s->use_lazy_refcounts;
+const char *compat, *prealloc;
+uint64_t cluster_size = s->cluster_size;
+bool encrypt;
 int ret;
-int i;
 
-for (i = 0; options[i].name; i++)
-{
-if (!options[i].assigned) {
-/* only change explicitly defined options */
-continue;
-}
+compat = qemu_opt_get_del(opts, "compat");
+if (!compat) {
+/* preserve default */
+} else if (!strcmp(compat, "0.10")) {
+new_version = 2;
+} else if (!strcmp(compat, "1.1")) {
+new_version = 3;
+} else {
+fprintf(stderr, "Unknown compatibility level %s.\n", compat);
+return -EINVAL;
+}
 
-if (!strcmp(options[i].name, "compat")) {
-if (!options[i].value.s) {
-/* preserve default */
-} else if (!strcmp(options[i].value.s, "0.10")) {
-new_version = 2;
-} else if (!strcmp(options[i].value.s, "1.1")) {
-new_version = 3;
-} else {
-fprintf(stderr, "Unknown compatibility level %s.\n",
-options[i].value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options[i].name, "preallocation")) {
-fprintf(stderr, "Cannot change preallocation mode.\n");
-return -ENOTSUP;
-} else if (!strcmp(options[i].name, "size")) {
-new_size = options[i].value.n;
-} else if (!strcmp(options[i].name, "backing_file")) {
-backing_file = options[i].value.s;
-} else if (!strcmp(options[i].name, "backing_fmt")) {
-backing_format = options[i].value.s;
-} else if (!strcmp(options[i].name, "encryption")) {
-if ((options[i].value.n != !!s->crypt_method)) {
-fprintf(stderr, "Changing the encryption flag is not "
-"supported.\n");
-return -ENOTSUP;
-}
-} else if (!strcmp(options[i].name, "cluster_size")) {
-if (options[i].value.n != s->cluster_size) {
-fprintf(stderr, "Changing the cluster size is not "
-"supported.\n");
-return -ENOTSUP;
-}
-} else if (!strcmp(options[i].name, "lazy_refcounts")) {
-lazy_refcounts = options[i].value.n;
-} else {
-/* if this assertion fails, this probably means a new option was
- * added without having it covered here */
-assert(false);
-}
+prealloc = qemu_opt_get_del(opts, "preallocation");
+if (prealloc) {
+fprintf(stderr, "Cannot change preallocation mode.\n");
+return -ENOTSUP;
 }
 
+new_size = qemu_opt_get_size_del(opts, "size", 0);
+backing_file = qemu_opt_get_del(opts, "backing_file");
+backing_format = qemu_opt_get_del(opts, "backing_fmt");
+
+encrypt = qemu_opt_get_bool_del(opts, "encryption", s->crypt_method);
+if (encrypt != !!s->crypt_method) {
+fprintf(stderr, "Changing the encryption flag is not "
+"supported.\n");
+return -ENOTSUP;
+}
+
+cluster_size = qemu_opt_get_size_del(opts, "cluster_size", cluster_size);
+if (cluster_size != s->cluster_size) {
+fprintf(stderr, "Changing the cluster size is not 

[Qemu-devel] [PATCH v20 08/26] gluster.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
gluster.c: replace QEMUOptionParameter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/gluster.c |   80 --
 1 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index a009b15..edac27e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -380,13 +380,14 @@ static inline int qemu_gluster_zerofill(struct glfs_fd 
*fd, int64_t offset,
 #endif
 
 static int qemu_gluster_create(const char *filename,
-QEMUOptionParameter *options, Error **errp)
+   QemuOpts *opts, Error **errp)
 {
 struct glfs *glfs;
 struct glfs_fd *fd;
 int ret = 0;
 int prealloc = 0;
 int64_t total_size = 0;
+const char *tmp;
 GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
 glfs = qemu_gluster_init(gconf, filename);
@@ -395,24 +396,21 @@ static int qemu_gluster_create(const char *filename,
 goto out;
 }
 
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / BDRV_SECTOR_SIZE;
-} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
-if (!options->value.s || !strcmp(options->value.s, "off")) {
-prealloc = 0;
-} else if (!strcmp(options->value.s, "full") &&
-gluster_supports_zerofill()) {
-prealloc = 1;
-} else {
-error_setg(errp, "Invalid preallocation mode: '%s'"
-" or GlusterFS doesn't support zerofill API",
-   options->value.s);
-ret = -EINVAL;
-goto out;
-}
-}
-options++;
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+
+tmp = qemu_opt_get(opts, BLOCK_OPT_PREALLOC);
+if (!tmp || !strcmp(tmp, "off")) {
+prealloc = 0;
+} else if (!strcmp(tmp, "full") &&
+gluster_supports_zerofill()) {
+prealloc = 1;
+} else {
+error_setg(errp, "Invalid preallocation mode: '%s'"
+" or GlusterFS doesn't support zerofill API",
+tmp);
+ret = -EINVAL;
+goto out;
 }
 
 fd = glfs_creat(glfs, gconf->image,
@@ -597,18 +595,22 @@ static int qemu_gluster_has_zero_init(BlockDriverState 
*bs)
 return 0;
 }
 
-static QEMUOptionParameter qemu_gluster_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_PREALLOC,
-.type = OPT_STRING,
-.help = "Preallocation mode (allowed values: off, full)"
-},
-{ NULL }
+static QemuOptsList qemu_gluster_create_opts = {
+.name = "qemu-gluster-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = OPT_STRING,
+.help = "Preallocation mode (allowed values: off, full)"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_gluster = {
@@ -618,7 +620,7 @@ static BlockDriver bdrv_gluster = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create  = qemu_gluster_create,
+.bdrv_create2 = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -632,7 +634,7 @@ static BlockDriver bdrv_gluster = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
 .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes,
 #endif
-.create_options   = qemu_gluster_create_options,
+.create_opts  = qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
@@ -642,7 +644,7 @@ static BlockDriver bdrv_gluster_tcp = {
 .bdrv_needs_filename  = true,
 .bdrv_file_open   = qemu_gluster_open,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create  = qemu_gluster_create,
+.bdrv_create2 = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -656,7 +658,7 @@ static BlockDriver bdrv_gluster_tcp = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
 .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes,
 #endif
-.create_options   = qemu_gluster_create_options,
+.create_opts 

[Qemu-devel] [PATCH v20 11/26] qcow2.c: replace QEMUOptionParameter with QemuOpts in create

2014-02-11 Thread Chunyan Liu
qcow2.c: replace QEMUOptionParameter with QemuOpts in 'qemu-img create'.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/qcow2.c |  176 
 1 files changed, 88 insertions(+), 88 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 10702f1..cab7097 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1453,7 +1453,7 @@ static int preallocate(BlockDriverState *bs)
 static int qcow2_create2(const char *filename, int64_t total_size,
  const char *backing_file, const char *backing_format,
  int flags, size_t cluster_size, int prealloc,
- QEMUOptionParameter *options, int version,
+ QemuOpts *opts, int version,
  Error **errp)
 {
 /* Calculate cluster_bits */
@@ -1485,7 +1485,7 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
 Error *local_err = NULL;
 int ret;
 
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
 return ret;
@@ -1614,11 +1614,12 @@ out:
 return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
+static int qcow2_create(const char *filename, QemuOpts *opts,
 Error **errp)
 {
 const char *backing_file = NULL;
 const char *backing_fmt = NULL;
+const char *buf;
 uint64_t sectors = 0;
 int flags = 0;
 size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1628,45 +1629,38 @@ static int qcow2_create(const char *filename, 
QEMUOptionParameter *options,
 int ret;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-sectors = options->value.n / 512;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
-backing_fmt = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
-flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
-} else if (!strcmp(options->name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options->value.n) {
-cluster_size = options->value.n;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
-if (!options->value.s || !strcmp(options->value.s, "off")) {
-prealloc = 0;
-} else if (!strcmp(options->value.s, "metadata")) {
-prealloc = 1;
-} else {
-error_setg(errp, "Invalid preallocation mode: '%s'",
-   options->value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_COMPAT_LEVEL)) {
-if (!options->value.s) {
-/* keep the default */
-} else if (!strcmp(options->value.s, "0.10")) {
-version = 2;
-} else if (!strcmp(options->value.s, "1.1")) {
-version = 3;
-} else {
-error_setg(errp, "Invalid compatibility level: '%s'",
-   options->value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options->name, BLOCK_OPT_LAZY_REFCOUNTS)) {
-flags |= options->value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
-}
-options++;
+sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
+}
+cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
+ DEFAULT_CLUSTER_SIZE);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+if (!buf || !strcmp(buf, "off")) {
+prealloc = 0;
+} else if (!strcmp(buf, "metadata")) {
+prealloc = 1;
+} else {
+fprintf(stderr, "Invalid preallocation mode: '%s'\n",
+buf);
+return -EINVAL;
+}
+buf = NULL;
+buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);
+if (!buf || !strcmp(buf, "0.10")) {
+version = 2;
+} else if (!strcmp(buf, "1.1")) {
+version = 3;
+} else {
+fprintf(stderr, "Invalid compatibility level: '%s'\n",
+buf);
+return -EINVAL;
+}
+
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
 }
 
 if (backing_file && prealloc) {
@@ -1682,7 +1676,7 @@ static int qcow2_create(const char *filename, 
QEMUOptionParameter *options,
 }
 
 ret = qcow2_create2

[Qemu-devel] [PATCH v20 10/26] qcow.c: replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
qcow.c: replace QEMUOptionParamter with QemuOpts

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block/qcow.c |   61 -
 1 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 992eed4..519276e 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -659,7 +659,7 @@ static void qcow_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
+static int qcow_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int header_size, backing_filename_len, l1_size, shift, i;
@@ -673,18 +673,13 @@ static int qcow_create(const char *filename, 
QEMUOptionParameter *options,
 BlockDriverState *qcow_bs;
 
 /* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
-total_size = options->value.n / 512;
-} else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options->value.s;
-} else if (!strcmp(options->name, BLOCK_OPT_ENCRYPT)) {
-flags |= options->value.n ? BLOCK_FLAG_ENCRYPT : 0;
-}
-options++;
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
 }
 
-ret = bdrv_create_file(filename, options, NULL, &local_err);
+ret = bdrv_create_file(filename, NULL, opts, &local_err);
 if (ret < 0) {
 qerror_report_err(local_err);
 error_free(local_err);
@@ -879,24 +874,28 @@ static int qcow_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-
-static QEMUOptionParameter qcow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = "Virtual disk size"
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = "File name of a base image"
-},
-{
-.name = BLOCK_OPT_ENCRYPT,
-.type = OPT_FLAG,
-.help = "Encrypt the image"
-},
-{ NULL }
+static QemuOptsList qcow_create_opts = {
+.name = "qcow-create-opts",
+.head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = "File name of a base image"
+},
+{
+.name = BLOCK_OPT_ENCRYPT,
+.type = QEMU_OPT_BOOL,
+.help = "Encrypt the image",
+.def_value_str = "off"
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_qcow = {
@@ -906,7 +905,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_open = qcow_open,
 .bdrv_close= qcow_close,
 .bdrv_reopen_prepare = qcow_reopen_prepare,
-.bdrv_create   = qcow_create,
+.bdrv_create2   = qcow_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_co_readv  = qcow_co_readv,
@@ -918,7 +917,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_write_compressed  = qcow_write_compressed,
 .bdrv_get_info  = qcow_get_info,
 
-.create_options = qcow_create_options,
+.create_opts = &qcow_create_opts,
 };
 
 static void bdrv_qcow_init(void)
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 00/26] replace QEMUOptionParameter with QemuOpts

2014-02-11 Thread Chunyan Liu
This patch series is to replace QEMUOptionParameter with QemuOpts, so that only
one Qemu Option structure is kept in QEMU code.

---
Changes to v19:
  * fix format issue
  * according to Kevin's comments, add convert functions (params_to_opts and
opts_to_params) to simplify the block layer patch (patch 06/25), so that it
could be easier for review
  * add patch to remove assertion in qemu_opts_get function to fix vvfat issue
  * rebase to latest code
  * v19 is here:

https://lists.endsoftwarepatents.org/archive/html/qemu-devel/2014-01/msg02409.html

Chunyan Liu (26):
  add def_value_str to QemuOptDesc
  qapi: output def_value_str when query command line options
  improve some functions in qemu-option.c
  add some QemuOpts functions for replace work
  remove assertion of qemu_opt_get functions
  change block layer to support both QemuOpts and QEMUOptionParameter
  cow.c: replace QEMUOptionParameter with QemuOpts
  gluster.c: replace QEMUOptionParameter with QemuOpts
  iscsi.c: replace QEMUOptionParameter with QemuOpts
  qcow.c: replace QEMUOptionParameter with QemuOpts
  qcow2.c: replace QEMUOptionParameter with QemuOpts in create
  qcow2.c: replace QEMUOptionParameter with QemuOpts in amend options
  qed.c: replace QEMUOptionParameter with QemuOpts
  raw-posix.c: replace QEMUOptionParameter with QemuOpts
  raw-win32.c: replace QEMUOptionParameter with QemuOpts
  raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  rbd.c: replace QEMUOptionParameter with QemuOpts
  sheepdog.c: replace QEMUOptionParameter with QemuOpts
  ssh.c: replace QEMUOptionParameter with QemuOpts
  vdi.c: replace QEMUOptionParameter with QemuOpts
  vmdk.c: replace QEMUOptionParameter with QemuOpts
  vpc.c: replace QEMUOptionParameter with QemuOpts
  vhdx.c: replace QEMUOptionParameter with QemuOpts
  vvfat.c: replace QEMUOptionParameter with QemuOpts
  cleanup QEMUOptionParameter
  change back to original name from bdrv_create2 to bdrv_create

 block.c   |   95 
 block/cow.c   |   44 ++--
 block/gluster.c   |   78 ---
 block/iscsi.c |   29 ++--
 block/qcow.c  |   61 +++---
 block/qcow2.c |  262 +++---
 block/qed.c   |   89 
 block/qed.h   |3 +-
 block/raw-posix.c |   48 ++---
 block/raw-win32.c |   33 ++--
 block/raw_bsd.c   |   27 ++-
 block/rbd.c   |   63 +++---
 block/sheepdog.c  |  101 -
 block/ssh.c   |   31 ++--
 block/vdi.c   |   69 +++---
 block/vhdx.c  |   93 
 block/vhdx.h  |1 +
 block/vmdk.c  |  109 +-
 block/vpc.c   |   52 +++--
 block/vvfat.c |   10 +-
 include/block/block.h |8 +-
 include/block/block_int.h |7 +-
 include/qemu/option.h |   47 +---
 qapi-schema.json  |8 +-
 qemu-img.c|   89 
 qmp-commands.hx   |2 +
 util/qemu-config.c|4 +
 util/qemu-option.c|  547 -
 28 files changed, 955 insertions(+), 1055 deletions(-)




[Qemu-devel] [PATCH v20 03/26] improve some functions in qemu-option.c

2014-02-11 Thread Chunyan Liu
Improve opt_get and opt_set group of functions. For opt_get, check and handle
NUlL input; for opt_set, when set to an existing option, rewrite the option
with new value.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 util/qemu-option.c |   84 +++
 1 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index fd84f95..ea6793a 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -499,6 +499,9 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
*name)
 {
 QemuOpt *opt;
 
+if (!opts)
+return NULL;
+
 QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) {
 if (strcmp(opt->name, name) != 0)
 continue;
@@ -509,9 +512,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
*name)
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
 const QemuOptDesc *desc;
 
+if (!opts) {
+return NULL;
+}
+
+opt = qemu_opt_find(opts, name);
 if (!opt) {
 desc = find_desc_by_name(opts->list->desc, name);
 if (desc && desc->def_value_str) {
@@ -535,10 +543,16 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
 
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
 const QemuOptDesc *desc;
 Error *local_err = NULL;
 
+if (!opts) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
+
 if (opt == NULL) {
 desc = find_desc_by_name(opts->list->desc, name);
 if (desc && desc->def_value_str) {
@@ -553,10 +567,16 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
 const QemuOptDesc *desc;
 Error *local_err = NULL;
 
+if (!opts) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
+
 if (opt == NULL) {
 desc = find_desc_by_name(opts->list->desc, name);
 if (desc && desc->def_value_str) {
@@ -571,10 +591,15 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
 const QemuOptDesc *desc;
 Error *local_err = NULL;
 
+if (!opts) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
 if (opt == NULL) {
 desc = find_desc_by_name(opts->list->desc, name);
 if (desc && desc->def_value_str) {
@@ -612,6 +637,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
 
 static void qemu_opt_del(QemuOpt *opt)
 {
+if (!opt) {
+return;
+}
+
 QTAILQ_REMOVE(&opt->opts->head, opt, next);
 g_free((/* !const */ char*)opt->name);
 g_free((/* !const */ char*)opt->str);
@@ -664,6 +693,13 @@ static void opt_set(QemuOpts *opts, const char *name, 
const char *value,
 return;
 }
 
+opt = qemu_opt_find(opts, name);
+if (opt) {
+g_free((char *)opt->str);
+opt->str = g_strdup(value);
+return;
+}
+
 opt = g_malloc0(sizeof(*opt));
 opt->name = g_strdup(name);
 opt->opts = opts;
@@ -704,16 +740,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, 
const char *value,
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 {
 QemuOpt *opt;
-const QemuOptDesc *desc = opts->list->desc;
+const QemuOptDesc *desc;
 
-opt = g_malloc0(sizeof(*opt));
-opt->desc = find_desc_by_name(desc, name);
-if (!opt->desc && !opts_accepts_any(opts)) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (!desc && !opts_accepts_any(opts)) {
 qerror_report(QERR_INVALID_PARAMETER, name);
-g_free(opt);
 return -1;
 }
 
+opt = qemu_opt_find(opts, name);
+if (opt) {
+g_free((char *)opt->str);
+opt->value.boolean = val;
+opt->str = g_strdup(val ? "on" : "off");
+return 0;
+}
+
+opt = g_malloc0(sizeof(*opt));
+opt->desc = desc;
 opt->name = g_strdup(name);
 opt->opts = opts;
 opt->value.boolean = !!val;
@@ -726,16 +770,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, 
bool val)
 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 {
 QemuOpt *opt;
-const QemuOptDesc *desc = opts->list->desc;
+const QemuOptDesc *desc;
 
-opt = g_malloc0(sizeof(*opt));
-opt->desc = find_desc_by_name(desc, name);
-if (!opt->desc && !opts_accepts_any(opts)) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (!desc && !opts_accepts_any(opts)) {
 qerror_report(QERR_INVALID_PARAMETER, name);
-g_free(opt);
 return -1;
 

[Qemu-devel] [PATCH v20 05/26] remove assertion of qemu_opt_get functions

2014-02-11 Thread Chunyan Liu
In qemu_opt_set functions, if desc doen't exist but opts_accepts_any is true, it
won't report error, but can still alloc an opt for the option and save it.
However, after that, when doing qemu_opt_get, this option could be found in opts
but opt->desc is NULL. This is correct, should not be treated as error.

This patch would fix vvfat issue after changing to QemuOpts.

Signed-off-by: Chunyan Liu 
---
 util/qemu-option.c |3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 21699d0..c51c55d 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -641,7 +641,6 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 }
 return defval;
 }
-assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
 
@@ -675,7 +674,6 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 }
 return defval;
 }
-assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
 return opt->value.uint;
 }
 
@@ -710,7 +708,6 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 }
 return defval;
 }
-assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
 return opt->value.uint;
 }
 
-- 
1.6.0.2




[Qemu-devel] [PATCH v20 06/26] change block layer to support both QemuOpts and QEMUOptionParameter

2014-02-11 Thread Chunyan Liu
Change block layer to support both QemuOpts and QEMUOptionParameter.
After this patch, it will change backend drivers one by one. At the end,
QEMUOptionParameter will be removed and only QemuOpts is kept.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 block.c   |  110 
 block/cow.c   |2 +-
 block/qcow.c  |2 +-
 block/qcow2.c |2 +-
 block/qed.c   |2 +-
 block/raw_bsd.c   |2 +-
 block/vhdx.c  |2 +-
 block/vmdk.c  |4 +-
 block/vvfat.c |2 +-
 include/block/block.h |4 +-
 include/block/block_int.h |4 +-
 include/qemu/option.h |2 +
 qemu-img.c|   87 +--
 util/qemu-option.c|  111 +
 14 files changed, 250 insertions(+), 86 deletions(-)

diff --git a/block.c b/block.c
index cb21a5f..69cec2f 100644
--- a/block.c
+++ b/block.c
@@ -408,6 +408,7 @@ typedef struct CreateCo {
 BlockDriver *drv;
 char *filename;
 QEMUOptionParameter *options;
+QemuOpts *opts;
 int ret;
 Error *err;
 } CreateCo;
@@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 CreateCo *cco = opaque;
 assert(cco->drv);
 
-ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+if (cco->drv->bdrv_create2) {
+ret = cco->drv->bdrv_create2(cco->filename, cco->opts, &local_err);
+} else {
+ret = cco->drv->bdrv_create(cco->filename, cco->options, &local_err);
+}
 if (error_is_set(&local_err)) {
 error_propagate(&cco->err, local_err);
 }
@@ -428,7 +433,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-QEMUOptionParameter *options, Error **errp)
+QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
 {
 int ret;
 
@@ -437,11 +442,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
 .drv = drv,
 .filename = g_strdup(filename),
 .options = options,
+.opts = opts,
 .ret = NOT_DONE,
 .err = NULL,
 };
 
-if (!drv->bdrv_create) {
+if (!drv->bdrv_create && !drv->bdrv_create2) {
 error_setg(errp, "Driver '%s' does not support image creation", 
drv->format_name);
 ret = -ENOTSUP;
 goto out;
@@ -473,7 +479,7 @@ out:
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+ QemuOpts *opts, Error **errp)
 {
 BlockDriver *drv;
 Error *local_err = NULL;
@@ -485,7 +491,7 @@ int bdrv_create_file(const char* filename, 
QEMUOptionParameter *options,
 return -ENOENT;
 }
 
-ret = bdrv_create(drv, filename, options, &local_err);
+ret = bdrv_create(drv, filename, options, opts, &local_err);
 if (error_is_set(&local_err)) {
 error_propagate(errp, local_err);
 }
@@ -1246,7 +1252,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
QDict *options,
 BlockDriverState *bs1;
 int64_t total_size;
 BlockDriver *bdrv_qcow2;
-QEMUOptionParameter *create_options;
+QEMUOptionParameter *create_options = NULL;
+QemuOpts *opts = NULL;
 QDict *snapshot_options;
 
 /* if snapshot, we create a temporary backing file and open it
@@ -1273,13 +1280,21 @@ int bdrv_open(BlockDriverState *bs, const char 
*filename, QDict *options,
 }
 
 bdrv_qcow2 = bdrv_find_format("qcow2");
-create_options = parse_option_parameters("", 
bdrv_qcow2->create_options,
- NULL);
-
-set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
+if (bdrv_qcow2->bdrv_create2) {
+opts = qemu_opts_create(bdrv_qcow2->create_opts, NULL, 0,
+&error_abort);
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+} else {
+create_options =
+parse_option_parameters("", bdrv_qcow2->create_options, NULL);
+set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
+ total_size);
+}
 
-ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, 
&local_err);
+ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
+  &local_err);
 free_option_parameters(create_options);
+qemu_opts_del(opts);
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not create temporary overlay "
  "'%s': %s", tmp_filename,
@@ -5197,7 +5212,10 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
  Error **errp, bool quiet)
 {
 QEMUOptionParameter *param = NUL

[Qemu-devel] [PATCH v20 01/26] add def_value_str to QemuOptDesc

2014-02-11 Thread Chunyan Liu
Add def_value_str (default value) to QemuOptDesc, to replace function of the
default value in QEMUOptionParameter. And improved related functions.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 include/qemu/option.h |3 +-
 util/qemu-option.c|   76 ++--
 2 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3ea871a..2c5b03f 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -97,6 +97,7 @@ typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
+const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
@@ -154,7 +155,7 @@ QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
 void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
-int qemu_opts_print(QemuOpts *opts, void *dummy);
+void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 668e5d9..fd84f95 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,9 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/option_int.h"
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+const char *name);
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -507,6 +510,14 @@ static QemuOpt *qemu_opt_find(QemuOpts *opts, const char 
*name)
 const char *qemu_opt_get(QemuOpts *opts, const char *name)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+
+if (!opt) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+return desc->def_value_str;
+}
+}
 return opt ? opt->str : NULL;
 }
 
@@ -525,9 +536,17 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_bool(name, desc->def_value_str, &defval, &local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
@@ -535,9 +554,17 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_number(name, desc->def_value_str, &defval, 
&local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
 return opt->value.uint;
 }
@@ -545,9 +572,17 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
+const QemuOptDesc *desc;
+Error *local_err = NULL;
 
-if (opt == NULL)
+if (opt == NULL) {
+desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_size(name, desc->def_value_str, &defval, &local_err);
+assert(!local_err);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
 return opt->value.uint;
 }
@@ -846,17 +881,38 @@ void qemu_opts_del(QemuOpts *opts)
 g_free(opts);
 }
 
-int qemu_opts_print(QemuOpts *opts, void *dummy)
+void qemu_opts_print(QemuOpts *opts)
 {
 QemuOpt *opt;
+QemuOptDesc *desc = opts->list->desc;
 
-fprintf(stderr, "%s: %s:", opts->list->name,
-opts->id ? opts->id : "");
-QTAILQ_FOREACH(opt, &opts->head, next) {
-fprintf(stderr, " %s=\"%s\"", opt->name, opt->str);
+if (desc[0].name == NULL) {
+QTAILQ_FOREACH(opt, &opts->head, next) {
+printf("%s=\"%s\" ", opt->name, opt->str);
+}
+return;
+}
+for (; desc && desc->name; desc++) {
+const char *value = desc->def_value_str;
+QemuOpt *opt;
+
+opt = qemu_opt_find(opts, desc->name);
+if (opt) {
+value = opt->str;
+}
+
+if (!value) {
+continue;
+}
+
+if (desc

[Qemu-devel] [PATCH v20 04/26] add some QemuOpts functions for replace work

2014-02-11 Thread Chunyan Liu
Add some qemu_opt functions to replace the same functionality of
QEMUOptionParameter handling.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 include/qemu/option.h |9 +++
 util/qemu-option.c|  134 +
 2 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 2c5b03f..3957604 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -109,6 +109,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
@@ -124,6 +125,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t 
defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+ uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+   uint64_t defval);
 int qemu_opt_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -159,4 +165,7 @@ void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index ea6793a..21699d0 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -379,6 +379,74 @@ QEMUOptionParameter 
*append_option_parameters(QEMUOptionParameter *dest,
 return dest;
 }
 
+static size_t count_opts_list(QemuOptsList *list)
+{
+QemuOptDesc *desc = NULL;
+size_t num_opts = 0;
+
+if (!list) {
+return 0;
+}
+
+desc = list->desc;
+while (desc && desc->name) {
+num_opts++;
+desc++;
+}
+
+return num_opts;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both lists can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+   QemuOptsList *list)
+{
+size_t num_opts, num_dst_opts;
+QemuOptsList *tmp;
+QemuOptDesc *desc;
+
+if (!dst && !list) {
+return NULL;
+}
+
+num_opts = count_opts_list(dst);
+num_opts += count_opts_list(list);
+tmp = g_malloc0(sizeof(QemuOptsList) +
+(num_opts + 1) * sizeof(QemuOptDesc));
+QTAILQ_INIT(&tmp->head);
+num_dst_opts = 0;
+
+/* copy dst->desc to new list */
+if (dst) {
+desc = dst->desc;
+while (desc && desc->name) {
+tmp->desc[num_dst_opts++] = *desc;
+tmp->desc[num_dst_opts].name = NULL;
+desc++;
+}
+}
+
+/* add list->desc to new list */
+if (list) {
+desc = list->desc;
+while (desc && desc->name) {
+if (find_desc_by_name(tmp->desc, desc->name) == NULL) {
+tmp->desc[num_dst_opts++] = *desc;
+tmp->desc[num_dst_opts].name = NULL;
+}
+desc++;
+}
+}
+
+return tmp;
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -529,6 +597,18 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 return opt ? opt->str : NULL;
 }
 
+static void qemu_opt_del(QemuOpt *opt);
+
+const char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+const char *str = qemu_opt_get(opts, name);
+QemuOpt *opt = qemu_opt_find(opts, name);
+if (opt) {
+qemu_opt_del(opt);
+}
+return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts *opts)
 {
 QemuOpt *opt;
@@ -565,6 +645,16 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 return opt->value.boolean;
 }
 
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval)
+{
+bool ret = qemu_opt_get_bool(opts, name, defval);
+QemuOpt *opt = qemu_opt_find(opts, name);
+if (opt) {
+qemu_opt_del(opt);
+}
+return ret;
+}
+
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
 QemuOpt *opt;
@@ -

[Qemu-devel] [PATCH v20 02/26] qapi: output def_value_str when query command line options

2014-02-11 Thread Chunyan Liu
Change qapi interfaces to output the newly added def_value_str when query
command line options.

Signed-off-by: Dong Xu Wang 
Signed-off-by: Chunyan Liu 
---
 qapi-schema.json   |8 ++--
 qmp-commands.hx|2 ++
 util/qemu-config.c |4 
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 05ced9d..45b40ca 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3930,12 +3930,16 @@
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
-# Since 1.5
+# @default: #optional string representation of the default used
+#   if the option is omitted.
+#
+# Since 1.6
 ##
 { 'type': 'CommandLineParameterInfo',
   'data': { 'name': 'str',
 'type': 'CommandLineParameterType',
-'*help': 'str' } }
+'*help': 'str',
+'*default': 'str'} }
 
 ##
 # @CommandLineOptionInfo:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index cce6b81..9220a19 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2792,6 +2792,8 @@ Each array entry contains the following:
   or 'size')
 - "help": human readable description of the parameter
   (json-string, optional)
+- "default": default value string for the parameter
+ (json-string, optional)
 
 Example:
 
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 9298f55..66295b9 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,6 +68,10 @@ static CommandLineParameterInfoList 
*query_option_descs(const QemuOptDesc *desc)
 info->has_help = true;
 info->help = g_strdup(desc[i].help);
 }
+if (desc[i].def_value_str) {
+info->has_q_default = true;
+info->q_default = g_strdup(desc[i].def_value_str);
+}
 
 entry = g_malloc0(sizeof(*entry));
 entry->value = info;
-- 
1.6.0.2




Re: [Qemu-devel] [PATCH target-arm v5 4/5] arm: Implement reset GPIO.

2014-02-11 Thread Peter Crosthwaite
On Tue, Jan 28, 2014 at 7:22 PM, Peter Maydell  wrote:
> On 28 January 2014 00:48, Peter Crosthwaite
>  wrote:
>> On Tue, Jan 28, 2014 at 3:52 AM, Peter Maydell  
>> wrote:
>>> On 15 January 2014 09:14, Peter Crosthwaite
>>>  wrote:
 Implement a reset GPIO for ARM CPUs. This allows individual reset of ARM
 CPUs from device land without the need for the much unwanted reset API
 calls.

 The CPU is halted as long as the pin is held in reset. Releasing the
 reset starts the CPU running again.
>>>
 +static void arm_cpu_reset_gpio(void *opaque, int irq, int level)
 +{
 +CPUState *cpu = opaque;
 +
 +if (level) {
 +cpu_reset(cpu);
 +cpu_interrupt(cpu, CPU_INTERRUPT_HALT);
 +} else {
 +cpu_reset_interrupt(cpu, CPU_INTERRUPT_HALT);
 +cpu_interrupt(cpu, CPU_INTERRUPT_EXITTB);
 +}
 +}
>>>
>>> I don't think this will work properly. For instance,
>>> cpu_exec() will bring the CPU out of halt if an inbound
>>> interrupt arrives, but we should stay in reset until
>>> the reset line is deasserted.
>>>
>>
>> I see. I guess I'm going to have to save the reset pin state as a
>> boolean in CPU state (and I guess that means is should be migratable).
>> Then inhibit the true return from cpu_has_work when the pin is
>> asserted.
>
> Maybe we can do it with a CPU_INTERRUPT_RESET ?
>
>>> Also ideally speaking we should probably do the reset
>>> actions on the falling edge of reset, not the rising edge.
>>>
>>
>> Any particular reason? I would have thought that any externally
>> visible state would best be reset ASAP. For level sensitive behavior,
>> the transitionals should happen going into the active level. Unless
>> ARM CPU resets are actually falling edge sensitive (in which case the
>> CPU would continue to run while the reset is held).
>
> I'm not an expert here, but what I thought happened was:
>  * on asserting edge of reset CPU stops running and starts
>resetting its internal state
>  * on real hardware you have to hold the line asserted for N clocks
>for this to finish
>  * on deasserting edge of reset, CPU samples config lines
>and starts running again
>
> so you should be able to say 'assert reset; change state of
> configuration signals; deassert reset', for instance. (On QEMU
> that would probably be 'assert reset; change r/w QOM properties;
> deassert reset'). Slightly less theoretically, M-class CPUs do
> the initial read of the PC from memory in cpu_reset(), so if you
> do that on asserting edge then you prevent "hold CPU in reset
> and modify the vector table before releasing CPU".
>
> So at least some of what we do in cpu_reset() ought I think
> to be done only on deasserting; unless you really want to
> split reset into two phases, it seems easiest just to hold the
> CPU not-running while reset is asserted and call cpu_reset()
> when it is deasserted.
>
>>> Does this work properly when we're running under KVM
>>> rather than using the TCG CPU?
>>
>> I must confess no, I explicitly LOG_UNIMP for KVM, as I have no means
>> to develop or test ARM KVM.
>
> I definitely don't want to take this if it doesn't cope with KVM.
> I guess I'll have to take a look at how that would work.
>

Is it as simple as a call to kvm_reset_vcpu?

Regards,
Peter

>>> Is there anything really ARM-specific in this reset_gpio
>>> function, or could it be implemented at a common level for
>>> all target architectures?
>>>
>>
>> Not yet, but probably will be ARM specific once I add the cpu reset
>> pin state. Unless Andreas is happy for that pin state and all this
>> code to go up to the base TYPE_CPU class.
>
> It might be possible for most of the mechanics to be shared
> (CPU_INTERRUPT_RESET and what setting/clearing it does),
> just not the gpio pin.
>
>> I wonder however, whether different arch will have level/edge/high/low
>> variances in reset behavior that must be accommodated.
>
> Mmm.
>
> thanks
> -- PMM
>



[Qemu-devel] [PATCH target-arm v1 2/2] char/cadence_uart: Add NULL guards against chr

2014-02-11 Thread Peter Crosthwaite
It's possible and valid for users of this device model to instantiate
it without a backing chr device. To avoid crashes, guard all uses of
the backing chr device against NULL.

Signed-off-by: Peter Crosthwaite 
---

 hw/char/cadence_uart.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 1985047..10abb4d 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -175,8 +175,10 @@ static void uart_send_breaks(UartState *s)
 {
 int break_enabled = 1;
 
-qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
-   &break_enabled);
+if (s->chr) {
+qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_BREAK,
+  &break_enabled);
+}
 }
 
 static void uart_parameters_setup(UartState *s)
@@ -227,7 +229,9 @@ static void uart_parameters_setup(UartState *s)
 
 packet_size += ssp.data_bits + ssp.stop_bits;
 s->char_tx_time = (get_ticks_per_sec() / ssp.speed) * packet_size;
-qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+if (s->chr) {
+qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
+}
 }
 
 static int uart_can_receive(void *opaque)
@@ -377,7 +381,9 @@ static void uart_read_rx_fifo(UartState *s, uint32_t *c)
 *c = s->rx_fifo[rx_rpos];
 s->rx_count--;
 
-qemu_chr_accept_input(s->chr);
+if (s->chr) {
+qemu_chr_accept_input(s->chr);
+}
 } else {
 *c = 0;
 }
-- 
1.8.5.4




[Qemu-devel] [PATCH target-arm v1 1/2] char/cadence_uart: Handle qemu_chr_fe_write errors

2014-02-11 Thread Peter Crosthwaite
By just ignoring them and trying again later. This handles the
EGAIN case properly (the previous implementation was only dealing
with short returns and not errors).

Signed-off-by: Peter Crosthwaite 
---

 hw/char/cadence_uart.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 1012f1a..1985047 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -302,8 +302,11 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, 
GIOCondition cond,
 }
 
 ret = qemu_chr_fe_write(s->chr, s->tx_fifo, s->tx_count);
-s->tx_count -= ret;
-memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count);
+
+if (ret >= 0) {
+s->tx_count -= ret;
+memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count);
+}
 
 if (s->tx_count) {
 int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT, cadence_uart_xmit, s);
-- 
1.8.5.4




[Qemu-devel] [PATCH target-arm v1 0/2] More Cadence UART fixes

2014-02-11 Thread Peter Crosthwaite

Hi Peter,

Two fixes to Cadence UART. First is a bug in the recently refactored
TX code path around error handling.

Second is the long known crashing-cadence-UART bug when there in no
backing serial device (i.e. boot a kernel that talks to serial without
adding -serial args).

Chris recently reported the second issue to me offline.

Chris,

Please test to see if this a resolution to your issue.

Regards,
Peter


Peter Crosthwaite (2):
  char/cadence_uart: Handle qemu_chr_fe_write errors
  char/cadence_uart: Add NULL guards against chr

 hw/char/cadence_uart.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

-- 
1.8.5.4




Re: [Qemu-devel] [PATCH v9 13/13] dump: add 'query-dump-guest-memory-capability' command

2014-02-11 Thread Eric Blake
On 02/11/2014 08:13 PM, Qiao Nuohan wrote:
> 'query-dump-guest-memory-capability' is used to query the available
> formats of
> 'dump-guest-memory'. The output of the command will be like:
> 
> -> { "execute": "query-dump-guest-memory-capability" }
> <- { "return": { "formats":
> ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }
> 
> Signed-off-by: Qiao Nuohan 
> ---
>  dump.c   |   33 +
>  qapi-schema.json |9 +
>  qmp-commands.hx  |   23 +++
>  3 files changed, 65 insertions(+), 0 deletions(-)


> +++ b/qapi-schema.json
> @@ -2783,6 +2783,15 @@
>  '*length': 'int', '*format': 'DumpGuestMemoryFormat' } }
> 
>  ##
> +# Since: 2.0

A bit sparse on the documentation; at a minimum, you want a line:

# @query-dump-guest-memory-capability:

prior to the Since designation (look at @query-name for an example).


> +
> +SQMP
> +query-dump-guest-memory-capability
> +--
> +
> +Show available format of 'dump-guest-memory'

s/format of/formats for/

> +
> +Example:
> +
> +-> { "execute": "query-dump-guest-memory-capability" }
> +<- { "return": { "formats":
> +["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }
> +
> +Note: This is a light-weight introspection to let management know the
> available
> +  formats of dump-guest-memory.

This note feels a bit redundant with the earlier summary; I'm okay if
you leave it in, but I also don't mind if you drop it.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v9 13/13] dump: add 'query-dump-guest-memory-capability' command

2014-02-11 Thread Qiao Nuohan

'query-dump-guest-memory-capability' is used to query the available formats of
'dump-guest-memory'. The output of the command will be like:

-> { "execute": "query-dump-guest-memory-capability" }
<- { "return": { "formats":
["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }

Signed-off-by: Qiao Nuohan 
---
 dump.c   |   33 +
 qapi-schema.json |9 +
 qmp-commands.hx  |   23 +++
 3 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/dump.c b/dump.c
index 2ebbb23..3a8d55e 100644
--- a/dump.c
+++ b/dump.c
@@ -1788,3 +1788,36 @@ void qmp_dump_guest_memory(bool paging, const char *file, 
bool has_begin,


 g_free(s);
 }
+
+DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
+{
+DumpGuestMemoryFormatList *item;
+DumpGuestMemoryCapability *cap =
+  g_malloc0(sizeof(DumpGuestMemoryCapability));
+
+/* elf is always available */
+item = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+cap->formats = item;
+item->value = DUMP_GUEST_MEMORY_FORMAT_ELF;
+
+/* kdump-zlib is always available */
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_ZLIB;
+
+/* add new item if kdump-lzo is available */
+#ifdef CONFIG_LZO
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_LZO;
+#endif
+
+/* add new item if kdump-snappy is available */
+#ifdef CONFIG_SNAPPY
+item->next = g_malloc0(sizeof(DumpGuestMemoryFormatList));
+item = item->next;
+item->value = DUMP_GUEST_MEMORY_FORMAT_KDUMP_SNAPPY;
+#endif
+
+return cap;
+}
diff --git a/qapi-schema.json b/qapi-schema.json
index 7f62007..5d13bb3 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2783,6 +2783,15 @@
 '*length': 'int', '*format': 'DumpGuestMemoryFormat' } }

 ##
+# Since: 2.0
+##
+{ 'type': 'DumpGuestMemoryCapability',
+  'data': {
+  'formats': ['DumpGuestMemoryFormat'] } }
+
+{ 'command': 'query-dump-guest-memory-capability', 'returns': 
'DumpGuestMemoryCapability' }

+
+##
 # @netdev_add:
 #
 # Add a network backend.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 019dde6..1f9ff69 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -829,6 +829,29 @@ Notes:
 EQMP

 {
+.name   = "query-dump-guest-memory-capability",
+.args_type  = "",
+.mhandler.cmd_new = 
qmp_marshal_input_query_dump_guest_memory_capability,
+},
+
+SQMP
+query-dump-guest-memory-capability
+--
+
+Show available format of 'dump-guest-memory'
+
+Example:
+
+-> { "execute": "query-dump-guest-memory-capability" }
+<- { "return": { "formats":
+["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] }
+
+Note: This is a light-weight introspection to let management know the available
+  formats of dump-guest-memory.
+
+EQMP
+
+{
 .name   = "netdev_add",
 .args_type  = "netdev:O",
 .mhandler.cmd_new = qmp_netdev_add,
--
1.7.1



[Qemu-devel] [PATCH v3] QMP: Allow dot separated dict path arguments in qmp-shell

2014-02-11 Thread Fam Zheng
As another convinience to allow using commands that expect a dict as
argument, this patch adds support for foo.bar=value syntax, similar to
command line argument style:

  (QEMU) blockdev-add options.driver=file options.id=drive1 options.filename=...

Signed-off-by: Fam Zheng 

---
v3: Fix error message wording. (Eric)
v2: Fix variable usage and improved error check and report.

Applies on top of Stefan's patch

[PATCH] QMP: allow JSON dict arguments in qmp-shell

Signed-off-by: Fam Zheng 
---
 scripts/qmp/qmp-shell | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index d374b35..e0e848b 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -112,13 +112,29 @@ class QMPShell(qmp.QEMUMonitorProtocol):
 value = json.loads(opt[1])
 else:
 value = opt[1]
-qmpcmd['arguments'][opt[0]] = value
+optpath = opt[0].split('.')
+parent = qmpcmd['arguments']
+curpath = []
+for p in optpath[:-1]:
+curpath.append(p)
+d = parent.get(p, {})
+if type(d) is not dict:
+raise QMPShellError('Cannot use "%s" as both leaf and 
non-leaf key' % '.'.join(curpath))
+parent[p] = d
+parent = d
+if optpath[-1] in parent:
+if type(parent[optpath[-1]]) is dict:
+raise QMPShellError('Cannot use "%s" as both leaf and 
non-leaf key' % '.'.join(curpath))
+else:
+raise QMPShellError('Cannot set "%s" multiple times' % 
opt[0])
+parent[optpath[-1]] = value
 return qmpcmd
 
 def _execute_cmd(self, cmdline):
 try:
 qmpcmd = self.__build_cmd(cmdline)
-except:
+except Exception, e:
+print 'Error while parsing command line: %s' % e
 print 'command format:  ',
 print '[arg-name1=arg1] ... [arg-nameN=argN]'
 return True
-- 
1.8.5.4




Re: [Qemu-devel] [PATCH target-arm v5 1/1] target-arm: Implements the ARM PMCCNTR register

2014-02-11 Thread Alistair Francis
Ping

On Fri, Jan 31, 2014 at 2:44 PM, Alistair Francis
 wrote:
> This patch implements the ARM PMCCNTR register including
> the disable and reset components of the PMCR register.
>
> Signed-off-by: Alistair Francis 
> ---
> This patch assumes that non-invasive debugging is not permitted
> when determining if the counter is disabled
> V5: Implement the actual write function to make sure that
> migration works correctly. Also includes the raw_read/write as
> the normal read/write functions depend on the pmcr register. So
> they don't allow for the pmccntr register to be written first.
> V4: Some bug fixes pointed out by Peter Crosthwaite. Including
> increasing the accuracy of the timer.
> V3: Fixed up incorrect reset, disable and enable handling that
> was submitted in V2. The patch should now also handle changing
> of the clock scaling.
> V2: Incorporated the comments that Peter Maydell and Peter
> Crosthwaite had. Now the implementation only requires one
> CPU state
>
>  target-arm/cpu.h|4 ++
>  target-arm/helper.c |   95 +-
>  2 files changed, 97 insertions(+), 2 deletions(-)
>
> diff --git a/target-arm/cpu.h b/target-arm/cpu.h
> index 198b6b8..5f96a4d 100644
> --- a/target-arm/cpu.h
> +++ b/target-arm/cpu.h
> @@ -215,6 +215,10 @@ typedef struct CPUARMState {
>  uint32_t c15_diagnostic; /* diagnostic register */
>  uint32_t c15_power_diagnostic;
>  uint32_t c15_power_control; /* power control */
> +/* If the counter is enabled, this stores the last time the counter
> + * was reset. Otherwise it stores the counter value
> + */
> +uint32_t c15_ccnt;
>  } cp15;
>
>  /* System registers (AArch64) */
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index c708f15..090953a 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -13,6 +13,12 @@ static inline int get_phys_addr(CPUARMState *env, uint32_t 
> address,
>  target_ulong *page_size);
>  #endif
>
> +/* Definitions for the PMCCNTR and PMCR registers */
> +#define PMCRDP  0x20
> +#define PMCRD   0x8
> +#define PMCRC   0x4
> +#define PMCRE   0x1
> +
>  static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
>  {
>  int nregs;
> @@ -502,12 +508,46 @@ static int pmreg_read(CPUARMState *env, const 
> ARMCPRegInfo *ri,
>  static int pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>uint64_t value)
>  {
> +uint32_t temp_ticks;
> +
>  if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
>  return EXCP_UDEF;
>  }
> +
> +temp_ticks = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) *
> +  get_ticks_per_sec() / 100;
> +
> +/* This assumes that non-invasive debugging is not permitted */
> +if (!(env->cp15.c9_pmcr & PMCRDP) ||
> +env->cp15.c9_pmcr & PMCRE) {
> +/* If the counter is enabled */
> +if (env->cp15.c9_pmcr & PMCRDP) {
> +/* Increment once every 64 processor clock cycles */
> +env->cp15.c15_ccnt = (temp_ticks/64) - env->cp15.c15_ccnt;
> +} else {
> +env->cp15.c15_ccnt = temp_ticks - env->cp15.c15_ccnt;
> +}
> +}
> +
> +if (value & PMCRC) {
> +/* The counter has been reset */
> +env->cp15.c15_ccnt = 0;
> +}
> +
>  /* only the DP, X, D and E bits are writable */
>  env->cp15.c9_pmcr &= ~0x39;
>  env->cp15.c9_pmcr |= (value & 0x39);
> +
> +/* This assumes that non-invasive debugging is not permitted */
> +if (!(env->cp15.c9_pmcr & PMCRDP) ||
> +env->cp15.c9_pmcr & PMCRE) {
> +if (env->cp15.c9_pmcr & PMCRDP) {
> +/* Increment once every 64 processor clock cycles */
> +temp_ticks /= 64;
> +}
> +env->cp15.c15_ccnt = temp_ticks - env->cp15.c15_ccnt;
> +}
> +
>  return 0;
>  }
>
> @@ -584,6 +624,56 @@ static int vbar_write(CPUARMState *env, const 
> ARMCPRegInfo *ri,
>  return 0;
>  }
>
> +static int pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri,
> +   uint64_t *value)
> +{
> +uint32_t total_ticks;
> +
> +/* This assumes that non-invasive debugging is not permitted */
> +if (env->cp15.c9_pmcr & PMCRDP ||
> +!(env->cp15.c9_pmcr & PMCRE)) {
> +/* Counter is disabled, do not change value */
> +*value = env->cp15.c15_ccnt;
> +return 0;
> +}
> +
> +total_ticks = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL) *
> +  get_ticks_per_sec() / 100;
> +
> +if (env->cp15.c9_pmcr & PMCRDP) {
> +/* Increment once every 64 processor clock cycles */
> +total_ticks /= 64;
> +}
> +*value = total_ticks - env->cp15.c15_ccnt;
> +
> +return 0;
> +}
> +
> +static int pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri,
> +uint64_t value)
> +{
> +uint32_t total_ticks;
> +
> +/* This assu

[Qemu-devel] Ping for patch "linux-user: add binfmt wrapper for argv[0] handling"

2014-02-11 Thread Dennis Lan (dlan)
Hi Folks:
   Any chance to get this patch accepted into master branch?
I found it useful when chroot into another system. Origianl post can
be found here[1], would be quite easy to forward port to latest code.

[1] https://lists.gnu.org/archive/html/qemu-devel/2011-09/msg03841.html



Re: [Qemu-devel] [PATCH v2] QMP: Allow dot separated dict path arguments in qmp-shell

2014-02-11 Thread Eric Blake
On 02/11/2014 06:22 PM, Fam Zheng wrote:
> As another convinience to allow using commands that expect a dict as

s/convinience/convenience/

> argument, this patch adds support for foo.bar=value syntax, similar to
> command line argument style:
> 
>   (QEMU) blockdev-add options.driver=file options.id=drive1 
> options.filename=...
> 
> Signed-off-by: Fam Zheng 

> +if type(d) is not dict:
> +raise QMPShellError('Can not use "%s" as both leaf and 
> non-leaf key' % '.'.join(curpath))

s/Can not/Cannot/

> +parent[p] = d
> +parent = d
> +if optpath[-1] in parent:
> +if type(parent[optpath[-1]]) is dict:
> +raise QMPShellError('Can not use "%s" as both leaf and 
> non-leaf key' % '.'.join(curpath))
> +else:
> +raise QMPShellError('Can not set "%s" for multiple 
> times' % opt[0])

twice more.  Also, s/for //

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v5 RESEND 3/4] raw-posix: Add full image preallocation option

2014-02-11 Thread Hu Tao
On Tue, Feb 11, 2014 at 05:04:09PM +0800, Fam Zheng wrote:
> On Tue, 02/11 15:07, Hu Tao wrote:
> > This patch adds a new option preallocation for raw format, and implements
> > full preallocation.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  block/raw-posix.c | 43 +++
> >  1 file changed, 35 insertions(+), 8 deletions(-)
> > 
> > diff --git a/block/raw-posix.c b/block/raw-posix.c
> > index 01fb41a..1961b74 100644
> > --- a/block/raw-posix.c
> > +++ b/block/raw-posix.c
> > @@ -1229,11 +1229,22 @@ static int raw_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  int fd;
> >  int result = 0;
> >  int64_t total_size = 0;
> > +PreallocMode prealloc = PREALLOC_MODE_OFF;
> >  
> >  /* Read out options */
> >  while (options && options->name) {
> >  if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> >  total_size = options->value.n & BDRV_SECTOR_MASK;
> > +} else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
> > +if (!options->value.s || !strcmp(options->value.s, "off")) {
> > +prealloc = PREALLOC_MODE_OFF;
> > +} else if (!strcmp(options->value.s, "full")) {
> > +prealloc = PREALLOC_MODE_FULL;
> > +} else {
> > +error_setg(errp, "Invalid preallocation mode: '%s'",
> > +   options->value.s);
> > +return -EINVAL;
> > +}
> >  }
> >  options++;
> >  }
> > @@ -1243,16 +1254,27 @@ static int raw_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  if (fd < 0) {
> >  result = -errno;
> >  error_setg_errno(errp, -result, "Could not create file");
> > -} else {
> > -if (ftruncate(fd, total_size) != 0) {
> > -result = -errno;
> > -error_setg_errno(errp, -result, "Could not resize file");
> > -}
> > -if (qemu_close(fd) != 0) {
> > -result = -errno;
> > -error_setg_errno(errp, -result, "Could not close the new 
> > file");
> > +goto out;
> > +}
> > +if (ftruncate(fd, total_size) != 0) {
> > +result = -errno;
> > +error_setg_errno(errp, -result, "Could not resize file");
> > +goto out_close;
> > +}
> > +if (prealloc == PREALLOC_MODE_FULL) {
> > +/* posix_fallocate() doesn't set errno. */
> > +result = -posix_fallocate(fd, 0, total_size);
> > +if (result != 0) {
> > +error_setg_errno(errp, -result,
> > + "Could not preallocate data for the new 
> > file");
> >  }
> >  }
> > +out_close:
> > +if (qemu_close(fd) != 0) {
> > +result = -errno;
> > +error_setg_errno(errp, -result, "Could not close the new file");
> 
> If errp is already set because ftruncate or posix_ftruncate failed, and
> qemu_close() fails too, the call to error_setg_errno() will abort on failing
> the assertion of (*errp == NULL).

The original code also has the problem. This brings a general problem
that two error_setg_errno() could be called on the same errp. In general
the first error is better to reveal to user.

> 
> You could either embed the two failures in one error message, or pick the
> urgent one and drop the other.
> 
> Thanks,
> Fam
> 
> > +}
> > +out:
> >  return result;
> >  }
> >  
> > @@ -1403,6 +1425,11 @@ static QEMUOptionParameter raw_create_options[] = {
> >  .type = OPT_SIZE,
> >  .help = "Virtual disk size"
> >  },
> > +{
> > +.name = BLOCK_OPT_PREALLOC,
> > +.type = OPT_STRING,
> > +.help = "Preallocation mode (allowed values: off, full)"
> > +},
> >  { NULL }
> >  };
> >  
> > -- 
> > 1.8.0
> > 



Re: [Qemu-devel] [PATCH v5 RESEND 1/4] qapi: introduce PreallocMode and a new PreallocMode full.

2014-02-11 Thread Hu Tao
On Tue, Feb 11, 2014 at 06:20:03AM -0700, Eric Blake wrote:
> On 02/11/2014 12:07 AM, Hu Tao wrote:
> > This patch prepares for the subsequent patches.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  block/qcow2.c|  8 
> >  qapi-schema.json | 12 
> >  2 files changed, 16 insertions(+), 4 deletions(-)
> 
> > +++ b/qapi-schema.json
> > @@ -4419,3 +4419,15 @@
> >  # Since: 1.7
> >  ##
> >  { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
> > +
> > +##
> > +# @PreallocMode
> > +#
> > +# Preallocation mode of QEMU image file
> > +#
> > +# @off: no preallocation
> > +# @metadata: preallocate only for metadata
> > +# @full: preallocate all data, including metadata
> 
> Missing a line:
> # Since 2.0

Thanks.



Re: [Qemu-devel] [PATCH v5 RESEND 2/4] raw, qcow2: don't convert file size to sector size

2014-02-11 Thread Hu Tao
On Tue, Feb 11, 2014 at 04:53:30PM +0800, Fam Zheng wrote:
> On Tue, 02/11 15:07, Hu Tao wrote:
> > and avoid convert it back later.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  block/qcow2.c | 8 
> >  block/raw-posix.c | 4 ++--
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/block/qcow2.c b/block/qcow2.c
> > index 30e36bc..e4bab70 100644
> > --- a/block/qcow2.c
> > +++ b/block/qcow2.c
> > @@ -1569,7 +1569,7 @@ static int qcow2_create2(const char *filename, 
> > int64_t total_size,
> >  }
> >  
> >  /* Okay, now that we have a valid image, let's give it the right size 
> > */
> > -ret = bdrv_truncate(bs, total_size * BDRV_SECTOR_SIZE);
> > +ret = bdrv_truncate(bs, total_size);
> >  if (ret < 0) {
> >  error_setg_errno(errp, -ret, "Could not resize image");
> >  goto out;
> > @@ -1619,7 +1619,7 @@ static int qcow2_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  {
> >  const char *backing_file = NULL;
> >  const char *backing_fmt = NULL;
> > -uint64_t sectors = 0;
> > +uint64_t size = 0;
> >  int flags = 0;
> >  size_t cluster_size = DEFAULT_CLUSTER_SIZE;
> >  PreallocMode prealloc = PREALLOC_MODE_OFF;
> > @@ -1630,7 +1630,7 @@ static int qcow2_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  /* Read out options */
> >  while (options && options->name) {
> >  if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> > -sectors = options->value.n / 512;
> > +size = options->value.n & BDRV_SECTOR_MASK;
> >  } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
> >  backing_file = options->value.s;
> >  } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FMT)) {
> > @@ -1681,7 +1681,7 @@ static int qcow2_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  return -EINVAL;
> >  }
> >  
> > -ret = qcow2_create2(filename, sectors, backing_file, backing_fmt, 
> > flags,
> > +ret = qcow2_create2(filename, size, backing_file, backing_fmt, flags,
> >  cluster_size, prealloc, options, version, 
> > &local_err);
> >  if (error_is_set(&local_err)) {
> >  error_propagate(errp, local_err);
> > diff --git a/block/raw-posix.c b/block/raw-posix.c
> > index 126a634..01fb41a 100644
> > --- a/block/raw-posix.c
> > +++ b/block/raw-posix.c
> > @@ -1233,7 +1233,7 @@ static int raw_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  /* Read out options */
> >  while (options && options->name) {
> >  if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> > -total_size = options->value.n / BDRV_SECTOR_SIZE;
> > +total_size = options->value.n & BDRV_SECTOR_MASK;
> >  }
> >  options++;
> >  }
> > @@ -1244,7 +1244,7 @@ static int raw_create(const char *filename, 
> > QEMUOptionParameter *options,
> >  result = -errno;
> >  error_setg_errno(errp, -result, "Could not create file");
> >  } else {
> > -if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
> > +if (ftruncate(fd, total_size) != 0) {
> >  result = -errno;
> >  error_setg_errno(errp, -result, "Could not resize file");
> >  }
> > -- 
> > 1.8.0
> > 
> 
> Why not change raw-win32.c as well? Otherwise it will be confusing when
> total_size means differently in two counterpart files.

Makes sense to make it consistent in all places.

> 
> Thanks,
> Fam



[Qemu-devel] [PATCH v2] QMP: Allow dot separated dict path arguments in qmp-shell

2014-02-11 Thread Fam Zheng
As another convinience to allow using commands that expect a dict as
argument, this patch adds support for foo.bar=value syntax, similar to
command line argument style:

  (QEMU) blockdev-add options.driver=file options.id=drive1 options.filename=...

Signed-off-by: Fam Zheng 

---
v2: Fix variable usage and improved error check and report.

Applies on top of Stefan's patch

[PATCH] QMP: allow JSON dict arguments in qmp-shell

Signed-off-by: Fam Zheng 
---
 scripts/qmp/qmp-shell | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index d374b35..62bdcda 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -112,13 +112,29 @@ class QMPShell(qmp.QEMUMonitorProtocol):
 value = json.loads(opt[1])
 else:
 value = opt[1]
-qmpcmd['arguments'][opt[0]] = value
+optpath = opt[0].split('.')
+parent = qmpcmd['arguments']
+curpath = []
+for p in optpath[:-1]:
+curpath.append(p)
+d = parent.get(p, {})
+if type(d) is not dict:
+raise QMPShellError('Can not use "%s" as both leaf and 
non-leaf key' % '.'.join(curpath))
+parent[p] = d
+parent = d
+if optpath[-1] in parent:
+if type(parent[optpath[-1]]) is dict:
+raise QMPShellError('Can not use "%s" as both leaf and 
non-leaf key' % '.'.join(curpath))
+else:
+raise QMPShellError('Can not set "%s" for multiple times' 
% opt[0])
+parent[optpath[-1]] = value
 return qmpcmd
 
 def _execute_cmd(self, cmdline):
 try:
 qmpcmd = self.__build_cmd(cmdline)
-except:
+except Exception, e:
+print 'Error while parsing command line: %s' % e
 print 'command format:  ',
 print '[arg-name1=arg1] ... [arg-nameN=argN]'
 return True
-- 
1.8.5.4




[Qemu-devel] [RFC/RFT v1 2/2] cris: axis_dev88: QOMify NAND controller

2014-02-11 Thread Peter Crosthwaite
First step QOMficiation of the Axis NAND controller. Setup the memory
regions properly as per sysbus.

Signed-off-by: Peter Crosthwaite 
---

 hw/cris/axis_dev88.c | 38 ++
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 645e45c..46d7c2a 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -39,6 +39,10 @@
 
 struct nand_state_t
 {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public > */
+
 DeviceState *nand;
 MemoryRegion iomem;
 unsigned int rdy:1;
@@ -47,6 +51,11 @@ struct nand_state_t
 unsigned int ce:1;
 };
 
+#define TYPE_AXIS_DEV88_NAND "axis-dev88-nand"
+
+#define AXIS_DEV88_NAND(obj) \
+OBJECT_CHECK(struct nand_state_t, (obj), TYPE_AXIS_DEV88_NAND)
+
 static struct nand_state_t nand_state;
 static uint64_t nand_read(void *opaque, hwaddr addr, unsigned size)
 {
@@ -82,6 +91,21 @@ static const MemoryRegionOps nand_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static void axis_dev88_nand_init(Object *obj)
+{
+struct nand_state_t *ns = AXIS_DEV88_NAND(obj);
+
+memory_region_init_io(&ns->iomem, NULL, &nand_ops, ns, "nand", 0x0500);
+sysbus_init_mmio(SYS_BUS_DEVICE(obj), &ns->iomem);
+}
+
+static const TypeInfo axis_dev88_nand_info = {
+.name   = TYPE_AXIS_DEV88_NAND,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size  = sizeof(struct nand_state_t),
+.instance_init  = axis_dev88_nand_init,
+};
+
 struct tempsensor_t
 {
 unsigned int shiftreg;
@@ -238,6 +262,13 @@ static const MemoryRegionOps gpio_ops = {
 },
 };
 
+static void axis_dev88_register(void)
+{
+type_register_static(&axis_dev88_nand_info);
+}
+
+type_init(axis_dev88_register)
+
 #define INTMEM_SIZE (128 * 1024)
 
 static struct cris_load_info li;
@@ -281,13 +312,12 @@ void axisdev88_init(QEMUMachineInitArgs *args)
 memory_region_add_subregion(address_space_mem, 0x3800, phys_intmem);
 
   /* Attach a NAND flash to CS1.  */
+object_initialize(&nand_state, sizeof(nand_state), TYPE_AXIS_DEV88_NAND);
+sysbus_mmio_map(SYS_BUS_DEVICE(&nand_state), 0, 0x1000);
 nand = drive_get(IF_MTD, 0, 0);
 nand_state.nand = nand_init(nand ? nand->bdrv : NULL,
 NAND_MFR_STMICRO, 0x39);
-memory_region_init_io(&nand_state.iomem, NULL, &nand_ops, &nand_state,
-  "nand", 0x0500);
-memory_region_add_subregion(address_space_mem, 0x1000,
-&nand_state.iomem);
+object_property_set_bool(OBJECT(&nand_state), true, "realized", NULL);
 
 gpio_state.nand = &nand_state;
 memory_region_init_io(&gpio_state.iomem, NULL, &gpio_ops, &gpio_state,
-- 
1.8.5.4




[Qemu-devel] [RFC/RFT v1 1/2] arm: tosa: QOMify NAND/display/irq controller

2014-02-11 Thread Peter Crosthwaite
First step QOMficiation of the tosa IO controller (NAND display and
interrupts. Setup the memory regions and IRQ properly as per sysbus.

Signed-off-by: Peter Crosthwaite 
---

 hw/arm/tosa.c | 12 ++--
 hw/display/tc6393xb.c | 36 +---
 include/hw/devices.h  |  2 --
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
index c00d8c2..941ab4d 100644
--- a/hw/arm/tosa.c
+++ b/hw/arm/tosa.c
@@ -227,8 +227,16 @@ static void tosa_init(QEMUMachineInitArgs *args)
 memory_region_set_readonly(rom, true);
 memory_region_add_subregion(address_space_mem, 0, rom);
 
-tmio = tc6393xb_init(address_space_mem, 0x1000,
-qdev_get_gpio_in(mpu->gpio, TOSA_GPIO_TC6393XB_INT));
+/*
+ * FIXME: remove this fishy cast when the board gets some
+ * more QOMification
+ */
+tmio = (TC6393xbState *)object_new("TC6393xb");
+sysbus_mmio_map(SYS_BUS_DEVICE(tmio), 0, 0x1000);
+sysbus_mmio_map(SYS_BUS_DEVICE(tmio), 1, 0x1010);
+sysbus_connect_irq(SYS_BUS_DEVICE(tmio), 0,
+   qdev_get_gpio_in(mpu->gpio, TOSA_GPIO_TC6393XB_INT));
+object_property_set_bool(OBJECT(tmio), true, "realized", NULL);
 
 scp0 = sysbus_create_simple("scoop", 0x0880, NULL);
 scp1 = sysbus_create_simple("scoop", 0x14800040, NULL);
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
index 3dd9b98..f78a9d0 100644
--- a/hw/display/tc6393xb.c
+++ b/hw/display/tc6393xb.c
@@ -12,6 +12,7 @@
  */
 #include "hw/hw.h"
 #include "hw/devices.h"
+#include "hw/sysbus.h"
 #include "hw/block/flash.h"
 #include "ui/console.h"
 #include "ui/pixel_ops.h"
@@ -82,6 +83,10 @@
 #define NAND_MODE_ECC_RST   0x60
 
 struct TC6393xbState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
 MemoryRegion iomem;
 qemu_irq irq;
 qemu_irq *sub_irqs;
@@ -134,6 +139,11 @@ struct TC6393xbState {
  blanked : 1;
 };
 
+#define TYPE_TC6393XB "TC6393xb"
+
+#define TC6393XB(obj) \
+OBJECT_CHECK(TC6393xbState, (obj), TYPE_TC6393XB)
+
 qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s)
 {
 return s->gpio_in;
@@ -552,9 +562,9 @@ static const GraphicHwOps tc6393xb_gfx_ops = {
 .gfx_update  = tc6393xb_update_display,
 };
 
-TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t base, qemu_irq irq)
+static void tc6393xb_init(Object *obj)
 {
-TC6393xbState *s;
+TC6393xbState *s = TC6393XB(obj);
 DriveInfo *nand;
 static const MemoryRegionOps tc6393xb_ops = {
 .read = tc6393xb_readb,
@@ -566,8 +576,7 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, uint32_t 
base, qemu_irq irq)
 },
 };
 
-s = (TC6393xbState *) g_malloc0(sizeof(TC6393xbState));
-s->irq = irq;
+sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
 s->gpio_in = qemu_allocate_irqs(tc6393xb_gpio_set, s, TC6393XB_GPIOS);
 
 s->l3v = *qemu_allocate_irqs(tc6393xb_l3v, s, 1);
@@ -579,15 +588,28 @@ TC6393xbState *tc6393xb_init(MemoryRegion *sysmem, 
uint32_t base, qemu_irq irq)
 s->flash = nand_init(nand ? nand->bdrv : NULL, NAND_MFR_TOSHIBA, 0x76);
 
 memory_region_init_io(&s->iomem, NULL, &tc6393xb_ops, s, "tc6393xb", 
0x1);
-memory_region_add_subregion(sysmem, base, &s->iomem);
+sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
 
 memory_region_init_ram(&s->vram, NULL, "tc6393xb.vram", 0x10);
 vmstate_register_ram_global(&s->vram);
 s->vram_ptr = memory_region_get_ram_ptr(&s->vram);
-memory_region_add_subregion(sysmem, base + 0x10, &s->vram);
+sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->vram);
+
 s->scr_width = 480;
 s->scr_height = 640;
 s->con = graphic_console_init(NULL, &tc6393xb_gfx_ops, s);
+}
 
-return s;
+static const TypeInfo tc6393xb_info = {
+.name   = TYPE_TC6393XB,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size  = sizeof(TC6393xbState),
+.instance_init  = tc6393xb_init,
+};
+
+static void tc6393xb_register(void)
+{
+type_register_static(&tc6393xb_info);
 }
+
+type_init(tc6393xb_register)
diff --git a/include/hw/devices.h b/include/hw/devices.h
index c60bcab..d3c1108 100644
--- a/include/hw/devices.h
+++ b/include/hw/devices.h
@@ -55,8 +55,6 @@ void retu_key_event(void *retu, int state);
 /* tc6393xb.c */
 typedef struct TC6393xbState TC6393xbState;
 #define TC6393XB_RAM   0x11 /* amount of ram for Video and USB */
-TC6393xbState *tc6393xb_init(struct MemoryRegion *sysmem,
- uint32_t base, qemu_irq irq);
 void tc6393xb_gpio_out_set(TC6393xbState *s, int line,
 qemu_irq handler);
 qemu_irq *tc6393xb_gpio_in_get(TC6393xbState *s);
-- 
1.8.5.4




[Qemu-devel] [RFC/RFT v1 0/2] NAND QOMification - Round 1

2014-02-11 Thread Peter Crosthwaite
Or perhaps even round 0.5 ...

Hi Andreas,

I have a work-in-progress lengthy series that moves towards the full
QOMification and BUSification of NAND. This will allow a few things:

Attachment of multiple nand devs to one controller.
Centralised CS GPIO control.
info qtree sanity

These patches are stylisitic updates to existing code needed before
starting the big change. They also bring us closer to full QOMification
irrespective on NAND anyway.

Regards,
Peter


Peter Crosthwaite (2):
  arm: tosa: QOMify NAND/display/irq controller
  cris: axis_dev88: QOMify NAND controller

 hw/arm/tosa.c | 12 ++--
 hw/cris/axis_dev88.c  | 38 ++
 hw/display/tc6393xb.c | 36 +---
 include/hw/devices.h  |  2 --
 4 files changed, 73 insertions(+), 15 deletions(-)

-- 
1.8.5.4




[Qemu-devel] [PULL] target-openrisc: Use new qemu_ld/st opcodes

2014-02-11 Thread Jia Liu
From: Richard Henderson 

Signed-off-by: Richard Henderson 
Acked-by: Jia Liu 
Signed-off-by: Jia Liu 
---
 target-openrisc/translate.c | 99 +++--
 1 file changed, 32 insertions(+), 67 deletions(-)

diff --git a/target-openrisc/translate.c b/target-openrisc/translate.c
index b381477..776cb6e 100644
--- a/target-openrisc/translate.c
+++ b/target-openrisc/translate.c
@@ -707,6 +707,8 @@ static void dec_misc(DisasContext *dc, uint32_t insn)
 uint32_t L6, K5;
 #endif
 uint32_t I16, I5, I11, N26, tmp;
+TCGMemOp mop;
+
 op0 = extract32(insn, 26, 6);
 op1 = extract32(insn, 24, 2);
 ra = extract32(insn, 16, 5);
@@ -838,72 +840,46 @@ static void dec_misc(DisasContext *dc, uint32_t insn)
 /*#ifdef TARGET_OPENRISC64
 case 0x20: l.ld
 LOG_DIS("l.ld r%d, r%d, %d\n", rd, ra, I16);
-{
-check_ob64s(dc);
-TCGv_i64 t0 = tcg_temp_new_i64();
-tcg_gen_addi_i64(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld64(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free_i64(t0);
-}
-break;
+check_ob64s(dc);
+mop = MO_TEQ;
+goto do_load;
 #endif*/
 
 case 0x21:/* l.lwz */
 LOG_DIS("l.lwz r%d, r%d, %d\n", rd, ra, I16);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld32u(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_TEUL;
+goto do_load;
 
 case 0x22:/* l.lws */
 LOG_DIS("l.lws r%d, r%d, %d\n", rd, ra, I16);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld32s(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_TESL;
+goto do_load;
 
 case 0x23:/* l.lbz */
 LOG_DIS("l.lbz r%d, r%d, %d\n", rd, ra, I16);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld8u(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_UB;
+goto do_load;
 
 case 0x24:/* l.lbs */
 LOG_DIS("l.lbs r%d, r%d, %d\n", rd, ra, I16);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld8s(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_SB;
+goto do_load;
 
 case 0x25:/* l.lhz */
 LOG_DIS("l.lhz r%d, r%d, %d\n", rd, ra, I16);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld16u(cpu_R[rd], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_TEUW;
+goto do_load;
 
 case 0x26:/* l.lhs */
 LOG_DIS("l.lhs r%d, r%d, %d\n", rd, ra, I16);
+mop = MO_TESW;
+goto do_load;
+
+do_load:
 {
 TCGv t0 = tcg_temp_new();
 tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(I16, 16));
-tcg_gen_qemu_ld16s(cpu_R[rd], t0, dc->mem_idx);
+tcg_gen_qemu_ld_tl(cpu_R[rd], t0, dc->mem_idx, mop);
 tcg_temp_free(t0);
 }
 break;
@@ -1042,42 +1018,31 @@ static void dec_misc(DisasContext *dc, uint32_t insn)
 /*#ifdef TARGET_OPENRISC64
 case 0x34: l.sd
 LOG_DIS("l.sd %d, r%d, r%d, %d\n", I5, ra, rb, I11);
-{
-check_ob64s(dc);
-TCGv_i64 t0 = tcg_temp_new_i64();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16));
-tcg_gen_qemu_st64(cpu_R[rb], t0, dc->mem_idx);
-tcg_temp_free_i64(t0);
-}
-break;
+check_ob64s(dc);
+mop = MO_TEQ;
+goto do_store;
 #endif*/
 
 case 0x35:/* l.sw */
 LOG_DIS("l.sw %d, r%d, r%d, %d\n", I5, ra, rb, I11);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16));
-tcg_gen_qemu_st32(cpu_R[rb], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_TEUL;
+goto do_store;
 
 case 0x36:/* l.sb */
 LOG_DIS("l.sb %d, r%d, r%d, %d\n", I5, ra, rb, I11);
-{
-TCGv t0 = tcg_temp_new();
-tcg_gen_addi_tl(t0, cpu_R[ra], sign_extend(tmp, 16));
-tcg_gen_qemu_st8(cpu_R[rb], t0, dc->mem_idx);
-tcg_temp_free(t0);
-}
-break;
+mop = MO_UB;
+goto do_store;
 
 case 0x37:/* l.sh */
 LOG_DIS("l.sh %d, r%d, r%d, %d\n", I5, ra, rb, I11);
+mop = MO_TEUW;
+goto do_store;
+
+do_store:
  

[Qemu-devel] [PULL] OpenRISC patch queue for 1.8

2014-02-11 Thread Jia Liu

Hi Anthony,

This is my OpenRISC patch queue for 1.8, it have been well tested, please pull.

Thanks to Richard Henderson, he made the LD/ST updated.


Regards,
Jia



The following changes since commit a4550442b947d2c2b346bd2efc8fe3da16425f4d:

  petalogix-ml605: Create the CPU with object_new() (2014-02-11 22:57:57 +1000)

are available in the git repository at:

  git://github.com/J-Liu/qemu.git or32-ld-st

for you to fetch changes up to 5631e69c269c6b832837715a3bd4d685120a2713:

  target-openrisc: Use new qemu_ld/st opcodes (2014-02-12 08:47:57 +0800)


Richard Henderson (1):
  target-openrisc: Use new qemu_ld/st opcodes

 target-openrisc/translate.c | 99 +++--
 1 file changed, 32 insertions(+), 67 deletions(-)



Re: [Qemu-devel] [PATCH] QMP: allow dot separated dict path arguments in qmp-shell

2014-02-11 Thread Fam Zheng
On Tue, 02/11 14:28, Stefan Hajnoczi wrote:
> On Tue, Feb 11, 2014 at 06:45:05PM +0800, Fam Zheng wrote:
> > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > index d374b35..9c84551 100755
> > --- a/scripts/qmp/qmp-shell
> > +++ b/scripts/qmp/qmp-shell
> > @@ -112,7 +112,14 @@ class QMPShell(qmp.QEMUMonitorProtocol):
> >  value = json.loads(opt[1])
> >  else:
> >  value = opt[1]
> > -qmpcmd['arguments'][opt[0]] = value
> > +optpath = opt[0].split('.')
> > +parent = qmpcmd['arguments']
> > +for p in optpath[:-1]:
> > +if not p in parent:
> > +d = dict()
> > +parent[p] = d
> > +parent = d
> 
> d is a stale reference when the path component already exists (e.g.
> a.b.c=1 a.d=2).  Since 'a' already exists when processing 'a.d' we'll
> the value of d will actually be the a.b dict!
> 
> I think you need the following instead:
> 
> for p in optpath[:-1]:
> d = parent.get(p, {})
> parent[p] = d
> parent = d

Yes, thanks. And we should check the contradictive case "foo=a foo.bar=b". Will
send v2.

Fam



Re: [Qemu-devel] [PATCH] target-arm: make smc behave as a nop

2014-02-11 Thread Rob Herring
On Tue, Feb 11, 2014 at 5:29 PM, Peter Maydell  wrote:
> On 11 February 2014 23:19, Rob Herring  wrote:
>> From: Rob Herring 
>>
>> Several platforms make smc calls for things such as PL310 cache setup.
>> In these cases, making smc a nop rather than an illegal instruction
>> is sufficient for qemu to work.
>
> I can't remember if we've had this discussion before. Anyway,
> I think that making SMC NOP is too much of a platform-specific
> hack. If we want to support these platforms we need to either
> (a) implement TrustZone properly (b) implement some coherent
> mechanism for handing off SMCs to a bit of board specific firmware.
> (We might want the latter anyway for running these guests under
> KVM.)

I don't disagree and that is coming in some form with PSCI support,
but what do you gain in the meantime by platforms not booting. There
is no real usecase for faulting on smc's. I rather see code that works
on actual h/w work than correctly model in qemu code that doesn't work
on actual h/w.

Rob



[Qemu-devel] [PATCH qom-next v1 6/6] block/m25p80: Remove FROM_SSI_SLAVE usages

2014-02-11 Thread Peter Crosthwaite
Signed-off-by: Peter Crosthwaite 
---

 hw/block/m25p80.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 02a1544..bdbb139 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -545,7 +545,7 @@ static void decode_new_cmd(Flash *s, uint32_t value)
 
 static int m25p80_cs(SSISlave *ss, bool select)
 {
-Flash *s = FROM_SSI_SLAVE(Flash, ss);
+Flash *s = M25P80(ss);
 
 if (select) {
 s->len = 0;
@@ -561,7 +561,7 @@ static int m25p80_cs(SSISlave *ss, bool select)
 
 static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
 {
-Flash *s = FROM_SSI_SLAVE(Flash, ss);
+Flash *s = M25P80(ss);
 uint32_t r = 0;
 
 switch (s->state) {
@@ -610,7 +610,7 @@ static uint32_t m25p80_transfer8(SSISlave *ss, uint32_t tx)
 static int m25p80_init(SSISlave *ss)
 {
 DriveInfo *dinfo;
-Flash *s = FROM_SSI_SLAVE(Flash, ss);
+Flash *s = M25P80(ss);
 M25P80Class *mc = M25P80_GET_CLASS(s);
 
 s->pi = mc->pi;
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 5/6] ssi: Remove SSI_SLAVE_FROM_QDEV macro

2014-02-11 Thread Peter Crosthwaite
There are no usages left of this legacy cast. delete.

Signed-off-by: Peter Crosthwaite 
---

 include/hw/ssi.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/hw/ssi.h b/include/hw/ssi.h
index fdae317..38e5b03 100644
--- a/include/hw/ssi.h
+++ b/include/hw/ssi.h
@@ -62,7 +62,6 @@ struct SSISlave {
 bool cs;
 };
 
-#define SSI_SLAVE_FROM_QDEV(dev) DO_UPCAST(SSISlave, qdev, dev)
 #define FROM_SSI_SLAVE(type, dev) DO_UPCAST(type, ssidev, dev)
 
 extern const VMStateDescription vmstate_ssi_slave;
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 4/6] misc: max111x: QOM casting sweep

2014-02-11 Thread Peter Crosthwaite
Define and use QOM cast macro. Removes some usages of legacy casting
systems.

Signed-off-by: Peter Crosthwaite 
---

 hw/misc/max111x.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/misc/max111x.c b/hw/misc/max111x.c
index 9e50e7e..8c78979 100644
--- a/hw/misc/max111x.c
+++ b/hw/misc/max111x.c
@@ -24,6 +24,9 @@ typedef struct {
 
 #define TYPE_MAX_111X "max111x"
 
+#define MAX_111X(obj) \
+OBJECT_CHECK(MAX111xState, (obj), TYPE_MAX_111X)
+
 #define TYPE_MAX_1110 "max1110"
 #define TYPE_MAX_ "max"
 
@@ -97,7 +100,7 @@ static void max111x_write(MAX111xState *s, uint32_t value)
 
 static uint32_t max111x_transfer(SSISlave *dev, uint32_t value)
 {
-MAX111xState *s = FROM_SSI_SLAVE(MAX111xState, dev);
+MAX111xState *s = MAX_111X(dev);
 max111x_write(s, value);
 return max111x_read(s);
 }
@@ -122,7 +125,7 @@ static const VMStateDescription vmstate_max111x = {
 
 static int max111x_init(SSISlave *dev, int inputs)
 {
-MAX111xState *s = FROM_SSI_SLAVE(MAX111xState, dev);
+MAX111xState *s = MAX_111X(dev);
 
 qdev_init_gpio_out(DEVICE(dev), &s->interrupt, 1);
 
@@ -154,7 +157,7 @@ static int max_init(SSISlave *dev)
 
 void max111x_set_input(DeviceState *dev, int line, uint8_t value)
 {
-MAX111xState *s = FROM_SSI_SLAVE(MAX111xState, SSI_SLAVE_FROM_QDEV(dev));
+MAX111xState *s = MAX_111X(dev);
 assert(line >= 0 && line < s->inputs);
 s->input[line] = value;
 }
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 3/6] misc: max111x: Create abstract max111x class

2014-02-11 Thread Peter Crosthwaite
Create an abstract class that encompasses both max111x variants. This is
needed for QOM cast macro creation (and is the right thing to do
anyway). Macroify type-names in the process.

Signed-off-by: Peter Crosthwaite 
---

 hw/misc/max111x.c | 33 +
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/hw/misc/max111x.c b/hw/misc/max111x.c
index fcf2a4d..9e50e7e 100644
--- a/hw/misc/max111x.c
+++ b/hw/misc/max111x.c
@@ -22,6 +22,11 @@ typedef struct {
 int inputs, com;
 } MAX111xState;
 
+#define TYPE_MAX_111X "max111x"
+
+#define TYPE_MAX_1110 "max1110"
+#define TYPE_MAX_ "max"
+
 /* Control-byte bitfields */
 #define CB_PD0 (1 << 0)
 #define CB_PD1 (1 << 1)
@@ -154,18 +159,31 @@ void max111x_set_input(DeviceState *dev, int line, 
uint8_t value)
 s->input[line] = value;
 }
 
-static void max1110_class_init(ObjectClass *klass, void *data)
+static void max111x_class_init(ObjectClass *klass, void *data)
 {
 SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
 
-k->init = max1110_init;
 k->transfer = max111x_transfer;
 }
 
-static const TypeInfo max1110_info = {
-.name  = "max1110",
+static const TypeInfo max111x_info = {
+.name  = TYPE_MAX_111X,
 .parent= TYPE_SSI_SLAVE,
 .instance_size = sizeof(MAX111xState),
+.class_init= max111x_class_init,
+.abstract  = true,
+};
+
+static void max1110_class_init(ObjectClass *klass, void *data)
+{
+SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+
+k->init = max1110_init;
+}
+
+static const TypeInfo max1110_info = {
+.name  = TYPE_MAX_1110,
+.parent= TYPE_MAX_111X,
 .class_init= max1110_class_init,
 };
 
@@ -174,18 +192,17 @@ static void max_class_init(ObjectClass *klass, void 
*data)
 SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
 
 k->init = max_init;
-k->transfer = max111x_transfer;
 }
 
 static const TypeInfo max_info = {
-.name  = "max",
-.parent= TYPE_SSI_SLAVE,
-.instance_size = sizeof(MAX111xState),
+.name  = TYPE_MAX_,
+.parent= TYPE_MAX_111X,
 .class_init= max_class_init,
 };
 
 static void max111x_register_types(void)
 {
+type_register_static(&max111x_info);
 type_register_static(&max1110_info);
 type_register_static(&max_info);
 }
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 2/6] ssi: Remove legacy SSI_BUS->BUS cast

2014-02-11 Thread Peter Crosthwaite
Remove two legacy ->qbus style casts from TYPE_SSI_BUS to TYPE_BUS in
ssi.c.

Signed-off-by: Peter Crosthwaite 
---

 hw/ssi/ssi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c
index 2c25260..f2bdf30 100644
--- a/hw/ssi/ssi.c
+++ b/hw/ssi/ssi.c
@@ -88,7 +88,7 @@ static const TypeInfo ssi_slave_info = {
 
 DeviceState *ssi_create_slave_no_init(SSIBus *bus, const char *name)
 {
-return qdev_create(&bus->qbus, name);
+return qdev_create(BUS(bus), name);
 }
 
 DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
@@ -156,7 +156,7 @@ static int ssi_auto_connect_slave(Object *child, void 
*opaque)
 }
 
 cs_line = qdev_get_gpio_in(DEVICE(dev), 0);
-qdev_set_parent_bus(DEVICE(dev), &arg->bus->qbus);
+qdev_set_parent_bus(DEVICE(dev), BUS(arg->bus));
 **arg->cs_linep = cs_line;
 (*arg->cs_linep)++;
 return 0;
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 1/6] ssi: Convert legacy casts from SSI_SLAVE->DEVICE

2014-02-11 Thread Peter Crosthwaite
Convert legacy ->qdev style casts from TYPE_SSI_SLAVE to TYPE_DEVICE.

Signed-off-by: Peter Crosthwaite 
---

 hw/arm/spitz.c   | 9 +
 hw/display/ads7846.c | 2 +-
 hw/display/ssd0323.c | 4 ++--
 hw/misc/max111x.c| 4 ++--
 hw/sd/ssi-sd.c   | 2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index ba17283..c7b3a94 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -660,12 +660,13 @@ static void spitz_adc_temp_on(void *opaque, int line, int 
level)
 
 static int corgi_ssp_init(SSISlave *dev)
 {
+DeviceState *d = DEVICE(dev);
 CorgiSSPState *s = FROM_SSI_SLAVE(CorgiSSPState, dev);
 
-qdev_init_gpio_in(&dev->qdev, corgi_ssp_gpio_cs, 3);
-s->bus[0] = ssi_create_bus(&dev->qdev, "ssi0");
-s->bus[1] = ssi_create_bus(&dev->qdev, "ssi1");
-s->bus[2] = ssi_create_bus(&dev->qdev, "ssi2");
+qdev_init_gpio_in(d, corgi_ssp_gpio_cs, 3);
+s->bus[0] = ssi_create_bus(d, "ssi0");
+s->bus[1] = ssi_create_bus(d, "ssi1");
+s->bus[2] = ssi_create_bus(d, "ssi2");
 
 return 0;
 }
diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c
index 5da3dc5..87beefe 100644
--- a/hw/display/ads7846.c
+++ b/hw/display/ads7846.c
@@ -137,7 +137,7 @@ static int ads7846_init(SSISlave *dev)
 {
 ADS7846State *s = FROM_SSI_SLAVE(ADS7846State, dev);
 
-qdev_init_gpio_out(&dev->qdev, &s->interrupt, 1);
+qdev_init_gpio_out(DEVICE(dev), &s->interrupt, 1);
 
 s->input[0] = ADS_TEMP0;   /* TEMP0 */
 s->input[2] = ADS_VBAT;/* VBAT */
diff --git a/hw/display/ssd0323.c b/hw/display/ssd0323.c
index c3231c6..c463bd8 100644
--- a/hw/display/ssd0323.c
+++ b/hw/display/ssd0323.c
@@ -345,9 +345,9 @@ static int ssd0323_init(SSISlave *dev)
 s->con = graphic_console_init(DEVICE(dev), &ssd0323_ops, s);
 qemu_console_resize(s->con, 128 * MAGNIFY, 64 * MAGNIFY);
 
-qdev_init_gpio_in(&dev->qdev, ssd0323_cd, 1);
+qdev_init_gpio_in(DEVICE(dev), ssd0323_cd, 1);
 
-register_savevm(&dev->qdev, "ssd0323_oled", -1, 1,
+register_savevm(DEVICE(dev), "ssd0323_oled", -1, 1,
 ssd0323_save, ssd0323_load, s);
 return 0;
 }
diff --git a/hw/misc/max111x.c b/hw/misc/max111x.c
index d477ecd..fcf2a4d 100644
--- a/hw/misc/max111x.c
+++ b/hw/misc/max111x.c
@@ -119,7 +119,7 @@ static int max111x_init(SSISlave *dev, int inputs)
 {
 MAX111xState *s = FROM_SSI_SLAVE(MAX111xState, dev);
 
-qdev_init_gpio_out(&dev->qdev, &s->interrupt, 1);
+qdev_init_gpio_out(DEVICE(dev), &s->interrupt, 1);
 
 s->inputs = inputs;
 /* TODO: add a user interface for setting these */
@@ -133,7 +133,7 @@ static int max111x_init(SSISlave *dev, int inputs)
 s->input[7] = 0x80;
 s->com = 0;
 
-vmstate_register(&dev->qdev, -1, &vmstate_max111x, s);
+vmstate_register(DEVICE(dev), -1, &vmstate_max111x, s);
 return 0;
 }
 
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 1bb56c4..2f34dc6 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -249,7 +249,7 @@ static int ssi_sd_init(SSISlave *dev)
 if (s->sd == NULL) {
 return -1;
 }
-register_savevm(&dev->qdev, "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
+register_savevm(DEVICE(dev), "ssi_sd", -1, 1, ssi_sd_save, ssi_sd_load, s);
 return 0;
 }
 
-- 
1.8.5.4




[Qemu-devel] [PATCH qom-next v1 0/6] SSI QOM cleanups

2014-02-11 Thread Peter Crosthwaite
Hi Andreas,

Here is a mixed bag of QOM cleanups, moving us slightly closer to
QOMification of SSI.

This prepares support for some major refactoring around SSI (in
particular some QSPI patches).

Regards,
Peter


Peter Crosthwaite (6):
  ssi: Convert legacy casts from SSI_SLAVE->DEVICE
  ssi: Remove legacy SSI_BUS->BUS cast
  misc: max111x: Create abstract max111x class
  misc: max111x: QOM casting sweep
  ssi: Remove SSI_SLAVE_FROM_QDEV macro
  block/m25p80: Remove FROM_SSI_SLAVE usages

 hw/arm/spitz.c   |  9 +
 hw/block/m25p80.c|  6 +++---
 hw/display/ads7846.c |  2 +-
 hw/display/ssd0323.c |  4 ++--
 hw/misc/max111x.c| 46 +-
 hw/sd/ssi-sd.c   |  2 +-
 hw/ssi/ssi.c |  4 ++--
 include/hw/ssi.h |  1 -
 8 files changed, 47 insertions(+), 27 deletions(-)

-- 
1.8.5.4




Re: [Qemu-devel] [PATCH v2 7/8] block: Reuse success path from bdrv_open()

2014-02-11 Thread Max Reitz

On 10.02.2014 15:56, Kevin Wolf wrote:

Am 08.02.2014 um 18:39 hat Max Reitz geschrieben:

The fail and success paths of bdrv_file_open() may be further shortened
by reusing code already existent in bdrv_open(). This includes
bdrv_file_open() not taking the reference to options which allows the
removal of QDECREF(options) in that function.

Signed-off-by: Max Reitz 
@@ -1001,41 +1003,35 @@ static int bdrv_file_open(BlockDriverState *bs, const 
char *filename,
  
  /* Parse the filename and open it */

  if (drv->bdrv_parse_filename && filename) {
-drv->bdrv_parse_filename(filename, options, &local_err);
+drv->bdrv_parse_filename(filename, *options, &local_err);
  if (error_is_set(&local_err)) {
  error_propagate(errp, local_err);
  ret = -EINVAL;
  goto fail;
  }
-qdict_del(options, "filename");
+qdict_del(*options, "filename");
+} else if (drv->bdrv_needs_filename && !filename) {
+error_setg(errp, "The '%s' block driver requires a file name",
+   drv->format_name);
+ret = -EINVAL;
+goto fail;
  }

How did this part end up in this patch? It doesn't look wrong, though I
think bdrv_open_common() should already catch it. In any case it's an
addition that the commit message didn't mention.


I wonder. It definitely doesn't belong here, since as of your commit 
"block: Fail gracefully with missing filename" this check should be in 
bdrv_open_common() and not here. I guess, I somehow ended up reverting 
it to the old state here. I just hope there aren't any more such 
reverts; I'll take a look. I remember some rebase conflict here (for 
obvious reasons), so it's probably just in this case, though.


Max



Re: [Qemu-devel] [PATCH v2 2/8] block: Add reference parameter to bdrv_open()

2014-02-11 Thread Max Reitz

On 10.02.2014 14:30, Benoît Canet wrote:

Le Saturday 08 Feb 2014 à 18:39:13 (+0100), Max Reitz a écrit :

Allow bdrv_open() to handle references to existing block devices just as
bdrv_file_open() is already capable of.

Signed-off-by: Max Reitz 
---
  block.c   | 41 ++---
  block/qcow2.c |  4 ++--
  block/vmdk.c  |  3 ++-
  block/vvfat.c |  2 +-
  blockdev.c| 12 ++--
  hw/block/xen_disk.c   |  4 ++--
  include/block/block.h |  5 +++--
  qemu-img.c|  8 
  qemu-io.c |  4 +++-
  qemu-nbd.c|  2 +-
  10 files changed, 58 insertions(+), 27 deletions(-)

diff --git a/block.c b/block.c
index 40a585a..3a32c37 100644
--- a/block.c
+++ b/block.c
@@ -1040,7 +1040,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char 
*filename,
  }
  
  if (!drv->bdrv_file_open) {

-ret = bdrv_open(&bs, filename, options, flags, drv, &local_err);
+ret = bdrv_open(&bs, filename, NULL, options, flags, drv, &local_err);
  options = NULL;
  } else {
  ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err);
@@ -1119,7 +1119,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
  
  assert(bs->backing_hd == NULL);

  ret = bdrv_open(&bs->backing_hd,
-*backing_filename ? backing_filename : NULL, options,
+*backing_filename ? backing_filename : NULL, NULL, options,
  back_flags, back_drv, &local_err);
  if (ret < 0) {
  bs->backing_hd = NULL;
@@ -1199,7 +1199,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char 
*filename,
  goto done;
  }
  
-ret = bdrv_open(pbs, filename, image_options, flags, NULL, errp);

+ret = bdrv_open(pbs, filename, NULL, image_options, flags, NULL, errp);
  } else {
  ret = bdrv_file_open(pbs, filename, reference, image_options, flags,
   errp);
@@ -1221,8 +1221,9 @@ done:
   * If *pbs is NULL, a new BDS will be created with a pointer to it stored 
there.
   * If it is not NULL, the referenced BDS will be reused.
   */
-int bdrv_open(BlockDriverState **pbs, const char *filename, QDict *options,
-  int flags, BlockDriver *drv, Error **errp)
+int bdrv_open(BlockDriverState **pbs, const char *filename,
+  const char *reference, QDict *options, int flags,
+  BlockDriver *drv, Error **errp)

Maybe a little reference to the reference parameters in the comments would help
?


Yes, that would probably be helpful.

Max


Aside from that:

Reviewed-by: Benoit Canet 


  {
  int ret;
  /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
@@ -1233,6 +1234,32 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename, QDict *options,
  
  assert(pbs);
  
+if (reference) {

+bool options_non_empty = options ? qdict_size(options) : false;
+QDECREF(options);
+
+if (*pbs) {
+error_setg(errp, "Cannot reuse an existing BDS when referencing "
+   "another block device");
+return -EINVAL;
+}
+
+if (filename || options_non_empty) {
+error_setg(errp, "Cannot reference an existing block device with "
+   "additional options or a new filename");
+return -EINVAL;
+}
+
+bs = bdrv_find(reference);
+if (!bs) {
+error_setg(errp, "Cannot find block device '%s'", reference);
+return -ENODEV;
+}
+bdrv_ref(bs);
+*pbs = bs;
+return 0;
+}
+
  if (*pbs) {
  bs = *pbs;
  } else {
@@ -1260,7 +1287,7 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename, QDict *options,
  /* Get the required size from the image */
  QINCREF(options);
  bs1 = NULL;
-ret = bdrv_open(&bs1, filename, options, BDRV_O_NO_BACKING,
+ret = bdrv_open(&bs1, filename, NULL, options, BDRV_O_NO_BACKING,
  drv, &local_err);
  if (ret < 0) {
  goto fail;
@@ -5305,7 +5332,7 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
  flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
  
  bs = NULL;

-ret = bdrv_open(&bs, backing_file->value.s, NULL, back_flags,
+ret = bdrv_open(&bs, backing_file->value.s, NULL, NULL, back_flags,
  backing_drv, &local_err);
  if (ret < 0) {
  error_setg_errno(errp, -ret, "Could not open '%s': %s",
diff --git a/block/qcow2.c b/block/qcow2.c
index c8e8ba7..6996276 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1553,7 +1553,7 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
   */
  BlockDriver* drv = bdrv_find_format("qcow2");
  

Re: [Qemu-devel] [PATCH v2 1/8] block: Change BDS parameter of bdrv_open() to **

2014-02-11 Thread Max Reitz

On 10.02.2014 14:17, Benoît Canet wrote:

Le Saturday 08 Feb 2014 à 18:39:12 (+0100), Max Reitz a écrit :

Make bdrv_open() take a pointer to a BDS pointer, similarly to
bdrv_file_open(). If a pointer to a NULL pointer is given, bdrv_open()
will create a new BDS with an empty name; if the BDS pointer is not
NULL, that existing BDS will be reused (in the same way as bdrv_open()
already did).

Signed-off-by: Max Reitz 
---
  block.c   | 64 +++
  block/blkdebug.c  |  1 +
  block/blkverify.c |  2 ++
  block/qcow2.c | 14 +++
  block/vmdk.c  |  5 ++--
  block/vvfat.c |  6 ++---
  blockdev.c| 20 
  hw/block/xen_disk.c   |  2 +-
  include/block/block.h |  2 +-
  qemu-img.c| 10 
  qemu-io.c |  2 +-
  qemu-nbd.c|  2 +-
  12 files changed, 72 insertions(+), 58 deletions(-)

diff --git a/block.c b/block.c
index 636aa11..40a585a 100644
--- a/block.c
+++ b/block.c
@@ -1040,7 +1040,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char 
*filename,
  }
  
  if (!drv->bdrv_file_open) {

-ret = bdrv_open(bs, filename, options, flags, drv, &local_err);
+ret = bdrv_open(&bs, filename, options, flags, drv, &local_err);
  options = NULL;
  } else {
  ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err);
@@ -1109,8 +1109,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 sizeof(backing_filename));
  }
  
-bs->backing_hd = bdrv_new("");

-
  if (bs->backing_format[0] != '\0') {
  back_drv = bdrv_find_format(bs->backing_format);
  }
@@ -1119,11 +1117,11 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
  back_flags = bs->open_flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT |
  BDRV_O_COPY_ON_READ);
  
-ret = bdrv_open(bs->backing_hd,

+assert(bs->backing_hd == NULL);
+ret = bdrv_open(&bs->backing_hd,
  *backing_filename ? backing_filename : NULL, options,
  back_flags, back_drv, &local_err);
  if (ret < 0) {
-bdrv_unref(bs->backing_hd);
  bs->backing_hd = NULL;
  bs->open_flags |= BDRV_O_NO_BACKING;
  error_setg(errp, "Could not open backing file: %s",
@@ -1160,6 +1158,10 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
   * BlockdevRef.
   *
   * The BlockdevRef will be removed from the options QDict.
+ *
+ * As with bdrv_open(), if *pbs is NULL, a new BDS will be created with a
+ * pointer to it stored there. If it is not NULL, the referenced BDS will
+ * be reused.
   */
  int bdrv_open_image(BlockDriverState **pbs, const char *filename,
  QDict *options, const char *bdref_key, int flags,
@@ -1190,8 +1192,6 @@ int bdrv_open_image(BlockDriverState **pbs, const char 
*filename,
  /* If a filename is given and the block driver should be detected
 automatically (instead of using none), use bdrv_open() in order to 
do
 that auto-detection. */
-BlockDriverState *bs;
-
  if (reference) {
  error_setg(errp, "Cannot reference an existing block device while 
"
 "giving a filename");
@@ -1199,13 +1199,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char 
*filename,
  goto done;
  }
  
-bs = bdrv_new("");

-ret = bdrv_open(bs, filename, image_options, flags, NULL, errp);
-if (ret < 0) {
-bdrv_unref(bs);
-} else {
-*pbs = bs;
-}
+ret = bdrv_open(pbs, filename, image_options, flags, NULL, errp);
  } else {
  ret = bdrv_file_open(pbs, filename, reference, image_options, flags,
   errp);
@@ -1223,22 +1217,32 @@ done:
   * empty set of options. The reference to the QDict belongs to the block layer
   * after the call (even on failure), so if the caller intends to reuse the
   * dictionary, it needs to use QINCREF() before calling bdrv_open.
+ *
+ * If *pbs is NULL, a new BDS will be created with a pointer to it stored 
there.
+ * If it is not NULL, the referenced BDS will be reused.
   */
-int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
+int bdrv_open(BlockDriverState **pbs, const char *filename, QDict *options,
int flags, BlockDriver *drv, Error **errp)
  {
  int ret;
  /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
  char tmp_filename[PATH_MAX + 1];
-BlockDriverState *file = NULL;
+BlockDriverState *file = NULL, *bs;
  const char *drvname;
  Error *local_err = NULL;
  
+assert(pbs);

+
+if (*pbs) {
+bs = *pbs;
+} else {
+bs = bdrv_new("");
+}
+
  /* NULL means an empt

Re: [Qemu-devel] [PATCH v2 1/8] block: Change BDS parameter of bdrv_open() to **

2014-02-11 Thread Max Reitz

On 10.02.2014 13:42, Kevin Wolf wrote:

Am 08.02.2014 um 18:39 hat Max Reitz geschrieben:

Make bdrv_open() take a pointer to a BDS pointer, similarly to
bdrv_file_open(). If a pointer to a NULL pointer is given, bdrv_open()
will create a new BDS with an empty name; if the BDS pointer is not
NULL, that existing BDS will be reused (in the same way as bdrv_open()
already did).

Signed-off-by: Max Reitz 
---
  block.c   | 64 +++
  block/blkdebug.c  |  1 +
  block/blkverify.c |  2 ++
  block/qcow2.c | 14 +++
  block/vmdk.c  |  5 ++--
  block/vvfat.c |  6 ++---
  blockdev.c| 20 
  hw/block/xen_disk.c   |  2 +-
  include/block/block.h |  2 +-
  qemu-img.c| 10 
  qemu-io.c |  2 +-
  qemu-nbd.c|  2 +-
  12 files changed, 72 insertions(+), 58 deletions(-)
@@ -1160,6 +1158,10 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
   * BlockdevRef.
   *
   * The BlockdevRef will be removed from the options QDict.
+ *
+ * As with bdrv_open(), if *pbs is NULL, a new BDS will be created with a
+ * pointer to it stored there. If it is not NULL, the referenced BDS will
+ * be reused.
   */
  int bdrv_open_image(BlockDriverState **pbs, const char *filename,
  QDict *options, const char *bdref_key, int flags,

There are no callers that make use of *pbs != NULL. Are you planning to
add such users? Otherwise, we could just assert() it here instead of
documenting behaviour that is never used.


No, currently, there aren't. Since we're planning to eventually adjust 
everything to give a pointer to a NULL pointer to these functions (i.e., 
nobody except bdrv_open() uses bdrv_new()), adding an assert() in order 
to prevent anyone from "exploiting" this in a way which would 
technically be fine but actually not what we want (i.e., reusing an 
already existing BDS), is fine with me. I'll add it and adjust the comment.


Max



Re: [Qemu-devel] [PATCH] qemu_file: use fwrite() correctly

2014-02-11 Thread Juan Quintela
Paolo Bonzini  wrote:
> Il 11/02/2014 22:56, Juan Quintela ha scritto:
>> fwrite() returns the number of items written.  But when there is one
>> error, it can return a short write.
>>
>> In the particular bug that I was tracking, I did a migration to a
>> read-only filesystem.  And it was able to finish the migration
>> correctly.  fwrite() never returned a negative error code, nor zero,
>> always 4096. (migration writes chunks of about 14000 bytes).  And it
>> was able to "complete" the migration with success (yes, reading the
>> file was a bit more difficult).
>>
>> To add insult to injury, if your amount of memory was big enough (12GB
>> on my case), it overwrote some important structure, and from them,
>> malloc failed.  This check makes the problem go away.
>>
>> Signed-off-by: Juan Quintela 
>> ---
>>  qemu-file.c | 9 -
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/qemu-file.c b/qemu-file.c
>> index 9473b67..f074af1 100644
>> --- a/qemu-file.c
>> +++ b/qemu-file.c
>> @@ -100,7 +100,14 @@ static int stdio_put_buffer(void *opaque, const uint8_t 
>> *buf, int64_t pos,
>>  int size)
>>  {
>>  QEMUFileStdio *s = opaque;
>> -return fwrite(buf, 1, size, s->stdio_file);
>> +int res;
>> +
>> +res = fwrite(buf, 1, size, s->stdio_file);
>> +
>> +if (res != size) {
>> +return -EIO;/* fake errno value */
>
> Can you return -errno here?  No need for a fake value.

Sending v2.  On the 1st round here, it returns -EPIPE on errno, exactly
the error that has happened.

Thanks.

> Paolo
>
>> +}
>> +return res;
>>  }
>>
>>  static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int 
>> size)
>>



[Qemu-devel] [PATCH v2] qemu_file: use fwrite() correctly

2014-02-11 Thread Juan Quintela
fwrite() returns the number of items written.  But when there is one
error, it can return a short write.

In the particular bug that I was tracking, I did a migration to a
read-only filesystem.  And it was able to finish the migration
correctly.  fwrite() never returned a negative error code, the 1st
time it returns 0, after that it returns 4096. (migration writes
chunks of about 14000 bytes).  And it was able to "complete" the
migration with success (yes, reading the file was a bit more
difficult).  On the 1st fwrite() for the read-only filesystem,
it returns an errno of -EPIPE, that is exactly what has failed.

To add insult to injury, if your amount of memory was big enough (12GB
on my case), it overwrote some important structure, and from them,
malloc failed.  This check makes the problem go away.

Signed-off-by: Juan Quintela 
---

v2: a.k.a Paolo was right

On the first call to fwrite() it returns 0, and errno is setup to
EPIPE, exactly what we wanted.

Once here, improve the commit message.

 qemu-file.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qemu-file.c b/qemu-file.c
index 9473b67..e5ec798 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -100,7 +100,14 @@ static int stdio_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos,
 int size)
 {
 QEMUFileStdio *s = opaque;
-return fwrite(buf, 1, size, s->stdio_file);
+int res;
+
+res = fwrite(buf, 1, size, s->stdio_file);
+
+if (res != size) {
+return -errno;
+}
+return res;
 }

 static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
-- 
1.8.5.3




Re: [Qemu-devel] [Qemu-ppc] [PATCH v3 09/10] raven: fix PCI bus accesses with size > 1

2014-02-11 Thread Andreas Färber
Am 10.02.2014 23:55, schrieb Mark Cave-Ayland:
> On 10/02/14 22:46, Artyom Tarasenko wrote:
> 
>> On Tue, Nov 5, 2013 at 12:09 AM, Hervé
>> Poussineau  wrote:
>>> Signed-off-by: Hervé Poussineau
>>
>> Without this patch PReP is broken really bad. Was going to submit the
>> same fix, and then found that the bug was already fixed 4 months ago.
>>
>> Hope it helps getting it closer to master:
>>
>> Tested-by: Artyom Tarasenko
> 
> What happened to the rest of the PReP patchset in the end? Is it still
> stuck waiting on someone to rebuild OHW?

Unfortunately yes. Earlier this week I made some progress towards a
buildable and commitable patchset for OHW - once agreed on, we'll need
to go through the same process as you do for OpenBIOS for a submodule
before we can continue with the remainder of the patchset that relies on it.

http://repo.or.cz/w/openhackware.git does not yet link for me.

If there's any part of the Raven patchset or other PReP patches that
don't rely on changes to our unholy OHW blob, do let me know.

Regards,
Andreas



Re: [Qemu-devel] [PATCH] target-arm: make smc behave as a nop

2014-02-11 Thread Peter Maydell
On 11 February 2014 23:19, Rob Herring  wrote:
> From: Rob Herring 
>
> Several platforms make smc calls for things such as PL310 cache setup.
> In these cases, making smc a nop rather than an illegal instruction
> is sufficient for qemu to work.

I can't remember if we've had this discussion before. Anyway,
I think that making SMC NOP is too much of a platform-specific
hack. If we want to support these platforms we need to either
(a) implement TrustZone properly (b) implement some coherent
mechanism for handing off SMCs to a bit of board specific firmware.
(We might want the latter anyway for running these guests under
KVM.)

thanks
-- PMM



[Qemu-devel] [PATCH] target-arm: make smc behave as a nop

2014-02-11 Thread Rob Herring
From: Rob Herring 

Several platforms make smc calls for things such as PL310 cache setup.
In these cases, making smc a nop rather than an illegal instruction
is sufficient for qemu to work.

Signed-off-by: Rob Herring 
---
 target-arm/translate.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index e701c0f..ab4cd56 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -7518,16 +7518,18 @@ static void disas_arm_insn(CPUARMState * env, 
DisasContext *s)
 store_reg(s, rd, tmp);
 break;
 case 7:
-/* SMC instruction (op1 == 3)
-   and undefined instructions (op1 == 0 || op1 == 2)
-   will trap */
-if (op1 != 1) {
-goto illegal_op;
+if (op1 == 3) {
+ARCH(6K);
+/* nop */
+break;
+} else if (op1 == 1) {
+/* bkpt */
+ARCH(5);
+gen_exception_insn(s, 4, EXCP_BKPT);
+break;
 }
-/* bkpt */
-ARCH(5);
-gen_exception_insn(s, 4, EXCP_BKPT);
-break;
+/* Undefined instructions will trap */
+goto illegal_op;
 case 0x8: /* signed multiply */
 case 0xa:
 case 0xc:
-- 
1.8.3.2




Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.

2014-02-11 Thread Hani Benhabiles
On Tue, Feb 11, 2014 at 01:38:32PM -0500, Luiz Capitulino wrote:
> On Thu,  6 Feb 2014 23:30:13 +0100
> Hani Benhabiles  wrote:
> 
> > ---
> >  monitor.c | 23 +++
> >  1 file changed, 23 insertions(+)
> > 
> > diff --git a/monitor.c b/monitor.c
> > index 4a2c1ae..397e1fe 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -56,6 +56,7 @@
> >  #include "qapi/qmp/qjson.h"
> >  #include "qapi/qmp/json-streamer.h"
> >  #include "qapi/qmp/json-parser.h"
> > +#include 
> >  #include "qemu/osdep.h"
> >  #include "cpu.h"
> >  #include "trace.h"
> > @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, 
> > const char *str)
> >  g_slist_free(list);
> >  }
> >  
> > +static void object_add_completion(ReadLineState *rs, const char *str)
> > +{
> > +GSList *list, *elt;
> > +size_t len;
> > +
> > +len = strlen(str);
> > +readline_set_completion_index(rs, len);
> > +list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
> > +while (elt) {
> > +const char *name;
> > +
> > +name = object_class_get_name(OBJECT_CLASS(elt->data));
> > +if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) 
> > {
> > +readline_add_completion(rs, name);
> > +}
> > +elt = elt->next;
> > +}
> > +g_slist_free(list);
> > +}
> > +
> >  static void device_del_completion(ReadLineState *rs, BusState *bus,
> >const char *str, size_t len)
> >  {
> > @@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor 
> > *mon,
> >  case 'O':
> >  if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
> >  device_add_completion(mon->rs, str);
> > +} else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
> > +object_add_completion(mon->rs, str);
> >  }
> >  break;
> >  case 's':
> 
> Those many ifs need to be generalized. Maybe we could add a
> command_completion callback to mon_cmd_t? Anyway, I won't refuse the series
> because of that but it would be very welcome to improve this.

I agree that it could be made better. I will be looking at it next for possible
improvements.


Cheers,

Hani.



Re: [Qemu-devel] [PATCH] qemu_file: use fwrite() correctly

2014-02-11 Thread Paolo Bonzini

Il 11/02/2014 22:56, Juan Quintela ha scritto:

fwrite() returns the number of items written.  But when there is one
error, it can return a short write.

In the particular bug that I was tracking, I did a migration to a
read-only filesystem.  And it was able to finish the migration
correctly.  fwrite() never returned a negative error code, nor zero,
always 4096. (migration writes chunks of about 14000 bytes).  And it
was able to "complete" the migration with success (yes, reading the
file was a bit more difficult).

To add insult to injury, if your amount of memory was big enough (12GB
on my case), it overwrote some important structure, and from them,
malloc failed.  This check makes the problem go away.

Signed-off-by: Juan Quintela 
---
 qemu-file.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qemu-file.c b/qemu-file.c
index 9473b67..f074af1 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -100,7 +100,14 @@ static int stdio_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos,
 int size)
 {
 QEMUFileStdio *s = opaque;
-return fwrite(buf, 1, size, s->stdio_file);
+int res;
+
+res = fwrite(buf, 1, size, s->stdio_file);
+
+if (res != size) {
+return -EIO;   /* fake errno value */


Can you return -errno here?  No need for a fake value.

Paolo


+}
+return res;
 }

 static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)






Re: [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands.

2014-02-11 Thread Hani Benhabiles
On Tue, Feb 11, 2014 at 01:39:13PM -0500, Luiz Capitulino wrote:
> On Thu,  6 Feb 2014 23:30:09 +0100
> Hani Benhabiles  wrote:
> 
> > This patch series add argument completion to multiple human monitor console
> > commands.
> > 
> > For device_add and object_add, only the 1st argument is completed.
> > 
> > Hani Benhabiles (4):
> >   monitor: Add device_del id argument completion.
> >   monitor: Add device_add device argument completion.
> >   monitor: Add object_del id argument completion.
> >   monitor: Add object_add class argument completion.
> > 
> >  monitor.c | 95 
> > +++
> >  1 file changed, 95 insertions(+)
> 
> Series look good and I've applied it to my queue, but I need your sob
> before sending a pull request.

Thanks Luiz! Sorry about the s-o-b.

Signed-off-by: Hani Benhabiles 



[Qemu-devel] [PATCH] qemu_file: use fwrite() correctly

2014-02-11 Thread Juan Quintela
fwrite() returns the number of items written.  But when there is one
error, it can return a short write.

In the particular bug that I was tracking, I did a migration to a
read-only filesystem.  And it was able to finish the migration
correctly.  fwrite() never returned a negative error code, nor zero,
always 4096. (migration writes chunks of about 14000 bytes).  And it
was able to "complete" the migration with success (yes, reading the
file was a bit more difficult).

To add insult to injury, if your amount of memory was big enough (12GB
on my case), it overwrote some important structure, and from them,
malloc failed.  This check makes the problem go away.

Signed-off-by: Juan Quintela 
---
 qemu-file.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qemu-file.c b/qemu-file.c
index 9473b67..f074af1 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -100,7 +100,14 @@ static int stdio_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos,
 int size)
 {
 QEMUFileStdio *s = opaque;
-return fwrite(buf, 1, size, s->stdio_file);
+int res;
+
+res = fwrite(buf, 1, size, s->stdio_file);
+
+if (res != size) {
+return -EIO;   /* fake errno value */
+}
+return res;
 }

 static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
-- 
1.8.5.3




Re: [Qemu-devel] [PATCH v4 00/22] Steps towards per CPU address-spaces

2014-02-11 Thread Paolo Bonzini

Il 11/02/2014 00:53, Edgar E. Iglesias ha scritto:

> Is there that much overhead to creating an AS per master? I guess
> you end up recalculating the same memory flatview for every AS
> when a memory region gets mapped or unmapped.
> In any case, if it's OK to share AddressSpaces between masters
> then we can relatively easily do so, since there's already a list
> of all AddressSpaces that you can run through to find the one
> whose root MemoryRegion is the one you want. (Probably needs
> a refcount in the AddressSpace struct as well.)

Right, something like that might be worthwhile.

It might not make much difference until we start ramping
things up significantly (in terms of amount of masters).


We already have a decent amount of masters for PCI, where each device 
that can do bus-master DMA has basically its own copy of 
address_space_memory.  It has never been a problem in terms of time 
spent updating the ASes.


Paolo



Re: [Qemu-devel] CPU models and feature probing (was Re: [PATCH qom-cpu 00/16 v10] target-i386: convert CPU) features into properties

2014-02-11 Thread Paolo Bonzini

Il 11/02/2014 19:57, Anthony Liguori ha scritto:

> Erm, sorry, that is already implemented in qemu.git!? instance_post_init
> by Eduardo plus glue by me.

Ah, even better then :-)


Still, the code is a bit ad hoc.  Static properties would let us remove 
that code and just read dc->props arrays along the hierarchy as usual.


Also, Igor reminded me offlist that right now we cannot dump the default 
values of the properties.  With this series, one could extend the 
device-list-properties command with that information.


Paolo



Re: [Qemu-devel] RFC: ioapic polarity vs. qemu os-x guest

2014-02-11 Thread Gabriel L. Somlo
On Tue, Feb 11, 2014 at 09:54:44PM +0200, Michael S. Tsirkin wrote:
> On Tue, Feb 11, 2014 at 01:23:31PM -0500, Gabriel L. Somlo wrote:
> > I'm trying to get OS X to work as a QEMU guest, and one of the few
> > remaining "mysteries" I need to solve is that the OS X guest hangs
> > during boot, waiting for its boot disk to be available, unless the
> > following KVM patch is applied:
> > [...]
> > 2. Is there anything in QEMU (besides the ACPI DSDT .dsl files) which
> > has a hardcoded assumption re. "polarity == 0", or active-high, for
> > level-triggered interrupts? I tried to dig through hw/i386/kvm/ioapic.c
> > and a bunch of other files, but couldn't isolate anything that I could
> > "flip" to fix things in userspace.
> > 
> > 
> > Any ideas or suggestions about the appropriate way to move forward would
> > be much appreciated !!!
> > 
> > 
> > Thanks much,
> > --Gabriel
> 
> I think changing ACPI is the right thing to
> do really. But we'll need to fix some things
> first of course.
> 
> I think it's PC Q35 that has this assumption.
> hw/i386/pc_q35.c
> 
> gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
>  GSI_NUM_PINS);
> 
> kvm_pc_gsi_handler simply forwards interrupts to kvm.
> 
> and
> 
> hw/isa/lpc_ich9.c
> static void ich9_lpc_update_pic(ICH9LPCState *lpc, int pic_irq)
> {
> int i, pic_level;
> 
> /* The pic level is the logical OR of all the PCI irqs mapped to it */
> /* The pic level is the logical OR of all the PCI irqs mapped to it
>  * */
> pic_level = 0;
> for (i = 0; i < ICH9_LPC_NB_PIRQS; i++) {
> int tmp_irq;
> int tmp_dis;
> ich9_lpc_pic_irq(lpc, i, &tmp_irq, &tmp_dis);
> if (!tmp_dis && pic_irq == tmp_irq) {
> pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
> }
> }
> 
> so somewhere we need to flip it, I am guessing in ich9
> along the lines of:
> 
> -pic_level = 0;
> -pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
> +pic_level = 1;
> +pic_level &= !pci_bus_get_irq_level(lpc->d.bus, i);

I think now we're on to something!

I managed to boot OS X on q35 with absolutely no kernel patches, but
Linux still hated it ("irqXX: nobody cared"). At least now I know what
I'm looking for, so I'll try to come up with a way to flip
level-triggered polarity to ActiveLow across all of i386, in a way
that works for Linux and Windows guests as well.

Thanks again for getting me unstuck!
--Gabriel



[Qemu-devel] [PATCH 0/3] X86: Invalid lock prefix (F0), invalid mov instruction, the xor_zero case should also update the parity.

2014-02-11 Thread Xabier Ugarte-Pedrero
The following patch corrects two invalid instructions on the X86 subsystem that 
are incorrectly translated. These
byte sequences should generate exceptions.

First, the lock prefix (F0) should only be prepended once before each 
instruction. Otherwise, (if two F0 bytes are
present), the cpu raises an "Invalid Lock Sequence" exception. This behaviour 
was reproduced on a 32 bit Windows XP SP-3 
installation and a i386-softmmu qemu machine. While the real machine generates 
the exception, the emulated one accepts it as a valid sequence. This problem is 
corrected by this patch. 

Nevertheless, the lock prefix should be restricted to a fixed set of 
instructions according to the
the Intel Manual. This aspect appears to be only partially implemented for the 
nop instruction (0x90).The following
comment in target-i386/translate.c: "/* XXX: correct lock test for all insn 
*/", invites to correct it for the rest of
instructions. Unfortunately, this correction requires to significantly modify 
the translation loop.

Second, the C7 mov instruction requires the Reg/Opcode field of the Mod/RM byte 
to be 0. Otherwise, it should generate
and invalid instruction exception. This problem is corrected with this patch, 
and was tested on a 32 bit Windows XP SP-3
installation and a i386-softmmu qemu machine.

Third, the xor of a register with itself should update (and set) both the Z and 
the P flags.

For further details, please refer to the Intel 64 and IA-32 Architectures 
Software Developer's Manual Volume 2A:
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in
Chapter 3, and "MOV—Move" in Chapter 3.

Signed-off-by: Xabier Ugarte-Pedrero 

Xabier Ugarte-Pedrero (3):
  X86: Invalid lock prefix (F0)
  X86: Invalid mov instruction (C7)
  X86: The xor_zero case should also update the parity flag

 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |   11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH 1/3] X86: Invalid lock prefix (F0)

2014-02-11 Thread Xabier Ugarte-Pedrero
  If the lock prefix (F0) is prepended more than once to any instruction, then 
it should generate an invalid instruction exception (illegal_op).
  See Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2A: 
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in Chapter 3.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/translate.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index b0f2279..733e5b2 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -4415,6 +4415,12 @@ static target_ulong disas_insn(CPUX86State *env, 
DisasContext *s,
 prefixes |= PREFIX_REPNZ;
 goto next_byte;
 case 0xf0:
+/*Invalid lock sequence*/
+if (prefixes & PREFIX_LOCK){
+/*Clear the PREFIX_LOCK FLAG*/
+prefixes &= !PREFIX_LOCK;
+goto illegal_op;
+}
 prefixes |= PREFIX_LOCK;
 goto next_byte;
 case 0x2e:
-- 
1.7.9.5




[Qemu-devel] [PATCH 0/3] X86: Invalid lock prefix (F0), invalid mov instruction

2014-02-11 Thread Xabier Ugarte-Pedrero
The following patch corrects two invalid instructions on the X86 subsystem that 
are incorrectly translated. These
byte sequences should generate exceptions.

First, the lock prefix (F0) should only be prepended once before each 
instruction. Otherwise, (if two F0 bytes are
present), the cpu raises an "Invalid Lock Sequence" exception. This behaviour 
was reproduced on a 32 bit Windows XP SP-3 
installation and a i386-softmmu qemu machine. While the real machine generates 
the exception, the emulated one accepts it as a valid sequence. This problem is 
corrected by this patch. 

Nevertheless, the lock prefix should be restricted to a fixed set of 
instructions according to the
the Intel Manual. This aspect appears to be only partially implemented for the 
nop instruction (0x90).The following
comment in target-i386/translate.c: "/* XXX: correct lock test for all insn 
*/", invites to correct it for the rest of
instructions. Unfortunately, this correction requires to significantly modify 
the translation loop.

Second, the C7 mov instruction requires the Reg/Opcode field of the Mod/RM byte 
to be 0. Otherwise, it should generate
and invalid instruction exception. This problem is corrected with this patch, 
and was tested on a 32 bit Windows XP SP-3
installation and a i386-softmmu qemu machine.

For further details, please refer to the Intel 64 and IA-32 Architectures 
Software Developer's Manual Volume 2A:
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in
Chapter 3, and "MOV—Move" in Chapter 3.

Signed-off-by: Xabier Ugarte-Pedrero 

Xabier Ugarte-Pedrero (3):
  X86: Invalid lock prefix (F0)
  X86: Invalid mov instruction (C7)
  X86: The xor_zero case should also update the parity flag

 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |   11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH 2/3] X86: Invalid mov instruction (C7)

2014-02-11 Thread Xabier Ugarte-Pedrero
  The mov instruction (with operational code C7) must be followed by a ModR/M 
byte with the Reg/Opcode field (bits 3 to 5) set to 0. Otherwise, it should 
generate an invalid instruction exception (illegal_op).
  See Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2A: 
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
"MOV—Move" in Chapter 3.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/translate.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 733e5b2..d800ae3 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -5347,6 +5347,9 @@ static target_ulong disas_insn(CPUX86State *env, 
DisasContext *s,
 ot = mo_b_d(b, dflag);
 modrm = cpu_ldub_code(env, s->pc++);
 mod = (modrm >> 6) & 3;
+if ((modrm >> 3) & 7){
+goto illegal_op;
+}
 if (mod != 3) {
 s->rip_offset = insn_const_size(ot);
 gen_lea_modrm(env, s, modrm);
-- 
1.7.9.5




[Qemu-devel] [PATCH 3/3] X86: The xor_zero case should also update the parity flag

2014-02-11 Thread Xabier Ugarte-Pedrero
  The xor of a register with itself should set the Z and the P flag, not only 
the Z flag.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/cc_helper.c b/target-i386/cc_helper.c
index ee04092..05dd12b 100644
--- a/target-i386/cc_helper.c
+++ b/target-i386/cc_helper.c
@@ -103,7 +103,7 @@ target_ulong helper_cc_compute_all(target_ulong dst, 
target_ulong src1,
 case CC_OP_EFLAGS:
 return src1;
 case CC_OP_CLR:
-return CC_Z;
+return CC_Z | CC_P;
 
 case CC_OP_MULB:
 return compute_all_mulb(dst, src1);
diff --git a/target-i386/translate.c b/target-i386/translate.c
index d800ae3..c97d686 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -748,7 +748,7 @@ static void gen_compute_eflags(DisasContext *s)
 return;
 }
 if (s->cc_op == CC_OP_CLR) {
-tcg_gen_movi_tl(cpu_cc_src, CC_Z);
+tcg_gen_movi_tl(cpu_cc_src, CC_Z | CC_P);
 set_cc_op(s, CC_OP_EFLAGS);
 return;
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 3/3] X86: The xor_zero case should also update the parity flag

2014-02-11 Thread Xabier Ugarte-Pedrero
  The xor of a register with itself should set the Z and the P flag, not only 
the Z flag.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/cc_helper.c b/target-i386/cc_helper.c
index ee04092..05dd12b 100644
--- a/target-i386/cc_helper.c
+++ b/target-i386/cc_helper.c
@@ -103,7 +103,7 @@ target_ulong helper_cc_compute_all(target_ulong dst, 
target_ulong src1,
 case CC_OP_EFLAGS:
 return src1;
 case CC_OP_CLR:
-return CC_Z;
+return CC_Z | CC_P;
 
 case CC_OP_MULB:
 return compute_all_mulb(dst, src1);
diff --git a/target-i386/translate.c b/target-i386/translate.c
index d800ae3..c97d686 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -748,7 +748,7 @@ static void gen_compute_eflags(DisasContext *s)
 return;
 }
 if (s->cc_op == CC_OP_CLR) {
-tcg_gen_movi_tl(cpu_cc_src, CC_Z);
+tcg_gen_movi_tl(cpu_cc_src, CC_Z | CC_P);
 set_cc_op(s, CC_OP_EFLAGS);
 return;
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 0/3] X86: Invalid lock prefix (F0), invalid mov instruction, the xor_zero case should also update the parity.

2014-02-11 Thread Xabier Ugarte-Pedrero
The following patch corrects two invalid instructions on the X86 subsystem that 
are incorrectly translated. These
byte sequences should generate exceptions.

First, the lock prefix (F0) should only be prepended once before each 
instruction. Otherwise, (if two F0 bytes are
present), the cpu raises an "Invalid Lock Sequence" exception. This behaviour 
was reproduced on a 32 bit Windows XP SP-3 
installation and a i386-softmmu qemu machine. While the real machine generates 
the exception, the emulated one accepts it as a valid sequence. This problem is 
corrected by this patch. 

Nevertheless, the lock prefix should be restricted to a fixed set of 
instructions according to the
the Intel Manual. This aspect appears to be only partially implemented for the 
nop instruction (0x90).The following
comment in target-i386/translate.c: "/* XXX: correct lock test for all insn 
*/", invites to correct it for the rest of
instructions. Unfortunately, this correction requires to significantly modify 
the translation loop.

Second, the C7 mov instruction requires the Reg/Opcode field of the Mod/RM byte 
to be 0. Otherwise, it should generate
and invalid instruction exception. This problem is corrected with this patch, 
and was tested on a 32 bit Windows XP SP-3
installation and a i386-softmmu qemu machine.

Third, the xor of a register with itself should update (and set) both the Z and 
the P flags.

For further details, please refer to the Intel 64 and IA-32 Architectures 
Software Developer's Manual Volume 2A:
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in
Chapter 3, and "MOV—Move" in Chapter 3.

Signed-off-by: Xabier Ugarte-Pedrero 

Xabier Ugarte-Pedrero (3):
  X86: Invalid lock prefix (F0)
  X86: Invalid mov instruction (C7)
  X86: The xor_zero case should also update the parity flag

 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |   11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH 3/3] X86: The xor_zero case should also update the parity flag

2014-02-11 Thread Xabier Ugarte-Pedrero
  The xor of a register with itself should set the Z and the P flag, not only 
the Z flag.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/cc_helper.c b/target-i386/cc_helper.c
index ee04092..05dd12b 100644
--- a/target-i386/cc_helper.c
+++ b/target-i386/cc_helper.c
@@ -103,7 +103,7 @@ target_ulong helper_cc_compute_all(target_ulong dst, 
target_ulong src1,
 case CC_OP_EFLAGS:
 return src1;
 case CC_OP_CLR:
-return CC_Z;
+return CC_Z | CC_P;
 
 case CC_OP_MULB:
 return compute_all_mulb(dst, src1);
diff --git a/target-i386/translate.c b/target-i386/translate.c
index d800ae3..c97d686 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -748,7 +748,7 @@ static void gen_compute_eflags(DisasContext *s)
 return;
 }
 if (s->cc_op == CC_OP_CLR) {
-tcg_gen_movi_tl(cpu_cc_src, CC_Z);
+tcg_gen_movi_tl(cpu_cc_src, CC_Z | CC_P);
 set_cc_op(s, CC_OP_EFLAGS);
 return;
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 3/3] X86: The xor_zero case should also update the parity flag

2014-02-11 Thread Xabier Ugarte-Pedrero
  The xor of a register with itself should set the Z and the P flag, not only 
the Z flag.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/cc_helper.c b/target-i386/cc_helper.c
index ee04092..05dd12b 100644
--- a/target-i386/cc_helper.c
+++ b/target-i386/cc_helper.c
@@ -103,7 +103,7 @@ target_ulong helper_cc_compute_all(target_ulong dst, 
target_ulong src1,
 case CC_OP_EFLAGS:
 return src1;
 case CC_OP_CLR:
-return CC_Z;
+return CC_Z | CC_P;
 
 case CC_OP_MULB:
 return compute_all_mulb(dst, src1);
diff --git a/target-i386/translate.c b/target-i386/translate.c
index d800ae3..c97d686 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -748,7 +748,7 @@ static void gen_compute_eflags(DisasContext *s)
 return;
 }
 if (s->cc_op == CC_OP_CLR) {
-tcg_gen_movi_tl(cpu_cc_src, CC_Z);
+tcg_gen_movi_tl(cpu_cc_src, CC_Z | CC_P);
 set_cc_op(s, CC_OP_EFLAGS);
 return;
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 2/3] X86: Invalid mov instruction (C7)

2014-02-11 Thread Xabier Ugarte-Pedrero
  The mov instruction (with operational code C7) must be followed by a ModR/M 
byte with the Reg/Opcode field (bits 3 to 5) set to 0. Otherwise, it should 
generate an invalid instruction exception (illegal_op).
  See Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2A: 
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
"MOV—Move" in Chapter 3.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/translate.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 733e5b2..d800ae3 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -5347,6 +5347,9 @@ static target_ulong disas_insn(CPUX86State *env, 
DisasContext *s,
 ot = mo_b_d(b, dflag);
 modrm = cpu_ldub_code(env, s->pc++);
 mod = (modrm >> 6) & 3;
+if ((modrm >> 3) & 7){
+goto illegal_op;
+}
 if (mod != 3) {
 s->rip_offset = insn_const_size(ot);
 gen_lea_modrm(env, s, modrm);
-- 
1.7.9.5




[Qemu-devel] [PATCH 1/3] X86: Invalid lock prefix (F0)

2014-02-11 Thread Xabier Ugarte-Pedrero
  If the lock prefix (F0) is prepended more than once to any instruction, then 
it should generate an invalid instruction exception (illegal_op).
  See Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2A: 
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in Chapter 3.

  Signed-off-by: Xabier Ugarte-Pedrero 
---
 target-i386/translate.c |6 ++
 1 file changed, 6 insertions(+)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index b0f2279..733e5b2 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -4415,6 +4415,12 @@ static target_ulong disas_insn(CPUX86State *env, 
DisasContext *s,
 prefixes |= PREFIX_REPNZ;
 goto next_byte;
 case 0xf0:
+/*Invalid lock sequence*/
+if (prefixes & PREFIX_LOCK){
+/*Clear the PREFIX_LOCK FLAG*/
+prefixes &= !PREFIX_LOCK;
+goto illegal_op;
+}
 prefixes |= PREFIX_LOCK;
 goto next_byte;
 case 0x2e:
-- 
1.7.9.5




[Qemu-devel] [PATCH 0/3] X86: Invalid lock prefix (F0), invalid mov instruction, the xor_zero case should also update the parity.

2014-02-11 Thread Xabier Ugarte-Pedrero
The following patch corrects two invalid instructions on the X86 subsystem that 
are incorrectly translated. These
byte sequences should generate exceptions.

First, the lock prefix (F0) should only be prepended once before each 
instruction. Otherwise, (if two F0 bytes are
present), the cpu raises an "Invalid Lock Sequence" exception. This behaviour 
was reproduced on a 32 bit Windows XP SP-3 
installation and a i386-softmmu qemu machine. While the real machine generates 
the exception, the emulated one accepts it as a valid sequence. This problem is 
corrected by this patch. 

Nevertheless, the lock prefix should be restricted to a fixed set of 
instructions according to the
the Intel Manual. This aspect appears to be only partially implemented for the 
nop instruction (0x90).The following
comment in target-i386/translate.c: "/* XXX: correct lock test for all insn 
*/", invites to correct it for the rest of
instructions. Unfortunately, this correction requires to significantly modify 
the translation loop.

Second, the C7 mov instruction requires the Reg/Opcode field of the Mod/RM byte 
to be 0. Otherwise, it should generate
and invalid instruction exception. This problem is corrected with this patch, 
and was tested on a 32 bit Windows XP SP-3
installation and a i386-softmmu qemu machine.

Third, the xor of a register with itself should update (and set) both the Z and 
the P flags.

For further details, please refer to the Intel 64 and IA-32 Architectures 
Software Developer's Manual Volume 2A:
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in
Chapter 3, and "MOV—Move" in Chapter 3.

Signed-off-by: Xabier Ugarte-Pedrero 

Xabier Ugarte-Pedrero (3):
  X86: Invalid lock prefix (F0)
  X86: Invalid mov instruction (C7)
  X86: The xor_zero case should also update the parity flag

 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |   11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH 0/3] X86: Invalid lock prefix (F0), invalid mov instruction

2014-02-11 Thread Xabier Ugarte-Pedrero
The following patch corrects two invalid instructions on the X86 subsystem that 
are incorrectly translated. These
byte sequences should generate exceptions.

First, the lock prefix (F0) should only be prepended once before each 
instruction. Otherwise, (if two F0 bytes are
present), the cpu raises an "Invalid Lock Sequence" exception. This behaviour 
was reproduced on a 32 bit Windows XP SP-3 
installation and a i386-softmmu qemu machine. While the real machine generates 
the exception, the emulated one accepts it as a valid sequence. This problem is 
corrected by this patch. 

Nevertheless, the lock prefix should be restricted to a fixed set of 
instructions according to the
the Intel Manual. This aspect appears to be only partially implemented for the 
nop instruction (0x90).The following
comment in target-i386/translate.c: "/* XXX: correct lock test for all insn 
*/", invites to correct it for the rest of
instructions. Unfortunately, this correction requires to significantly modify 
the translation loop.

Second, the C7 mov instruction requires the Reg/Opcode field of the Mod/RM byte 
to be 0. Otherwise, it should generate
and invalid instruction exception. This problem is corrected with this patch, 
and was tested on a 32 bit Windows XP SP-3
installation and a i386-softmmu qemu machine.

For further details, please refer to the Intel 64 and IA-32 Architectures 
Software Developer's Manual Volume 2A:
Instruction Set Reference, A-M. Order Number: 253666-049US February 2014. See 
“LOCK—Assert LOCK# Signal Prefix” in
Chapter 3, and "MOV—Move" in Chapter 3.

Signed-off-by: Xabier Ugarte-Pedrero 

Xabier Ugarte-Pedrero (3):
  X86: Invalid lock prefix (F0)
  X86: Invalid mov instruction (C7)
  X86: The xor_zero case should also update the parity flag

 target-i386/cc_helper.c |2 +-
 target-i386/translate.c |   11 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [Bug 1278977] [NEW] qemu-system-sparc64 crash when initializing disk

2014-02-11 Thread wbx
Public bug reported:

Hi,

I try to boot up Linux for SPARC64 in qemu-system-sparc64 (qemu 1.7.0). A self 
compiled kernel with initramfs as piggyback boots up fine.
(http://www.openadk.org/qemu-sparc64-initramfs-piggyback-kernel)
When trying to use a disk image I get following trace:
qemu-system-sparc64 -nographic -kernel 
/home/wbx/openadk/bin/qemu_sparc64_eglibc/qemu-sparc64-archive-kernel 
qemu-sparc64.img -append "root=/dev/sda1" 
[   43.520705] ata1.00: ATA-7: QEMU HARDDISK, 1.7.0, max UDMA/100
[   43.792734] ata1.00: 1048576 sectors, multi 16: LBA48 
[   44.100768] ata1.00: configured for UDMA/33
[   44.316791] scsi 0:0:0:0: Direct-Access ATA  QEMU HARDDISK1.7. 
PQ: 0 ANSI: 5
[   44.724835] sd 0:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 
MiB)
[   45.172883] ata2.00: ATAPI: QEMU DVD-ROM, 1.7.0, max UDMA/100
[   45.508920] ata2.00: configured for UDMA/33
[   45.752946] scsi 1:0:0:0: CD-ROMQEMU QEMU DVD-ROM 1.7. 
PQ: 0 ANSI: 5
[   46.309006] sd 0:0:0:0: [sda] Write Protect is off
[   46.737053] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, 
doesn't support DPO or FUA
qemu: fatal: Trap 0x0032 while trap level (5) >= MAXTL (5), Error state
pc: 004055dc  npc: 004055e0
%g0-3:  0200 f80006a3f170 0200
%g4-7: f5000464  f80006a3c000 f500
%o0-3: f80006a10140 f80006a10160 f80006900010 06a6c000 
%o4-7: 0002 03e7 f80006a3e1c1 00593988 
%l0-3:  00ff 2000 0001 
%l4-7:  f80006a0d980 0001 c0004000 
%i0-3:  ff00 0001 0001 
%i4-7: f80006a11d50 f80006a1 f80006a3e271 00582444 
%f00:     
%f08:     
%f16:  076e072707740720 0773077507700770 076f077207740720 07440750074f0720
%f24:  076f077207200746 0755074107200720 0720072007200720 0720072007200720
%f32:  0720072007200720 0720072007200720 0720072007200720 0720072007200720
%f40:  0720072007200720 0720072007200720 0720072007200720 0720072007200720
%f48:  0720072007200720 0755074107200720 0720072007200720 0720072007200720
%f56:  0720072007200720 0720072007200720 0720072007200720 0720072007200720
pstate: 0015 ccr: 00 (icc:  xcc: ) asi: 80 tl: 5 pil: e
cansave: 4 canrestore: 2 otherwin: 0 wstate: 0 cleanwin: 7 cwp: 4
fsr:  y:  fprs: 

Aborted

Same happens when starting up Debian/wheezy 7.4 for sparc64:
qemu-system-sparc64 -nographic -kernel vmlinuz -initrd initrd.gz qemu.img
[  102.943129] eth0: RealTek RTL-8029 found at 0x1fe02000400, IRQ 6, 
52:54:00:12:34:56.
[  105.143367] scsi0 : pata_cmd64x
[  105.667424] scsi1 : pata_cmd64x
[  106.003460] ata1: PATA max UDMA/33 cmd 0x1fe02000500 ctl 0x1fe02000580 bmdma 
0x1fe02000700 irq 7
[  106.871554] ata2: PATA max UDMA/33 cmd 0x1fe02000600 ctl 0x1fe02000680 bmdma 
0x1fe02000708 irq 7
[  108.247703] ata1.00: ATA-7: QEMU HARDDISK, 1.7.0, max UDMA/100
[  108.775760] ata1.00: 1048576 sectors, multi 16: LBA48 
[  109.399827] ata1.00: configured for UDMA/33
[  109.815872] scsi 0:0:0:0: Direct-Access ATA  QEMU HARDDISK1.7. 
PQ: 0 ANSI: 5
[  111.004001] ata2.00: ATAPI: QEMU DVD-ROM, 1.7.0, max UDMA/100
[  111.608066] ata2.00: configured for UDMA/33
[  112.040113] scsi 1:0:0:0: CD-ROMQEMU QEMU DVD-ROM 1.7. 
PQ: 0 ANSI: 5
[  114.344362] sd 0:0:0:0: [sda] 1048576 512-byte logical blocks: (536 MB/512 
MiB)
qemu: fatal: Trap 0x0032 while trap level (5) >= MAXTL (5), Error state
pc: 004055bc  npc: 004055c0
%g0-3:  0200 f80007e6bd10 0200
%g4-7: f5000464  f80005d34000 f500
%o0-3: f80005f68148 f80005f68180 000c 0001 
%o4-7: f80005d4b889 01fe02000600 f8000705b391 10064474 
%l0-3:  007f6330 00200200 f80007e6be60 
%l4-7:  00945bd8 00945fd8 009463d8 
%i0-3: f80005f68000 f80005f68148 0058 0001 
%i4-7: f80005f69ce8  f8000705b451 10064ab8 
%f00:     
%f08:     
%f16:     
%f24:     
%f32:     
%f40:     
%f48:     
%f56:  00

Re: [Qemu-devel] [PATCH v4 06/22] cpu: Add per-cpu address space

2014-02-11 Thread Andreas Färber
Edgar,

Am 03.02.2014 10:44, schrieb Edgar E. Iglesias:
> From: "Edgar E. Iglesias" 
> 
> Signed-off-by: Edgar E. Iglesias 
> ---
>  cpus.c  |  2 ++
>  cputlb.c|  7 ---
>  exec.c  | 27 +++
>  include/exec/exec-all.h |  1 +
>  include/exec/softmmu_template.h |  6 --
>  include/qom/cpu.h   |  3 +++
>  6 files changed, 33 insertions(+), 13 deletions(-)

This CPU patch did not get a Reviewed-by or Acked-by from me and was
still committed, even without indicating so here! Had you asked me, you
would've got one and my go-ahead, but what annoys me is that I learned
about you committing this through it breaking my qom-cpu-13 branch with
a conflict in target-i386/helper.c in later patch I had not yet
reviewed... :/

Please a) indicate you committed patches as an email reply to that
series and b) read the replies - me, Peter and Paolo were converging on
giving me the okay to take a subset of this series into qom-cpu, you
neither asked nor did anyone propose committing them directly on the
mailing list.

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] RFC: ioapic polarity vs. qemu os-x guest

2014-02-11 Thread Michael S. Tsirkin
On Tue, Feb 11, 2014 at 01:23:31PM -0500, Gabriel L. Somlo wrote:
> Hi,
> 
> I'm trying to get OS X to work as a QEMU guest, and one of the few
> remaining "mysteries" I need to solve is that the OS X guest hangs
> during boot, waiting for its boot disk to be available, unless the
> following KVM patch is applied:
> 
> 
> diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
> index ce9ed99..1539d37 100644
> --- a/virt/kvm/ioapic.c
> +++ b/virt/kvm/ioapic.c
> @@ -328,7 +328,6 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int 
> irq, int irq_source_id,
>   irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq],
>irq_source_id, level);
>   entry = ioapic->redirtbl[irq];
> - irq_level ^= entry.fields.polarity;
>   if (!irq_level) {
>   ioapic->irr &= ~mask;
>   ret = 1;
> --
> 
> 
> After digging around the KVM source for a bit, and printk-ing things
> from Windows 7, Fedora 20, and OS X (10.9), I figured out the following:
> 
> 
> 1. Edge-triggered interrupts are invariably unaffected by the xor line
> being removed by the patch. On all three guest types, edge-triggered
> interrupts have polarity set to 0, so the xor is essentially a no-op,
> and we can forget about it altogether.
> 
> 
> 2. Windows and Linux always configure all level-triggered interrupts
> with polarity 0 (active-high, consistent with QEMU's ACPI/DSDT, in
> particular q35-acpi-dsdt.dsl, which is what I'm using with -M q35).
> As such, on Windows and Linux, the xor line in question is still a
> no-op.
> 
> 
> 3. OS X (all versions I tried, at least since 10.5/Leopard) always
> configures all level-triggered interrupts with polarity 1 (active-low),
> regardless of what the QEMU DSDT says. As such, the xor line acts as
> a negation of "irq_level", which at first glance sounds reasonable.
> 
> However: when KVM negates "irq_level" due to "polarity == 1", the OS X
> guest hangs during boot.
> 
> OS X works fine when "polarity == 1" is ignored (with the xor line
> commented out).
> 
> This may be another instance (similar to how OS X didn't use to check
> with CPUID regarding monitor/mwait instruction availability) where
> apple devs know that any of their supported hardware advertises
> active-low in the DSDT, so no need to check, just hardcode that
> assumption... :)
> 
> 
> 4. With s/ActiveHigh/ActiveLow/ in QEMU's q35-acpi-dsdt.dsl, Linux
> actually switches to "polarity == 1" (active-low), and works fine
> *with the xor line removed* !!!. With the xor line left intact (i.e.
> without the above patch), the active-low fedora guest worked extremely
> poorly, and printed out multiple error messages during boot:
> 
>   irq XX: nobody cared (try booting with the "irqpoll" option)
>   ...
>   Disabling IRQ #XX
> 
> for XX in [16, 18, 19, ...].
> 
> 
> So, right now, I'm wondering about the following:
> 
> 
> 1. Regarding KVM and the polarity xor line in the patch above: Does
> anyone have experience with any *other* guests which insist on setting
> level-triggered interrupt polarity to 1/active-low ? Is that xor line
> actually doing anything useful in practice, for any other guest, on
> either QEMU or any other platform ?
> 
> 
> 2. Is there anything in QEMU (besides the ACPI DSDT .dsl files) which
> has a hardcoded assumption re. "polarity == 0", or active-high, for
> level-triggered interrupts? I tried to dig through hw/i386/kvm/ioapic.c
> and a bunch of other files, but couldn't isolate anything that I could
> "flip" to fix things in userspace.
> 
> 
> Any ideas or suggestions about the appropriate way to move forward would
> be much appreciated !!!
> 
> 
> Thanks much,
> --Gabriel

I think changing ACPI is the right thing to
do really. But we'll need to fix some things
first of course.

I think it's PC Q35 that has this assumption.
hw/i386/pc_q35.c

gsi = qemu_allocate_irqs(kvm_pc_gsi_handler, gsi_state,
 GSI_NUM_PINS);

kvm_pc_gsi_handler simply forwards interrupts to kvm.

and

hw/isa/lpc_ich9.c
static void ich9_lpc_update_pic(ICH9LPCState *lpc, int pic_irq)
{
int i, pic_level;

/* The pic level is the logical OR of all the PCI irqs mapped to it */
/* The pic level is the logical OR of all the PCI irqs mapped to it
 * */
pic_level = 0;
for (i = 0; i < ICH9_LPC_NB_PIRQS; i++) {
int tmp_irq;
int tmp_dis;
ich9_lpc_pic_irq(lpc, i, &tmp_irq, &tmp_dis);
if (!tmp_dis && pic_irq == tmp_irq) {
pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
}
}

so somewhere we need to flip it, I am guessing in ich9
along the lines of:

-pic_level = 0;
-pic_level |= pci_bus_get_irq_level(lpc->d.bus, i);
+pic_level = 1;
+pic_level &= !pci_bus_get_irq_level(lpc->d.bus, i);




-- 
MST



Re: [Qemu-devel] [PATCH V6 00/10] qapi script: support enum as discriminator and better enum name

2014-02-11 Thread Luiz Capitulino
On Tue, 11 Feb 2014 05:48:31 +0800
Wenchao Xia  wrote:

> This series address two issues:
> 
> 1. support using enum as discriminator in union.
> For example, if we have following define in qapi schema:
> { 'enum': 'EnumOne',
>   'data': [ 'value1', 'value2', 'value3' ] }
> 
> { 'type': 'UserDefBase0',
>   'data': { 'base-string0': 'str', 'base-enum0': 'EnumOne' } }
> 
> Before this series, discriminator in union must be a string, and a
> hidden enum type as discriminator is generated. After this series,
> qapi schema can directly use predefined enum type:
> { 'union': 'UserDefEnumDiscriminatorUnion',
>   'base': 'UserDefBase0',
>   'discriminator' : 'base-enum0',
>   'data': { 'value1' : 'UserDefA',
> 'value2' : 'UserDefInherit',
> 'value3' : 'UserDefB' } }
> 
> The benefit is that every thing is defined explicitly in schema file,
> the discriminator enum type can be used in other API define in schema,
> and a compile time check will be put to verify the correctness according
> to enum define. Currently BlockdevOptions used discriminator which can
> be converted, in the future other union can also use enum discriminator.
> 
> The implement is done by:
> 1.1 remember the enum defines by qapi scripts.(patch 1)
> 1.2 use the remembered enum define to check correctness at compile
> time.(patch 3), more strict check(patch 2)
> 1.3 use the same enum name generation rule to avoid C code mismatch,
> esp for "case [ENUM_VALUE]" in qapi-visit.c.(patch 4,5)
> 1.4 switch the code path, when pre-defined enum type is used as discriminator,
> don't generate a hidden enum type, use the enum type instead, add
> docs/qapi-code-gen.txt.(Patch 6)
> 1.5 test case shows how it looks like.(Patch 7)
> 1.6 convert BlockdevOptions. (Patch 8)
> 
> 2. Better enum name generation
> Before this patch, AIOContext->A_I_O_CONTEXT, after this patch,
> AIOContet->AIO_CONTEXT. Since previous patch has foldered enum
> name generation codes into one function, it is done easily by modifying
> it.(Patch 9)

Applied to the qmp branch, thanks.

> 
> 
> Changes from RFC:
>   Mainly address Eric's comments: fix typo, add patch 2 to allow partly 
> mapping
> enum value in union, add related test case, remove direct inherit support 
> "_base"
> and related test case. RFC series at:
> http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg00363.html
> 
> v2:
>   General:
>   3/8: use Raise exception instead of sys.error.write in qapi.py.
>   Address Eric's comments:
>   2/8,3/8: more check for enum value at compile time, not allow partly 
> mapping.
>   8/8: correspond test case change.
> 
> v3:
>   General:
>   move enum name generation patch to last in the series, add convert patch
> 8/9.
>   Address Luiz and Kevin's comments:
>   Better introduction.
>   6/9: renamed this patch, add docs/qapi-code-gen.txt part.
> 
> v4:
>   Address Eric's comments:
>   5/9: better commit message.
>   6/9: typo fix in doc.
>   9/9: typo fix, fix indentation, better incode comment.
> 
> v5:
>   Address Eric's comments:
>   6/10: doc typo fix.
>   8/10: new patch to remove string discriminator.
>   9/10: removed the string discriminator test case.
> 
> v6:
>   rebased on upstream by adding "blgdebug" and "blkverify" in qapi-schema.json
> in patch 7/10.
> 
> Wenchao Xia (10):
>   1 qapi script: remember enum values
>   2 qapi script: add check for duplicated key
>   3 qapi script: check correctness of discriminator values in union
>   4 qapi script: code move for generate_enum_name()
>   5 qapi script: use same function to generate enum string
>   6 qapi script: support pre-defined enum type as discriminator in union
>   7 qapi: convert BlockdevOptions to use enum discriminator
>   8 qapi script: do not allow string discriminator
>   9 tests: add cases for inherited struct and union with discriminator
>   10 qapi script: do not add "_" for every capitalized char in enum
> 
>  docs/qapi-code-gen.txt  |8 ++-
>  include/qapi/qmp/qerror.h   |2 +-
>  qapi-schema.json|   14 -
>  scripts/qapi-types.py   |   34 +-
>  scripts/qapi-visit.py   |   61 ++---
>  scripts/qapi.py |   84 +--
>  target-i386/cpu.c   |2 +-
>  tests/qapi-schema/comments.out  |2 +-
>  tests/qapi-schema/qapi-schema-test.json |   22 ++
>  tests/qapi-schema/qapi-schema-test.out  |   13 +++-
>  tests/test-qmp-input-visitor.c  |   93 +
>  tests/test-qmp-output-visitor.c |  116 
> +++
>  12 files changed, 411 insertions(+), 40 deletions(-)
> 




Re: [Qemu-devel] CPU models and feature probing (was Re: [PATCH qom-cpu 00/16 v10] target-i386: convert CPU) features into properties

2014-02-11 Thread Anthony Liguori
On Tue, Feb 11, 2014 at 8:55 AM, Andreas Färber  wrote:
> Am 11.02.2014 16:58, schrieb Anthony Liguori:
>> On Tue, Feb 11, 2014 at 7:25 AM, Eduardo Habkost  wrote:
>>> On Tue, Feb 11, 2014 at 06:31:35AM -0800, Anthony Liguori wrote:
 On Fri, Feb 7, 2014 at 2:55 AM, Paolo Bonzini  wrote:
> Il 07/02/2014 11:16, Eduardo Habkost ha scritto:
>
>> You are not alone. I remember we spent lots of time trying to convince
>> Anthony to allow global properties and compat_props affect dynamic
>> properties not just static properties, and static properties were a big
>> deal due to reasons I didn't understand completely. Now I am hearing the
>> opposite message, and I don't understand the reasons for the change of
>> plans. I am confused.
>
>
> Picture me confused as well, but at the same I think I understand the
> reasons for the change of plans.

 There's no real convincing.  It's just a question of code.
>>>
>>> I am sure there's a lot of convincing involved, even after the code is
>>> written (in this case, 15 months after the code was written).
>>
>> N.B. the code you refer to doesn't "make global propeties and
>> compat_props affect dynamic properties."  It converts CPU properties
>> to static properties which I'm pretty sure I said many times is a
>> perfectly reasonable thing to do.
>>
 There are
 no defaults in classes for dynamic properties to modify.  compat_props
 are a nice mechanism, making them work for all properties is a
 reasonable thing to do.
>>>
>>> That's exactly the opposite of what you said before[1]. But that isn't
>>> supposed to be a problem, I understand there may be change of plans (we
>>> should be able to change our minds).
>>
>> I think you're confusing a few things.  You cannot make dynamic
>> properties work with globals today.  Globals change class default
>> values and there are no class defaults for dynamic properties.[*]
>>
>> There's a perfectly valid discussion to have about whether we should
>> even have dynamic properties.  It's certainly been a long time since
>> they were introduced and they haven't made their way into all that
>> many devices so it's reasonable to say that perhaps we'd be better off
>> without them.  I would not object to a patch series that moved
>> properties to classes entirely provided it removed existing uses of
>> dynamic properties and didn't just introduce yet another mechanism.
>>
>> But compat properties as a concept could be made to work with dynamic
>> properties.  They would have to be evaluated after instance init.
>> There's quite a few places they would end up touching I suspect.
>
> Erm, sorry, that is already implemented in qemu.git!? instance_post_init
> by Eduardo plus glue by me.

Ah, even better then :-)

Regards,

Anthony Liguori

> Andreas
>
>>
>> Another point of confusion worth mention is legacy properties since
>> this usually comes up in the discussion.  Legacy properties (the
>> properties that are set/get as strings) are something that we should
>> try to avoid.  They end up as strings on the wire and make it harder
>> to write client code.
>>
>> * I recognize that compat_props are implemented as globals.  I'm
>> really talking about the current implementation of globals, not the
>> concept of -global which could be made with dynamic properties.
>>
>> Regards,
>>
>> Anthony Liguori
>>
>>> What I don't understand is the rejection of code that works, matches the
>>> style used by 200+ other source files, adds more useful introspectable
>>> information, done in the way that was suggested 16 months ago, because
>>> we have some rough idea about how a new grand design will look like in
>>> the far future.
>>>
>>> [1] http://lists.gnu.org/archive/html/qemu-devel/2013-06/msg00990.html
>>>
>>> --
>>> Eduardo
>
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH V9 2/5] target-ppc: Fix htab_mask calculation

2014-02-11 Thread Aneesh Kumar K.V

Hi Greg,

can you try the below patch and see if it fix the TCG mode failure ?

-aneesh

commit d98b5098bc04f44ef4e175f689345e92cf469231
Author: Aneesh Kumar K.V 
Date:   Tue Feb 11 23:43:12 2014 +0530

tcg fixes

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index e1f778faf3ae..d3aca706fdc9 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -91,7 +91,10 @@ static target_ulong h_enter(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 
 pteh &= ~0x60ULL;
 
-if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
+/*
+ * hash value/pteg group index is normalized by htab_mask
+ */
+if (((pte_index & ~7ULL) / HPTES_PER_GROUP) & ~env->htab_mask) {
 return H_PARAMETER;
 }
 
@@ -140,7 +143,10 @@ static RemoveResult remove_hpte(CPUPPCState *env, 
target_ulong ptex,
 uint64_t token;
 target_ulong v, r, rb;
 
-if ((ptex * HASH_PTE_SIZE_64) & ~env->htab_mask) {
+/*
+ * hash value/pteg group index is normalized by htab_mask
+ */
+if (((ptex & ~7ULL) / HPTES_PER_GROUP) & ~env->htab_mask) {
 return REMOVE_PARM;
 }
 
@@ -266,7 +272,10 @@ static target_ulong h_protect(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 uint64_t token;
 target_ulong v, r, rb;
 
-if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
+/*
+ * hash value/pteg group index is normalized by htab_mask
+ */
+if (((pte_index & ~7ULL) / HPTES_PER_GROUP) & ~env->htab_mask) {
 return H_PARAMETER;
 }
 
@@ -303,7 +312,10 @@ static target_ulong h_read(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 uint8_t *hpte;
 int i, ridx, n_entries = 1;
 
-if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
+/*
+ * hash value/pteg group index is normalized by htab_mask
+ */
+if (((pte_index & ~7ULL) / HPTES_PER_GROUP) & ~env->htab_mask) {
 return H_PARAMETER;
 }
 




Re: [Qemu-devel] [PATCH 1/4] monitor: Add device_del id argument completion.

2014-02-11 Thread Luiz Capitulino
On Thu,  6 Feb 2014 23:30:10 +0100
Hani Benhabiles  wrote:

> ---
>  monitor.c | 23 +++
>  1 file changed, 23 insertions(+)

Your S-o-B is missing in all patches. Can reply to them adding it?

> 
> diff --git a/monitor.c b/monitor.c
> index b1ea262..f8c4cae 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4254,6 +4254,25 @@ static const char *next_arg_type(const char *typestr)
>  return (p != NULL ? ++p : typestr);
>  }
>  
> +static void device_del_completion(ReadLineState *rs, BusState *bus,
> +  const char *str, size_t len)
> +{
> +BusChild *kid;
> +
> +QTAILQ_FOREACH(kid, &bus->children, sibling) {
> +DeviceState *dev = kid->child;
> +BusState *dev_child;
> +
> +if (dev->id && !strncmp(str, dev->id, len)) {
> +readline_add_completion(rs, dev->id);
> +}
> +
> +QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
> +device_del_completion(rs, dev_child, str, len);
> +}
> +}
> +}
> +
>  static void monitor_find_completion_by_table(Monitor *mon,
>   const mon_cmd_t *cmd_table,
>   char **args,
> @@ -4330,6 +4349,10 @@ static void monitor_find_completion_by_table(Monitor 
> *mon,
>  } else if (!strcmp(cmd->name, "help|?")) {
>  monitor_find_completion_by_table(mon, cmd_table,
>   &args[1], nb_args - 1);
> +} else if (!strcmp(cmd->name, "device_del") && nb_args == 2) {
> +size_t len = strlen(str);
> +readline_set_completion_index(mon->rs, len);
> +device_del_completion(mon->rs, sysbus_get_default(), str, 
> len);
>  }
>  break;
>  default:




Re: [Qemu-devel] [PATCH v2 08/35] target-arm: A64: Implement store-exclusive for system mode

2014-02-11 Thread Peter Maydell
On 31 January 2014 15:45, Peter Maydell  wrote:
> System mode store-exclusive use a different code path to usermode ones;
> implement this missing code, in a similar way to the 32 bit version.
>
> Signed-off-by: Peter Maydell 

I just got a reviewed-by from rth on IRC for this patch
and so I'm going to add it to target-arm.next.

thanks
-- PMM



Re: [Qemu-devel] [PATCH 0/4] monitor: Add argument completion for multiple commands.

2014-02-11 Thread Luiz Capitulino
On Thu,  6 Feb 2014 23:30:09 +0100
Hani Benhabiles  wrote:

> This patch series add argument completion to multiple human monitor console
> commands.
> 
> For device_add and object_add, only the 1st argument is completed.
> 
> Hani Benhabiles (4):
>   monitor: Add device_del id argument completion.
>   monitor: Add device_add device argument completion.
>   monitor: Add object_del id argument completion.
>   monitor: Add object_add class argument completion.
> 
>  monitor.c | 95 
> +++
>  1 file changed, 95 insertions(+)

Series look good and I've applied it to my queue, but I need your sob
before sending a pull request.



Re: [Qemu-devel] [PATCH 4/4] monitor: Add object_add class argument completion.

2014-02-11 Thread Luiz Capitulino
On Thu,  6 Feb 2014 23:30:13 +0100
Hani Benhabiles  wrote:

> ---
>  monitor.c | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/monitor.c b/monitor.c
> index 4a2c1ae..397e1fe 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -56,6 +56,7 @@
>  #include "qapi/qmp/qjson.h"
>  #include "qapi/qmp/json-streamer.h"
>  #include "qapi/qmp/json-parser.h"
> +#include 
>  #include "qemu/osdep.h"
>  #include "cpu.h"
>  #include "trace.h"
> @@ -4275,6 +4276,26 @@ static void device_add_completion(ReadLineState *rs, 
> const char *str)
>  g_slist_free(list);
>  }
>  
> +static void object_add_completion(ReadLineState *rs, const char *str)
> +{
> +GSList *list, *elt;
> +size_t len;
> +
> +len = strlen(str);
> +readline_set_completion_index(rs, len);
> +list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
> +while (elt) {
> +const char *name;
> +
> +name = object_class_get_name(OBJECT_CLASS(elt->data));
> +if (!strncmp(name, str, len) && strcmp(name, TYPE_USER_CREATABLE)) {
> +readline_add_completion(rs, name);
> +}
> +elt = elt->next;
> +}
> +g_slist_free(list);
> +}
> +
>  static void device_del_completion(ReadLineState *rs, BusState *bus,
>const char *str, size_t len)
>  {
> @@ -4381,6 +4402,8 @@ static void monitor_find_completion_by_table(Monitor 
> *mon,
>  case 'O':
>  if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
>  device_add_completion(mon->rs, str);
> +} else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
> +object_add_completion(mon->rs, str);
>  }
>  break;
>  case 's':

Those many ifs need to be generalized. Maybe we could add a
command_completion callback to mon_cmd_t? Anyway, I won't refuse the series
because of that but it would be very welcome to improve this.



Re: [Qemu-devel] memory allocation of migration changed?

2014-02-11 Thread Stefan Priebe

Am 11.02.2014 17:22, schrieb Peter Lieven:




Am 11.02.2014 um 16:44 schrieb Stefan Hajnoczi :

On Tue, Feb 11, 2014 at 3:54 PM, Stefan Priebe - Profihost AG
 wrote:

in the past (Qemu 1.5) a migration failed if there was not enogh memory
on the target host available directly at the beginning.

Now with Qemu 1.7 i've seen succeeded migrations but the kernel OOM
memory killer killing qemu processes. So the migration seems to takes
place without having anough memory on the target machine?


How much memory is the guest configured with?  How much memory does
the host have?

I wonder if there are zero pages that can be migrated almost "for
free" and the destination host doesn't touch.  When they are touched
for the first time after migration handover, they need to be allocated
on the destination host.  This can lead to OOM if you overcommitted
memory.

Can you reproduce the OOM reliably?  It should be possible to debug it
and figure out whether it's just bad luck or a true regression.

Stefan


Kernel Version would also be interesting as well as thp and ksm settings.


Kernel Host: 3.10.26

What's thp / ksm? how to get those settings?

Greets,
Stefan



Re: [Qemu-devel] memory allocation of migration changed?

2014-02-11 Thread Stefan Priebe

Am 11.02.2014 16:44, schrieb Stefan Hajnoczi:

On Tue, Feb 11, 2014 at 3:54 PM, Stefan Priebe - Profihost AG
 wrote:

in the past (Qemu 1.5) a migration failed if there was not enogh memory
on the target host available directly at the beginning.

Now with Qemu 1.7 i've seen succeeded migrations but the kernel OOM
memory killer killing qemu processes. So the migration seems to takes
place without having anough memory on the target machine?


How much memory is the guest configured with?  How much memory does
the host have?


Guest: 48GB
Host: 192GB


I wonder if there are zero pages that can be migrated almost "for
free" and the destination host doesn't touch.  When they are touched
for the first time after migration handover, they need to be allocated
on the destination host.  This can lead to OOM if you overcommitted
memory.


In the past the migration failed immediatly with exit code 255.


Can you reproduce the OOM reliably?  It should be possible to debug it
and figure out whether it's just bad luck or a true regression.


So there is no known patch changing this behaviour?

What is about those?
fc1c4a5d32e15a4c40c47945da85ef9c1e0c1b54
211ea74022f51164a7729030b28eec90b6c99a08
f1c72795af573b24a7da5eb52375c9aba8a37972

Stefan



  1   2   3   >