Patchwork [RFC,11/16] Choose output visitor based on env variable

login
register
mail settings
Submitter Dave Gilbert
Date March 25, 2014, 8:17 p.m.
Message ID <1395778647-30925-12-git-send-email-dgilbert@redhat.com>
Download mbox | patch
Permalink /patch/333700/
State New
Headers show

Comments

Dave Gilbert - March 25, 2014, 8:17 p.m.
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 savevm.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

Patch

diff --git a/savevm.c b/savevm.c
index 7431773..25e92f2 100644
--- a/savevm.c
+++ b/savevm.c
@@ -26,6 +26,7 @@ 
 #include "qemu-common.h"
 #include "qapi/qemu-file-binary-input-visitor.h"
 #include "qapi/qemu-file-binary-output-visitor.h"
+#include "qapi/qemu-file-debug-output-visitor.h"
 #include "hw/hw.h"
 #include "hw/qdev.h"
 #include "net/net.h"
@@ -524,6 +525,35 @@  bool qemu_savevm_state_blocked(Error **errp)
     return false;
 }
 
+/* Return a visitor for use on the QEMUFile; visit_destroy should be
+ * called on it to clean it up.
+ */
+static Visitor *qemu_savevm_get_visitor(QEMUFile *f)
+{
+    char *formatvar = getenv("QEMUMIGFORMAT");
+
+    if (formatvar && (!strcmp(formatvar, "debug"))) {
+        QemuFileDebugOutputVisitor *qfdov =
+            qemu_file_debug_output_visitor_new(f);
+        Visitor *v = qemu_file_debug_output_get_visitor(qfdov);
+
+        qemu_file_set_tmp_visitor(f, v);
+        return v;
+    }
+
+    if (formatvar) {
+        error_report("QEMUMIGFORMAT set to unknown value '%s'", formatvar);
+        assert(0);
+    }
+
+    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
+    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
+
+    qemu_file_set_tmp_visitor(f, v);
+
+    return v;
+}
+
 void qemu_savevm_state_begin(QEMUFile *f,
                              const MigrationParams *params)
 {
@@ -531,10 +561,7 @@  void qemu_savevm_state_begin(QEMUFile *f,
     int ret;
     Error *local_err = NULL;
     SectionHeader sh;
-
-    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
-    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
-    qemu_file_set_tmp_visitor(f, v);
+    Visitor *v = qemu_savevm_get_visitor(f);
 
     QTAILQ_FOREACH(se, &savevm_handlers, entry) {
         if (!se->ops || !se->ops->set_params) {
@@ -781,13 +808,11 @@  static int qemu_savevm_state(QEMUFile *f)
 
 static int qemu_save_device_state(QEMUFile *f)
 {
+    Visitor *v = qemu_savevm_get_visitor(f);
     SaveStateEntry *se;
     Error *local_err;
     SectionHeader sh;
 
-    QemuFileBinOutputVisitor *qfbov = qemu_file_bin_output_visitor_new(f);
-    qemu_file_set_tmp_visitor(f, qemu_file_bin_output_get_visitor(qfbov));
-    Visitor *v = qemu_file_bin_output_get_visitor(qfbov);
     int32_t section_type;
 
     cpu_synchronize_all_states();