File qemu-img-snapshot.patch of Package xen

Index: xen-3.3.1-testing/tools/ioemu-remote/qemu-img.c
===================================================================
--- xen-3.3.1-testing.orig/tools/ioemu-remote/qemu-img.c
+++ xen-3.3.1-testing/tools/ioemu-remote/qemu-img.c
@@ -57,6 +57,7 @@ static void help(void)
            "  commit [-f fmt] filename\n"
            "  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] filename [filename2 [...]] output_filename\n"
            "  info [-f fmt] filename\n"
+           "  snapshot [-l|-a snapshot|-d snapshot] filename\n"
            "\n"
            "Command parameters:\n"
            "  'filename' is a disk image filename\n"
@@ -694,6 +695,91 @@ static int img_info(int argc, char **arg
     return 0;
 }
 
+#define SNAPSHOT_LIST   1
+#define SNAPSHOT_APPLY  2
+#define SNAPSHOT_DELETE 3
+
+static void img_snapshot(int argc, char **argv)
+{
+    BlockDriverState *bs;
+    char *filename, *snapshot_name = NULL;
+    char c;
+    int ret;
+    int action = 0;
+
+    /* Parse commandline parameters */
+    for(;;) {
+        c = getopt(argc, argv, "la:d:h");
+        if (c == -1)
+            break;
+        switch(c) {
+        case 'h':
+            help();
+            return;
+        case 'l':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_LIST;
+            break;
+        case 'a':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_APPLY;
+            snapshot_name = optarg;
+            break;
+        case 'd':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_DELETE;
+            snapshot_name = optarg;
+            break;
+        }
+    }
+
+    if (optind >= argc)
+        help();
+    filename = argv[optind++];
+
+    /* Open the image */
+    bs = bdrv_new("");
+    if (!bs)
+        error("Not enough memory");
+
+    if (bdrv_open2(bs, filename, 0, NULL) < 0) {
+        error("Could not open '%s'", filename);
+    }
+
+    /* Perform the requested action */
+    switch(action) {
+    case SNAPSHOT_LIST:
+        dump_snapshots(bs);
+        break;
+
+    case SNAPSHOT_APPLY:
+        ret = bdrv_snapshot_goto(bs, snapshot_name);
+        if (ret)
+            error("Could not apply snapshot '%s': %d (%s)",
+                snapshot_name, ret, strerror(-ret));
+        break;
+
+    case SNAPSHOT_DELETE:
+        ret = bdrv_snapshot_delete(bs, snapshot_name);
+        if (ret)
+            error("Could not delete snapshot '%s': %d (%s)",
+                snapshot_name, ret, strerror(-ret));
+        break;
+    }
+
+    /* Cleanup */
+    bdrv_delete(bs);
+}
+
 int main(int argc, char **argv)
 {
     const char *cmd;
@@ -711,6 +797,8 @@ int main(int argc, char **argv)
         img_convert(argc, argv);
     } else if (!strcmp(cmd, "info")) {
         img_info(argc, argv);
+    } else if (!strcmp(cmd, "snapshot")) {
+        img_snapshot(argc, argv);
     } else {
         help();
     }
openSUSE Build Service is sponsored by