Re: [Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-20 Thread Peter Lieven

On 21.03.2014 01:13, Leandro Dorileo wrote:

Do the directly migration from QemuOptionParameter to QemuOpts on
iscsi block driver.

Signed-off-by: Leandro Dorileo 
---
  block/iscsi.c | 32 
  1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..85252e7 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags,
  QemuOpts *opts;
  Error *local_err = NULL;
  const char *filename;
-int i, ret;
+int i, ret = 0;


why? is there a chance that ret remains uninitialized?

  
  if ((BDRV_SECTOR_SIZE % 512) != 0) {

  error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t 
offset)
  return 0;
  }
  
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,

-Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
  {
  int ret = 0;
  int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
  }

you don't need the if condition. 0 / BDRV_SECTOR_SIZE = 0.

Peter
  
  bs->opaque = g_malloc0(sizeof(struct IscsiLun));

@@ -1451,13 +1447,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"
+static QemuOptsList iscsi_create_options = {
+.name = "iscsi_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
  },
-{ NULL }
  };
  
  static BlockDriver bdrv_iscsi = {

@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
  .bdrv_file_open  = iscsi_open,
  .bdrv_close  = iscsi_close,
  .bdrv_create = iscsi_create,
-.create_options  = iscsi_create_options,
+.create_options  = &iscsi_create_options,
  .bdrv_reopen_prepare  = iscsi_reopen_prepare,
  
  .bdrv_getlength  = iscsi_getlength,



--

Mit freundlichen Grüßen

Peter Lieven

...

  KAMP Netzwerkdienste GmbH
  Vestische Str. 89-91 | 46117 Oberhausen
  Tel: +49 (0) 208.89 402-50 | Fax: +49 (0) 208.89 402-40
  p...@kamp.de | http://www.kamp.de

  Geschäftsführer: Heiner Lante | Michael Lante
  Amtsgericht Duisburg | HRB Nr. 12154
  USt-Id-Nr.: DE 120607556

...




[Qemu-devel] [PATCH v3] sparc : 32bits integer division overflow

2014-03-20 Thread Olivier Danet
The signed integer division -0x8000___ / -1 must be handled
separately to avoid an overflow on the QEMU host.

Negative overflow must be a negative number for correct sign
extension in Sparc64 mode. Use  constants.

Signed-off-by: Olivier Danet 
---
 target-sparc/helper.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index f3c7fbf..ae7740b 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -85,8 +85,8 @@ static target_ulong helper_udiv_common(CPUSPARCState *env, 
target_ulong a,
 }
 
 x0 = x0 / x1;
-if (x0 > 0x) {
-x0 = 0x;
+if (x0 > UINT32_MAX) {
+x0 = UINT32_MAX;
 overflow = 1;
 }
 
@@ -122,12 +122,15 @@ static target_ulong helper_sdiv_common(CPUSPARCState 
*env, target_ulong a,
 if (x1 == 0) {
 cpu_restore_state(CPU(cpu), GETPC());
 helper_raise_exception(env, TT_DIV_ZERO);
-}
-
-x0 = x0 / x1;
-if ((int32_t) x0 != x0) {
-x0 = x0 < 0 ? 0x8000 : 0x7fff;
+} else if (x1 == -1 && x0 == INT64_MIN) {
+x0 = INT32_MAX;
 overflow = 1;
+} else {
+x0 = x0 / x1;
+if ((int32_t) x0 != x0) {
+x0 = x0 < 0 ? INT32_MIN : INT32_MAX;
+overflow = 1;
+}
 }
 
 if (cc) {
-- 
1.8.1.5



[Qemu-devel] [PATCH 17/26] rbd: migrate rbd driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
rbd block driver.

Signed-off-by: Leandro Dorileo 
---
 block/rbd.c | 60 +---
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..ae8c471 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 *options,
Error **errp)
 {
 int64_t bytes = 0;
@@ -305,25 +305,19 @@ static int qemu_rbd_create(const char *filename, 
QEMUOptionParameter *options,
 return -EINVAL;
 }
 
-/* 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(options, BLOCK_OPT_SIZE, 0);
+objsize = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+if (objsize != 0) {
+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,22 @@ 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"
+static QemuOptsList qemu_rbd_create_options = {
+.name = "qemu_rbd_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_options.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"
+},
+{NULL}
 },
-{NULL}
 };
 
 static BlockDriver bdrv_rbd = {
@@ -923,7 +921,7 @@ static BlockDriver bdrv_rbd = {
 .bdrv_create= 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_options = &qemu_rbd_create_options,
 .bdrv_getlength = qemu_rbd_getlength,
 .bdrv_truncate  = qemu_rbd_truncate,
 .protocol_name  = "rbd",
-- 
1.9.0




[Qemu-devel] [PATCH 06/26] block: migrate block later QemuOptionParameter

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
block layer.

Signed-off-by: Leandro Dorileo 
---
 block.c   | 133 --
 include/block/block.h |   7 ++-
 include/block/block_int.h |   8 ++-
 3 files changed, 86 insertions(+), 62 deletions(-)

diff --git a/block.c b/block.c
index acb70fd..e70f360 100644
--- a/block.c
+++ b/block.c
@@ -407,7 +407,7 @@ BlockDriver *bdrv_find_whitelisted_format(const char 
*format_name,
 typedef struct CreateCo {
 BlockDriver *drv;
 char *filename;
-QEMUOptionParameter *options;
+QemuOpts *options;
 int ret;
 Error *err;
 } CreateCo;
@@ -427,8 +427,8 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 cco->ret = ret;
 }
 
-int bdrv_create(BlockDriver *drv, const char* filename,
-QEMUOptionParameter *options, Error **errp)
+int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *options,
+Error **errp)
 {
 int ret;
 
@@ -472,8 +472,7 @@ out:
 return ret;
 }
 
-int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+int bdrv_create_file(const char *filename, QemuOpts *options, Error **errp)
 {
 BlockDriver *drv;
 Error *local_err = NULL;
@@ -1248,7 +1247,7 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 BlockDriverState *bs1;
 int64_t total_size;
 BlockDriver *bdrv_qcow2;
-QEMUOptionParameter *create_options;
+QemuOpts *create_options;
 QDict *snapshot_options;
 
 /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1273,27 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 }
 
 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);
+create_options = qemu_opts_create(bdrv_qcow2->create_options, NULL, 0,
+  &local_err);
+
+if (create_options == NULL) {
+error_setg(errp, "Could not create internal option %s",
+   error_get_pretty(local_err));
+error_free(local_err);
+local_err = NULL;
+goto fail;
+}
+
+ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, total_size);
+if (ret < 0) {
+qemu_opts_del(create_options);
+goto fail;
+}
 
 ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, 
&local_err);
-free_option_parameters(create_options);
+qemu_opts_del(create_options);
+
 if (ret < 0) {
 error_setg_errno(errp, -ret, "Could not create temporary overlay "
  "'%s': %s", tmp_filename,
@@ -5259,12 +5272,14 @@ 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;
-QEMUOptionParameter *backing_fmt, *backing_file, *size;
+QemuOptsList *list;
+QemuOpts *create_options;
+const char *backing_file, *backing_fmt;
 BlockDriver *drv, *proto_drv;
 BlockDriver *backing_drv = NULL;
 Error *local_err = NULL;
 int ret = 0;
+uint64_t size;
 
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
@@ -5279,28 +5294,39 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
 return;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+list = qemu_opts_append(drv->create_options, proto_drv->create_options);
+if (!list) {
+error_setg(errp, "Could not allocate option list");
+return;
+}
 
-/* Create parameter list with default values */
-param = parse_option_parameters("", create_options, param);
+create_options = qemu_opts_create(list, NULL, 0, &local_err);
+if (create_options == NULL) {
+error_setg(errp, "Could not create internal option %s",
+   error_get_pretty(local_err));
+error_free(local_err);
+g_free(list);
+local_err = NULL;
+return;
+}
 
-set_option_parameter_int(param, BLOCK_OPT_SIZE, img_size);
+ret = qemu_opt_set_number(create_options, BLOCK_OPT_SIZE, img_size);
+if (ret < 0) {
+goto out;
+}
 
 /* Parse -o options */
 if (options) {
-param = parse_option_parameters(options, create_options, param);
-if (param == NULL) {
-error_setg(errp, "Invalid opti

[Qemu-devel] [PATCH 19/26] ssh: migrate ssh driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
ssh block driver.

Signed-off-by: Leandro Dorileo 
---
 block/ssh.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..b55c518 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -642,17 +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"
+static QemuOptsList ssh_create_options = {
+.name = "ssh_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(ssh_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int ssh_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int r, ret;
 Error *local_err = NULL;
@@ -664,13 +667,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(options, BLOCK_OPT_SIZE, 0);
 DPRINTF("total_size=%" PRIi64, total_size);
 
 uri_options = qdict_new();
@@ -1051,7 +1048,7 @@ static BlockDriver bdrv_ssh = {
 .bdrv_co_writev   = ssh_co_writev,
 .bdrv_getlength   = ssh_getlength,
 .bdrv_co_flush_to_disk= ssh_co_flush,
-.create_options   = ssh_create_options,
+.create_options   = &ssh_create_options,
 };
 
 static void bdrv_ssh_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 20/26] vdi: migrate vdi driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vdi block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vdi.c | 73 -
 1 file changed, 34 insertions(+), 39 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index ae49cd8..4f8a143 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -653,8 +653,7 @@ static int vdi_co_write(BlockDriverState *bs,
 return ret;
 }
 
-static int vdi_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int vdi_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int result = 0;
@@ -662,31 +661,23 @@ static int vdi_create(const char *filename, 
QEMUOptionParameter *options,
 uint32_t blocks;
 size_t block_size = DEFAULT_CLUSTER_SIZE;
 uint32_t image_type = VDI_TYPE_DYNAMIC;
+bool stat;
 VdiHeader header;
 size_t i;
 size_t bmap_size;
 
 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(options, 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;
-}
-#endif
-#if defined(CONFIG_VDI_STATIC_IMAGE)
-} else if (!strcmp(options->name, BLOCK_OPT_STATIC)) {
-if (options->value.n) {
-image_type = VDI_TYPE_STATIC;
-}
+/* TODO: Additional checks (SECTOR_SIZE * 2^n, ...). */
+block_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
 #endif
-}
-options++;
+
+stat = qemu_opt_get_bool(options, BLOCK_OPT_STATIC, false);
+if (stat) {
+image_type = VDI_TYPE_STATIC;
 }
 
 fd = qemu_open(filename,
@@ -767,29 +758,33 @@ 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_options = {
+.name = "vdi_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vdi_create_options.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_val = QEMU_OPT_VAL_SIZE(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"
+},
 #endif
-/* TODO: An additional option to set UUID values might be useful. */
-{ NULL }
+/* TODO: An additional option to set UUID values might be useful. */
+{ NULL }
+},
 };
 
 static BlockDriver bdrv_vdi = {
@@ -811,7 +806,7 @@ static BlockDriver bdrv_vdi = {
 
 .bdrv_get_info = vdi_get_info,
 
-.create_options = vdi_create_options,
+.create_options = &vdi_create_options,
 .bdrv_check = vdi_check,
 };
 
-- 
1.9.0




[Qemu-devel] [PATCH 11/26] qcow: migrate qcow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qcow.c | 59 +--
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 1e128be..65c7486 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -662,31 +662,26 @@ static void qcow_close(BlockDriverState *bs)
 error_free(s->migration_blocker);
 }
 
-static int qcow_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int qcow_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int header_size, backing_filename_len, l1_size, shift, i;
 QCowHeader header;
 uint8_t *tmp;
 int64_t total_size = 0;
 const char *backing_file = NULL;
-int flags = 0;
+uint64_t flags = 0;
 Error *local_err = NULL;
 int ret;
 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(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / 512;
 }
 
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+flags |= qemu_opt_get_number(options, BLOCK_OPT_ENCRYPT, 0);
+
 ret = bdrv_create_file(filename, options, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
@@ -882,23 +877,27 @@ static int qcow_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 }
 
 
-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"
+static QemuOptsList qcow_create_options = {
+.name = "qcow_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qcow_create_options.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_NUMBER,
+.help = "Encrypt the image"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_qcow = {
@@ -920,7 +919,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_write_compressed  = qcow_write_compressed,
 .bdrv_get_info  = qcow_get_info,
 
-.create_options = qcow_create_options,
+.create_options = &qcow_create_options,
 };
 
 static void bdrv_qcow_init(void)
-- 
1.9.0




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

2014-03-20 Thread Leandro Dorileo
From: Chunyan Liu 

Change qapi interfaces to output the newly added def_value_str when querying
command line options.

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

diff --git a/qapi-schema.json b/qapi-schema.json
index b68cd44..cf9174e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4088,12 +4088,16 @@
 #
 # @help: #optional human readable text string, not suitable for parsing.
 #
+# @default: #optional string representation of the default used
+#   if the option is omitted. (since 2.0)
+#
 # Since 1.5
 ##
 { '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 a22621f..178aadd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2895,6 +2895,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 f610101..d608b2f 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.9.0




[Qemu-devel] [PATCH 18/26] sheepdog: migrate sheepdog driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
sheepdog block driver.

Signed-off-by: Leandro Dorileo 
---
 block/sheepdog.c | 104 ---
 1 file changed, 53 insertions(+), 51 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f7bd024..4f4945f 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1626,17 +1626,18 @@ static int parse_redundancy(BDRVSheepdogState *s, const 
char *opt)
 return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
- Error **errp)
+static int sd_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 uint32_t vid = 0;
-char *backing_file = NULL;
+const char *backing_file = NULL;
 BDRVSheepdogState *s;
 char tag[SD_MAX_VDI_TAG_LEN];
 uint32_t snapid;
 bool prealloc = false;
 Error *local_err = NULL;
+const char *prealloc_opt;
+char *redundancy_opt;
 
 s = g_malloc0(sizeof(BDRVSheepdogState));
 
@@ -1650,31 +1651,28 @@ 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(options, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = false;
+} else if (!strcmp(prealloc_opt, "full")) {
+prealloc = true;
+} else {
+error_report("Invalid preallocation mode: '%s'", prealloc_opt);
+ret = -EINVAL;
+goto out;
+}
+}
+
+redundancy_opt = (char *)qemu_opt_get(options, BLOCK_OPT_REDUNDANCY);
+if (redundancy_opt) {
+ret = parse_redundancy(s, redundancy_opt);
+if (ret < 0) {
+goto out;
 }
-options++;
 }
 
 if (s->inode.vdi_size > SD_MAX_VDI_SIZE) {
@@ -2490,28 +2488,32 @@ 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"
+static QemuOptsList sd_create_options = {
+.name = "sd_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(sd_create_options.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)"
+},
+{
+.name = BLOCK_OPT_REDUNDANCY,
+.type = QEMU_OPT_STRING,
+.help = "Redundancy of the image"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2541,7 +2543,7 @@ static BlockDriver bdrv_sheepdog = {
 .bdrv_save_vmstate  = sd_save_vmstate,
 .bdrv_load_vmstate  = sd_load_vmstate,
 
-.create_options = sd_create_options,
+.create_options = &sd_create_options,
 };
 
 static BlockDriver bdrv_sheepdog_tcp = {
@@ -2571,7 +2573,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
 .bdrv_save_vmstate  = sd_save_vmstate,
 .bdrv_load_vmstate  = sd_load_vmstate,
 
-.create_opti

[Qemu-devel] [PATCH 00/26] QemuOptionParameter -> QemuOpts migration

2014-03-20 Thread Leandro Dorileo
This patch series does the QemuOptionParameter -> QemuOpts migration. The idea
is to collect all the required Reviewed-by and squash the patches changing the
block layer + block drivers (patches [06..25]) in a single patch so we don't
break anything and keep the tree's bisectability (just in case we realize this 
patch
series must be integrated).

In response to Chunyan's patchset, this patch series was first intended to 
describe
my thoughts on how this migration should be performed.

The patches 2 and 3 can be squashed later on, I just kept them split to keep
Chunyan's authorship.

--
Dorileo

Chunyan Liu (3):
  qapi: output def_value_str when query command line options
  add def_value_str to QemuOptDesc
  QemuOpt: introduce qemu_opts_append()

Leandro Dorileo (23):
  QemuOpt: improve default value
  QemuOpt: add qemu_opt_print_help()
  block: migrate block later QemuOptionParameter
  cow: migrate cow driver QemuOptionParameter usage
  gluster: migrate gluster driver QemuOptionParameter usage
  iscsi: migrate iscsi driver QemuOptionParameter usage
  nfs: migrate nfs driver QemuOptionParameter usage
  qcow: migrate qcow driver QemuOptionParameter usage
  qcow2: migrate qcow2 driver QemuOptionParameter usage
  qed: migrate qed driver QemuOptionParameter usage
  raw-posix: migrate raw-posix driver QemuOptionParameter usage
  raw-win32: migrate cow driver QemuOptionParameter usage
  raw_bsd: migrate raw_bsd driver QemuOptionParameter usage
  rbd: migrate rbd driver QemuOptionParameter usage
  sheepdog: migrate sheepdog driver QemuOptionParameter usage
  ssh: migrate ssh driver QemuOptionParameter usage
  vdi: migrate vdi driver QemuOptionParameter usage
  vhdx: migrate vhdx driver QemuOptionParameter usage
  vmdk: migrate vmdk driver QemuOptionParameter usage
  vpc: migrate vpc driver QemuOptionParameter usage
  vvfat: migrate vvfat driver QemuOptionParameter usage
  QemuOpt: get rid of QEMUOptionParameter
  qemu-img: migrate QemuOptionParameter usage

 block.c   | 133 +--
 block/cow.c   |  44 
 block/gluster.c   |  68 ++--
 block/iscsi.c |  32 +++---
 block/nfs.c   |  11 +-
 block/qcow.c  |  59 +--
 block/qcow2.c | 263 ++
 block/qed.c   |  79 ++
 block/raw-posix.c |  50 -
 block/raw-win32.c |  29 +++--
 block/raw_bsd.c   |  21 ++--
 block/rbd.c   |  60 +--
 block/sheepdog.c  | 104 +-
 block/ssh.c   |  29 +++--
 block/vdi.c   |  73 ++---
 block/vhdx.c  |  88 
 block/vmdk.c  | 105 +-
 block/vpc.c   |  54 +-
 block/vvfat.c |  26 -
 include/block/block.h |   7 +-
 include/block/block_int.h |   8 +-
 include/qemu/option.h |  23 +++-
 qapi-schema.json  |   6 +-
 qemu-img.c| 166 -
 qmp-commands.hx   |   2 +
 util/qemu-config.c|   4 +
 util/qemu-option.c| 174 +-
 27 files changed, 952 insertions(+), 766 deletions(-)

-- 
1.9.0




[Qemu-devel] [PATCH 24/26] vvfat: migrate vvfat driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vvfat block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vvfat.c | 26 +-
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index f966ea5..7aefba3 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -2907,7 +2907,7 @@ static BlockDriver vvfat_write_target = {
 static int enable_write_target(BDRVVVFATState *s)
 {
 BlockDriver *bdrv_qcow;
-QEMUOptionParameter *options;
+QemuOpts *options;
 Error *local_err = NULL;
 int ret;
 int size = sector2cluster(s, s->sector_count);
@@ -2918,13 +2918,26 @@ static int enable_write_target(BDRVVVFATState *s)
 s->qcow_filename = g_malloc(1024);
 ret = get_tmp_filename(s->qcow_filename, 1024);
 if (ret < 0) {
-goto err;
+goto err_opt;
 }
 
 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:");
+
+options = qemu_opts_create(bdrv_qcow->create_options, NULL, 0,
+   &error_abort);
+if (!options) {
+goto err_opt;
+}
+
+ret = qemu_opt_set_number(options, BLOCK_OPT_SIZE, s->sector_count * 512);
+if (ret < 0) {
+goto err;
+}
+
+ret = qemu_opt_set(options, BLOCK_OPT_BACKING_FILE, "fat:");
+if (ret < 0) {
+goto err;
+}
 
 ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, &local_err);
 if (ret < 0) {
@@ -2951,10 +2964,13 @@ static int enable_write_target(BDRVVVFATState *s)
 s->bs->backing_hd->drv = &vvfat_write_target;
 s->bs->backing_hd->opaque = g_malloc(sizeof(void*));
 *(void**)s->bs->backing_hd->opaque = s;
+qemu_opts_del(options);
 
 return 0;
 
 err:
+qemu_opts_del(options);
+err_opt:
 g_free(s->qcow_filename);
 s->qcow_filename = NULL;
 return ret;
-- 
1.9.0




[Qemu-devel] [PATCH 22/26] vmdk: migrate vmdk driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vmdk block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vmdk.c | 105 ++-
 1 file changed, 53 insertions(+), 52 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..1974c30 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1681,8 +1681,7 @@ static int filename_decompose(const char *filename, char 
*path, char *prefix,
 return VMDK_OK;
 }
 
-static int vmdk_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int vmdk_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int idx = 0;
 BlockDriverState *new_bs = NULL;
@@ -1704,6 +1703,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 uint32_t number_heads = 16;
 bool zeroed_grain = false;
 uint32_t desc_offset = 0, desc_len;
+bool compat6;
 const char desc_template[] =
 "# Disk DescriptorFile\n"
 "version=1\n"
@@ -1730,23 +1730,19 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 ret = -EINVAL;
 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(options, BLOCK_OPT_SIZE, 0);
+adapter_type = qemu_opt_get(options, BLOCK_OPT_ADAPTER_TYPE);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
+compat6 = qemu_opt_get_bool(options, BLOCK_OPT_COMPAT6, false);
+if (compat6) {
+flags |= BLOCK_FLAG_COMPAT6;
 }
+
+fmt = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+zeroed_grain = qemu_opt_get_bool(options, BLOCK_OPT_ZEROED_GRAIN, false);
+
 if (!adapter_type) {
 adapter_type = "ide";
 } else if (strcmp(adapter_type, "ide") &&
@@ -2062,41 +2058,46 @@ 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 =
+static QemuOptsList vmdk_create_options = {
+.name = "vmdk_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vmdk_create_options.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"
+},
+{
+.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_OPT_ZEROED_GRAIN,
-.type = OPT_FLAG,
-.help = "Enable efficient zero writes using the zeroed-grain GTE 
feature"
-},
-{ NULL }
+},
+{
+.name = BLOCK_OPT_ZEROED_GRAIN,
+.type = QEMU_OPT_BOOL,
+.help = "Enable efficient zero writes using the zeroed-grain "
+"GTE feature"
+},
+{ NULL }
+}
 };
 
 static BlockDriver bdrv_vmdk = {
@@ -2118,7 +2119,7 

Re: [Qemu-devel] [RFC PATCH V3 5/5] qapi event: convert RTC_CHANGE

2014-03-20 Thread Eric Blake
On 03/18/2014 11:16 PM, Wenchao Xia wrote:
> This is just an example of how to use qapi event API, and it
> bypassed the event throttle queue. A complete convert should
> be first define all events in qapi-schema.json, use qapi
> event types in monitor functions, then change caller one
> by one.

This commit message will need to be adjusted when you change this to be
a non-RFC series.

> 
> Signed-off-by: Wenchao Xia 
> ---
>  monitor.c|   15 +++
>  qapi-schema.json |   13 +
>  vl.c |7 ++-
>  3 files changed, 30 insertions(+), 5 deletions(-)
> 

I'm liking where this is headed, and looking forward to the full
conversion in 2.1

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 16/26] raw_bsd: migrate raw_bsd driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw_bsd block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw_bsd.c | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 01ea692..5090b4e 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"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ 0 }
 },
-{ 0 }
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,8 +143,7 @@ static int raw_has_zero_init(BlockDriverState *bs)
 return bdrv_has_zero_init(bs->file);
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 Error *local_err = NULL;
 int ret;
@@ -194,7 +197,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_options   = &raw_create_options,
 .bdrv_has_zero_init   = &raw_has_zero_init
 };
 
-- 
1.9.0




Re: [Qemu-devel] [RFC PATCH V3 4/5] test: add test cases for qapi event

2014-03-20 Thread Eric Blake
On 03/18/2014 11:16 PM, Wenchao Xia wrote:
> These cases will verify whether the expected qdict is built.
> 
> Signed-off-by: Wenchao Xia 
> ---
>  tests/Makefile  |   14 ++-
>  tests/qapi-schema/qapi-schema-test.json |   12 ++
>  tests/qapi-schema/qapi-schema-test.out  |   10 +-
>  tests/test-qmp-event.c  |  258 
> +++
>  4 files changed, 289 insertions(+), 5 deletions(-)
>  create mode 100644 tests/test-qmp-event.c
> 


> +++ b/tests/test-qmp-event.c
> @@ -0,0 +1,258 @@
> +/*
> + * qapi event unit-tests.
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.
> + *

Missing "Copyright"

> +case QTYPE_QINT:
> +d->result = (qint_get_int(qobject_to_qint(obj1)) ==
> + qint_get_int(qobject_to_qint(obj2)));
> +return;
> +case QTYPE_QSTRING:
> +if (!g_strcmp0(qstring_get_str(qobject_to_qstring(obj1)),
> +   qstring_get_str(qobject_to_qstring(obj2 {
> +d->result = true;
> +} else {
> +d->result = false;
> +}

Could also be written without 'if':
  d->result = g_strcmp0(...) == 0;

> +obj = qdict_get(t, "seconds");
> +g_assert(obj && qobject_type(obj) == QTYPE_QINT);
> +obj = qdict_get(t, "microseconds");
> +g_assert(obj && qobject_type(obj) == QTYPE_QINT);

Might be worth asserting that microseconds is within the range
[0,99] (or -1 if seconds is -1)

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 15/26] raw-win32: migrate cow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-win32 block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw-win32.c | 29 +
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 48cb2c2..4cca514 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -475,21 +475,14 @@ static int64_t 
raw_get_allocated_file_size(BlockDriverState *bs)
 return st.st_size;
 }
 
-static int raw_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int64_t total_size = 0;
 
 strstart(filename, "file:", &filename);
 
-/* 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(options, BLOCK_OPT_SIZE, 0);
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -503,13 +496,17 @@ 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"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_file = {
@@ -532,7 +529,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 };
 
 /***/
-- 
1.9.0




[Qemu-devel] [PATCH 26/26] qemu-img: migrate QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qemu-img.

Signed-off-by: Leandro Dorileo 
---
 qemu-img.c | 166 +++--
 1 file changed, 95 insertions(+), 71 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 2e40cc1..1a8ce3c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -235,7 +235,9 @@ static int read_password(char *buf, int buf_size)
 static int print_block_option_help(const char *filename, const char *fmt)
 {
 BlockDriver *drv, *proto_drv;
-QEMUOptionParameter *create_options = NULL;
+QemuOptsList *proto_opts = NULL;
+QemuOpts *opts;
+QemuOptsList *list;
 
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
@@ -244,21 +246,32 @@ static int print_block_option_help(const char *filename, 
const char *fmt)
 return 1;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-
 if (filename) {
 proto_drv = bdrv_find_protocol(filename, true);
 if (!proto_drv) {
 error_report("Unknown protocol '%s'", filename);
 return 1;
 }
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+proto_opts = proto_drv->create_options;
+}
+
+list = qemu_opts_append(drv->create_options, proto_opts);
+if (!list) {
+error_report("Could not allocate option descriptors structure");
+return 1;
+}
+
+opts = qemu_opts_create(list, NULL, 0, &error_abort);
+if (!list) {
+error_report("Could not allocate options structure");
+g_free(list);
+return 1;
 }
 
-print_option_help(create_options);
-free_option_parameters(create_options);
+qemu_opts_print_help(opts);
+
+qemu_opts_del(opts);
+g_free(list);
 return 0;
 }
 
@@ -311,22 +324,26 @@ fail:
 return NULL;
 }
 
-static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
+static int add_old_style_options(const char *fmt, QemuOpts *opts,
  const char *base_filename,
  const char *base_fmt)
 {
+int ret;
+
 if (base_filename) {
-if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) 
{
+ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename);
+if (ret < 0) {
 error_report("Backing file not supported for file format '%s'",
  fmt);
-return -1;
+return ret;
 }
 }
 if (base_fmt) {
-if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
+ret = qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt);
+if (ret < 0) {
 error_report("Backing file format not supported for file "
  "format '%s'", fmt);
-return -1;
+return ret;
 }
 }
 return 0;
@@ -1153,8 +1170,8 @@ static int img_convert(int argc, char **argv)
 size_t bufsectors = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
 const uint8_t *buf1;
 BlockDriverInfo bdi;
-QEMUOptionParameter *param = NULL, *create_options = NULL;
-QEMUOptionParameter *out_baseimg_param;
+QemuOpts *create_options;
+QemuOptsList *opts_list = NULL;
 char *options = NULL;
 const char *snapshot_name = NULL;
 int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
@@ -1340,72 +1357,73 @@ static int img_convert(int argc, char **argv)
 goto out;
 }
 
-create_options = append_option_parameters(create_options,
-  drv->create_options);
-create_options = append_option_parameters(create_options,
-  proto_drv->create_options);
+opts_list = qemu_opts_append(drv->create_options,
+ proto_drv->create_options);
+if (!opts_list) {
+error_report("Could not allocate option descriptors structure");
+ret = -1;
+goto out;
+}
+
+create_options = qemu_opts_create(opts_list, NULL, 0, &error_abort);
+if (!create_options) {
+error_report("Could not allocate options structure");
+ret = -1;
+goto err_opts;
+}
 
 if (options) {
-param = parse_option_parameters(options, create_options, param);
-if (param == NULL) {
+ret = qemu_opts_do_parse(create_options, options, NULL);
+if (ret < 0) {
 error_report("Invalid options for file format '%s'.", out_fmt);
-ret = -1;
-goto out;
+goto err;
 }
-} else {
-param = parse_option_parameters("", create_options, param);
 }
 
-set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
-ret = add_old_style_options(out_fmt, para

[Qemu-devel] [PATCH 12/26] qcow2: migrate qcow2 driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qcow2 block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qcow2.c | 263 --
 1 file changed, 128 insertions(+), 135 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index b9dc960..a69438f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1472,7 +1472,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 *options, int version,
  Error **errp)
 {
 /* Calculate cluster_bits */
@@ -1639,9 +1639,10 @@ out:
 return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *options, Error **errp)
 {
+const char *compat_level_opt = NULL;
+const char *prealloc_opt = NULL;
 const char *backing_file = NULL;
 const char *backing_fmt = NULL;
 uint64_t sectors = 0;
@@ -1652,46 +1653,47 @@ static int qcow2_create(const char *filename, 
QEMUOptionParameter *options,
 Error *local_err = NULL;
 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;
+sectors = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (sectors) {
+sectors = sectors / 512;
+}
+
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+
+if (qemu_opt_get_bool(options, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
+}
+
+cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = 0;
+} else if (!strcmp(prealloc_opt, "metadata")) {
+prealloc = 1;
+} else {
+error_setg(errp, "Invalid preallocation mode: '%s'", prealloc_opt);
+return -EINVAL;
+}
+}
+
+compat_level_opt = qemu_opt_get(options, BLOCK_OPT_COMPAT_LEVEL);
+if (compat_level_opt) {
+if (!strcmp(compat_level_opt, "0.10")) {
+version = 2;
+} else if (!strcmp(compat_level_opt, "1.1")) {
+version = 3;
+} else {
+error_setg(errp, "Invalid compatibility level: '%s'",
+   compat_level_opt);
+return -EINVAL;
 }
-options++;
+}
+
+if (qemu_opt_get_bool(options, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
 }
 
 if (backing_file && prealloc) {
@@ -2075,66 +2077,53 @@ static int qcow2_downgrade(BlockDriverState *bs, int 
target_version)
 return 0;
 }
 
-static int qcow2_amend_options(BlockDriverState *bs,
-   QEMUOptionParameter *options)
+static int qcow2_amend_options(BlockDriverState *bs, Q

[Qemu-devel] [PATCH 21/26] vhdx: migrate vhdx driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vhdx block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vhdx.c | 88 
 1 file changed, 41 insertions(+), 47 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index 5390ba6..106ea7a 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1708,8 +1708,7 @@ exit:
  *. ~ --- ~  ~  ~ ---.
  *   1MB
  */
-static int vhdx_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int vhdx_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1726,20 +1725,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(options, BLOCK_OPT_SIZE, 0);
+log_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+block_size = qemu_opt_get_size(options, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+type = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
+use_zero_blocks = qemu_opt_get_bool(options, VHDX_BLOCK_OPT_ZERO, false);
 
 if (image_size > VHDX_MAX_IMAGE_SIZE) {
 error_setg_errno(errp, EINVAL, "Image size too large; max of 64TB");
@@ -1870,37 +1860,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."
+static QemuOptsList vhdx_create_options = {
+.name = "vhdx_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_options.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_val = QEMU_OPT_VAL_SIZE(1 * MiB),
+.help = "Log size; min 1MB."
+},
+{
+.name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+.type = QEMU_OPT_SIZE,
+.def_val = QEMU_OPT_VAL_SIZE(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 }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_vhdx = {
@@ -1916,7 +1910,7 @@ static BlockDriver bdrv_vhdx = {
 .bdrv_get_info  = vhdx_get_info,
 .bdrv_check = vhdx_check,
 
-.create_options = vhdx_create_options,
+.create_options = &vhdx_create_options,
 };
 
 static void bdrv_vhdx_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 10/26] nfs: migrate nfs driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
nfs block driver.

Signed-off-by: Leandro Dorileo 
---
 block/nfs.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 98aa363..c01f109 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -357,20 +357,13 @@ static int nfs_file_open(BlockDriverState *bs, QDict 
*options, int flags,
 return 0;
 }
 
-static int nfs_file_create(const char *url, QEMUOptionParameter *options,
-   Error **errp)
+static int nfs_file_create(const char *url, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 int64_t total_size = 0;
 NFSClient *client = g_malloc0(sizeof(NFSClient));
 
-/* Read out options */
-while (options && options->name) {
-if (!strcmp(options->name, "size")) {
-total_size = options->value.n;
-}
-options++;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
 
 ret = nfs_client_open(client, url, O_CREAT, errp);
 if (ret < 0) {
-- 
1.9.0




[Qemu-devel] [PATCH 09/26] iscsi: migrate iscsi driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
iscsi block driver.

Signed-off-by: Leandro Dorileo 
---
 block/iscsi.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index b490e98..85252e7 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1125,7 +1125,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags,
 QemuOpts *opts;
 Error *local_err = NULL;
 const char *filename;
-int i, ret;
+int i, ret = 0;
 
 if ((BDRV_SECTOR_SIZE % 512) != 0) {
 error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. "
@@ -1382,8 +1382,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t 
offset)
 return 0;
 }
 
-static int iscsi_create(const char *filename, QEMUOptionParameter *options,
-Error **errp)
+static int iscsi_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int ret = 0;
 int64_t total_size = 0;
@@ -1393,12 +1392,9 @@ 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(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 bs->opaque = g_malloc0(sizeof(struct IscsiLun));
@@ -1451,13 +1447,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"
+static QemuOptsList iscsi_create_options = {
+.name = "iscsi_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(iscsi_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_iscsi = {
@@ -1469,7 +1469,7 @@ static BlockDriver bdrv_iscsi = {
 .bdrv_file_open  = iscsi_open,
 .bdrv_close  = iscsi_close,
 .bdrv_create = iscsi_create,
-.create_options  = iscsi_create_options,
+.create_options  = &iscsi_create_options,
 .bdrv_reopen_prepare  = iscsi_reopen_prepare,
 
 .bdrv_getlength  = iscsi_getlength,
-- 
1.9.0




[Qemu-devel] [PATCH 14/26] raw-posix: migrate raw-posix driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
raw-posix block driver.

Signed-off-by: Leandro Dorileo 
---
 block/raw-posix.c | 50 +++---
 1 file changed, 23 insertions(+), 27 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 1688e16..ddeafa7 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1234,8 +1234,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,
-  Error **errp)
+static int raw_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int result = 0;
@@ -1243,12 +1242,9 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 
 strstart(filename, "file:", &filename);
 
-/* 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(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
@@ -1410,13 +1406,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"
+static QemuOptsList raw_create_options = {
+.name = "raw_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_file = {
@@ -1448,7 +1448,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 };
 
 /***/
@@ -1769,8 +1769,7 @@ static coroutine_fn int 
hdev_co_write_zeroes(BlockDriverState *bs,
 return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int hdev_create(const char *filename, QemuOpts *options, Error **errp)
 {
 int fd;
 int ret = 0;
@@ -1789,12 +1788,9 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options,
 
 (void)has_prefix;
 
-/* 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(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
 }
 
 fd = qemu_open(filename, O_WRONLY | O_BINARY);
@@ -1833,7 +1829,7 @@ static BlockDriver bdrv_host_device = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
 .bdrv_aio_readv= raw_aio_readv,
@@ -1977,7 +1973,7 @@ static BlockDriver bdrv_host_floppy = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2102,7 +2098,7 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2233,7 +2229,7 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
 .bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.create_options = &raw_create_options,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
-- 
1.9.0




[Qemu-devel] [PATCH 13/26] qed: migrate qed driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
qed block driver.

Signed-off-by: Leandro Dorileo 
---
 block/qed.c | 79 +++--
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index 3bd9db9..c082ba3 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -621,7 +621,7 @@ out:
 return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
+static int bdrv_qed_create(const char *filename, QemuOpts *options,
Error **errp)
 {
 uint64_t image_size = 0;
@@ -630,24 +630,11 @@ 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(options, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get(options, BLOCK_OPT_BACKING_FMT);
+cluster_size = qemu_opt_get_size(options, BLOCK_OPT_CLUSTER_SIZE, 0);
+table_size = qemu_opt_get_size(options, BLOCK_OPT_TABLE_SIZE, 0);
 
 if (!qed_is_cluster_size_valid(cluster_size)) {
 fprintf(stderr, "QED cluster size must be within range [%u, %u] and 
power of 2\n",
@@ -1593,36 +1580,40 @@ 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_options = {
+.name = "qed_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qed_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size (in bytes)"
+}, {
+.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_val = QEMU_OPT_VAL_SIZE(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_options   = &qed_create_options,
 
 .bdrv_probe   = bdrv_qed_probe,
 .bdrv_rebind  = bdrv_qed_rebind,
-- 
1.9.0




[Qemu-devel] [PATCH 07/26] cow: migrate cow driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
cow block driver.

Signed-off-by: Leandro Dorileo 
---
 block/cow.c | 44 ++--
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 30deb88..811f7f7 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -324,8 +324,7 @@ static void cow_close(BlockDriverState *bs)
 {
 }
 
-static int cow_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int cow_create(const char *filename, QemuOpts *options, Error **errp)
 {
 struct cow_header_v2 cow_header;
 struct stat st;
@@ -335,16 +334,13 @@ static int cow_create(const char *filename, 
QEMUOptionParameter *options,
 int ret;
 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(options, BLOCK_OPT_SIZE, 0);
+if (image_sectors) {
+image_sectors = image_sectors / 512;
 }
 
+image_filename = qemu_opt_get(options, BLOCK_OPT_BACKING_FILE);
+
 ret = bdrv_create_file(filename, options, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
@@ -393,18 +389,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"
+static QemuOptsList cow_create_options = {
+.name = "cow_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(cow_create_options.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"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_cow = {
@@ -421,7 +421,7 @@ static BlockDriver bdrv_cow = {
 .bdrv_write = cow_co_write,
 .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-.create_options = cow_create_options,
+.create_options = &cow_create_options,
 };
 
 static void bdrv_cow_init(void)
-- 
1.9.0




[Qemu-devel] [PATCH 08/26] gluster: migrate gluster driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
gluster block driver.

Signed-off-by: Leandro Dorileo 
---
 block/gluster.c | 68 +++--
 1 file changed, 37 insertions(+), 31 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index a44d612..e8d966e 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -470,14 +470,15 @@ 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)
+static int qemu_gluster_create(const char *filename, QemuOpts *options,
+   Error **errp)
 {
 struct glfs *glfs;
 struct glfs_fd *fd;
 int ret = 0;
 int prealloc = 0;
 int64_t total_size = 0;
+const char *prealloc_opt;
 GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
 glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,25 @@ 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;
-}
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+if (total_size) {
+total_size = total_size / BDRV_SECTOR_SIZE;
+}
+
+prealloc_opt = qemu_opt_get(options, BLOCK_OPT_PREALLOC);
+if (prealloc_opt) {
+if (!strcmp(prealloc_opt, "off")) {
+prealloc = 0;
+} else if (!strcmp(prealloc_opt, "full") &&
+   gluster_supports_zerofill()) {
+prealloc = 1;
+} else {
+error_setg(errp, "Invalid preallocation mode: '%s'"
+   " or GlusterFS doesn't support zerofill API",
+   prealloc_opt);
+ret = -EINVAL;
+goto out;
 }
-options++;
 }
 
 fd = glfs_creat(glfs, gconf->image,
@@ -688,18 +690,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)"
+static QemuOptsList qemu_gluster_create_options = {
+.name = "qemu_gluster_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_options.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = "Virtual disk size"
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = QEMU_OPT_STRING,
+.help = "Preallocation mode (allowed values: off, full)"
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_gluster = {
@@ -726,7 +732,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_options   = &qemu_gluster_create_options,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
-- 
1.9.0




[Qemu-devel] [PATCH 05/26] QemuOpt: add qemu_opt_print_help()

2014-03-20 Thread Leandro Dorileo
Analogous to print_option_help(QEMUOptionParameter *list) this function
displays the available key and help for each described QemuOptDesc in
QemuOptList.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  1 +
 util/qemu-option.c| 12 
 2 files changed, 13 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 3f4976d..62eacf3 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -177,6 +177,7 @@ void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, 
Error **errp);
 
 typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
 void qemu_opts_print(QemuOpts *opts);
+void qemu_opts_print_help(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 026d2ff..6fac370 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1022,6 +1022,18 @@ void qemu_opts_print(QemuOpts *opts)
 }
 }
 
+void qemu_opts_print_help(QemuOpts *opts)
+{
+QemuOptDesc *desc = opts->list->desc;
+
+printf("Supported options:\n");
+
+for (; desc && desc->name; desc++) {
+printf("%-16s %s\n", desc->name, desc->help ?
+   desc->help : "No description available");
+}
+}
+
 static int opts_do_parse(QemuOpts *opts, const char *params,
  const char *firstname, bool prepend)
 {
-- 
1.9.0




[Qemu-devel] [PATCH 25/26] QemuOpt: get rid of QEMUOptionParameter

2014-03-20 Thread Leandro Dorileo
Finally remove all the remaining QEMUOptionParameter bits.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  40 ---
 util/qemu-option.c| 296 --
 2 files changed, 336 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 62eacf3..4a7c148 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -31,24 +31,6 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-enum QEMUOptionParType {
-OPT_FLAG,
-OPT_NUMBER,
-OPT_SIZE,
-OPT_STRING,
-};
-
-typedef struct QEMUOptionParameter {
-const char *name;
-enum QEMUOptionParType type;
-union {
-uint64_t n;
-char* s;
-} value;
-const char *help;
-bool assigned;
-} QEMUOptionParameter;
-
 
 const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
 const char *get_opt_value(char *buf, int buf_size, const char *p);
@@ -57,33 +39,11 @@ int get_next_param_value(char *buf, int buf_size,
 int get_param_value(char *buf, int buf_size,
 const char *tag, const char *str);
 
-
-/*
- * The following functions take a parameter list as input. This is a pointer to
- * the first element of a QEMUOptionParameter array which is terminated by an
- * entry with entry->name == NULL.
- */
-
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name);
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value);
-int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
-uint64_t value);
-QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
-QEMUOptionParameter *list);
-QEMUOptionParameter *parse_option_parameters(const char *param,
-QEMUOptionParameter *list, QEMUOptionParameter *dest);
 void parse_option_size(const char *name, const char *value,
uint64_t *ret, Error **errp);
-void free_option_parameters(QEMUOptionParameter *list);
-void print_option_parameters(QEMUOptionParameter *list);
-void print_option_help(QEMUOptionParameter *list);
 bool has_help_option(const char *param);
 bool is_valid_option_list(const char *param);
 
-/* -- */
-
 typedef struct QemuOpt QemuOpt;
 typedef struct QemuOpts QemuOpts;
 typedef struct QemuOptsList QemuOptsList;
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 6fac370..e08ed74 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -137,22 +137,6 @@ int get_param_value(char *buf, int buf_size,
 return get_next_param_value(buf, buf_size, tag, &str);
 }
 
-/*
- * Searches an option list for an option with the given name
- */
-QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
-const char *name)
-{
-while (list && list->name) {
-if (!strcmp(list->name, name)) {
-return list;
-}
-list++;
-}
-
-return NULL;
-}
-
 static void parse_option_bool(const char *name, const char *value, bool *ret,
   Error **errp)
 {
@@ -226,244 +210,6 @@ void parse_option_size(const char *name, const char 
*value,
 }
 }
 
-/*
- * Sets the value of a parameter in a given option list. The parsing of the
- * value depends on the type of option:
- *
- * OPT_FLAG (uses value.n):
- *  If no value is given, the flag is set to 1.
- *  Otherwise the value must be "on" (set to 1) or "off" (set to 0)
- *
- * OPT_STRING (uses value.s):
- *  value is strdup()ed and assigned as option value
- *
- * OPT_SIZE (uses value.n):
- *  The value is converted to an integer. Suffixes for kilobytes etc. are
- *  allowed (powers of 1024).
- *
- * Returns 0 on succes, -1 in error cases
- */
-int set_option_parameter(QEMUOptionParameter *list, const char *name,
-const char *value)
-{
-bool flag;
-Error *local_err = NULL;
-
-// Find a matching parameter
-list = get_option_parameter(list, name);
-if (list == NULL) {
-fprintf(stderr, "Unknown option '%s'\n", name);
-return -1;
-}
-
-// Process parameter
-switch (list->type) {
-case OPT_FLAG:
-parse_option_bool(name, value, &flag, &local_err);
-if (!local_err) {
-list->value.n = flag;
-}
-break;
-
-case OPT_STRING:
-if (value != NULL) {
-list->value.s = g_strdup(value);
-} else {
-fprintf(stderr, "Option '%s' needs a parameter\n", name);
-return -1;
-}
-break;
-
-case OPT_SIZE:
-parse_option_size(name, value, &list->value.n, &local_err);
-break;
-
-default:
-fprintf(stderr, "Bug: Option '%s' has an unknown type\n", name);
-return -1;
-}
-
-if (local_err) {
-qerror_report_err(local_err);
-error_free(local_err);
-return -1;
-}
-
-list->assigned = true;
-
-return 0;
-}
-
-/*
- * 

[Qemu-devel] [PATCH 23/26] vpc: migrate vpc driver QemuOptionParameter usage

2014-03-20 Thread Leandro Dorileo
Do the directly migration from QemuOptionParameter to QemuOpts on
vpc block driver.

Signed-off-by: Leandro Dorileo 
---
 block/vpc.c | 54 +++---
 1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 82bf248..421b820 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -714,12 +714,11 @@ 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,
-  Error **errp)
+static int vpc_create(const char *filename, QemuOpts *options, 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,20 +728,17 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 int disk_type;
 int ret = -EIO;
 
-/* Read out options */
-total_size = get_option_parameter(options, BLOCK_OPT_SIZE)->value.n;
+total_size = qemu_opt_get_size(options, BLOCK_OPT_SIZE, 0);
+disk_type_param = qemu_opt_get(options, BLOCK_OPT_SUBFMT);
 
-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")) {
-disk_type = VHD_DYNAMIC;
-} else if (!strcmp(disk_type_param->value.s, "fixed")) {
-disk_type = VHD_FIXED;
-} else {
-return -EINVAL;
-}
-} else {
+if (!disk_type_param) {
 disk_type = VHD_DYNAMIC;
+} else if (!strcmp(disk_type_param, "dynamic")) {
+disk_type = VHD_DYNAMIC;
+} else if (!strcmp(disk_type_param, "fixed")) {
+disk_type = VHD_FIXED;
+} else {
+return -EINVAL;
 }
 
 /* Create the file */
@@ -842,20 +838,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 =
+static QemuOptsList vpc_create_options = {
+.name = "vpc_create_options",
+.head = QTAILQ_HEAD_INITIALIZER(vpc_create_options.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} "
+},
+{ NULL }
 },
-{ NULL }
 };
 
 static BlockDriver bdrv_vpc = {
@@ -873,7 +873,7 @@ static BlockDriver bdrv_vpc = {
 
 .bdrv_get_info  = vpc_get_info,
 
-.create_options = vpc_create_options,
+.create_options = &vpc_create_options,
 .bdrv_has_zero_init = vpc_has_zero_init,
 };
 
-- 
1.9.0




[Qemu-devel] [PATCH 03/26] QemuOpt: improve default value

2014-03-20 Thread Leandro Dorileo
Use a pointer to a structure holding the primitive types and avoid
parsing the default value representation.

Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h | 20 +++-
 util/qemu-config.c|  4 ++--
 util/qemu-option.c| 45 ++---
 3 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index c3b0a91..f0d4798 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -95,11 +95,29 @@ enum QemuOptType {
 QEMU_OPT_SIZE,/* size, accepts (K)ilo, (M)ega, (G)iga, (T)era 
postfix */
 };
 
+#define QEMU_OPT_VAL_STR(_val)  \
+&(QemuOptValue) {.s = _val} \
+
+#define QEMU_OPT_VAL_NUMBER(_val)   \
+&(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_SIZE(_val) \
+&(QemuOptValue) {.n = _val} \
+
+#define QEMU_OPT_VAL_BOOL(_val) \
+&(QemuOptValue) {.b = _val} \
+
+typedef struct QemuOptValue {
+bool b;
+uint64_t n;
+const char *s;
+} QemuOptValue;
+
 typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
-const char *def_value_str;
+QemuOptValue *def_val;
 } QemuOptDesc;
 
 struct QemuOptsList {
diff --git a/util/qemu-config.c b/util/qemu-config.c
index d608b2f..a40711b 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -68,9 +68,9 @@ 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) {
+if (desc[i].def_val) {
 info->has_q_default = true;
-info->q_default = g_strdup(desc[i].def_value_str);
+info->q_default = g_strdup(desc[i].def_val->s);
 }
 
 entry = g_malloc0(sizeof(*entry));
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 8c0756d..612a966 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -573,8 +573,8 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 
 if (!opt) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-return desc->def_value_str;
+if (desc && desc->def_val) {
+return desc->def_val->s;
 }
 }
 return opt ? opt->str : NULL;
@@ -598,11 +598,12 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_bool(name, desc->def_value_str, &defval, 
&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->b;
 }
 return defval;
 }
+
 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
@@ -613,9 +614,8 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_number(name, desc->def_value_str, &defval,
-&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->n;
 }
 return defval;
 }
@@ -629,8 +629,8 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
-if (desc && desc->def_value_str) {
-parse_option_size(name, desc->def_value_str, &defval, 
&error_abort);
+if (desc && desc->def_val) {
+return desc->def_val->n;
 }
 return defval;
 }
@@ -929,21 +929,28 @@ void qemu_opts_print(QemuOpts *opts)
 }
 return;
 }
+
 for (; desc && desc->name; desc++) {
-const char *value;
-QemuOpt *opt = qemu_opt_find(opts, desc->name);
+const char *str;
+uint64_t number;
+bool bol;
 
-value = opt ? opt->str : desc->def_value_str;
-if (!value) {
-continue;
-}
 if (desc->type == QEMU_OPT_STRING) {
-fprintf(stderr, "%s='%s' ", desc->name, value);
-} else {
-fprintf(stderr, "%s=%s ", desc->name, value);
+str = qemu_opt_get(opts, desc->name);
+if (str) {
+fprintf(stderr, "%s='%s' ", desc->name, str);
+}
+} else if (desc->type == QEMU_OPT_BOOL) {
+bol = qemu_opt_get_bool(opts, desc->name, false);
+fprintf(stderr, "%s=%s ", des

[Qemu-devel] [PATCH 04/26] QemuOpt: introduce qemu_opts_append()

2014-03-20 Thread Leandro Dorileo
From: Chunyan Liu 

The qemu_opts_append() function is intended to merge to different
QemuOptsList's. The resulting list must be freed by its user.

Signed-off-by: Chunyan Liu 
Signed-off-by: Leandro Dorileo 
---
 include/qemu/option.h |  1 +
 util/qemu-option.c| 69 +++
 2 files changed, 70 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index f0d4798..3f4976d 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -157,6 +157,7 @@ int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc 
func, void *opaque,
 QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
 QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
int fail_if_exists, Error **errp);
+QemuOptsList *qemu_opts_append(QemuOptsList *head, QemuOptsList *tail);
 void qemu_opts_reset(QemuOptsList *list);
 void qemu_opts_loc_restore(QemuOpts *opts);
 int qemu_opts_set(QemuOptsList *list, const char *id,
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 612a966..026d2ff 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -863,6 +863,75 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char 
*id,
 return opts;
 }
 
+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;
+}
+
+/**
+ * Merge two QEMUOptsList. First argument's QemuOptDesc members take precedence
+ * over second's.
+ *
+ * @note 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.
+ *
+ * The resulting QemuOptsList should be freed by this functions caller.
+ */
+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;
+}
+
 void qemu_opts_reset(QemuOptsList *list)
 {
 QemuOpts *opts, *next_opts;
-- 
1.9.0




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

2014-03-20 Thread Leandro Dorileo
From: 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| 84 +--
 2 files changed, 63 insertions(+), 24 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index 8c0ac34..c3b0a91 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -99,6 +99,7 @@ typedef struct QemuOptDesc {
 const char *name;
 enum QemuOptType type;
 const char *help;
+const char *def_value_str;
 } QemuOptDesc;
 
 struct QemuOptsList {
@@ -156,7 +157,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 9d898af..8c0756d 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,20 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/option_int.h"
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+const char *name)
+{
+int i;
+
+for (i = 0; desc[i].name != NULL; i++) {
+if (strcmp(desc[i].name, name) == 0) {
+return &desc[i];
+}
+}
+
+return NULL;
+}
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -556,6 +570,13 @@ 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);
+
+if (!opt) {
+const QemuOptDesc *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;
 }
 
@@ -575,8 +596,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_bool(name, desc->def_value_str, &defval, 
&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_BOOL);
 return opt->value.boolean;
 }
@@ -585,8 +611,14 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_number(name, desc->def_value_str, &defval,
+&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_NUMBER);
 return opt->value.uint;
 }
@@ -595,8 +627,13 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
 
-if (opt == NULL)
+if (opt == NULL) {
+const QemuOptDesc *desc = find_desc_by_name(opts->list->desc, name);
+if (desc && desc->def_value_str) {
+parse_option_size(name, desc->def_value_str, &defval, 
&error_abort);
+}
 return defval;
+}
 assert(opt->desc && opt->desc->type == QEMU_OPT_SIZE);
 return opt->value.uint;
 }
@@ -637,20 +674,6 @@ static bool opts_accepts_any(const QemuOpts *opts)
 return opts->list->desc[0].name == NULL;
 }
 
-static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
-const char *name)
-{
-int i;
-
-for (i = 0; desc[i].name != NULL; i++) {
-if (strcmp(desc[i].name, name) == 0) {
-return &desc[i];
-}
-}
-
-return NULL;
-}
-
 int qemu_opt_unset(QemuOpts *opts, const char *name)
 {
 QemuOpt *opt = qemu_opt_find(opts, name);
@@ -895,17 +918,32 @@ 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) {
+fprintf(stderr, "%s=\"%s\"

Re: [Qemu-devel] [PATCH v22 00/25] replace QEMUOptionParameter with QemuOpts

2014-03-20 Thread Leandro Dorileo
Hi Chunyan,

On Mon, Mar 10, 2014 at 03:31:36PM +0800, Chunyan Liu wrote:
> This patch series is to replace QEMUOptionParameter with QemuOpts, so that 
> only
> one Qemu Option structure is kept in QEMU code.
> 


Last night I took some time do take a deeper look at you series and the required
effort to do the QemuOptionParameter -> QemuOpts migration.

I think you've over complicated the things, I understand you tried to keep your
serie's bisectability (?), but the final result was something really hard to
review and to integrate as well. The overall approach wasn't even resolving the
bisectability problem since it breaks the tree until the last commit. Moreover,
in the path of getting things ready you created new problems and their 
respective
fixes, what we really don't need to.

In this regards you could have kept things as simple as possible and submitted
the patches in a "natural way", even if they were breaking the build between 
each
patch, you could get all the required maintainer's Reviewed-by + Tested-by +
Signed-off-by and so on for each individual patch and when it was time to
integrate get squashed the needed patches.

I mean, add N patches introducing new required QemuOpts API's, 1 patch migrating
the block upper layer (block.c, block.h, etc), one patch for each block driver
(i.e ssh.c, qcow.c, qcow2.c, etc), one patch for qemu-img.c and finally a last
patch removing the QEMUOptionParamer itself. When time comes to integrate your
series the patches changing the block layer + patches changing the block 
drivers +
patches changing qemu-img.c could be squashed adding all the collected 
Reviewed-by
to this single squashed patch.

As I said, last night I took a deeper look at the problem and, understood most
of changes weren't required to do the job. We don't need an adaptation layer 
between
QemuOptionParameter and QemuOpts, we don't need to add new opts accessors (like
those qemu_opt_*_del() functions), all we need is 1) that qemu_opts_append() 
function
so we can merge the protocol and drivers options in a single QemuOptList and
2) the default value support. All we need is already present in the QemuOpts 
APIs.

With that simpler approach in mind I ended up putting my hands in the source 
code
trying to see how feasible it is, and turns out I came up with a full solution. 
I'm
sending the job's resulting series to the mailing list so I can show you what
I mean and have some more room for discussion. It doesn't mean I want to overlap
you work, I just needed to have a little more input on that.

Regards

-- 
Leandro Dorileo



Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 23:33, Marcel Apfelbaum ha scritto:

I've seen something like that somewhere, but I didn't quite like it.
I was looking for something more elegant as I was *almost* sure
this kind of solution will not pass the reviews :)

But maybe I'll try this, let's see what happens,


If all you're looking for is bigendian (disabling iasl disassembly on 
bigendian makes sense), your patch v2 is fine.


Assembling ASL on bigendian is supported by at least Fedora and Debian 
(and hence Ubuntu).


Paolo



Re: [Qemu-devel] [RFC PATCH V3 3/5] qapi script: add event support

2014-03-20 Thread Eric Blake
On 03/18/2014 11:16 PM, Wenchao Xia wrote:
> qapi-event.py will parse the schema and generate qapi-event.c, then
> the API in qapi-event.c can be used to handle event in qemu code.
> All API have prefix "qapi_event".
> 
> The script mainly include two parts: generate API for each event

s/include/includes/

> define, generate an enum type for all defined events.
> 
> Since in some case the real emit behavior may change, for example,

s/case/cases/

> qemu-img would not send a event, a callback layer is used to
> control the behavior. As a result, the stubs at compile time
> can be saved, the binding of block layer code and monitor code
> will become looser.
> 
> Signed-off-by: Wenchao Xia 
> ---
>  Makefile   |9 +-
>  Makefile.objs  |2 +-
>  docs/qapi-code-gen.txt |   18 +++
>  scripts/qapi-event.py  |  373 
> 
>  4 files changed, 398 insertions(+), 4 deletions(-)
>  create mode 100644 scripts/qapi-event.py
> 
> +++ b/docs/qapi-code-gen.txt
> @@ -180,6 +180,24 @@ An example command is:
> 'data': { 'arg1': 'str', '*arg2': 'str' },
> 'returns': 'str' }
>  
> +=== Events ===
> +
> +Events are defined with key workd 'event'.  When 'data' is also specified,

s/workd/word/

> +additional info will be carried on.  Finally there will be C API generated
> +in qapi-event.h, and when called by QEMU code, message with timestamp will

s/message/a message/

> +be emit on the wire.  If timestamp is -1, it means failure in host time

s/emit/emitted/

> +retrieving.

s/in host time retrieving/to retrieve host time/

> +++ b/scripts/qapi-event.py
> @@ -0,0 +1,373 @@
> +#
> +# QAPI event generator
> +#
> +# Authors:
> +#  Wenchao Xia 
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2.
> +# See the COPYING file in the top-level directory.

Needs to use "Copyright".


> +
> +if params:
> +for argname, argentry, optional, structured in parse_args(params):
> +if structured:
> +sys.stderr.write("Nested structure define in event is not "
> + "supported now, event '%s', argname '%s'\n" 
> %
> + (event_name, argname))
> +sys.exit(1)
> +continue

Isn't this 'continue' dead code?

> +
> +# Following are the functions that generate an enum type for all defined
> +# events, similar with qapi-types.py. Here we already have enum name and

s/with/to/

> +# values which is generated before and recorded in event_enum_*. It also

s/is/were/

> +# walk around the issue that "import qapi-types" can't work.

s/walk around/works around/


> +
> +fdef.write(mcgen('''
> +/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
> +
> +/*
> + * schema-defined QAPI event functions
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.

Also needs "Copyright"

> +fdecl.write(mcgen('''
> +/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
> +
> +/*
> + * schema-defined QAPI event function

s/function/functions/

> + *
> + * Authors:
> + *  Wenchao Xia  
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.

Needs "Copyright"

-- 
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 for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Peter Maydell
On 20 March 2014 22:41, Marcel Apfelbaum  wrote:
> On Thu, 2014-03-20 at 22:17 +, Peter Maydell wrote:
>> echo "trivial iasl source" | iasl --compile-options | iasl
>> --disassemble-options | grep "error"
>>
>> Fill in the handwaving with actual syntax ;-)

> Problem with this solution is that if we start from the source,
> it will compile into a *wrong* AML (e.g header length will be BE and not LE),
> then the disassemble will *succeed* (!!!).
> However, the expected AML file will be in the right format and fail :(.

Well, grep for 'some integer that comes out wrong due
to the iasl bug', if it doesn't always result in an error
like the case you reported to the iasl mailing list.

You need to write this code at some point because we do
need to be able to configure-time detect whether we have
a working iasl or a broken one, once fixed ones get out
into the wild. It doesn't seem like it ought to be that hard
to just do it right to start with...

thanks
-- PMM



Re: [Qemu-devel] [RFC PATCH V3 2/5] qapi: add event helper functions

2014-03-20 Thread Eric Blake
On 03/18/2014 11:16 PM, Wenchao Xia wrote:
> This file hold some functions that do not need to be generated.

s/hold/holds/

> 
> Signed-off-by: Wenchao Xia 
> ---
>  include/qapi/qmp-event.h |   25 
>  qapi/Makefile.objs   |1 +
>  qapi/qmp-event.c |   71 
> ++
>  3 files changed, 97 insertions(+), 0 deletions(-)
>  create mode 100644 include/qapi/qmp-event.h
>  create mode 100644 qapi/qmp-event.c
> 
> diff --git a/include/qapi/qmp-event.h b/include/qapi/qmp-event.h
> new file mode 100644
> index 000..fdf1a7f
> --- /dev/null
> +++ b/include/qapi/qmp-event.h
> @@ -0,0 +1,25 @@
> +/*
> + * QMP Event related
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.

For the [L]GPL to work, someone must assert copyright.

> +++ b/qapi/qmp-event.c
> @@ -0,0 +1,71 @@
> +/*
> + * QMP Event related
> + *
> + * Authors:
> + *  Wenchao Xia   
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
> later.
> + * See the COPYING.LIB file in the top-level directory.

Again, missing an actual use of the word "Copyright".

> +
> +typedef struct QMPEventFunctions {
> +QMPEventFuncEmit emit;
> +} QMPEventFunctions;
> +
> +QMPEventFunctions qmp_event_functions;
> +
> +void qmp_event_set_func_emit(QMPEventFuncEmit emit)
> +{
> +qmp_event_functions.emit = emit;
> +}
> +
> +QMPEventFuncEmit qmp_event_get_func_emit(void)
> +{
> +return qmp_event_functions.emit;
> +}

Is this struct a bit overkill, or do you extend it to include other
fields later?


> +err = qemu_gettimeofday(&tv);
> +if (err < 0) {
> +/* Put -1 to indicate failure of getting host time */
> +tv.tv_sec = tv.tv_usec = -1;

Believe it or not, this is NOT portable.  Let's consider what happens
when tv_sec is int64_t and tv_usec is uint32_t.  Assignments happen
right to left, so tv_usec gets the unsigned value 0x, then since
all uint32_t values fit in int64_t, integer promotion says that the
value is 0-extended (not sign-extended), and tv_sec is NOT assigned -1.
 Solution: break this into two separate statements:

tv.tv_sec = -1;
tv.tv_usec = -1;

> +}
> +
> +obj = qobject_from_jsonf("{ 'seconds': %" PRId64 ", "
> +"'microseconds': %" PRId64 " }",
> +(int64_t) tv.tv_sec, (int64_t) tv.tv_usec);

Indentation is odd, but that's cosmetic.

-- 
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 for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Laszlo Ersek
On 03/20/14 23:33, Marcel Apfelbaum wrote:
> On Thu, 2014-03-20 at 23:26 +0100, Laszlo Ersek wrote:
>> On 03/20/14 23:06, Marcel Apfelbaum wrote:
>>> On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
 Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
> +# All known versions of iasl on BE machines are broken.
> +# TODO: add detection code once a non-broken version makes an appearance.
> +if ($iasl -h > /dev/null 2>&1) &&
> +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then

 lscpu is not portable.
>>> I am open to suggestions...
>>> I'll try to come up with something else.
>>
>> The printf and od utilities are portable. You can use printf to print a
>> character string, and use od to group that character string into
>> multibyte integers in the native byte order.
>>
>> Example:
>>
>>   X=$(printf '\336\255\276\357' | od -A n -t x4)
> Hi Laszlo,
> Thanks for the help!
> 
> I've seen something like that somewhere, but I didn't quite like it.
> I was looking for something more elegant as I was *almost* sure
> this kind of solution will not pass the reviews :)
> 
> But maybe I'll try this, let's see what happens,

For ultimate pedantry, don't depend on the number and kind of blanks on
the left hand side of the output. If you set LC_ALL to POSIX, then only
 and  count as blank; but even that way you should be
prepared to see any number of them on the LHS. Probably just use grep:

if printf '\336\255\276\357' | od -A n -t x4 | grep -q deadbeef; then
  printf 'big endian\n' >&2
fi

Laszlo




Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
On Thu, 2014-03-20 at 22:17 +, Peter Maydell wrote:
> On 20 March 2014 22:06, Marcel Apfelbaum  wrote:
> > On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
> >> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
> >> > +# All known versions of iasl on BE machines are broken.
> >> > +# TODO: add detection code once a non-broken version makes an 
> >> > appearance.
> >> > +if ($iasl -h > /dev/null 2>&1) &&
> >> > +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
> >>
> >> lscpu is not portable.
> > I am open to suggestions...
> 
> echo "trivial iasl source" | iasl --compile-options | iasl
> --disassemble-options | grep "error"
> 
> Fill in the handwaving with actual syntax ;-)
Thanks Peter!

Problem with this solution is that if we start from the source,
it will compile into a *wrong* AML (e.g header length will be BE and not LE),
then the disassemble will *succeed* (!!!).
However, the expected AML file will be in the right format and fail :(.

I can use one of the expected AML files, but it would not be elegant
to use a test file in the configuration script.
What about Laszlo's idea? Would something like:
X=$(printf '\336\255\276\357' | od -A n -t x4) be acceptable ?

Thanks,
Marcel

> 
> thanks
> -- PMM






Re: [Qemu-devel] [PATCH v4 01/10] hw/mips/cputimer: Don't start periodic timer in KVM mode

2014-03-20 Thread Paolo Bonzini
Il 20/03/2014 10:57, James Hogan ha scritto:
> On 19/03/14 16:29, Paolo Bonzini wrote:
>> Il 14/03/2014 13:47, James Hogan ha scritto:
>>> From: Sanjay Lal 
>>>
>>> Compare/Count timer interrupts are handled in-kernel for KVM, so don't
>>> bother starting it in QEMU.
>>>
>>> Signed-off-by: Sanjay Lal 
>>> Signed-off-by: James Hogan 
>>> Reviewed-by: Aurelien Jarno 
>>> ---
>>> Changes in v2:
>>>  - Expand commit message
>>>  - Rebase on v1.7.0
>>>  - Wrap comment
>>> ---
>>>  hw/mips/cputimer.c | 13 ++---
>>>  1 file changed, 10 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/mips/cputimer.c b/hw/mips/cputimer.c
>>> index c8b4b00..52570fd 100644
>>> --- a/hw/mips/cputimer.c
>>> +++ b/hw/mips/cputimer.c
>>> @@ -23,6 +23,7 @@
>>>  #include "hw/hw.h"
>>>  #include "hw/mips/cpudevs.h"
>>>  #include "qemu/timer.h"
>>> +#include "sysemu/kvm.h"
>>>
>>>  #define TIMER_FREQ100 * 1000 * 1000
>>>
>>> @@ -141,7 +142,13 @@ static void mips_timer_cb (void *opaque)
>>>
>>>  void cpu_mips_clock_init (CPUMIPSState *env)
>>>  {
>>> -env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &mips_timer_cb, env);
>>> -env->CP0_Compare = 0;
>>> -cpu_mips_store_count(env, 1);
>>> +/*
>>> + * If we're in KVM mode, don't start the periodic timer, that is
>>> handled in
>>> + * kernel.
>>> + */
>>> +if (!kvm_enabled()) {
>>> +env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &mips_timer_cb,
>>> env);
>>> +env->CP0_Compare = 0;
>>> +cpu_mips_store_count(env, 1);
>>> +}
>>>  }
>>>
>>
>> I hate to make you do unrelated changes, but... initializing CP0_Compare
>> is unnecessary, it should already be 0;
> 
> You mean because of the memset in object_initialize_with_type, when
> object_new is called? Although that wouldn't handle reset, although
> technically the reset state of Compare is undefined.

No, see mips_cpu_reset:

static void mips_cpu_reset(CPUState *s)
{
MIPSCPU *cpu = MIPS_CPU(s);
MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cpu);
CPUMIPSState *env = &cpu->env;

mcc->parent_reset(s);

memset(env, 0, offsetof(CPUMIPSState, mvp));
tlb_flush(s, 1);

cpu_state_reset(env);
}

Fields before mvp are reset to zero (including CP0_Compare and CP0_Count).

> Am I right that the correct way to prevent clock drift is for
> kvm_arch_put_registers to only set the Count register if level !=
> KVM_PUT_RUNTIME_STATE?

Yes, that makes sense.  Or, better, do not provide a set_onereg 
interface for CP0_Count.  Instead, in the kernel you can base the CPU 
timer on the value of CLOCK_MONOTONIC, like this:

+static inline u64 get_monotonic_ns(void)
+{
+   struct timespec ts;
+
+   ktime_get_ts(&ts);
+   return timespec_to_ns(&ts);
+}
+

Then you provide three set_onereg interfaces.  One is normal cp0_count, 
but it is only used if the timer is not running (according to 
cp0_cause).  The second is the rate at which the timer counts 
(cp0_count_hz).  The third is used when the timer is running, and
it is:

cp0_count_bias
   = cp0_count * 10^9 / cp0_count_hz - get_monotonic_ns()

So when the timer is running cp0_count is computed as follows:

cp0_count =
  = (get_monotonic_ns() + cp0_count_bias) * cp0_count_hz / 10^9

QEMU can then set:

  cp0_count = cpu_mips_get_count(env)
  cp0_count_bias =
 cpu_mips_get_count(env) * 10^9 / cp0_count_hz - qemu_get_clock_ns(rt_clock)

Note that QEMU's qemu_get_clock_ns(rt_clock) == kernel's get_monotonic_ns().

So when the guest reads cp0_count (and the timer was running at the time
kvm_arch_put_registers was set), the kernel will return:

cp0_count =
 = (get_monotonic_ns() + cp0_count_bias) * cp0_count_hz / 10^9
 = env->cp0_count
   + (get_monotonic_ns() - qemu_get_clock_ns(rt_clock)
 + qemu_get_clock_ns(vm_clock)) * cp0_count_hz 
/ 10^9
 = env->cp0_count + qemu_get_clock_ns(vm_clock) * cp0_count_hz / 10^9
 = cpu_mips_get_count(env)

Paolo



Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
> > +# All known versions of iasl on BE machines are broken.
> > +# TODO: add detection code once a non-broken version makes an appearance.
> > +if ($iasl -h > /dev/null 2>&1) &&
> > +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
> 
> lscpu is not portable.
I am open to suggestions...
I'll try to come up with something else.

Thanks,
Marcel
> 
> Paolo






Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
On Thu, 2014-03-20 at 23:26 +0100, Laszlo Ersek wrote:
> On 03/20/14 23:06, Marcel Apfelbaum wrote:
> > On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
> >> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
> >>> +# All known versions of iasl on BE machines are broken.
> >>> +# TODO: add detection code once a non-broken version makes an appearance.
> >>> +if ($iasl -h > /dev/null 2>&1) &&
> >>> +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
> >>
> >> lscpu is not portable.
> > I am open to suggestions...
> > I'll try to come up with something else.
> 
> The printf and od utilities are portable. You can use printf to print a
> character string, and use od to group that character string into
> multibyte integers in the native byte order.
> 
> Example:
> 
>   X=$(printf '\336\255\276\357' | od -A n -t x4)
Hi Laszlo,
Thanks for the help!

I've seen something like that somewhere, but I didn't quite like it.
I was looking for something more elegant as I was *almost* sure
this kind of solution will not pass the reviews :)

But maybe I'll try this, let's see what happens,
Thanks!
Marcel

> 
> This sets X to " efbeadde" on little endian, and " deadbeef" on big endian.
> 
> Laszlo






Re: [Qemu-devel] [RFC PATCH V2 3/5] qapi script: add event support by qapi-event.py

2014-03-20 Thread Eric Blake
On 03/18/2014 08:38 PM, Wenchao Xia wrote:
> 于 2014/3/7 2:49, Eric Blake 写道:
>> On 01/02/2014 04:10 PM, Wenchao Xia wrote:
>>> qapi-event.py will parse the schema and generate qapi-event.c, then
>>> the API in qapi-event.c can be used to handle event in qemu code.
>>> All API have prefix "qapi_event", all types have prefix "QAPIEvent".
>>> Examples can be found in following patches.
>>>

>>> +for o, a in opts:
>>> +if o in ("-p", "--prefix"):
>>> +prefix = a
>>> +elif o in ("-o", "--output-dir"):
>>> +output_dir = a + "/"
>>> +elif o in ("-c", "--source"):
>>> +do_c = True
>>> +elif o in ("-h", "--header"):
>>> +do_h = True
>>> +elif o in ("-b", "--builtins"):
>>> +do_builtins = True
>> You may need to rebase this on top of other patches that refactor the
>> qapi generators to track the input file, for improved error messages.
>   It seems qapi-visit.py and qapi-types.py remains the same as above in
> upstream, which kind of change are your referring to?

Lluís' patch to use an explicit input file via a new -i option:
https://lists.gnu.org/archive/html/qemu-devel/2014-02/msg05220.html

-- 
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 for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Laszlo Ersek
On 03/20/14 23:06, Marcel Apfelbaum wrote:
> On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
>> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
>>> +# All known versions of iasl on BE machines are broken.
>>> +# TODO: add detection code once a non-broken version makes an appearance.
>>> +if ($iasl -h > /dev/null 2>&1) &&
>>> +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
>>
>> lscpu is not portable.
> I am open to suggestions...
> I'll try to come up with something else.

The printf and od utilities are portable. You can use printf to print a
character string, and use od to group that character string into
multibyte integers in the native byte order.

Example:

  X=$(printf '\336\255\276\357' | od -A n -t x4)

This sets X to " efbeadde" on little endian, and " deadbeef" on big endian.

Laszlo



[Qemu-devel] [PATCH v4 3/7] allwinner-a10-pit: avoid generation of spurious interrupts

2014-03-20 Thread Beniamino Galvani
The model was generating interrupts for all enabled timers after the
expiration of one of them. Avoid this by passing explicitly the timer
index to the callback function.

Signed-off-by: Beniamino Galvani 
Reviewed-by: Li Guang 
Reviewed-by: Peter Crosthwaite 
---
 hw/timer/allwinner-a10-pit.c |   25 ++---
 include/hw/timer/allwinner-a10-pit.h |8 
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
index b27fce8..696b7d9 100644
--- a/hw/timer/allwinner-a10-pit.c
+++ b/hw/timer/allwinner-a10-pit.c
@@ -193,18 +193,17 @@ static void a10_pit_reset(DeviceState *dev)
 
 static void a10_pit_timer_cb(void *opaque)
 {
-AwA10PITState *s = AW_A10_PIT(opaque);
-uint8_t i;
+AwA10TimerContext *tc = opaque;
+AwA10PITState *s = tc->container;
+uint8_t i = tc->index;
 
-for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
-if (s->control[i] & AW_A10_PIT_TIMER_EN) {
-s->irq_status |= 1 << i;
-if (s->control[i] & AW_A10_PIT_TIMER_MODE) {
-ptimer_stop(s->timer[i]);
-s->control[i] &= ~AW_A10_PIT_TIMER_EN;
-}
-qemu_irq_pulse(s->irq[i]);
+if (s->control[i] & AW_A10_PIT_TIMER_EN) {
+s->irq_status |= 1 << i;
+if (s->control[i] & AW_A10_PIT_TIMER_MODE) {
+ptimer_stop(s->timer[i]);
+s->control[i] &= ~AW_A10_PIT_TIMER_EN;
 }
+qemu_irq_pulse(s->irq[i]);
 }
 }
 
@@ -223,7 +222,11 @@ static void a10_pit_init(Object *obj)
 sysbus_init_mmio(sbd, &s->iomem);
 
 for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
-bh[i] = qemu_bh_new(a10_pit_timer_cb, s);
+AwA10TimerContext *tc = &s->timer_context[i];
+
+tc->container = s;
+tc->index = i;
+bh[i] = qemu_bh_new(a10_pit_timer_cb, tc);
 s->timer[i] = ptimer_init(bh[i]);
 ptimer_set_freq(s->timer[i], 24);
 }
diff --git a/include/hw/timer/allwinner-a10-pit.h 
b/include/hw/timer/allwinner-a10-pit.h
index 15efab8..a48d3c7 100644
--- a/include/hw/timer/allwinner-a10-pit.h
+++ b/include/hw/timer/allwinner-a10-pit.h
@@ -35,12 +35,20 @@
 
 #define AW_A10_PIT_DEFAULT_CLOCK   0x4
 
+typedef struct AwA10PITState AwA10PITState;
+
+typedef struct AwA10TimerContext {
+AwA10PITState *container;
+int index;
+} AwA10TimerContext;
+
 typedef struct AwA10PITState {
 /*< private >*/
 SysBusDevice parent_obj;
 /*< public >*/
 qemu_irq irq[AW_A10_PIT_TIMER_NR];
 ptimer_state * timer[AW_A10_PIT_TIMER_NR];
+AwA10TimerContext timer_context[AW_A10_PIT_TIMER_NR];
 MemoryRegion iomem;
 
 uint32_t irq_enable;
-- 
1.7.10.4




[Qemu-devel] [PATCH v4 5/7] allwinner-a10-pit: implement prescaler and source selection

2014-03-20 Thread Beniamino Galvani
This implements the prescaler and source fields of the timer control
register. The source for each timer can be selected among 4 clock
inputs whose frequencies are set through model properties.

Signed-off-by: Beniamino Galvani 
---
 hw/arm/cubieboard.c  |   13 ++
 hw/timer/allwinner-a10-pit.c |   43 +-
 include/hw/timer/allwinner-a10-pit.h |4 
 3 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
index d95a7f3..9d158c7 100644
--- a/hw/arm/cubieboard.c
+++ b/hw/arm/cubieboard.c
@@ -43,6 +43,19 @@ static void cubieboard_init(QEMUMachineInitArgs *args)
 exit(1);
 }
 
+object_property_set_int(OBJECT(&s->a10->timer), 32768, "clk0-freq", &err);
+if (err != NULL) {
+error_report("Couldn't set clk0 frequency: %s", error_get_pretty(err));
+exit(1);
+}
+
+object_property_set_int(OBJECT(&s->a10->timer), 2400, "clk1-freq",
+&err);
+if (err != NULL) {
+error_report("Couldn't set clk1 frequency: %s", error_get_pretty(err));
+exit(1);
+}
+
 object_property_set_bool(OBJECT(s->a10), true, "realized", &err);
 if (err != NULL) {
 error_report("Couldn't realize Allwinner A10: %s",
diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
index 5aa78a9..5c1ffba 100644
--- a/hw/timer/allwinner-a10-pit.c
+++ b/hw/timer/allwinner-a10-pit.c
@@ -74,6 +74,37 @@ static uint64_t a10_pit_read(void *opaque, hwaddr offset, 
unsigned size)
 return 0;
 }
 
+static void a10_pit_set_freq(AwA10PITState *s, int index)
+{
+uint32_t prescaler, source;
+uint32_t source_freq;
+
+prescaler = 1 << extract32(s->control[index], 4, 3);
+source = extract32(s->control[index], 2, 2);
+
+switch (source) {
+case 0:
+source_freq = s->clk0_freq;
+break;
+case 1:
+source_freq = s->clk1_freq;
+break;
+case 2:
+source_freq = s->clk2_freq;
+break;
+case 3:
+source_freq = s->clk3_freq;
+break;
+}
+
+if (source_freq) {
+ptimer_set_freq(s->timer[index], source_freq / prescaler);
+} else {
+qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid clock source %u\n",
+  __func__, source);
+}
+}
+
 static void a10_pit_write(void *opaque, hwaddr offset, uint64_t value,
 unsigned size)
 {
@@ -96,6 +127,7 @@ static void a10_pit_write(void *opaque, hwaddr offset, 
uint64_t value,
 switch (offset & 0x0f) {
 case AW_A10_PIT_TIMER_CONTROL:
 s->control[index] = value;
+a10_pit_set_freq(s, index);
 if (s->control[index] & AW_A10_PIT_TIMER_RELOAD) {
 ptimer_set_count(s->timer[index], s->interval[index]);
 }
@@ -161,6 +193,14 @@ static const MemoryRegionOps a10_pit_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static Property a10_pit_properties[] = {
+DEFINE_PROP_UINT32("clk0-freq", AwA10PITState, clk0_freq, 0),
+DEFINE_PROP_UINT32("clk1-freq", AwA10PITState, clk1_freq, 0),
+DEFINE_PROP_UINT32("clk2-freq", AwA10PITState, clk2_freq, 0),
+DEFINE_PROP_UINT32("clk3-freq", AwA10PITState, clk3_freq, 0),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static const VMStateDescription vmstate_a10_pit = {
 .name = "a10.pit",
 .version_id = 1,
@@ -196,6 +236,7 @@ static void a10_pit_reset(DeviceState *dev)
 s->interval[i] = 0;
 s->count[i] = 0;
 ptimer_stop(s->timer[i]);
+a10_pit_set_freq(s, i);
 }
 s->watch_dog_mode = 0;
 s->watch_dog_control = 0;
@@ -241,7 +282,6 @@ static void a10_pit_init(Object *obj)
 tc->index = i;
 bh[i] = qemu_bh_new(a10_pit_timer_cb, tc);
 s->timer[i] = ptimer_init(bh[i]);
-ptimer_set_freq(s->timer[i], 24);
 }
 }
 
@@ -250,6 +290,7 @@ static void a10_pit_class_init(ObjectClass *klass, void 
*data)
 DeviceClass *dc = DEVICE_CLASS(klass);
 
 dc->reset = a10_pit_reset;
+dc->props = a10_pit_properties;
 dc->desc = "allwinner a10 timer";
 dc->vmsd = &vmstate_a10_pit;
 }
diff --git a/include/hw/timer/allwinner-a10-pit.h 
b/include/hw/timer/allwinner-a10-pit.h
index a48d3c7..5388b2b 100644
--- a/include/hw/timer/allwinner-a10-pit.h
+++ b/include/hw/timer/allwinner-a10-pit.h
@@ -50,6 +50,10 @@ typedef struct AwA10PITState {
 ptimer_state * timer[AW_A10_PIT_TIMER_NR];
 AwA10TimerContext timer_context[AW_A10_PIT_TIMER_NR];
 MemoryRegion iomem;
+uint32_t clk0_freq;
+uint32_t clk1_freq;
+uint32_t clk2_freq;
+uint32_t clk3_freq;
 
 uint32_t irq_enable;
 uint32_t irq_status;
-- 
1.7.10.4




[Qemu-devel] [PATCH v4 0/7] Allwinner A10 fixes

2014-03-20 Thread Beniamino Galvani
This series introduces some fixes and missing features found while
trying to run mainline Linux kernel on emulated Allwinner A10.

The changes concern interrupt handling, timer and ethernet MAC.

With these applied I'm able to boot Linux 3.14-rc2 using a NFS root:

https://gist.github.com/anonymous/3e09495652009c6b9da4

Changelog:
v4: Address comments from Peter Crosthwaite:
* force argument of qemu_set_irq to 0/1
* update irq status in pit reset handler
* add properties for setting input frequencies of pit
* set pit input frequencies in cubieboard init function

v3: Address comments from Peter Crosthwaite:
* make pending register read-only (patch 2)
* inline timer context structure into timer state (patch 3)
* cleanup timer frequency initialization (patch 5)

v2: Address comments from Li Guang:
* make pic vector register read-only
* allow writing to pic pending register

Beniamino Galvani (7):
  allwinner-a10-pic: set vector address when an interrupt is pending
  allwinner-a10-pic: fix behaviour of pending register
  allwinner-a10-pit: avoid generation of spurious interrupts
  allwinner-a10-pit: use level triggered interrupts
  allwinner-a10-pit: implement prescaler and source selection
  allwinner-emac: set autonegotiation complete bit on link up
  allwinner-emac: update irq status after writes to interrupt registers

 hw/arm/cubieboard.c  |   13 ++
 hw/intc/allwinner-a10-pic.c  |   22 ++---
 hw/net/allwinner_emac.c  |6 ++-
 hw/timer/allwinner-a10-pit.c |   81 +-
 include/hw/net/allwinner_emac.h  |1 +
 include/hw/timer/allwinner-a10-pit.h |   12 +
 6 files changed, 116 insertions(+), 19 deletions(-)

-- 
1.7.10.4




[Qemu-devel] [PATCH v4 1/7] allwinner-a10-pic: set vector address when an interrupt is pending

2014-03-20 Thread Beniamino Galvani
This patch implements proper updating of the vector register which
should hold, according to the A10 user manual, the vector address for
the interrupt currently active on the CPU IRQ input.

Interrupt priority is not implemented at the moment and thus the first
pending interrupt is returned.

Signed-off-by: Beniamino Galvani 
Reviewed-by: Peter Crosthwaite 
Reviewed-by: Li Guang 
---
 hw/intc/allwinner-a10-pic.c |   14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/intc/allwinner-a10-pic.c b/hw/intc/allwinner-a10-pic.c
index 407d563..00f3c11 100644
--- a/hw/intc/allwinner-a10-pic.c
+++ b/hw/intc/allwinner-a10-pic.c
@@ -23,11 +23,20 @@
 static void aw_a10_pic_update(AwA10PICState *s)
 {
 uint8_t i;
-int irq = 0, fiq = 0;
+int irq = 0, fiq = 0, pending;
+
+s->vector = 0;
 
 for (i = 0; i < AW_A10_PIC_REG_NUM; i++) {
 irq |= s->irq_pending[i] & ~s->mask[i];
 fiq |= s->select[i] & s->irq_pending[i] & ~s->mask[i];
+
+if (!s->vector) {
+pending = ffs(s->irq_pending[i] & ~s->mask[i]);
+if (pending) {
+s->vector = (i * 32 + pending - 1) * 4;
+}
+}
 }
 
 qemu_set_irq(s->parent_irq, !!irq);
@@ -84,9 +93,6 @@ static void aw_a10_pic_write(void *opaque, hwaddr offset, 
uint64_t value,
 uint8_t index = (offset & 0xc) / 4;
 
 switch (offset) {
-case AW_A10_PIC_VECTOR:
-s->vector = value & ~0x3;
-break;
 case AW_A10_PIC_BASE_ADDR:
 s->base_addr = value & ~0x3;
 case AW_A10_PIC_PROTECT:
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Peter Maydell
On 20 March 2014 22:06, Marcel Apfelbaum  wrote:
> On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
>> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
>> > +# All known versions of iasl on BE machines are broken.
>> > +# TODO: add detection code once a non-broken version makes an appearance.
>> > +if ($iasl -h > /dev/null 2>&1) &&
>> > +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
>>
>> lscpu is not portable.
> I am open to suggestions...

echo "trivial iasl source" | iasl --compile-options | iasl
--disassemble-options | grep "error"

Fill in the handwaving with actual syntax ;-)

thanks
-- PMM



Re: [Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Laszlo Ersek
On 03/20/14 22:18, Christian Borntraeger wrote:
> On 20/03/14 21:56, Laszlo Ersek wrote:
>> On 03/20/14 21:38, Christian Borntraeger wrote:
>>> Qiao Nuohan,
>>>
>>> is there a reason why you did not implemented the HMP part for that format
>>> of kdump compressed format? After all this is a patch mostly for developers,
>>> so a HMP interface might come handy. Do you already have some patch in 
>>> preparation or know somebody doing it?
>>
>> http://thread.gmane.org/gmane.comp.emulators.qemu/249283/focus=250059
>>
>> Laszlo
>>
> So in essence: Due to the limitations of the command line parser we cannot
> add the format to the hmp command line.
> So something like adding
> 
> dump_guest_memory_set_format 
> 
> would be the only possible solution with the hmp code as is. Correct?

Yes, one possibility would be to make the dump command stateful (=
compression format), and to add a new command setting/getting that state.

Another option would be to leave the current command intact, and add an
independent command that wouldn't take "begin", "end", nor "paging", but
would take compression format.

> (If adding such a command is nice or not is another question)

Yep.

Thanks
Laszlo




Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
On Thu, 2014-03-20 at 22:57 +0100, Paolo Bonzini wrote:
> Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:
> > +# All known versions of iasl on BE machines are broken.
> > +# TODO: add detection code once a non-broken version makes an appearance.
> > +if ($iasl -h > /dev/null 2>&1) &&
> > +   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
> 
> lscpu is not portable.
I am open to suggestions...
I'll try to come up with something else.

Thanks,
Marcel

> 
> Paolo






[Qemu-devel] [PATCH v4 2/7] allwinner-a10-pic: fix behaviour of pending register

2014-03-20 Thread Beniamino Galvani
The pending register is read-only and the value returned upon a read
reflects the state of irq input pins (interrupts are level triggered).
This patch implements such behaviour.

Signed-off-by: Beniamino Galvani 
Reviewed-by: Li Guang 
Reviewed-by: Peter Crosthwaite 
---
 hw/intc/allwinner-a10-pic.c |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/intc/allwinner-a10-pic.c b/hw/intc/allwinner-a10-pic.c
index 00f3c11..0924d98 100644
--- a/hw/intc/allwinner-a10-pic.c
+++ b/hw/intc/allwinner-a10-pic.c
@@ -49,6 +49,8 @@ static void aw_a10_pic_set_irq(void *opaque, int irq, int 
level)
 
 if (level) {
 set_bit(irq % 32, (void *)&s->irq_pending[irq / 32]);
+} else {
+clear_bit(irq % 32, (void *)&s->irq_pending[irq / 32]);
 }
 aw_a10_pic_update(s);
 }
@@ -102,7 +104,11 @@ static void aw_a10_pic_write(void *opaque, hwaddr offset, 
uint64_t value,
 s->nmi = value;
 break;
 case AW_A10_PIC_IRQ_PENDING ... AW_A10_PIC_IRQ_PENDING + 8:
-s->irq_pending[index] &= ~value;
+/*
+ * The register is read-only; nevertheless, Linux (including
+ * the version originally shipped by Allwinner) pretends to
+ * write to the register. Just ignore it.
+ */
 break;
 case AW_A10_PIC_FIQ_PENDING ... AW_A10_PIC_FIQ_PENDING + 8:
 s->fiq_pending[index] &= ~value;
-- 
1.7.10.4




[Qemu-devel] [PATCH] target-i386: Remove unused data from local array

2014-03-20 Thread Stefan Weil
Signed-off-by: Stefan Weil 
---

This patch is based on a previous patch for the same file,
see http://patchwork.ozlabs.org/patch/330708/.

Regards
Stefan W.

 target-i386/kvm.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 4389959..d17eea3 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -130,14 +130,13 @@ static const struct kvm_para_features {
 { KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
 { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
 { KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF },
-{ -1, -1 }
 };
 
 static int get_para_features(KVMState *s)
 {
 int i, features = 0;
 
-for (i = 0; i < ARRAY_SIZE(para_features) - 1; i++) {
+for (i = 0; i < ARRAY_SIZE(para_features); i++) {
 if (kvm_check_extension(s, para_features[i].cap)) {
 features |= (1 << para_features[i].feature);
 }
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 22:14, Marcel Apfelbaum ha scritto:

+# All known versions of iasl on BE machines are broken.
+# TODO: add detection code once a non-broken version makes an appearance.
+if ($iasl -h > /dev/null 2>&1) &&
+   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then


lscpu is not portable.

Paolo



[Qemu-devel] [PATCH v4 6/7] allwinner-emac: set autonegotiation complete bit on link up

2014-03-20 Thread Beniamino Galvani
Signed-off-by: Beniamino Galvani 
Reviewed-by: Peter Crosthwaite 
---
 hw/net/allwinner_emac.c |4 ++--
 include/hw/net/allwinner_emac.h |1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c
index 469f2f0..91931ac 100644
--- a/hw/net/allwinner_emac.c
+++ b/hw/net/allwinner_emac.c
@@ -27,11 +27,11 @@ static uint8_t padding[60];
 static void mii_set_link(RTL8201CPState *mii, bool link_ok)
 {
 if (link_ok) {
-mii->bmsr |= MII_BMSR_LINK_ST;
+mii->bmsr |= MII_BMSR_LINK_ST | MII_BMSR_AN_COMP;
 mii->anlpar |= MII_ANAR_TXFD | MII_ANAR_10FD | MII_ANAR_10 |
MII_ANAR_CSMACD;
 } else {
-mii->bmsr &= ~MII_BMSR_LINK_ST;
+mii->bmsr &= ~(MII_BMSR_LINK_ST | MII_BMSR_AN_COMP);
 mii->anlpar = MII_ANAR_TX;
 }
 }
diff --git a/include/hw/net/allwinner_emac.h b/include/hw/net/allwinner_emac.h
index a5e944a..5ae7717 100644
--- a/include/hw/net/allwinner_emac.h
+++ b/include/hw/net/allwinner_emac.h
@@ -144,6 +144,7 @@
 #define MII_BMSR_10T_FD (1 << 12)
 #define MII_BMSR_10T_HD (1 << 11)
 #define MII_BMSR_MFPS   (1 << 6)
+#define MII_BMSR_AN_COMP(1 << 5)
 #define MII_BMSR_AUTONEG(1 << 3)
 #define MII_BMSR_LINK_ST(1 << 2)
 
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH for-2.0 V2] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 21:16, Michael S. Tsirkin ha scritto:

Seems too aggressive: can't we detect the broken iasl?
E.g. won't it fail to disassemble expected AML files?


Yes.


Also, won't this broken iasl generate corrupt AML
on output? If yes we should detect this at configure
time instead?


No, the output is fine.  There are patches from Debian (that I updated 
and applied to Fedora last year) that take care of fixing endianness on 
output, but no such patches for the disassembly.


On one hand, I'm fine with not running IASL at all on big-endian 
machines.  On the other hand, it will certainly cause the patches to bitrot.


Paolo



[Qemu-devel] [PATCH v4 7/7] allwinner-emac: update irq status after writes to interrupt registers

2014-03-20 Thread Beniamino Galvani
The irq line status must be updated after writes to the INT_CTL and
INT_STA registers.

Signed-off-by: Beniamino Galvani 
Reviewed-by: Peter Crosthwaite 
---
 hw/net/allwinner_emac.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/net/allwinner_emac.c b/hw/net/allwinner_emac.c
index 91931ac..d780ba0 100644
--- a/hw/net/allwinner_emac.c
+++ b/hw/net/allwinner_emac.c
@@ -391,9 +391,11 @@ static void aw_emac_write(void *opaque, hwaddr offset, 
uint64_t value,
 break;
 case EMAC_INT_CTL_REG:
 s->int_ctl = value;
+aw_emac_update_irq(s);
 break;
 case EMAC_INT_STA_REG:
 s->int_sta &= ~value;
+aw_emac_update_irq(s);
 break;
 case EMAC_MAC_MADR_REG:
 s->phy_target = value;
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH] target-i386: Remove unused data from local array

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 22:30, Stefan Weil ha scritto:

Signed-off-by: Stefan Weil 
---

This patch is based on a previous patch for the same file,
see http://patchwork.ozlabs.org/patch/330708/.

Regards
Stefan W.

 target-i386/kvm.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 4389959..d17eea3 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -130,14 +130,13 @@ static const struct kvm_para_features {
 { KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
 { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
 { KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF },
-{ -1, -1 }
 };

 static int get_para_features(KVMState *s)
 {
 int i, features = 0;

-for (i = 0; i < ARRAY_SIZE(para_features) - 1; i++) {
+for (i = 0; i < ARRAY_SIZE(para_features); i++) {
 if (kvm_check_extension(s, para_features[i].cap)) {
 features |= (1 << para_features[i].feature);
 }



Applied to uq/master, thanks.

I'm leaving the other patch to Andreas or Michael Tokarev.

Paolo



Re: [Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 22:28, Laszlo Ersek ha scritto:

On 03/20/14 22:18, Christian Borntraeger wrote:

On 20/03/14 21:56, Laszlo Ersek wrote:

On 03/20/14 21:38, Christian Borntraeger wrote:

Qiao Nuohan,

is there a reason why you did not implemented the HMP part for that format
of kdump compressed format? After all this is a patch mostly for developers,
so a HMP interface might come handy. Do you already have some patch in
preparation or know somebody doing it?


http://thread.gmane.org/gmane.comp.emulators.qemu/249283/focus=250059

Laszlo


So in essence: Due to the limitations of the command line parser we cannot
add the format to the hmp command line.
So something like adding

dump_guest_memory_set_format 

would be the only possible solution with the hmp code as is. Correct?


Yes, one possibility would be to make the dump command stateful (=
compression format), and to add a new command setting/getting that state.

Another option would be to leave the current command intact, and add an
independent command that wouldn't take "begin", "end", nor "paging", but
would take compression format.


Another possibility is to kill begin/length from the dump-guest-memory 
command.  HMP is not stable, so if that's useful we can do it.


Paolo




[Qemu-devel] [PATCH v4 4/7] allwinner-a10-pit: use level triggered interrupts

2014-03-20 Thread Beniamino Galvani
Convert the interrupt generation logic to the use of level triggered
interrupts.

Signed-off-by: Beniamino Galvani 
Reviewed-by: Peter Crosthwaite 
---
 hw/timer/allwinner-a10-pit.c |   15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
index 696b7d9..5aa78a9 100644
--- a/hw/timer/allwinner-a10-pit.c
+++ b/hw/timer/allwinner-a10-pit.c
@@ -19,6 +19,15 @@
 #include "sysemu/sysemu.h"
 #include "hw/timer/allwinner-a10-pit.h"
 
+static void a10_pit_update_irq(AwA10PITState *s)
+{
+int i;
+
+for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
+qemu_set_irq(s->irq[i], !!(s->irq_status & s->irq_enable & (1 << i)));
+}
+}
+
 static uint64_t a10_pit_read(void *opaque, hwaddr offset, unsigned size)
 {
 AwA10PITState *s = AW_A10_PIT(opaque);
@@ -74,9 +83,11 @@ static void a10_pit_write(void *opaque, hwaddr offset, 
uint64_t value,
 switch (offset) {
 case AW_A10_PIT_TIMER_IRQ_EN:
 s->irq_enable = value;
+a10_pit_update_irq(s);
 break;
 case AW_A10_PIT_TIMER_IRQ_ST:
 s->irq_status &= ~value;
+a10_pit_update_irq(s);
 break;
 case AW_A10_PIT_TIMER_BASE ... AW_A10_PIT_TIMER_BASE_END:
 index = offset & 0xf0;
@@ -178,6 +189,8 @@ static void a10_pit_reset(DeviceState *dev)
 
 s->irq_enable = 0;
 s->irq_status = 0;
+a10_pit_update_irq(s);
+
 for (i = 0; i < 6; i++) {
 s->control[i] = AW_A10_PIT_DEFAULT_CLOCK;
 s->interval[i] = 0;
@@ -203,7 +216,7 @@ static void a10_pit_timer_cb(void *opaque)
 ptimer_stop(s->timer[i]);
 s->control[i] &= ~AW_A10_PIT_TIMER_EN;
 }
-qemu_irq_pulse(s->irq[i]);
+a10_pit_update_irq(s);
 }
 }
 
-- 
1.7.10.4




Re: [Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Christian Borntraeger
On 20/03/14 21:56, Laszlo Ersek wrote:
> On 03/20/14 21:38, Christian Borntraeger wrote:
>> Qiao Nuohan,
>>
>> is there a reason why you did not implemented the HMP part for that format
>> of kdump compressed format? After all this is a patch mostly for developers,
>> so a HMP interface might come handy. Do you already have some patch in 
>> preparation or know somebody doing it?
> 
> http://thread.gmane.org/gmane.comp.emulators.qemu/249283/focus=250059
> 
> Laszlo
> 
So in essence: Due to the limitations of the command line parser we cannot
add the format to the hmp command line.
So something like adding

dump_guest_memory_set_format 

would be the only possible solution with the hmp code as is. Correct?
(If adding such a command is nice or not is another question)

Christian




[Qemu-devel] [PATCH 1/1 V2] target-ppc: Adding Functionality to rtas_ibm_get_system_parameter.

2014-03-20 Thread Tomo Berry
This patch adds the functionality for
rtas_ibm_get_system_parameter to return a string containing
the values for partition_max_entitled_capacity and
system_potential_processors.

Signed-off-by: Tomo Berry 
---
V1->V2:
changed memory allocation to glib calls
I'm not sure if this is meant for 2.1 or not

 hw/ppc/spapr_rtas.c| 32 
 include/hw/ppc/spapr.h | 13 +
 2 files changed, 45 insertions(+)

diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 1cb276d..734ebc0 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -225,6 +225,9 @@ static void rtas_stop_self(PowerPCCPU *cpu, 
sPAPREnvironment *spapr,
 }
 
 #define DIAGNOSTICS_RUN_MODE42
+#define SPLPAR_CHARACTERISTICS_TOKEN 20
+#define CMO_CHARACTERISTICS_TOKEN 44
+#define CEDE_LATENCY_TOKEN 45
 
 static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
   sPAPREnvironment *spapr,
@@ -236,6 +239,7 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 target_ulong buffer = rtas_ld(args, 1);
 target_ulong length = rtas_ld(args, 2);
 target_ulong ret = RTAS_OUT_NOT_SUPPORTED;
+char *local_buffer;
 
 switch (parameter) {
 case DIAGNOSTICS_RUN_MODE:
@@ -244,6 +248,34 @@ static void rtas_ibm_get_system_parameter(PowerPCCPU *cpu,
 ret = RTAS_OUT_SUCCESS;
 }
 break;
+case SPLPAR_CHARACTERISTICS_TOKEN:
+
+/*  Create a string of length bytes locally to copy to buffer  */
+
+local_buffer = g_malloc0(length);
+
+/*  These are the current system parameters supported.  The first
+ *  16 bits of the buffer must contain the length of the string.
+ *  These 16 bits are not included in the length of the string. 
+ */
+
+((uint16_t *)local_buffer)[0] = cpu_to_be16(snprintf(local_buffer + 2,
+ length - 2, "MaxEntCap=%d,MaxPlatProcs=%d", max_cpus, smp_cpus));
+
+rtas_st_buffer(buffer, length, (uint8_t *)local_buffer);
+
+g_free(local_buffer);
+ret = RTAS_OUT_SUCCESS;
+break;
+case CMO_CHARACTERISTICS_TOKEN:
+ret = RTAS_OUT_NOT_SUPPORTED;
+break;
+case CEDE_LATENCY_TOKEN:
+ret = RTAS_OUT_NOT_SUPPORTED;
+break;
+default:
+ret = RTAS_OUT_NOT_SUPPORTED;
+break;
 }
 
 rtas_st(rets, 0, ret);
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index b2f11e9..bf5b528 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -356,6 +356,19 @@ static inline void rtas_st(target_ulong phys, int n, 
uint32_t val)
 stl_be_phys(ppc64_phys_to_real(phys + 4*n), val);
 }
 
+/*  This function will store a buffer 1 byte at a time into the
+ *  address at phys up to a maximum of phys_len bytes.*/
+
+static inline void rtas_st_buffer(target_ulong phys,
+  target_ulong phys_len,
+  uint8_t *buffer) 
+{
+uint32_t i;
+for (i = 0; i < phys_len; i++) {
+stb_phys(ppc64_phys_to_real(phys + i), buffer[i]);
+}
+}
+
 typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
   uint32_t token,
   uint32_t nargs, target_ulong args,
-- 
1.8.3.1




[Qemu-devel] [PATCH for-2.0 V3] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
There is an issue with iasl on big endian machines: It
cannot disassemble acpi tables taken from little endian
machines, so we cannot check the expected tables.

Do not run iasl on those machines until this
problem is solved by the acpica community.

Signed-off-by: Marcel Apfelbaum 
---
V2 -> V3:
 Addressed Michael S. Tsirkin's review:
 - tests don't need to re-run detection, use configure
   to figure out if it is an LE machine.

V1 -> V2:
 Addressed an offline tip for a much cleaner
 macro line, thanks!

 configure | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index aae617e..2c0a3b2 100755
--- a/configure
+++ b/configure
@@ -4656,7 +4656,10 @@ else
 fi
 echo "PYTHON=$python" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
-if $iasl -h > /dev/null 2>&1; then
+# All known versions of iasl on BE machines are broken.
+# TODO: add detection code once a non-broken version makes an appearance.
+if ($iasl -h > /dev/null 2>&1) &&
+   (lscpu | grep "Byte Order" | grep --quiet "Little Endian" ); then
   echo "IASL=$iasl" >> $config_host_mak
 fi
 echo "CC_I386=$cc_i386" >> $config_host_mak
-- 
1.8.3.1




Re: [Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Laszlo Ersek
Two additional points:

On 03/20/14 21:56, Laszlo Ersek wrote:
> On 03/20/14 21:38, Christian Borntraeger wrote:
>> Qiao Nuohan,
>>
>> is there a reason why you did not implemented the HMP part for that format
>> of kdump compressed format? After all this is a patch mostly for developers,
>> so a HMP interface might come handy. Do you already have some patch in 
>> preparation or know somebody doing it?
> 
> http://thread.gmane.org/gmane.comp.emulators.qemu/249283/focus=250059

- HMP interface could be implemented as a fully new command of course,

- the feature being targeted at developers strikes me as a completely
unexpected idea. The main goal in my understanding is to allow the
management layer (libvirt) to save a compressed vmcore when the guest
panicks, crashes, or the admin feels like it. For communication with
another program, QMP is actually preferable.

So I'm certainly not against anyone adding a HMP interface too, but it
cannot be an extension to the current HMP command (because it would
break existing HMP command lines unless the HMP parser were reworked
too), plus during review I saw no reason to stall the series even
longer, for a side feature that I perceived to be of low importance (and
I actually thought that Qiao Nuohan shared that notion).

Thanks
Laszlo




Re: [Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Laszlo Ersek
On 03/20/14 21:38, Christian Borntraeger wrote:
> Qiao Nuohan,
> 
> is there a reason why you did not implemented the HMP part for that format
> of kdump compressed format? After all this is a patch mostly for developers,
> so a HMP interface might come handy. Do you already have some patch in 
> preparation or know somebody doing it?

http://thread.gmane.org/gmane.comp.emulators.qemu/249283/focus=250059

Laszlo




Re: [Qemu-devel] [PATCH v3 for 2.0] update names in option tables to match with actual command-line spelling

2014-03-20 Thread Eric Blake
On 03/20/2014 07:07 AM, Amos Kong wrote:
> We want to establish a mapping between option name and option table,
> then we can search related option table by option name.
> 
> This patch makes all the member name of QemuOptsList to match with
> actual command-line spelling(option name).
> 
> [ Important Note ]
> 
> The QemuOptsList member name values are ABI, changing them can break
> existing -readconfig configuration files.
> 
> This patch changes:
> 
> fromto  introduced in
> acpiacpitable   0c764a9 v1.5.0
> boot-opts   boot3d3b830 v1.0
> smp-optssmp 12b7f57 v1.6.0
> 
> All three have calcified into ABI already.
> 
> I have updated the release note of 2.0
> http://wiki.qemu.org/ChangeLog/2.0#ABI_breaking
> 
> Signed-off-by: Amos Kong 
> ---

The benefit of this patch is that 'query-command-line-options' gains a
fix where three bogus entries are replaced by their actual command line
spelling.  The drawback is that anyone that doesn't pay attention to the
ABI break announcement, and expects -readconfig and friends to work
while using the old spelling, is in for a surprise.  But since we have
prominently documented the change, and since consistency makes life
nicer, I'm in favor of this patch.

Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] hmp interface for kdump compressed format

2014-03-20 Thread Christian Borntraeger
Qiao Nuohan,

is there a reason why you did not implemented the HMP part for that format
of kdump compressed format? After all this is a patch mostly for developers,
so a HMP interface might come handy. Do you already have some patch in 
preparation or know somebody doing it?

Thanks a lot

Christian




Re: [Qemu-devel] [PATCH for-2.0] hw/i386: fix acpi tables generation for big endian machines

2014-03-20 Thread Michael S. Tsirkin
On Thu, Mar 20, 2014 at 06:40:50PM +0200, Marcel Apfelbaum wrote:
> The acpi tables are not corrected loaded into guest's memory
> for big-endian hosts because of a linker-loader field
> swapped incorrectly. Fixed that.
> 
> Signed-off-by: Marcel Apfelbaum 

Applied, thanks!

> ---
> Note that the acpi test still fails because of
> an iasl issue, I will send a patch separately
> that disables disassembly validation for big
> endian machines until we'll have an iasl fix. 
> 
>  hw/i386/bios-linker-loader.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> index aa56184..0e1cfb7 100644
> --- a/hw/i386/bios-linker-loader.c
> +++ b/hw/i386/bios-linker-loader.c
> @@ -109,9 +109,8 @@ void bios_linker_loader_alloc(GArray *linker,
>  strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
>  entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
>  entry.alloc.align = cpu_to_le32(alloc_align);
> -entry.alloc.zone = cpu_to_le32(alloc_fseg ?
> -BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> -BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> +entry.alloc.zone = alloc_fseg ? BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
> +BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH;
>  
>  /* Alloc entries must come first, so prepend them */
>  g_array_prepend_vals(linker, &entry, sizeof entry);
> -- 
> 1.8.3.1



Re: [Qemu-devel] [PATCH for-2.0 V2] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Michael S. Tsirkin
On Thu, Mar 20, 2014 at 08:40:08PM +0200, Marcel Apfelbaum wrote:
> There is an issue with iasl on big endian machines: It
> cannot disassemble acpi tables taken from little endian
> machines, so we cannot check the expected tables.
> 
> Do not run iasl on those machines until this
> problem is solved by the acpica community.
> 
> Signed-off-by: Marcel Apfelbaum 

Seems too aggressive: can't we detect the broken iasl?
E.g. won't it fail to disassemble expected AML files?
Also, won't this broken iasl generate corrupt AML
on output? If yes we should detect this at configure
time instead?

> ---
> V1 -> V2:
>  Addressed an offline tip for a much cleaner
>  macro line, thanks!
> 
>  tests/acpi-test.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tests/acpi-test.c b/tests/acpi-test.c
> index 249fe03..88e876f 100644
> --- a/tests/acpi-test.c
> +++ b/tests/acpi-test.c
> @@ -145,7 +145,7 @@ static uint8_t boot_sector[0x7e000] = {
>  
>  static const char *disk = "tests/acpi-test-disk.raw";
>  static const char *data_dir = "tests/acpi-test-data";
> -#ifdef CONFIG_IASL
> +#if G_BYTE_ORDER == G_LITTLE_ENDIAN && defined(CONFIG_IASL)
>  static const char *iasl = stringify(CONFIG_IASL);
>  #else
>  static const char *iasl;
> -- 
> 1.8.3.1



Re: [Qemu-devel] [PATCH v3 06/10] XBZRLE: rebuild the cache_is_cached function

2014-03-20 Thread Eric Blake
On 03/20/2014 01:44 PM, Eric Blake wrote:
> On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
>> From: ChenLiang 
>>
>> Rebuild the cache_is_cached function by cache_get_by_addr.
>>
>> Signed-off-by: ChenLiang 
>> Signed-off-by: Gonglei 
>> ---
>>  page_cache.c | 38 --
>>  1 file changed, 16 insertions(+), 22 deletions(-)
>>
> 
>>  int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
>>   uint64_t current_age)
>>  {
>>  
>> -CacheItem *it = NULL;
>> -
>> -g_assert(cache);
>> -g_assert(cache->page_cache);
>> +CacheItem *it;
> 
> Why are you dropping the asserts?

And if the answer is "because the caller is also asserting the same
thing", then mention it in the commit message.  The best commit messages
are the ones that not only mention WHAT (no silent changes), but also WHY.

-- 
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 v3 00/10] migration: Optimizate the xbzrle and fix two corruption issues

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> V2-->V3
> * rename the bitmap_sync_cnt to bitmap_sync_counter
> * expose xbzrle cache miss rate
> 
> V1-->V2
> * expose the counter that logs the times of updating the dirty bitmap to end 
> user.
> 
> a. Optimization the xbzrle remarkable decrease the cache misses.
> The efficiency of compress increases more than fifty times.
> Before the patch set, the cache almost totally miss when the 
> number of cache item less than the dirty page number. Now the
> hot pages in the cache will not be replaced by other pages. 
> 
> b. Reducing the data copy
> 
> c. Fix two corruption issues.

Your QAPI changes were marked 2.1, but this series also includes a
corruption fix.  Please split this series into patches that MUST be
applied for 2.0 as bug fixes, vs. the patches that are a feature
enhancement (or else with strong justification why a speed optimization
is safe enough to be considered a bug fix, if you think the whole series
belongs in 2.0).

-- 
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 v3 10/10] XBZRLE: update the doc of XBZRLE

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> update the doc of XBZRLE

Having the subject line and the body of the commit message be identical
is redundant.  And just by looking at the commit message, I can't see
WHY you are updating things.  If you were to keep this as a separate
commit, I'd suggest it look more like:

XBZRLE: document cache miss policy

Add a section to the XBZRLE documentation describing how the page cache
determines which pages are hot.


That said, I think you should squash this documentation update into
patch 5/10 where you actually implement it, so that a single patch
becomes self-documenting why you went with this design.  At which point,
the combined patch commit message should look something like:

XBZRLE: optimize XBZRLE to decrease cache misses

...existing text from 5/10...

Additionally, document the new cache age policy.

> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  docs/xbzrle.txt | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/docs/xbzrle.txt b/docs/xbzrle.txt
> index cc3a26a..cdf1e3e 100644
> --- a/docs/xbzrle.txt
> +++ b/docs/xbzrle.txt
> @@ -71,6 +71,13 @@ encoded buffer:
>  encoded length 24
>  e9 07 0f 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 03 01 67 01 01 69
>  
> +The strategy of updating cache
> +=

Copy-and-paste from bad examples already in this file, but it's nicer
when the length of  matches the heading it is paired with.

> +Keeping the hot page in cache is effective to decrease cache missing.
> +XBZRLE use a counter as the age of page. The counter will increase
> +after the ram dirty bitmap syncing. When cache conflicts XBZRLE only
> +replace the old page in cache.

Suggestions for better grammar:

Cache update strategy
=
Keeping the hot pages in the cache is effective for decreased cache
misses. XBZRLE uses a counter as the age of each page. The counter will
increase after each ram dirty bitmap sync. When a cache conflict is
detected, XBZRLE will only evict pages in the cache that are older than
a threshold.

-- 
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 v3 06/10] XBZRLE: rebuild the cache_is_cached function

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> Rebuild the cache_is_cached function by cache_get_by_addr.
> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  page_cache.c | 38 --
>  1 file changed, 16 insertions(+), 22 deletions(-)
> 

>  int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
>   uint64_t current_age)
>  {
>  
> -CacheItem *it = NULL;
> -
> -g_assert(cache);
> -g_assert(cache->page_cache);
> +CacheItem *it;

Why are you dropping the asserts?

-- 
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 v3 05/10] XBZRLE: optimize XBZRLE to decrease the cache missing

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 

In the subject: s/missing/misses/

> 
> Avoid hot pages being replaced by others to remarkably decrease cache

s/cache/cache misses/

> 
> before this patch:
> virsh qemu-monitor-command test_vm '{"execute": "query-migrate"}'
> {"return":{"expected-downtime":1020,"xbzrle-cache":{"bytes":1108284,

1.1M bytes saved by compression,

> "cache-size":8388608,"cache-miss-rate":0.987013,"pages":18297,"overflow":8,

18k pages sent compressed

> "cache-miss":1228737},"status":"active","setup-time":10,"total-time":52398,
> "ram":{"total":12466991104,"remaining":1695744,"mbps":935.559472,
> "transferred":5780760580,"dirty-sync-counter":271,"duplicate":2878530,
> "dirty-pages-rate":29130,"skipped":0,"normal-bytes":5748592640,
> "normal":1403465}},"id":"libvirt-706"}
> 
> cache-miss-rate is 98.7%, totally miss.
> 
> after optimizing:
> virsh qemu-monitor-command test_vm '{"execute": "query-migrate"}'
> {"return":{"expected-downtime":2054,"xbzrle-cache":{"bytes":5066763,

5.0M bytes saved by compression

> "cache-size":8388608,"cache-miss-rate":0.485924,"pages":194823,"overflow":0,

194k pages sent compressed

> "cache-miss":210653},"status":"active","setup-time":11,"total-time":18729,

And reduced from 52 milleseconds to just under 19 on total time.
Definite improvements!

> "ram":{"total":12466991104,"remaining":3895296,"mbps":937.663549,
> "transferred":1615042219,"dirty-sync-counter":98,"duplicate":2869840,
> "dirty-pages-rate":58781,"skipped":0,"normal-bytes":1588404224,
> "normal":387794}},"id":"libvirt-266"}
> 
> The value of cache-miss-rate decrease 49.13%.

s/decrease/decreased to/

> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  arch_init.c|  8 +---
>  include/migration/page_cache.h | 10 +++---
>  page_cache.c   | 23 +++
>  3 files changed, 31 insertions(+), 10 deletions(-)
> 

Reviewed-by: Eric Blake 

However, I think it would be worth squashing patch 10 into this one.

-- 
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 v3 04/10] migration: expose xbzrle cache miss rate

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> expose xbzrle cache miss rate
> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  arch_init.c   | 18 ++
>  hmp.c |  2 ++
>  include/migration/migration.h |  1 +
>  migration.c   |  1 +
>  qapi-schema.json  |  5 -
>  qmp-commands.hx   |  2 ++
>  6 files changed, 28 insertions(+), 1 deletion(-)
> 

> +++ b/qapi-schema.json
> @@ -674,13 +674,16 @@
>  #
>  # @cache-miss: number of cache miss
>  #
> +# @cache-miss-rate: rate of cache miss

Missing '(since 2.1)'

-- 
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 v3 02/10] migration: Add counters of updating the dirty bitmap

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> Add counters to log the times of updating the dirty bitmap.
> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  arch_init.c | 5 +
>  1 file changed, 5 insertions(+)

Reviewed-by: Eric Blake 

-- 
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 v3 03/10] migration: expose the bitmap_sync_counter to the end user

2014-03-20 Thread Eric Blake
On 03/18/2014 06:24 AM, arei.gong...@huawei.com wrote:
> From: ChenLiang 
> 
> expose the counter that log the times of updating the dirty bitmap to

s/log/logs/

> end user.
> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---
>  arch_init.c   |  1 +
>  hmp.c |  2 ++
>  include/migration/migration.h |  1 +
>  migration.c   |  2 ++
>  qapi-schema.json  |  4 +++-
>  qmp-commands.hx   | 13 +
>  6 files changed, 18 insertions(+), 5 deletions(-)
> 

> +++ b/qapi-schema.json
> @@ -651,13 +651,15 @@
>  #
>  # @mbps: throughput in megabits/sec. (since 1.6)
>  #
> +# @dirty-sync-counter: the times of ram dirty sync (since 2.1)

The name could possibly be shortened.  Also, this sentence reads
awkwardly.  Maybe:

@dirty-sync-count: number of times that dirty ram was synchronized
(since 2.1)

> +++ b/qmp-commands.hx
> @@ -2928,6 +2928,7 @@ The main json-object contains the following:
>  pages. This is just normal pages times size of one page,
>  but this way upper levels don't need to care about page
>  size (json-int)
> + - "dirty-sync-counter": the times of ram dirty sync (json-int)

and if you do change the wording above (or even shorten the variable
name), make it match here

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] qapi-commands.py generates code that uses uninitialized variables

2014-03-20 Thread Michael Roth
Quoting Markus Armbruster (2014-03-18 04:32:08)
> Peter Maydell  writes:
> 
> > This is something clang's -fsanitize=undefined spotted. The
> > code generated by qapi-commands.py in qmp-marshal.c for
> > qmp_marshal_* functions where there are some optional
> > arguments looks like this:
> >
> > bool has_force = false;
> > bool force;
> >
> > mi = qmp_input_visitor_new_strict(QOBJECT(args));
> > v = qmp_input_get_visitor(mi);
> > visit_type_str(v, &device, "device", errp);
> > visit_start_optional(v, &has_force, "force", errp);
> > if (has_force) {
> > visit_type_bool(v, &force, "force", errp);
> > }
> > visit_end_optional(v, errp);
> > qmp_input_visitor_cleanup(mi);
> >
> > if (error_is_set(errp)) {
> > goto out;
> > }
> > qmp_eject(device, has_force, force, errp);
> >
> > In the case where has_force is false, we never initialize
> > force, but then we use it by passing it to qmp_eject.
> > I imagine we don't then actually use the value, but clang
> 
> Use of FOO when !has_FOO is a bug.
> 
> > complains in particular for 'bool' variables because the value
> > that ends up being loaded from memory for 'force' is not either
> > 0 or 1 (being uninitialized stack contents).
> >
> > Anybody understand what the codegenerator is doing well enough
> > to suggest a fix? I'd guess that just initializing the variable either
> > at point of declaration or in an else {) clause of the 'if (has_force)'
> > conditional would suffice, but presumably you need to handle
> > all the possible data types...
> 
> I can give it a try.  Will probably take a while, though.

Could it be as simple as this?:

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 9734ab0..a70482e 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -99,7 +99,7 @@ bool has_%(argname)s = false;
  argname=c_var(argname), argtype=c_type(argtype))
 else:
 ret += mcgen('''
-%(argtype)s %(argname)s;
+%(argtype)s %(argname)s = {0};
 ''',
  argname=c_var(argname), argtype=c_type(argtype))

Pointer-type are special-cased initialized to NULL, so that leaves these guys
in the current set of qapi-defined types that we use as direct arguments for
qmp commands:

  NON-POINTER TYPE: BlockdevOnError
  NON-POINTER TYPE: bool
  NON-POINTER TYPE: DataFormat
  NON-POINTER TYPE: double
  NON-POINTER TYPE: DumpGuestMemoryFormat
  NON-POINTER TYPE: int64_t
  NON-POINTER TYPE: MirrorSyncMode
  NON-POINTER TYPE: NewImageMode
  NON-POINTER TYPE: uint32_t

I'm trying to make sense of whether {0} is a valid initializer in all these
cases, as I saw some references to GCC complaining about cases where you don't
use an initializer for each nested subtype (back in 2002 at least:
http://www.ex-parrot.com/~chris/random/initialise.html), but that doesn't seem
to be the case now.

If that's not safe, we can memset based on sizeof() in the else clause, but
obviously that's sub-optimal.




Re: [Qemu-devel] [PATCH v4 20/21] target-arm: Add Cortex-A57 processor

2014-03-20 Thread Peter Maydell
On 6 March 2014 19:33, Peter Maydell  wrote:
> Add Cortex-A57 processor.
>
> Signed-off-by: Peter Maydell 

> +static void aarch64_a57_initfn(Object *obj)
> +{
> +ARMCPU *cpu = ARM_CPU(obj);
> +
> +set_feature(&cpu->env, ARM_FEATURE_V8);
> +set_feature(&cpu->env, ARM_FEATURE_VFP4);
> +set_feature(&cpu->env, ARM_FEATURE_VFP_FP16);
> +set_feature(&cpu->env, ARM_FEATURE_NEON);
> +set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);

This last one should be removed, since Thumb2EE is
not present in ARMv8.

thanks
-- PMM



Re: [Qemu-devel] [PULL for 2.0 0/5] MinGW related patches

2014-03-20 Thread Peter Maydell
On 20 March 2014 19:12, Stefan Weil  wrote:
> Unfortunately a recent commit added new code in util/, and that code
> needs a modification of patch 5/5. I really should have re-run the
> compile test :-(
>
> Peter, is it possible to pull only patches 1-4? They compile and are
> fine, and we'd save mail bandwidth if I don't have to send them again.
> You could also apply only patch 1. It is the only really important one
> because it adds GTK for Windows users. The other ones can also be
> applied after QEMU 2.0, if you prefer that.

I'm afraid I can only either apply or not apply pullrequests.
You can always resend just the cover letter if the only
thing you're doing is dropping some patches from it.

thanks
-- PMM



Re: [Qemu-devel] [PULL for 2.0 0/5] MinGW related patches

2014-03-20 Thread Stefan Weil
Am 20.03.2014 13:45, schrieb Peter Maydell:
> On 20 March 2014 06:29, Stefan Weil  wrote:
>> Am 20.03.2014 07:25, schrieb Stefan Weil:
>>> This includes a patch for GTK (needed for MinGW, but not restricted to it)
>>> and most of the patches which restructure the includes for the Win API.
>>> I ommitted the last optional block patch.
>>>
>>> Stefan
>>>
>>> [PULL for 2.0 1/5] gtk: Support GTK without VTE
>>> [PULL for 2.0 2/5] w32: Add and use intermediate include file for
>>> [PULL for 2.0 3/5] w32: Move inline function from header file to C
>>> [PULL for 2.0 4/5] w32: Reduce dependencies in sysemu/os-win32.h
>>> [PULL for 2.0 5/5] w32: Replace Windows specific data types in
>>>
>>
>> The most important part was missing, sorry:
>>
>> The following changes since commit 06c1bee85a7def8d0139ee6829728a891efe623f:
>>
>>   Merge remote-tracking branch 'remotes/afaerber/tags/prep-for-2.0' into
>> staging (2014-03-19 23:34:43 +)
>>
>> are available in the git repository at:
>>
>>
>>   git://qemu.weilnetz.de/qemu.git qemu-2.0
> 
> I'm afraid this doesn't build on my mingw32 setup:
> 
>   CCutil/rfifolock.o
> In file included from
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread.h:14,
>  from
> /home/petmay01/linaro/qemu-for-merges/include/qemu/rfifolock.h:17,
>  from 
> /home/petmay01/linaro/qemu-for-merges/util/rfifolock.c:15:
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:8:
> error: expected specifier-qualifier-list before ‘WinHandle’
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:18:
> error: expected specifier-qualifier-list before ‘WinLong’
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:22:
> error: expected specifier-qualifier-list before ‘WinLong’
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:28:
> error: expected specifier-qualifier-list before ‘WinHandle’
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:32:
> error: expected specifier-qualifier-list before ‘WinHandle’
> /home/petmay01/linaro/qemu-for-merges/include/qemu/thread-win32.h:42:
> error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before
> ‘qemu_thread_get_handle’
> make: *** [util/rfifolock.o] Error 1
> 
> thanks
> -- PMM
> 

Unfortunately a recent commit added new code in util/, and that code
needs a modification of patch 5/5. I really should have re-run the
compile test :-(

Peter, is it possible to pull only patches 1-4? They compile and are
fine, and we'd save mail bandwidth if I don't have to send them again.
You could also apply only patch 1. It is the only really important one
because it adds GTK for Windows users. The other ones can also be
applied after QEMU 2.0, if you prefer that.

I'll send an updated patch 5, and because it is modified, it will need a
new review.

Cheers,
Stefan




Re: [Qemu-devel] [PATCH for-2.0] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
On Thu, 2014-03-20 at 19:00 +, Peter Maydell wrote:
> On 20 March 2014 17:47, Marcel Apfelbaum  wrote:
> > There is an issue with iasl on big endian machines: It
> > cannot disassemble acpi tables taken from little endian
> > machines, so we cannot check the expected tables.
> >
> > Do not run iasl on those machines until this
> > problem is solved by the acpica community.
> 
> Is there an upstream bug report for this? It would be
> nice to have a reference somewhere so we can tell if
> we can remove the check in future...
Hi Peter,
I opened a bug http://bugs.acpica.org/show_bug.cgi?id=1082 and
started a discussion 
https://lists.acpica.org/pipermail/devel/2014-March/000637.html

Thanks,
Marcel

> 
> thanks
> -- PMM
> 





Re: [Qemu-devel] [PATCH for-2.0] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Peter Maydell
On 20 March 2014 17:47, Marcel Apfelbaum  wrote:
> There is an issue with iasl on big endian machines: It
> cannot disassemble acpi tables taken from little endian
> machines, so we cannot check the expected tables.
>
> Do not run iasl on those machines until this
> problem is solved by the acpica community.

Is there an upstream bug report for this? It would be
nice to have a reference somewhere so we can tell if
we can remove the check in future...

thanks
-- PMM



[Qemu-devel] [PATCH for-2.0 V2] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
There is an issue with iasl on big endian machines: It
cannot disassemble acpi tables taken from little endian
machines, so we cannot check the expected tables.

Do not run iasl on those machines until this
problem is solved by the acpica community.

Signed-off-by: Marcel Apfelbaum 
---
V1 -> V2:
 Addressed an offline tip for a much cleaner
 macro line, thanks!

 tests/acpi-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/acpi-test.c b/tests/acpi-test.c
index 249fe03..88e876f 100644
--- a/tests/acpi-test.c
+++ b/tests/acpi-test.c
@@ -145,7 +145,7 @@ static uint8_t boot_sector[0x7e000] = {
 
 static const char *disk = "tests/acpi-test-disk.raw";
 static const char *data_dir = "tests/acpi-test-data";
-#ifdef CONFIG_IASL
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN && defined(CONFIG_IASL)
 static const char *iasl = stringify(CONFIG_IASL);
 #else
 static const char *iasl;
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH v4 10/21] target-arm: Add v8 mmu translation support

2014-03-20 Thread Peter Maydell
On 6 March 2014 19:32, Peter Maydell  wrote:
> @@ -1065,8 +1065,9 @@ static void par_write(CPUARMState *env, const 
> ARMCPRegInfo *ri, uint64_t value)
>   */
>  static inline bool extended_addresses_enabled(CPUARMState *env)
>  {
> -return arm_feature(env, ARM_FEATURE_LPAE)
> -&& (env->cp15.c2_control & (1U << 31));
> +return arm_feature(env, ARM_FEATURE_V8)
> +|| (arm_feature(env, ARM_FEATURE_LPAE)
> +&& (env->cp15.c2_control & (1U << 31)));
>  }

Just noticed a minor nit here -- rather than checking
for ARM_FEATURE_V8 we should be using arm_el_is_aa64(env, 1)
(as the translation code itself does). At the moment the
two give the same answer, but if/when we ever support
running a 32 bit kernel on an ARMv8 CPU they'll be
different, so better to get the check right to start with.

I'll fix this for the next round of these patches
(and also update the now out of date comment).

thanks
-- PMM



Re: [Qemu-devel] [RFC 4/8] qdev: link based hotplug

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 17:20, Igor Mammedov ha scritto:

>
> What about just looking up on the QOM tree until you find a
> HotplugHandler, if the device doesn't have a bus or the bus doesn't have
> a hotplug handler link itself?  This is similar to how FWPathProvider works.

it does so "hotplug_handler_get_from_path()",
above just provides option to specify lookup path. See 6/8 where PC board
allocates links and sets its own board specific path for generic DimmDevice.


Yeah, but I'm not sure why you need the links.  Why can't you just start 
from the canonical path, such as /machine/peripheral/dimm-0 for -device 
dimm,id=dimm-0, and walk up from there?


Paolo



Re: [Qemu-devel] [PATCH v3 06/10] XBZRLE: rebuild the cache_is_cached function

2014-03-20 Thread Dr. David Alan Gilbert
* arei.gong...@huawei.com (arei.gong...@huawei.com) wrote:
> From: ChenLiang 
> 
> Rebuild the cache_is_cached function by cache_get_by_addr.
> 
> Signed-off-by: ChenLiang 
> Signed-off-by: Gonglei 
> ---

Reviewed-by: Dr. David Alan Gilbert 

>  page_cache.c | 38 --
>  1 file changed, 16 insertions(+), 22 deletions(-)
> 
> diff --git a/page_cache.c b/page_cache.c
> index c78157b..3190c55 100644
> --- a/page_cache.c
> +++ b/page_cache.c
> @@ -124,24 +124,6 @@ static size_t cache_get_cache_pos(const PageCache *cache,
>  return pos;
>  }
>  
> -bool cache_is_cached(const PageCache *cache, uint64_t addr,
> - uint64_t current_age)
> -{
> -size_t pos;
> -
> -g_assert(cache);
> -g_assert(cache->page_cache);
> -
> -pos = cache_get_cache_pos(cache, addr);
> -
> -if (cache->page_cache[pos].it_addr == addr) {
> -/* update the it_age when the cache hit */
> -cache->page_cache[pos].it_age = current_age;
> -return true;
> -}
> -return false;
> -}
> -
>  static CacheItem *cache_get_by_addr(const PageCache *cache, uint64_t addr)
>  {
>  size_t pos;
> @@ -159,14 +141,26 @@ uint8_t *get_cached_data(const PageCache *cache, 
> uint64_t addr)
>  return cache_get_by_addr(cache, addr)->it_data;
>  }
>  
> +bool cache_is_cached(const PageCache *cache, uint64_t addr,
> + uint64_t current_age)
> +{
> +CacheItem *it;
> +
> +it = cache_get_by_addr(cache, addr);
> +
> +if (it->it_addr == addr) {
> +/* update the it_age when the cache hit */
> +it->it_age = current_age;
> +return true;
> +}
> +return false;
> +}
> +
>  int cache_insert(PageCache *cache, uint64_t addr, const uint8_t *pdata,
>   uint64_t current_age)
>  {
>  
> -CacheItem *it = NULL;
> -
> -g_assert(cache);
> -g_assert(cache->page_cache);
> +CacheItem *it;
>  
>  /* actual update of entry */
>  it = cache_get_by_addr(cache, addr);
> -- 
> 1.7.12.4
> 
> 
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



[Qemu-devel] [PATCH for-2.0] tests/acpi-test: do not run iasl on big endian machines

2014-03-20 Thread Marcel Apfelbaum
There is an issue with iasl on big endian machines: It
cannot disassemble acpi tables taken from little endian
machines, so we cannot check the expected tables.

Do not run iasl on those machines until this
problem is solved by the acpica community.

Signed-off-by: Marcel Apfelbaum 
---
 tests/acpi-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/acpi-test.c b/tests/acpi-test.c
index 249fe03..af44e47 100644
--- a/tests/acpi-test.c
+++ b/tests/acpi-test.c
@@ -145,8 +145,10 @@ static uint8_t boot_sector[0x7e000] = {
 
 static const char *disk = "tests/acpi-test-disk.raw";
 static const char *data_dir = "tests/acpi-test-data";
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 #ifdef CONFIG_IASL
 static const char *iasl = stringify(CONFIG_IASL);
+#endif
 #else
 static const char *iasl;
 #endif
-- 
1.8.3.1




Re: [Qemu-devel] [Qemu-trivial] [PATCH] serial-pci: Set prog interface field of pci config to 16550 compatible

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 17:58, BALATON Zoltan ha scritto:


Classes (or anything guest-visible in fact) must never ever be changed
for the same machine type.  It's a rule.


The class did not change only the prog interface field after it (which
is guest visible but I think most guests just ignore it). So then what's
the correct way to do it? Do I need to change the patch or can it be
merged as it is the next time a new machine type is added?


You can wait for the 2.1 machine type to be added.

Paolo



Re: [Qemu-devel] Windows XP Setup hangs on Fedora FC20 install

2014-03-20 Thread Cole Robinson
On 03/20/2014 02:35 AM, Gerhard Wiesinger wrote:
> On 17.03.2014 13:31, Cole Robinson wrote:
>> Works fine here but I'm using AMD. Please file a Fedora bug against qemu, and
>> include:
>>
>> - full qemu command line (if using libvirt: 
>> /var/log/libvirt/qemu/$vmname.log)
>> - Any qemu stdout/stderr output
>> - Check dmesg for any kvm errors
>> - Try booting an older Fedora 20 kernel and see if it makes any difference
>> - Optionally try a rawhide kernel: sudo yum install fedora-release-rawhide &&
>> sudo yum --enablrepo=rawhide update kernel
>>
> 
> Hello Cole,
> 
> I tried it on a Fedora 20 installation with latest updates (same software
> version) with an AMD CPU and I can confirm that it works, too.
> 
> Can you try it on Intel based CPUs, too?
> 

Works fine on my t430s thinkpad, intel i7.

Please file a bug with the requested info and we can follow up there.

- Cole




Re: [Qemu-devel] [PATCH v4 16/21] target-arm: Implement SP_EL0, SP_EL1

2014-03-20 Thread Peter Maydell
On 17 March 2014 07:02, Peter Crosthwaite  wrote:
> On Fri, Mar 7, 2014 at 5:33 AM, Peter Maydell  
> wrote:
>> Implement handling for the AArch64 SP_EL0 system register.
>> This holds the EL0 stack pointer, and is only accessible when
>> it's not being used as the stack pointer, ie when we're in EL1
>> and EL1 is using its own stack pointer. We also provide a
>> definition of the SP_EL1 register; this isn't guest visible
>> as a system register for an implementation like QEMU which
>> doesn't provide EL2 or EL3; however it is useful for ensuring
>> the underlying state is migrated.
>>
>> We need to update the state fields in the CPU state whenever
>
> "whenever we".

Fixed, thanks.

>> switch stack pointers; this happens when we take an exception
>> and also when SPSEL is used to change the bit in PSTATE which
>> indicates which stack pointer EL1 should use.
>>
>> Signed-off-by: Peter Maydell 
>> ---
>>  target-arm/cpu.h   |  2 ++
>>  target-arm/helper.c| 34 ++
>>  target-arm/internals.h | 25 +
>>  target-arm/kvm64.c | 37 ++---
>>  target-arm/machine.c   |  7 ---
>>  target-arm/op_helper.c |  2 +-
>>  6 files changed, 100 insertions(+), 7 deletions(-)
>>
>> diff --git a/target-arm/cpu.h b/target-arm/cpu.h
>> index 7ef2c71..338edc3 100644
>> --- a/target-arm/cpu.h
>> +++ b/target-arm/cpu.h
>> @@ -163,6 +163,7 @@ typedef struct CPUARMState {
>>  uint64_t daif; /* exception masks, in the bits they are in in PSTATE */
>>
>>  uint64_t elr_el1; /* AArch64 ELR_EL1 */
>> +uint64_t sp_el[2]; /* AArch64 banked stack pointers */
>>
>
> Should the macro AARCH64_MAX_EL_LEVELS exist for this?

I'm not really convinced, because the set of things that
would need to change to make the maximum EL not 1 would
be so huge that one array size more or less is not really
very relevant. This seems to me like the kind of thing that
will shake itself out when somebody gets round to adding
EL2 or EL3 emulation support.

>>  const VMStateDescription vmstate_arm_cpu = {
>>  .name = "cpu",
>> -.version_id = 15,
>> -.minimum_version_id = 15,
>> -.minimum_version_id_old = 15,
>> +.version_id = 16,
>> +.minimum_version_id = 16,
>> +.minimum_version_id_old = 16,
>
> So in the past, I have squashed unrelated patches together to minimise
> VMSD versions bumps. Whats more important - these versions numbers of
> git patch separation?

We have an entire 32 bit integer to work with for the ID
numbers, so there's no reason to make patches harder to
review by squashing together things that would be clearer
handled separately.

thanks
-- PMM



Re: [Qemu-devel] [Qemu-trivial] [PATCH] serial-pci: Set prog interface field of pci config to 16550 compatible

2014-03-20 Thread BALATON Zoltan

On Thu, 20 Mar 2014, Paolo Bonzini wrote:

Il 20/03/2014 17:01, BALATON Zoltan ha scritto:

On Thu, 20 Mar 2014, Paolo Bonzini wrote:

Il 20/03/2014 16:42, Michael Tokarev ha scritto:

10.03.2014 22:40, BALATON Zoltan wrote:

Ping!
http://patchwork.ozlabs.org/patch/324674/


Thanks, applied to -trivial.


No, please don't; this needs to be done for new machine types only.


Why? I tried running a Windows XP image that was set up before this
patch and it did not complain about changed hardware. Or is there
another reason I'm missing?


Classes (or anything guest-visible in fact) must never ever be changed for 
the same machine type.  It's a rule.


The class did not change only the prog interface field after it (which is 
guest visible but I think most guests just ignore it). So then what's the 
correct way to do it? Do I need to change the patch or can it be merged as 
it is the next time a new machine type is added?


Regards,
BALATON Zoltan



[Qemu-devel] [PATCH for-2.0] hw/i386: fix acpi tables generation for big endian machines

2014-03-20 Thread Marcel Apfelbaum
The acpi tables are not corrected loaded into guest's memory
for big-endian hosts because of a linker-loader field
swapped incorrectly. Fixed that.

Signed-off-by: Marcel Apfelbaum 
---
Note that the acpi test still fails because of
an iasl issue, I will send a patch separately
that disables disassembly validation for big
endian machines until we'll have an iasl fix. 

 hw/i386/bios-linker-loader.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
index aa56184..0e1cfb7 100644
--- a/hw/i386/bios-linker-loader.c
+++ b/hw/i386/bios-linker-loader.c
@@ -109,9 +109,8 @@ void bios_linker_loader_alloc(GArray *linker,
 strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
 entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
 entry.alloc.align = cpu_to_le32(alloc_align);
-entry.alloc.zone = cpu_to_le32(alloc_fseg ?
-BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
-BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
+entry.alloc.zone = alloc_fseg ? BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
+BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH;
 
 /* Alloc entries must come first, so prepend them */
 g_array_prepend_vals(linker, &entry, sizeof entry);
-- 
1.8.3.1




Re: [Qemu-devel] [Qemu-trivial] [PATCH] fix return check for KVM_GET_DIRTY_LOG ioctl

2014-03-20 Thread Mario Smarduch

I agree. One thing I forgot to mention andother side effect
of this bug was virtio VRing used, avail index error 
the Guest was 1,2,..  less then host.

I looked up that bug it happend on some architectures. 
This may or may not be related. Obviously if the dirty
bitmap is not processed properly you may see issues like that.

- Mario 

On 03/20/2014 08:45 AM, Michael Tokarev wrote:
> 19.03.2014 21:24, Mario Smarduch wrote:
>>
>> Fix return condition check from kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) to
>> handle internal failures or no support for memory slot dirty bitmap.
>> Otherwise the ioctl succeeds and continues with migration.
>> Addresses BUG# 1294227
> 
> Thanks, applied to -trivial.
> 
> []
>> -if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) {
>> +if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) < 0) {
> 
> Actually I'd make all error checks like this.  Many checks compares
> return value with -1 for some reason, while actually, any <0 value
> should be treated as error in many many places...  At the same time,
> comparison with 0 is cheaper than comparison with -1 ;)
> 
> /mjt
> 




Re: [Qemu-devel] [PATCH 4/5] sclp-s390: Define new SCLP codes and structures

2014-03-20 Thread Christian Borntraeger
On 20/03/14 17:33, Matthew Rosato wrote:
> 
> Hi Christian -- You already accepted this patch into s390-next with
> these changes as 234eef51a12e2f0f8dfd71cb49d2469d462b1855.  Or am I
> missing something else you wanted changed?

Gnarf. Yes I wanted to start review and took the wrong version :-(





Re: [Qemu-devel] [PATCH 4/5] sclp-s390: Define new SCLP codes and structures

2014-03-20 Thread Matthew Rosato
On 03/20/2014 05:56 AM, Christian Borntraeger wrote:
> On 16/12/13 21:51, Matthew Rosato wrote:
>> Define new SCLP codes and structures that will be needed for s390 memory
>> hotplug.
>>
>> Signed-off-by: Matthew Rosato 
>> ---
>>  hw/s390x/sclp.c |2 +-
>>  include/hw/s390x/sclp.h |   46 
>> ++
>>  2 files changed, 47 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
>> index 86d6ae0..cb53d7e 100644
>> --- a/hw/s390x/sclp.c
>> +++ b/hw/s390x/sclp.c
>> @@ -45,7 +45,7 @@ static void sclp_execute(SCCB *sccb, uint64_t code)
>>  {
>>  S390SCLPDevice *sdev = get_event_facility();
>>
>> -switch (code) {
>> +switch (code & SCLP_NO_CMD_PARM) {
> 
> This is already done in latest upstream, so please provide a newer version of
> these patches against s390-next. Will apply then.
> 
> Christian

Hi Christian -- You already accepted this patch into s390-next with
these changes as 234eef51a12e2f0f8dfd71cb49d2469d462b1855.  Or am I
missing something else you wanted changed?

This is part of v1 -- v2 of the whole patch set excluded this patch as a
result (among other changes).

I noticed that v2 doesn't fit anymore.  I'll submit a trimmed-down and
re-fit v3 of the patch set once Igor's 'convert -m to QemuOpts' set goes
in (it just got applied to trivial).

> 
>>  case SCLP_CMDW_READ_SCP_INFO:
>>  case SCLP_CMDW_READ_SCP_INFO_FORCED:
>>  read_SCP_info(sccb);
>> diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
>> index 231a38a..e80cb23 100644
>> --- a/include/hw/s390x/sclp.h
>> +++ b/include/hw/s390x/sclp.h
>> @@ -20,18 +20,31 @@
>>  /* SCLP command codes */
>>  #define SCLP_CMDW_READ_SCP_INFO 0x00020001
>>  #define SCLP_CMDW_READ_SCP_INFO_FORCED  0x00120001
>> +#define SCLP_READ_STORAGE_ELEMENT_INFO  0x00040001
>> +#define SCLP_ATTACH_STORAGE_ELEMENT 0x00080001
>> +#define SCLP_ASSIGN_STORAGE 0x000D0001
>> +#define SCLP_UNASSIGN_STORAGE   0x000C0001
>>  #define SCLP_CMD_READ_EVENT_DATA0x00770005
>>  #define SCLP_CMD_WRITE_EVENT_DATA   0x00760005
>>  #define SCLP_CMD_READ_EVENT_DATA0x00770005
>>  #define SCLP_CMD_WRITE_EVENT_DATA   0x00760005
>>  #define SCLP_CMD_WRITE_EVENT_MASK   0x00780005
>>
>> +/* SCLP Memory hotplug codes */
>> +#define SCLP_NO_CMD_PARM0x00ff
> This can then go as well.
> 
>> +#define SCLP_FC_ASSIGN_ATTACH_READ_STOR 0xE000ULL
>> +#define SCLP_STARTING_SUBINCREMENT_ID   0x10001
>> +#define SCLP_INCREMENT_UNIT 0x1
>> +#define MAX_AVAIL_SLOTS 32
>> +
>>  /* SCLP response codes */
>>  #define SCLP_RC_NORMAL_READ_COMPLETION  0x0010
>>  #define SCLP_RC_NORMAL_COMPLETION   0x0020
>> +#define SCLP_RC_SCCB_BOUNDARY_VIOLATION 0x0100
>>  #define SCLP_RC_INVALID_SCLP_COMMAND0x01f0
>>  #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK   0x0340
>>  #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH0x0300
>> +#define SCLP_RC_STANDBY_READ_COMPLETION 0x0410
>>  #define SCLP_RC_INVALID_FUNCTION0x40f0
>>  #define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0
>>  #define SCLP_RC_INVALID_SELECTION_MASK  0x70f0
>> @@ -75,8 +88,41 @@ typedef struct ReadInfo {
>>  SCCBHeader h;
>>  uint16_t rnmax;
>>  uint8_t rnsize;
>> +uint8_t  _reserved1[16 - 11];   /* 11-15 */
>> +uint16_t entries_cpu;   /* 16-17 */
>> +uint16_t offset_cpu;/* 18-19 */
>> +uint8_t  _reserved2[24 - 20];   /* 20-23 */
>> +uint8_t  loadparm[8];   /* 24-31 */
>> +uint8_t  _reserved3[48 - 32];   /* 32-47 */
>> +uint64_t facilities;/* 48-55 */
>> +uint8_t  _reserved0[100 - 56];
>> +uint32_t rnsize2;
>> +uint64_t rnmax2;
>>  } QEMU_PACKED ReadInfo;
>>
>> +typedef struct ReadStorageElementInfo {
>> +SCCBHeader h;
>> +uint16_t max_id;
>> +uint16_t assigned;
>> +uint16_t standby;
>> +uint8_t _reserved0[16 - 14]; /* 14-15 */
>> +uint32_t entries[0];
>> +} QEMU_PACKED ReadStorageElementInfo;
>> +
>> +typedef struct AttachStorageElement {
>> +SCCBHeader h;
>> +uint8_t _reserved0[10 - 8];  /* 8-9 */
>> +uint16_t assigned;
>> +uint8_t _reserved1[16 - 12]; /* 12-15 */
>> +uint32_t entries[0];
>> +} QEMU_PACKED AttachStorageElement;
>> +
>> +typedef struct AssignStorage {
>> +SCCBHeader h;
>> +uint16_t rn;
>> +} QEMU_PACKED AssignStorage;
>> +
>> +
> 
> Only one space, I guess.
> 
>>  typedef struct SCCB {
>>  SCCBHeader h;
>>  char data[SCCB_DATA_LEN];
>>
> 
> Otherwise: 
> 
> Acked-by: Christian Borntraeger 
> 
> 
> 
> 
> 




Re: [Qemu-devel] [Qemu-trivial] [PATCH] serial-pci: Set prog interface field of pci config to 16550 compatible

2014-03-20 Thread Paolo Bonzini

Il 20/03/2014 17:01, BALATON Zoltan ha scritto:

On Thu, 20 Mar 2014, Paolo Bonzini wrote:

Il 20/03/2014 16:42, Michael Tokarev ha scritto:

10.03.2014 22:40, BALATON Zoltan wrote:

Ping!
http://patchwork.ozlabs.org/patch/324674/


Thanks, applied to -trivial.


No, please don't; this needs to be done for new machine types only.


Why? I tried running a Windows XP image that was set up before this
patch and it did not complain about changed hardware. Or is there
another reason I'm missing?


Classes (or anything guest-visible in fact) must never ever be changed 
for the same machine type.  It's a rule.


Paolo




[Qemu-devel] Outreach Program for Women application deadline extended

2014-03-20 Thread Stefan Hajnoczi
Good news!  The deadline for Outreach Program for Women applications
to work on QEMU, KVM, or libvirt for 12 weeks this summer has been
extended to March 31st 19:00 UTC:
https://wiki.gnome.org/OutreachProgramForWomen/2014/MayAugust#Participating_Organizations

Outreach Program for Women was started by GNOME specifically for women
who want to start contributing to open source.  It has since grown to
include other organizations and we are able to take part this summer!

If you would like to apply or know someone who might be interested in
a 12-week, paid, open source gig from May 19 to August 18, take a look
at our wiki:

http://qemu-project.org/Outreach_Program_for_Women_Summer_2014

Join the #qemu-gsoc IRC channel on irc.oftc.net to chat with mentors
or ask questions.

Stefan



Re: [Qemu-devel] Want to discuss about Outreach Program for Women

2014-03-20 Thread Stefan Hajnoczi
On Thu, Mar 20, 2014 at 9:33 AM, Stefan Hajnoczi  wrote:
> On Wed, Mar 19, 2014 at 08:34:08PM +0530, preeti soni wrote:
>> I want to discuss about project in which I am interested. Can you please
>> give me How I can do this. As early as possible.
>
> The application deadline was 19:00 UTC on 19th of March.  I'm afraid
> it's too late.

Hi Preeti,
We have just extended our OPW application deadline until 31st March
19:00 UTC.  I recommend applying to both OPW and GSoC.

Stefan



Re: [Qemu-devel] [Qemu-trivial] [PATCH v4 0/2] convert -m to QemuOpts

2014-03-20 Thread Michael Tokarev
06.03.2014 13:39, Igor Mammedov wrote:
> Igor Mammedov (1):
>   vl: convert -m to QemuOpts

This patch (2/2) was mime-damaged, I had to edit it manually
in order for it to apply.  Please take a look at
http://git.corpit.ru/?p=qemu.git;a=shortlog;h=refs/heads/trivial-patches-next
to verify it's okay.

Applied to -trivial.

Thanks,

/mjt



Re: [Qemu-devel] [RFC 4/8] qdev: link based hotplug

2014-03-20 Thread Igor Mammedov
On Thu, 20 Mar 2014 17:12:17 +0100
Paolo Bonzini  wrote:

> Il 20/03/2014 16:01, Igor Mammedov ha scritto:
> > +/*
> > + * Returns path to link<> that should be set/unset on dev hotplug.
> > + * Used for link based bussless devices hotplug.
> > + */
> > +char* (*hotplug_path)(DeviceState *dev);
> > +
> 
> What about just looking up on the QOM tree until you find a 
> HotplugHandler, if the device doesn't have a bus or the bus doesn't have 
> a hotplug handler link itself?  This is similar to how FWPathProvider works.

it does so "hotplug_handler_get_from_path()",
above just provides option to specify lookup path. See 6/8 where PC board
allocates links and sets its own board specific path for generic DimmDevice.

> 
> Paolo




  1   2   >