Patchwork [RESEND,5/6] savevm: Allow set_params and save_live_state to error

login
register
mail settings
Submitter Alex Williamson
Date Nov. 5, 2010, 9:16 p.m.
Message ID <20101105211646.19958.43832.stgit@s20.home>
Download mbox | patch
Permalink /patch/70300/
State New
Headers show

Comments

Alex Williamson - Nov. 5, 2010, 9:16 p.m.
This lets a save state handler NAK a migration or cancel if
it runs into problems.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---

 block-migration.c |    4 +++-
 hw/hw.h           |    2 +-
 savevm.c          |   18 +++++++++++++++---
 3 files changed, 19 insertions(+), 5 deletions(-)

Patch

diff --git a/block-migration.c b/block-migration.c
index 0bfdb73..5fb3b72 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -628,13 +628,15 @@  static int block_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void block_set_params(int blk_enable, int shared_base, void *opaque)
+static int block_set_params(int blk_enable, int shared_base, void *opaque)
 {
     block_mig_state.blk_enable = blk_enable;
     block_mig_state.shared_base = shared_base;
 
     /* shared base means that blk_enable = 1 */
     block_mig_state.blk_enable |= shared_base;
+
+    return 0;
 }
 
 void blk_mig_init(void)
diff --git a/hw/hw.h b/hw/hw.h
index 3ef67c8..dac89c7 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -239,7 +239,7 @@  static inline void qemu_get_sbe64s(QEMUFile *f, int64_t *pv)
 int64_t qemu_ftell(QEMUFile *f);
 int64_t qemu_fseek(QEMUFile *f, int64_t pos, int whence);
 
-typedef void SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
+typedef int SaveSetParamsHandler(int blk_enable, int shared, void * opaque);
 typedef int SaveStateHandler(QEMUFile *f, void *opaque);
 typedef int SaveLiveStateHandler(Monitor *mon, QEMUFile *f, int stage,
                                  void *opaque);
diff --git a/savevm.c b/savevm.c
index ade7eb5..521edc8 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1435,12 +1435,16 @@  int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
                             int shared)
 {
     SaveStateEntry *se;
+    int ret;
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         if(se->set_params == NULL) {
             continue;
 	}
-	se->set_params(blk_enable, shared, se->opaque);
+	ret = se->set_params(blk_enable, shared, se->opaque);
+        if (ret < 0) {
+            return ret;
+        }
     }
     
     qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
@@ -1464,7 +1468,10 @@  int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
         qemu_put_be32(f, se->instance_id);
         qemu_put_be32(f, se->version_id);
 
-        se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
+        ret = se->save_live_state(mon, f, QEMU_VM_SECTION_START, se->opaque);
+        if (ret < 0) {
+            return ret;
+        }
     }
 
     if (qemu_file_has_error(f)) {
@@ -1495,6 +1502,8 @@  int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
                and reduces the probability that a faster changing state is
                synchronized over and over again. */
             break;
+        } else if (ret < 0) {
+            return ret;
         }
     }
 
@@ -1524,7 +1533,10 @@  int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
         qemu_put_byte(f, QEMU_VM_SECTION_END);
         qemu_put_be32(f, se->section_id);
 
-        se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque);
+        r = se->save_live_state(mon, f, QEMU_VM_SECTION_END, se->opaque);
+        if (r < 0) {
+            return r;
+        }
     }
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {