[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 3/6] QMP: Reserve namespace for complex object c

From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH 3/6] QMP: Reserve namespace for complex object classes
Date: Fri, 02 Sep 2011 13:02:04 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10

On 09/02/2011 12:23 PM, Luiz Capitulino wrote:
On Fri, 26 Aug 2011 16:48:13 +0200
Jan Kiszka<address@hidden>  wrote:

This reserves JSON objects that contain the key '__class__' for QMP-specific
complex objects. First user will be the buffer class.

BTW, we need to teach QAPI how handle these types.

QAPI already has the information about the class that it's working with. I think that means you can probably do something like this (completely untested):

diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index 4419a31..9895792 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -105,6 +105,8 @@ static void qmp_output_start_struct(Visitor *v, void **obj,

     qmp_output_add(qov, name, dict);
     qmp_output_push(qov, dict);
+    visit_type_str(v, "__class__", kind, errp);

 static void qmp_output_end_struct(Visitor *v, Error **errp)

That will add class information for every type that gets written by QAPI. Likewise:

diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index fcf8bf9..77e7ab4 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -86,6 +86,7 @@ static void qmp_input_start_struct(Visitor *v, void **obj, con
     QmpInputVisitor *qiv = to_qiv(v);
     const QObject *qobj = qmp_input_get_object(qiv, name);
+    char *type;

     if (!qobj || qobject_type(qobj) != QTYPE_QDICT) {
         error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
@@ -101,6 +102,15 @@ static void qmp_input_start_struct(Visitor *v, void **obj,
     if (obj) {
         *obj = g_malloc0(size);
+    visit_type_str(v, &type, "__class__", errp);
+    if (error_is_set(errp)) {
+        return;
+    }

Will do type checking on incoming data.

Maybe we should relax that and only do the type checking if __class__ is specified..


Anthony Liguori

CC: Luiz Capitulino<address@hidden>
Signed-off-by: Jan Kiszka<address@hidden>
  QMP/qmp-spec.txt |   16 +++++++++++++---
  1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/QMP/qmp-spec.txt b/QMP/qmp-spec.txt
index 9d30a8c..fa1dd62 100644
--- a/QMP/qmp-spec.txt
+++ b/QMP/qmp-spec.txt
@@ -146,6 +146,15 @@ The format is:
  For a listing of supported asynchronous events, please, refer to the
  qmp-events.txt file.

+2.6 Complex object classes
+JSON objects that contain the key-value pair '"__class__": json-string' are
+reserved for QMP-specific complex object classes that. QMP specifies which

Can I just drop the period or is it misplaced?

+further keys each of these objects include and how they are encoded.
+So far, no complex object class is specified.
  3. QMP Examples

@@ -229,9 +238,10 @@ avoid modifying QMP.  Both upstream and downstream need to 
take care to
  preserve long-term compatibility and interoperability.

  To help with that, QMP reserves JSON object member names beginning with
-'__' (double underscore) for downstream use ("downstream names").  This
-means upstream will never use any downstream names for its commands,
-arguments, errors, asynchronous events, and so forth.
+'__' (double underscore) for downstream use ("downstream names").  Downstream
+names MUST NOT end with '__' as this pattern is reserved for QMP-defined JSON
+object classes.  Upstream will never use any downstream names for its
+commands, arguments, errors, asynchronous events, and so forth.

  Any new names downstream wishes to add must begin with '__'.  To
  ensure compatibility with other downstreams, it is strongly

reply via email to

[Prev in Thread] Current Thread [Next in Thread]