Re: [Qemu-devel] [PATCH v3 5/8] qmp: convert blockdev-snapshot-sync to a wrapper around transactions

2012-03-06 Thread Luiz Capitulino
On Mon, 05 Mar 2012 20:44:39 +0100
Paolo Bonzini  wrote:

> Il 05/03/2012 19:55, Eric Blake ha scritto:
> > Right now, libvirt has an API virDomainSnapshotCreateXML with a flag
> > VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT, which should map to this new mode
> > operand.  Am I guaranteed that if I pass a 'mode' argument of 'existing'
> > to an older qemu that lacked mode, I will get a sane error?  If so, then
> > this rewrite looks fine from libvirt's point of view.
> 
> Not sure... Luiz?

The question is: will I get an error if I pass an unknown argument to
a command? Yes, you will.



Re: [Qemu-devel] [PATCH v3 5/8] qmp: convert blockdev-snapshot-sync to a wrapper around transactions

2012-03-05 Thread Paolo Bonzini
Il 05/03/2012 20:44, Paolo Bonzini ha scritto:
> Il 05/03/2012 19:55, Eric Blake ha scritto:
>> Right now, libvirt has an API virDomainSnapshotCreateXML with a flag
>> VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT, which should map to this new mode
>> operand.  Am I guaranteed that if I pass a 'mode' argument of 'existing'
>> to an older qemu that lacked mode, I will get a sane error?  If so, then
>> this rewrite looks fine from libvirt's point of view.
> 
> Not sure... Luiz?

Well, you could always use the transaction command if the flag is there.
 That command will have it always.

Paolo




Re: [Qemu-devel] [PATCH v3 5/8] qmp: convert blockdev-snapshot-sync to a wrapper around transactions

2012-03-05 Thread Paolo Bonzini
Il 05/03/2012 19:55, Eric Blake ha scritto:
> Right now, libvirt has an API virDomainSnapshotCreateXML with a flag
> VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT, which should map to this new mode
> operand.  Am I guaranteed that if I pass a 'mode' argument of 'existing'
> to an older qemu that lacked mode, I will get a sane error?  If so, then
> this rewrite looks fine from libvirt's point of view.

Not sure... Luiz?

Paolo



Re: [Qemu-devel] [PATCH v3 5/8] qmp: convert blockdev-snapshot-sync to a wrapper around transactions

2012-03-05 Thread Eric Blake
On 03/05/2012 10:33 AM, Paolo Bonzini wrote:
> Simplify the blockdev-snapshot-sync code and gain failsafe operation
> by turning it into a wrapper around the new transaction command.  A new
> option is also added matching "mode".
> 
> Signed-off-by: Paolo Bonzini 
> ---
>  blockdev.c   |   81 -
>  hmp-commands.hx  |9 --
>  hmp.c|6 +++-
>  qapi-schema.json |   15 +
>  qmp-commands.hx  |2 +
>  5 files changed, 40 insertions(+), 73 deletions(-)
> 

> +++ b/qapi-schema.json
> @@ -1143,6 +1143,9 @@
>  # @snapshot-file: the target of the new image. A new file will be created.
>  #
>  # @format: #optional the format of the snapshot image, default is 'qcow2'.
> +#
> +# @mode: #optional whether and how QEMU should create a new image, default is
> +# 'absolute-paths'.
>  ##
>  { 'type': 'BlockdevSnapshot',
>'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str',
> @@ -1199,21 +1202,19 @@
>  #
>  # @format: #optional the format of the snapshot image, default is 'qcow2'.
>  #
> +# @mode: #optional whether and how QEMU should create a new image, default is
> +# 'absolute-paths'.

Right now, libvirt has an API virDomainSnapshotCreateXML with a flag
VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT, which should map to this new mode
operand.  Am I guaranteed that if I pass a 'mode' argument of 'existing'
to an older qemu that lacked mode, I will get a sane error?  If so, then
this rewrite looks fine from libvirt's point of view.

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v3 5/8] qmp: convert blockdev-snapshot-sync to a wrapper around transactions

2012-03-05 Thread Paolo Bonzini
Simplify the blockdev-snapshot-sync code and gain failsafe operation
by turning it into a wrapper around the new transaction command.  A new
option is also added matching "mode".

Signed-off-by: Paolo Bonzini 
---
 blockdev.c   |   81 -
 hmp-commands.hx  |9 --
 hmp.c|6 +++-
 qapi-schema.json |   15 +
 qmp-commands.hx  |2 +
 5 files changed, 40 insertions(+), 73 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index c9bd25b..06c3017 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -648,70 +648,27 @@ void do_commit(Monitor *mon, const QDict *qdict)
 
 void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file,
 bool has_format, const char *format,
+bool has_mode, enum NewImageMode mode,
 Error **errp)
 {
-BlockDriverState *bs;
-BlockDriver *drv, *old_drv, *proto_drv;
-int ret = 0;
-int flags;
-char old_filename[1024];
-
-bs = bdrv_find(device);
-if (!bs) {
-error_set(errp, QERR_DEVICE_NOT_FOUND, device);
-return;
-}
-if (bdrv_in_use(bs)) {
-error_set(errp, QERR_DEVICE_IN_USE, device);
-return;
-}
-
-pstrcpy(old_filename, sizeof(old_filename), bs->filename);
-
-old_drv = bs->drv;
-flags = bs->open_flags;
-
-if (!has_format) {
-format = "qcow2";
-}
-
-drv = bdrv_find_format(format);
-if (!drv) {
-error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
-return;
-}
-
-proto_drv = bdrv_find_protocol(snapshot_file);
-if (!proto_drv) {
-error_set(errp, QERR_INVALID_BLOCK_FORMAT, format);
-return;
-}
-
-ret = bdrv_img_create(snapshot_file, format, bs->filename,
-  bs->drv->format_name, NULL, -1, flags);
-if (ret) {
-error_set(errp, QERR_UNDEFINED_ERROR);
-return;
-}
-
-bdrv_drain_all();
-bdrv_flush(bs);
-
-bdrv_close(bs);
-ret = bdrv_open(bs, snapshot_file, flags, drv);
-/*
- * If reopening the image file we just created fails, fall back
- * and try to re-open the original image. If that fails too, we
- * are in serious trouble.
- */
-if (ret != 0) {
-ret = bdrv_open(bs, old_filename, flags, old_drv);
-if (ret != 0) {
-error_set(errp, QERR_OPEN_FILE_FAILED, old_filename);
-} else {
-error_set(errp, QERR_OPEN_FILE_FAILED, snapshot_file);
-}
-}
+BlockdevSnapshot snapshot = {
+.device = (char *) device,
+.snapshot_file = (char *) snapshot_file,
+.has_format = has_format,
+.format = (char *) format,
+.has_mode = has_mode,
+.mode = mode,
+};
+BlockdevAction action = {
+.kind = BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC,
+.blockdev_snapshot_sync = &snapshot,
+};
+BlockdevActionList list = {
+.value = &action,
+.next = NULL
+};
+
+qmp_transaction(&list, errp);
 }
 
 
diff --git a/hmp-commands.hx b/hmp-commands.hx
index ed88877..6980214 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -882,14 +882,17 @@ ETEXI
 
 {
 .name   = "snapshot_blkdev",
-.args_type  = "device:B,snapshot-file:s?,format:s?",
-.params = "device [new-image-file] [format]",
+.args_type  = "reuse:-n,device:B,snapshot-file:s?,format:s?",
+.params = "[-n] device [new-image-file] [format]",
 .help   = "initiates a live snapshot\n\t\t\t"
   "of device. If a new image file is specified, 
the\n\t\t\t"
   "new image file will become the new root image.\n\t\t\t"
   "If format is specified, the snapshot file will\n\t\t\t"
   "be created in that format. Otherwise the\n\t\t\t"
-  "snapshot will be internal! (currently unsupported)",
+  "snapshot will be internal! (currently 
unsupported).\n\t\t\t"
+  "The default format is qcow2.  The -n flag requests 
QEMU\n\t\t\t"
+  "to reuse the image found in new-image-file, instead 
of\n\t\t\t"
+  "recreating it from scratch.",
 .mhandler.cmd = hmp_snapshot_blkdev,
 },
 
diff --git a/hmp.c b/hmp.c
index 3a54455..290c43d 100644
--- a/hmp.c
+++ b/hmp.c
@@ -692,6 +692,8 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
 const char *device = qdict_get_str(qdict, "device");
 const char *filename = qdict_get_try_str(qdict, "snapshot-file");
 const char *format = qdict_get_try_str(qdict, "format");
+int reuse = qdict_get_try_bool(qdict, "reuse", 0);
+enum NewImageMode mode;
 Error *errp = NULL;
 
 if (!filename) {
@@ -702,7 +704,9 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
 return;
 }
 
-qmp_bloc