qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
Cc: Juan Quintela <quintela@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t
Date: Tue, 20 Dec 2011 12:43:31 +0100	[thread overview]
Message-ID: <4EF074E3.1090505@redhat.com> (raw)
In-Reply-To: <4EF06D87.9000809@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2729 bytes --]

On 12/20/2011 12:12 PM, Paolo Bonzini wrote:
>
> I think this approach is wrong.  We're mashing the design of vmstate
> with that of visitors and getting something that is not a visitor and
> not vmstate.
>
> Instead, I think you should have something like this:
>
>      struct VMStateInfo {
>          const char *name;
>          // takes a QMPOutputVisitor and a QEMUFile open for reading
>          int (*load)(QEMUFile *f, const char *name, Visitor *v,
>                      size_t size, Error **err);
>
>          // takes a QMPInputVisitor and a QEMUFile open for writing
>          void (*save)(QEMUFile *f, const char *name, Visitor *v,
>                      size_t size, Error **err);
>
>          // takes a QMPOutputVisitor and reads from *pv
>          int (*get)(Visitor *v, const char *name, void *pv,
>                     size_t size, Error **err);
>
>          // takes a QMPInputVisitor and writes into *pv
>          void (*set)(Visitor *v, const char *name, void *pv,
>                     size_t size, Error **err);
>      };
>
> that splits the existing callbacks in two steps.
>
> For saving, you would adapt your visitor-based vmstate "put" routines so
> that they put things in a dictionary with no regard for integer types (a
> bit ugly for uint64, but perfectly fine for everything else).  You take
> the dictionary from the output visitor and (with an input visitor) you
> feed it back to the "save" routines, which convert the dictionary to a
> QEMUFile.  Both steps keep the types internal to vmstate.
>
> For loading, it's the other way round: you interpret the vmstate with
> the QEMUFile reading routines, and create a dictionary.  Then make an
> input visitor and use the vmstate "set" interpreter to fill in the
> struct fields.
>
> I'm sorry for noticing this just now, I was waiting for Anthony's QOM
> plans to be committed so that I could understand better how vmstate and
> QOM properties would interact.  In fact, it would be great and not hard
> if the struct<->visitor step (get/set) was also exposed as a QOM property.

Note that this doesn't prevent sharing the code for loading and saving.

1) You can still add a vtable to QEMUFile for "visit_type_int*" and 
"visit_type_uint*".  But this vtable doesn't need start/end callbacks.

2) Similarly, I don't object to adding visit_type_int* and 
visit_type_uint* to Visitor.  However, these should be exclusively a 
convenience for the callers, so that they do not have to convert between 
int64 and other types.  There should be exactly two implementations of 
these callbacks, one for input visitors (including e.g. the dealloc 
visitor) and one for output visitors.  I attach a sample patch that does 
this for int16 only.

Paolo

[-- Attachment #2: qapi-visitor-types.patch --]
[-- Type: text/x-patch, Size: 4682 bytes --]

diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index a154523..17964ad 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -154,6 +154,7 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void)
 
     v = g_malloc0(sizeof(*v));
 
+    qapi_init_input_visitor(&v->visitor);
     v->visitor.start_struct = qapi_dealloc_start_struct;
     v->visitor.end_struct = qapi_dealloc_end_struct;
     v->visitor.start_list = qapi_dealloc_start_list;
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index ddef3ed..5c1881d 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -116,3 +116,37 @@ void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp)
         v->type_number(v, obj, name, errp);
     }
 }
+
+static void visit_type_int16_in(Visitor *v, int16_t *obj, const char *name, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        int64_t value;
+        v->type_int(v, &value, name, errp);
+        *obj = value;
+    }
+}
+
+static void visit_type_int16_out(Visitor *v, int16_t *obj, const char *name, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        int64_t value = *obj;
+        v->type_int(v, &value, name, errp);
+    }
+}
+
+void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        v->type_int16(v, obj, name, errp);
+    }
+}
+
+void qapi_init_input_visitor(Visitor *v)
+{
+    v->type_int16 = visit_type_int16_in;
+}
+
+void qapi_init_output_visitor(Visitor *v)
+{
+    v->type_int16 = visit_type_int16_out;
+}
diff --git a/qapi/qapi-visit-core.h b/qapi/qapi-visit-core.h
index e850746..c0395b3 100644
--- a/qapi/qapi-visit-core.h
+++ b/qapi/qapi-visit-core.h
@@ -52,6 +52,9 @@ struct Visitor
     void (*start_handle)(Visitor *v, void **obj, const char *kind,
                          const char *name, Error **errp);
     void (*end_handle)(Visitor *v, Error **errp);
+
+    /* Internal only.  */
+    void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp);
 };
 
 void visit_start_handle(Visitor *v, void **obj, const char *kind,
@@ -69,8 +72,24 @@ void visit_end_optional(Visitor *v, Error **errp);
 void visit_type_enum(Visitor *v, int *obj, const char *strings[],
                      const char *kind, const char *name, Error **errp);
 void visit_type_int(Visitor *v, int64_t *obj, const char *name, Error **errp);
+void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
 
+static inline void visit_type_uint(Visitor *v, uint64_t *obj,
+                                   const char *name, Error **errp)
+{
+    visit_type_int(v, (int64_t *) obj, name, errp);
+}
+
+static inline void visit_type_uint16(Visitor *v, uint16_t *obj,
+                                     const char *name, Error **errp)
+{
+    visit_type_int16(v, (int16_t *) obj, name, errp);
+}
+
+void qapi_init_input_visitor(Visitor *v);
+void qapi_init_output_visitor(Visitor *v);
+
 #endif
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index c78022b..67da359 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -283,6 +283,7 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj)
 
     v = g_malloc0(sizeof(*v));
 
+    qapi_init_input_visitor(&v->visitor);
     v->visitor.start_struct = qmp_input_start_struct;
     v->visitor.end_struct = qmp_input_end_struct;
     v->visitor.start_list = qmp_input_start_list;
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index f76d015..65f8e3e 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -234,6 +234,7 @@ QmpOutputVisitor *qmp_output_visitor_new(void)
 
     v = g_malloc0(sizeof(*v));
 
+    qapi_init_output_visitor(&v->visitor);
     v->visitor.start_struct = qmp_output_start_struct;
     v->visitor.end_struct = qmp_output_end_struct;
     v->visitor.start_list = qmp_output_start_list;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 663c2a0..77bc529 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -229,10 +229,8 @@ static void get_int16(DeviceState *dev, Visitor *v, void *opaque,
 {
     Property *prop = opaque;
     int16_t *ptr = qdev_get_prop_ptr(dev, prop);
-    int64_t value;
 
-    value = *ptr;
-    visit_type_int(v, &value, name, errp);
+    visit_type_int16(v, ptr, name, errp);
 }
 
 static void set_int16(DeviceState *dev, Visitor *v, void *opaque,

  reply	other threads:[~2011-12-20 11:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-27 17:06 [Qemu-devel] [PATCH v2 00/10] do savevm/migration save/load via Visitor interface Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 01/10] qapi: add Visitor interfaces for uint*_t and int*_t Michael Roth
2011-12-20 11:12   ` Paolo Bonzini
2011-12-20 11:43     ` Paolo Bonzini [this message]
2011-12-20 12:00       ` Paolo Bonzini
2011-12-20 13:50     ` Anthony Liguori
2011-12-20 14:30       ` Paolo Bonzini
2011-12-20 20:22         ` Michael Roth
2011-12-21 12:29           ` Paolo Bonzini
2011-12-20 20:56         ` Anthony Liguori
2011-12-21 12:35           ` Paolo Bonzini
2011-12-21 14:45             ` Anthony Liguori
2011-12-21 15:39               ` Paolo Bonzini
2011-12-21 16:24                 ` Anthony Liguori
2011-12-21 16:52                   ` Paolo Bonzini
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 02/10] qapi: add QemuFileOutputVisitor Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 03/10] qapi: add QemuFileInputVisitor Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 04/10] savevm: move QEMUFile interfaces into qemu-file.c Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 05/10] qapi: test cases for QEMUFile input/output visitors Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 06/10] qemu-file: add QEMUFile<->visitor lookup routines Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 07/10] trace: qemu_(put|get)_(byte|buffer) events Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 08/10] trace: add trace statements for visitor interface Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 09/10] qapi: add trace statements to qapi-visit-core.c Michael Roth
2011-10-27 17:06 ` [Qemu-devel] [PATCH v2 10/10] vmstate: use visitors Michael Roth

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=4EF074E3.1090505@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.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).