Patchwork [RFC,1/2] live backup vm, export functions

login
register
mail settings
Submitter Wayne Xia
Date Dec. 8, 2012, 8:24 a.m.
Message ID <1354955059-14391-2-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/204429/
State New
Headers show

Comments

Wayne Xia - Dec. 8, 2012, 8:24 a.m.
This patch moved bdrv_snapshot_find() from savevm.c to block.c,
also exports some function in savevm.c.

Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
---
 block.c  |   21 +++++++++++++++++++++
 block.h  |    2 ++
 savevm.c |   37 +++++++++++--------------------------
 sysemu.h |    2 ++
 4 files changed, 36 insertions(+), 26 deletions(-)

Patch

diff --git a/block.c b/block.c
index c05875f..155b562 100644
--- a/block.c
+++ b/block.c
@@ -3322,6 +3322,27 @@  char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn)
     return buf;
 }
 
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
+                              const char *name)
+{
+    QEMUSnapshotInfo *sn_tab, *sn;
+    int nb_sns, i, ret;
+
+    ret = -ENOENT;
+    nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+    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)) {
+            *sn_info = *sn;
+            ret = 0;
+            break;
+        }
+    }
+    g_free(sn_tab);
+    return ret;
+}
 /**************************************************************/
 /* async I/Os */
 
diff --git a/block.h b/block.h
index 722c620..0838736 100644
--- a/block.h
+++ b/block.h
@@ -330,6 +330,8 @@  int bdrv_snapshot_list(BlockDriverState *bs,
 int bdrv_snapshot_load_tmp(BlockDriverState *bs,
                            const char *snapshot_name);
 char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn);
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
+                              const char *name);
 
 char *get_human_readable_size(char *buf, int buf_size, int64_t size);
 int path_is_absolute(const char *path);
diff --git a/savevm.c b/savevm.c
index 5d04d59..e1bad85 100644
--- a/savevm.c
+++ b/savevm.c
@@ -698,7 +698,7 @@  int qemu_get_byte(QEMUFile *f)
     return result;
 }
 
-static int64_t qemu_ftell(QEMUFile *f)
+int64_t qemu_ftell(QEMUFile *f)
 {
     return f->buf_offset - f->buf_size + f->buf_index;
 }
@@ -2061,32 +2061,10 @@  out:
     return ret;
 }
 
-static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                              const char *name)
-{
-    QEMUSnapshotInfo *sn_tab, *sn;
-    int nb_sns, i, ret;
-
-    ret = -ENOENT;
-    nb_sns = bdrv_snapshot_list(bs, &sn_tab);
-    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)) {
-            *sn_info = *sn;
-            ret = 0;
-            break;
-        }
-    }
-    g_free(sn_tab);
-    return ret;
-}
-
 /*
  * Deletes snapshots of a given name in all opened images.
  */
-static int del_existing_snapshots(Monitor *mon, const char *name)
+int del_existing_snapshots(Monitor *mon, Error **errp, const char *name)
 {
     BlockDriverState *bs;
     QEMUSnapshotInfo sn1, *snapshot = &sn1;
@@ -2099,9 +2077,16 @@  static int del_existing_snapshots(Monitor *mon, const char *name)
         {
             ret = bdrv_snapshot_delete(bs, name);
             if (ret < 0) {
-                monitor_printf(mon,
+                if (mon != NULL) {
+                    monitor_printf(mon,
                                "Error while deleting snapshot on '%s'\n",
                                bdrv_get_device_name(bs));
+                }
+                if (errp != NULL) {
+                    error_setg(errp,
+                               "Error while deleting snapshot on '%s'\n",
+                               bdrv_get_device_name(bs));
+                }
                 return -1;
             }
         }
@@ -2186,7 +2171,7 @@  void do_savevm(Monitor *mon, const QDict *qdict)
     }
 
     /* Delete old snapshots of the same name */
-    if (name && del_existing_snapshots(mon, name) < 0) {
+    if (name && del_existing_snapshots(mon, NULL, name) < 0) {
         goto the_end;
     }
 
diff --git a/sysemu.h b/sysemu.h
index f5ac664..f44f9ee 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -69,6 +69,8 @@  void do_savevm(Monitor *mon, const QDict *qdict);
 int load_vmstate(const char *name);
 void do_delvm(Monitor *mon, const QDict *qdict);
 void do_info_snapshots(Monitor *mon);
+int del_existing_snapshots(Monitor *mon, Error **errp, const char *name);
+int64_t qemu_ftell(QEMUFile *f);
 
 void qemu_announce_self(void);