From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanb@linux.vnet.ibm.com, quintela@redhat.com,
mdroth@linux.vnet.ibm.com, agraf@suse.de, mst@redhat.com,
aliguori@amazon.com, afaerber@suse.de
Subject: [Qemu-devel] [RFC PATCH 16/16] Wire in BER visitors
Date: Tue, 25 Mar 2014 20:17:27 +0000 [thread overview]
Message-ID: <1395778647-30925-17-git-send-email-dgilbert@redhat.com> (raw)
In-Reply-To: <1395778647-30925-1-git-send-email-dgilbert@redhat.com>
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
BER output visitor to be selected with env (as other output visitors)
BER input visitor recognized by file header
exec.c: Set cpu-common to use it's own type tag (as example)
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
exec.c | 2 ++
include/migration/migration.h | 2 ++
savevm.c | 76 +++++++++++++++++++++++++++++++------------
3 files changed, 60 insertions(+), 20 deletions(-)
diff --git a/exec.c b/exec.c
index 91513c6..e2f3907 100644
--- a/exec.c
+++ b/exec.c
@@ -23,6 +23,7 @@
#endif
#include "qemu-common.h"
+#include "qapi/ber.h"
#include "cpu.h"
#include "tcg.h"
#include "hw/hw.h"
@@ -427,6 +428,7 @@ static int cpu_common_post_load(void *opaque, int version_id)
const VMStateDescription vmstate_cpu_common = {
.name = "cpu_common",
+ .ber_tag = BER_TYPE_QEMU_VMSTATE_CPU_COMMON,
.version_id = 1,
.minimum_version_id = 1,
.minimum_version_id_old = 1,
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 1987e79..7ddb934 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -27,6 +27,8 @@
#define QEMU_VM_FILE_VERSION_COMPAT 0x00000002
#define QEMU_VM_FILE_VERSION 0x00000003
+#define QEMU_VM_BER_FILE_MAGIC 0x7fcdc551
+
#define QEMU_VM_EOF 0x00
#define QEMU_VM_SECTION_START 0x01
#define QEMU_VM_SECTION_PART 0x02
diff --git a/savevm.c b/savevm.c
index 25e92f2..3dbfd79 100644
--- a/savevm.c
+++ b/savevm.c
@@ -24,6 +24,8 @@
#include "config-host.h"
#include "qemu-common.h"
+#include "qapi/qemu-file-ber-output-visitor.h"
+#include "qapi/qemu-file-ber-input-visitor.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"
@@ -532,6 +534,14 @@ static Visitor *qemu_savevm_get_visitor(QEMUFile *f)
{
char *formatvar = getenv("QEMUMIGFORMAT");
+ if (formatvar && (!strcmp(formatvar, "BER"))) {
+ QemuFileBEROutputVisitor *qfberov = qemu_file_ber_output_visitor_new(f);
+ Visitor *v = qemu_file_ber_output_get_visitor(qfberov);
+
+ qemu_file_set_tmp_visitor(f, v);
+ return v;
+ }
+
if (formatvar && (!strcmp(formatvar, "debug"))) {
QemuFileDebugOutputVisitor *qfdov =
qemu_file_debug_output_visitor_new(f);
@@ -876,41 +886,65 @@ typedef struct LoadStateEntry {
int version_id;
} LoadStateEntry;
+/* Given a just opened input QEMUFile, peak at the header and figure
+ * out which visitor should be used for it.
+ * Return the visitor ready for use.
+ */
+static Visitor *pick_input_visitor(QEMUFile *f)
+{
+ uint32_t tmp32;
+
+ if (qemu_peek_buffer(f, (uint8_t *)&tmp32, 4, 0) != 4) {
+ fprintf(stderr, "Failed to read SaveVM header word\n");
+ return NULL;
+ }
+
+ tmp32 = be32_to_cpu(tmp32);
+
+ switch (tmp32) {
+ case QEMU_VM_FILE_MAGIC: {
+ QemuFileBinInputVisitor *qfbiv = qemu_file_bin_input_visitor_new(f);
+ Visitor *v = qemu_file_bin_input_get_visitor(qfbiv);
+ qemu_file_set_tmp_visitor(f, v);
+
+ return v;
+ }
+
+ case QEMU_VM_BER_FILE_MAGIC: {
+ QemuFileBERInputVisitor *qfberiv = qemu_file_ber_input_visitor_new(f);
+ Visitor *v = qemu_file_ber_input_get_visitor(qfberiv);
+ qemu_file_set_tmp_visitor(f, v);
+
+ return v;
+ }
+
+ default:
+ fprintf(stderr, "Invalid SaveVM header (0x%x)\n", tmp32);
+ return NULL;
+ }
+}
+
int qemu_loadvm_state(QEMUFile *f)
{
QLIST_HEAD(, LoadStateEntry) loadvm_handlers =
QLIST_HEAD_INITIALIZER(loadvm_handlers);
LoadStateEntry *le, *new_le;
+ Visitor *v;
Error *local_err = NULL;
int32_t section_type;
- unsigned int tmp;
int ret;
if (qemu_savevm_state_blocked(NULL)) {
return -EINVAL;
}
- tmp = qemu_get_be32(f);
- if (tmp != QEMU_VM_FILE_MAGIC) {
- return -EINVAL;
- }
-
- tmp = qemu_get_be32(f);
- if (tmp == QEMU_VM_FILE_VERSION_COMPAT) {
- error_report("SaveVM v2 format is obsolete and don't work anymore");
+ v = pick_input_visitor(f);
+ if (!v) {
return -ENOTSUP;
}
- if (tmp != QEMU_VM_FILE_VERSION) {
- return -ENOTSUP;
- }
-
- /* TODO: Here we should be able to figure out if it's a binary file
- * or what and open the right type of visitor
- */
- QemuFileBinInputVisitor *qfbiv = qemu_file_bin_input_visitor_new(f);
- Visitor *v = qemu_file_bin_input_get_visitor(qfbiv);
- qemu_file_set_tmp_visitor(f, v);
+ visit_start_sequence_compat(v, "file", VISIT_SEQ_COMPAT_FILE, NULL,
+ &local_err);
visit_start_sequence_compat(v, "top", VISIT_SEQ_COMPAT_BYTE0TERM,
NULL, &local_err);
while (visit_get_next_type(v, §ion_type, NULL, "section", &local_err),
@@ -927,6 +961,7 @@ int qemu_loadvm_state(QEMUFile *f)
"secstart" : "secfull",
VISIT_SEQ_COMPAT_SECTION_HEADER, &sh, &local_err);
if (local_err) {
+ error_report("%s", error_get_pretty(local_err));
ret = -EINVAL;
goto out;
}
@@ -1016,6 +1051,7 @@ out:
}
visit_end_sequence_compat(v, "top", VISIT_SEQ_COMPAT_BYTE0TERM, &local_err);
+ visit_end_sequence_compat(v, "file", VISIT_SEQ_COMPAT_FILE, &local_err);
if (local_err) {
error_report("%s", error_get_pretty(local_err));
ret = -EINVAL;
@@ -1025,7 +1061,7 @@ out:
ret = qemu_file_get_error(f);
}
- qemu_file_bin_input_visitor_cleanup(qfbiv);
+ visit_destroy(v, &local_err);
return ret;
}
--
1.8.5.3
next prev parent reply other threads:[~2014-03-25 20:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-25 20:17 [Qemu-devel] [RFC PATCH 00/16] visitor+BER migration format Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 01/16] Visitor: Add methods for migration format use Dr. David Alan Gilbert (git)
2014-06-05 17:00 ` Markus Armbruster
2014-06-05 17:43 ` Dr. David Alan Gilbert
2014-06-05 18:59 ` Dr. David Alan Gilbert
2014-06-06 8:19 ` Markus Armbruster
2014-06-06 11:44 ` Dr. David Alan Gilbert
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 02/16] QEMUSizedBuffer/QEMUFile Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 03/16] qemu-file: Add set/get tmp_visitor Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 04/16] Header/constant/types fixes for visitors Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 05/16] Visitor: Binary compatible output visitor Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 06/16] Visitor: Debug " Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 07/16] Visitor: Binary compatible input visitor Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 08/16] Visitor: Output path Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 09/16] Visitor: Load path Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 10/16] Visitor: Common types to use visitors Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 11/16] Choose output visitor based on env variable Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 12/16] BER Visitor: Create output visitor Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 13/16] BER Visitor: Create input visitor Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 14/16] Start some BER format docs Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` [Qemu-devel] [RFC PATCH 15/16] ASN.1 schema for new migration format Dr. David Alan Gilbert (git)
2014-03-25 20:17 ` Dr. David Alan Gilbert (git) [this message]
2014-03-25 20:43 ` [Qemu-devel] [RFC PATCH 00/16] visitor+BER " Michael S. Tsirkin
2014-03-26 9:16 ` Dr. David Alan Gilbert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395778647-30925-17-git-send-email-dgilbert@redhat.com \
--to=dgilbert@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aliguori@amazon.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanb@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).