qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	Wenchao Xia <xiawenc@linux.vnet.ibm.com>,
	Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 34/48] qemu-img: add -l for snapshot in convert
Date: Fri,  6 Dec 2013 17:36:33 +0100	[thread overview]
Message-ID: <1386347807-27359-35-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1386347807-27359-1-git-send-email-stefanha@redhat.com>

From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>

Now qemu-img convert have similar options as qemu-nbd for internal
snapshot.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 qemu-img-cmds.hx |  4 ++--
 qemu-img.c       | 44 +++++++++++++++++++++++++++++++++++---------
 qemu-img.texi    | 12 ++++++++----
 3 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index da1d965..d029609 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -34,9 +34,9 @@ STEXI
 ETEXI
 
 DEF("convert", img_convert,
-    "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename")
+    "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] filename [filename2 [...]] output_filename")
 STEXI
-@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
 DEF("info", img_info,
diff --git a/qemu-img.c b/qemu-img.c
index 685c566..54ae984 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -93,6 +93,11 @@ static void help(void)
            "  'options' is a comma separated list of format specific options in a\n"
            "    name=value format. Use -o ? for an overview of the options supported by the\n"
            "    used format\n"
+           "  'snapshot_param' is param used for internal snapshot, format\n"
+           "    is 'snapshot.id=[ID],snapshot.name=[NAME]', or\n"
+           "    '[ID_OR_NAME]'\n"
+           "  'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n"
+           "    instead\n"
            "  '-c' indicates that target image must be compressed (qcow format only)\n"
            "  '-u' enables unsafe rebasing. It is assumed that old and new backing file\n"
            "       match exactly. The image doesn't need a working backing file before\n"
@@ -1144,6 +1149,7 @@ static int img_convert(int argc, char **argv)
     int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
     bool quiet = false;
     Error *local_err = NULL;
+    QemuOpts *sn_opts = NULL;
 
     fmt = NULL;
     out_fmt = "raw";
@@ -1152,7 +1158,7 @@ static int img_convert(int argc, char **argv)
     compress = 0;
     skip_create = 0;
     for(;;) {
-        c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qn");
+        c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qnl:");
         if (c == -1) {
             break;
         }
@@ -1187,6 +1193,18 @@ static int img_convert(int argc, char **argv)
         case 's':
             snapshot_name = optarg;
             break;
+        case 'l':
+            if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) {
+                sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0);
+                if (!sn_opts) {
+                    error_report("Failed in parsing snapshot param '%s'",
+                                 optarg);
+                    return 1;
+                }
+            } else {
+                snapshot_name = optarg;
+            }
+            break;
         case 'S':
         {
             int64_t sval;
@@ -1258,7 +1276,12 @@ static int img_convert(int argc, char **argv)
         total_sectors += bs_sectors;
     }
 
-    if (snapshot_name != NULL) {
+    if (sn_opts) {
+        ret = bdrv_snapshot_load_tmp(bs[0],
+                                     qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID),
+                                     qemu_opt_get(sn_opts, SNAPSHOT_OPT_NAME),
+                                     &local_err);
+    } else if (snapshot_name != NULL) {
         if (bs_n > 1) {
             error_report("No support for concatenating multiple snapshot");
             ret = -1;
@@ -1266,13 +1289,13 @@ static int img_convert(int argc, char **argv)
         }
 
         bdrv_snapshot_load_tmp_by_id_or_name(bs[0], snapshot_name, &local_err);
-        if (error_is_set(&local_err)) {
-            error_report("Failed to load snapshot: %s",
-                         error_get_pretty(local_err));
-            error_free(local_err);
-            ret = -1;
-            goto out;
-        }
+    }
+    if (error_is_set(&local_err)) {
+        error_report("Failed to load snapshot: %s",
+                     error_get_pretty(local_err));
+        error_free(local_err);
+        ret = -1;
+        goto out;
     }
 
     /* Find driver and parse its options */
@@ -1571,6 +1594,9 @@ out:
     free_option_parameters(create_options);
     free_option_parameters(param);
     qemu_vfree(buf);
+    if (sn_opts) {
+        qemu_opts_del(sn_opts);
+    }
     if (out_bs) {
         bdrv_unref(out_bs);
     }
diff --git a/qemu-img.texi b/qemu-img.texi
index da36975..be31191 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -46,7 +46,11 @@ is the destination disk image filename
 is a comma separated list of format specific options in a
 name=value format. Use @code{-o ?} for an overview of the options supported
 by the used format or see the format descriptions below for details.
-
+@item snapshot_param
+is param used for internal snapshot, format is
+'snapshot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]'
+@item snapshot_id_or_name
+is deprecated, use snapshot_param instead
 
 @item -c
 indicates that target image must be compressed (qcow format only)
@@ -179,10 +183,10 @@ Error on reading data
 
 @end table
 
-@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 
-Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename}
-using format @var{output_fmt}. It can be optionally compressed (@code{-c}
+Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@var{snapshot_id_or_name} is deprecated)
+to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c}
 option) or use any format specific options like encryption (@code{-o} option).
 
 Only the formats @code{qcow} and @code{qcow2} support compression. The
-- 
1.8.4.2

  parent reply	other threads:[~2013-12-06 16:38 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-06 16:35 [Qemu-devel] [PULL 00/48] Block patches Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 01/48] coroutine: remove qemu_co_queue_wait_insert_head Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 02/48] coroutine: remove unused CoQueue AioContext Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 03/48] vmdk: Fix creating big description file Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 04/48] block: generalize BlockLimits handling to cover bdrv_aio_discard too Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 05/48] block: add flags to BlockRequest Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 06/48] block: add flags argument to bdrv_co_write_zeroes tracepoint Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 07/48] block: add bdrv_aio_write_zeroes Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 08/48] block: handle ENOTSUP from discard in generic code Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 09/48] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 10/48] vpc, vhdx: add get_info Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 11/48] block drivers: add discard/write_zeroes properties to bdrv_get_info implementation Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 12/48] block drivers: expose requirement for write same alignment from formats Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 13/48] block/iscsi: remove .bdrv_has_zero_init Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 14/48] block/iscsi: updated copyright Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 15/48] block/iscsi: check WRITE SAME support differently depending on MAY_UNMAP Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 16/48] raw-posix: implement write_zeroes with MAY_UNMAP for files Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 17/48] raw-posix: implement write_zeroes with MAY_UNMAP for block devices Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 18/48] raw-posix: add support for write_zeroes on XFS and " Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 19/48] qemu-iotests: 033 is fast Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 20/48] scsi-disk: catch write protection errors in UNMAP Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 21/48] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME commands Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 22/48] scsi-disk: correctly implement WRITE SAME Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 23/48] block: Close backing file early in bdrv_img_create Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 24/48] qcow2: Zero-initialise first cluster for new images Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 25/48] qemu-iotests: Add "-c <cache-mode>" option Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 26/48] qemu-iotests: Honour cache mode in iotests.py Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 27/48] qemu-iotests: Add _default_cache_mode and _supported_cache_modes Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 28/48] qemu-iotests: Change default cache mode to "writeback" Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 29/48] qemu-iotests: Clean up spaces in usage output Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 30/48] qemu-iotests: Split qcow2 only cases in 048 Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 31/48] snapshot: distinguish id and name in load_tmp Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 32/48] qemu-nbd: support internal snapshot export Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 33/48] qemu-iotests: add 058 internal snapshot export with qemu-nbd case Stefan Hajnoczi
2013-12-06 16:36 ` Stefan Hajnoczi [this message]
2013-12-06 16:36 ` [Qemu-devel] [PULL 35/48] qemu-iotests: add test for snapshot in qemu-img convert Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 36/48] qemu-nbd: add doc for option -f Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 37/48] qemu-img: add support for skipping zeroes in input during convert Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 38/48] qemu-img: fix usage instruction for qemu-img convert Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 39/48] block/iscsi: set bdi->cluster_size Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 40/48] block: add opt_transfer_length to BlockLimits Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 41/48] block/iscsi: set bs->bl.opt_transfer_length Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 42/48] qemu-img: dynamically adjust iobuffer size during convert Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 43/48] qemu-img: round down request length to an aligned sector Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 44/48] qemu-img: decrease progress update interval on convert Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 45/48] qcow2: use start_of_cluster() and offset_into_cluster() everywhere Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 46/48] block: clean up bdrv_drain_all() throttling comments Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 47/48] aio: make aio_poll(ctx, true) block with no fds Stefan Hajnoczi
2013-12-06 16:36 ` [Qemu-devel] [PULL 48/48] qemu-iotests: filter QEMU monitor \r\n Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386347807-27359-35-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xiawenc@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).