]> git.proxmox.com Git - pve-qemu-kvm.git/commitdiff
implement 'delete-drive-snapshot', make statefile optional
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Sep 2012 09:33:17 +0000 (11:33 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 6 Sep 2012 09:33:17 +0000 (11:33 +0200)
debian/patches/internal-snapshot.patch

index 5469fa9220399becc8adbac8e21302e7de618fc6..a07854604bbc8994ba5b597a8f17a3088940ea10 100644 (file)
@@ -1,23 +1,25 @@
 Index: new/qapi-schema.json
 ===================================================================
 --- new.orig/qapi-schema.json  2012-09-04 12:52:21.000000000 +0200
-+++ new/qapi-schema.json       2012-09-04 12:53:35.000000000 +0200
-@@ -2493,3 +2493,10 @@
++++ new/qapi-schema.json       2012-09-06 11:26:26.000000000 +0200
+@@ -2493,3 +2493,12 @@
  # Since: 1.2.0
  ##
  { 'command': 'query-target', 'returns': 'TargetInfo' }
 +
 +
-+{ 'command': 'snapshot-start' 'data': { 'statefile': 'str' } }
++{ 'command': 'snapshot-start' 'data': { '*statefile': 'str' } }
 +
 +{ 'command': 'snapshot-drive', 'data': { 'device': 'str', 'name': 'str' } }
 +
++{ 'command': 'delete-drive-snapshot', 'data': { 'device': 'str', 'name': 'str' } }
++
 +{ 'command': 'snapshot-end' }
 Index: new/qmp.c
 ===================================================================
 --- new.orig/qmp.c     2012-09-04 12:52:21.000000000 +0200
-+++ new/qmp.c  2012-09-05 10:34:10.000000000 +0200
-@@ -479,3 +479,155 @@
++++ new/qmp.c  2012-09-06 11:28:14.000000000 +0200
+@@ -479,3 +479,191 @@
      return arch_query_cpu_definitions(errp);
  }
  
@@ -26,7 +28,7 @@ Index: new/qmp.c
 +      int saved_vm_running;
 +} snap_state;
 +
-+void qmp_snapshot_start(const char *statefile, Error **errp)
++void qmp_snapshot_start(bool has_statefile, const char *statefile, Error **errp)
 +{
 +      QEMUFile *f;
 +      int ret;
@@ -43,6 +45,9 @@ Index: new/qmp.c
 +
 +      vm_stop(RUN_STATE_SAVE_VM);
 +
++      if (!has_statefile)
++              return;
++
 +      f = qemu_fopen(statefile, "wb");
 +      if (!f) {
 +              error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
@@ -173,11 +178,44 @@ Index: new/qmp.c
 +              return;
 +      }
 +}
++
++void qmp_delete_drive_snapshot(const char *device, const char *name, Error **errp)
++{
++      BlockDriverState *bs;
++      QEMUSnapshotInfo sn1, *sn = &sn1;
++      int ret;
++
++      bs = bdrv_find(device);
++        if (!bs) {
++              error_set(errp, QERR_DEVICE_NOT_FOUND, device);
++              return;
++      }
++      if (bdrv_is_read_only(bs)) {
++              error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
++              return;
++      }
++
++      if (!bdrv_can_snapshot(bs)) {
++              error_set(errp, QERR_NOT_SUPPORTED);
++              return;
++      }
++
++      if (bdrv_snapshot_find(bs, sn, name) < 0) {
++              /* return success if snapshot does not exists */
++              return;
++      }
++
++      ret = bdrv_snapshot_delete(bs, name);
++      if (ret < 0) {
++                error_set(errp, ERROR_CLASS_GENERIC_ERROR, "Error while deleting snapshot on '%s'\n", device);
++              return;
++      }
++}
 Index: new/qmp-commands.hx
 ===================================================================
 --- new.orig/qmp-commands.hx   2012-09-04 12:52:21.000000000 +0200
-+++ new/qmp-commands.hx        2012-09-04 12:53:35.000000000 +0200
-@@ -2514,3 +2514,21 @@
++++ new/qmp-commands.hx        2012-09-06 11:13:10.000000000 +0200
+@@ -2514,3 +2514,27 @@
          .args_type  = "",
          .mhandler.cmd_new = qmp_marshal_input_query_target,
      },
@@ -195,6 +233,12 @@ Index: new/qmp-commands.hx
 +    },
 +
 +    {
++        .name       = "delete-drive-snapshot",
++        .args_type  = "device:s,name:s",
++        .mhandler.cmd_new = qmp_marshal_input_delete_drive_snapshot,
++    },
++
++    {
 +        .name       = "snapshot-end",
 +        .args_type  = "",
 +        .mhandler.cmd_new = qmp_marshal_input_snapshot_end,
@@ -202,8 +246,8 @@ Index: new/qmp-commands.hx
 Index: new/hmp.c
 ===================================================================
 --- new.orig/hmp.c     2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp.c  2012-09-04 12:53:35.000000000 +0200
-@@ -1102,3 +1102,30 @@
++++ new/hmp.c  2012-09-06 11:30:32.000000000 +0200
+@@ -1102,3 +1102,40 @@
      qmp_closefd(fdname, &errp);
      hmp_handle_error(mon, &errp);
  }
@@ -211,9 +255,9 @@ Index: new/hmp.c
 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict)
 +{
 +    Error *errp = NULL;
-+    const char *statefile = qdict_get_str(qdict, "statefile");
++    const char *statefile = qdict_get_try_str(qdict, "statefile");
 +
-+    qmp_snapshot_start(statefile, &errp);
++    qmp_snapshot_start(statefile != NULL, statefile, &errp);
 +    hmp_handle_error(mon, &errp);
 +}
 +
@@ -227,6 +271,16 @@ Index: new/hmp.c
 +    hmp_handle_error(mon, &errp);
 +}
 +
++void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict)
++{
++    Error *errp = NULL;
++    const char *name = qdict_get_str(qdict, "name");
++    const char *device = qdict_get_str(qdict, "device");
++
++    qmp_delete_drive_snapshot(device, name, &errp);
++    hmp_handle_error(mon, &errp);
++}
++
 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict)
 +{
 +    Error *errp = NULL;
@@ -237,34 +291,34 @@ Index: new/hmp.c
 Index: new/hmp.h
 ===================================================================
 --- new.orig/hmp.h     2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp.h  2012-09-04 12:53:35.000000000 +0200
-@@ -71,5 +71,8 @@
++++ new/hmp.h  2012-09-06 11:14:38.000000000 +0200
+@@ -71,5 +71,9 @@
  void hmp_netdev_del(Monitor *mon, const QDict *qdict);
  void hmp_getfd(Monitor *mon, const QDict *qdict);
  void hmp_closefd(Monitor *mon, const QDict *qdict);
 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict);
 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict);
++void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict);
 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict);
  
  #endif
 Index: new/hmp-commands.hx
 ===================================================================
 --- new.orig/hmp-commands.hx   2012-09-04 12:52:21.000000000 +0200
-+++ new/hmp-commands.hx        2012-09-04 12:53:35.000000000 +0200
-@@ -1494,3 +1494,28 @@
++++ new/hmp-commands.hx        2012-09-06 11:29:05.000000000 +0200
+@@ -1494,3 +1494,35 @@
  STEXI
  @end table
  ETEXI
 +
 +    {
 +        .name       = "snapshot-start",
-+        .args_type  = "statefile:s",
-+        .params     = "statefile",
++        .args_type  = "statefile:s?",
++        .params     = "[statefile]",
 +        .help       = "Prepare for snapshot and halt VM. Save VM state to statefile.",
 +        .mhandler.cmd = hmp_snapshot_start,
 +    },
 +
-+
 +    {
 +        .name       = "snapshot-drive",
 +        .args_type  = "device:s,name:s",
@@ -274,6 +328,14 @@ Index: new/hmp-commands.hx
 +    },
 +
 +    {
++        .name       = "delete-drive-snapshot",
++        .args_type  = "device:s,name:s",
++        .params     = "device name",
++        .help       = "Delete internal snapshot.",
++        .mhandler.cmd = hmp_delete_drive_snapshot,
++    },
++
++    {
 +        .name       = "snapshot-end",
 +        .args_type  = "",
 +        .params     = "",