Patchwork [V3,5/7] qemu-img: add -L for snapshot in convert

login
register
mail settings
Submitter Wayne Xia
Date Sept. 26, 2013, 12:16 a.m.
Message ID <1380154568-5339-6-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/278044/
State New
Headers show

Comments

Wayne Xia - Sept. 26, 2013, 12:16 a.m.
Now qemu-img convert have similar options as qemu-nbd for internal
snapshot.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 qemu-img.c |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
Eric Blake - Oct. 1, 2013, 2:54 p.m.
On 09/25/2013 06:16 PM, Wenchao Xia wrote:
> Now qemu-img convert have similar options as qemu-nbd for internal
> snapshot.
> 
> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
> ---
>  qemu-img.c |   30 +++++++++++++++++++++---------
>  1 files changed, 21 insertions(+), 9 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 6df58ed..a784ad4 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -1140,6 +1140,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";
> @@ -1148,7 +1149,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:");

New options should be documented in the same patch that introduces them.
Paolo Bonzini - Oct. 1, 2013, 4:07 p.m.
Il 26/09/2013 02:16, Wenchao Xia ha scritto:
> +        c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qnL:");
>          if (c == -1) {
>              break;
>          }
> @@ -1183,6 +1184,9 @@ static int img_convert(int argc, char **argv)
>          case 's':
>              snapshot_name = optarg;
>              break;
> +        case 'L':
> +            sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0);
> +            break;
>          case 'S':

Should qemu-img introduce -l too, and deprecate -s (continue to accept
it silently, but not document it)?

Paolo
Wayne Xia - Oct. 10, 2013, 6:07 a.m.
于 2013/10/2 0:07, Paolo Bonzini 写道:
> Il 26/09/2013 02:16, Wenchao Xia ha scritto:
>> +        c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:qnL:");
>>           if (c == -1) {
>>               break;
>>           }
>> @@ -1183,6 +1184,9 @@ static int img_convert(int argc, char **argv)
>>           case 's':
>>               snapshot_name = optarg;
>>               break;
>> +        case 'L':
>> +            sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0);
>> +            break;
>>           case 'S':
> Should qemu-img introduce -l too, and deprecate -s (continue to accept
> it silently, but not document it)?
>
> Paolo
>
OK, will document both but mark it deprecated.

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 6df58ed..a784ad4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1140,6 +1140,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";
@@ -1148,7 +1149,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;
         }
@@ -1183,6 +1184,9 @@  static int img_convert(int argc, char **argv)
         case 's':
             snapshot_name = optarg;
             break;
+        case 'L':
+            sn_opts = qemu_opts_parse(&internal_snapshot_opts, optarg, 0);
+            break;
         case 'S':
         {
             int64_t sval;
@@ -1254,7 +1258,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;
@@ -1262,13 +1271,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 */
@@ -1559,6 +1568,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);
     }