Re: [Qemu-devel] [PATCH v16 00/14] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD

2014-03-10 Thread Fam Zheng
On Mon, 03/10 06:13, Benoît Canet wrote:
 The Friday 07 Mar 2014 à 16:20:42 (+0800), Fam Zheng wrote :
  This series adds for point-in-time snapshot NBD exporting based on
  blockdev-backup (variant of drive-backup with existing device as target).
  
  We get a thin point-in-time snapshot by COW mechanism of drive-backup, and
  export it through built in NBD server. The steps are as below:
  
   1. (SHELL) qemu-img create -f qcow2 BACKUP.qcow2 source size here
  
  (Alternatively we can use -o backing_file=RUNNING-VM.img to omit 
  explicitly
  providing the size by ourselves, but it's risky because 
  RUNNING-VM.qcow2 is
  used r/w by guest. Whether or not setting backing file in the image file
  doesn't matter, as we are going to override the backing hd in the next
  step)
  
   2. (QMP) blockdev-add backing=source-drive file.driver=file 
  file.filename=BACKUP.qcow2 id=target0 if=none driver=qcow2
  
  (where source-drive is the running BlockDriverState name for
  RUNNING-VM.img. This patch implements backing= option to override
  backing_hd for added drive)
  
   3. (QMP) blockdev-backup device=source-drive sync=none target=target0
  
  (this is the QMP command introduced by this series, which use a named
  device as target of drive-backup)
  
   4. (QMP) nbd-server-add device=target0
  
  When image fleecing done:
  
   1. (QMP) block-job-cancel device=source-drive
  
   2. (HMP) drive_del target0
  
   3. (SHELL) rm BACKUP.qcow2
  
  v16: Address review comments from Jeff and Markus (thanks for reviewing!)
   (A side-by-side diff of v15 - v16: http://goo.gl/1goc6S)
  
  [03/14] block: Replace in_use with operation blocker
  Improve error message. (Markus)
  
  [05/14] block: Add bdrv_set_backing_hd()
  in bdrv_set_backing_hd:
  * Don't call bdrv_ref and bdrv_unref. (Jeff)
  * Add bs-open_flags = ~BDRV_O_NO_BACKING. (Jeff)
  in bdrv_open_backing_file:
  * Remove unnecessary bs-backing_hd = NULL;. (Jeff)
  * Don't get wrong refcnt on backing_hd. (Jeff)
  in bdrv_append:
  * Remove unnessary backing_file and backing_format copy, it's 
  taken
care of in bdrv_set_backing_hd(). (Jeff)
  
  [06/14] block: Add backing_blocker in BlockDriverState
  Add call to bdrv_ref() since bdrv_set_backing_hd() doesn't do it
  now.
  
  [08/14] block: Support dropping active in bdrv_drop_intermediate
  Verify active, top, base are in the same backing chain. (Jeff)
  Remember to change backing file when base != NULL. (Jeff)
  
  [09/14] stream: Use bdrv_drop_intermediate and drop close_unused_images
  Drop more unnecessary code. (Jeff)
  
  Thanks,
  Fam
  
  
  Fam Zheng (14):
block: Add BlockOpType enum
block: Introduce op_blockers to BlockDriverState
block: Replace in_use with operation blocker
block: Move op_blocker check from block_job_create to its caller
block: Add bdrv_set_backing_hd()
block: Add backing_blocker in BlockDriverState
block: Parse backing option to reference existing BDS
block: Support dropping active in bdrv_drop_intermediate
stream: Use bdrv_drop_intermediate and drop close_unused_images
qmp: Add command 'blockdev-backup'
block: Allow backup on referenced named BlockDriverState
block: Add blockdev-backup to transaction
qemu-iotests: Test blockdev-backup in 055
qemu-iotests: Image fleecing test case 083
  
   block-migration.c   |   7 +-
   block.c | 314 
  +++-
   block/backup.c  |  26 
   block/commit.c  |   2 +-
   block/mirror.c  |   1 +
   block/stream.c  |  42 +-
   blockdev.c  | 122 ++--
   blockjob.c  |  14 +-
   hw/block/dataplane/virtio-blk.c |  19 ++-
   include/block/block.h   |  29 +++-
   include/block/block_int.h   |   9 +-
   include/block/blockjob.h|   3 +
   qapi-schema.json|  50 +++
   qmp-commands.hx |  44 ++
   tests/qemu-iotests/055  | 275 +--
   tests/qemu-iotests/055.out  |   4 +-
   tests/qemu-iotests/083  |  99 +
   tests/qemu-iotests/083.out  |   5 +
   tests/qemu-iotests/group|   1 +
   19 files changed, 854 insertions(+), 212 deletions(-)
   create mode 100755 tests/qemu-iotests/083
   create mode 100644 tests/qemu-iotests/083.out
  
  -- 
  1.9.0
  
 
 Hi Fam,
 
 I want to rebase my patches on top of yours but I have trouble applying your
 series to kevin/block-next. Is it based on it ?
 

No, I used qemu.git master. I see some conflicts, I will rebase and send to
list.  But I think you meant kevin/block, since kevin/block-next looks 

Re: [Qemu-devel] [PATCH v16 00/14] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD

2014-03-10 Thread Benoît Canet
The Monday 10 Mar 2014 à 14:38:12 (+0800), Fam Zheng wrote :
 On Mon, 03/10 06:13, Benoît Canet wrote:
  The Friday 07 Mar 2014 à 16:20:42 (+0800), Fam Zheng wrote :
   This series adds for point-in-time snapshot NBD exporting based on
   blockdev-backup (variant of drive-backup with existing device as target).
   
   We get a thin point-in-time snapshot by COW mechanism of drive-backup, and
   export it through built in NBD server. The steps are as below:
   
1. (SHELL) qemu-img create -f qcow2 BACKUP.qcow2 source size here
   
   (Alternatively we can use -o backing_file=RUNNING-VM.img to omit 
   explicitly
   providing the size by ourselves, but it's risky because 
   RUNNING-VM.qcow2 is
   used r/w by guest. Whether or not setting backing file in the image 
   file
   doesn't matter, as we are going to override the backing hd in the next
   step)
   
2. (QMP) blockdev-add backing=source-drive file.driver=file 
   file.filename=BACKUP.qcow2 id=target0 if=none driver=qcow2
   
   (where source-drive is the running BlockDriverState name for
   RUNNING-VM.img. This patch implements backing= option to override
   backing_hd for added drive)
   
3. (QMP) blockdev-backup device=source-drive sync=none target=target0
   
   (this is the QMP command introduced by this series, which use a named
   device as target of drive-backup)
   
4. (QMP) nbd-server-add device=target0
   
   When image fleecing done:
   
1. (QMP) block-job-cancel device=source-drive
   
2. (HMP) drive_del target0
   
3. (SHELL) rm BACKUP.qcow2
   
   v16: Address review comments from Jeff and Markus (thanks for reviewing!)
(A side-by-side diff of v15 - v16: http://goo.gl/1goc6S)
   
   [03/14] block: Replace in_use with operation blocker
   Improve error message. (Markus)
   
   [05/14] block: Add bdrv_set_backing_hd()
   in bdrv_set_backing_hd:
   * Don't call bdrv_ref and bdrv_unref. (Jeff)
   * Add bs-open_flags = ~BDRV_O_NO_BACKING. (Jeff)
   in bdrv_open_backing_file:
   * Remove unnecessary bs-backing_hd = NULL;. (Jeff)
   * Don't get wrong refcnt on backing_hd. (Jeff)
   in bdrv_append:
   * Remove unnessary backing_file and backing_format copy, it's 
   taken
 care of in bdrv_set_backing_hd(). (Jeff)
   
   [06/14] block: Add backing_blocker in BlockDriverState
   Add call to bdrv_ref() since bdrv_set_backing_hd() doesn't do 
   it
   now.
   
   [08/14] block: Support dropping active in bdrv_drop_intermediate
   Verify active, top, base are in the same backing chain. (Jeff)
   Remember to change backing file when base != NULL. (Jeff)
   
   [09/14] stream: Use bdrv_drop_intermediate and drop 
   close_unused_images
   Drop more unnecessary code. (Jeff)
   
   Thanks,
   Fam
   
   
   Fam Zheng (14):
 block: Add BlockOpType enum
 block: Introduce op_blockers to BlockDriverState
 block: Replace in_use with operation blocker
 block: Move op_blocker check from block_job_create to its caller
 block: Add bdrv_set_backing_hd()
 block: Add backing_blocker in BlockDriverState
 block: Parse backing option to reference existing BDS
 block: Support dropping active in bdrv_drop_intermediate
 stream: Use bdrv_drop_intermediate and drop close_unused_images
 qmp: Add command 'blockdev-backup'
 block: Allow backup on referenced named BlockDriverState
 block: Add blockdev-backup to transaction
 qemu-iotests: Test blockdev-backup in 055
 qemu-iotests: Image fleecing test case 083
   
block-migration.c   |   7 +-
block.c | 314 
   +++-
block/backup.c  |  26 
block/commit.c  |   2 +-
block/mirror.c  |   1 +
block/stream.c  |  42 +-
blockdev.c  | 122 ++--
blockjob.c  |  14 +-
hw/block/dataplane/virtio-blk.c |  19 ++-
include/block/block.h   |  29 +++-
include/block/block_int.h   |   9 +-
include/block/blockjob.h|   3 +
qapi-schema.json|  50 +++
qmp-commands.hx |  44 ++
tests/qemu-iotests/055  | 275 +--
tests/qemu-iotests/055.out  |   4 +-
tests/qemu-iotests/083  |  99 +
tests/qemu-iotests/083.out  |   5 +
tests/qemu-iotests/group|   1 +
19 files changed, 854 insertions(+), 212 deletions(-)
create mode 100755 tests/qemu-iotests/083
create mode 100644 tests/qemu-iotests/083.out
   
   -- 
   1.9.0
   
  
  Hi Fam,
  
  I want to rebase my patches on top of yours but I have trouble applying your
  

[Qemu-devel] [PATCH v17 06/14] block: Add backing_blocker in BlockDriverState

2014-03-10 Thread Fam Zheng
This makes use of op_blocker and blocks all the operations except for
commit target, on each BlockDriverState-backing_hd.

The asserts for op_blocker in bdrv_swap are removed because with this
change, the target of block commit has at least the backing blocker of
its child, so the assertion is not true. Callers should do their check.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 24 
 block/mirror.c|  1 +
 include/block/block_int.h |  3 +++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index 64738dc..95247c8 100644
--- a/block.c
+++ b/block.c
@@ -1050,16 +1050,33 @@ fail:
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
 {
 
+if (bs-backing_hd) {
+assert(error_is_set(bs-backing_blocker));
+bdrv_op_unblock_all(bs-backing_hd, bs-backing_blocker);
+} else if (backing_hd) {
+error_setg(bs-backing_blocker,
+   device is used as backing hd of '%s',
+   bs-device_name);
+}
+
 bs-backing_hd = backing_hd;
 if (!backing_hd) {
 bs-backing_file[0] = '\0';
 bs-backing_format[0] = '\0';
+if (error_is_set(bs-backing_blocker)) {
+error_free(bs-backing_blocker);
+}
 goto out;
 }
 bs-open_flags = ~BDRV_O_NO_BACKING;
 pstrcpy(bs-backing_file, sizeof(bs-backing_file), backing_hd-filename);
 pstrcpy(bs-backing_format, sizeof(bs-backing_format),
 backing_hd-drv ? backing_hd-drv-format_name : );
+
+bdrv_op_block_all(bs-backing_hd, bs-backing_blocker);
+/* Otherwise we won't be able to commit due to check in bdrv_commit */
+bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_COMMIT,
+bs-backing_blocker);
 out:
 bdrv_refresh_limits(bs);
 }
@@ -1699,8 +1716,9 @@ void bdrv_close(BlockDriverState *bs)
 
 if (bs-drv) {
 if (bs-backing_hd) {
-bdrv_unref(bs-backing_hd);
-bs-backing_hd = NULL;
+BlockDriverState *backing_hd = bs-backing_hd;
+bdrv_set_backing_hd(bs, NULL);
+bdrv_unref(backing_hd);
 }
 bs-drv-bdrv_close(bs);
 g_free(bs-opaque);
@@ -1908,7 +1926,6 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 assert(QLIST_EMPTY(bs_new-dirty_bitmaps));
 assert(bs_new-job == NULL);
 assert(bs_new-dev == NULL);
-assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1927,7 +1944,6 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 /* Check a few fields that should remain attached to the device */
 assert(bs_new-dev == NULL);
 assert(bs_new-job == NULL);
-assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
diff --git a/block/mirror.c b/block/mirror.c
index dd5ee05..6dc84e8 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -487,6 +487,7 @@ immediate_exit:
  * trigger the unref from the top one */
 BlockDriverState *p = s-base-backing_hd;
 s-base-backing_hd = NULL;
+bdrv_op_unblock_all(p, s-base-backing_blocker);
 bdrv_unref(p);
 }
 }
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 1d3f76f..1f4f78b 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -369,6 +369,9 @@ struct BlockDriverState {
 BlockJob *job;
 
 QDict *options;
+
+/* The error object in use for blocking operations on backing_hd */
+Error *backing_blocker;
 };
 
 int get_tmp_filename(char *filename, int size);
-- 
1.9.0




[Qemu-devel] [PATCH v17 00/14] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD

2014-03-10 Thread Fam Zheng
This series adds for point-in-time snapshot NBD exporting based on
blockdev-backup (variant of drive-backup with existing device as target).

We get a thin point-in-time snapshot by COW mechanism of drive-backup, and
export it through built in NBD server. The steps are as below:

 1. (SHELL) qemu-img create -f qcow2 BACKUP.qcow2 source size here

(Alternatively we can use -o backing_file=RUNNING-VM.img to omit explicitly
providing the size by ourselves, but it's risky because RUNNING-VM.qcow2 is
used r/w by guest. Whether or not setting backing file in the image file
doesn't matter, as we are going to override the backing hd in the next
step)

 2. (QMP) blockdev-add backing=source-drive file.driver=file 
file.filename=BACKUP.qcow2 id=target0 if=none driver=qcow2

(where source-drive is the running BlockDriverState name for
RUNNING-VM.img. This patch implements backing= option to override
backing_hd for added drive)

 3. (QMP) blockdev-backup device=source-drive sync=none target=target0

(this is the QMP command introduced by this series, which use a named
device as target of drive-backup)

 4. (QMP) nbd-server-add device=target0

When image fleecing done:

 1. (QMP) block-job-cancel device=source-drive

 2. (HMP) drive_del target0

 3. (SHELL) rm BACKUP.qcow2

v17: Rebase to current master.

v16: Address review comments from Jeff and Markus (thanks for reviewing!)
 (A side-by-side diff of v15 - v16: http://goo.gl/1goc6S)

[03/14] block: Replace in_use with operation blocker
Improve error message. (Markus)

[05/14] block: Add bdrv_set_backing_hd()
in bdrv_set_backing_hd:
* Don't call bdrv_ref and bdrv_unref. (Jeff)
* Add bs-open_flags = ~BDRV_O_NO_BACKING. (Jeff)
in bdrv_open_backing_file:
* Remove unnecessary bs-backing_hd = NULL;. (Jeff)
* Don't get wrong refcnt on backing_hd. (Jeff)
in bdrv_append:
* Remove unnessary backing_file and backing_format copy, it's taken
  care of in bdrv_set_backing_hd(). (Jeff)

[06/14] block: Add backing_blocker in BlockDriverState
Add call to bdrv_ref() since bdrv_set_backing_hd() doesn't do it
now.

[08/14] block: Support dropping active in bdrv_drop_intermediate
Verify active, top, base are in the same backing chain. (Jeff)
Remember to change backing file when base != NULL. (Jeff)

[09/14] stream: Use bdrv_drop_intermediate and drop close_unused_images
Drop more unnecessary code. (Jeff)

Thanks,
Fam

Fam Zheng (14):
  block: Add BlockOpType enum
  block: Introduce op_blockers to BlockDriverState
  block: Replace in_use with operation blocker
  block: Move op_blocker check from block_job_create to its caller
  block: Add bdrv_set_backing_hd()
  block: Add backing_blocker in BlockDriverState
  block: Parse backing option to reference existing BDS
  block: Support dropping active in bdrv_drop_intermediate
  stream: Use bdrv_drop_intermediate and drop close_unused_images
  qmp: Add command 'blockdev-backup'
  block: Allow backup on referenced named BlockDriverState
  block: Add blockdev-backup to transaction
  qemu-iotests: Test blockdev-backup in 055
  qemu-iotests: Image fleecing test case 083

 block-migration.c   |   7 +-
 block.c | 314 +++-
 block/backup.c  |  26 
 block/commit.c  |   2 +-
 block/mirror.c  |   1 +
 block/stream.c  |  42 +-
 blockdev.c  | 122 ++--
 blockjob.c  |  14 +-
 hw/block/dataplane/virtio-blk.c |  19 ++-
 include/block/block.h   |  29 +++-
 include/block/block_int.h   |   9 +-
 include/block/blockjob.h|   3 +
 qapi-schema.json|  50 +++
 qmp-commands.hx |  44 ++
 tests/qemu-iotests/055  | 275 +--
 tests/qemu-iotests/055.out  |   4 +-
 tests/qemu-iotests/083  |  99 +
 tests/qemu-iotests/083.out  |   5 +
 tests/qemu-iotests/group|   1 +
 19 files changed, 854 insertions(+), 212 deletions(-)
 create mode 100755 tests/qemu-iotests/083
 create mode 100644 tests/qemu-iotests/083.out

-- 
1.9.0




[Qemu-devel] [PATCH v17 04/14] block: Move op_blocker check from block_job_create to its caller

2014-03-10 Thread Fam Zheng
It makes no sense to check for any blocker on bs, we are here only
because of the mechanical conversion from in_use to op_blockers. Remove
it now, and let the callers check specific operation types. Backup and
mirror already have it, add checker to stream and commit.

Signed-off-by: Fam Zheng f...@redhat.com
Reviewed-by: Benoit Canet ben...@irqsave.net
---
 blockdev.c | 8 
 blockjob.c | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index 593925e..d68fd2b 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1846,6 +1846,10 @@ void qmp_block_stream(const char *device, bool has_base,
 return;
 }
 
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_STREAM, errp)) {
+return;
+}
+
 if (base) {
 base_bs = bdrv_find_backing_image(bs, base);
 if (base_bs == NULL) {
@@ -1886,6 +1890,10 @@ void qmp_block_commit(const char *device,
 return;
 }
 
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, errp)) {
+return;
+}
+
 /* default top_bs is the active layer */
 top_bs = bs;
 
diff --git a/blockjob.c b/blockjob.c
index f643a78..3e33051 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -41,7 +41,7 @@ void *block_job_create(const BlockJobDriver *driver, 
BlockDriverState *bs,
 {
 BlockJob *job;
 
-if (bs-job || !bdrv_op_blocker_is_empty(bs)) {
+if (bs-job) {
 error_set(errp, QERR_DEVICE_IN_USE, bdrv_get_device_name(bs));
 return NULL;
 }
-- 
1.9.0




[Qemu-devel] [PATCH v17 01/14] block: Add BlockOpType enum

2014-03-10 Thread Fam Zheng
This adds the enum of all the operations that can be taken on a block
device.

Signed-off-by: Fam Zheng f...@redhat.com
Reviewed-by: Benoit Canet ben...@irqsave.net
---
 include/block/block.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/include/block/block.h b/include/block/block.h
index 780f48b..8820735 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -154,6 +154,25 @@ typedef struct BDRVReopenState {
 void *opaque;
 } BDRVReopenState;
 
+/*
+ * Block operation types
+ */
+typedef enum BlockOpType {
+BLOCK_OP_TYPE_BACKUP_SOURCE,
+BLOCK_OP_TYPE_BACKUP_TARGET,
+BLOCK_OP_TYPE_CHANGE,
+BLOCK_OP_TYPE_COMMIT,
+BLOCK_OP_TYPE_DATAPLANE,
+BLOCK_OP_TYPE_DRIVE_DEL,
+BLOCK_OP_TYPE_EJECT,
+BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
+BLOCK_OP_TYPE_INTERNAL_SNAPSHOT,
+BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
+BLOCK_OP_TYPE_MIRROR,
+BLOCK_OP_TYPE_RESIZE,
+BLOCK_OP_TYPE_STREAM,
+BLOCK_OP_TYPE_MAX,
+} BlockOpType;
 
 void bdrv_iostatus_enable(BlockDriverState *bs);
 void bdrv_iostatus_reset(BlockDriverState *bs);
-- 
1.9.0




[Qemu-devel] [PATCH v17 05/14] block: Add bdrv_set_backing_hd()

2014-03-10 Thread Fam Zheng
This is the common but non-trivial steps to assign or change the
backing_hd of BDS.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 39 +--
 include/block/block.h |  1 +
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/block.c b/block.c
index c79d5dc..64738dc 100644
--- a/block.c
+++ b/block.c
@@ -1047,6 +1047,23 @@ fail:
 return ret;
 }
 
+void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
+{
+
+bs-backing_hd = backing_hd;
+if (!backing_hd) {
+bs-backing_file[0] = '\0';
+bs-backing_format[0] = '\0';
+goto out;
+}
+bs-open_flags = ~BDRV_O_NO_BACKING;
+pstrcpy(bs-backing_file, sizeof(bs-backing_file), backing_hd-filename);
+pstrcpy(bs-backing_format, sizeof(bs-backing_format),
+backing_hd-drv ? backing_hd-drv-format_name : );
+out:
+bdrv_refresh_limits(bs);
+}
+
 /*
  * Opens the backing file for a BlockDriverState if not yet open
  *
@@ -1060,6 +1077,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 char backing_filename[PATH_MAX];
 int back_flags, ret;
 BlockDriver *back_drv = NULL;
+BlockDriverState *backing_hd;
 Error *local_err = NULL;
 
 if (bs-backing_hd != NULL) {
@@ -1083,6 +1101,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
sizeof(backing_filename));
 }
 
+backing_hd = bdrv_new();
+
 if (bs-backing_format[0] != '\0') {
 back_drv = bdrv_find_format(bs-backing_format);
 }
@@ -1091,23 +,19 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict 
*options, Error **errp)
 back_flags = bs-open_flags  ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT |
 BDRV_O_COPY_ON_READ);
 
-assert(bs-backing_hd == NULL);
-ret = bdrv_open(bs-backing_hd,
+ret = bdrv_open(backing_hd,
 *backing_filename ? backing_filename : NULL, NULL, options,
 back_flags, back_drv, local_err);
 if (ret  0) {
-bs-backing_hd = NULL;
+bdrv_unref(backing_hd);
+backing_hd = NULL;
 bs-open_flags |= BDRV_O_NO_BACKING;
 error_setg(errp, Could not open backing file: %s,
error_get_pretty(local_err));
 error_free(local_err);
 return ret;
 }
-
-if (bs-backing_hd-file) {
-pstrcpy(bs-backing_file, sizeof(bs-backing_file),
-bs-backing_hd-file-filename);
-}
+bdrv_set_backing_hd(bs, backing_hd);
 
 /* Recalculate the BlockLimits with the backing file */
 bdrv_refresh_limits(bs);
@@ -1944,12 +1960,7 @@ void bdrv_append(BlockDriverState *bs_new, 
BlockDriverState *bs_top)
 
 /* The contents of 'tmp' will become bs_top, as we are
  * swapping bs_new and bs_top contents. */
-bs_top-backing_hd = bs_new;
-bs_top-open_flags = ~BDRV_O_NO_BACKING;
-pstrcpy(bs_top-backing_file, sizeof(bs_top-backing_file),
-bs_new-filename);
-pstrcpy(bs_top-backing_format, sizeof(bs_top-backing_format),
-bs_new-drv ? bs_new-drv-format_name : );
+bdrv_set_backing_hd(bs_top, bs_new);
 }
 
 static void bdrv_delete(BlockDriverState *bs)
diff --git a/include/block/block.h b/include/block/block.h
index a46f70a..ee1582d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -208,6 +208,7 @@ int bdrv_parse_discard_flags(const char *mode, int *flags);
 int bdrv_open_image(BlockDriverState **pbs, const char *filename,
 QDict *options, const char *bdref_key, int flags,
 bool allow_none, Error **errp);
+void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
 int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
   const char *reference, QDict *options, int flags,
-- 
1.9.0




[Qemu-devel] [PATCH v17 02/14] block: Introduce op_blockers to BlockDriverState

2014-03-10 Thread Fam Zheng
BlockDriverState.op_blockers is an array of lists with BLOCK_OP_TYPE_MAX
elements. Each list is a list of blockers of an operation type
(BlockOpType), that marks this BDS as currently blocked for a certain
type of operation with reason errors stored in the list. The rule of
usage is:

 * BDS user who wants to take an operation should check if there's any
   blocker of the type with bdrv_op_is_blocked().

 * BDS user who wants to block certain types of operation, should call
   bdrv_op_block (or bdrv_op_block_all to block all types of operations,
   which is similar to the existing bdrv_set_in_use()).

 * A blocker is only referenced by op_blockers, so the lifecycle is
   managed by caller, and shouldn't be lost until unblock, so typically
   a caller does these:

   - Allocate a blocker with error_setg or similar, call bdrv_op_block()
 to block some operations.
   - Hold the blocker, do his job.
   - Unblock operations that it blocked, with the same reason pointer
 passed to bdrv_op_unblock().
   - Release the blocker with error_free().

Signed-off-by: Fam Zheng f...@redhat.com
Reviewed-by: Benoit Canet ben...@irqsave.net
---
 block.c   | 75 +++
 include/block/block.h |  7 +
 include/block/block_int.h |  5 
 3 files changed, 87 insertions(+)

diff --git a/block.c b/block.c
index f1ef4b0..56a4433 100644
--- a/block.c
+++ b/block.c
@@ -335,6 +335,7 @@ void bdrv_register(BlockDriver *bdrv)
 BlockDriverState *bdrv_new(const char *device_name)
 {
 BlockDriverState *bs;
+int i;
 
 bs = g_malloc0(sizeof(BlockDriverState));
 QLIST_INIT(bs-dirty_bitmaps);
@@ -342,6 +343,9 @@ BlockDriverState *bdrv_new(const char *device_name)
 if (device_name[0] != '\0') {
 QTAILQ_INSERT_TAIL(bdrv_states, bs, device_list);
 }
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+QLIST_INIT(bs-op_blockers[i]);
+}
 bdrv_iostatus_disable(bs);
 notifier_list_init(bs-close_notifiers);
 notifier_with_return_list_init(bs-before_write_notifiers);
@@ -1853,6 +1857,8 @@ static void bdrv_move_feature_fields(BlockDriverState 
*bs_dest,
 pstrcpy(bs_dest-device_name, sizeof(bs_dest-device_name),
 bs_src-device_name);
 bs_dest-device_list = bs_src-device_list;
+memcpy(bs_dest-op_blockers, bs_src-op_blockers,
+   sizeof(bs_dest-op_blockers));
 }
 
 /*
@@ -5151,6 +5157,75 @@ void bdrv_unref(BlockDriverState *bs)
 }
 }
 
+struct BdrvOpBlocker {
+Error *reason;
+QLIST_ENTRY(BdrvOpBlocker) list;
+};
+
+bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
+{
+BdrvOpBlocker *blocker;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+if (!QLIST_EMPTY(bs-op_blockers[op])) {
+blocker = QLIST_FIRST(bs-op_blockers[op]);
+if (errp) {
+*errp = error_copy(blocker-reason);
+}
+return true;
+}
+return false;
+}
+
+void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason)
+{
+BdrvOpBlocker *blocker;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+
+blocker = g_malloc0(sizeof(BdrvOpBlocker));
+blocker-reason = reason;
+QLIST_INSERT_HEAD(bs-op_blockers[op], blocker, list);
+}
+
+void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason)
+{
+BdrvOpBlocker *blocker, *next;
+assert((int) op = 0  op  BLOCK_OP_TYPE_MAX);
+QLIST_FOREACH_SAFE(blocker, bs-op_blockers[op], list, next) {
+if (blocker-reason == reason) {
+QLIST_REMOVE(blocker, list);
+g_free(blocker);
+}
+}
+}
+
+void bdrv_op_block_all(BlockDriverState *bs, Error *reason)
+{
+int i;
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+bdrv_op_block(bs, i, reason);
+}
+}
+
+void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason)
+{
+int i;
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+bdrv_op_unblock(bs, i, reason);
+}
+}
+
+bool bdrv_op_blocker_is_empty(BlockDriverState *bs)
+{
+int i;
+
+for (i = 0; i  BLOCK_OP_TYPE_MAX; i++) {
+if (!QLIST_EMPTY(bs-op_blockers[i])) {
+return false;
+}
+}
+return true;
+}
+
 void bdrv_set_in_use(BlockDriverState *bs, int in_use)
 {
 assert(bs-in_use != in_use);
diff --git a/include/block/block.h b/include/block/block.h
index 8820735..4874e2a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -474,6 +474,13 @@ void bdrv_unref(BlockDriverState *bs);
 void bdrv_set_in_use(BlockDriverState *bs, int in_use);
 int bdrv_in_use(BlockDriverState *bs);
 
+bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
+void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
+void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason);
+void bdrv_op_block_all(BlockDriverState *bs, Error *reason);
+void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason);
+bool 

[Qemu-devel] [PATCH v17 09/14] stream: Use bdrv_drop_intermediate and drop close_unused_images

2014-03-10 Thread Fam Zheng
This reuses the new bdrv_drop_intermediate.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/stream.c | 42 +-
 1 file changed, 1 insertion(+), 41 deletions(-)

diff --git a/block/stream.c b/block/stream.c
index dd0b4ac..1b348a2 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -32,7 +32,6 @@ typedef struct StreamBlockJob {
 RateLimit limit;
 BlockDriverState *base;
 BlockdevOnError on_error;
-char backing_file_id[1024];
 } StreamBlockJob;
 
 static int coroutine_fn stream_populate(BlockDriverState *bs,
@@ -51,34 +50,6 @@ static int coroutine_fn stream_populate(BlockDriverState *bs,
 return bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, qiov);
 }
 
-static void close_unused_images(BlockDriverState *top, BlockDriverState *base,
-const char *base_id)
-{
-BlockDriverState *intermediate;
-intermediate = top-backing_hd;
-
-/* Must assign before bdrv_delete() to prevent traversing dangling pointer
- * while we delete backing image instances.
- */
-top-backing_hd = base;
-
-while (intermediate) {
-BlockDriverState *unused;
-
-/* reached base */
-if (intermediate == base) {
-break;
-}
-
-unused = intermediate;
-intermediate = intermediate-backing_hd;
-unused-backing_hd = NULL;
-bdrv_unref(unused);
-}
-
-bdrv_refresh_limits(top);
-}
-
 static void coroutine_fn stream_run(void *opaque)
 {
 StreamBlockJob *s = opaque;
@@ -184,15 +155,7 @@ wait:
 ret = error;
 
 if (!block_job_is_cancelled(s-common)  sector_num == end  ret == 0) {
-const char *base_id = NULL, *base_fmt = NULL;
-if (base) {
-base_id = s-backing_file_id;
-if (base-drv) {
-base_fmt = base-drv-format_name;
-}
-}
-ret = bdrv_change_backing_file(bs, base_id, base_fmt);
-close_unused_images(bs, base, base_id);
+ret = bdrv_drop_intermediate(bs, bs-backing_hd, base);
 }
 
 qemu_vfree(buf);
@@ -237,9 +200,6 @@ void stream_start(BlockDriverState *bs, BlockDriverState 
*base,
 }
 
 s-base = base;
-if (base_id) {
-pstrcpy(s-backing_file_id, sizeof(s-backing_file_id), base_id);
-}
 
 s-on_error = on_error;
 s-common.co = qemu_coroutine_create(stream_run);
-- 
1.9.0




Re: [Qemu-devel] sdl mouse no longer works

2014-03-10 Thread Gerd Hoffmann
On Sa, 2014-03-08 at 20:56 -0500, Gabriel L. Somlo wrote:
 Gerd,
 
 After the latest pull, my sdl mouse no longer works. I've tried with
 both OS X and Fedora 20 live. The latter (easier command line with
 no out of tree dependencies) is started with the following command line:
 
 bin/qemu-system-x86_64 -enable-kvm -m 2048 -machine q35 \
 -usb -device usb-kbd -device usb-mouse \
 -device ide-drive,bus=ide.2,drive=HDD \
 -drive 
 id=HDD,if=none,snapshot=on,file=Fedora-Live-Desktop-x86_64-20-1.iso \
 -monitor stdio
 
 After a git bisect I tracked it down to commit
 3ab193e66262e60e0ff74ac1ab5cff04412e83cb (mouse: switch sdl ui to new
 core).
 
 Is my command line deprecated, or am I tickling some sort of bug ?

More likely a bug, I'll go dig ...

cheers,
  Gerd





[Qemu-devel] [PATCH v17 12/14] block: Add blockdev-backup to transaction

2014-03-10 Thread Fam Zheng
Signed-off-by: Fam Zheng f...@redhat.com
---
 blockdev.c   | 48 
 qapi-schema.json |  1 +
 2 files changed, 49 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index f241455..8a6ae0a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1409,6 +1409,49 @@ static void drive_backup_abort(BlkTransactionState 
*common)
 }
 }
 
+typedef struct BlockdevBackupState {
+BlkTransactionState common;
+BlockDriverState *bs;
+BlockJob *job;
+} BlockdevBackupState;
+
+static void blockdev_backup_prepare(BlkTransactionState *common, Error **errp)
+{
+BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, 
common);
+BlockdevBackup *backup;
+Error *local_err = NULL;
+
+assert(common-action-kind == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
+backup = common-action-blockdev_backup;
+
+qmp_blockdev_backup(backup-device, backup-target,
+backup-sync,
+backup-has_speed, backup-speed,
+backup-has_on_source_error, backup-on_source_error,
+backup-has_on_target_error, backup-on_target_error,
+local_err);
+if (error_is_set(local_err)) {
+error_propagate(errp, local_err);
+state-bs = NULL;
+state-job = NULL;
+return;
+}
+
+state-bs = bdrv_find(backup-device);
+state-job = state-bs-job;
+}
+
+static void blockdev_backup_abort(BlkTransactionState *common)
+{
+BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, 
common);
+BlockDriverState *bs = state-bs;
+
+/* Only cancel if it's the job we started */
+if (bs  bs-job  bs-job == state-job) {
+block_job_cancel_sync(bs-job);
+}
+}
+
 static void abort_prepare(BlkTransactionState *common, Error **errp)
 {
 error_setg(errp, Transaction aborted using Abort action);
@@ -1431,6 +1474,11 @@ static const BdrvActionOps actions[] = {
 .prepare = drive_backup_prepare,
 .abort = drive_backup_abort,
 },
+[TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP] = {
+.instance_size = sizeof(BlockdevBackupState),
+.prepare = blockdev_backup_prepare,
+.abort = blockdev_backup_abort,
+},
 [TRANSACTION_ACTION_KIND_ABORT] = {
 .instance_size = sizeof(BlkTransactionState),
 .prepare = abort_prepare,
diff --git a/qapi-schema.json b/qapi-schema.json
index acff31a..6476d4a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1972,6 +1972,7 @@
   'data': {
'blockdev-snapshot-sync': 'BlockdevSnapshot',
'drive-backup': 'DriveBackup',
+   'blockdev-backup': 'BlockdevBackup',
'abort': 'Abort',
'blockdev-snapshot-internal-sync': 'BlockdevSnapshotInternal'
} }
-- 
1.9.0




[Qemu-devel] [PATCH v17 08/14] block: Support dropping active in bdrv_drop_intermediate

2014-03-10 Thread Fam Zheng
Dropping intermediate could be useful both for commit and stream, and
BDS refcnt plus bdrv_swap could do most of the job nicely. It also needs
to work with op blockers.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c| 139 -
 block/commit.c |   2 +-
 2 files changed, 70 insertions(+), 71 deletions(-)

diff --git a/block.c b/block.c
index 05f7766..0af7c62 100644
--- a/block.c
+++ b/block.c
@@ -2503,115 +2503,114 @@ BlockDriverState *bdrv_find_overlay(BlockDriverState 
*active,
 return overlay;
 }
 
-typedef struct BlkIntermediateStates {
-BlockDriverState *bs;
-QSIMPLEQ_ENTRY(BlkIntermediateStates) entry;
-} BlkIntermediateStates;
-
-
 /*
- * Drops images above 'base' up to and including 'top', and sets the image
- * above 'top' to have base as its backing file.
+ * Drops images above 'base' up to and including 'top', and sets new 'base' as
+ * backing_hd of top's overlay (the image orignally has 'top' as backing file).
+ * top's overlay may be NULL if 'top' is active, no such update needed.
+ * Requires that the top's overlay to 'top' is opened r/w.
+ *
+ * 1) This will convert the following chain:
+ *
+ * ... - base - ... - top - overlay -... - active
  *
- * Requires that the overlay to 'top' is opened r/w, so that the backing file
- * information in 'bs' can be properly updated.
+ * to
+ *
+ * ... - base - overlay - active
+ *
+ * 2) It is allowed for bottom==base, in which case it converts:
  *
- * E.g., this will convert the following chain:
- * bottom - base - intermediate - top - active
+ * base - ... - top - overlay - ... - active
  *
  * to
  *
- * bottom - base - active
+ * base - overlay - active
  *
- * It is allowed for bottom==base, in which case it converts:
+ * 2) It also allows active==top, in which case it converts:
  *
- * base - intermediate - top - active
+ * ... - base - ... - top (active)
  *
  * to
  *
- * base - active
+ * ... - base == active == top
+ *
+ * i.e. only base and lower remains: *top == *base when return.
+ *
+ * 3) If base==NULL, it will drop all the BDS below overlay and set its
+ * backing_hd to NULL. I.e.:
  *
- * Error conditions:
- *  if active == top, that is considered an error
+ * base(NULL) - ... - overlay - ... - active
+ *
+ * to
+ *
+ * overlay - ... - active
  *
  */
 int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
BlockDriverState *base)
 {
-BlockDriverState *intermediate;
-BlockDriverState *base_bs = NULL;
-BlockDriverState *new_top_bs = NULL;
-BlkIntermediateStates *intermediate_state, *next;
-int ret = -EIO;
-
-QSIMPLEQ_HEAD(states_to_delete, BlkIntermediateStates) states_to_delete;
-QSIMPLEQ_INIT(states_to_delete);
+BlockDriverState *drop_start, *overlay, *bs;
+int ret = -EINVAL;
 
-if (!top-drv || !base-drv) {
+assert(active);
+assert(top);
+/* Verify that top is in backing chain of active */
+bs = active;
+while (bs  bs != top) {
+bs = bs-backing_hd;
+}
+if (!bs) {
 goto exit;
 }
+/* Verify that base is in backing chain of top */
+if (base) {
+while (bs  bs != base) {
+bs = bs-backing_hd;
+}
+if (bs != base) {
+goto exit;
+}
+}
 
-new_top_bs = bdrv_find_overlay(active, top);
-
-if (new_top_bs == NULL) {
-/* we could not find the image above 'top', this is an error */
+if (!top-drv || (base  !base-drv)) {
 goto exit;
 }
-
-/* special case of new_top_bs-backing_hd already pointing to base - 
nothing
- * to do, no intermediate images */
-if (new_top_bs-backing_hd == base) {
+if (top == base) {
+ret = 0;
+goto exit;
+} else if (top == active) {
+assert(base);
+drop_start = active-backing_hd;
+bdrv_swap(active, base);
+base-backing_hd = NULL;
+bdrv_unref(drop_start);
 ret = 0;
 goto exit;
 }
 
-intermediate = top;
-
-/* now we will go down through the list, and add each BDS we find
- * into our deletion queue, until we hit the 'base'
- */
-while (intermediate) {
-intermediate_state = g_malloc0(sizeof(BlkIntermediateStates));
-intermediate_state-bs = intermediate;
-QSIMPLEQ_INSERT_TAIL(states_to_delete, intermediate_state, entry);
-
-if (intermediate-backing_hd == base) {
-base_bs = intermediate-backing_hd;
-break;
-}
-intermediate = intermediate-backing_hd;
-}
-if (base_bs == NULL) {
-/* something went wrong, we did not end at the base. safely
- * unravel everything, and exit with error */
+overlay = bdrv_find_overlay(active, top);
+if (!overlay) {
 goto exit;
 }
-
-/* success - we can delete the intermediate states, and link top-base */
-ret = 

[Qemu-devel] [PATCH v17 14/14] qemu-iotests: Image fleecing test case 083

2014-03-10 Thread Fam Zheng
This tests the workflow of creating a lightweight point-in-time snapshot
with blockdev-backup command and export it with built-in NBD server.

It's tested that after the snapshot it created, writing to the original
device doesn't change data that can be read from target with NBD.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/083 | 99 ++
 tests/qemu-iotests/083.out |  5 +++
 tests/qemu-iotests/group   |  1 +
 3 files changed, 105 insertions(+)
 create mode 100755 tests/qemu-iotests/083
 create mode 100644 tests/qemu-iotests/083.out

diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083
new file mode 100755
index 000..8be32d7
--- /dev/null
+++ b/tests/qemu-iotests/083
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+#
+# Tests for image fleecing (point in time snapshot export to NBD)
+#
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# Based on 055.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img, qemu_io
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+target_img = os.path.join(iotests.test_dir, 'target.img')
+nbd_sock = os.path.join(iotests.test_dir, 'nbd.sock')
+
+class TestImageFleecing(iotests.QMPTestCase):
+image_len = 64 * 1024 * 1024 # MB
+
+def setUp(self):
+# Write data to the image so we can compare later
+qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestImageFleecing.image_len))
+self.patterns = [
+(0x5d, 0, 64k),
+(0xd5, 1M, 64k),
+(0xdc, 32M, 64k),
+(0xdc, 67043328, 64k)]
+
+for p in self.patterns:
+qemu_io('-c', 'write -P%s %s %s' % p, test_img)
+
+qemu_img('create', '-f', iotests.imgfmt, target_img, 
str(TestImageFleecing.image_len))
+
+self.vm = iotests.VM().add_drive(test_img)
+self.vm.launch()
+
+self.overwrite_patterns = [
+(0xa0, 0, 64k),
+(0x0a, 1M, 64k),
+(0x55, 32M, 64k),
+(0x56, 67043328, 64k)]
+
+self.nbd_uri = nbd+unix:///drive1?socket=%s % nbd_sock
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(test_img)
+os.remove(target_img)
+
+def verify_patterns(self):
+for p in self.patterns:
+self.assertEqual(-1, qemu_io(self.nbd_uri, '-c', 'read -P%s %s %s' 
% p).find(verification failed),
+ Failed to verify pattern: %s %s %s % p)
+
+def test_image_fleecing(self):
+result = self.vm.qmp(blockdev-add, **{options: {
+driver: qcow2,
+id: drive1,
+file: {
+driver: file,
+filename: target_img,
+},
+backing: drive0,
+}})
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(nbd-server-start, **{addr: { type: unix, 
data: { path: nbd_sock } } })
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(blockdev-backup, device=drive0, 
target=drive1, sync=none)
+self.assert_qmp(result, 'return', {})
+result = self.vm.qmp(nbd-server-add, device=drive1)
+self.assert_qmp(result, 'return', {})
+
+self.verify_patterns()
+
+for p in self.overwrite_patterns:
+self.vm.hmp_qemu_io(drive0, write -P%s %s %s % p)
+
+self.verify_patterns()
+
+self.cancel_and_wait(resume=True)
+self.assert_no_active_block_jobs()
+
+if __name__ == '__main__':
+iotests.main(supported_fmts=['raw', 'qcow2'])
diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out
new file mode 100644
index 000..ae1213e
--- /dev/null
+++ b/tests/qemu-iotests/083.out
@@ -0,0 +1,5 @@
+.
+--
+Ran 1 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index e96eafd..b96c6bc 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -85,6 +85,7 @@
 079 rw auto
 081 rw auto
 082 rw auto quick
+083 rw auto quick
 085 rw auto quick
 086 rw auto quick
 087 rw auto quick
-- 
1.9.0




[Qemu-devel] [PATCH v22 08/25] cow.c: replace QEMUOptionParameter with QemuOpts

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/cow.c | 54 ++
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/block/cow.c b/block/cow.c
index 26cf4a5..4085201 100644
--- a/block/cow.c
+++ b/block/cow.c
@@ -324,31 +324,24 @@ 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 *opts, Error **errp)
 {
 struct cow_header_v2 cow_header;
 struct stat st;
 int64_t image_sectors = 0;
-const char *image_filename = NULL;
+char *image_filename = NULL;
 Error *local_err = NULL;
 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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+image_filename = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
 
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
-return ret;
+goto exit;
 }
 
 cow_bs = NULL;
@@ -356,7 +349,7 @@ static int cow_create(const char *filename, 
QEMUOptionParameter *options,
 BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
-return ret;
+goto exit;
 }
 
 memset(cow_header, 0, sizeof(cow_header));
@@ -389,22 +382,27 @@ static int cow_create(const char *filename, 
QEMUOptionParameter *options,
 }
 
 exit:
+g_free(image_filename);
 bdrv_unref(cow_bs);
 return ret;
 }
 
-static QEMUOptionParameter cow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = File name of a base image
-},
-{ NULL }
+static QemuOptsList cow_create_opts = {
+.name = cow-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(cow_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = File name of a base image
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_cow = {
@@ -414,14 +412,14 @@ static BlockDriver bdrv_cow = {
 .bdrv_probe = cow_probe,
 .bdrv_open  = cow_open,
 .bdrv_close = cow_close,
-.bdrv_create= cow_create,
+.bdrv_create2   = cow_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_read  = cow_co_read,
 .bdrv_write = cow_co_write,
 .bdrv_co_get_block_status   = cow_co_get_block_status,
 
-.create_options = cow_create_options,
+.create_opts   = cow_create_opts,
 };
 
 static void bdrv_cow_init(void)
-- 
1.7.12.4




[Qemu-devel] [PATCH v17 10/14] qmp: Add command 'blockdev-backup'

2014-03-10 Thread Fam Zheng
Similar to drive-backup, but this command uses a device id as target
instead of creating/opening an image file.

Also add blocker on target bs, since the target is also a named device
now.

Add check and report error for bs == target which became possible but is
an illegal case with introduction of blockdev-backup.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/backup.c   | 26 ++
 blockdev.c   | 47 +++
 qapi-schema.json | 49 +
 qmp-commands.hx  | 44 
 4 files changed, 166 insertions(+)

diff --git a/block/backup.c b/block/backup.c
index 15a2e55..ea46340 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -344,6 +344,7 @@ static void coroutine_fn backup_run(void *opaque)
 hbitmap_free(job-bitmap);
 
 bdrv_iostatus_disable(target);
+bdrv_op_unblock_all(target, job-common.blocker);
 bdrv_unref(target);
 
 block_job_completed(job-common, ret);
@@ -362,6 +363,11 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 assert(target);
 assert(cb);
 
+if (bs == target) {
+error_setg(errp, Source and target cannot be the same);
+return;
+}
+
 if ((on_source_error == BLOCKDEV_ON_ERROR_STOP ||
  on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) 
 !bdrv_iostatus_is_enabled(bs)) {
@@ -369,6 +375,24 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 return;
 }
 
+if (!bdrv_is_inserted(bs)) {
+error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, bs-device_name);
+return;
+}
+
+if (!bdrv_is_inserted(target)) {
+error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, target-device_name);
+return;
+}
+
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
+return;
+}
+
+if (bdrv_op_is_blocked(target, BLOCK_OP_TYPE_BACKUP_TARGET, errp)) {
+return;
+}
+
 len = bdrv_getlength(bs);
 if (len  0) {
 error_setg_errno(errp, -len, unable to get length for '%s',
@@ -382,6 +406,8 @@ void backup_start(BlockDriverState *bs, BlockDriverState 
*target,
 return;
 }
 
+bdrv_op_block_all(target, job-common.blocker);
+
 job-on_source_error = on_source_error;
 job-on_target_error = on_target_error;
 job-target = target;
diff --git a/blockdev.c b/blockdev.c
index d68fd2b..f241455 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1969,6 +1969,8 @@ void qmp_drive_backup(const char *device, const char 
*target,
 return;
 }
 
+/* Although backup_run has this check too, we need to use bs-drv below, so
+ * do an early check redundantly. */
 if (!bdrv_is_inserted(bs)) {
 error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
 return;
@@ -1985,6 +1987,7 @@ void qmp_drive_backup(const char *device, const char 
*target,
 }
 }
 
+/* Early check to avoid creating target */
 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
 return;
 }
@@ -2047,6 +2050,50 @@ BlockDeviceInfoList *qmp_query_named_block_nodes(Error 
**errp)
 return bdrv_named_nodes_list();
 }
 
+void qmp_blockdev_backup(const char *device, const char *target,
+ enum MirrorSyncMode sync,
+ bool has_speed, int64_t speed,
+ bool has_on_source_error,
+ BlockdevOnError on_source_error,
+ bool has_on_target_error,
+ BlockdevOnError on_target_error,
+ Error **errp)
+{
+BlockDriverState *bs;
+BlockDriverState *target_bs;
+Error *local_err = NULL;
+
+if (!has_speed) {
+speed = 0;
+}
+if (!has_on_source_error) {
+on_source_error = BLOCKDEV_ON_ERROR_REPORT;
+}
+if (!has_on_target_error) {
+on_target_error = BLOCKDEV_ON_ERROR_REPORT;
+}
+
+bs = bdrv_find(device);
+if (!bs) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+return;
+}
+
+target_bs = bdrv_find(target);
+if (!target_bs) {
+error_set(errp, QERR_DEVICE_NOT_FOUND, target);
+return;
+}
+
+bdrv_ref(target_bs);
+backup_start(bs, target_bs, speed, sync, on_source_error, on_target_error,
+ block_job_cb, bs, local_err);
+if (local_err != NULL) {
+bdrv_unref(target_bs);
+error_propagate(errp, local_err);
+}
+}
+
 #define DEFAULT_MIRROR_BUF_SIZE   (10  20)
 
 void qmp_drive_mirror(const char *device, const char *target,
diff --git a/qapi-schema.json b/qapi-schema.json
index 6c381b7..acff31a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1919,6 +1919,40 @@
 '*on-target-error': 'BlockdevOnError' } }
 
 ##
+# @BlockdevBackup
+#
+# @device: the name of the device which should be copied.
+#
+# @target: the name of the backup target 

[Qemu-devel] [PATCH v17 11/14] block: Allow backup on referenced named BlockDriverState

2014-03-10 Thread Fam Zheng
Drive backup is a read only operation on source bs. We want to allow
this specific case to enable image-fleecing. Note that when
image-fleecing job starts, the job still add its blocker to source bs,
and any other operation on it will be blocked by that.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/block.c b/block.c
index 0af7c62..9f2fe85 100644
--- a/block.c
+++ b/block.c
@@ -1077,6 +1077,8 @@ void bdrv_set_backing_hd(BlockDriverState *bs, 
BlockDriverState *backing_hd)
 /* Otherwise we won't be able to commit due to check in bdrv_commit */
 bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_COMMIT,
 bs-backing_blocker);
+bdrv_op_unblock(bs-backing_hd, BLOCK_OP_TYPE_BACKUP_SOURCE,
+bs-backing_blocker);
 out:
 bdrv_refresh_limits(bs);
 }
-- 
1.9.0




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

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

---
Changes to v21:
  * update verison info in patch 2/25
  * others are not changed except for rebase

Chunyan Liu (25):
  add def_value_str to QemuOptDesc
  qapi: output def_value_str when query command line options
  improve some functions in qemu-option.c
  improve assertion in qemu_opt_get functions
  add some QemuOpts functions for replace work
  add convert functions between QEMUOptionParameter to QemuOpts
  change block layer to support both QemuOpts and QEMUOptionParamter
  cow.c: replace QEMUOptionParameter with QemuOpts
  gluster.c: replace QEMUOptionParameter with QemuOpts
  iscsi.c: replace QEMUOptionParameter with QemuOpts
  qcow.c: replace QEMUOptionParameter with QemuOpts
  qcow2.c: replace QEMUOptionParameter with QemuOpts
  qed.c: replace QEMUOptionParameter with QemuOpts
  raw-posix.c: replace QEMUOptionParameter with QemuOpts
  raw-win32.c: replace QEMUOptionParameter with QemuOpts
  raw_bsd.c: replace QEMUOptionParameter with QemuOpts
  rbd.c: replace QEMUOptionParameter with QemuOpts
  sheepdog.c: replace QEMUOptionParameter with QemuOpts
  ssh.c: replace QEMUOptionParameter with QemuOpts
  vdi.c: replace QEMUOptionParameter with QemuOpts
  vmdk.c: replace QEMUOptionParameter with QemuOpts
  vpc.c: replace QEMUOptionParameter with QemuOpts
  vhdx.c: replace QEMUOptionParameter with QemuOpts
  vvfat.c: replace QEMUOptionParameter with QemuOpts
  cleanup QEMUOptionParameter

 block.c   |  96 
 block/cow.c   |  52 ++---
 block/gluster.c   |  73 +++---
 block/iscsi.c |  29 ++-
 block/qcow.c  |  72 +++---
 block/qcow2.c | 325 +-
 block/qed.c   | 112 -
 block/qed.h   |   3 +-
 block/raw-posix.c |  55 ++---
 block/raw-win32.c |  38 +--
 block/raw_bsd.c   |  25 +-
 block/rbd.c   |  61 +++--
 block/sheepdog.c  | 102 
 block/ssh.c   |  30 ++-
 block/vdi.c   |  70 +++---
 block/vhdx.c  |  97 
 block/vhdx.h  |   1 +
 block/vmdk.c  | 121 +-
 block/vpc.c   |  60 ++---
 block/vvfat.c |  10 +-
 include/block/block.h |   7 +-
 include/block/block_int.h |   9 +-
 include/qemu/option.h |  56 +
 include/qemu/option_int.h |   4 +-
 qapi-schema.json  |   6 +-
 qemu-img.c|  89 ---
 qmp-commands.hx   |   2 +
 util/qemu-config.c|   4 +
 util/qemu-option.c| 576 ++
 29 files changed, 1060 insertions(+), 1125 deletions(-)

-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/sheepdog.c | 108 ---
 1 file changed, 55 insertions(+), 53 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index f7bd024..027a34e 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1626,12 +1626,13 @@ static int parse_redundancy(BDRVSheepdogState *s, const 
char *opt)
 return 0;
 }
 
-static int sd_create(const char *filename, QEMUOptionParameter *options,
+static int sd_create(const char *filename, QemuOpts *opts,
  Error **errp)
 {
 int ret = 0;
 uint32_t vid = 0;
 char *backing_file = NULL;
+char *buf = NULL;
 BDRVSheepdogState *s;
 char tag[SD_MAX_VDI_TAG_LEN];
 uint32_t snapid;
@@ -1650,31 +1651,26 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options,
 goto out;
 }
 
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-s-inode.vdi_size = options-value.n;
-} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) {
-if (!options-value.s || !strcmp(options-value.s, off)) {
-prealloc = false;
-} else if (!strcmp(options-value.s, full)) {
-prealloc = true;
-} else {
-error_report(Invalid preallocation mode: '%s',
- options-value.s);
-ret = -EINVAL;
-goto out;
-}
-} else if (!strcmp(options-name, BLOCK_OPT_REDUNDANCY)) {
-if (options-value.s) {
-ret = parse_redundancy(s, options-value.s);
-if (ret  0) {
-goto out;
-}
-}
+s-inode.vdi_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+if (!buf || !strcmp(buf, off)) {
+prealloc = false;
+} else if (!strcmp(buf, full)) {
+prealloc = true;
+} else {
+error_report(Invalid preallocation mode: '%s', buf);
+ret = -EINVAL;
+goto out;
+}
+
+g_free(buf);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_REDUNDANCY);
+if (buf) {
+ret = parse_redundancy(s, buf);
+if (ret  0) {
+goto out;
 }
-options++;
 }
 
 if (s-inode.vdi_size  SD_MAX_VDI_SIZE) {
@@ -1724,6 +1720,8 @@ static int sd_create(const char *filename, 
QEMUOptionParameter *options,
 
 ret = sd_prealloc(filename);
 out:
+g_free(backing_file);
+g_free(buf);
 g_free(s);
 return ret;
 }
@@ -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
-},
-{ NULL }
+static QemuOptsList sd_create_opts = {
+.name = sheepdog-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(sd_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = File name of a base image
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = QEMU_OPT_STRING,
+.help = Preallocation mode (allowed values: off, full)
+},
+{
+.name = BLOCK_OPT_REDUNDANCY,
+.type = QEMU_OPT_STRING,
+.help = Redundancy of the image
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_sheepdog = {
@@ -2521,7 +2523,7 @@ static BlockDriver bdrv_sheepdog = {
 .bdrv_needs_filename = true,
 .bdrv_file_open = sd_open,
 .bdrv_close = sd_close,
-.bdrv_create= sd_create,
+.bdrv_create2   = sd_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_getlength = sd_getlength,
 .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
@@ -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_opts= sd_create_opts,
 

[Qemu-devel] [PATCH v22 09/25] gluster.c: replace QEMUOptionParameter with QemuOpts

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/gluster.c | 81 ++---
 1 file changed, 42 insertions(+), 39 deletions(-)

diff --git a/block/gluster.c b/block/gluster.c
index a44d612..bd72d8d 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -471,13 +471,14 @@ static inline int qemu_gluster_zerofill(struct glfs_fd 
*fd, int64_t offset,
 #endif
 
 static int qemu_gluster_create(const char *filename,
-QEMUOptionParameter *options, Error **errp)
+   QemuOpts *opts, Error **errp)
 {
 struct glfs *glfs;
 struct glfs_fd *fd;
 int ret = 0;
 int prealloc = 0;
 int64_t total_size = 0;
+char *tmp;
 GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
 
 glfs = qemu_gluster_init(gconf, filename, errp);
@@ -486,24 +487,21 @@ static int qemu_gluster_create(const char *filename,
 goto out;
 }
 
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-total_size = options-value.n / BDRV_SECTOR_SIZE;
-} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) {
-if (!options-value.s || !strcmp(options-value.s, off)) {
-prealloc = 0;
-} else if (!strcmp(options-value.s, full) 
-gluster_supports_zerofill()) {
-prealloc = 1;
-} else {
-error_setg(errp, Invalid preallocation mode: '%s'
- or GlusterFS doesn't support zerofill API,
-   options-value.s);
-ret = -EINVAL;
-goto out;
-}
-}
-options++;
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+
+tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+if (!tmp || !strcmp(tmp, off)) {
+prealloc = 0;
+} else if (!strcmp(tmp, full) 
+   gluster_supports_zerofill()) {
+prealloc = 1;
+} else {
+error_setg(errp, Invalid preallocation mode: '%s'
+ or GlusterFS doesn't support zerofill API,
+tmp);
+ret = -EINVAL;
+goto out;
 }
 
 fd = glfs_creat(glfs, gconf-image,
@@ -525,6 +523,7 @@ static int qemu_gluster_create(const char *filename,
 }
 }
 out:
+g_free(tmp);
 qemu_gluster_gconf_free(gconf);
 if (glfs) {
 glfs_fini(glfs);
@@ -688,18 +687,22 @@ static int qemu_gluster_has_zero_init(BlockDriverState 
*bs)
 return 0;
 }
 
-static QEMUOptionParameter qemu_gluster_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{
-.name = BLOCK_OPT_PREALLOC,
-.type = OPT_STRING,
-.help = Preallocation mode (allowed values: off, full)
-},
-{ NULL }
+static QemuOptsList qemu_gluster_create_opts = {
+.name = qemu-gluster-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_gluster_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_PREALLOC,
+.type = OPT_STRING,
+.help = Preallocation mode (allowed values: off, full)
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_gluster = {
@@ -712,7 +715,7 @@ static BlockDriver bdrv_gluster = {
 .bdrv_reopen_commit   = qemu_gluster_reopen_commit,
 .bdrv_reopen_abort= qemu_gluster_reopen_abort,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create  = qemu_gluster_create,
+.bdrv_create2 = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -726,7 +729,7 @@ static BlockDriver bdrv_gluster = {
 #ifdef CONFIG_GLUSTERFS_ZEROFILL
 .bdrv_co_write_zeroes = qemu_gluster_co_write_zeroes,
 #endif
-.create_options   = qemu_gluster_create_options,
+.create_opts  = qemu_gluster_create_opts,
 };
 
 static BlockDriver bdrv_gluster_tcp = {
@@ -739,7 +742,7 @@ static BlockDriver bdrv_gluster_tcp = {
 .bdrv_reopen_commit   = qemu_gluster_reopen_commit,
 .bdrv_reopen_abort= qemu_gluster_reopen_abort,
 .bdrv_close   = qemu_gluster_close,
-.bdrv_create  = qemu_gluster_create,
+.bdrv_create2 = qemu_gluster_create,
 .bdrv_getlength   = qemu_gluster_getlength,
 .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
 .bdrv_truncate= qemu_gluster_truncate,
@@ -753,7 +756,7 @@ static BlockDriver bdrv_gluster_tcp = {
 

[Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work

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

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/qemu/option.h |   9 +++
 util/qemu-option.c| 188 ++
 2 files changed, 184 insertions(+), 13 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index c3b0a91..de4912a 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -111,6 +111,7 @@ struct QemuOptsList {
 };
 
 const char *qemu_opt_get(QemuOpts *opts, const char *name);
+char *qemu_opt_get_del(QemuOpts *opts, const char *name);
 /**
  * qemu_opt_has_help_opt:
  * @opts: options to search for a help request
@@ -126,6 +127,11 @@ bool qemu_opt_has_help_opt(QemuOpts *opts);
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t 
defval);
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
+bool qemu_opt_get_bool_del(QemuOpts *opts, const char *name, bool defval);
+uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name,
+ uint64_t defval);
+uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name,
+   uint64_t defval);
 int qemu_opt_unset(QemuOpts *opts, const char *name);
 int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
 void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
@@ -161,4 +167,7 @@ void qemu_opts_print(QemuOpts *opts);
 int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void 
*opaque,
   int abort_on_failure);
 
+QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
+void qemu_opts_free(QemuOptsList *list);
+void qemu_opts_print_help(QemuOptsList *list);
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index df79235..2c450e0 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -35,6 +35,7 @@
 
 static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
 const char *name);
+static void qemu_opt_del(QemuOpt *opt);
 
 /*
  * Extracts the name of an option from the parameter string (p points at the
@@ -379,6 +380,74 @@ QEMUOptionParameter 
*append_option_parameters(QEMUOptionParameter *dest,
 return dest;
 }
 
+static size_t count_opts_list(QemuOptsList *list)
+{
+QemuOptDesc *desc = NULL;
+size_t num_opts = 0;
+
+if (!list) {
+return 0;
+}
+
+desc = list-desc;
+while (desc  desc-name) {
+num_opts++;
+desc++;
+}
+
+return num_opts;
+}
+
+/* Create a new QemuOptsList with a desc of the merge of the first
+ * and second. It will allocate space for one new QemuOptsList plus
+ * enough space for QemuOptDesc in first and second QemuOptsList.
+ * First argument's QemuOptDesc members take precedence over second's.
+ * The result's name and implied_opt_name are not copied from them.
+ * Both merge_lists should not be set. Both lists can be NULL.
+ */
+QemuOptsList *qemu_opts_append(QemuOptsList *dst,
+   QemuOptsList *list)
+{
+size_t num_opts, num_dst_opts;
+QemuOptsList *tmp;
+QemuOptDesc *desc;
+
+if (!dst  !list) {
+return NULL;
+}
+
+num_opts = count_opts_list(dst);
+num_opts += count_opts_list(list);
+tmp = g_malloc0(sizeof(QemuOptsList) +
+(num_opts + 1) * sizeof(QemuOptDesc));
+QTAILQ_INIT(tmp-head);
+num_dst_opts = 0;
+
+/* copy dst-desc to new list */
+if (dst) {
+desc = dst-desc;
+while (desc  desc-name) {
+tmp-desc[num_dst_opts++] = *desc;
+tmp-desc[num_dst_opts].name = NULL;
+desc++;
+}
+}
+
+/* add list-desc to new list */
+if (list) {
+desc = list-desc;
+while (desc  desc-name) {
+if (find_desc_by_name(tmp-desc, desc-name) == NULL) {
+tmp-desc[num_dst_opts++] = *desc;
+tmp-desc[num_dst_opts].name = NULL;
+}
+desc++;
+}
+}
+
+return tmp;
+}
+
 /*
  * Parses a parameter string (param) into an option list (dest).
  *
@@ -574,6 +643,29 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
 return opt ? opt-str : NULL;
 }
 
+char *qemu_opt_get_del(QemuOpts *opts, const char *name)
+{
+QemuOpt *opt;
+const QemuOptDesc *desc;
+char *str = NULL;
+
+if (opts == NULL) {
+return NULL;
+}
+
+opt = qemu_opt_find(opts, name);
+if (!opt) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (desc  desc-def_value_str) {
+str = g_strdup(desc-def_value_str);
+}
+return str;
+}
+str = g_strdup(opt-str);
+qemu_opt_del(opt);
+return str;
+}
+
 bool qemu_opt_has_help_opt(QemuOpts 

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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/vdi.c | 72 +
 1 file changed, 34 insertions(+), 38 deletions(-)

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




[Qemu-devel] [PATCH v22 10/25] iscsi.c: replace QEMUOptionParameter with QemuOpts

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/iscsi.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

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




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/vhdx.c | 99 +---
 block/vhdx.h |  1 +
 2 files changed, 48 insertions(+), 52 deletions(-)

diff --git a/block/vhdx.c b/block/vhdx.c
index d8afb42..d90fe55 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 *opts, Error **errp)
 {
 int ret = 0;
 uint64_t image_size = (uint64_t) 2 * GiB;
@@ -1722,24 +1721,15 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 gunichar2 *creator = NULL;
 glong creator_items;
 BlockDriverState *bs;
-const char *type = NULL;
+char *type = NULL;
 VHDXImageType image_type;
 Error *local_err = NULL;
 
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-image_size = options-value.n;
-} else if (!strcmp(options-name, VHDX_BLOCK_OPT_LOG_SIZE)) {
-log_size = options-value.n;
-} else if (!strcmp(options-name, VHDX_BLOCK_OPT_BLOCK_SIZE)) {
-block_size = options-value.n;
-} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) {
-type = options-value.s;
-} else if (!strcmp(options-name, VHDX_BLOCK_OPT_ZERO)) {
-use_zero_blocks = options-value.n != 0;
-}
-options++;
-}
+image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+log_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_LOG_SIZE, 0);
+block_size = qemu_opt_get_size_del(opts, VHDX_BLOCK_OPT_BLOCK_SIZE, 0);
+type = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+use_zero_blocks = qemu_opt_get_bool_del(opts, VHDX_BLOCK_OPT_ZERO, false);
 
 if (image_size  VHDX_MAX_IMAGE_SIZE) {
 error_setg_errno(errp, EINVAL, Image size too large; max of 64TB);
@@ -1748,7 +1738,7 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 }
 
 if (type == NULL) {
-type = dynamic;
+type = g_strdup(dynamic);
 }
 
 if (!strcmp(type, dynamic)) {
@@ -1788,7 +1778,7 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 block_size = block_size  VHDX_BLOCK_SIZE_MAX ? VHDX_BLOCK_SIZE_MAX :
 block_size;
 
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
 goto exit;
@@ -1848,6 +1838,7 @@ static int vhdx_create(const char *filename, 
QEMUOptionParameter *options,
 delete_and_exit:
 bdrv_unref(bs);
 exit:
+g_free(type);
 g_free(creator);
 return ret;
 }
@@ -1870,37 +1861,41 @@ static int vhdx_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return 0;
 }
 
-static QEMUOptionParameter vhdx_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size; max of 64TB.
-},
-{
-.name = VHDX_BLOCK_OPT_LOG_SIZE,
-.type = OPT_SIZE,
-.value.n = 1 * MiB,
-.help = Log size; min 1MB.
-},
-{
-.name = VHDX_BLOCK_OPT_BLOCK_SIZE,
-.type = OPT_SIZE,
-.value.n = 0,
-.help = Block Size; min 1MB, max 256MB.  \
-0 means auto-calculate based on image size.
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help = VHDX format type, can be either 'dynamic' or 'fixed'. \
-Default is 'dynamic'.
-},
-{
-.name = VHDX_BLOCK_OPT_ZERO,
-.type = OPT_FLAG,
-.help = Force use of payload blocks of type 'ZERO'.  Non-standard.
-},
-{ NULL }
+static QemuOptsList vhdx_create_opts = {
+.name = vhdx-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(vhdx_create_opts.head),
+.desc = {
+{
+   .name = BLOCK_OPT_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .help = Virtual disk size; max of 64TB.
+   },
+   {
+   .name = VHDX_BLOCK_OPT_LOG_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .def_value_str = stringify(DEFAULT_LOG_SIZE),
+   .help = Log size; min 1MB.
+   },
+   {
+   .name = VHDX_BLOCK_OPT_BLOCK_SIZE,
+   .type = QEMU_OPT_SIZE,
+   .def_value_str = stringify(0),
+   .help = Block Size; min 1MB, max 256MB.  \
+   0 means auto-calculate based on image size.
+   },
+   {
+   .name = BLOCK_OPT_SUBFMT,
+   .type = QEMU_OPT_STRING,
+   .help = VHDX format type, can be either 'dynamic' or 'fixed'. \
+   Default is 'dynamic'.
+   },
+   {
+   .name = 

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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/rbd.c | 63 +
 1 file changed, 30 insertions(+), 33 deletions(-)

diff --git a/block/rbd.c b/block/rbd.c
index dbc79f4..f878877 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -282,8 +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,
-   Error **errp)
+static int qemu_rbd_create(const char *filename, QemuOpts *opts, Error **errp)
 {
 int64_t bytes = 0;
 int64_t objsize;
@@ -306,24 +305,18 @@ static int qemu_rbd_create(const char *filename, 
QEMUOptionParameter *options,
 }
 
 /* Read out options */
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-bytes = options-value.n;
-} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options-value.n) {
-objsize = options-value.n;
-if ((objsize - 1)  objsize) {/* not a power of 2? */
-error_report(obj size needs to be power of 2);
-return -EINVAL;
-}
-if (objsize  4096) {
-error_report(obj size too small);
-return -EINVAL;
-}
-obj_order = ffs(objsize) - 1;
-}
+bytes = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+objsize = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, 0);
+if (objsize) {
+if ((objsize - 1)  objsize) {/* not a power of 2? */
+error_report(obj size needs to be power of 2);
+return -EINVAL;
+}
+if (objsize  4096) {
+error_report(obj size too small);
+return -EINVAL;
 }
-options++;
+obj_order = ffs(objsize) - 1;
 }
 
 clientname = qemu_rbd_parse_clientname(conf, clientname_buf);
@@ -900,18 +893,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
-},
-{NULL}
+static QemuOptsList qemu_rbd_create_opts = {
+.name = rbd-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_rbd_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = RBD object size
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_rbd = {
@@ -920,10 +917,10 @@ static BlockDriver bdrv_rbd = {
 .bdrv_needs_filename = true,
 .bdrv_file_open = qemu_rbd_open,
 .bdrv_close = qemu_rbd_close,
-.bdrv_create= qemu_rbd_create,
+.bdrv_create2   = qemu_rbd_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_get_info  = qemu_rbd_getinfo,
-.create_options = qemu_rbd_create_options,
+.create_opts= qemu_rbd_create_opts,
 .bdrv_getlength = qemu_rbd_getlength,
 .bdrv_truncate  = qemu_rbd_truncate,
 .protocol_name  = rbd,
-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/vpc.c | 62 +
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/block/vpc.c b/block/vpc.c
index 82bf248..ac85514 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 *opts, Error **errp)
 {
 uint8_t buf[1024];
 VHDFooter *footer = (VHDFooter *) buf;
-QEMUOptionParameter *disk_type_param;
+char *disk_type_param;
 int fd, i;
 uint16_t cyls = 0;
 uint8_t heads = 0;
@@ -730,16 +729,16 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 int ret = -EIO;
 
 /* Read out options */
-total_size = get_option_parameter(options, BLOCK_OPT_SIZE)-value.n;
-
-disk_type_param = get_option_parameter(options, BLOCK_OPT_SUBFMT);
-if (disk_type_param  disk_type_param-value.s) {
-if (!strcmp(disk_type_param-value.s, dynamic)) {
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+disk_type_param = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+if (disk_type_param) {
+if (!strcmp(disk_type_param, dynamic)) {
 disk_type = VHD_DYNAMIC;
-} else if (!strcmp(disk_type_param-value.s, fixed)) {
+} else if (!strcmp(disk_type_param, fixed)) {
 disk_type = VHD_FIXED;
 } else {
-return -EINVAL;
+ret = -EINVAL;
+goto out;
 }
 } else {
 disk_type = VHD_DYNAMIC;
@@ -748,7 +747,8 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 /* Create the file */
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
 if (fd  0) {
-return -EIO;
+ret = -EIO;
+goto out;
 }
 
 /*
@@ -813,8 +813,10 @@ static int vpc_create(const char *filename, 
QEMUOptionParameter *options,
 ret = create_fixed_disk(fd, buf, total_size);
 }
 
- fail:
+fail:
 qemu_close(fd);
+out:
+g_free(disk_type_param);
 return ret;
 }
 
@@ -842,20 +844,24 @@ static void vpc_close(BlockDriverState *bs)
 error_free(s-migration_blocker);
 }
 
-static QEMUOptionParameter vpc_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
-Type of virtual hard disk format. Supported formats are 
-{dynamic (default) | fixed} 
-},
-{ NULL }
+static QemuOptsList vpc_create_opts = {
+.name = vpc-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(vpc_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_SUBFMT,
+.type = QEMU_OPT_STRING,
+.help =
+Type of virtual hard disk format. Supported formats are 
+{dynamic (default) | fixed} 
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_vpc = {
@@ -866,14 +872,14 @@ static BlockDriver bdrv_vpc = {
 .bdrv_open  = vpc_open,
 .bdrv_close = vpc_close,
 .bdrv_reopen_prepare= vpc_reopen_prepare,
-.bdrv_create= vpc_create,
+.bdrv_create2   = vpc_create,
 
 .bdrv_read  = vpc_co_read,
 .bdrv_write = vpc_co_write,
 
 .bdrv_get_info  = vpc_get_info,
 
-.create_options = vpc_create_options,
+.create_opts= vpc_create_opts,
 .bdrv_has_zero_init = vpc_has_zero_init,
 };
 
-- 
1.7.12.4




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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/raw-win32.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 9954748..29f8e54 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -475,8 +475,7 @@ 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 *opts, Error **errp)
 {
 int fd;
 int64_t total_size = 0;
@@ -484,12 +483,8 @@ 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 / 512;
-}
-options++;
-}
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -503,13 +498,18 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options,
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{ NULL }
+
+static QemuOptsList raw_create_opts = {
+.name = raw-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_file = {
@@ -518,9 +518,9 @@ static BlockDriver bdrv_file = {
 .instance_size = sizeof(BDRVRawState),
 .bdrv_needs_filename = true,
 .bdrv_parse_filename = raw_parse_filename,
-.bdrv_file_open= raw_open,
-.bdrv_close= raw_close,
-.bdrv_create   = raw_create,
+.bdrv_file_open = raw_open,
+.bdrv_close = raw_close,
+.bdrv_create2   = raw_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_aio_readv = raw_aio_readv,
@@ -532,7 +532,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_opts= raw_create_opts,
 };
 
 /***/
-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/raw_bsd.c | 27 +++
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 9ae5fc2..ee797fd 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -29,13 +29,17 @@
 #include block/block_int.h
 #include qemu/option.h
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{ 0 }
+static QemuOptsList raw_create_opts = {
+.name = raw-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{ /* end of list */ }
+}
 };
 
 static int raw_reopen_prepare(BDRVReopenState *reopen_state,
@@ -139,13 +143,12 @@ 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 *opts, Error **errp)
 {
 Error *local_err = NULL;
 int ret;
 
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 }
@@ -177,7 +180,7 @@ static BlockDriver bdrv_raw = {
 .bdrv_reopen_prepare  = raw_reopen_prepare,
 .bdrv_open= raw_open,
 .bdrv_close   = raw_close,
-.bdrv_create  = raw_create,
+.bdrv_create2 = raw_create,
 .bdrv_co_readv= raw_co_readv,
 .bdrv_co_writev   = raw_co_writev,
 .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -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_opts  = raw_create_opts,
 .bdrv_has_zero_init   = raw_has_zero_init
 };
 
-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/ssh.c | 32 +++-
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index aa63c9d..3a5eead 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
-},
-{ NULL }
+static QemuOptsList ssh_create_opts = {
+.name = ssh-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(ssh_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{ /* end of list */ }
+}
 };
 
-static int ssh_create(const char *filename, QEMUOptionParameter *options,
-  Error **errp)
+static int ssh_create(const char *filename, QemuOpts *opts, Error **errp)
 {
 int r, ret;
 Error *local_err = NULL;
@@ -665,12 +668,7 @@ static int ssh_create(const char *filename, 
QEMUOptionParameter *options,
 ssh_state_init(s);
 
 /* Get desired file size. */
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-total_size = options-value.n;
-}
-options++;
-}
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
 DPRINTF(total_size=% PRIi64, total_size);
 
 uri_options = qdict_new();
@@ -1044,14 +1042,14 @@ static BlockDriver bdrv_ssh = {
 .instance_size= sizeof(BDRVSSHState),
 .bdrv_parse_filename  = ssh_parse_filename,
 .bdrv_file_open   = ssh_file_open,
-.bdrv_create  = ssh_create,
+.bdrv_create2 = ssh_create,
 .bdrv_close   = ssh_close,
 .bdrv_has_zero_init   = ssh_has_zero_init,
 .bdrv_co_readv= ssh_co_readv,
 .bdrv_co_writev   = ssh_co_writev,
 .bdrv_getlength   = ssh_getlength,
 .bdrv_co_flush_to_disk= ssh_co_flush,
-.create_options   = ssh_create_options,
+.create_opts  = ssh_create_opts,
 };
 
 static void bdrv_ssh_init(void)
-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/vvfat.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index ee32b3c..03be65d 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 *opts;
 Error *local_err = NULL;
 int ret;
 int size = sector2cluster(s, s-sector_count);
@@ -2922,11 +2922,11 @@ static int enable_write_target(BDRVVVFATState *s)
 }
 
 bdrv_qcow = bdrv_find_format(qcow);
-options = parse_option_parameters(, bdrv_qcow-create_options, NULL);
-set_option_parameter_int(options, BLOCK_OPT_SIZE, s-sector_count * 512);
-set_option_parameter(options, BLOCK_OPT_BACKING_FILE, fat:);
+opts = qemu_opts_create(bdrv_qcow-create_opts, NULL, 0, error_abort);
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, s-sector_count * 512);
+qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, fat:);
 
-ret = bdrv_create(bdrv_qcow, s-qcow_filename, options, NULL, local_err);
+ret = bdrv_create(bdrv_qcow, s-qcow_filename, NULL, opts, local_err);
 if (ret  0) {
 qerror_report_err(local_err);
 error_free(local_err);
-- 
1.7.12.4




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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





Re: [Qemu-devel] [PATCH qom-cpu v2 09/40] cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook

2014-03-10 Thread Paolo Bonzini

Il 10/03/2014 01:15, Andreas Färber ha scritto:

Note that while such functions may exist both for *-user and softmmu,
only *-user uses the CPUState hook, while softmmu reuses the prototype
for calling it directly.


I'm not sure I understand why you omit the hook for *-softmmu.  It 
doesn't hurt to have it, does it?


Paolo



[Qemu-devel] [PATCH] input: sdl: fix guest_cursor logic.

2014-03-10 Thread Gerd Hoffmann
Unbreaks relative mouse mode with SDL.

Reported-by: Gabriel L. Somlo gso...@gmail.com
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/sdl.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index c1a16be..4e7f920 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -455,13 +455,17 @@ static void sdl_send_mouse_event(int dx, int dy, int x, 
int y, int state)
  real_screen-w);
 qemu_input_queue_abs(dcl-con, INPUT_AXIS_Y, y,
  real_screen-h);
-} else if (guest_cursor) {
-x -= guest_x;
-y -= guest_y;
-guest_x += x;
-guest_y += y;
-qemu_input_queue_rel(dcl-con, INPUT_AXIS_X, x);
-qemu_input_queue_rel(dcl-con, INPUT_AXIS_Y, y);
+} else {
+if (guest_cursor) {
+x -= guest_x;
+y -= guest_y;
+guest_x += x;
+guest_y += y;
+dx = x;
+dy = y;
+}
+qemu_input_queue_rel(dcl-con, INPUT_AXIS_X, dx);
+qemu_input_queue_rel(dcl-con, INPUT_AXIS_Y, dy);
 }
 qemu_input_event_sync();
 }
-- 
1.8.3.1




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

2014-03-10 Thread Chunyan Liu
Change qapi interfaces to output the newly added def_value_str when querying
command line options.

Signed-off-by: Dong Xu Wang address@hidden
Signed-off-by: Chunyan Liu cy...@suse.com
---
 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 6c381b7..f37834e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4059,12 +4059,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 d982cd6..94e8f9f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2856,6 +2856,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.7.12.4




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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





[Qemu-devel] [PATCH] input: map INPUT_BUTTON_WHEEL_{UP, DOWN} to legacy input z axis moves.

2014-03-10 Thread Gerd Hoffmann
Unbreaks mouse wheel.

Reported-by: BALATON Zoltan bala...@eik.bme.hu
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/input-legacy.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index f38984b..7dc486b 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -359,6 +359,20 @@ static void legacy_mouse_event(DeviceState *dev, 
QemuConsole *src,
 } else {
 s-buttons = ~bmap[evt-btn-button];
 }
+if (evt-btn-down  evt-btn-button == INPUT_BUTTON_WHEEL_UP) {
+s-qemu_put_mouse_event(s-qemu_put_mouse_event_opaque,
+s-axis[INPUT_AXIS_X],
+s-axis[INPUT_AXIS_Y],
+-1,
+s-buttons);
+}
+if (evt-btn-down  evt-btn-button == INPUT_BUTTON_WHEEL_DOWN) {
+s-qemu_put_mouse_event(s-qemu_put_mouse_event_opaque,
+s-axis[INPUT_AXIS_X],
+s-axis[INPUT_AXIS_Y],
+1,
+s-buttons);
+}
 break;
 case INPUT_EVENT_KIND_ABS:
 s-axis[evt-abs-axis] = evt-abs-value;
-- 
1.8.3.1




[Qemu-devel] [PATCH v17 07/14] block: Parse backing option to reference existing BDS

2014-03-10 Thread Fam Zheng
Now it's safe to allow reference for backing_hd in the interface.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 95247c8..05f7766 100644
--- a/block.c
+++ b/block.c
@@ -1401,12 +1401,35 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 /* If there is a backing file, use it */
 if ((flags  BDRV_O_NO_BACKING) == 0) {
 QDict *backing_options;
+const char *backing_name;
+BlockDriverState *backing_hd;
 
+backing_name = qdict_get_try_str(options, backing);
 qdict_extract_subqdict(options, backing_options, backing.);
-ret = bdrv_open_backing_file(bs, backing_options, local_err);
-if (ret  0) {
+
+if (backing_name  qdict_size(backing_options)) {
+error_setg(local_err,
+   Option \backing\ and \backing.*\ cannot be 
+   used together);
+ret = -EINVAL;
 goto close_and_fail;
 }
+if (backing_name) {
+backing_hd = bdrv_find(backing_name);
+if (!backing_hd) {
+error_set(local_err, QERR_DEVICE_NOT_FOUND, backing_name);
+ret = -ENOENT;
+goto close_and_fail;
+}
+qdict_del(options, backing);
+bdrv_set_backing_hd(bs, backing_hd);
+bdrv_ref(backing_hd);
+} else {
+ret = bdrv_open_backing_file(bs, backing_options, local_err);
+if (ret  0) {
+goto close_and_fail;
+}
+}
 }
 
 done:
-- 
1.9.0




[Qemu-devel] armv8 support in qemu

2014-03-10 Thread Gaurav Sharma
Hi,
I just wanted to know what is the current status armv8 support in qemu ?
After initial look into the source code i see the support for user mode.
Even though aarch64-softmmu is supported in the target list, i do not see
any corresponding code for init in target-arm/cpu64.c.

Thanks,
Gaurav


Re: [Qemu-devel] [PATCH] New feature - RFC3931 L2TPv3 network transport using static Ethernet over L2TPv3 tunnels

2014-03-10 Thread Stefan Hajnoczi
On Sun, Mar 09, 2014 at 05:06:15PM +, Anton Ivanov wrote:
 +   return -1;
 +}
 +
 +freeaddrinfo(result);
 +
 +memset(hints, 0, sizeof(hints));
 +
 +if (s-ipv6) {
 +   hints.ai_family = AF_INET6;
 +} else {
 +   hints.ai_family = AF_INET;
 +}
 +if (s-udp) {
 +   hints.ai_socktype = SOCK_DGRAM;
 +   hints.ai_protocol = 0;
 +} else {
 +   hints.ai_socktype = SOCK_RAW;
 +   hints.ai_protocol = IPPROTO_L2TP;
 Hang on, this is bogus.  This is a *userspace* L2TP implementation!
 
 We don't want a kernel L2TP driver to handle this socket.  Luckily this
 never happens anyway since net/l2tp/l2tp_ip.c only registers its socket
 type for AF_INET, SOCK_DGRAM, IPPROTO_L2TP and AF_INET6, SOCK_DGRAM,
 IPPROTO_L2TP.
 
 When we create this socket with AF_INET, SOCK_RAW, IPPROTO_L2TP what
 really happens is that the kernel falls back to the IPv4 raw socket
 driver due to a wildcard match.
 
 In other words, we shouldn't use IPPROTO_L2TP.  Just use 0.
 
 
 This is not passed to socket directly - both setups share a call to
 getaddinfo() after that and use whatever it returns.
 
 If you pass family, RAW, 0 to getaddrinfo it returns  family, DGRAM,
 0. So when you use it later on the socket is setup incorrectly.
 
 If you pass RAW, PROTO_L2TPV3 it returns the correct values to setup
 the socket. Bug for bug canceling each other out :(

That doesn't match what I see.  Can you double-check your test and figure out
what is happening?

Here is my test:

$ grep -r SOCK_RAW /usr/include/
/usr/include/bits/socket_type.h:  SOCK_RAW = 3, /* Raw protocol interface.  */
$ ./a
src ai_family 2 ai_socketype 3 ai_protocol 0
dst ai_family 2 ai_socketype 3 ai_protocol 0
$ cat a.c
#include stdio.h
#include sys/types.h
#include sys/socket.h
#include netdb.h

int main(int argc, char **argv)
{
int fd, gairet;
struct addrinfo hints;
struct addrinfo * result = NULL;

memset(hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = 0;

gairet = getaddrinfo(localhost, NULL, hints, result);
if ((gairet !=0) || (result == NULL)) {
fprintf(stderr, could not resolve src, errno = %s\n, 
gai_strerror(gairet));
return 1;
}

printf(src ai_family %d ai_socketype %d ai_protocol %d\n,
   result-ai_family, result-ai_socktype, result-ai_protocol);

freeaddrinfo(result);

memset(hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = 0;

gairet = getaddrinfo(8.8.8.8, NULL, hints, result);
if ((gairet !=0) || (result == NULL)) {
fprintf(stderr, could not resolve dst, errno = %s\n, 
gai_strerror(gairet));
return 1;
}

printf(dst ai_family %d ai_socketype %d ai_protocol %d\n,
   result-ai_family, result-ai_socktype, result-ai_protocol);

freeaddrinfo(result);

return 0;
}



Re: [Qemu-devel] [PATCH v6] vl.c: Output error on invalid machine type

2014-03-10 Thread Miroslav Rezanina
Hi,
is there any issue with this patch?

Mirek
- Original Message -
 From: mreza...@redhat.com
 To: qemu-devel@nongnu.org
 Sent: Wednesday, February 5, 2014 2:44:23 PM
 Subject: [Qemu-devel] [PATCH v6] vl.c: Output error on invalid machine type
 
 From: Miroslav Rezanina mreza...@redhat.com
 
 Output error message using qemu's error_report() function when user
 provides the invalid machine type on the command line. This also saves
 time to find what issue is when you downgrade from one version of qemu
 to another that doesn't support required machine type yet (the version
 user downgraded to have to have this patch applied too, of course).
 
 Signed-off-by: Miroslav Rezanina mreza...@redhat.com
 ---
 v6:
  - print help instead of list supported machines on error
  vl.c | 18 --
  1 file changed, 12 insertions(+), 6 deletions(-)
 
 diff --git a/vl.c b/vl.c
 index 383be1b..3297c0a 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -2600,13 +2600,19 @@ static QEMUMachine *machine_parse(const char *name)
  if (machine) {
  return machine;
  }
 -printf(Supported machines are:\n);
 -for (m = first_machine; m != NULL; m = m-next) {
 -if (m-alias) {
 -printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name);
 +
 +if (name  !is_help_option(name)) {
 +error_report(Unsupported machine type);
 +printf(\nUse '-M help' to list supported machines!\n);
 +} else {
 +printf(Supported machines are:\n);
 +for (m = first_machine; m != NULL; m = m-next) {
 +if (m-alias) {
 +printf(%-20s %s (alias of %s)\n, m-alias, m-desc,
 m-name);
 +}
 +printf(%-20s %s%s\n, m-name, m-desc,
 +   m-is_default ?  (default) : );
  }
 -printf(%-20s %s%s\n, m-name, m-desc,
 -   m-is_default ?  (default) : );
  }
  exit(!name || !is_help_option(name));
  }
 --
 1.8.5.3
 
 
 

-- 
Miroslav Rezanina
Software Engineer - Virtualization Team




[Qemu-devel] [PATCH v22 06/25] add convert functions between QEMUOptionParameter to QemuOpts

2014-03-10 Thread Chunyan Liu
Add two temp convert functions between QEMUOptionParameter to QemuOpts, so that
next patch can use it. It will simplify next patch for easier review.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/qemu/option.h |   2 +
 util/qemu-option.c| 105 ++
 2 files changed, 107 insertions(+)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index de4912a..a6aca59 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -170,4 +170,6 @@ int qemu_opts_foreach(QemuOptsList *list, 
qemu_opts_loopfunc func, void *opaque,
 QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 void qemu_opts_free(QemuOptsList *list);
 void qemu_opts_print_help(QemuOptsList *list);
+QEMUOptionParameter *opts_to_params(QemuOpts *opts);
+QemuOptsList *params_to_opts(QEMUOptionParameter *list);
 #endif
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 2c450e0..e05b126 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -1464,3 +1464,108 @@ void qemu_opts_print_help(QemuOptsList *list)
list-desc[i].help : );
 }
 }
+
+/* convert QEMUOptionParameter to QemuOpts */
+QemuOptsList *params_to_opts(QEMUOptionParameter *list)
+{
+QemuOptsList *opts = NULL;
+size_t num_opts, i = 0;
+
+if (!list) {
+return NULL;
+}
+
+num_opts = count_option_parameters(list);
+opts = g_malloc0(sizeof(QemuOptsList) +
+ (num_opts + 1) * sizeof(QemuOptDesc));
+QTAILQ_INIT(opts-head);
+opts-desc[i].name = NULL;
+
+while (list  list-name) {
+opts-desc[i].name = g_strdup(list-name);
+opts-desc[i].help = g_strdup(list-help);
+switch (list-type) {
+case OPT_FLAG:
+opts-desc[i].type = QEMU_OPT_BOOL;
+opts-desc[i].def_value_str = list-value.n ? on : off;
+break;
+
+case OPT_NUMBER:
+opts-desc[i].type = QEMU_OPT_NUMBER;
+if (list-value.n) {
+opts-desc[i].def_value_str =
+g_strdup_printf(% PRIu64, list-value.n);
+}
+break;
+
+case OPT_SIZE:
+opts-desc[i].type = QEMU_OPT_SIZE;
+if (list-value.n) {
+opts-desc[i].def_value_str =
+g_strdup_printf(% PRIu64, list-value.n);
+}
+break;
+
+case OPT_STRING:
+opts-desc[i].type = QEMU_OPT_STRING;
+opts-desc[i].def_value_str = g_strdup(list-value.s);
+break;
+}
+
+i++;
+list++;
+opts-desc[i].name = NULL;
+}
+
+return opts;
+}
+
+QEMUOptionParameter *opts_to_params(QemuOpts *opts)
+{
+QEMUOptionParameter *dest = NULL;
+QemuOptDesc *desc;
+size_t num_opts, i = 0;
+const char *tmp;
+
+if (!opts || !opts-list || !opts-list-desc) {
+return NULL;
+}
+
+num_opts = count_opts_list(opts-list);
+dest = g_malloc0((num_opts + 1) * sizeof(QEMUOptionParameter));
+dest[i].name = NULL;
+
+desc = opts-list-desc;
+while (desc  desc-name) {
+dest[i].name = g_strdup(desc-name);
+dest[i].help = g_strdup(desc-help);
+switch (desc-type) {
+case QEMU_OPT_STRING:
+dest[i].type = OPT_STRING;
+tmp = qemu_opt_get(opts, desc-name);
+dest[i].value.s = g_strdup(tmp);
+break;
+
+case QEMU_OPT_BOOL:
+dest[i].type = OPT_FLAG;
+dest[i].value.n = qemu_opt_get_bool(opts, desc-name, 0) ? 1 : 0;
+break;
+
+case QEMU_OPT_NUMBER:
+dest[i].type = OPT_NUMBER;
+dest[i].value.n = qemu_opt_get_number(opts, desc-name, 0);
+break;
+
+case QEMU_OPT_SIZE:
+dest[i].type = OPT_SIZE;
+dest[i].value.n = qemu_opt_get_size(opts, desc-name, 0);
+break;
+}
+
+i++;
+desc++;
+dest[i].name = NULL;
+}
+
+return dest;
+}
-- 
1.7.12.4




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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





[Qemu-devel] [PATCH] KVM: x86: Work around buggy MPX platform

2014-03-10 Thread Liu, Jinsong
From 5854070994c5002b3a37577165ed3e82f36f712d Mon Sep 17 00:00:00 2001
From: Liu Jinsong jinsong@intel.com
Date: Sat, 8 Mar 2014 04:40:02 +0800
Subject: [PATCH] KVM: x86: Work around buggy MPX platform

Work around buggy MPX platform which support MSR_IA32_BNDCFGS
but has issue at, say, VMX ucode.

Signed-off-by: Liu Jinsong jinsong@intel.com
---
 arch/x86/kvm/x86.c |   14 +-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1e91a24..1fc184d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3936,6 +3936,16 @@ static void kvm_init_msr_list(void)
for (i = j = KVM_SAVE_MSRS_BEGIN; i  ARRAY_SIZE(msrs_to_save); i++) {
if (rdmsr_safe(msrs_to_save[i], dummy[0], dummy[1])  0)
continue;
+
+   /*
+* Work around some buggy MPX platform which support
+* MSR_IA32_BNDCFGS but has issue at, say, VMX ucode.
+*/
+   if ((msrs_to_save[i] == MSR_IA32_BNDCFGS) 
+   (kvm_x86_ops-mpx_supported   ?
+   !kvm_x86_ops-mpx_supported() : 1))
+   continue;
+
if (j  i)
msrs_to_save[j] = msrs_to_save[i];
j++;
@@ -5576,9 +5586,11 @@ int kvm_arch_init(void *opaque)
goto out_free_percpu;
 
kvm_set_mmio_spte_mask();
-   kvm_init_msr_list();
 
kvm_x86_ops = ops;
+
+   kvm_init_msr_list();
+
kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
PT_DIRTY_MASK, PT64_NX_MASK, 0);
 
-- 
1.7.1



Re: [Qemu-devel] [PATCH] New feature - RFC3931 L2TPv3 network transport using static Ethernet over L2TPv3 tunnels

2014-03-10 Thread Anton Ivanov
You are correct. My test is wrong.

However, the result is the same - it wants a non-zero proto there.

$ sudo ./gaitest
src ai_family 2 ai_socketype 3 ai_protocol 0
socket creation failed, errno = 93
src ai_family 2 ai_socketype 3 ai_protocol 115

No error on the second one, -93 on the first one.

A.
#include stdio.h
#include sys/types.h
#include sys/socket.h
#include netdb.h
#include errno.h


int main(int argc, char **argv)
{
int fd, gairet;
struct addrinfo hints;
struct addrinfo * result = NULL;

memset(hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = 0;

gairet = getaddrinfo(localhost, NULL, hints, result);
if ((gairet !=0) || (result == NULL)) {
fprintf(stderr, could not resolve src, errno = %s\n, gai_strerror(gairet));
return 1;
}

printf(src ai_family %d ai_socketype %d ai_protocol %d\n,
   result-ai_family, result-ai_socktype, result-ai_protocol);


if (
	(fd = socket(result-ai_family, result-ai_socktype, result-ai_protocol)) == -1) {
	fd = -errno;
	printf(socket creation failed, errno = %d\n, -fd);
}

freeaddrinfo(result);

memset(hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_RAW;
hints.ai_protocol = 0x73;

gairet = getaddrinfo(localhost, NULL, hints, result);
if ((gairet !=0) || (result == NULL)) {
fprintf(stderr, could not resolve src, errno = %s\n, gai_strerror(gairet));
return 1;
}

printf(src ai_family %d ai_socketype %d ai_protocol %d\n,
   result-ai_family, result-ai_socktype, result-ai_protocol);


if (
	(fd = socket(result-ai_family, result-ai_socktype, result-ai_protocol)) == -1) {
	fd = -errno;
	printf(l2tpv3_open : socket creation failed, errno = %d, -fd);
}

freeaddrinfo(result);

return 0;
}


Re: [Qemu-devel] armv8 support in qemu

2014-03-10 Thread Alex Bennée

Gaurav Sharma gauravs.2...@gmail.com writes:

 Hi,
 I just wanted to know what is the current status armv8 support in qemu ?
 After initial look into the source code i see the support for user mode.
 Even though aarch64-softmmu is supported in the target list, i do not see
 any corresponding code for init in target-arm/cpu64.c.

Initial support is already in and the latest set of patches which get
you to boot a kernel to user-space is currently on this very list for review.

Cheers,

--
Alex Bennée
QEMU/KVM Hacker for Linaro




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

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

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/qemu/option_int.h |  4 +--
 util/qemu-option.c| 81 +++
 2 files changed, 69 insertions(+), 16 deletions(-)

diff --git a/include/qemu/option_int.h b/include/qemu/option_int.h
index 8212fa4..db9ed91 100644
--- a/include/qemu/option_int.h
+++ b/include/qemu/option_int.h
@@ -30,8 +30,8 @@
 #include qemu/error-report.h
 
 struct QemuOpt {
-const char   *name;
-const char   *str;
+char   *name;
+char   *str;
 
 const QemuOptDesc *desc;
 union {
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 65d1c22..c7639e8 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -558,8 +558,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);
+QemuOpt *opt;
 
+if (opts == NULL) {
+return NULL;
+}
+
+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) {
@@ -583,7 +588,13 @@ bool qemu_opt_has_help_opt(QemuOpts *opts)
 
 bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
+
+if (opts == NULL) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name);
@@ -598,7 +609,13 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 
 uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
+
+if (opts == NULL) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
 
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name);
@@ -614,8 +631,13 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 
 uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval)
 {
-QemuOpt *opt = qemu_opt_find(opts, name);
+QemuOpt *opt;
 
+if (opts == NULL) {
+return defval;
+}
+
+opt = qemu_opt_find(opts, name);
 if (opt == NULL) {
 const QemuOptDesc *desc = find_desc_by_name(opts-list-desc, name);
 if (desc  desc-def_value_str) {
@@ -652,6 +674,10 @@ static void qemu_opt_parse(QemuOpt *opt, Error **errp)
 
 static void qemu_opt_del(QemuOpt *opt)
 {
+if (opt == NULL) {
+return;
+}
+
 QTAILQ_REMOVE(opt-opts-head, opt, next);
 g_free((/* !const */ char*)opt-name);
 g_free((/* !const */ char*)opt-str);
@@ -704,6 +730,13 @@ static void opt_set(QemuOpts *opts, const char *name, 
const char *value,
 return;
 }
 
+opt = qemu_opt_find(opts, name);
+if (opt) {
+g_free((char *)opt-str);
+opt-str = g_strdup(value);
+return;
+}
+
 opt = g_malloc0(sizeof(*opt));
 opt-name = g_strdup(name);
 opt-opts = opts;
@@ -744,16 +777,24 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, 
const char *value,
 int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val)
 {
 QemuOpt *opt;
-const QemuOptDesc *desc = opts-list-desc;
+const QemuOptDesc *desc;
 
-opt = g_malloc0(sizeof(*opt));
-opt-desc = find_desc_by_name(desc, name);
-if (!opt-desc  !opts_accepts_any(opts)) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (!desc  !opts_accepts_any(opts)) {
 qerror_report(QERR_INVALID_PARAMETER, name);
-g_free(opt);
 return -1;
 }
 
+opt = qemu_opt_find(opts, name);
+if (opt) {
+g_free((char *)opt-str);
+opt-value.boolean = val;
+opt-str = g_strdup(val ? on : off);
+return 0;
+}
+
+opt = g_malloc0(sizeof(*opt));
+opt-desc = desc;
 opt-name = g_strdup(name);
 opt-opts = opts;
 opt-value.boolean = !!val;
@@ -766,16 +807,24 @@ int qemu_opt_set_bool(QemuOpts *opts, const char *name, 
bool val)
 int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val)
 {
 QemuOpt *opt;
-const QemuOptDesc *desc = opts-list-desc;
+const QemuOptDesc *desc;
 
-opt = g_malloc0(sizeof(*opt));
-opt-desc = find_desc_by_name(desc, name);
-if (!opt-desc  !opts_accepts_any(opts)) {
+desc = find_desc_by_name(opts-list-desc, name);
+if (!desc  !opts_accepts_any(opts)) {
 qerror_report(QERR_INVALID_PARAMETER, name);
-g_free(opt);
 return -1;
 }
 
+opt = qemu_opt_find(opts, name);
+if (opt) {
+g_free((char 

Re: [Qemu-devel] [PATCH] KVM: x86: Work around buggy MPX platform

2014-03-10 Thread Paolo Bonzini

Il 10/03/2014 09:48, Liu, Jinsong ha scritto:

From 5854070994c5002b3a37577165ed3e82f36f712d Mon Sep 17 00:00:00 2001
From: Liu Jinsong jinsong@intel.com
Date: Sat, 8 Mar 2014 04:40:02 +0800
Subject: [PATCH] KVM: x86: Work around buggy MPX platform

Work around buggy MPX platform which support MSR_IA32_BNDCFGS
but has issue at, say, VMX ucode.

Signed-off-by: Liu Jinsong jinsong@intel.com
---
 arch/x86/kvm/x86.c |   14 +-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1e91a24..1fc184d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3936,6 +3936,16 @@ static void kvm_init_msr_list(void)
for (i = j = KVM_SAVE_MSRS_BEGIN; i  ARRAY_SIZE(msrs_to_save); i++) {
if (rdmsr_safe(msrs_to_save[i], dummy[0], dummy[1])  0)
continue;
+
+   /*
+* Work around some buggy MPX platform which support
+* MSR_IA32_BNDCFGS but has issue at, say, VMX ucode.
+*/
+   if ((msrs_to_save[i] == MSR_IA32_BNDCFGS) 


Too many parentheses in this if.



+   (kvm_x86_ops-mpx_supported   ?
+   !kvm_x86_ops-mpx_supported() : 1))


Better: !kvm_x86_ops-mpx_supported || !kvm_x86_ops-mpx_supported() 
but I'm leaning towards adding an implementation of mpx_supported to SVM 
too (it will always return false).



+   continue;
+
if (j  i)
msrs_to_save[j] = msrs_to_save[i];
j++;
@@ -5576,9 +5586,11 @@ int kvm_arch_init(void *opaque)
goto out_free_percpu;

kvm_set_mmio_spte_mask();
-   kvm_init_msr_list();

kvm_x86_ops = ops;
+
+   kvm_init_msr_list();
+
kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
PT_DIRTY_MASK, PT64_NX_MASK, 0);




Thanks Liu.  Indeed I could not reproduce Robert's issue, though it 
might be possible to get it with nested virtualization.  I'll send a 
similar patch that I was testing.


Paolo



[Qemu-devel] [PATCH v22 12/25] qcow2.c: replace QEMUOptionParameter with QemuOpts

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/qcow2.c | 325 ++
 1 file changed, 167 insertions(+), 158 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index dcd43bc..e0f00bf 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1455,7 +1455,7 @@ static int preallocate(BlockDriverState *bs)
 static int qcow2_create2(const char *filename, int64_t total_size,
  const char *backing_file, const char *backing_format,
  int flags, size_t cluster_size, int prealloc,
- QEMUOptionParameter *options, int version,
+ QemuOpts *opts, int version,
  Error **errp)
 {
 /* Calculate cluster_bits */
@@ -1487,7 +1487,7 @@ static int qcow2_create2(const char *filename, int64_t 
total_size,
 Error *local_err = NULL;
 int ret;
 
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
 return ret;
@@ -1622,11 +1622,11 @@ out:
 return ret;
 }
 
-static int qcow2_create(const char *filename, QEMUOptionParameter *options,
-Error **errp)
+static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
 {
-const char *backing_file = NULL;
-const char *backing_fmt = NULL;
+char *backing_file = NULL;
+char *backing_fmt = NULL;
+char *buf;
 uint64_t sectors = 0;
 int flags = 0;
 size_t cluster_size = DEFAULT_CLUSTER_SIZE;
@@ -1636,64 +1636,64 @@ static int qcow2_create(const char *filename, 
QEMUOptionParameter *options,
 int ret;
 
 /* Read out options */
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-sectors = options-value.n / 512;
-} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FMT)) {
-backing_fmt = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_ENCRYPT)) {
-flags |= options-value.n ? BLOCK_FLAG_ENCRYPT : 0;
-} else if (!strcmp(options-name, BLOCK_OPT_CLUSTER_SIZE)) {
-if (options-value.n) {
-cluster_size = options-value.n;
-}
-} else if (!strcmp(options-name, BLOCK_OPT_PREALLOC)) {
-if (!options-value.s || !strcmp(options-value.s, off)) {
-prealloc = 0;
-} else if (!strcmp(options-value.s, metadata)) {
-prealloc = 1;
-} else {
-error_setg(errp, Invalid preallocation mode: '%s',
-   options-value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options-name, BLOCK_OPT_COMPAT_LEVEL)) {
-if (!options-value.s) {
-/* keep the default */
-} else if (!strcmp(options-value.s, 0.10)) {
-version = 2;
-} else if (!strcmp(options-value.s, 1.1)) {
-version = 3;
-} else {
-error_setg(errp, Invalid compatibility level: '%s',
-   options-value.s);
-return -EINVAL;
-}
-} else if (!strcmp(options-name, BLOCK_OPT_LAZY_REFCOUNTS)) {
-flags |= options-value.n ? BLOCK_FLAG_LAZY_REFCOUNTS : 0;
-}
-options++;
+sectors = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
+}
+cluster_size = qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE,
+ DEFAULT_CLUSTER_SIZE);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
+if (!buf || !strcmp(buf, off)) {
+prealloc = 0;
+} else if (!strcmp(buf, metadata)) {
+prealloc = 1;
+} else {
+fprintf(stderr, Invalid preallocation mode: '%s'\n, buf);
+ret = -EINVAL;
+goto finish;
+}
+g_free(buf);
+buf = qemu_opt_get_del(opts, BLOCK_OPT_COMPAT_LEVEL);
+if (!buf || !strcmp(buf, 0.10)) {
+version = 2;
+} else if (!strcmp(buf, 1.1)) {
+version = 3;
+} else {
+fprintf(stderr, Invalid compatibility level: '%s'\n, buf);
+ret = -EINVAL;
+goto finish;
+}
+
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_LAZY_REFCOUNTS, false)) {
+flags |= BLOCK_FLAG_LAZY_REFCOUNTS;
 }
 
 if (backing_file  prealloc) {
 error_setg(errp, Backing file and preallocation cannot be used at 
the same time);
-return 

[Qemu-devel] [PATCH v17 13/14] qemu-iotests: Test blockdev-backup in 055

2014-03-10 Thread Fam Zheng
This applies cases on drive-backup on blockdev-backup, except cases with
target format and mode.

Also add a case to check source == target.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/055 | 275 ++---
 tests/qemu-iotests/055.out |   4 +-
 2 files changed, 235 insertions(+), 44 deletions(-)

diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
index 451b67d..1fab088 100755
--- a/tests/qemu-iotests/055
+++ b/tests/qemu-iotests/055
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 #
-# Tests for drive-backup
+# Tests for drive-backup and blockdev-backup
 #
 # Copyright (C) 2013 Red Hat, Inc.
 #
@@ -27,6 +27,7 @@ from iotests import qemu_img, qemu_io
 
 test_img = os.path.join(iotests.test_dir, 'test.img')
 target_img = os.path.join(iotests.test_dir, 'target.img')
+blockdev_target_img = os.path.join(iotests.test_dir, 'blockdev-target.img')
 
 class TestSingleDrive(iotests.QMPTestCase):
 image_len = 64 * 1024 * 1024 # MB
@@ -38,34 +39,48 @@ class TestSingleDrive(iotests.QMPTestCase):
 qemu_io('-c', 'write -P0xd5 1M 32k', test_img)
 qemu_io('-c', 'write -P0xdc 32M 124k', test_img)
 qemu_io('-c', 'write -P0xdc 67043328 64k', test_img)
+qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, 
str(TestSingleDrive.image_len))
 
-self.vm = iotests.VM().add_drive(test_img)
+self.vm = 
iotests.VM().add_drive(test_img).add_drive(blockdev_target_img)
 self.vm.launch()
 
 def tearDown(self):
 self.vm.shutdown()
 os.remove(test_img)
+os.remove(blockdev_target_img)
 try:
 os.remove(target_img)
 except OSError:
 pass
 
-def test_cancel(self):
+def do_test_cancel(self, test_drive_backup):
 self.assert_no_active_block_jobs()
 
-result = self.vm.qmp('drive-backup', device='drive0',
- target=target_img, sync='full')
+if test_drive_backup:
+result = self.vm.qmp('drive-backup', device='drive0',
+ target=target_img, sync='full')
+else:
+result = self.vm.qmp('blockdev-backup', device='drive0',
+ target='drive1', sync='full')
 self.assert_qmp(result, 'return', {})
 
 event = self.cancel_and_wait()
 self.assert_qmp(event, 'data/type', 'backup')
 
-def test_pause(self):
+def test_cancel(self):
+self.do_test_cancel(True)
+self.do_test_cancel(False)
+
+def do_test_pause(self, test_drive_backup):
 self.assert_no_active_block_jobs()
 
 self.vm.pause_drive('drive0')
-result = self.vm.qmp('drive-backup', device='drive0',
- target=target_img, sync='full')
+if test_drive_backup:
+result = self.vm.qmp('drive-backup', device='drive0',
+ target=target_img, sync='full')
+else:
+result = self.vm.qmp('blockdev-backup', device='drive0',
+ target='drive1', sync='full')
 self.assert_qmp(result, 'return', {})
 
 result = self.vm.qmp('block-job-pause', device='drive0')
@@ -86,14 +101,28 @@ class TestSingleDrive(iotests.QMPTestCase):
 self.wait_until_completed()
 
 self.vm.shutdown()
-self.assertTrue(iotests.compare_images(test_img, target_img),
-'target image does not match source after backup')
+if test_drive_backup:
+self.assertTrue(iotests.compare_images(test_img, target_img),
+'target image does not match source after backup')
+else:
+self.assertTrue(iotests.compare_images(test_img, 
blockdev_target_img),
+'target image does not match source after backup')
+
+def test_pause_drive_backup(self):
+self.do_test_pause(True)
+
+def test_pause_blockdev_backup(self):
+self.do_test_pause(False)
 
 def test_medium_not_found(self):
 result = self.vm.qmp('drive-backup', device='ide1-cd0',
  target=target_img, sync='full')
 self.assert_qmp(result, 'error/class', 'GenericError')
 
+result = self.vm.qmp('blockdev-backup', device='ide1-cd0',
+ target='drive1', sync='full')
+self.assert_qmp(result, 'error/class', 'GenericError')
+
 def test_image_not_found(self):
 result = self.vm.qmp('drive-backup', device='drive0',
  target=target_img, sync='full', mode='existing')
@@ -110,26 +139,56 @@ class TestSingleDrive(iotests.QMPTestCase):
  target=target_img, sync='full')
 self.assert_qmp(result, 'error/class', 'DeviceNotFound')
 
+result = self.vm.qmp('blockdev-backup', device='nonexistent',
+ target='drive0', sync='full')
+

[Qemu-devel] [PATCH v17 03/14] block: Replace in_use with operation blocker

2014-03-10 Thread Fam Zheng
This drops BlockDriverState.in_use with op_blockers:

  - Call bdrv_op_block_all in place of bdrv_set_in_use(bs, 1).
  - Call bdrv_op_unblock_all in place of bdrv_set_in_use(bs, 0).
  - Check bdrv_op_is_blocked() in place of bdrv_in_use(bs).
The specific types are used, e.g. in place of starting block backup,
bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP, ...).
  - Check bdrv_op_blocker_is_empty() in place of assert(!bs-in_use).

Note: there is only bdrv_op_block_all and bdrv_op_unblock_all callers at
this moment. So although the checks are specific to op types, this
changes can still be seen as identical logic with previously with
in_use. The difference is error message are improved because of blocker
error info.

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Markus Armbruster arm...@redhat.com
---
 block-migration.c   |  7 +--
 block.c | 24 +++-
 blockdev.c  | 19 +--
 blockjob.c  | 14 +-
 hw/block/dataplane/virtio-blk.c | 19 ---
 include/block/block.h   |  2 --
 include/block/block_int.h   |  1 -
 include/block/blockjob.h|  3 +++
 8 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/block-migration.c b/block-migration.c
index 897fdba..bf9a25f 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -59,6 +59,7 @@ typedef struct BlkMigDevState {
 unsigned long *aio_bitmap;
 int64_t completed_sectors;
 BdrvDirtyBitmap *dirty_bitmap;
+Error *blocker;
 } BlkMigDevState;
 
 typedef struct BlkMigBlock {
@@ -346,7 +347,8 @@ static void init_blk_migration_it(void *opaque, 
BlockDriverState *bs)
 bmds-completed_sectors = 0;
 bmds-shared_base = block_mig_state.shared_base;
 alloc_aio_bitmap(bmds);
-bdrv_set_in_use(bs, 1);
+error_setg(bmds-blocker, block device is in use by migration);
+bdrv_op_block_all(bs, bmds-blocker);
 bdrv_ref(bs);
 
 block_mig_state.total_sector_sum += sectors;
@@ -584,7 +586,8 @@ static void blk_mig_cleanup(void)
 blk_mig_lock();
 while ((bmds = QSIMPLEQ_FIRST(block_mig_state.bmds_list)) != NULL) {
 QSIMPLEQ_REMOVE_HEAD(block_mig_state.bmds_list, entry);
-bdrv_set_in_use(bmds-bs, 0);
+bdrv_op_unblock_all(bmds-bs, bmds-blocker);
+error_free(bmds-blocker);
 bdrv_unref(bmds-bs);
 g_free(bmds-aio_bitmap);
 g_free(bmds);
diff --git a/block.c b/block.c
index 56a4433..c79d5dc 100644
--- a/block.c
+++ b/block.c
@@ -1850,7 +1850,6 @@ static void bdrv_move_feature_fields(BlockDriverState 
*bs_dest,
 bs_dest-refcnt = bs_src-refcnt;
 
 /* job */
-bs_dest-in_use = bs_src-in_use;
 bs_dest-job= bs_src-job;
 
 /* keep the same entry in bdrv_states */
@@ -1893,7 +1892,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 assert(QLIST_EMPTY(bs_new-dirty_bitmaps));
 assert(bs_new-job == NULL);
 assert(bs_new-dev == NULL);
-assert(bs_new-in_use == 0);
+assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1912,7 +1911,7 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState 
*bs_old)
 /* Check a few fields that should remain attached to the device */
 assert(bs_new-dev == NULL);
 assert(bs_new-job == NULL);
-assert(bs_new-in_use == 0);
+assert(bdrv_op_blocker_is_empty(bs_new));
 assert(bs_new-io_limits_enabled == false);
 assert(!throttle_have_timer(bs_new-throttle_state));
 
@@ -1957,7 +1956,7 @@ static void bdrv_delete(BlockDriverState *bs)
 {
 assert(!bs-dev);
 assert(!bs-job);
-assert(!bs-in_use);
+assert(bdrv_op_blocker_is_empty(bs));
 assert(!bs-refcnt);
 assert(QLIST_EMPTY(bs-dirty_bitmaps));
 
@@ -2139,7 +2138,8 @@ int bdrv_commit(BlockDriverState *bs)
 return -ENOTSUP;
 }
 
-if (bdrv_in_use(bs) || bdrv_in_use(bs-backing_hd)) {
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT, NULL) ||
+bdrv_op_is_blocked(bs-backing_hd, BLOCK_OP_TYPE_COMMIT, NULL)) {
 return -EBUSY;
 }
 
@@ -3374,8 +3374,9 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
 return -ENOTSUP;
 if (bs-read_only)
 return -EACCES;
-if (bdrv_in_use(bs))
+if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
 return -EBUSY;
+}
 ret = drv-bdrv_truncate(bs, offset);
 if (ret == 0) {
 ret = refresh_total_sectors(bs, offset  BDRV_SECTOR_BITS);
@@ -5226,17 +5227,6 @@ bool bdrv_op_blocker_is_empty(BlockDriverState *bs)
 return true;
 }
 
-void bdrv_set_in_use(BlockDriverState *bs, int in_use)
-{
-assert(bs-in_use != in_use);
-bs-in_use = in_use;
-}
-
-int bdrv_in_use(BlockDriverState *bs)
-{
-return bs-in_use;
-}
-
 void 

Re: [Qemu-devel] [PATCH v2 1/5] w32: Add and use intermediate include file for windows.h

2014-03-10 Thread Markus Armbruster
Stefan Weil s...@weilnetz.de writes:

 Including windows.h from the new file include/qemu/winapi.h allows
 better tracking of the files which depend on the Windows API.

 1864 *.o files depend on windows.h in a typical build, only 88 *.o files
 don't.

 The windows.h specific macro WIN32_LEAN_AND_MEAN is now defined in the new
 file and no longer part of the QEMU_CFLAGS. A hack in ui/sdl.c can be
 removed after this change.

 WINVER is still needed for all compilations with MinGW, so it cannot be
 defined in the new file. Replace its numeric value by a symbolic value to
 show which API is requested.
[...]
 diff --git a/block/raw-win32.c b/block/raw-win32.c
 index ae1c8e6..95b27a5 100644
 --- a/block/raw-win32.c
 +++ b/block/raw-win32.c
 @@ -23,13 +23,13 @@
   */
  #include qemu-common.h
  #include qemu/timer.h
 +#include qemu/winapi.h/* HANDLE (in raw-aio.h) */

Such comments get out of date real fast.  I treat them as noise.

If raw-aio.h needs stuff from winapi.h, why doesn't raw-aio.h include
it?

  #include block/block_int.h
  #include qemu/module.h
  #include raw-aio.h
  #include trace.h
  #include block/thread-pool.h
  #include qemu/iov.h
 -#include windows.h
  #include winioctl.h
  
  #define FTYPE_FILE 0
[...]



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

2014-03-10 Thread Chun Yan Liu
The whole patch series could also be get from here:
https://github.com/chunyanliu/qemu/commits/QemuOpts

-Chunyan

 On 3/10/2014 at 03:31 PM, in message
1394436721-21812-1-git-send-email-cy...@suse.com, Chunyan Liu
cy...@suse.com wrote: 
 This patch series is to replace QEMUOptionParameter with QemuOpts, so that  
 only 
 one Qemu Option structure is kept in QEMU code. 
  
 --- 
 Changes to v21: 
   * update verison info in patch 2/25 
   * others are not changed except for rebase 
  
 Chunyan Liu (25): 
   add def_value_str to QemuOptDesc 
   qapi: output def_value_str when query command line options 
   improve some functions in qemu-option.c 
   improve assertion in qemu_opt_get functions 
   add some QemuOpts functions for replace work 
   add convert functions between QEMUOptionParameter to QemuOpts 
   change block layer to support both QemuOpts and QEMUOptionParamter 
   cow.c: replace QEMUOptionParameter with QemuOpts 
   gluster.c: replace QEMUOptionParameter with QemuOpts 
   iscsi.c: replace QEMUOptionParameter with QemuOpts 
   qcow.c: replace QEMUOptionParameter with QemuOpts 
   qcow2.c: replace QEMUOptionParameter with QemuOpts 
   qed.c: replace QEMUOptionParameter with QemuOpts 
   raw-posix.c: replace QEMUOptionParameter with QemuOpts 
   raw-win32.c: replace QEMUOptionParameter with QemuOpts 
   raw_bsd.c: replace QEMUOptionParameter with QemuOpts 
   rbd.c: replace QEMUOptionParameter with QemuOpts 
   sheepdog.c: replace QEMUOptionParameter with QemuOpts 
   ssh.c: replace QEMUOptionParameter with QemuOpts 
   vdi.c: replace QEMUOptionParameter with QemuOpts 
   vmdk.c: replace QEMUOptionParameter with QemuOpts 
   vpc.c: replace QEMUOptionParameter with QemuOpts 
   vhdx.c: replace QEMUOptionParameter with QemuOpts 
   vvfat.c: replace QEMUOptionParameter with QemuOpts 
   cleanup QEMUOptionParameter 
  
  block.c   |  96  
  block/cow.c   |  52 ++--- 
  block/gluster.c   |  73 +++--- 
  block/iscsi.c |  29 ++- 
  block/qcow.c  |  72 +++--- 
  block/qcow2.c | 325 +- 
  block/qed.c   | 112 - 
  block/qed.h   |   3 +- 
  block/raw-posix.c |  55 ++--- 
  block/raw-win32.c |  38 +-- 
  block/raw_bsd.c   |  25 +- 
  block/rbd.c   |  61 +++-- 
  block/sheepdog.c  | 102  
  block/ssh.c   |  30 ++- 
  block/vdi.c   |  70 +++--- 
  block/vhdx.c  |  97  
  block/vhdx.h  |   1 + 
  block/vmdk.c  | 121 +- 
  block/vpc.c   |  60 ++--- 
  block/vvfat.c |  10 +- 
  include/block/block.h |   7 +- 
  include/block/block_int.h |   9 +- 
  include/qemu/option.h |  56 + 
  include/qemu/option_int.h |   4 +- 
  qapi-schema.json  |   6 +- 
  qemu-img.c|  89 --- 
  qmp-commands.hx   |   2 + 
  util/qemu-config.c|   4 + 
  util/qemu-option.c| 576 
 ++ 
  29 files changed, 1060 insertions(+), 1125 deletions(-) 
 





[Qemu-devel] [PATCH v22 11/25] qcow.c: replace QEMUOptionParameter with QemuOpts

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/qcow.c | 72 ++--
 1 file changed, 36 insertions(+), 36 deletions(-)

diff --git a/block/qcow.c b/block/qcow.c
index 153b9bd..374e6df 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -662,35 +662,29 @@ 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 *opts, 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;
+char *backing_file = NULL;
 int 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_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) {
+flags |= BLOCK_FLAG_ENCRYPT;
 }
 
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
-return ret;
+goto cleanup;
 }
 
 qcow_bs = NULL;
@@ -698,7 +692,7 @@ static int qcow_create(const char *filename, 
QEMUOptionParameter *options,
 BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, local_err);
 if (ret  0) {
 error_propagate(errp, local_err);
-return ret;
+goto cleanup;
 }
 
 ret = bdrv_truncate(qcow_bs, 0);
@@ -769,6 +763,8 @@ static int qcow_create(const char *filename, 
QEMUOptionParameter *options,
 ret = 0;
 exit:
 bdrv_unref(qcow_bs);
+cleanup:
+g_free(backing_file);
 return ret;
 }
 
@@ -881,24 +877,28 @@ static int qcow_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-
-static QEMUOptionParameter qcow_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = File name of a base image
-},
-{
-.name = BLOCK_OPT_ENCRYPT,
-.type = OPT_FLAG,
-.help = Encrypt the image
-},
-{ NULL }
+static QemuOptsList qcow_create_opts = {
+.name = qcow-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(qcow_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = File name of a base image
+},
+{
+.name = BLOCK_OPT_ENCRYPT,
+.type = QEMU_OPT_BOOL,
+.help = Encrypt the image,
+.def_value_str = off
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_qcow = {
@@ -907,8 +907,8 @@ static BlockDriver bdrv_qcow = {
 .bdrv_probe= qcow_probe,
 .bdrv_open = qcow_open,
 .bdrv_close= qcow_close,
-.bdrv_reopen_prepare = qcow_reopen_prepare,
-.bdrv_create   = qcow_create,
+.bdrv_reopen_prepare= qcow_reopen_prepare,
+.bdrv_create2   = qcow_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
 .bdrv_co_readv  = qcow_co_readv,
@@ -920,7 +920,7 @@ static BlockDriver bdrv_qcow = {
 .bdrv_write_compressed  = qcow_write_compressed,
 .bdrv_get_info  = qcow_get_info,
 
-.create_options = qcow_create_options,
+.create_opts= qcow_create_opts,
 };
 
 static void bdrv_qcow_init(void)
-- 
1.7.12.4




[Qemu-devel] [PATCH v22 25/25] cleanup QEMUOptionParameter

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

Signed-off-by: Dong Xu Wang address@hidden
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block.c   |  69 ++--
 block/cow.c   |   4 +-
 block/gluster.c   |   8 +-
 block/qcow.c  |   4 +-
 block/qcow2.c |   6 +-
 block/qed.c   |   4 +-
 block/raw-posix.c |  10 +-
 block/raw-win32.c |   2 +-
 block/raw_bsd.c   |   4 +-
 block/rbd.c   |   2 +-
 block/sheepdog.c  |   6 +-
 block/ssh.c   |   2 +-
 block/vdi.c   |   2 +-
 block/vhdx.c  |   4 +-
 block/vmdk.c  |   6 +-
 block/vpc.c   |   2 +-
 block/vvfat.c |   2 +-
 include/block/block.h |   8 +-
 include/block/block_int.h |  13 +-
 include/qemu/option.h |  46 --
 qemu-img.c|  63 +---
 util/qemu-option.c| 401 --
 22 files changed, 62 insertions(+), 606 deletions(-)

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

Re: [Qemu-devel] [PATCH v3 1/3] loader: rename in_ram/has_mr

2014-03-10 Thread Paolo Bonzini

Il 09/03/2014 19:06, Michael S. Tsirkin ha scritto:

we put copy of ROMs in MR for migration.
but the name rom_in_ram makes one think we
load it in guest RAM.
Rename has_mr to make intent clearer.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 include/hw/loader.h | 2 +-
 hw/core/loader.c| 6 +++---
 hw/i386/pc_piix.c   | 2 +-
 hw/i386/pc_q35.c| 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/hw/loader.h b/include/hw/loader.h
index aaf08c3..3dc5b94 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -49,7 +49,7 @@ void pstrcpy_targphys(const char *name,
   hwaddr dest, int buf_size,
   const char *source);

-extern bool rom_file_in_ram;
+extern bool rom_file_has_mr;

 int rom_add_file(const char *file, const char *fw_dir,
  hwaddr addr, int32_t bootindex);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index b323c0c..13e98d8 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -54,7 +54,7 @@

 #include zlib.h

-bool rom_file_in_ram = true;
+bool rom_file_has_mr = true;

 static int roms_loaded;

@@ -694,7 +694,7 @@ int rom_add_file(const char *file, const char *fw_dir,
  basename);
 snprintf(devpath, sizeof(devpath), /rom@%s, fw_file_name);

-if (rom_file_in_ram) {
+if (rom_file_has_mr) {
 data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
 } else {
 data = rom-data;
@@ -738,7 +738,7 @@ void *rom_add_blob(const char *name, const void *blob, 
size_t len,

 snprintf(devpath, sizeof(devpath), /rom@%s, fw_file_name);

-if (rom_file_in_ram) {
+if (rom_file_has_mr) {
 data = rom_set_mr(rom, OBJECT(fw_cfg), devpath);
 } else {
 data = rom-data;
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index ae1699d..fb2d636 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -272,7 +272,7 @@ static void pc_compat_1_6(QEMUMachineInitArgs *args)
 {
 pc_compat_1_7(args);
 has_pci_info = false;
-rom_file_in_ram = false;
+rom_file_has_mr = false;
 has_acpi_build = false;
 }

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index a7f6260..eb55ae4 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -250,7 +250,7 @@ static void pc_compat_1_6(QEMUMachineInitArgs *args)
 {
 pc_compat_1_7(args);
 has_pci_info = false;
-rom_file_in_ram = false;
+rom_file_has_mr = false;
 has_acpi_build = false;
 }




Series looks good, but please squash patch 3 into patch 2.

Paolo



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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/vmdk.c | 123 ++-
 1 file changed, 63 insertions(+), 60 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index d87c8f6..f9b68a0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1681,17 +1681,16 @@ 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 *opts, Error **errp)
 {
 int idx = 0;
 BlockDriverState *new_bs = NULL;
 Error *local_err;
 char *desc = NULL;
 int64_t total_size = 0, filesize;
-const char *adapter_type = NULL;
-const char *backing_file = NULL;
-const char *fmt = NULL;
+char *adapter_type = NULL;
+char *backing_file = NULL;
+char *fmt = NULL;
 int flags = 0;
 int ret = 0;
 bool flat, split, compress;
@@ -1731,24 +1730,19 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 goto exit;
 }
 /* Read out options */
-while (options  options-name) {
-if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-total_size = options-value.n;
-} else if (!strcmp(options-name, BLOCK_OPT_ADAPTER_TYPE)) {
-adapter_type = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_BACKING_FILE)) {
-backing_file = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_COMPAT6)) {
-flags |= options-value.n ? BLOCK_FLAG_COMPAT6 : 0;
-} else if (!strcmp(options-name, BLOCK_OPT_SUBFMT)) {
-fmt = options-value.s;
-} else if (!strcmp(options-name, BLOCK_OPT_ZEROED_GRAIN)) {
-zeroed_grain |= options-value.n;
-}
-options++;
+total_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
+flags |= BLOCK_FLAG_COMPAT6;
+}
+fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
+if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
+zeroed_grain = true;
 }
+
 if (!adapter_type) {
-adapter_type = ide;
+adapter_type = g_strdup(ide);
 } else if (strcmp(adapter_type, ide) 
strcmp(adapter_type, buslogic) 
strcmp(adapter_type, lsilogic) 
@@ -1764,7 +1758,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 }
 if (!fmt) {
 /* Default format to monolithicSparse */
-fmt = monolithicSparse;
+fmt = g_strdup(monolithicSparse);
 } else if (strcmp(fmt, monolithicFlat) 
strcmp(fmt, monolithicSparse) 
strcmp(fmt, twoGbMaxExtentSparse) 
@@ -1865,7 +1859,7 @@ static int vmdk_create(const char *filename, 
QEMUOptionParameter *options,
 if (!split  !flat) {
 desc_offset = 0x200;
 } else {
-ret = bdrv_create_file(filename, options, NULL, local_err);
+ret = bdrv_create_file(filename, NULL, opts, local_err);
 if (ret  0) {
 error_setg_errno(errp, -ret, Could not create image file);
 goto exit;
@@ -1895,6 +1889,9 @@ exit:
 if (new_bs) {
 bdrv_unref(new_bs);
 }
+g_free(adapter_type);
+g_free(backing_file);
+g_free(fmt);
 g_free(desc);
 g_string_free(ext_desc_lines, true);
 return ret;
@@ -2062,41 +2059,47 @@ static ImageInfoSpecific 
*vmdk_get_specific_info(BlockDriverState *bs)
 return spec_info;
 }
 
-static QEMUOptionParameter vmdk_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{
-.name = BLOCK_OPT_ADAPTER_TYPE,
-.type = OPT_STRING,
-.help = Virtual adapter type, can be one of 
-ide (default), lsilogic, buslogic or legacyESX
-},
-{
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = File name of a base image
-},
-{
-.name = BLOCK_OPT_COMPAT6,
-.type = OPT_FLAG,
-.help = VMDK version 6 image
-},
-{
-.name = BLOCK_OPT_SUBFMT,
-.type = OPT_STRING,
-.help =
-VMDK flat extent format, can be one of 
-{monolithicSparse (default) | monolithicFlat | 
twoGbMaxExtentSparse | twoGbMaxExtentFlat | streamOptimized} 
-},
-{
-.name = BLOCK_OPT_ZEROED_GRAIN,
-.type = OPT_FLAG,
-.help = Enable efficient zero writes using the zeroed-grain GTE 
feature
-},
-{ NULL }
+static QemuOptsList vmdk_create_opts = {
+.name = vmdk-create-opts,
+.head = 

[Qemu-devel] [PATCH v22 01/25] add def_value_str to QemuOptDesc

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

Signed-off-by: Dong Xu Wang address@hidden
Signed-off-by: Chunyan Liu cy...@suse.com
---
 include/qemu/option.h |  3 ++-
 util/qemu-option.c| 59 +++
 2 files changed, 52 insertions(+), 10 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..65d1c22 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -33,6 +33,9 @@
 #include qapi/qmp/qerror.h
 #include qemu/option_int.h
 
+static const QemuOptDesc *find_desc_by_name(const QemuOptDesc *desc,
+const char *name);
+
 /*
  * Extracts the name of an option from the parameter string (p points at the
  * first byte of the option name)
@@ -556,6 +559,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 +585,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 +600,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 +616,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;
 }
@@ -895,17 +921,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 : noid);
-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\ , opt-name, opt-str);
+}
+return;
+}
+for (; desc  desc-name; desc++) {
+const char *value;
+QemuOpt *opt = qemu_opt_find(opts, desc-name);
+
+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);
+}
 }
 fprintf(stderr, \n);
-return 0;
 }
 
 static int opts_do_parse(QemuOpts *opts, const char *params,
-- 
1.7.12.4




Re: [Qemu-devel] [PATCH 00/11] tcg-sparc updates

2014-03-10 Thread Artyom Tarasenko
On Sun, Mar 9, 2014 at 11:21 PM, Mark Cave-Ayland
mark.cave-ayl...@ilande.co.uk wrote:
 On 05/03/14 18:11, Richard Henderson wrote:

 Rescued from a branch from September.  I can't recall if I ever
 actually posted these back then, so I'll wait a week before asking
 for a pull.

 Re-tested on v8plus.  The machine doesn't have 64-bit libraries
 installed, so I'm a bit stuck with that.


 r~


 Richard Henderson (11):
tcg-sparc: Fix ld64 for 32-bit mode
tcg-sparc: Fix tlb read
tcg-sparc: Tidy call+jump patterns
tcg-sparc: Use intptr_t as appropriate
tcg-sparc: Don't handle remainder
tcg-sparc: Dont handle constant arguments to ext32 ops
tcg-sparc: Improve tcg_out_movi
tcg-sparc: Use TCGMemOp within qemu_ldst routines
tcg-sparc: Tidy tcg_out_tlb_load interface
tcg-sparc: Convert to new ldst helpers
tcg-sparc: Convert to new ldst opcodes

   tcg/sparc/tcg-target.c | 599
 +
   tcg/sparc/tcg-target.h |   6 +-
   2 files changed, 304 insertions(+), 301 deletions(-)


 Hi Richard,

 The basic patchset applies fine to git master although I got the following
 warning from git-am:

 Applying: tcg-sparc: Fix tlb read
 /home/build/src/qemu/git/qemu/.git/rebase-apply/patch:49: trailing
 whitespace.

 All my SPARC32 and SPARC64 images run with no regressions, and there is a
 perceivable slight increase in performance here.

 Tested-by: Mark Cave-Ayland mark.cave-ayl...@ilande.co.uk

Hi Mark,

I think a better test case would be looking for regressions in
x86/x86-64 images. I'd suspect someone would launch QEMU on a SPARC
machine to emulate some other platform. (Solaris containers would be
more efficient for running SPARC on SPARC)

Artyom


-- 
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu



Re: [Qemu-devel] [PATCH v16 00/14] Drop in_use from BlockDriverState and enable point-in-time snapshot exporting over NBD

2014-03-10 Thread Kevin Wolf
Am 10.03.2014 um 07:38 hat Fam Zheng geschrieben:
 On Mon, 03/10 06:13, Benoît Canet wrote:
  The Friday 07 Mar 2014 à 16:20:42 (+0800), Fam Zheng wrote :
   This series adds for point-in-time snapshot NBD exporting based on
   blockdev-backup (variant of drive-backup with existing device as target).
   
   We get a thin point-in-time snapshot by COW mechanism of drive-backup, and
   export it through built in NBD server. The steps are as below:
   
1. (SHELL) qemu-img create -f qcow2 BACKUP.qcow2 source size here
   
   (Alternatively we can use -o backing_file=RUNNING-VM.img to omit 
   explicitly
   providing the size by ourselves, but it's risky because 
   RUNNING-VM.qcow2 is
   used r/w by guest. Whether or not setting backing file in the image 
   file
   doesn't matter, as we are going to override the backing hd in the next
   step)
   
2. (QMP) blockdev-add backing=source-drive file.driver=file 
   file.filename=BACKUP.qcow2 id=target0 if=none driver=qcow2
   
   (where source-drive is the running BlockDriverState name for
   RUNNING-VM.img. This patch implements backing= option to override
   backing_hd for added drive)
   
3. (QMP) blockdev-backup device=source-drive sync=none target=target0
   
   (this is the QMP command introduced by this series, which use a named
   device as target of drive-backup)
   
4. (QMP) nbd-server-add device=target0
   
   When image fleecing done:
   
1. (QMP) block-job-cancel device=source-drive
   
2. (HMP) drive_del target0
   
3. (SHELL) rm BACKUP.qcow2
   
   v16: Address review comments from Jeff and Markus (thanks for reviewing!)
(A side-by-side diff of v15 - v16: http://goo.gl/1goc6S)
   
   [03/14] block: Replace in_use with operation blocker
   Improve error message. (Markus)
   
   [05/14] block: Add bdrv_set_backing_hd()
   in bdrv_set_backing_hd:
   * Don't call bdrv_ref and bdrv_unref. (Jeff)
   * Add bs-open_flags = ~BDRV_O_NO_BACKING. (Jeff)
   in bdrv_open_backing_file:
   * Remove unnecessary bs-backing_hd = NULL;. (Jeff)
   * Don't get wrong refcnt on backing_hd. (Jeff)
   in bdrv_append:
   * Remove unnessary backing_file and backing_format copy, it's 
   taken
 care of in bdrv_set_backing_hd(). (Jeff)
   
   [06/14] block: Add backing_blocker in BlockDriverState
   Add call to bdrv_ref() since bdrv_set_backing_hd() doesn't do 
   it
   now.
   
   [08/14] block: Support dropping active in bdrv_drop_intermediate
   Verify active, top, base are in the same backing chain. (Jeff)
   Remember to change backing file when base != NULL. (Jeff)
   
   [09/14] stream: Use bdrv_drop_intermediate and drop 
   close_unused_images
   Drop more unnecessary code. (Jeff)
   
   Thanks,
   Fam
   
   
   Fam Zheng (14):
 block: Add BlockOpType enum
 block: Introduce op_blockers to BlockDriverState
 block: Replace in_use with operation blocker
 block: Move op_blocker check from block_job_create to its caller
 block: Add bdrv_set_backing_hd()
 block: Add backing_blocker in BlockDriverState
 block: Parse backing option to reference existing BDS
 block: Support dropping active in bdrv_drop_intermediate
 stream: Use bdrv_drop_intermediate and drop close_unused_images
 qmp: Add command 'blockdev-backup'
 block: Allow backup on referenced named BlockDriverState
 block: Add blockdev-backup to transaction
 qemu-iotests: Test blockdev-backup in 055
 qemu-iotests: Image fleecing test case 083
   
block-migration.c   |   7 +-
block.c | 314 
   +++-
block/backup.c  |  26 
block/commit.c  |   2 +-
block/mirror.c  |   1 +
block/stream.c  |  42 +-
blockdev.c  | 122 ++--
blockjob.c  |  14 +-
hw/block/dataplane/virtio-blk.c |  19 ++-
include/block/block.h   |  29 +++-
include/block/block_int.h   |   9 +-
include/block/blockjob.h|   3 +
qapi-schema.json|  50 +++
qmp-commands.hx |  44 ++
tests/qemu-iotests/055  | 275 +--
tests/qemu-iotests/055.out  |   4 +-
tests/qemu-iotests/083  |  99 +
tests/qemu-iotests/083.out  |   5 +
tests/qemu-iotests/group|   1 +
19 files changed, 854 insertions(+), 212 deletions(-)
create mode 100755 tests/qemu-iotests/083
create mode 100644 tests/qemu-iotests/083.out
   
   -- 
   1.9.0
   
  
  Hi Fam,
  
  I want to rebase my patches on top of yours but I have trouble applying your
  series to 

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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/raw-posix.c | 59 +--
 1 file changed, 27 insertions(+), 32 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index e6b4c1f..7fc4a3a 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 *opts, Error **errp)
 {
 int fd;
 int result = 0;
@@ -1244,12 +1243,8 @@ 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_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -1410,13 +1405,17 @@ static int raw_get_info(BlockDriverState *bs, 
BlockDriverInfo *bdi)
 return 0;
 }
 
-static QEMUOptionParameter raw_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size
-},
-{ NULL }
+static QemuOptsList raw_create_opts = {
+.name = raw-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{ /* end of list */ }
+}
 };
 
 static BlockDriver bdrv_file = {
@@ -1431,7 +1430,7 @@ static BlockDriver bdrv_file = {
 .bdrv_reopen_commit = raw_reopen_commit,
 .bdrv_reopen_abort = raw_reopen_abort,
 .bdrv_close = raw_close,
-.bdrv_create = raw_create,
+.bdrv_create2 = raw_create,
 .bdrv_has_zero_init = bdrv_has_zero_init_1,
 .bdrv_co_get_block_status = raw_co_get_block_status,
 .bdrv_co_write_zeroes = raw_co_write_zeroes,
@@ -1448,7 +1447,7 @@ static BlockDriver bdrv_file = {
 .bdrv_get_allocated_file_size
 = raw_get_allocated_file_size,
 
-.create_options = raw_create_options,
+.create_opts = raw_create_opts,
 };
 
 /***/
@@ -1760,7 +1759,7 @@ static coroutine_fn int 
hdev_co_write_zeroes(BlockDriverState *bs,
 return -ENOTSUP;
 }
 
-static int hdev_create(const char *filename, QEMUOptionParameter *options,
+static int hdev_create(const char *filename, QemuOpts *opts,
Error **errp)
 {
 int fd;
@@ -1769,12 +1768,8 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options,
 int64_t total_size = 0;
 
 /* Read out options */
-while (options  options-name) {
-if (!strcmp(options-name, size)) {
-total_size = options-value.n / BDRV_SECTOR_SIZE;
-}
-options++;
-}
+total_size =
+qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
 
 fd = qemu_open(filename, O_WRONLY | O_BINARY);
 if (fd  0) {
@@ -1810,8 +1805,8 @@ static BlockDriver bdrv_host_device = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = raw_create_opts,
 .bdrv_co_write_zeroes = hdev_co_write_zeroes,
 
 .bdrv_aio_readv= raw_aio_readv,
@@ -1944,8 +1939,8 @@ static BlockDriver bdrv_host_floppy = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = raw_create_opts,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2055,8 +2050,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = raw_reopen_abort,
-.bdrv_create= hdev_create,
-.create_options = raw_create_options,
+.bdrv_create2= hdev_create,
+.create_opts = raw_create_opts,
 
 .bdrv_aio_readv = raw_aio_readv,
 .bdrv_aio_writev= raw_aio_writev,
@@ -2185,8 +2180,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_reopen_prepare = raw_reopen_prepare,
 .bdrv_reopen_commit  = raw_reopen_commit,
 .bdrv_reopen_abort   = 

[Qemu-devel] [PATCH v22 07/25] change block layer to support both QemuOpts and QEMUOptionParamter

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

Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block.c   | 121 ++
 block/cow.c   |   2 +-
 block/qcow.c  |   2 +-
 block/qcow2.c |   2 +-
 block/qed.c   |   2 +-
 block/raw_bsd.c   |   2 +-
 block/vhdx.c  |   2 +-
 block/vmdk.c  |   4 +-
 block/vvfat.c |   2 +-
 include/block/block.h |   7 +--
 include/block/block_int.h |   8 ++-
 qemu-img.c| 120 +
 12 files changed, 177 insertions(+), 97 deletions(-)

diff --git a/block.c b/block.c
index f1ef4b0..d9b1da3 100644
--- a/block.c
+++ b/block.c
@@ -408,6 +408,7 @@ typedef struct CreateCo {
 BlockDriver *drv;
 char *filename;
 QEMUOptionParameter *options;
+QemuOpts *opts;
 int ret;
 Error *err;
 } CreateCo;
@@ -420,7 +421,11 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 CreateCo *cco = opaque;
 assert(cco-drv);
 
-ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err);
+if (cco-drv-bdrv_create2) {
+ret = cco-drv-bdrv_create2(cco-filename, cco-opts, local_err);
+} else {
+ret = cco-drv-bdrv_create(cco-filename, cco-options, local_err);
+}
 if (local_err) {
 error_propagate(cco-err, local_err);
 }
@@ -428,7 +433,7 @@ static void coroutine_fn bdrv_create_co_entry(void *opaque)
 }
 
 int bdrv_create(BlockDriver *drv, const char* filename,
-QEMUOptionParameter *options, Error **errp)
+QEMUOptionParameter *options, QemuOpts *opts, Error **errp)
 {
 int ret;
 
@@ -437,11 +442,12 @@ int bdrv_create(BlockDriver *drv, const char* filename,
 .drv = drv,
 .filename = g_strdup(filename),
 .options = options,
+.opts = opts,
 .ret = NOT_DONE,
 .err = NULL,
 };
 
-if (!drv-bdrv_create) {
+if (!drv-bdrv_create  !drv-bdrv_create2) {
 error_setg(errp, Driver '%s' does not support image creation, 
drv-format_name);
 ret = -ENOTSUP;
 goto out;
@@ -473,7 +479,7 @@ out:
 }
 
 int bdrv_create_file(const char* filename, QEMUOptionParameter *options,
- Error **errp)
+ QemuOpts *opts, Error **errp)
 {
 BlockDriver *drv;
 Error *local_err = NULL;
@@ -485,7 +491,7 @@ int bdrv_create_file(const char* filename, 
QEMUOptionParameter *options,
 return -ENOENT;
 }
 
-ret = bdrv_create(drv, filename, options, local_err);
+ret = bdrv_create(drv, filename, options, opts, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 }
@@ -1248,7 +1254,8 @@ int bdrv_open(BlockDriverState **pbs, const char 
*filename,
 BlockDriverState *bs1;
 int64_t total_size;
 BlockDriver *bdrv_qcow2;
-QEMUOptionParameter *create_options;
+QEMUOptionParameter *create_options = NULL;
+QemuOpts *opts = NULL;
 QDict *snapshot_options;
 
 /* if snapshot, we create a temporary backing file and open it
@@ -1274,13 +1281,21 @@ 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);
+if (bdrv_qcow2-bdrv_create2) {
+opts = qemu_opts_create(bdrv_qcow2-create_opts, NULL, 0,
+error_abort);
+qemu_opt_set_number(opts, BLOCK_OPT_SIZE, total_size);
+} else {
+create_options =
+parse_option_parameters(, bdrv_qcow2-create_options, NULL);
+set_option_parameter_int(create_options, BLOCK_OPT_SIZE,
+ total_size);
+}
 
-ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, 
local_err);
+ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, opts,
+  local_err);
 free_option_parameters(create_options);
+qemu_opts_del(opts);
 if (ret  0) {
 error_setg_errno(errp, -ret, Could not create temporary overlay 
  '%s': %s, tmp_filename,
@@ -5229,7 +5244,10 @@ void bdrv_img_create(const char *filename, const char 
*fmt,
  Error **errp, bool quiet)
 {
 QEMUOptionParameter *param = NULL, *create_options = NULL;
-QEMUOptionParameter *backing_fmt, *backing_file, *size;
+QemuOptsList *create_opts = NULL;
+QemuOpts *opts = NULL;
+const char 

[Qemu-devel] [PATCH v22 04/25] improve assertion in qemu_opt_get functions

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

This patch would fix vvfat issue after changing to QemuOpts.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 util/qemu-option.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index c7639e8..df79235 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -603,7 +603,9 @@ bool qemu_opt_get_bool(QemuOpts *opts, const char *name, 
bool defval)
 }
 return defval;
 }
-assert(opt-desc  opt-desc-type == QEMU_OPT_BOOL);
+if (opt-desc) {
+assert(opt-desc-type == QEMU_OPT_BOOL);
+}
 return opt-value.boolean;
 }
 
@@ -625,7 +627,9 @@ uint64_t qemu_opt_get_number(QemuOpts *opts, const char 
*name, uint64_t defval)
 }
 return defval;
 }
-assert(opt-desc  opt-desc-type == QEMU_OPT_NUMBER);
+if (opt-desc) {
+assert(opt-desc-type == QEMU_OPT_NUMBER);
+}
 return opt-value.uint;
 }
 
@@ -645,7 +649,9 @@ uint64_t qemu_opt_get_size(QemuOpts *opts, const char 
*name, uint64_t defval)
 }
 return defval;
 }
-assert(opt-desc  opt-desc-type == QEMU_OPT_SIZE);
+if (opt-desc) {
+assert(opt-desc-type == QEMU_OPT_SIZE);
+}
 return opt-value.uint;
 }
 
-- 
1.7.12.4




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

2014-03-10 Thread Chunyan Liu
Signed-off-by: Dong Xu Wang wdon...@linux.vnet.ibm.com
Signed-off-by: Chunyan Liu cy...@suse.com
---
 block/qed.c | 114 
 block/qed.h |   3 +-
 2 files changed, 61 insertions(+), 56 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index db27f36..a22c2d9 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -621,53 +621,51 @@ out:
 return ret;
 }
 
-static int bdrv_qed_create(const char *filename, QEMUOptionParameter *options,
-   Error **errp)
+static int bdrv_qed_create(const char *filename, QemuOpts *opts, Error **errp)
 {
 uint64_t image_size = 0;
 uint32_t cluster_size = QED_DEFAULT_CLUSTER_SIZE;
 uint32_t table_size = QED_DEFAULT_TABLE_SIZE;
-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++;
-}
+char *backing_file = NULL;
+char *backing_fmt = NULL;
+int ret;
+
+image_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
+backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+cluster_size = qemu_opt_get_size_del(opts,
+ BLOCK_OPT_CLUSTER_SIZE,
+ QED_DEFAULT_CLUSTER_SIZE);
+table_size = qemu_opt_get_size_del(opts, BLOCK_OPT_TABLE_SIZE,
+   QED_DEFAULT_TABLE_SIZE);
 
 if (!qed_is_cluster_size_valid(cluster_size)) {
 fprintf(stderr, QED cluster size must be within range [%u, %u] and 
power of 2\n,
 QED_MIN_CLUSTER_SIZE, QED_MAX_CLUSTER_SIZE);
-return -EINVAL;
+ret = -EINVAL;
+goto finish;
 }
 if (!qed_is_table_size_valid(table_size)) {
 fprintf(stderr, QED table size must be within range [%u, %u] and 
power of 2\n,
 QED_MIN_TABLE_SIZE, QED_MAX_TABLE_SIZE);
-return -EINVAL;
+ret = -EINVAL;
+goto finish;
 }
 if (!qed_is_image_size_valid(image_size, cluster_size, table_size)) {
 fprintf(stderr, QED image size must be a non-zero multiple of 
 cluster size and less than % PRIu64  bytes\n,
 qed_max_image_size(cluster_size, table_size));
-return -EINVAL;
+ret = -EINVAL;
+goto finish;
 }
 
-return qed_create(filename, cluster_size, image_size, table_size,
-  backing_file, backing_fmt, errp);
+ret = qed_create(filename, cluster_size, image_size, table_size,
+ backing_file, backing_fmt, errp);
+
+finish:
+g_free(backing_file);
+g_free(backing_fmt);
+return ret;
 }
 
 typedef struct {
@@ -1575,43 +1573,51 @@ static int bdrv_qed_check(BlockDriverState *bs, 
BdrvCheckResult *result,
 return qed_check(s, result, !!fix);
 }
 
-static QEMUOptionParameter qed_create_options[] = {
-{
-.name = BLOCK_OPT_SIZE,
-.type = OPT_SIZE,
-.help = Virtual disk size (in bytes)
-}, {
-.name = BLOCK_OPT_BACKING_FILE,
-.type = OPT_STRING,
-.help = File name of a base image
-}, {
-.name = BLOCK_OPT_BACKING_FMT,
-.type = OPT_STRING,
-.help = Image format of the base image
-}, {
-.name = BLOCK_OPT_CLUSTER_SIZE,
-.type = OPT_SIZE,
-.help = Cluster size (in bytes),
-.value = { .n = QED_DEFAULT_CLUSTER_SIZE },
-}, {
-.name = BLOCK_OPT_TABLE_SIZE,
-.type = OPT_SIZE,
-.help = L1/L2 table size (in clusters)
-},
-{ /* end of list */ }
+static QemuOptsList qed_create_opts = {
+.name = qed-create-opts,
+.head = QTAILQ_HEAD_INITIALIZER(qed_create_opts.head),
+.desc = {
+{
+.name = BLOCK_OPT_SIZE,
+.type = QEMU_OPT_SIZE,
+.help = Virtual disk size
+},
+{
+.name = BLOCK_OPT_BACKING_FILE,
+.type = QEMU_OPT_STRING,
+.help = File name of a base image
+},
+{
+.name = BLOCK_OPT_BACKING_FMT,
+.type = QEMU_OPT_STRING,
+.help = Image format of the base image
+},
+{
+.name = BLOCK_OPT_CLUSTER_SIZE,
+.type = 

Re: [Qemu-devel] [PATCH 00/11] tcg-sparc updates

2014-03-10 Thread Mark Cave-Ayland

On 10/03/14 09:06, Artyom Tarasenko wrote:


Hi Mark,

I think a better test case would be looking for regressions in
x86/x86-64 images. I'd suspect someone would launch QEMU on a SPARC
machine to emulate some other platform. (Solaris containers would be
more efficient for running SPARC on SPARC)

Artyom


Oh so this is for host code generation rather than target? In that case 
I don't have any suitable hardware to test :/



ATB,

Mark.



Re: [Qemu-devel] armv8 support in qemu

2014-03-10 Thread Gaurav Sharma
What all is supported in the initial code for full system emulation ?
I am trying to bring up u-boot, which will require a minimal functionality.
But in the file [target-arm/cpu64.c] this piece of code raises some
questions to me :

static const ARMCPUInfo aarch64_cpus[] = {
#ifdef CONFIG_USER_ONLY
{ .name = any, .initfn = aarch64_any_initfn },
#endif
{ .name = NULL }
};

1. Is there any place else from where we are initializing aarch64 ?
2. In the folder [/hw/arm] I do not see any machine type initializing
aarch64 core ?



On Mon, Mar 10, 2014 at 2:20 PM, Alex Bennée alex.ben...@linaro.org wrote:


 Gaurav Sharma gauravs.2...@gmail.com writes:

  Hi,
  I just wanted to know what is the current status armv8 support in qemu ?
  After initial look into the source code i see the support for user mode.
  Even though aarch64-softmmu is supported in the target list, i do not see
  any corresponding code for init in target-arm/cpu64.c.

 Initial support is already in and the latest set of patches which get
 you to boot a kernel to user-space is currently on this very list for
 review.

 Cheers,

 --
 Alex Bennée
 QEMU/KVM Hacker for Linaro




Re: [Qemu-devel] [PULL] migration patches

2014-03-10 Thread Peter Maydell
On 10 March 2014 04:39, Amit Shah amit.s...@redhat.com wrote:
 Should I mark the subject line as [migration PULL], so you don't have
 to bother with the pull req?  Something else?

That seems a reasonable convention, yes, or [PULL migration] maybe.

thanks
-- PMM



[Qemu-devel] [PULL] Update OpenBIOS images to r1280

2014-03-10 Thread Mark Cave-Ayland
Hi Peter,

Please pull the latest OpenBIOS binary images in preparation for the next
release. These images contain numerous fixes/improvements for all of SPARC32, 
SPARC64 and PPC.


Many thanks,

Mark.


The following changes since commit f53f3d0a00b6df39ce8dfca942608e5b6a9a4f71:

  Merge remote-tracking branch 'remotes/kvaneesh/for-upstream' into staging 
(2014-03-08 12:38:43 +)

are available in the git repository at:


  https://github.com/mcayland/qemu.git qemu-openbios

for you to fetch changes up to 5264917bcf79d63d7a8df47eef1fd99597ba33a5:

  Update OpenBIOS images (2014-03-10 08:48:31 +)


Mark Cave-Ayland (1):
  Update OpenBIOS images

 pc-bios/README   |2 +-
 pc-bios/openbios-ppc |  Bin 729912 - 734008 bytes
 pc-bios/openbios-sparc32 |  Bin 381512 - 381512 bytes
 pc-bios/openbios-sparc64 |  Bin 1598376 - 1598376 bytes
 roms/openbios|2 +-
 5 files changed, 2 insertions(+), 2 deletions(-)



Re: [Qemu-devel] armv8 support in qemu

2014-03-10 Thread Peter Maydell
On 10 March 2014 09:24, Gaurav Sharma gauravs.2...@gmail.com wrote:
 What all is supported in the initial code for full system emulation ?
 I am trying to bring up u-boot, which will require a minimal functionality.
 But in the file [target-arm/cpu64.c] this piece of code raises some
 questions to me :

 static const ARMCPUInfo aarch64_cpus[] = {
 #ifdef CONFIG_USER_ONLY
 { .name = any, .initfn = aarch64_any_initfn },
 #endif
 { .name = NULL }
 };

The code you are looking for is in the patches on the list which
Alex just told you about -- it is not currently in master.

-- PMM



Re: [Qemu-devel] [PATCH v6] vl.c: Output error on invalid machine type

2014-03-10 Thread Markus Armbruster
mreza...@redhat.com writes:

 From: Miroslav Rezanina mreza...@redhat.com

 Output error message using qemu's error_report() function when user
 provides the invalid machine type on the command line. This also saves
 time to find what issue is when you downgrade from one version of qemu
 to another that doesn't support required machine type yet (the version
 user downgraded to have to have this patch applied too, of course).

 Signed-off-by: Miroslav Rezanina mreza...@redhat.com
 ---
 v6:
  - print help instead of list supported machines on error
  vl.c | 18 --
  1 file changed, 12 insertions(+), 6 deletions(-)

 diff --git a/vl.c b/vl.c
 index 383be1b..3297c0a 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -2600,13 +2600,19 @@ static QEMUMachine *machine_parse(const char *name)
   static QEMUMachine *machine_parse(const char *name)
   {
   QEMUMachine *m, *machine = NULL;

   if (name) {
   machine = find_machine(name);
   }
  if (machine) {
  return machine;
  }
 -printf(Supported machines are:\n);
 -for (m = first_machine; m != NULL; m = m-next) {
 -if (m-alias) {
 -printf(%-20s %s (alias of %s)\n, m-alias, m-desc, m-name);
 +
 +if (name  !is_help_option(name)) {

I don't think !name can happen, but you're sticking to what the existing
code does.  Okay.

 +error_report(Unsupported machine type);
 +printf(\nUse '-M help' to list supported machines!\n);

I like this.  It gives a concise error message followed by a hint,
instead of dumping lengthy help on me without a clear indication why I
need it.

-M TYPE is sugar for -machine type=TYPE.  It was deprecated in commit
80f52a6, and purged from documentation and help texts, except for two
occurences in qemu-doc.texi.

Unless we un-deprecate -M, this patch should point to the documented
option -machine type=help, and we should update qemu-doc.texi to use
-machine instead of -M.

 +} else {
 +printf(Supported machines are:\n);
 +for (m = first_machine; m != NULL; m = m-next) {
 +if (m-alias) {
 +printf(%-20s %s (alias of %s)\n, m-alias, m-desc, 
 m-name);
 +}
 +printf(%-20s %s%s\n, m-name, m-desc,
 +   m-is_default ?  (default) : );
  }
 -printf(%-20s %s%s\n, m-name, m-desc,
 -   m-is_default ?  (default) : );
  }
  exit(!name || !is_help_option(name));
  }



Re: [Qemu-devel] test-qapi-visit causes clang -fsanitize=undefined warning

2014-03-10 Thread Markus Armbruster
Peter Maydell peter.mayd...@linaro.org writes:

 On 8 March 2014 12:39, Peter Maydell peter.mayd...@linaro.org wrote:
 I've noticed that the tests/test-qapi-visit.c code provokes the following
 complaint from clang's -fsanitize=undefined undefined-behaviour
 checker when you run 'make check':

 tests/test-qapi-visit.c:462:33: runtime error: member access within
 null pointer of type 'UserDefA' (aka 'struct UserDefA')

 There's also this clang compile warning which is probably not
 related but is also in code dealing with unions:

   CCtests/test-qmp-output-visitor.o
 /home/petmay01/linaro/qemu-for-merges/tests/test-qmp-output-visitor.c:452:17:
 warning: implicit conversion from enumeration type
   'enum UserDefUnionKind' to different enumeration type
 'UserDefFlatUnionKind' (aka 'enum UserDefFlatUnionKind')
   [-Wenum-conversion]
 tmp-kind = USER_DEF_UNION_KIND_A;
   ~ ^
 1 warning generated.

Thanks, I'll look into both.



[Qemu-devel] [Bug 1289527] Re: qemu-aarch64-static: java dies with SIGILL

2014-03-10 Thread Alex Bennée
For SIGILL's it's useful to have the qemu log with -d unimp output.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1289527

Title:
  qemu-aarch64-static: java dies with SIGILL

Status in QEMU:
  New
Status in “qemu” package in Ubuntu:
  Confirmed

Bug description:
  qemu-aarch64-static from qemu-user-static 1.7.0+dfsg-3ubuntu5
  (I haven't tried reproducing w/ upstream git yet)

  In an arm64 trusty chroot on an amd64 system:

  dannf@server-75e0210e-4f99-4c86-9277-3201ab7b6afd:~$ java
  #
  # A fatal error has been detected by the Java Runtime Environment:
  #
  #  SIGILL (0x4) at pc=0x0040098e8070, pid=15034, tid=274902467056
  #
  # JRE version:  (7.0_51-b31) (build )
  # Java VM: OpenJDK 64-Bit Server VM (25.0-b59 mixed mode linux-aarch64 
compressed oops)
  # Problematic frame:
  # v  ~BufferBlob::flush_icache_stub
  #
  # Failed to write core dump. Core dumps have been disabled. To enable core 
dumping, try ulimit -c unlimited before starting Java again
  #
  # An error report file with more information is saved as:
  # /home/dannf/hs_err_pid15034.log
  #
  # If you would like to submit a bug report, please visit:
  #   http://bugreport.sun.com/bugreport/crash.jsp
  #
  qemu: uncaught target signal 6 (Aborted) - core dumped
  Aborted (core dumped)
  dannf@server-75e0210e-4f99-4c86-9277-3201ab7b6afd:~$

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1289527/+subscriptions



[Qemu-devel] Hello from a new comer

2014-03-10 Thread Edgar Simon
Hi everybody,

As a newcomer at qemu-devel, I would like to  introduce myself to you. I am an 
engineer student in embedded systems. I already worked with qemu for school 
projects. However I never contributed to qemu or to another open source 
project. 

I think qemu is a powerful and convenient emulator. I would like to contribute 
to it. First because it's a nice project which deals about things I like  : 
computer architecture, emulation, C language... Second because I am eager to 
learn more in these fields and gain practical experience. Third because I need 
to use qemu for some emulation that currently does not exist yet (from what I 
know).

What I would like to do is to do is to be able to emulate the STM32L platform 
(it's a ARM CortexM3 based micro-controller). 

I know it seems ambitious, but I want to try it. I saw that other cortexM3 
platforms were already emulated in qemu. I think I will start from there and 
check for the implementation of the existing peripherals to gain knowledge 
about how to do the same thing for the STM32L specific peripherals.

What do you think? Do you find that it's a right start-point?

Best Regards
Edgar Simon
  

Re: [Qemu-devel] [PATCH] vnc: Fix tight_detect_smooth_image() for lossless case

2014-03-10 Thread Markus Armbruster
Ping?

Markus Armbruster arm...@redhat.com writes:

 VncTight member uint8_t quality is either (uint8_t)-1 for lossless or
 less than 10 for lossy.

 tight_detect_smooth_image() first promotes it to int, then compares
 with -1.  Always unequal, so we always execute the lossy code.  Reads
 beyond tight_conf[] and returns crap when quality is actually
 lossless.

 Compare to (uint8_t)-1 instead, like we do elsewhere.

 Spotted by Coverity.

 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  ui/vnc-enc-tight.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c
 index e6966ae..59b59c0 100644
 --- a/ui/vnc-enc-tight.c
 +++ b/ui/vnc-enc-tight.c
 @@ -330,7 +330,7 @@ tight_detect_smooth_image(VncState *vs, int w, int h)
  } else {
  errors = tight_detect_smooth_image16(vs, w, h);
  }
 -if (quality != -1) {
 +if (quality != (uint8_t)-1) {
  return (errors  tight_conf[quality].jpeg_threshold);
  }
  return (errors  tight_conf[compression].gradient_threshold);



[Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption

2014-03-10 Thread wzis
I can't test from git: on one box with git, it failed for the pixman
missing. and the RHEL 5.3 doesn't have git.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1289898

Title:
  qemu-system-ppc64 easily cause file corruption

Status in QEMU:
  New

Bug description:
  the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
  Previously I was using QEMU 1.5.x for several months with no problem. But 
after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:

  * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 5.9 
PPC VM, found the size is correct, but the content is corrupted from the middle 
of the 90+ MB file.  re-transfer again, got a correct file. But after untar, 
found some extracted files corrupted.
  The extracted file corruption happened several times, and also the filesystem 
in the VM had corrupted several times, had to restore the boot image to recover.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions



Re: [Qemu-devel] [PATCH] vnc: Fix tight_detect_smooth_image() for lossless case

2014-03-10 Thread Gerd Hoffmann
On Mo, 2014-03-10 at 11:10 +0100, Markus Armbruster wrote:
 Ping?

picked up this (and some other vnc bits) vnc pull req will go out soon.

cheers,
  Gerd





Re: [Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption

2014-03-10 Thread Peter Maydell
On 10 March 2014 10:00, wzis w...@hotmail.com wrote:
 I can't test from git: on one box with git, it failed for the pixman
 missing

Did you try the git submodule command that configure
suggests when it can't find pixman? That will pull
in and build a local copy of pixman for QEMU.

thanks
-- PMM



[Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption

2014-03-10 Thread Paolo Bonzini
Also, RHEL5 does have git in the EPEL repository.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1289898

Title:
  qemu-system-ppc64 easily cause file corruption

Status in QEMU:
  New

Bug description:
  the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
  Previously I was using QEMU 1.5.x for several months with no problem. But 
after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:

  * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 5.9 
PPC VM, found the size is correct, but the content is corrupted from the middle 
of the 90+ MB file.  re-transfer again, got a correct file. But after untar, 
found some extracted files corrupted.
  The extracted file corruption happened several times, and also the filesystem 
in the VM had corrupted several times, had to restore the boot image to recover.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions



Re: [Qemu-devel] [PATCH qom-cpu 1/6] cpu: Introduce CPUClass::parse_features() hook

2014-03-10 Thread Igor Mammedov
On Sun, 09 Mar 2014 16:45:20 +0100
Andreas Färber afaer...@suse.de wrote:

 Am 04.03.2014 03:55, schrieb Andreas Färber:
  Adapt the X86CPU implementation to suit the generic hook.
  This involves a cleanup of error handling to cope with NULL errp.
  
  Signed-off-by: Andreas Färber afaer...@suse.de
  ---
   include/qom/cpu.h |  3 +++
   target-i386/cpu.c | 36 +---
   2 files changed, 24 insertions(+), 15 deletions(-)
 
 X86CPU subclasses require the following trivial rebase:
 
 diff --cc target-i386/cpu.c
 index 3c3a987,653840a..000
 --- a/target-i386/cpu.c
 +++ b/target-i386/cpu.c
 @@@ -1941,7 -1923,15 +1946,7 @@@ X86CPU *cpu_x86_create(const char *cpu_
   object_unref(OBJECT(cpu));
   #endif
 
 - cpu_x86_parse_featurestr(cpu, features, error);
  -/* Emulate per-model subclasses for global properties */
  -typename = g_strdup_printf(%s- TYPE_X86_CPU, name);
  -qdev_prop_set_globals_for_type(DEVICE(cpu), typename, error);
  -g_free(typename);
  -if (error) {
  -goto out;
  -}
  -
 + x86_cpu_parse_featurestr(CPU(cpu), features, error);
   if (error) {
   goto out;
   }
 @@@ -2790,7 -2753,7 +2795,8 @@@ static void x86_cpu_common_class_init(O
   cc-reset = x86_cpu_reset;
   cc-reset_dump_flags = CPU_DUMP_FPU | CPU_DUMP_CCOP;
 
  +cc-class_by_name = x86_cpu_class_by_name;
 + cc-parse_features = x86_cpu_parse_featurestr;
   cc-has_work = x86_cpu_has_work;
   cc-do_interrupt = x86_cpu_do_interrupt;
   cc-dump_state = x86_cpu_dump_state;
 
 Andreas
 

looks good,

Reviewed-by: Igor Mammedov imamm...@redhat.com



Re: [Qemu-devel] Call for testing QEMU aarch64-linux-user emulation

2014-03-10 Thread Alex Bennée

Peter Maydell peter.mayd...@linaro.org writes:

 On 9 March 2014 23:37, Dann Frazier dann.fraz...@canonical.com wrote:
 Also - I've found an issue with running OpenJDK in the latest upstream git:

 root@server-75e0210e-4f99-4c86-9277-3201ab7b6afd:/root# java
 #
 [thread 274902467056 also had an error]# A fatal error has been
 detected by the Java Runtime Environment:

 #
 #  SIGSEGV (0xb) at pc=0x, pid=9960, tid=297441608176

 Not sure there's much point looking very deeply into this.
 Java programs are threaded, threaded programs don't work
 under QEMU = don't try to run Java under QEMU :-)

Having said that I'm sure there was another SIGILL related crash on
Launchpad and I think we would be interested in those. Is JAVA really
that buggy under QEMU just because of threading?


 thanks
 -- PMM

-- 
Alex Bennée




[Qemu-devel] [PATCH] net: L2TPv3 transport

2014-03-10 Thread anton . ivanov
From: Anton Ivanov antiv...@cisco.com

This tranport allows to connect a qemu nic to a static Ethernet
over L2TPv3 tunnel. The transport supports all options present
in the linux kernel implementation. It allows qemu to connect
to any linux host running kernel 3.3+, most routers and network

Signed-off-by: Anton Ivanov antiv...@cisco.com
---
 net/Makefile.objs |1 +
 net/clients.h |2 +
 net/l2tpv3.c  |  585 +
 net/net.c |3 +
 qapi-schema.json  |   59 +-
 qemu-options.hx   |   94 +++--
 6 files changed, 730 insertions(+), 14 deletions(-)
 create mode 100644 net/l2tpv3.c

diff --git a/net/Makefile.objs b/net/Makefile.objs
index 4854a14..160214e 100644
--- a/net/Makefile.objs
+++ b/net/Makefile.objs
@@ -2,6 +2,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o
 common-obj-y += socket.o
 common-obj-y += dump.o
 common-obj-y += eth.o
+common-obj-$(CONFIG_LINUX) += l2tpv3.o
 common-obj-$(CONFIG_POSIX) += tap.o
 common-obj-$(CONFIG_LINUX) += tap-linux.o
 common-obj-$(CONFIG_WIN32) += tap-win32.o
diff --git a/net/clients.h b/net/clients.h
index 7793294..bbf177c 100644
--- a/net/clients.h
+++ b/net/clients.h
@@ -47,6 +47,8 @@ int net_init_tap(const NetClientOptions *opts, const char 
*name,
 int net_init_bridge(const NetClientOptions *opts, const char *name,
 NetClientState *peer);
 
+int net_init_l2tpv3(const NetClientOptions *opts, const char *name,
+NetClientState *peer);
 #ifdef CONFIG_VDE
 int net_init_vde(const NetClientOptions *opts, const char *name,
  NetClientState *peer);
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
new file mode 100644
index 000..ed2226e
--- /dev/null
+++ b/net/l2tpv3.c
@@ -0,0 +1,585 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2012-2014 Cisco Systems
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include linux/ip.h
+#include netdb.h
+#include config-host.h
+#include net/net.h
+#include clients.h
+#include monitor/monitor.h
+#include qemu-common.h
+#include qemu/error-report.h
+#include qemu/option.h
+#include qemu/sockets.h
+#include qemu/iov.h
+#include qemu/main-loop.h
+
+
+/* The buffer size needs to be investigated for optimum numbers and
+ * optimum means of paging in on different systems. This size is
+ * chosen to be sufficient to accommodate one packet with some headers
+ */
+
+#define BUFFER_ALIGN sysconf(_SC_PAGESIZE)
+#define BUFFER_SIZE 2048
+#define IOVSIZE 2
+#define MAX_L2TPV3_MSGCNT 32
+#define MAX_L2TPV3_IOVCNT (MAX_L2TPV3_MSGCNT * IOVSIZE)
+
+/* Header set to 0x3 signifies a data packet */
+
+#define L2TPV3_DATA_PACKET 0x3
+
+
+/* This protocol number is passed getaddrinfo(), and not
+ * used directly. If you give gettaddrinfo() what one is
+ * supposed to give - INET, RAW, 0, the result is not
+ * set correctly.
+ * Setting the args to INET, RAW, L2TPv3 is the lowest pain
+ * workaround in this case as it allows common raw and udp
+ * setup.
+ */
+
+#ifndef IPPROTO_L2TP
+#define IPPROTO_L2TP 0x73
+#endif
+
+typedef struct NetL2TPV3State {
+NetClientState nc;
+int fd;
+
+/*
+ * these are used for xmit - that happens packet a time
+ * and for first sign of life packet (easier to parse that once)
+ */
+
+uint8_t *header_buf;
+struct iovec *vec;
+
+/*
+ * these are used for receive - try to eat up to 32 packets at a time
+ */
+
+struct mmsghdr *msgvec;
+
+/*
+ * peer address
+ */
+
+struct sockaddr_storage *dgram_dst;
+uint32_t dst_size;
+
+/*
+ * L2TPv3 parameters
+ */
+
+uint64_t rx_cookie;
+uint64_t tx_cookie;
+uint32_t rx_session;
+uint32_t tx_session;
+uint32_t header_size;
+uint32_t counter;
+
+/*
+ * Precomputed offsets
+ */
+
+uint32_t offset;
+uint32_t cookie_offset;
+uint32_t counter_offset;
+  

Re: [Qemu-devel] [PATCH] qdev: Fix bus dependency of DeviceState::hotpluggable getter

2014-03-10 Thread Igor Mammedov
On Sun, 9 Mar 2014 18:55:05 +0200
Michael S. Tsirkin m...@redhat.com wrote:

 On Sun, Mar 09, 2014 at 05:48:57PM +0100, Andreas Färber wrote:
  Am 09.03.2014 17:40, schrieb Michael S. Tsirkin:
   On Fri, Mar 07, 2014 at 07:13:18PM +0100, Andreas Färber wrote:
   Commit 1a37eca107cece3ed454bae29eef0bd1fac4a244 (qdev: add
   hotpluggable property to Device) added a property hotpluggable to
   each device, with its getter accessing parent_bus-allow_hotplug.
  
   Add a NULL check.
  
   Cc: Igor Mammedov imamm...@redhat.com
   Signed-off-by: Andreas Färber afaer...@suse.de
   
   Fair enough but I'm guessing we should
   assume devices without a parent are not
   hotpluggable, should we not?
   
   Without a bus what handles hotplug?
  
  The device has to, in its realize function.
   ---
hw/core/qdev.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
  
   diff --git a/hw/core/qdev.c b/hw/core/qdev.c
   index 749c83a..cb07863 100644
   --- a/hw/core/qdev.c
   +++ b/hw/core/qdev.c
   @@ -735,7 +735,8 @@ static bool device_get_hotpluggable(Object *obj, 
   Error **err)
DeviceClass *dc = DEVICE_GET_CLASS(obj);
DeviceState *dev = DEVICE(obj);

   -return dc-hotpluggable  dev-parent_bus-allow_hotplug;
   +return dc-hotpluggable  (dev-parent_bus == NULL ||
   +dev-parent_bus-allow_hotplug);
   
   So maybe this should be:
   return dc-hotpluggable  dev-parent_bus 
  dev-parent_bus-allow_hotplug;
   
   ?
  
  Hmm... that would render non-x86 CPUs non-hotpluggable. I guess we need
  to check dc-bus_type for a NULL value and if non-NULL use your variant
  and otherwise mine.
  I'll give it some more thought.
  
  Thanks,
  Andreas
 
 Or clear dc-hotpluggable if there's no parent bus
 and we don't want to allow hotplug.
 
 I'm beginning to think your patch is the right one
 after all...
Before hotplug rework all devices were assumed to be hotpluggable,
the non-hotpluggable ones explicitly cleared dc-hotpluggable in
class_init(), rework hasn't changed it so Andreas's patch looks
better as to not block hotplug on bus-less devices.

Later if we implement bus-less hotplug with links, we can
add link set hook to that will call hotplug handler in the same manner
as it's done for bus based devices.

  
   
}

static void device_initfn(Object *obj)
   -- 
   1.8.4.5
  
  -- 
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
  GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg




Re: [Qemu-devel] Call for testing QEMU aarch64-linux-user emulation

2014-03-10 Thread Peter Maydell
On 10 March 2014 11:28, Alex Bennée alex.ben...@linaro.org wrote:

 Peter Maydell peter.mayd...@linaro.org writes:

 On 9 March 2014 23:37, Dann Frazier dann.fraz...@canonical.com wrote:
 Also - I've found an issue with running OpenJDK in the latest upstream git:

 root@server-75e0210e-4f99-4c86-9277-3201ab7b6afd:/root# java
 #
 [thread 274902467056 also had an error]# A fatal error has been
 detected by the Java Runtime Environment:

 #
 #  SIGSEGV (0xb) at pc=0x, pid=9960, tid=297441608176

 Not sure there's much point looking very deeply into this.
 Java programs are threaded, threaded programs don't work
 under QEMU = don't try to run Java under QEMU :-)

 Having said that I'm sure there was another SIGILL related crash on
 Launchpad and I think we would be interested in those. Is JAVA really
 that buggy under QEMU just because of threading?

My experience is that typically it's take a day investigating
what's going wrong in a complicated and hard to debug guest
program, determine that it's the same cluster of issues we
already know about and have no plan to fix. So 99% of the
time it's just not worth investigating if the guest program
uses threads at all.

thanks
-- PMM



Re: [Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption

2014-03-10 Thread wzis
Yes, I tried that, but it failed due to some php component missing.

 Date: Mon, 10 Mar 2014 10:45:34 +
 From: peter.mayd...@linaro.org
 To: w...@hotmail.com
 Subject: Re: [Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause 
 file corruption
 
 On 10 March 2014 10:00, wzis w...@hotmail.com wrote:
  I can't test from git: on one box with git, it failed for the pixman
  missing
 
 Did you try the git submodule command that configure
 suggests when it can't find pixman? That will pull
 in and build a local copy of pixman for QEMU.
 
 thanks
 -- PMM
 
 -- 
 You received this bug notification because you are subscribed to the bug
 report.
 https://bugs.launchpad.net/bugs/1289898
 
 Title:
   qemu-system-ppc64 easily cause file corruption
 
 Status in QEMU:
   New
 
 Bug description:
   the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
   Previously I was using QEMU 1.5.x for several months with no problem. But 
 after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
 QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:
 
   * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 
 5.9 PPC VM, found the size is correct, but the content is corrupted from the 
 middle of the 90+ MB file.  re-transfer again, got a correct file. But after 
 untar, found some extracted files corrupted.
   The extracted file corruption happened several times, and also the 
 filesystem in the VM had corrupted several times, had to restore the boot 
 image to recover.
 
 To manage notifications about this bug go to:
 https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1289898

Title:
  qemu-system-ppc64 easily cause file corruption

Status in QEMU:
  New

Bug description:
  the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
  Previously I was using QEMU 1.5.x for several months with no problem. But 
after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:

  * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 5.9 
PPC VM, found the size is correct, but the content is corrupted from the middle 
of the 90+ MB file.  re-transfer again, got a correct file. But after untar, 
found some extracted files corrupted.
  The extracted file corruption happened several times, and also the filesystem 
in the VM had corrupted several times, had to restore the boot image to recover.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions



Re: [Qemu-devel] [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption

2014-03-10 Thread wzis
On my RHEL 5.3 box, there are too many problems to get git work. And on
the CentOS 6.4 it has many problem to get pixman, so I just can't test
the latest qemu unless you also put the pixman in as 1.7.0 does.

 Date: Mon, 10 Mar 2014 10:53:48 +
 From: bonz...@gnu.org
 To: w...@hotmail.com
 Subject: [Bug 1289898] Re: qemu-system-ppc64 easily cause file corruption
 
 Also, RHEL5 does have git in the EPEL repository.
 
 -- 
 You received this bug notification because you are subscribed to the bug
 report.
 https://bugs.launchpad.net/bugs/1289898
 
 Title:
   qemu-system-ppc64 easily cause file corruption
 
 Status in QEMU:
   New
 
 Bug description:
   the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
   Previously I was using QEMU 1.5.x for several months with no problem. But 
 after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
 QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:
 
   * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 
 5.9 PPC VM, found the size is correct, but the content is corrupted from the 
 middle of the 90+ MB file.  re-transfer again, got a correct file. But after 
 untar, found some extracted files corrupted.
   The extracted file corruption happened several times, and also the 
 filesystem in the VM had corrupted several times, had to restore the boot 
 image to recover.
 
 To manage notifications about this bug go to:
 https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1289898

Title:
  qemu-system-ppc64 easily cause file corruption

Status in QEMU:
  New

Bug description:
  the qemu-system-ppc64 is used to run RHEL5.9 for IBM Power on RHEL 5.3.
  Previously I was using QEMU 1.5.x for several months with no problem. But 
after the RHEL 5.3 host damaged, and rebuilt, now I tried both QEMU 1.6.2 and 
QEMU 1.7.0, found both can easily cause file corruptions. Symptoms:

  * using scp to transfer a tar.bz file from the RHEL 5.3 host to the RHEL 5.9 
PPC VM, found the size is correct, but the content is corrupted from the middle 
of the 90+ MB file.  re-transfer again, got a correct file. But after untar, 
found some extracted files corrupted.
  The extracted file corruption happened several times, and also the filesystem 
in the VM had corrupted several times, had to restore the boot image to recover.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1289898/+subscriptions



Re: [Qemu-devel] [PATCH 3/4] linux-user: set minimum kernel version to2.6.322

2014-03-10 Thread Riku Voipio
On 7 March 2014 10:45, Peter Maydell peter.mayd...@linaro.org wrote:
 On 7 March 2014 02:19, Riku Voipio riku.voi...@linaro.org wrote:
  So you agree these patches are the way to go?

 I haven't actually reviewed them but I think the idea is right,
 yes.

With the hard freeze getting close,  and me being away until wednesday, I
think I'll send a pull req for the reviewed patches now in que + this patch
from
this series. While this patch hasn't any reviews, it is probably less
controversial
than the others, and allows distributions to stop calling the configure
option.

Riku


Re: [Qemu-devel] [PATCH] target-arm: Fix intptr_t vs tcg_target_long

2014-03-10 Thread Peter Maydell
On 5 March 2014 18:14, Richard Henderson r...@twiddle.net wrote:
 Fixes a build error when these are different, e.g. x32.

 Signed-off-by: Richard Henderson r...@twiddle.net

Reviewed-by: Peter Maydell peter.mayd...@linaro.org

A quick grep of the uses of tcg_gen_exit_tb() suggests
we would be better to change this function to take
(TranslationBlock *tb, int tb_exit_code), possibly
also with a special case for 0 if tcg_gen_exit_tb(NULL, 0)
seems too verbose.

I'll apply this to target-arm as the fix for 2.0, though.

 ---
  target-arm/translate-a64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
 index 08ac659..37e05e8 100644
 --- a/target-arm/translate-a64.c
 +++ b/target-arm/translate-a64.c
 @@ -210,7 +210,7 @@ static inline void gen_goto_tb(DisasContext *s, int n, 
 uint64_t dest)
  if (use_goto_tb(s, n, dest)) {
  tcg_gen_goto_tb(n);
  gen_a64_set_pc_im(dest);
 -tcg_gen_exit_tb((tcg_target_long)tb + n);
 +tcg_gen_exit_tb((intptr_t)tb + n);
  s-is_jmp = DISAS_TB_JUMP;
  } else {
  gen_a64_set_pc_im(dest);
 --
 1.8.5.3


thanks
-- PMM



[Qemu-devel] [PATCH 1/2] tests/libqtest: Fix possible deadlock in qtest initialization

2014-03-10 Thread Marcel Apfelbaum
'socket_accept' waits for Qemu to init its unix socket.
If Qemu encounters an error during command line parsing,
it can exit before initializing the communication channel.
It gets worse as the make check-qtest-* gets stuck without
notifying which test exactly has problems, so debugging can
be a challenge.

The solution has two parts:
 - Use a timeout for the socket.
 - Expose a qtest_state_valid that checks that the connections
   with Qemu are OK.
Asserting qtest_state_valid in each test after qtest_init
is a must, as we need to trace which test failed.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
---
 tests/libqtest.c | 26 +-
 tests/libqtest.h |  8 
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/tests/libqtest.c b/tests/libqtest.c
index f587d36..93dfa81 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -34,6 +34,7 @@
 #include qapi/qmp/json-parser.h
 
 #define MAX_IRQ 256
+#define SOCKET_TIMEOUT 5
 
 QTestState *global_qtest;
 
@@ -83,7 +84,6 @@ static int socket_accept(int sock)
 do {
 ret = accept(sock, (struct sockaddr *)addr, addrlen);
 } while (ret == -1  errno == EINTR);
-g_assert_no_errno(ret);
 close(sock);
 
 return ret;
@@ -111,6 +111,8 @@ QTestState *qtest_init(const char *extra_args)
 gchar *command;
 const char *qemu_binary;
 struct sigaction sigact;
+struct timeval socket_timeout = { .tv_sec = SOCKET_TIMEOUT,
+  .tv_usec = 0 };
 
 qemu_binary = getenv(QTEST_QEMU_BINARY);
 g_assert(qemu_binary != NULL);
@@ -123,6 +125,11 @@ QTestState *qtest_init(const char *extra_args)
 sock = init_socket(socket_path);
 qmpsock = init_socket(qmp_socket_path);
 
+setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)socket_timeout,
+   sizeof(socket_timeout));
+setsockopt(qmpsock, SOL_SOCKET, SO_RCVTIMEO, (void *)socket_timeout,
+   sizeof(socket_timeout));
+
 /* Catch SIGABRT to clean up on g_assert() failure */
 sigact = (struct sigaction){
 .sa_handler = sigabrt_handler,
@@ -147,7 +154,9 @@ QTestState *qtest_init(const char *extra_args)
 }
 
 s-fd = socket_accept(sock);
-s-qmp_fd = socket_accept(qmpsock);
+if (s-fd = 0) {
+s-qmp_fd = socket_accept(qmpsock);
+}
 unlink(socket_path);
 unlink(qmp_socket_path);
 g_free(socket_path);
@@ -158,9 +167,11 @@ QTestState *qtest_init(const char *extra_args)
 s-irq_level[i] = false;
 }
 
-/* Read the QMP greeting and then do the handshake */
-qtest_qmp_discard_response(s, );
-qtest_qmp_discard_response(s, { 'execute': 'qmp_capabilities' });
+if (qtest_state_valid(s)) {
+/* Read the QMP greeting and then do the handshake */
+qtest_qmp_discard_response(s, );
+qtest_qmp_discard_response(s, { 'execute': 'qmp_capabilities' });
+}
 
 if (getenv(QTEST_STOP)) {
 kill(s-qemu_pid, SIGSTOP);
@@ -169,6 +180,11 @@ QTestState *qtest_init(const char *extra_args)
 return s;
 }
 
+bool qtest_state_valid(QTestState *s)
+{
+return (s-fd = 0)  (s-qmp_fd = 0);
+}
+
 void qtest_quit(QTestState *s)
 {
 sigaction(SIGABRT, s-sigact_old, NULL);
diff --git a/tests/libqtest.h b/tests/libqtest.h
index 9deebdc..39a37b1 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -45,6 +45,14 @@ QTestState *qtest_init(const char *extra_args);
 void qtest_quit(QTestState *s);
 
 /**
+ * qtest_state_valid:
+ * @state: #QTestState instance to check
+ *
+ * Returns: True if qtest was initialized successfully
+ */
+bool qtest_state_valid(QTestState *s);
+
+/**
  * qtest_qmp_discard_response:
  * @s: #QTestState instance to operate on.
  * @fmt...: QMP message to send to qemu
-- 
1.8.3.1




[Qemu-devel] [PATCH 0/2] tests: Fix possible deadlock in qtest initialization

2014-03-10 Thread Marcel Apfelbaum
'socket_accept' waits for Qemu to init its unix socket.
If Qemu encounters an error during command line parsing,
it can exit before initializing the communication channel.
It gets worse as the make check-qtest-* gets stuck without
notifying which test exactly has problems, so debugging can
be a challenge.

The solution has two parts:
 - Use a timeout for the socket.
 - Expose a qtest_state_valid that checks that the connections
   with Qemu are OK.
Asserting qtest_state_valid in each test after qtest_init
is a must, as we need to trace which test failed.

As a nice side effect, even the nop tests will
check at least that the device/option is still
supported by Qemu.

Note: I encountered this issue while working on 'Machine as QOM object';
because of my changes some tests tried to run qtest with a not supported
machine. The result was 'make check' getting stuck with no clue why is 
happening.

Marcel Apfelbaum (2):
  tests/libqtest: Fix possible deadlock in qtest initialization
  tests: check that qtest state is valid before starting the test

 tests/acpi-test.c |  4 +++-
 tests/blockdev-test.c |  4 +++-
 tests/boot-order-test.c   |  4 +++-
 tests/e1000-test.c|  5 -
 tests/eepro100-test.c |  1 +
 tests/endianness-test.c   | 15 ---
 tests/fdc-test.c  |  5 -
 tests/fw_cfg-test.c   |  2 ++
 tests/hd-geo-test.c   | 20 
 tests/i440fx-test.c   | 10 --
 tests/ide-test.c  |  5 -
 tests/ipoctal232-test.c   |  5 -
 tests/libqtest.c  | 26 +-
 tests/libqtest.h  |  8 
 tests/m48t59-test.c   |  1 +
 tests/ne2000-test.c   |  5 -
 tests/pcnet-test.c|  5 -
 tests/qdev-monitor-test.c |  4 +++-
 tests/qom-test.c  | 10 --
 tests/rtc-test.c  |  4 +++-
 tests/rtl8139-test.c  |  5 -
 tests/tmp105-test.c   |  4 +++-
 tests/tpci200-test.c  |  5 -
 tests/virtio-net-test.c   |  5 -
 tests/vmxnet3-test.c  |  5 -
 25 files changed, 135 insertions(+), 32 deletions(-)

-- 
1.8.3.1




[Qemu-devel] [PATCH 2/2] tests: check that qtest state is valid before starting the test

2014-03-10 Thread Marcel Apfelbaum
It is possible that the argument parsing went wrong,
check that qstate is valid after qtest_init.
As a nice side effect, even the nop tests will
check at least that the device/option is still
supported by Qemu.

Signed-off-by: Marcel Apfelbaum marce...@redhat.com
---
 tests/acpi-test.c |  4 +++-
 tests/blockdev-test.c |  4 +++-
 tests/boot-order-test.c   |  4 +++-
 tests/e1000-test.c|  5 -
 tests/eepro100-test.c |  1 +
 tests/endianness-test.c   | 15 ---
 tests/fdc-test.c  |  5 -
 tests/fw_cfg-test.c   |  2 ++
 tests/hd-geo-test.c   | 20 
 tests/i440fx-test.c   | 10 --
 tests/ide-test.c  |  5 -
 tests/ipoctal232-test.c   |  5 -
 tests/m48t59-test.c   |  1 +
 tests/ne2000-test.c   |  5 -
 tests/pcnet-test.c|  5 -
 tests/qdev-monitor-test.c |  4 +++-
 tests/qom-test.c  | 10 --
 tests/rtc-test.c  |  4 +++-
 tests/rtl8139-test.c  |  5 -
 tests/tmp105-test.c   |  4 +++-
 tests/tpci200-test.c  |  5 -
 tests/virtio-net-test.c   |  5 -
 tests/vmxnet3-test.c  |  5 -
 23 files changed, 106 insertions(+), 27 deletions(-)

diff --git a/tests/acpi-test.c b/tests/acpi-test.c
index 31f5359..cbcc849 100644
--- a/tests/acpi-test.c
+++ b/tests/acpi-test.c
@@ -551,6 +551,7 @@ static void test_acpi_asl(test_data *data)
 
 static void test_acpi_one(const char *params, test_data *data)
 {
+QTestState *s;
 char *args;
 uint8_t signature_low;
 uint8_t signature_high;
@@ -564,7 +565,8 @@ static void test_acpi_one(const char *params, test_data 
*data)
 
 args = g_strdup_printf(-net none -display none %s -drive file=%s%s,,
params ? params : , disk, device);
-qtest_start(args);
+s = qtest_start(args);
+g_assert(qtest_state_valid(s));
 
/* Wait at most 1 minute */
 #define TEST_DELAY (1 * G_USEC_PER_SEC / 10)
diff --git a/tests/blockdev-test.c b/tests/blockdev-test.c
index c940e00..d0a8bbf 100644
--- a/tests/blockdev-test.c
+++ b/tests/blockdev-test.c
@@ -16,11 +16,13 @@
 
 static void test_drive_add_empty(void)
 {
+QTestState *s;
 QDict *response;
 const char *response_return;
 
 /* Start with an empty drive */
-qtest_start(-drive if=none,id=drive0);
+s = qtest_start(-drive if=none,id=drive0);
+g_assert(qtest_state_valid(s));
 
 /* Delete the drive */
 response = qmp({\execute\: \human-monitor-command\,
diff --git a/tests/boot-order-test.c b/tests/boot-order-test.c
index 360a691..10f995d 100644
--- a/tests/boot-order-test.c
+++ b/tests/boot-order-test.c
@@ -31,6 +31,7 @@ static void test_a_boot_order(const char *machine,
   uint64_t expected_boot,
   uint64_t expected_reboot)
 {
+QTestState *s;
 char *args;
 uint64_t actual;
 
@@ -38,7 +39,8 @@ static void test_a_boot_order(const char *machine,
machine ?  -M  : ,
machine ?: ,
test_args);
-qtest_start(args);
+s = qtest_start(args);
+g_assert(qtest_state_valid(s));
 actual = read_boot_order();
 g_assert_cmphex(actual, ==, expected_boot);
 qmp_discard_response({ 'execute': 'system_reset' });
diff --git a/tests/e1000-test.c b/tests/e1000-test.c
index a8ba2fc..2dfc18f 100644
--- a/tests/e1000-test.c
+++ b/tests/e1000-test.c
@@ -19,12 +19,15 @@ static void nop(void)
 
 int main(int argc, char **argv)
 {
+QTestState *s;
 int ret;
 
 g_test_init(argc, argv, NULL);
 qtest_add_func(/e1000/nop, nop);
 
-qtest_start(-device e1000);
+s = qtest_start(-device e1000);
+g_assert(qtest_state_valid(s));
+
 ret = g_test_run();
 
 qtest_end();
diff --git a/tests/eepro100-test.c b/tests/eepro100-test.c
index bf82526..19623c0 100644
--- a/tests/eepro100-test.c
+++ b/tests/eepro100-test.c
@@ -20,6 +20,7 @@ static void test_device(gconstpointer data)
 
 args = g_strdup_printf(-device %s, model);
 s = qtest_start(args);
+g_assert(qtest_state_valid(s));
 
 /* Tests only initialization so far. TODO: Implement functional tests */
 
diff --git a/tests/endianness-test.c b/tests/endianness-test.c
index 92e17d2..6ffe6a2 100644
--- a/tests/endianness-test.c
+++ b/tests/endianness-test.c
@@ -118,6 +118,7 @@ static void isa_outl(const TestCase *test, uint16_t addr, 
uint32_t value)
 
 static void test_endianness(gconstpointer data)
 {
+QTestState *s;
 const TestCase *test = data;
 char *args;
 
@@ -125,7 +126,9 @@ static void test_endianness(gconstpointer data)
test-machine,
test-superio ?  -device  : ,
test-superio ?: );
-qtest_start(args);
+s = qtest_start(args);
+g_assert(qtest_state_valid(s));
+
 isa_outl(test, 0xe0, 0x87654321);
 g_assert_cmphex(isa_inl(test, 0xe0), ==, 0x87654321);
 

Re: [Qemu-devel] test-qapi-visit causes clang -fsanitize=undefined warning

2014-03-10 Thread Markus Armbruster
Peter Maydell peter.mayd...@linaro.org writes:

 I've noticed that the tests/test-qapi-visit.c code provokes the following
 complaint from clang's -fsanitize=undefined undefined-behaviour
 checker when you run 'make check':

 tests/test-qapi-visit.c:462:33: runtime error: member access within
 null pointer of type 'UserDefA' (aka 'struct UserDefA')

 which is the line
 visit_type_bool(m, (*obj)-boolean, boolean, err);
 in static void visit_type_UserDefA_fields(Visitor *m, UserDefA ** obj,
 Error **errp).

 It's presumably complaining because we've passed in an obj which
 points to NULL (ie *obj == NULL). The callsite in visit_type_UserDefA()
 checks for this and doesn't call the visit..fields function. The callsite
 in visit_type_UserDefFlatUnion doesn't.

 Unfortunately this is all autogenerated C so I'm not sure where exactly
 the bug should be fixed. Could one of you have a look at it?

My local clang doesn't complain.  May I have your clang version, exact
invocation and output?



[Qemu-devel] [PATCH 3/8] linux-user: Don't use UID16 on AArch64

2014-03-10 Thread riku . voipio
From: Andreas Schwab sch...@suse.de

The AArch64 kernel defines its __kernel_uid_t type as 32 bits, unlike
32 bit ARM, so don't enable our 16-bit UID wrapper handling.

Signed-off-by: Andreas Schwab sch...@suse.de
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Richard Henderson r...@twiddle.net
---
 linux-user/syscall_defs.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 3c8869e..d55f396 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -53,7 +53,8 @@
 #define TARGET_IOC_NRBITS  8
 #define TARGET_IOC_TYPEBITS8
 
-#if defined(TARGET_I386) || defined(TARGET_ARM) || defined(TARGET_SPARC) \
+#if defined(TARGET_I386) || (defined(TARGET_ARM)  defined(TARGET_ABI32)) \
+|| defined(TARGET_SPARC) \
 || defined(TARGET_M68K) || defined(TARGET_SH4) || defined(TARGET_CRIS)
 /* 16 bit uid wrappers emulation */
 #define USE_UID16
-- 
1.8.1.2




[Qemu-devel] [PATCH 2/8] linux-user: AArch64: Implement SA_RESTORER for signal handlers

2014-03-10 Thread riku . voipio
From: Michael Matz m...@suse.de

Implement support for signal handlers with the SA_RESTORER
flag set.

Signed-off-by: Michael Matz m...@suse.de
[PMM: minor tweaks to make patch apply to current master]
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Richard Henderson r...@twiddle.net
---
 linux-user/signal.c | 16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 29734b2..c8a1da0 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -1273,7 +1273,7 @@ static void target_setup_frame(int usig, struct 
target_sigaction *ka,
CPUARMState *env)
 {
 struct target_rt_sigframe *frame;
-abi_ulong frame_addr;
+abi_ulong frame_addr, return_addr;
 
 frame_addr = get_sigframe(ka, env);
 if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
@@ -1290,15 +1290,19 @@ static void target_setup_frame(int usig, struct 
target_sigaction *ka,
 __put_user(target_sigaltstack_used.ss_size,
   frame-uc.tuc_stack.ss_size);
 target_setup_sigframe(frame, env, set);
-/* mov x8,#__NR_rt_sigreturn; svc #0 */
-__put_user(0xd2801168, frame-tramp[0]);
-__put_user(0xd401, frame-tramp[1]);
+if (ka-sa_flags  TARGET_SA_RESTORER) {
+return_addr = ka-sa_restorer;
+} else {
+/* mov x8,#__NR_rt_sigreturn; svc #0 */
+__put_user(0xd2801168, frame-tramp[0]);
+__put_user(0xd401, frame-tramp[1]);
+return_addr = frame_addr + offsetof(struct target_rt_sigframe, tramp);
+}
 env-xregs[0] = usig;
 env-xregs[31] = frame_addr;
 env-xregs[29] = env-xregs[31] + offsetof(struct target_rt_sigframe, fp);
 env-pc = ka-_sa_handler;
-env-xregs[30] = env-xregs[31] +
-offsetof(struct target_rt_sigframe, tramp);
+env-xregs[30] = return_addr;
 if (info) {
 if (copy_siginfo_to_user(frame-info, info)) {
 goto give_sigsegv;
-- 
1.8.1.2




[Qemu-devel] [PATCH 1/8] linux-user/signal.c: Fix AArch64 big-endian FP register restore

2014-03-10 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

Fix the loop restoring the FP registers from the signal frame to match
the one used when setting up the signal frame, so that it handles
TARGET_WORDS_BIGENDIAN being set.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Richard Henderson r...@twiddle.net
---
 linux-user/signal.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 04638e2..29734b2 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -1233,8 +1233,14 @@ static int target_restore_sigframe(CPUARMState *env,
 return 1;
 }
 
-for (i = 0; i  32 * 2; i++) {
-__get_user(env-vfp.regs[i], aux-fpsimd.vregs[i]);
+for (i = 0; i  32; i++) {
+#ifdef TARGET_WORDS_BIGENDIAN
+__get_user(env-vfp.regs[i * 2], aux-fpsimd.vregs[i * 2 + 1]);
+__get_user(env-vfp.regs[i * 2 + 1], aux-fpsimd.vregs[i * 2]);
+#else
+__get_user(env-vfp.regs[i * 2], aux-fpsimd.vregs[i * 2]);
+__get_user(env-vfp.regs[i * 2 + 1], aux-fpsimd.vregs[i * 2 + 1]);
+#endif
 }
 __get_user(fpsr, aux-fpsimd.fpsr);
 vfp_set_fpsr(env, fpsr);
-- 
1.8.1.2




[Qemu-devel] [PATCH 6/8] linux-user: translate signal number on return from sigtimedwait

2014-03-10 Thread riku . voipio
From: Petar Jovanovic petar.jovano...@imgtec.com

On success, sigtimedwait() returns a signal number that needs to be
translated from a host value to a target value.

This change also fixes issues with sigwait (that is implemented using
sigtimedwait()).

Signed-off-by: Petar Jovanovic petar.jovano...@imgtec.com
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 linux-user/syscall.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1f64867..e2c10cc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6185,11 +6185,17 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 puts = NULL;
 }
 ret = get_errno(sigtimedwait(set, uinfo, puts));
-if (!is_error(ret)  arg2) {
-if (!(p = lock_user(VERIFY_WRITE, arg2, 
sizeof(target_siginfo_t), 0)))
-goto efault;
-host_to_target_siginfo(p, uinfo);
-unlock_user(p, arg2, sizeof(target_siginfo_t));
+if (!is_error(ret)) {
+if (arg2) {
+p = lock_user(VERIFY_WRITE, arg2, sizeof(target_siginfo_t),
+  0);
+if (!p) {
+goto efault;
+}
+host_to_target_siginfo(p, uinfo);
+unlock_user(p, arg2, sizeof(target_siginfo_t));
+}
+ret = host_to_target_signal(ret);
 }
 }
 break;
-- 
1.8.1.2




[Qemu-devel] [PATCH 4/8] linux-user: Fix getresuid, getresgid if !USE_UID16

2014-03-10 Thread riku . voipio
From: Peter Maydell peter.mayd...@linaro.org

The size of the UID/GID types depends on whether USE_UID16 is
defined. Define a new put_user_id() which writes a uid/gid
type to guest memory. This fixes getresuid and getresgid, which
were always storing 16 bits even if the uid type was 32 bits.

Reported-by: Michael Matz m...@suse.de
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Andreas Färber afaer...@suse.de
Reviewed-by: Richard Henderson r...@twiddle.net
---
 linux-user/syscall.c | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1407b7a..ccdbc4e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4528,6 +4528,9 @@ static inline int tswapid(int id)
 {
 return tswap16(id);
 }
+
+#define put_user_id(x, gaddr) put_user_u16(x, gaddr)
+
 #else /* !USE_UID16 */
 static inline int high2lowuid(int uid)
 {
@@ -4549,6 +4552,9 @@ static inline int tswapid(int id)
 {
 return tswap32(id);
 }
+
+#define put_user_id(x, gaddr) put_user_u32(x, gaddr)
+
 #endif /* USE_UID16 */
 
 void syscall_init(void)
@@ -7805,9 +7811,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 uid_t ruid, euid, suid;
 ret = get_errno(getresuid(ruid, euid, suid));
 if (!is_error(ret)) {
-if (put_user_u16(high2lowuid(ruid), arg1)
-|| put_user_u16(high2lowuid(euid), arg2)
-|| put_user_u16(high2lowuid(suid), arg3))
+if (put_user_id(high2lowuid(ruid), arg1)
+|| put_user_id(high2lowuid(euid), arg2)
+|| put_user_id(high2lowuid(suid), arg3))
 goto efault;
 }
 }
@@ -7826,9 +7832,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 gid_t rgid, egid, sgid;
 ret = get_errno(getresgid(rgid, egid, sgid));
 if (!is_error(ret)) {
-if (put_user_u16(high2lowgid(rgid), arg1)
-|| put_user_u16(high2lowgid(egid), arg2)
-|| put_user_u16(high2lowgid(sgid), arg3))
+if (put_user_id(high2lowgid(rgid), arg1)
+|| put_user_id(high2lowgid(egid), arg2)
+|| put_user_id(high2lowgid(sgid), arg3))
 goto efault;
 }
 }
-- 
1.8.1.2




[Qemu-devel] [PATCH 8/8] linux-user: set minimum kernel version to 2.6.32

2014-03-10 Thread riku . voipio
From: Riku Voipio riku.voi...@linaro.org

Popular glibc based distributions[1] require minimum
2.6.32 as kernel version. For some targets 2.6.18
would be enough, but dropping so low would mean some
suboptimal system calls could get used.

Set the minimum kernel advertized to 2.6.32 for
all architectures but aarch64 to ensure working qemu
linux-user in case host kernel is older.

[1] https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/921078

Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/alpha/syscall.h  | 1 +
 linux-user/arm/syscall.h| 1 +
 linux-user/cris/syscall.h   | 2 +-
 linux-user/i386/syscall.h   | 1 +
 linux-user/m68k/syscall.h   | 2 +-
 linux-user/microblaze/syscall.h | 2 +-
 linux-user/mips/syscall.h   | 1 +
 linux-user/mips64/syscall.h | 1 +
 linux-user/openrisc/syscall.h   | 1 +
 linux-user/ppc/syscall.h| 1 +
 linux-user/s390x/syscall.h  | 1 +
 linux-user/sh4/syscall.h| 1 +
 linux-user/sparc/syscall.h  | 1 +
 linux-user/sparc64/syscall.h| 1 +
 linux-user/unicore32/syscall.h  | 1 +
 linux-user/x86_64/syscall.h | 1 +
 16 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/linux-user/alpha/syscall.h b/linux-user/alpha/syscall.h
index 15a0100..ed13d9a 100644
--- a/linux-user/alpha/syscall.h
+++ b/linux-user/alpha/syscall.h
@@ -39,6 +39,7 @@ struct target_pt_regs {
 };
 
 #define UNAME_MACHINE alpha
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #undef TARGET_EDEADLK
 #define TARGET_EDEADLK 11
diff --git a/linux-user/arm/syscall.h b/linux-user/arm/syscall.h
index 73f2931..ce2c2a8 100644
--- a/linux-user/arm/syscall.h
+++ b/linux-user/arm/syscall.h
@@ -40,5 +40,6 @@ struct target_pt_regs {
 #else
 #define UNAME_MACHINE armv5tel
 #endif
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/cris/syscall.h b/linux-user/cris/syscall.h
index 832ee64..f5783c0 100644
--- a/linux-user/cris/syscall.h
+++ b/linux-user/cris/syscall.h
@@ -1,8 +1,8 @@
 #ifndef CRIS_SYSCALL_H
 #define CRIS_SYSCALL_H 1
 
-
 #define UNAME_MACHINE cris
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 /* pt_regs not only specifices the format in the user-struct during
  * ptrace but is also the frame format used in the kernel prologue/epilogues
diff --git a/linux-user/i386/syscall.h b/linux-user/i386/syscall.h
index 12b8c3b..9bfc1ad 100644
--- a/linux-user/i386/syscall.h
+++ b/linux-user/i386/syscall.h
@@ -144,5 +144,6 @@ struct target_vm86plus_struct {
 };
 
 #define UNAME_MACHINE i686
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/m68k/syscall.h b/linux-user/m68k/syscall.h
index 2618793..889eaf7 100644
--- a/linux-user/m68k/syscall.h
+++ b/linux-user/m68k/syscall.h
@@ -15,7 +15,7 @@ struct target_pt_regs {
 uint16_t __fill;
 };
 
-
 #define UNAME_MACHINE m68k
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 void do_m68k_simcall(CPUM68KState *, int);
diff --git a/linux-user/microblaze/syscall.h b/linux-user/microblaze/syscall.h
index d550989..5b5f6b4 100644
--- a/linux-user/microblaze/syscall.h
+++ b/linux-user/microblaze/syscall.h
@@ -1,8 +1,8 @@
 #ifndef MICROBLAZE_SYSCALLS_H
 #define MICROBLAZE_SYSCALLS_H 1
 
-
 #define UNAME_MACHINE microblaze
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 /* We use microblaze_reg_t to keep things similar to the kernel sources.  */
 typedef uint32_t microblaze_reg_t;
diff --git a/linux-user/mips/syscall.h b/linux-user/mips/syscall.h
index 9d437d9..5bc5696 100644
--- a/linux-user/mips/syscall.h
+++ b/linux-user/mips/syscall.h
@@ -225,5 +225,6 @@ struct target_pt_regs {
 #define TARGET_QEMU_ESIGRETURN 255
 
 #define UNAME_MACHINE mips
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/mips64/syscall.h b/linux-user/mips64/syscall.h
index 1710f76..a7f5a58 100644
--- a/linux-user/mips64/syscall.h
+++ b/linux-user/mips64/syscall.h
@@ -222,5 +222,6 @@ struct target_pt_regs {
 #define TARGET_QEMU_ESIGRETURN 255
 
 #define UNAME_MACHINE mips64
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/openrisc/syscall.h b/linux-user/openrisc/syscall.h
index bdbb577..c3b36da 100644
--- a/linux-user/openrisc/syscall.h
+++ b/linux-user/openrisc/syscall.h
@@ -22,3 +22,4 @@ struct target_pt_regs {
 };
 
 #define UNAME_MACHINE openrisc
+#define UNAME_MINIMUM_RELEASE 2.6.32
diff --git a/linux-user/ppc/syscall.h b/linux-user/ppc/syscall.h
index ba36acb..6514c63 100644
--- a/linux-user/ppc/syscall.h
+++ b/linux-user/ppc/syscall.h
@@ -62,5 +62,6 @@ struct target_revectored_struct {
 #else
 #define UNAME_MACHINE ppc
 #endif
+#define UNAME_MINIMUM_RELEASE 2.6.32
 
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/s390x/syscall.h b/linux-user/s390x/syscall.h
index e5ce30b..aaad512 100644
--- a/linux-user/s390x/syscall.h
+++ b/linux-user/s390x/syscall.h
@@ -21,5 +21,6 @@ struct target_pt_regs {
 };
 
 #define UNAME_MACHINE s390x
+#define UNAME_MINIMUM_RELEASE 

[Qemu-devel] [PATCH 7/8] linux-user: correct handling of break exception for MIPS

2014-03-10 Thread riku . voipio
From: Petar Jovanovic petar.jovano...@imgtec.com

Exception with break instruction has not been correctly propagated as
SIGTRAP. This resolves crash issues with examples that use break
instruction on MIPS.

Signed-off-by: Petar Jovanovic petar.jovano...@imgtec.com
Signed-off-by: Riku Voipio riku.voi...@linaro.org
---
 linux-user/main.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/linux-user/main.c b/linux-user/main.c
index 9192977..c19e7fb 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2384,6 +2384,10 @@ static int do_break(CPUMIPSState *env, target_siginfo_t 
*info,
 ret = 0;
 break;
 default:
+info-si_signo = TARGET_SIGTRAP;
+info-si_errno = 0;
+queue_signal(env, info-si_signo, *info);
+ret = 0;
 break;
 }
 
-- 
1.8.1.2




[Qemu-devel] [PATCH 5/8] linux-user: Implement sendmmsg syscall

2014-03-10 Thread riku . voipio
From: Alexander Graf ag...@suse.de

Glibc when built for newer kernels assumes that the sendmmsg syscall is
available. Without it, dns resolution simply fails to work.

Wrap the syscall with existing infrastructure so that we don't have a host
dependency on sendmmsg.

To avoid locking the same area of guest memory twice (which will break if
DEBUG_REMAP is defined) we pull the lock/unlock part of do_sendrecvmsg()
out into its own function so the actual implementation can be shared.

Signed-off-by: Alexander Graf ag...@suse.de
[PMM: add recvmmsg support;
 handle errors (which also implies support for non-blocking operations);
 cap the vector length as the kernel implementation does;
 don't lock guest memory twice;
 support MSG_WAITFORONE flag]
Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Riku Voipio riku.voi...@linaro.org
Reviewed-by: Richard Henderson r...@twiddle.net
---
 linux-user/syscall.c  | 86 +--
 linux-user/syscall_defs.h |  4 +++
 2 files changed, 80 insertions(+), 10 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ccdbc4e..1f64867 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1904,23 +1904,16 @@ static abi_long do_connect(int sockfd, abi_ulong 
target_addr,
 return get_errno(connect(sockfd, addr, addrlen));
 }
 
-/* do_sendrecvmsg() Must return target values and target errnos. */
-static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,
-   int flags, int send)
+/* do_sendrecvmsg_locked() Must return target values and target errnos. */
+static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp,
+  int flags, int send)
 {
 abi_long ret, len;
-struct target_msghdr *msgp;
 struct msghdr msg;
 int count;
 struct iovec *vec;
 abi_ulong target_vec;
 
-/* FIXME */
-if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,
-  msgp,
-  target_msg,
-  send ? 1 : 0))
-return -TARGET_EFAULT;
 if (msgp-msg_name) {
 msg.msg_namelen = tswap32(msgp-msg_namelen);
 msg.msg_name = alloca(msg.msg_namelen);
@@ -1975,10 +1968,75 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong 
target_msg,
 out:
 unlock_iovec(vec, target_vec, count, !send);
 out2:
+return ret;
+}
+
+static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg,
+   int flags, int send)
+{
+abi_long ret;
+struct target_msghdr *msgp;
+
+if (!lock_user_struct(send ? VERIFY_READ : VERIFY_WRITE,
+  msgp,
+  target_msg,
+  send ? 1 : 0)) {
+return -TARGET_EFAULT;
+}
+ret = do_sendrecvmsg_locked(fd, msgp, flags, send);
 unlock_user_struct(msgp, target_msg, send ? 0 : 1);
 return ret;
 }
 
+#ifdef TARGET_NR_sendmmsg
+/* We don't rely on the C library to have sendmmsg/recvmmsg support,
+ * so it might not have this *mmsg-specific flag either.
+ */
+#ifndef MSG_WAITFORONE
+#define MSG_WAITFORONE 0x1
+#endif
+
+static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec,
+unsigned int vlen, unsigned int flags,
+int send)
+{
+struct target_mmsghdr *mmsgp;
+abi_long ret = 0;
+int i;
+
+if (vlen  UIO_MAXIOV) {
+vlen = UIO_MAXIOV;
+}
+
+mmsgp = lock_user(VERIFY_WRITE, target_msgvec, sizeof(*mmsgp) * vlen, 1);
+if (!mmsgp) {
+return -TARGET_EFAULT;
+}
+
+for (i = 0; i  vlen; i++) {
+ret = do_sendrecvmsg_locked(fd, mmsgp[i].msg_hdr, flags, send);
+if (is_error(ret)) {
+break;
+}
+mmsgp[i].msg_len = tswap32(ret);
+/* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
+if (flags  MSG_WAITFORONE) {
+flags |= MSG_DONTWAIT;
+}
+}
+
+unlock_user(mmsgp, target_msgvec, sizeof(*mmsgp) * i);
+
+/* Return number of datagrams sent if we sent any at all;
+ * otherwise return the error.
+ */
+if (i) {
+return i;
+}
+return ret;
+}
+#endif
+
 /* If we don't have a system accept4() then just call accept.
  * The callsites to do_accept4() will ensure that they don't
  * pass a non-zero flags argument in this config.
@@ -6716,6 +6774,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 ret = do_sendrecvmsg(arg1, arg2, arg3, 1);
 break;
 #endif
+#ifdef TARGET_NR_sendmmsg
+case TARGET_NR_sendmmsg:
+ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1);
+break;
+case TARGET_NR_recvmmsg:
+ret = do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0);
+break;
+#endif
 #ifdef TARGET_NR_sendto
 case TARGET_NR_sendto:
 ret = do_sendto(arg1, arg2, arg3, arg4, arg5, arg6);
diff --git a/linux-user/syscall_defs.h 

Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/2] Fix return value of vga initlization on ppc

2014-03-10 Thread Alexey Kardashevskiy
On 03/10/2014 05:07 AM, Paolo Bonzini wrote:
 Il 08/03/2014 14:26, Alexey Kardashevskiy ha scritto:
  I think that after this patch, -nodefaults -device VGA will get a USB
  controller that it didn't get before.

 I suspect what was meant by the machine not aware of the graphics device
  is that the guest won't work with VGA and without keyboard (default
 console will be vga + keyboard and not serial) which is USB and this is why
 the patch is trying to add USB.
 
 But with -nodefaults QEMU should never be adding USB.


As I was told in this list before, even with -nodefaults, QEMU should not
create a machine which is known for not working or not being supported.
Having VGA and not having any input device is kind of such a config, no?


-- 
Alexey



  1   2   3   >