From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [RFC 6/8] savevm: add QEMUFile->visitor lookup routines
Date: Mon, 19 Sep 2011 09:41:47 -0500 [thread overview]
Message-ID: <1316443309-23843-7-git-send-email-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <1316443309-23843-1-git-send-email-mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
hw/hw.h | 19 +++++++++++++++++
qemu-file.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index 244bfb9..e6d7c6a 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -10,6 +10,25 @@
#include "ioport.h"
#include "irq.h"
+#include "qemu-queue.h"
+#include "qapi/qapi-visit-core.h"
+#include "qapi/qemu-file-output-visitor.h"
+#include "qapi/qemu-file-input-visitor.h"
+
+/* QEMUFile->Visitor lookup routines to support legacy qemu_put_* calls */
+typedef struct QemuFileVisitorNode {
+ void *opaque; /* Visitor type */
+ QemuFileOutputVisitor *ov;
+ QemuFileInputVisitor *iv;
+ QEMUFile *f;
+ QTAILQ_ENTRY(QemuFileVisitorNode) entry;
+} QemuFileVisitorNode;
+
+Visitor *qemu_file_get_input_visitor(QEMUFile *f);
+Visitor *qemu_file_get_output_visitor(QEMUFile *f);
+QemuFileVisitorNode *qemu_file_get_visitor_node(QEMUFile *f);
+void qemu_file_put_visitor_node(QemuFileVisitorNode *n);
+void qemu_file_remove_visitor_node(QemuFileVisitorNode *n);
/* VM Load/Save */
diff --git a/qemu-file.c b/qemu-file.c
index fb91b91..ec69627 100644
--- a/qemu-file.c
+++ b/qemu-file.c
@@ -25,6 +25,8 @@
#include "qemu-common.h"
#include "qemu_socket.h"
#include "hw/hw.h"
+#include "qapi/qemu-file-output-visitor.h"
+#include "qapi/qemu-file-input-visitor.h"
#define IO_BUF_SIZE 32768
@@ -47,6 +49,61 @@ struct QEMUFile {
int has_error;
};
+/* TODO: temporary mechanism to support existing function signatures by
+ * creating a 1-to-1 mapping between QEMUFile's and the actual Visitor type.
+ * In the case of QemuFileOutputVisitor/QemuFileInputVisitor, the QEMUFile
+ * arg corresponds to the handle used by the visitor for reads/writes. For
+ * other visitors, the QEMUFile will serve purely as a key.
+ *
+ * Once all interfaces are converted to using Visitor directly, we will
+ * remove this lookup logic and pass the Visitor to the registered save/load
+ * functions directly.
+ */
+static QTAILQ_HEAD(, QemuFileVisitorNode) qemu_file_visitors =
+ QTAILQ_HEAD_INITIALIZER(qemu_file_visitors);
+
+QemuFileVisitorNode *qemu_file_get_visitor_node(QEMUFile *f)
+{
+ QemuFileVisitorNode *node;
+ QTAILQ_FOREACH(node, &qemu_file_visitors, entry) {
+ if (node->f == f) {
+ return node;
+ }
+ }
+ return NULL;
+}
+
+Visitor *qemu_file_get_output_visitor(QEMUFile *f)
+{
+ QemuFileVisitorNode *node = qemu_file_get_visitor_node(f);
+
+ if (node && node->ov) {
+ return qemu_file_output_get_visitor(node->ov);
+ }
+ return NULL;
+}
+
+Visitor *qemu_file_get_input_visitor(QEMUFile *f)
+{
+ QemuFileVisitorNode *node = qemu_file_get_visitor_node(f);
+
+ if (node && node->iv) {
+ return qemu_file_input_get_visitor(node->iv);
+ }
+ return NULL;
+}
+
+void qemu_file_put_visitor_node(QemuFileVisitorNode *node)
+{
+ QTAILQ_INSERT_TAIL(&qemu_file_visitors, node, entry);
+}
+
+void qemu_file_remove_visitor_node(QemuFileVisitorNode *node)
+{
+ QTAILQ_REMOVE(&qemu_file_visitors, node, entry);
+ g_free(node);
+}
+
QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
QEMUFileGetBufferFunc *get_buffer,
QEMUFileCloseFunc *close,
@@ -55,6 +112,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
QEMUFileGetRateLimit *get_rate_limit)
{
QEMUFile *f;
+ QemuFileVisitorNode *node;
f = g_malloc0(sizeof(QEMUFile));
@@ -67,6 +125,12 @@ QEMUFile *qemu_fopen_ops(void *opaque, QEMUFilePutBufferFunc *put_buffer,
f->get_rate_limit = get_rate_limit;
f->is_write = 0;
+ node = g_malloc0(sizeof(QemuFileVisitorNode));
+ node->ov = qemu_file_output_visitor_new(f);
+ node->iv = qemu_file_input_visitor_new(f);
+ node->f = f;
+ qemu_file_put_visitor_node(node);
+
return f;
}
--
1.7.0.4
next prev parent reply other threads:[~2011-09-19 14:43 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-19 14:41 [Qemu-devel] [RFC] New Migration Protocol using Visitor Interface Michael Roth
2011-09-19 14:41 ` [Qemu-devel] [RFC 1/8] qapi: add Visitor interfaces for uint*_t and int*_t Michael Roth
2011-09-19 14:41 ` [Qemu-devel] [RFC 2/8] qapi: add QemuFileOutputVisitor Michael Roth
2011-09-19 14:41 ` [Qemu-devel] [RFC 3/8] qapi: add QemuFileInputVisitor Michael Roth
2011-10-24 23:59 ` Chris Krumme
2011-09-19 14:41 ` [Qemu-devel] [RFC 4/8] savevm: move QEMUFile interfaces into qemu-file.c Michael Roth
2011-09-24 7:23 ` Blue Swirl
2011-09-19 14:41 ` [Qemu-devel] [RFC 5/8] qapi: test cases for QEMUFile input/output visitors Michael Roth
2011-09-19 14:41 ` Michael Roth [this message]
2011-09-19 14:41 ` [Qemu-devel] [RFC 7/8] cutil: add strocat(), to concat a string to an offset in another Michael Roth
2011-09-20 10:43 ` Paolo Bonzini
2011-09-19 14:41 ` [Qemu-devel] [RFC 8/8] slirp: convert save/load function to visitor interface Michael Roth
2011-09-30 13:39 ` Anthony Liguori
2011-09-30 14:08 ` Michael Roth
2011-10-02 20:21 ` [Qemu-devel] [RFC] New Migration Protocol using Visitor Interface Stefan Berger
2011-10-02 21:08 ` Michael S. Tsirkin
2011-10-03 12:55 ` Anthony Liguori
2011-10-03 13:10 ` Stefan Berger
2011-10-03 13:18 ` Anthony Liguori
2011-10-03 13:30 ` Michael S. Tsirkin
2011-10-03 13:48 ` Anthony Liguori
2011-10-03 14:18 ` Michael S. Tsirkin
2011-10-03 14:56 ` Anthony Liguori
2011-10-03 15:42 ` Michael S. Tsirkin
2011-10-03 13:38 ` Michael S. Tsirkin
2011-10-03 13:51 ` Anthony Liguori
2011-10-03 14:41 ` Michael S. Tsirkin
2011-10-03 15:00 ` Anthony Liguori
2011-10-03 15:45 ` Michael S. Tsirkin
2011-10-03 16:05 ` Anthony Liguori
2011-10-03 16:24 ` Daniel P. Berrange
2011-10-03 16:51 ` Michael S. Tsirkin
2011-10-05 11:28 ` Michael S. Tsirkin
2011-10-05 12:46 ` Anthony Liguori
2011-10-03 6:46 ` Michael S. Tsirkin
2011-10-03 12:51 ` Anthony Liguori
2011-10-03 13:24 ` Michael S. Tsirkin
2011-10-03 13:43 ` Anthony Liguori
2011-10-03 14:11 ` Michael S. Tsirkin
2011-10-03 14:42 ` Anthony Liguori
2011-10-03 15:29 ` Michael S. Tsirkin
2011-10-03 15:44 ` Anthony Liguori
2011-10-03 15:58 ` Michael S. Tsirkin
2011-10-03 16:02 ` Anthony Liguori
2011-10-03 14:15 ` Michael S. Tsirkin
2011-10-03 14:55 ` Anthony Liguori
2011-10-03 15:41 ` Michael S. Tsirkin
2011-10-05 2:05 ` Stefan Berger
2011-10-05 12:54 ` Anthony Liguori
2011-10-05 19:06 ` Michael S. Tsirkin
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=1316443309-23843-7-git-send-email-mdroth@linux.vnet.ibm.com \
--to=mdroth@linux.vnet.ibm.com \
--cc=aliguori@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/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).