Patchwork [03/22] savevm: Introduce delete_snapshot() and use it

login
register
mail settings
Submitter Luiz Capitulino
Date April 20, 2010, 9:09 p.m.
Message ID <1271797792-24571-4-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/50575/
State New
Headers show

Comments

Luiz Capitulino - April 20, 2010, 9:09 p.m.
del_existing_snapshots() and do_delvm() can share some code as
the two call bdrv_snapshot_delete() and print a message to the
user if an error has happened.

This commit introduces a new function to share this code.

Please, note that while do_delvm() should stay the same,
del_existing_snapshots() will now print a specific message for
-ENOTSUP errors (instead of a generic one).

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 savevm.c |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

Patch

diff --git a/savevm.c b/savevm.c
index 254f9fc..cc6cbb2 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1619,6 +1619,28 @@  static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
     return ret;
 }
 
+static int delete_snapshot(Monitor *mon, BlockDriverState *bs,
+                           const char *name)
+{
+    int ret;
+
+    ret = bdrv_snapshot_delete(bs, name);
+    if (ret < 0) {
+        switch (ret) {
+        case -ENOTSUP:
+            monitor_printf(mon, "Snapshots not supported on device '%s'\n",
+                           bdrv_get_device_name(bs));
+            break;
+        default:
+            monitor_printf(mon, "Error %d while deleting snapshot on '%s'\n",
+                           ret, bdrv_get_device_name(bs));
+            break;
+        }
+    }
+
+    return ret;
+}
+
 /*
  * Deletes snapshots of a given name in all opened images.
  */
@@ -1634,11 +1656,8 @@  static int del_existing_snapshots(Monitor *mon, const char *name)
         if (bdrv_can_snapshot(bs) &&
             bdrv_snapshot_find(bs, snapshot, name) >= 0)
         {
-            ret = bdrv_snapshot_delete(bs, name);
+            ret = delete_snapshot(mon, bs, name);
             if (ret < 0) {
-                monitor_printf(mon,
-                               "Error while deleting snapshot on '%s'\n",
-                               bdrv_get_device_name(bs));
                 return -1;
             }
         }
@@ -1799,7 +1818,6 @@  void do_delvm(Monitor *mon, const QDict *qdict)
 {
     DriveInfo *dinfo;
     BlockDriverState *bs, *bs1;
-    int ret;
     const char *name = qdict_get_str(qdict, "name");
 
     bs = get_bs_snapshots();
@@ -1811,16 +1829,7 @@  void do_delvm(Monitor *mon, const QDict *qdict)
     QTAILQ_FOREACH(dinfo, &drives, next) {
         bs1 = dinfo->bdrv;
         if (bdrv_has_snapshot(bs1)) {
-            ret = bdrv_snapshot_delete(bs1, name);
-            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));
-            }
+            delete_snapshot(mon, bs1, name);
         }
     }
 }