[Sheepdog] [PATCH 4/5] add a format option to qemu-img snapshot

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Jan 9 15:03:34 CET 2010


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 qemu-img-cmds.hx |    4 ++--
 qemu-img.c       |   17 ++++++++++++++---
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 641bd87..be873a4 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -40,8 +40,8 @@ STEXI
 ETEXI
 
 DEF("snapshot", img_snapshot,
-    "snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename")
+    "snapshot [-f fmt] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
 STEXI
- at item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
+ at item snapshot [-f fmt] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
 @end table
 ETEXI
diff --git a/qemu-img.c b/qemu-img.c
index 0056f5e..aa33a6b 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -938,6 +938,8 @@ static int img_info(int argc, char **argv)
 static int img_snapshot(int argc, char **argv)
 {
     BlockDriverState *bs;
+    const char *fmt = "raw";
+    BlockDriver *drv;
     QEMUSnapshotInfo sn;
     char *filename, *snapshot_name = NULL;
     int c, ret;
@@ -946,7 +948,7 @@ static int img_snapshot(int argc, char **argv)
 
     /* Parse commandline parameters */
     for(;;) {
-        c = getopt(argc, argv, "la:c:d:h");
+        c = getopt(argc, argv, "la:c:d:f:h");
         if (c == -1)
             break;
         switch(c) {
@@ -984,6 +986,9 @@ static int img_snapshot(int argc, char **argv)
             action = SNAPSHOT_DELETE;
             snapshot_name = optarg;
             break;
+        case 'f':
+            fmt = optarg;
+            break;
         }
     }
 
@@ -995,8 +1000,14 @@ static int img_snapshot(int argc, char **argv)
     bs = bdrv_new("");
     if (!bs)
         error("Not enough memory");
-
-    if (bdrv_open2(bs, filename, 0, NULL) < 0) {
+    if (fmt) {
+        drv = bdrv_find_format(fmt);
+        if (!drv)
+            error("Unknown file format '%s'", fmt);
+    } else {
+        drv = NULL;
+    }
+    if (bdrv_open2(bs, filename, 0, drv) < 0) {
         error("Could not open '%s'", filename);
     }
 
-- 
1.5.6.5




More information about the sheepdog mailing list