diff mbox

[v2,15/17] qapi: Convert delvm

Message ID 1632528b81f07b470178e2899937d5961e97793d.1355404685.git.phrdina@redhat.com
State New
Headers show

Commit Message

Pavel Hrdina Dec. 13, 2012, 3:40 p.m. UTC
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 hmp-commands.hx  |  2 +-
 hmp.c            | 10 ++++++++++
 hmp.h            |  1 +
 qapi-schema.json | 14 ++++++++++++++
 qmp-commands.hx  | 24 ++++++++++++++++++++++++
 savevm.c         | 17 +++--------------
 sysemu.h         |  1 -
 7 files changed, 53 insertions(+), 16 deletions(-)

Comments

Eric Blake Dec. 14, 2012, 6:39 p.m. UTC | #1
On 12/13/2012 08:40 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  hmp-commands.hx  |  2 +-
>  hmp.c            | 10 ++++++++++
>  hmp.h            |  1 +
>  qapi-schema.json | 14 ++++++++++++++
>  qmp-commands.hx  | 24 ++++++++++++++++++++++++
>  savevm.c         | 17 +++--------------
>  sysemu.h         |  1 -
>  7 files changed, 53 insertions(+), 16 deletions(-)
> 

> +##
> +# @vm-snapshot-delete:
> +#
> +# Delete the snapshot identified by tag or id.
> +#
> +# @name: tag|id of existing snapshot
> +#
> +# Returns: Nothing on success
> +#          If an error occurs, GenericError with error message
> +#
> +# Since: 1.3

Another case of 1.4.
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 5194f15..0b3d783 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -342,7 +342,7 @@  ETEXI
         .args_type  = "name:s",
         .params     = "tag|id",
         .help       = "delete a VM snapshot from its tag or id",
-        .mhandler.cmd = do_delvm,
+        .mhandler.cmd = hmp_vm_snapshot_delete,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 29f60a8..78c9a7c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1353,3 +1353,13 @@  void hmp_vm_snapshot_load(Monitor *mon, const QDict *qdict)
     qmp_vm_snapshot_load(name, &err);
     hmp_handle_error(mon, &err);
 }
+
+void hmp_vm_snapshot_delete(Monitor *mon, const QDict *qdict)
+{
+    const char *name = qdict_get_str(qdict, "name");
+    Error *err = NULL;
+
+    qmp_vm_snapshot_delete(name, &err);
+
+    hmp_handle_error(mon, &err);
+}
diff --git a/hmp.h b/hmp.h
index 3f61b32..8f929af 100644
--- a/hmp.h
+++ b/hmp.h
@@ -82,5 +82,6 @@  void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
 void hmp_vm_snapshot_save(Monitor *mon, const QDict *qdict);
 void hmp_vm_snapshot_load(Monitor *mon, const QDict *qdict);
+void hmp_vm_snapshot_delete(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index f8ab4d9..431df69 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3051,3 +3051,17 @@ 
 # Since: 1.3
 ##
 { 'command': 'vm-snapshot-load', 'data': {'name': 'str'} }
+
+##
+# @vm-snapshot-delete:
+#
+# Delete the snapshot identified by tag or id.
+#
+# @name: tag|id of existing snapshot
+#
+# Returns: Nothing on success
+#          If an error occurs, GenericError with error message
+#
+# Since: 1.3
+##
+{ 'command': 'vm-snapshot-delete', 'data': {'name': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 62da843..c3671f7 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1402,6 +1402,30 @@  Example:
 
 EQMP
     {
+        .name       = "vm-snapshot-delete",
+        .args_type  = "name:s",
+        .params     = "tag|id",
+        .help       = "delete a VM snapshot from its tag or id",
+        .mhandler.cmd_new = qmp_marshal_input_vm_snapshot_delete
+    },
+
+SQMP
+vm-snapshot-delete
+------
+
+Delete the snapshot identified by tag or id.
+
+Arguments:
+
+- "name": tag|id of existing snapshot (json-string)
+
+Example:
+
+-> { "execute": "vm-snapshot-delete", "arguments": { "name": "my_snapshot" } }
+<- { "return": {} }
+
+EQMP
+    {
         .name       = "qmp_capabilities",
         .args_type  = "",
         .params     = "",
diff --git a/savevm.c b/savevm.c
index 636cca8..8da888e 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2355,31 +2355,20 @@  void qmp_vm_snapshot_load(const char *name, Error **errp)
     }
 }
 
-void do_delvm(Monitor *mon, const QDict *qdict)
+void qmp_vm_snapshot_delete(const char *name, Error **errp)
 {
     BlockDriverState *bs, *bs1;
-    int ret;
-    const char *name = qdict_get_str(qdict, "name");
 
     bs = bdrv_snapshots();
     if (!bs) {
-        monitor_printf(mon, "No block device supports snapshots\n");
+        error_setg(errp, "No block device supports snapshots.");
         return;
     }
 
     bs1 = NULL;
     while ((bs1 = bdrv_next(bs1))) {
         if (bdrv_can_snapshot(bs1)) {
-            ret = bdrv_snapshot_delete(bs1, name, NULL);
-            if (ret < 0) {
-                if (ret == -ENOTSUP)
-                    monitor_printf(mon,
-                                   "Snapshots not supported on device '%s'\n",
-                                   bdrv_get_device_name(bs1));
-                else
-                    monitor_printf(mon, "Error %d while deleting snapshot on "
-                                   "'%s'\n", ret, bdrv_get_device_name(bs1));
-            }
+            bdrv_snapshot_delete(bs1, name, errp);
         }
     }
 }
diff --git a/sysemu.h b/sysemu.h
index 83fc17e..e440dcc 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -65,7 +65,6 @@  void qemu_remove_exit_notifier(Notifier *notify);
 
 void qemu_add_machine_init_done_notifier(Notifier *notify);
 
-void do_delvm(Monitor *mon, const QDict *qdict);
 void do_info_snapshots(Monitor *mon);
 
 void qemu_announce_self(void);