Patchwork [06/18] block: add error parameter to bdrv_snapshot_find()

login
register
mail settings
Submitter Pavel Hrdina
Date Aug. 15, 2012, 7:41 a.m.
Message ID <39238d17c8ced6e88adcb5575f63fc89d6793e98.1345016001.git.phrdina@redhat.com>
Download mbox | patch
Permalink /patch/177582/
State New
Headers show

Comments

Pavel Hrdina - Aug. 15, 2012, 7:41 a.m.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 savevm.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

Patch

diff --git a/savevm.c b/savevm.c
index 92da274..55b65cf 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2015,16 +2015,21 @@  out:
     return ret;
 }
 
-static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                              const char *name)
+static int bdrv_snapshot_find(BlockDriverState *bs,
+                              QEMUSnapshotInfo *sn_info,
+                              const char *name,
+                              Error **errp)
 {
     QEMUSnapshotInfo *sn_tab, *sn;
     int nb_sns, i, ret;
 
+
+    nb_sns = bdrv_snapshot_list(bs, &sn_tab, errp);
+    if (error_is_set(errp)) {
+        return nb_sns;
+    }
+
     ret = -ENOENT;
-    nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL);
-    if (nb_sns < 0)
-        return ret;
     for(i = 0; i < nb_sns; i++) {
         sn = &sn_tab[i];
         if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
@@ -2034,6 +2039,9 @@  static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
         }
     }
     g_free(sn_tab);
+    if (ret < 0) {
+        error_set(errp, QERR_OPEN_FILE_FAILED, name);
+    }
     return ret;
 }
 
@@ -2049,7 +2057,7 @@  static int del_existing_snapshots(Monitor *mon, const char *name)
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
         if (bdrv_can_snapshot(bs) &&
-            bdrv_snapshot_find(bs, snapshot, name) >= 0)
+            bdrv_snapshot_find(bs, snapshot, name, NULL) >= 0)
         {
             ret = bdrv_snapshot_delete(bs, name, NULL);
             if (ret < 0) {
@@ -2120,7 +2128,7 @@  void do_savevm(Monitor *mon, const QDict *qdict)
     sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
 
     if (name) {
-        ret = bdrv_snapshot_find(bs, old_sn, name);
+        ret = bdrv_snapshot_find(bs, old_sn, name, NULL);
         if (ret >= 0) {
             pstrcpy(sn->name, sizeof(sn->name), old_sn->name);
             pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);
@@ -2218,7 +2226,7 @@  int load_vmstate(const char *name)
     }
 
     /* Don't even try to load empty VM states */
-    ret = bdrv_snapshot_find(bs_vm_state, &sn, name);
+    ret = bdrv_snapshot_find(bs_vm_state, &sn, name, NULL);
     if (ret < 0) {
         return ret;
     } else if (sn.vm_state_size == 0) {
@@ -2242,7 +2250,7 @@  int load_vmstate(const char *name)
             return -ENOTSUP;
         }
 
-        ret = bdrv_snapshot_find(bs, &sn, name);
+        ret = bdrv_snapshot_find(bs, &sn, name, NULL);
         if (ret < 0) {
             error_report("Device '%s' does not have the requested snapshot '%s'",
                            bdrv_get_device_name(bs), name);
@@ -2348,7 +2356,7 @@  void do_info_snapshots(Monitor *mon)
 
         while ((bs1 = bdrv_next(bs1))) {
             if (bdrv_can_snapshot(bs1) && bs1 != bs) {
-                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str);
+                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL);
                 if (ret < 0) {
                     available = 0;
                     break;