All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions
@ 2011-09-28 14:44 Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 01/21] error: let error_is_type take a NULL error Luiz Capitulino
                   ` (21 more replies)
  0 siblings, 22 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

This series is a bundle of three things:

 1. Patches 01 to 04 add the middle mode feature to the current QMP server.
    That mode allows for the current server to support QAPI commands. The
    Original author is Anthony, you can find his original post here:

        http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg00374.html

 2. Patches 05 to 10 are fixes from Anthony and Michael to the QAPI
    handling of the list type.

 3. Patches 11 to 21 are simple monitor commands conversions to the QAPI.
    This is just a rebase of a previous conversion work by Anthony.

 Makefile                    |   12 ++
 Makefile.objs               |    3 +
 Makefile.target             |    6 +-
 error.c                     |    4 +
 hmp-commands.hx             |   11 +-
 hmp.c                       |  116 ++++++++++++++++++
 hmp.h                       |   31 +++++
 monitor.c                   |  273 +++++--------------------------------------
 qapi-schema.json            |  273 +++++++++++++++++++++++++++++++++++++++++++
 qapi/qapi-dealloc-visitor.c |   34 +++++-
 qapi/qapi-types-core.h      |    3 +
 qapi/qmp-input-visitor.c    |    4 +-
 qapi/qmp-output-visitor.c   |   20 +++-
 qemu-char.c                 |   35 ++----
 qerror.c                    |   33 +++++
 qerror.h                    |    2 +
 qmp-commands.hx             |   57 +++++++--
 qmp.c                       |   92 +++++++++++++++
 scripts/qapi-commands.py    |   98 ++++++++++++---
 scripts/qapi-types.py       |    5 +
 scripts/qapi-visit.py       |    4 +-
 scripts/qapi.py             |    4 +-
 test-qmp-commands.c         |   29 +++++
 test-visitor.c              |   48 +++++++--
 vl.c                        |   12 ++
 25 files changed, 877 insertions(+), 332 deletions(-)

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 01/21] error: let error_is_type take a NULL error
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 02/21] qerror: add qerror_report_err() Luiz Capitulino
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

Reported-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 error.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/error.c b/error.c
index b802752..68c0039 100644
--- a/error.c
+++ b/error.c
@@ -97,6 +97,10 @@ bool error_is_type(Error *err, const char *fmt)
     char *ptr;
     char *end;
 
+    if (!err) {
+        return false;
+    }
+
     ptr = strstr(fmt, "'class': '");
     assert(ptr != NULL);
     ptr += strlen("'class': '");
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 02/21] qerror: add qerror_report_err()
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 01/21] error: let error_is_type take a NULL error Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 03/21] qapi: add code generation support for middle mode Luiz Capitulino
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

This provides a bridge between Error (new error mechanism) and QError (old error
mechanism).  Errors can be propagated whereas QError cannot.

The minor evilness avoids layering violations.  Since QError should go away RSN,
it seems like a reasonable hack.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qerror.c |   33 +++++++++++++++++++++++++++++++++
 qerror.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/qerror.c b/qerror.c
index c591a54..68998d4 100644
--- a/qerror.c
+++ b/qerror.c
@@ -482,6 +482,39 @@ void qerror_report_internal(const char *file, int linenr, const char *func,
     }
 }
 
+/* Evil... */
+struct Error
+{
+    QDict *obj;
+    const char *fmt;
+    char *msg;
+};
+
+void qerror_report_err(Error *err)
+{
+    QError *qerr;
+    int i;
+
+    qerr = qerror_new();
+    loc_save(&qerr->loc);
+    QINCREF(err->obj);
+    qerr->error = err->obj;
+
+    for (i = 0; qerror_table[i].error_fmt; i++) {
+        if (strcmp(qerror_table[i].error_fmt, err->fmt) == 0) {
+            qerr->entry = &qerror_table[i];
+            break;
+        }
+    }
+
+    if (monitor_cur_is_qmp()) {
+        monitor_set_error(cur_mon, qerr);
+    } else {
+        qerror_print(qerr);
+        QDECREF(qerr);
+    }
+}
+
 /**
  * qobject_to_qerror(): Convert a QObject into a QError
  */
diff --git a/qerror.h b/qerror.h
index d407001..d4bfcfd 100644
--- a/qerror.h
+++ b/qerror.h
@@ -15,6 +15,7 @@
 #include "qdict.h"
 #include "qstring.h"
 #include "qemu-error.h"
+#include "error.h"
 #include <stdarg.h>
 
 typedef struct QErrorStringTable {
@@ -39,6 +40,7 @@ QString *qerror_human(const QError *qerror);
 void qerror_print(QError *qerror);
 void qerror_report_internal(const char *file, int linenr, const char *func,
                             const char *fmt, ...) GCC_FMT_ATTR(4, 5);
+void qerror_report_err(Error *err);
 QString *qerror_format(const char *fmt, QDict *error);
 #define qerror_report(fmt, ...) \
     qerror_report_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 03/21] qapi: add code generation support for middle mode
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 01/21] error: let error_is_type take a NULL error Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 02/21] qerror: add qerror_report_err() Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 04/21] qapi: use middle mode in QMP server Luiz Capitulino
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

To get the ball rolling merging QAPI, this patch introduces a "middle mode" to
the code generator.  In middle mode, the code generator generates marshalling
functions that are compatible with the current QMP server.  We absolutely need
to replace the current QMP server in order to support proper asynchronous
commands but using a middle mode provides a middle-ground that lets us start
converting commands in tree.

Note that all of the commands have been converted already in my glib branch.
Middle mode only exists until we finish merging them from my branch into the
main tree.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qapi/qapi-types-core.h   |    3 ++
 scripts/qapi-commands.py |   79 +++++++++++++++++++++++++++++++++++++--------
 scripts/qapi-types.py    |    3 ++
 scripts/qapi.py          |    4 ++-
 4 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/qapi/qapi-types-core.h b/qapi/qapi-types-core.h
index a79bc2b..27e6be0 100644
--- a/qapi/qapi-types-core.h
+++ b/qapi/qapi-types-core.h
@@ -17,4 +17,7 @@
 #include "qemu-common.h"
 #include "error.h"
 
+/* FIXME this is temporary until we remove middle mode */
+#include "monitor.h"
+
 #endif
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index bf61740..2776804 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -167,9 +167,10 @@ qmp_input_visitor_cleanup(mi);
     pop_indent()
     return ret.rstrip()
 
-def gen_marshal_output(name, args, ret_type):
+def gen_marshal_output(name, args, ret_type, middle_mode):
     if not ret_type:
         return ""
+
     ret = mcgen('''
 static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_out, Error **errp)
 {
@@ -188,16 +189,34 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-            c_ret_type=c_type(ret_type), c_name=c_var(name), ret_type=ret_type)
+                 c_ret_type=c_type(ret_type), c_name=c_var(name),
+                 ret_type=ret_type)
 
     return ret
 
-def gen_marshal_input(name, args, ret_type):
+def gen_marshal_input_decl(name, args, ret_type, middle_mode):
+    if middle_mode:
+        return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_var(name)
+    else:
+        return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_var(name)
+
+
+
+def gen_marshal_input(name, args, ret_type, middle_mode):
+    hdr = gen_marshal_input_decl(name, args, ret_type, middle_mode)
+
     ret = mcgen('''
-static void qmp_marshal_input_%(c_name)s(QDict *args, QObject **ret, Error **errp)
+%(header)s
 {
 ''',
-                c_name=c_var(name))
+                header=hdr)
+
+    if middle_mode:
+        ret += mcgen('''
+    Error *local_err = NULL;
+    Error **errp = &local_err;
+    QDict *args = (QDict *)qdict;
+''')
 
     if ret_type:
         if c_type(ret_type).endswith("*"):
@@ -220,6 +239,10 @@ static void qmp_marshal_input_%(c_name)s(QDict *args, QObject **ret, Error **err
                      visitor_input_containers_decl=gen_visitor_input_containers_decl(args),
                      visitor_input_vars_decl=gen_visitor_input_vars_decl(args),
                      visitor_input_block=gen_visitor_input_block(args, "QOBJECT(args)"))
+    else:
+        ret += mcgen('''
+    (void)args;
+''')
 
     ret += mcgen('''
     if (error_is_set(errp)) {
@@ -234,10 +257,29 @@ out:
 ''')
     ret += mcgen('''
 %(visitor_input_block_cleanup)s
+''',
+                 visitor_input_block_cleanup=gen_visitor_input_block(args, None,
+                                                                     dealloc=True))
+
+    if middle_mode:
+        ret += mcgen('''
+
+    if (local_err) {
+        qerror_report_err(local_err);
+        error_free(local_err);
+        return -1;
+    }
+    return 0;
+''')
+    else:
+        ret += mcgen('''
     return;
+''')
+
+    ret += mcgen('''
 }
-''',
-                 visitor_input_block_cleanup=gen_visitor_input_block(args, None, dealloc=True))
+''')
+
     return ret
 
 def gen_registry(commands):
@@ -284,7 +326,7 @@ def gen_command_decl_prologue(header, guard, prefix=""):
 #include "error.h"
 
 ''',
-                 header=basename(h_file), guard=guardname(h_file), prefix=prefix)
+                 header=basename(header), guard=guardname(header), prefix=prefix)
     return ret
 
 def gen_command_def_prologue(prefix="", proxy=False):
@@ -317,11 +359,11 @@ def gen_command_def_prologue(prefix="", proxy=False):
                 prefix=prefix)
     if not proxy:
         ret += '#include "%sqmp-commands.h"' % prefix
-    return ret + "\n"
+    return ret + "\n\n"
 
 
 try:
-    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:", ["prefix=", "output-dir=", "type="])
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "p:o:m", ["prefix=", "output-dir=", "type=", "middle"])
 except getopt.GetoptError, err:
     print str(err)
     sys.exit(1)
@@ -331,6 +373,7 @@ prefix = ""
 dispatch_type = "sync"
 c_file = 'qmp-marshal.c'
 h_file = 'qmp-commands.h'
+middle_mode = False
 
 for o, a in opts:
     if o in ("-p", "--prefix"):
@@ -339,6 +382,8 @@ for o, a in opts:
         output_dir = a + "/"
     elif o in ("-t", "--type"):
         dispatch_type = a
+    elif o in ("-m", "--middle"):
+        middle_mode = True
 
 c_file = output_dir + prefix + c_file
 h_file = output_dir + prefix + h_file
@@ -370,14 +415,20 @@ if dispatch_type == "sync":
         ret = generate_command_decl(cmd['command'], arglist, ret_type) + "\n"
         fdecl.write(ret)
         if ret_type:
-            ret = gen_marshal_output(cmd['command'], arglist, ret_type) + "\n"
+            ret = gen_marshal_output(cmd['command'], arglist, ret_type, middle_mode) + "\n"
             fdef.write(ret)
-        ret = gen_marshal_input(cmd['command'], arglist, ret_type) + "\n"
+
+        if middle_mode:
+            fdecl.write('%s;\n' % gen_marshal_input_decl(cmd['command'], arglist, ret_type, middle_mode))
+
+        ret = gen_marshal_input(cmd['command'], arglist, ret_type, middle_mode) + "\n"
         fdef.write(ret)
 
     fdecl.write("\n#endif\n");
-    ret = gen_registry(commands)
-    fdef.write(ret)
+
+    if not middle_mode:
+        ret = gen_registry(commands)
+        fdef.write(ret)
 
     fdef.flush()
     fdef.close()
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index cece325..fc0f7af 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -268,3 +268,6 @@ fdecl.write('''
 
 fdecl.flush()
 fdecl.close()
+
+fdef.flush()
+fdef.close()
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 56af232..5299976 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -200,4 +200,6 @@ def basename(filename):
     return filename.split("/")[-1]
 
 def guardname(filename):
-    return filename.replace("/", "_").replace("-", "_").split(".")[0].upper()
+    if filename.startswith('./'):
+        filename = filename[2:]
+    return filename.replace("/", "_").replace("-", "_").split(".")[0].upper() + '_H'
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 04/21] qapi: use middle mode in QMP server
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (2 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 03/21] qapi: add code generation support for middle mode Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 05/21] qapi: fixup command generation for functions that return list types Luiz Capitulino
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

Use the new middle mode within the existing QMP server.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile         |   12 ++++++++++++
 Makefile.objs    |    2 ++
 Makefile.target  |    6 +++---
 monitor.c        |    9 ++++-----
 qapi-schema.json |    3 +++
 5 files changed, 24 insertions(+), 8 deletions(-)
 create mode 100644 qapi-schema.json

diff --git a/Makefile b/Makefile
index 6ed3194..55ee79c 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
 ifeq ($(TRACE_BACKEND),dtrace)
 GENERATED_HEADERS += trace-dtrace.h
 endif
+GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -187,9 +188,20 @@ $(qapi-dir)/qga-qapi-types.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scr
 $(qapi-dir)/qga-qapi-visit.c: $(qapi-dir)/qga-qapi-visit.h
 $(qapi-dir)/qga-qapi-visit.h: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-visit.py
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
+$(qapi-dir)/qga-qmp-commands.h: $(qapi-dir)/qga-qmp-marshal.c
 $(qapi-dir)/qga-qmp-marshal.c: $(SRC_PATH)/qapi-schema-guest.json $(SRC_PATH)/scripts/qapi-commands.py
 	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -o "$(qapi-dir)" -p "qga-" < $<, "  GEN   $@")
 
+qapi-types.c: qapi-types.h
+qapi-types.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py -o "." < $<, "  GEN   $@")
+qapi-visit.c: qapi-visit.h
+qapi-visit.h: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py -o "."  < $<, "  GEN   $@")
+qmp-commands.h: qmp-marshal.c
+qmp-marshal.c: $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py
+	$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py -m -o "." < $<, "  GEN   $@")
+
 test-visitor.o: $(addprefix $(qapi-dir)/, test-qapi-types.c test-qapi-types.h test-qapi-visit.c test-qapi-visit.h) $(qapi-obj-y)
 test-visitor: test-visitor.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o $(qapi-obj-y) error.o osdep.o $(oslib-obj-y) qjson.o json-streamer.o json-lexer.o json-parser.o qerror.o qemu-error.o qemu-tool.o $(qapi-dir)/test-qapi-visit.o $(qapi-dir)/test-qapi-types.o
 
diff --git a/Makefile.objs b/Makefile.objs
index 1c65087..441d797 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -406,6 +406,8 @@ qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-
 qapi-nested-y += qmp-registry.o qmp-dispatch.o
 qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
 
+common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y)
+
 ######################################################################
 # guest agent
 
diff --git a/Makefile.target b/Makefile.target
index 88d2f1f..b5ed5df 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -375,7 +375,7 @@ obj-xtensa-y += xtensa-semi.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: hmp-commands.h qmp-commands.h
+monitor.o: hmp-commands.h qmp-commands-old.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -407,13 +407,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
 hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
-qmp-commands.h: $(SRC_PATH)/qmp-commands.hx
+qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
 clean:
 	rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o
 	rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o
-	rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
 ifdef CONFIG_TRACE_SYSTEMTAP
 	rm -f *.stp
 endif
diff --git a/monitor.c b/monitor.c
index 8ec2c5e..150fe45 100644
--- a/monitor.c
+++ b/monitor.c
@@ -121,6 +121,7 @@ typedef struct mon_cmd_t {
         int  (*cmd_async)(Monitor *mon, const QDict *params,
                           MonitorCompletion *cb, void *opaque);
     } mhandler;
+    bool qapi;
     int flags;
 } mon_cmd_t;
 
@@ -3169,7 +3170,7 @@ static const mon_cmd_t info_cmds[] = {
 };
 
 static const mon_cmd_t qmp_cmds[] = {
-#include "qmp-commands.h"
+#include "qmp-commands-old.h"
     { /* NULL */ },
 };
 
@@ -5094,12 +5095,10 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         goto err_out;
     }
 
-    if (strstart(cmd_name, "query-", &query_cmd)) {
+    cmd = qmp_find_cmd(cmd_name);
+    if (!cmd && strstart(cmd_name, "query-", &query_cmd)) {
         cmd = qmp_find_query_cmd(query_cmd);
-    } else {
-        cmd = qmp_find_cmd(cmd_name);
     }
-
     if (!cmd) {
         qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
         goto err_out;
diff --git a/qapi-schema.json b/qapi-schema.json
new file mode 100644
index 0000000..7fcefdb
--- /dev/null
+++ b/qapi-schema.json
@@ -0,0 +1,3 @@
+# -*- Mode: Python -*-
+#
+# QAPI Schema
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 05/21] qapi: fixup command generation for functions that return list types
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (3 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 04/21] qapi: use middle mode in QMP server Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic Luiz Capitulino
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 scripts/qapi-commands.py |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 2776804..c947ba4 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -17,12 +17,18 @@ import os
 import getopt
 import errno
 
+def type_visitor(name):
+    if type(name) == list:
+        return 'visit_type_%sList' % name[0]
+    else:
+        return 'visit_type_%s' % name
+
 def generate_decl_enum(name, members, genlist=True):
     return mcgen('''
 
-void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
+void %(visitor)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
 ''',
-                name=name)
+                 visitor=type_visitor(name))
 
 def generate_command_decl(name, args, ret_type):
     arglist=""
@@ -146,9 +152,10 @@ if (has_%(c_name)s) {
                          c_name=c_var(argname), name=argname)
             push_indent()
         ret += mcgen('''
-visit_type_%(argtype)s(v, &%(c_name)s, "%(name)s", errp);
+%(visitor)s(v, &%(c_name)s, "%(name)s", errp);
 ''',
-                      c_name=c_var(argname), name=argname, argtype=argtype)
+                     c_name=c_var(argname), name=argname, argtype=argtype,
+                     visitor=type_visitor(argtype))
         if optional:
             pop_indent()
             ret += mcgen('''
@@ -179,18 +186,18 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s ret_in, QObject **ret_o
     Visitor *v;
 
     v = qmp_output_get_visitor(mo);
-    visit_type_%(ret_type)s(v, &ret_in, "unused", errp);
+    %(visitor)s(v, &ret_in, "unused", errp);
     if (!error_is_set(errp)) {
         *ret_out = qmp_output_get_qobject(mo);
     }
     qmp_output_visitor_cleanup(mo);
     v = qapi_dealloc_get_visitor(md);
-    visit_type_%(ret_type)s(v, &ret_in, "unused", errp);
+    %(visitor)s(v, &ret_in, "unused", errp);
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-                 c_ret_type=c_type(ret_type), c_name=c_var(name),
-                 ret_type=ret_type)
+                c_ret_type=c_type(ret_type), c_name=c_var(name),
+                visitor=type_visitor(ret_type))
 
     return ret
 
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (4 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 05/21] qapi: fixup command generation for functions that return list types Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:49   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types Luiz Capitulino
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Michael Roth <mdroth@linux.vnet.ibm.com>

Currently we do 3 things wrong:

1) The list iterator, in practice, is used in a manner where the pointer
we pass in is the same as the pointer we assign the output to from
visit_next_list(). This causes an infinite loop where we keep freeing
the same structures.

2) We attempt to free list->value rather than list. visit_type_<type>
handles this. We should only be concerned with the containing list.

3) We free prematurely: iterator function will continue accessing values
we've already freed.

This patch should fix all of these issues. QmpOutputVisitor also suffers
from 1).

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qapi/qapi-dealloc-visitor.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index f629061..6b586ad 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -26,6 +26,7 @@ struct QapiDeallocVisitor
 {
     Visitor visitor;
     QTAILQ_HEAD(, StackEntry) stack;
+    bool is_list_head;
 };
 
 static QapiDeallocVisitor *to_qov(Visitor *v)
@@ -70,15 +71,24 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp)
 
 static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp)
 {
+    QapiDeallocVisitor *qov = to_qov(v);
+    qov->is_list_head = true;
 }
 
-static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **list,
+static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
                                            Error **errp)
 {
-    GenericList *retval = *list;
-    g_free(retval->value);
-    *list = retval->next;
-    return retval;
+    GenericList *list = *listp;
+    QapiDeallocVisitor *qov = to_qov(v);
+
+    if (!qov->is_list_head) {
+        *listp = list->next;
+        g_free(list);
+        return *listp;
+    }
+
+    qov->is_list_head = false;
+    return list;
 }
 
 static void qapi_dealloc_end_list(Visitor *v, Error **errp)
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (5 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:50   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions Luiz Capitulino
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Michael Roth <mdroth@linux.vnet.ibm.com>

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 scripts/qapi-types.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index fc0f7af..4797a70 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -254,6 +254,8 @@ for expr in exprs:
     ret = "\n"
     if expr.has_key('type'):
         ret += generate_struct(expr['type'], "", expr['data']) + "\n"
+        ret += generate_type_cleanup_decl(expr['type'] + "List")
+        fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n")
         ret += generate_type_cleanup_decl(expr['type'])
         fdef.write(generate_type_cleanup(expr['type']) + "\n")
     elif expr.has_key('union'):
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (6 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:51   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists Luiz Capitulino
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Michael Roth <mdroth@linux.vnet.ibm.com>

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/test-qmp-commands.c b/test-qmp-commands.c
index f142cc6..7db38b6 100644
--- a/test-qmp-commands.c
+++ b/test-qmp-commands.c
@@ -98,6 +98,34 @@ static void test_dispatch_cmd_io(void)
     QDECREF(req);
 }
 
+/* test generated dealloc functions for generated types */
+static void test_dealloc_types(void)
+{
+    UserDefOne *ud1test, *ud1a, *ud1b;
+    UserDefOneList *ud1list;
+
+    ud1test = g_malloc0(sizeof(UserDefOne));
+    ud1test->integer = 42;
+    ud1test->string = strdup("hi there 42");
+
+    qapi_free_UserDefOne(ud1test);
+
+    ud1a = g_malloc0(sizeof(UserDefOne));
+    ud1a->integer = 43;
+    ud1a->string = strdup("hi there 43");
+
+    ud1b = g_malloc0(sizeof(UserDefOne));
+    ud1b->integer = 44;
+    ud1b->string = strdup("hi there 44");
+
+    ud1list = g_malloc0(sizeof(UserDefOneList));
+    ud1list->value = ud1a;
+    ud1list->next = g_malloc0(sizeof(UserDefOneList));
+    ud1list->next->value = ud1b;
+
+    qapi_free_UserDefOneList(ud1list);
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -105,6 +133,7 @@ int main(int argc, char **argv)
     g_test_add_func("/0.15/dispatch_cmd", test_dispatch_cmd);
     g_test_add_func("/0.15/dispatch_cmd_error", test_dispatch_cmd_error);
     g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
+    g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
 
     module_call_init(MODULE_INIT_QAPI);
     g_test_run();
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (7 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:51   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration Luiz Capitulino
                   ` (12 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Michael Roth <mdroth@linux.vnet.ibm.com>

Previously our logic for keeping track of when we're visiting the head
of a list was done via a global bool. This can be overwritten if dealing
with nested lists, so use stack entries to track this instead.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qapi/qapi-dealloc-visitor.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
index 6b586ad..a154523 100644
--- a/qapi/qapi-dealloc-visitor.c
+++ b/qapi/qapi-dealloc-visitor.c
@@ -19,6 +19,7 @@
 typedef struct StackEntry
 {
     void *value;
+    bool is_list_head;
     QTAILQ_ENTRY(StackEntry) node;
 } StackEntry;
 
@@ -39,6 +40,11 @@ static void qapi_dealloc_push(QapiDeallocVisitor *qov, void *value)
     StackEntry *e = g_malloc0(sizeof(*e));
 
     e->value = value;
+
+    /* see if we're just pushing a list head tracker */
+    if (value == NULL) {
+        e->is_list_head = true;
+    }
     QTAILQ_INSERT_HEAD(&qov->stack, e, node);
 }
 
@@ -72,7 +78,7 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp)
 static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp)
 {
     QapiDeallocVisitor *qov = to_qov(v);
-    qov->is_list_head = true;
+    qapi_dealloc_push(qov, NULL);
 }
 
 static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
@@ -80,19 +86,27 @@ static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
 {
     GenericList *list = *listp;
     QapiDeallocVisitor *qov = to_qov(v);
+    StackEntry *e = QTAILQ_FIRST(&qov->stack);
 
-    if (!qov->is_list_head) {
-        *listp = list->next;
-        g_free(list);
-        return *listp;
+    if (e && e->is_list_head) {
+        e->is_list_head = false;
+        return list;
     }
 
-    qov->is_list_head = false;
-    return list;
+    if (list) {
+        list = list->next;
+        g_free(*listp);
+        return list;
+    }
+
+    return NULL;
 }
 
 static void qapi_dealloc_end_list(Visitor *v, Error **errp)
 {
+    QapiDeallocVisitor *qov = to_qov(v);
+    void *obj = qapi_dealloc_pop(qov);
+    assert(obj == NULL); /* should've been list head tracker with no payload */
 }
 
 static void qapi_dealloc_type_str(Visitor *v, char **obj, const char *name,
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (8 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:53   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 11/21] qapi: convert query-name Luiz Capitulino
                   ` (11 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Michael Roth <mdroth@linux.vnet.ibm.com>

Modify logic such that we never assign values to the list head argument
to progress through the list on subsequent iterations, instead rely only
on having our return value passed back in as an argument on the next
call. Also update QMP I/O visitors and test cases accordingly, and add a
missing test case for QmpOutputVisitor.

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qapi/qmp-input-visitor.c  |    4 +-
 qapi/qmp-output-visitor.c |   20 +++++++++++++++---
 scripts/qapi-visit.py     |    4 +-
 test-visitor.c            |   48 +++++++++++++++++++++++++++++++++++++-------
 4 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index fcf8bf9..8cbc0ab 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -144,8 +144,6 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list,
         }
         (*list)->next = entry;
     }
-    *list = entry;
-
 
     return entry;
 }
@@ -240,9 +238,11 @@ static void qmp_input_type_enum(Visitor *v, int *obj, const char *strings[],
 
     if (strings[value] == NULL) {
         error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
+        g_free(enum_str);
         return;
     }
 
+    g_free(enum_str);
     *obj = value;
 }
 
diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
index 4419a31..d67724e 100644
--- a/qapi/qmp-output-visitor.c
+++ b/qapi/qmp-output-visitor.c
@@ -20,6 +20,7 @@
 typedef struct QStackEntry
 {
     QObject *value;
+    bool is_list_head;
     QTAILQ_ENTRY(QStackEntry) node;
 } QStackEntry;
 
@@ -45,6 +46,9 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value)
     QStackEntry *e = g_malloc0(sizeof(*e));
 
     e->value = value;
+    if (qobject_type(e->value) == QTYPE_QLIST) {
+        e->is_list_head = true;
+    }
     QTAILQ_INSERT_HEAD(&qov->stack, e, node);
 }
 
@@ -122,12 +126,20 @@ static void qmp_output_start_list(Visitor *v, const char *name, Error **errp)
     qmp_output_push(qov, list);
 }
 
-static GenericList *qmp_output_next_list(Visitor *v, GenericList **list,
+static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp,
                                          Error **errp)
 {
-    GenericList *retval = *list;
-    *list = retval->next;
-    return retval;
+    GenericList *list = *listp;
+    QmpOutputVisitor *qov = to_qov(v);
+    QStackEntry *e = QTAILQ_FIRST(&qov->stack);
+
+    assert(e);
+    if (e->is_list_head) {
+        e->is_list_head = false;
+        return list;
+    }
+
+    return list ? list->next : NULL;
 }
 
 static void qmp_output_end_list(Visitor *v, Error **errp)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 252230e..62de83d 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -79,11 +79,11 @@ def generate_visit_list(name, members):
 
 void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
 {
-    GenericList *i;
+    GenericList *i, **head = (GenericList **)obj;
 
     visit_start_list(m, name, errp);
 
-    for (i = visit_next_list(m, (GenericList **)obj, errp); i; i = visit_next_list(m, &i, errp)) {
+    for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m, &i, errp)) {
         %(name)sList *native_i = (%(name)sList *)i;
         visit_type_%(name)s(m, &native_i->value, NULL, errp);
     }
diff --git a/test-visitor.c b/test-visitor.c
index b7717de..847ce14 100644
--- a/test-visitor.c
+++ b/test-visitor.c
@@ -27,11 +27,11 @@ static void visit_type_TestStruct(Visitor *v, TestStruct **obj, const char *name
 
 static void visit_type_TestStructList(Visitor *m, TestStructList ** obj, const char *name, Error **errp)
 {
-    GenericList *i;
+    GenericList *i, **head = (GenericList **)obj;
 
     visit_start_list(m, name, errp);
 
-    for (i = visit_next_list(m, (GenericList **)obj, errp); i; i = visit_next_list(m, &i, errp)) {
+    for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m, &i, errp)) {
         TestStructList *native_i = (TestStructList *)i;
         visit_type_TestStruct(m, &native_i->value, NULL, errp);
     }
@@ -50,6 +50,8 @@ static void test_visitor_core(void)
     TestStructList *lts = NULL;
     Error *err = NULL;
     QObject *obj;
+    QList *qlist;
+    QDict *qdict;
     QString *str;
     int64_t value = 0;
 
@@ -96,7 +98,9 @@ static void test_visitor_core(void)
     g_assert(pts->y == 84);
 
     qobject_decref(obj);
+    g_free(pts);
 
+    /* test list input visitor */
     obj = qobject_from_json("[{'x': 42, 'y': 84}, {'x': 12, 'y': 24}]");
     mi = qmp_input_visitor_new(obj);
     v = qmp_input_get_visitor(mi);
@@ -110,14 +114,41 @@ static void test_visitor_core(void)
     g_assert(lts->value->x == 42);
     g_assert(lts->value->y == 84);
 
-    lts = lts->next;
-    g_assert(lts != NULL);
-    g_assert(lts->value->x == 12);
-    g_assert(lts->value->y == 24);
+    g_assert(lts->next != NULL);
+    g_assert(lts->next->value->x == 12);
+    g_assert(lts->next->value->y == 24);
+    g_assert(lts->next->next == NULL);
 
-    g_assert(lts->next == NULL);
+    qobject_decref(obj);
 
+    /* test list output visitor */
+    mo = qmp_output_visitor_new();
+    v = qmp_output_get_visitor(mo);
+    visit_type_TestStructList(v, &lts, NULL, &err);
+    if (err) {
+        g_error("%s", error_get_pretty(err));
+    }
+    obj = qmp_output_get_qobject(mo);
+    g_print("obj: %s\n", qstring_get_str(qobject_to_json(obj)));
+
+    qlist = qobject_to_qlist(obj);
+    assert(qlist);
+    obj = qlist_pop(qlist);
+    qdict = qobject_to_qdict(obj);
+    assert(qdict);
+    assert(qdict_get_int(qdict, "x") == 42);
+    assert(qdict_get_int(qdict, "y") == 84);
+    qobject_decref(obj);
+
+    obj = qlist_pop(qlist);
+    qdict = qobject_to_qdict(obj);
+    assert(qdict);
+    assert(qdict_get_int(qdict, "x") == 12);
+    assert(qdict_get_int(qdict, "y") == 24);
     qobject_decref(obj);
+
+    qmp_output_visitor_cleanup(mo);
+    QDECREF(qlist);
 }
 
 /* test deep nesting with refs to other user-defined types */
@@ -286,7 +317,8 @@ static void test_nested_enums(void)
     g_assert(nested_enums_cpy->has_enum2 == false);
     g_assert(nested_enums_cpy->has_enum4 == true);
 
-    qobject_decref(obj);
+    qmp_output_visitor_cleanup(mo);
+    qmp_input_visitor_cleanup(mi);
     qapi_free_NestedEnumsOne(nested_enums);
     qapi_free_NestedEnumsOne(nested_enums_cpy);
 }
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 11/21] qapi: convert query-name
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (9 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 12/21] qapi: Convert query-version Luiz Capitulino
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

From: Anthony Liguori <aliguori@us.ibm.com>

A simple example conversion 'info name'.  This also adds the new files for
QMP and HMP.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile.objs    |    1 +
 hmp.c            |   26 ++++++++++++++++++++++++++
 hmp.h            |   22 ++++++++++++++++++++++
 monitor.c        |   31 +++----------------------------
 qapi-schema.json |   22 ++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   28 ++++++++++++++++++++++++++++
 7 files changed, 108 insertions(+), 28 deletions(-)
 create mode 100644 hmp.c
 create mode 100644 hmp.h
 create mode 100644 qmp.c

diff --git a/Makefile.objs b/Makefile.objs
index 441d797..c90a3cb 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -407,6 +407,7 @@ qapi-nested-y += qmp-registry.o qmp-dispatch.o
 qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
 
 common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y)
+common-obj-y += qmp.o hmp.o
 
 ######################################################################
 # guest agent
diff --git a/hmp.c b/hmp.c
new file mode 100644
index 0000000..47e1ff7
--- /dev/null
+++ b/hmp.c
@@ -0,0 +1,26 @@
+/*
+ * Human Monitor Interface
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hmp.h"
+#include "qmp-commands.h"
+
+void hmp_info_name(Monitor *mon)
+{
+    NameInfo *info;
+
+    info = qmp_query_name(NULL);
+    if (info->has_name) {
+        monitor_printf(mon, "%s\n", info->name);
+    }
+    qapi_free_NameInfo(info);
+}
diff --git a/hmp.h b/hmp.h
new file mode 100644
index 0000000..5fe73f1
--- /dev/null
+++ b/hmp.h
@@ -0,0 +1,22 @@
+/*
+ * Human Monitor Interface
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef HMP_H
+#define HMP_H
+
+#include "qemu-common.h"
+#include "qapi-types.h"
+
+void hmp_info_name(Monitor *mon);
+
+#endif
diff --git a/monitor.c b/monitor.c
index 150fe45..8af0e27 100644
--- a/monitor.c
+++ b/monitor.c
@@ -63,6 +63,8 @@
 #endif
 #include "trace/control.h"
 #include "ui/qemu-spice.h"
+#include "qmp-commands.h"
+#include "hmp.h"
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
@@ -759,24 +761,6 @@ static void do_info_version(Monitor *mon, QObject **ret_data)
         'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
 }
 
-static void do_info_name_print(Monitor *mon, const QObject *data)
-{
-    QDict *qdict;
-
-    qdict = qobject_to_qdict(data);
-    if (qdict_size(qdict) == 0) {
-        return;
-    }
-
-    monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name"));
-}
-
-static void do_info_name(Monitor *mon, QObject **ret_data)
-{
-    *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) :
-                            qobject_from_jsonf("{}");
-}
-
 static QObject *get_cmd_dict(const char *name)
 {
     const char *p;
@@ -3081,8 +3065,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the current VM name",
-        .user_print = do_info_name_print,
-        .mhandler.info_new = do_info_name,
+        .mhandler.info = hmp_info_name,
     },
     {
         .name       = "uuid",
@@ -3274,14 +3257,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
     },
 #endif
     {
-        .name       = "name",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the current VM name",
-        .user_print = do_info_name_print,
-        .mhandler.info_new = do_info_name,
-    },
-    {
         .name       = "uuid",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index 7fcefdb..3585324 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1,3 +1,25 @@
 # -*- Mode: Python -*-
 #
 # QAPI Schema
+
+##
+# @NameInfo:
+#
+# Guest name information.
+#
+# @name: #optional The name of the guest
+#
+# Since 0.14.0
+##
+{ 'type': 'NameInfo', 'data': {'*name': 'str'} }
+
+##
+# @query-name:
+#
+# Return the name information of a guest.
+#
+# Returns: @NameInfo of the guest
+#
+# Since 0.14.0
+##
+{ 'command': 'query-name', 'returns': 'NameInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d83bce5..7b3839e 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1780,6 +1780,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-name",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_name,
+    },
+
 SQMP
 query-uuid
 ----------
diff --git a/qmp.c b/qmp.c
new file mode 100644
index 0000000..8aa9c66
--- /dev/null
+++ b/qmp.c
@@ -0,0 +1,28 @@
+/*
+ * QEMU Management Protocol
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "qmp-commands.h"
+
+NameInfo *qmp_query_name(Error **errp)
+{
+    NameInfo *info = g_malloc0(sizeof(*info));
+
+    if (qemu_name) {
+        info->has_name = true;
+        info->name = g_strdup(qemu_name);
+    }
+
+    return info;
+}
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 12/21] qapi: Convert query-version
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (10 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 11/21] qapi: convert query-name Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:54   ` Anthony Liguori
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 13/21] qapi: Convert query-kvm Luiz Capitulino
                   ` (9 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 monitor.c        |   46 +++-------------------------------------------
 qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   16 ++++++++++++++++
 6 files changed, 76 insertions(+), 43 deletions(-)

diff --git a/hmp.c b/hmp.c
index 47e1ff7..bb6c86f 100644
--- a/hmp.c
+++ b/hmp.c
@@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
     }
     qapi_free_NameInfo(info);
 }
+
+void hmp_info_version(Monitor *mon)
+{
+    VersionInfo *info;
+
+    info = qmp_query_version(NULL);
+
+    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
+                   info->qemu.major, info->qemu.minor, info->qemu.micro,
+                   info->package);
+
+    qapi_free_VersionInfo(info);
+}
diff --git a/hmp.h b/hmp.h
index 5fe73f1..2aa75a2 100644
--- a/hmp.h
+++ b/hmp.h
@@ -18,5 +18,6 @@
 #include "qapi-types.h"
 
 void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 8af0e27..9edc38c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -730,37 +730,6 @@ help:
     help_cmd(mon, "info");
 }
 
-static void do_info_version_print(Monitor *mon, const QObject *data)
-{
-    QDict *qdict;
-    QDict *qemu;
-
-    qdict = qobject_to_qdict(data);
-    qemu = qdict_get_qdict(qdict, "qemu");
-
-    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
-                  qdict_get_int(qemu, "major"),
-                  qdict_get_int(qemu, "minor"),
-                  qdict_get_int(qemu, "micro"),
-                  qdict_get_str(qdict, "package"));
-}
-
-static void do_info_version(Monitor *mon, QObject **ret_data)
-{
-    const char *version = QEMU_VERSION;
-    int major = 0, minor = 0, micro = 0;
-    char *tmp;
-
-    major = strtol(version, &tmp, 10);
-    tmp++;
-    minor = strtol(tmp, &tmp, 10);
-    tmp++;
-    micro = strtol(tmp, &tmp, 10);
-
-    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
-        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
-}
-
 static QObject *get_cmd_dict(const char *name)
 {
     const char *p;
@@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the version of QEMU",
-        .user_print = do_info_version_print,
-        .mhandler.info_new = do_info_version,
+        .mhandler.info = hmp_info_version,
     },
     {
         .name       = "network",
@@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
 
 static const mon_cmd_t qmp_query_cmds[] = {
     {
-        .name       = "version",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the version of QEMU",
-        .user_print = do_info_version_print,
-        .mhandler.info_new = do_info_version,
-    },
-    {
         .name       = "commands",
         .args_type  = "",
         .params     = "",
@@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
 
 static QObject *get_qmp_greeting(void)
 {
-    QObject *ver;
+    QObject *ver = NULL;
 
-    do_info_version(NULL, &ver);
+    qmp_marshal_input_query_version(NULL, NULL, &ver);
     return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
 }
 
diff --git a/qapi-schema.json b/qapi-schema.json
index 3585324..3c0ac4e 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -23,3 +23,40 @@
 # Since 0.14.0
 ##
 { 'command': 'query-name', 'returns': 'NameInfo' }
+
+##
+# @VersionInfo:
+#
+# A description of QEMU's version.
+#
+# @qemu.major:  The major version of QEMU
+#
+# @qemu.minor:  The minor version of QEMU
+#
+# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
+#               version of 50 signifies a development branch.  A micro version
+#               greater than or equal to 90 signifies a release candidate for
+#               the next minor version.  A micro version of less than 50
+#               signifies a stable release.
+#
+# @package:     QEMU will always set this field to an empty string.  Downstream
+#               versions of QEMU should set this to a non-empty string.  The
+#               exact format depends on the downstream however it highly
+#               recommended that a unique name is used.
+#
+# Since: 0.14.0
+##
+{ 'type': 'VersionInfo',
+  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
+           'package': 'str'} }
+
+##
+# @query-version:
+#
+# Returns the current version of QEMU.
+#
+# Returns:  A @VersionInfo object describing the current version of QEMU.
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-version', 'returns': 'VersionInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7b3839e..9f067ea 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1053,6 +1053,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
 SQMP
 query-commands
 --------------
diff --git a/qmp.c b/qmp.c
index 8aa9c66..f978ea4 100644
--- a/qmp.c
+++ b/qmp.c
@@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
 
     return info;
 }
+
+VersionInfo *qmp_query_version(Error **err)
+{
+    VersionInfo *info = g_malloc0(sizeof(*info));
+    const char *version = QEMU_VERSION;
+    char *tmp;
+
+    info->qemu.major = strtol(version, &tmp, 10);
+    tmp++;
+    info->qemu.minor = strtol(tmp, &tmp, 10);
+    tmp++;
+    info->qemu.micro = strtol(tmp, &tmp, 10);
+    info->package = g_strdup(QEMU_PKGVERSION);
+
+    return info;
+}
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 13/21] qapi: Convert query-kvm
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (11 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 12/21] qapi: Convert query-version Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 14/21] qapi: Convert query-status Luiz Capitulino
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |   16 ++++++++++++++++
 hmp.h            |    1 +
 monitor.c        |   36 +-----------------------------------
 qapi-schema.json |   25 +++++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   13 +++++++++++++
 6 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/hmp.c b/hmp.c
index bb6c86f..94a7f74 100644
--- a/hmp.c
+++ b/hmp.c
@@ -37,3 +37,19 @@ void hmp_info_version(Monitor *mon)
 
     qapi_free_VersionInfo(info);
 }
+
+void hmp_info_kvm(Monitor *mon)
+{
+    KvmInfo *info;
+
+    info = qmp_query_kvm(NULL);
+    monitor_printf(mon, "kvm support: ");
+    if (info->present) {
+        monitor_printf(mon, "%s\n", info->enabled ? "enabled" : "disabled");
+    } else {
+        monitor_printf(mon, "not compiled\n");
+    }
+
+    qapi_free_KvmInfo(info);
+}
+
diff --git a/hmp.h b/hmp.h
index 2aa75a2..a93ac1f 100644
--- a/hmp.h
+++ b/hmp.h
@@ -19,5 +19,6 @@
 
 void hmp_info_name(Monitor *mon);
 void hmp_info_version(Monitor *mon);
+void hmp_info_kvm(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 9edc38c..edb56b9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2424,31 +2424,6 @@ static void tlb_info(Monitor *mon)
 }
 #endif
 
-static void do_info_kvm_print(Monitor *mon, const QObject *data)
-{
-    QDict *qdict;
-
-    qdict = qobject_to_qdict(data);
-
-    monitor_printf(mon, "kvm support: ");
-    if (qdict_get_bool(qdict, "present")) {
-        monitor_printf(mon, "%s\n", qdict_get_bool(qdict, "enabled") ?
-                                    "enabled" : "disabled");
-    } else {
-        monitor_printf(mon, "not compiled\n");
-    }
-}
-
-static void do_info_kvm(Monitor *mon, QObject **ret_data)
-{
-#ifdef CONFIG_KVM
-    *ret_data = qobject_from_jsonf("{ 'enabled': %i, 'present': true }",
-                                   kvm_enabled());
-#else
-    *ret_data = qobject_from_jsonf("{ 'enabled': false, 'present': false }");
-#endif
-}
-
 static void do_info_numa(Monitor *mon)
 {
     int i;
@@ -2942,8 +2917,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show KVM information",
-        .user_print = do_info_kvm_print,
-        .mhandler.info_new = do_info_kvm,
+        .mhandler.info = hmp_info_kvm,
     },
     {
         .name       = "numa",
@@ -3175,14 +3149,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
         .mhandler.info_new = do_pci_info,
     },
     {
-        .name       = "kvm",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show KVM information",
-        .user_print = do_info_kvm_print,
-        .mhandler.info_new = do_info_kvm,
-    },
-    {
         .name       = "status",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index 3c0ac4e..641f12d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -60,3 +60,28 @@
 # Since: 0.14.0
 ##
 { 'command': 'query-version', 'returns': 'VersionInfo' }
+
+##
+# @KvmInfo:
+#
+# Information about support for KVM acceleration
+#
+# @enabled: true if KVM acceleration is active
+#
+# @present: true if KVM acceleration is built into this executable
+#
+# Since: 0.14.0
+##
+{ 'type': 'KvmInfo', 'data': {'enabled': 'bool', 'present': 'bool'} }
+
+##
+# @query-kvm:
+#
+# Returns information about KVM acceleration
+#
+# Returns: @KvmInfo
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-kvm', 'returns': 'KvmInfo' }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 9f067ea..9f9751d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1570,6 +1570,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-kvm",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_kvm,
+    },
+
 SQMP
 query-status
 ------------
diff --git a/qmp.c b/qmp.c
index f978ea4..8f7f666 100644
--- a/qmp.c
+++ b/qmp.c
@@ -14,6 +14,8 @@
 #include "qemu-common.h"
 #include "sysemu.h"
 #include "qmp-commands.h"
+#include "kvm.h"
+#include "arch_init.h"
 
 NameInfo *qmp_query_name(Error **errp)
 {
@@ -42,3 +44,14 @@ VersionInfo *qmp_query_version(Error **err)
 
     return info;
 }
+
+KvmInfo *qmp_query_kvm(Error **errp)
+{
+    KvmInfo *info = g_malloc0(sizeof(*info));
+
+    info->enabled = kvm_enabled();
+    info->present = kvm_available();
+
+    return info;
+}
+
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 14/21] qapi: Convert query-status
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (12 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 13/21] qapi: Convert query-kvm Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 20:11   ` Michael Roth
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 15/21] qapi: Convert query-uuid Luiz Capitulino
                   ` (7 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |   19 +++++++++++++++
 hmp.h            |    1 +
 monitor.c        |   41 +--------------------------------
 qapi-schema.json |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx  |    6 +++++
 vl.c             |   12 +++++++++
 6 files changed, 106 insertions(+), 40 deletions(-)

diff --git a/hmp.c b/hmp.c
index 94a7f74..9e7f07e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -53,3 +53,22 @@ void hmp_info_kvm(Monitor *mon)
     qapi_free_KvmInfo(info);
 }
 
+void hmp_info_status(Monitor *mon)
+{
+    StatusInfo *info;
+
+    info = qmp_query_status(NULL);
+
+    monitor_printf(mon, "VM status: %s%s",
+                   info->running ? "running" : "paused",
+                   info->singlestep ? " (single step mode)" : "");
+
+    if (!info->running && info->status != VM_RUN_STATUS_PAUSED) {
+        monitor_printf(mon, " (%s)", VmRunStatus_lookup[info->status]);
+    }
+
+    monitor_printf(mon, "\n");
+
+    qapi_free_StatusInfo(info);
+}
+
diff --git a/hmp.h b/hmp.h
index a93ac1f..df4242f 100644
--- a/hmp.h
+++ b/hmp.h
@@ -20,5 +20,6 @@
 void hmp_info_name(Monitor *mon);
 void hmp_info_version(Monitor *mon);
 void hmp_info_kvm(Monitor *mon);
+void hmp_info_status(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index edb56b9..f641504 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2544,36 +2544,6 @@ static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)
 }
 #endif
 
-static void do_info_status_print(Monitor *mon, const QObject *data)
-{
-    QDict *qdict;
-    const char *status;
-
-    qdict = qobject_to_qdict(data);
-
-    monitor_printf(mon, "VM status: ");
-    if (qdict_get_bool(qdict, "running")) {
-        monitor_printf(mon, "running");
-        if (qdict_get_bool(qdict, "singlestep")) {
-            monitor_printf(mon, " (single step mode)");
-        }
-    } else {
-        monitor_printf(mon, "paused");
-    }
-
-    status = qdict_get_str(qdict, "status");
-    if (strcmp(status, "paused") && strcmp(status, "running")) {
-        monitor_printf(mon, " (%s)", status);
-    }
-
-    monitor_printf(mon, "\n");
-}
-
-static void do_info_status(Monitor *mon, QObject **ret_data)
-{
-    *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i, 'status': %s }", runstate_is_running(), singlestep, runstate_as_string());
-}
-
 static qemu_acl *find_acl(Monitor *mon, const char *name)
 {
     qemu_acl *acl = qemu_acl_find(name);
@@ -2966,8 +2936,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the current VM status (running|paused)",
-        .user_print = do_info_status_print,
-        .mhandler.info_new = do_info_status,
+        .mhandler.info = hmp_info_status,
     },
     {
         .name       = "pcmcia",
@@ -3149,14 +3118,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
         .mhandler.info_new = do_pci_info,
     },
     {
-        .name       = "status",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the current VM status (running|paused)",
-        .user_print = do_info_status_print,
-        .mhandler.info_new = do_info_status,
-    },
-    {
         .name       = "mice",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index 641f12d..de0f807 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -85,3 +85,70 @@
 ##
 { 'command': 'query-kvm', 'returns': 'KvmInfo' }
 
+##
+# @VmRunStatus
+#
+# An enumation of VM run status.
+#
+# @debug: QEMU is running on a debugger
+#
+# @inmigrate: guest is paused waiting for an incoming migration
+#
+# @internal-error: An internal error that prevents further guest execution
+# has occurred
+#
+# @io-error: the last IOP has failed and the device is configured to pause
+# on I/O errors
+#
+# @paused: guest has been paused via the 'stop' command
+#
+# @postmigrate: guest is paused following a successful 'migrate'
+#
+# @prelaunch: QEMU was started with -S and guest has not started
+#
+# @finish-migrate: guest is paused to finish the migration process
+#
+# @restore-vm: guest is paused to restore VM state
+#
+# @running: guest is actively running
+#
+# @save-vm: guest is paused to save the VM state
+#
+# @shutdown: guest is shut down (and -no-shutdown is in use)
+#
+# @watchdog: the watchdog action is configured to pause and has been triggered
+##
+{ 'enum': 'VmRunStatus',
+  'data': [ 'no-status', 'debug', 'inmigrate', 'internal-error', 'io-error',
+            'paused', 'postmigrate', 'prelaunch', 'finish-migrate',
+            'restore-vm', 'running', 'save-vm', 'shutdown', 'watchdog' ] }
+
+##
+# @StatusInfo:
+#
+# Information about VCPU run state
+#
+# @running: true if all VCPUs are runnable, false if not runnable
+#
+# @singlestep: true if VCPUs are in single-step mode
+#
+# @status: the @VmRunStatus
+#
+# Since:  0.14.0
+#
+# Notes: @singlestep is enabled through the GDB stub
+##
+{ 'type': 'StatusInfo',
+  'data': {'running': 'bool', 'singlestep': 'bool', 'status': 'VmRunStatus'} }
+
+##
+# @query-status:
+#
+# Query the run status of all VCPUs
+#
+# Returns: @StatusInfo reflecting all VCPUs
+#
+# Since:  0.14.0
+##
+{ 'command': 'query-status', 'returns': 'StatusInfo' }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 9f9751d..afa95bd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1609,6 +1609,12 @@ Example:
 <- { "return": { "running": true, "singlestep": false, "status": "running" } }
 
 EQMP
+    
+    {
+        .name       = "query-status",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_status,
+    },
 
 SQMP
 query-mice
diff --git a/vl.c b/vl.c
index bd4a5ce..b7bef59 100644
--- a/vl.c
+++ b/vl.c
@@ -147,6 +147,7 @@ int main(int argc, char **argv)
 #include "qemu-config.h"
 #include "qemu-objects.h"
 #include "qemu-options.h"
+#include "qmp-commands.h"
 #ifdef CONFIG_VIRTFS
 #include "fsdev/qemu-fsdev.h"
 #endif
@@ -434,6 +435,17 @@ int runstate_is_running(void)
     return runstate_check(RSTATE_RUNNING);
 }
 
+StatusInfo *qmp_query_status(Error **errp)
+{
+    StatusInfo *info = g_malloc0(sizeof(*info));
+
+    info->running = runstate_is_running();
+    info->singlestep = singlestep;
+    info->status = current_run_state;
+
+    return info;
+}
+
 /***********************************************************/
 /* real time host monotonic timer */
 
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 15/21] qapi: Convert query-uuid
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (13 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 14/21] qapi: Convert query-status Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev Luiz Capitulino
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |    8 ++++++++
 hmp.h            |    1 +
 monitor.c        |   28 +---------------------------
 qapi-schema.json |   24 ++++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 qmp.c            |   15 +++++++++++++++
 6 files changed, 55 insertions(+), 27 deletions(-)

diff --git a/hmp.c b/hmp.c
index 9e7f07e..1cd40ae 100644
--- a/hmp.c
+++ b/hmp.c
@@ -72,3 +72,11 @@ void hmp_info_status(Monitor *mon)
     qapi_free_StatusInfo(info);
 }
 
+void hmp_info_uuid(Monitor *mon)
+{
+    UuidInfo *info;
+
+    info = qmp_query_uuid(NULL);
+    monitor_printf(mon, "%s\n", info->UUID);
+    qapi_free_UuidInfo(info);
+}
diff --git a/hmp.h b/hmp.h
index df4242f..49a5971 100644
--- a/hmp.h
+++ b/hmp.h
@@ -21,5 +21,6 @@ void hmp_info_name(Monitor *mon);
 void hmp_info_version(Monitor *mon);
 void hmp_info_kvm(Monitor *mon);
 void hmp_info_status(Monitor *mon);
+void hmp_info_uuid(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index f641504..d294bc9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -765,23 +765,6 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
     *ret_data = QOBJECT(cmd_list);
 }
 
-static void do_info_uuid_print(Monitor *mon, const QObject *data)
-{
-    monitor_printf(mon, "%s\n", qdict_get_str(qobject_to_qdict(data), "UUID"));
-}
-
-static void do_info_uuid(Monitor *mon, QObject **ret_data)
-{
-    char uuid[64];
-
-    snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
-                   qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
-                   qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
-                   qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
-                   qemu_uuid[14], qemu_uuid[15]);
-    *ret_data = qobject_from_jsonf("{ 'UUID': %s }", uuid);
-}
-
 /* get the current CPU defined by the user */
 static int mon_set_cpu(int cpu_index)
 {
@@ -2983,8 +2966,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the current VM UUID",
-        .user_print = do_info_uuid_print,
-        .mhandler.info_new = do_info_uuid,
+        .mhandler.info = hmp_info_uuid,
     },
 #if defined(TARGET_PPC)
     {
@@ -3144,14 +3126,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
     },
 #endif
     {
-        .name       = "uuid",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the current VM UUID",
-        .user_print = do_info_uuid_print,
-        .mhandler.info_new = do_info_uuid,
-    },
-    {
         .name       = "migrate",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index de0f807..b678f07 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -152,3 +152,27 @@
 ##
 { 'command': 'query-status', 'returns': 'StatusInfo' }
 
+##
+# @UuidInfo:
+#
+# Guest UUID information.
+#
+# @UUID: the UUID of the guest
+#
+# Since: 0.14.0
+#
+# Notes: If no UUID was specified for the guest, a null UUID is returned.
+##
+{ 'type': 'UuidInfo', 'data': {'UUID': 'str'} }
+
+##
+# @query-uuid:
+#
+# Query the guest UUID information.
+#
+# Returns: The @UuidInfo for the guest
+#
+# Since 0.14.0
+##
+{ 'command': 'query-uuid', 'returns': 'UuidInfo' }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index afa95bd..4fef25f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1821,6 +1821,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-uuid",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_uuid,
+    },
+
 SQMP
 query-migrate
 -------------
diff --git a/qmp.c b/qmp.c
index 8f7f666..58337c7 100644
--- a/qmp.c
+++ b/qmp.c
@@ -55,3 +55,18 @@ KvmInfo *qmp_query_kvm(Error **errp)
     return info;
 }
 
+UuidInfo *qmp_query_uuid(Error **errp)
+{
+    UuidInfo *info = g_malloc0(sizeof(*info));
+    char uuid[64];
+
+    snprintf(uuid, sizeof(uuid), UUID_FMT, qemu_uuid[0], qemu_uuid[1],
+                   qemu_uuid[2], qemu_uuid[3], qemu_uuid[4], qemu_uuid[5],
+                   qemu_uuid[6], qemu_uuid[7], qemu_uuid[8], qemu_uuid[9],
+                   qemu_uuid[10], qemu_uuid[11], qemu_uuid[12], qemu_uuid[13],
+                   qemu_uuid[14], qemu_uuid[15]);
+
+    info->UUID = g_strdup(uuid);
+    return info;
+}
+
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (14 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 15/21] qapi: Convert query-uuid Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 19:17   ` Michael Roth
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands Luiz Capitulino
                   ` (5 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp.c            |   13 +++++++++++++
 hmp.h            |    1 +
 monitor.c        |   11 +----------
 qapi-schema.json |   26 ++++++++++++++++++++++++++
 qemu-char.c      |   35 +++++++++++------------------------
 qmp-commands.hx  |    6 ++++++
 6 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/hmp.c b/hmp.c
index 1cd40ae..91de86c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -80,3 +80,16 @@ void hmp_info_uuid(Monitor *mon)
     monitor_printf(mon, "%s\n", info->UUID);
     qapi_free_UuidInfo(info);
 }
+
+void hmp_info_chardev(Monitor *mon)
+{
+    ChardevInfoList *char_info, *info;
+
+    char_info = qmp_query_chardev(NULL);
+    for (info = char_info; info; info = info->next) {
+        monitor_printf(mon, "%s: filename=%s\n", info->value->label,
+                                                 info->value->filename);
+    }
+
+    qapi_free_ChardevInfoList(char_info);
+}
diff --git a/hmp.h b/hmp.h
index 49a5971..7388f9a 100644
--- a/hmp.h
+++ b/hmp.h
@@ -22,5 +22,6 @@ void hmp_info_version(Monitor *mon);
 void hmp_info_kvm(Monitor *mon);
 void hmp_info_status(Monitor *mon);
 void hmp_info_uuid(Monitor *mon);
+void hmp_info_chardev(Monitor *mon);
 
 #endif
diff --git a/monitor.c b/monitor.c
index d294bc9..66b3004 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2777,8 +2777,7 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the character devices",
-        .user_print = qemu_chr_info_print,
-        .mhandler.info_new = qemu_chr_info,
+        .mhandler.info = hmp_info_chardev,
     },
     {
         .name       = "block",
@@ -3060,14 +3059,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
         .mhandler.info_new = do_info_commands,
     },
     {
-        .name       = "chardev",
-        .args_type  = "",
-        .params     = "",
-        .help       = "show the character devices",
-        .user_print = qemu_chr_info_print,
-        .mhandler.info_new = qemu_chr_info,
-    },
-    {
         .name       = "block",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index b678f07..2ebcb1c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -176,3 +176,29 @@
 ##
 { 'command': 'query-uuid', 'returns': 'UuidInfo' }
 
+##
+# @ChardevInfo:
+#
+# Information about a character device.
+#
+# @label: the label of the character device
+#
+# @filename: the filename of the character device
+#
+# Notes: @filename is encoded using the QEMU command line character device
+#        encoding.  See the QEMU man page for details.
+#
+# Since: 0.14.0
+##
+{ 'type': 'ChardevInfo', 'data': {'label': 'str', 'filename': 'str'} }
+
+##
+# @query-chardev:
+#
+# Returns information about current character devices.
+#
+# Returns: a list of @ChardevInfo
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
diff --git a/qemu-char.c b/qemu-char.c
index 09d2309..8bdbcfd 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -31,7 +31,7 @@
 #include "hw/usb.h"
 #include "hw/baum.h"
 #include "hw/msmouse.h"
-#include "qemu-objects.h"
+#include "qmp-commands.h"
 
 #include <unistd.h>
 #include <fcntl.h>
@@ -2650,35 +2650,22 @@ void qemu_chr_delete(CharDriverState *chr)
     g_free(chr);
 }
 
-static void qemu_chr_qlist_iter(QObject *obj, void *opaque)
+ChardevInfoList *qmp_query_chardev(Error **errp)
 {
-    QDict *chr_dict;
-    Monitor *mon = opaque;
-
-    chr_dict = qobject_to_qdict(obj);
-    monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"),
-                                         qdict_get_str(chr_dict, "filename"));
-}
-
-void qemu_chr_info_print(Monitor *mon, const QObject *ret_data)
-{
-    qlist_iter(qobject_to_qlist(ret_data), qemu_chr_qlist_iter, mon);
-}
-
-void qemu_chr_info(Monitor *mon, QObject **ret_data)
-{
-    QList *chr_list;
+    ChardevInfoList *chr_list = NULL;
     CharDriverState *chr;
 
-    chr_list = qlist_new();
-
     QTAILQ_FOREACH(chr, &chardevs, next) {
-        QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }",
-                                          chr->label, chr->filename);
-        qlist_append_obj(chr_list, obj);
+        ChardevInfoList *info = g_malloc0(sizeof(*info));
+        info->value = g_malloc0(sizeof(*info->value));
+        info->value->label = g_strdup(chr->label);
+        info->value->filename = g_strdup(chr->filename);
+
+        info->next = chr_list;
+        chr_list = info;
     }
 
-    *ret_data = QOBJECT(chr_list);
+    return chr_list;
 }
 
 CharDriverState *qemu_chr_find(const char *name)
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 4fef25f..dfc02af 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1120,6 +1120,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-chardev",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_chardev,
+    },
+
 SQMP
 query-block
 -----------
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (15 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 19:25   ` Michael Roth
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 18/21] qapi: Convert quit Luiz Capitulino
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c        |   40 +++++++++++++++-------------------------
 qapi-schema.json |   23 +++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 3 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/monitor.c b/monitor.c
index 66b3004..d546bad 100644
--- a/monitor.c
+++ b/monitor.c
@@ -730,39 +730,37 @@ help:
     help_cmd(mon, "info");
 }
 
-static QObject *get_cmd_dict(const char *name)
+static CommandInfoList *alloc_cmd_entry(const char *cmd_name)
 {
-    const char *p;
+    CommandInfoList *info;
 
-    /* Remove '|' from some commands */
-    p = strchr(name, '|');
-    if (p) {
-        p++;
-    } else {
-        p = name;
-    }
+    info = g_malloc0(sizeof(*info));
+    info->value = g_malloc0(sizeof(*info->value));
+    info->value->name = g_strdup(cmd_name);
 
-    return qobject_from_jsonf("{ 'name': %s }", p);
+    return info;
 }
 
-static void do_info_commands(Monitor *mon, QObject **ret_data)
+CommandInfoList *qmp_query_commands(Error **errp)
 {
-    QList *cmd_list;
+    CommandInfoList *info, *cmd_list = NULL;
     const mon_cmd_t *cmd;
 
-    cmd_list = qlist_new();
-
     for (cmd = qmp_cmds; cmd->name != NULL; cmd++) {
-        qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
+        info = alloc_cmd_entry(cmd->name);
+        info->next = cmd_list;
+        cmd_list = info;
     }
 
     for (cmd = qmp_query_cmds; cmd->name != NULL; cmd++) {
         char buf[128];
         snprintf(buf, sizeof(buf), "query-%s", cmd->name);
-        qlist_append_obj(cmd_list, get_cmd_dict(buf));
+        info = alloc_cmd_entry(buf);
+        info->next = cmd_list;
+        cmd_list = info;
     }
 
-    *ret_data = QOBJECT(cmd_list);
+    return cmd_list;
 }
 
 /* get the current CPU defined by the user */
@@ -3051,14 +3049,6 @@ static const mon_cmd_t qmp_cmds[] = {
 
 static const mon_cmd_t qmp_query_cmds[] = {
     {
-        .name       = "commands",
-        .args_type  = "",
-        .params     = "",
-        .help       = "list QMP available commands",
-        .user_print = monitor_user_noop,
-        .mhandler.info_new = do_info_commands,
-    },
-    {
         .name       = "block",
         .args_type  = "",
         .params     = "",
diff --git a/qapi-schema.json b/qapi-schema.json
index 2ebcb1c..b26dd25 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -202,3 +202,26 @@
 # Since: 0.14.0
 ##
 { 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
+
+##
+# @CommandInfo:
+#
+# Information about a QMP command
+#
+# @name: The command name
+#
+# Since: 0.14.0
+##
+{ 'type': 'CommandInfo', 'data': {'name': 'str'} }
+
+##
+# @query-commands:
+#
+# Return a list of supported QMP commands by this server
+#
+# Returns: A list of @CommandInfo for all supported commands
+#
+# Since: 0.14.0
+##
+{ 'command': 'query-commands', 'returns': ['CommandInfo'] }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index dfc02af..0fda5c3 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1090,6 +1090,12 @@ Note: This example has been shortened as the real response is too long.
 
 EQMP
 
+    {
+        .name       = "query-commands",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_commands,
+    },
+
 SQMP
 query-chardev
 -------------
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 18/21] qapi: Convert quit
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (16 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 19/21] qapi: Convert stop Luiz Capitulino
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp-commands.hx  |    2 +-
 hmp.c            |    6 ++++++
 hmp.h            |    1 +
 monitor.c        |   12 ------------
 qapi-schema.json |   11 +++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    6 ++++++
 7 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 9e1cca8..2163e6f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -43,7 +43,7 @@ ETEXI
         .params     = "",
         .help       = "quit the emulator",
         .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_quit,
+        .mhandler.cmd = hmp_quit,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 91de86c..1f7000a 100644
--- a/hmp.c
+++ b/hmp.c
@@ -93,3 +93,9 @@ void hmp_info_chardev(Monitor *mon)
 
     qapi_free_ChardevInfoList(char_info);
 }
+
+void hmp_quit(Monitor *mon, const QDict *qdict)
+{
+    monitor_suspend(mon);
+    qmp_quit(NULL);
+}
diff --git a/hmp.h b/hmp.h
index 7388f9a..a3dfafd 100644
--- a/hmp.h
+++ b/hmp.h
@@ -23,5 +23,6 @@ void hmp_info_kvm(Monitor *mon);
 void hmp_info_status(Monitor *mon);
 void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
+void hmp_quit(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index d546bad..42c754a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -945,18 +945,6 @@ static void do_trace_print_events(Monitor *mon)
     trace_print_events((FILE *)mon, &monitor_fprintf);
 }
 
-/**
- * do_quit(): Quit QEMU execution
- */
-static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    monitor_suspend(mon);
-    no_shutdown = 0;
-    qemu_system_shutdown_request();
-
-    return 0;
-}
-
 #ifdef CONFIG_VNC
 static int change_vnc_password(const char *password)
 {
diff --git a/qapi-schema.json b/qapi-schema.json
index b26dd25..d6a60d2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -225,3 +225,14 @@
 ##
 { 'command': 'query-commands', 'returns': ['CommandInfo'] }
 
+##
+# @quit:
+#
+# This command will cause the QEMU process to exit gracefully.  While every
+# attempt is made to send the QMP response before terminating, this is not
+# guaranteed.  When using this interface, a premature EOF would not be
+# unexpected.
+#
+# Since: 0.14.0
+##
+{ 'command': 'quit' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0fda5c3..151a5fa 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -63,10 +63,7 @@ EQMP
     {
         .name       = "quit",
         .args_type  = "",
-        .params     = "",
-        .help       = "quit the emulator",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_quit,
+        .mhandler.cmd_new = qmp_marshal_input_quit,
     },
 
 SQMP
diff --git a/qmp.c b/qmp.c
index 58337c7..1d380b6 100644
--- a/qmp.c
+++ b/qmp.c
@@ -70,3 +70,9 @@ UuidInfo *qmp_query_uuid(Error **errp)
     return info;
 }
 
+void qmp_quit(Error **err)
+{
+    no_shutdown = 0;
+    qemu_system_shutdown_request();
+}
+
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 19/21] qapi: Convert stop
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (17 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 18/21] qapi: Convert quit Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 20/21] qapi: Convert system_reset Luiz Capitulino
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 monitor.c        |    9 ---------
 qapi-schema.json |   12 ++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    5 +++++
 7 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 2163e6f..3ad1ce7 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -290,8 +290,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "stop emulation",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_stop,
+        .mhandler.cmd = hmp_stop,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 1f7000a..871f858 100644
--- a/hmp.c
+++ b/hmp.c
@@ -99,3 +99,8 @@ void hmp_quit(Monitor *mon, const QDict *qdict)
     monitor_suspend(mon);
     qmp_quit(NULL);
 }
+
+void hmp_stop(Monitor *mon, const QDict *qdict)
+{
+    qmp_stop(NULL);
+}
diff --git a/hmp.h b/hmp.h
index a3dfafd..cb21cce 100644
--- a/hmp.h
+++ b/hmp.h
@@ -24,5 +24,6 @@ void hmp_info_status(Monitor *mon);
 void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_quit(Monitor *mon, const QDict *qdict);
+void hmp_stop(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 42c754a..b4a58b1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1211,15 +1211,6 @@ static void do_singlestep(Monitor *mon, const QDict *qdict)
     }
 }
 
-/**
- * do_stop(): Stop VM execution
- */
-static int do_stop(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    vm_stop(RSTATE_PAUSED);
-    return 0;
-}
-
 static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs);
 
 struct bdrv_iterate_context {
diff --git a/qapi-schema.json b/qapi-schema.json
index d6a60d2..830a508 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -236,3 +236,15 @@
 # Since: 0.14.0
 ##
 { 'command': 'quit' }
+
+##
+# @stop:
+#
+# Stop all guest VCPU execution.
+#
+# Since:  0.14.0
+#
+# Notes:  This function will succeed even if the guest is already in the stopped
+#         state
+##
+{ 'command': 'stop' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 151a5fa..2ccddee 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -178,10 +178,7 @@ EQMP
     {
         .name       = "stop",
         .args_type  = "",
-        .params     = "",
-        .help       = "stop emulation",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_stop,
+        .mhandler.cmd_new = qmp_marshal_input_stop,
     },
 
 SQMP
diff --git a/qmp.c b/qmp.c
index 1d380b6..e17c8b2 100644
--- a/qmp.c
+++ b/qmp.c
@@ -76,3 +76,8 @@ void qmp_quit(Error **err)
     qemu_system_shutdown_request();
 }
 
+void qmp_stop(Error **errp)
+{
+    vm_stop(RSTATE_PAUSED);
+}
+
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 20/21] qapi: Convert system_reset
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (18 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 19/21] qapi: Convert stop Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 21/21] qapi: Convert system_powerdown Luiz Capitulino
  2011-09-29 12:55 ` [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Anthony Liguori
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 monitor.c        |   10 ----------
 qapi-schema.json |    9 +++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |    4 ++++
 7 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3ad1ce7..b2f5cd1 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -477,8 +477,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "reset the system",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_system_reset,
+        .mhandler.cmd = hmp_system_reset,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 871f858..d8b4de6 100644
--- a/hmp.c
+++ b/hmp.c
@@ -104,3 +104,8 @@ void hmp_stop(Monitor *mon, const QDict *qdict)
 {
     qmp_stop(NULL);
 }
+
+void hmp_system_reset(Monitor *mon, const QDict *qdict)
+{
+    qmp_system_reset(NULL);
+}
diff --git a/hmp.h b/hmp.h
index cb21cce..a49a6e6 100644
--- a/hmp.h
+++ b/hmp.h
@@ -25,5 +25,6 @@ void hmp_info_uuid(Monitor *mon);
 void hmp_info_chardev(Monitor *mon);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
+void hmp_system_reset(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index b4a58b1..de6a865 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1929,16 +1929,6 @@ static void do_boot_set(Monitor *mon, const QDict *qdict)
 }
 
 /**
- * do_system_reset(): Issue a machine reset
- */
-static int do_system_reset(Monitor *mon, const QDict *qdict,
-                           QObject **ret_data)
-{
-    qemu_system_reset_request();
-    return 0;
-}
-
-/**
  * do_system_powerdown(): Issue a machine powerdown
  */
 static int do_system_powerdown(Monitor *mon, const QDict *qdict,
diff --git a/qapi-schema.json b/qapi-schema.json
index 830a508..e14f2f7 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -248,3 +248,12 @@
 #         state
 ##
 { 'command': 'stop' }
+
+##
+# @system_reset:
+#
+# Performs a hard reset of a guest.
+#
+# Since: 0.14.0
+##
+{ 'command': 'system_reset' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 2ccddee..ea96191 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -223,10 +223,7 @@ EQMP
     {
         .name       = "system_reset",
         .args_type  = "",
-        .params     = "",
-        .help       = "reset the system",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_system_reset,
+        .mhandler.cmd_new = qmp_marshal_input_system_reset,
     },
 
 SQMP
diff --git a/qmp.c b/qmp.c
index e17c8b2..6767640 100644
--- a/qmp.c
+++ b/qmp.c
@@ -81,3 +81,7 @@ void qmp_stop(Error **errp)
     vm_stop(RSTATE_PAUSED);
 }
 
+void qmp_system_reset(Error **errp)
+{
+    qemu_system_reset_request();
+}
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* [Qemu-devel] [PATCH 21/21] qapi: Convert system_powerdown
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (19 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 20/21] qapi: Convert system_reset Luiz Capitulino
@ 2011-09-28 14:44 ` Luiz Capitulino
  2011-09-29 12:55 ` [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Anthony Liguori
  21 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-28 14:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, aliguori, mdroth, armbru

The original conversion was done by Anthony Liguori. This commit
is just a rebase.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hmp-commands.hx  |    3 +--
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 qapi-schema.json |   14 ++++++++++++++
 qmp.c            |    5 +++++
 5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index b2f5cd1..07b493c 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -492,8 +492,7 @@ ETEXI
         .args_type  = "",
         .params     = "",
         .help       = "send system power down event",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_system_powerdown,
+        .mhandler.cmd = hmp_system_powerdown,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index d8b4de6..13146a4 100644
--- a/hmp.c
+++ b/hmp.c
@@ -109,3 +109,8 @@ void hmp_system_reset(Monitor *mon, const QDict *qdict)
 {
     qmp_system_reset(NULL);
 }
+
+void hmp_system_powerdown(Monitor *mon, const QDict *qdict)
+{
+    qmp_system_powerdown(NULL);
+}
diff --git a/hmp.h b/hmp.h
index a49a6e6..92433cf 100644
--- a/hmp.h
+++ b/hmp.h
@@ -26,5 +26,6 @@ void hmp_info_chardev(Monitor *mon);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
+void hmp_system_powerdown(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index e14f2f7..413fcd5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -257,3 +257,17 @@
 # Since: 0.14.0
 ##
 { 'command': 'system_reset' }
+
+##
+# @system_powerdown:
+#
+# Requests that a guest perform a powerdown operation.
+#
+# Since: 0.14.0
+#
+# Notes: A guest may or may not respond to this command.  This command
+#        returning does not indicate that a guest has accepted the request or
+#        that it has shut down.  Many guests will respond to this command by
+#        prompting the user in some way.
+##
+{ 'command': 'system_powerdown' }
diff --git a/qmp.c b/qmp.c
index 6767640..aa43207 100644
--- a/qmp.c
+++ b/qmp.c
@@ -85,3 +85,8 @@ void qmp_system_reset(Error **errp)
 {
     qemu_system_reset_request();
 }
+
+void qmp_system_powerdown(Error **erp)
+{
+    qemu_system_powerdown_request();
+}
-- 
1.7.7.rc0.72.g4b5ea

^ permalink raw reply related	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic Luiz Capitulino
@ 2011-09-29 12:49   ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:49 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Currently we do 3 things wrong:
>
> 1) The list iterator, in practice, is used in a manner where the pointer
> we pass in is the same as the pointer we assign the output to from
> visit_next_list(). This causes an infinite loop where we keep freeing
> the same structures.
>
> 2) We attempt to free list->value rather than list. visit_type_<type>
> handles this. We should only be concerned with the containing list.
>
> 3) We free prematurely: iterator function will continue accessing values
> we've already freed.
>
> This patch should fix all of these issues. QmpOutputVisitor also suffers
> from 1).
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   qapi/qapi-dealloc-visitor.c |   20 +++++++++++++++-----
>   1 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
> index f629061..6b586ad 100644
> --- a/qapi/qapi-dealloc-visitor.c
> +++ b/qapi/qapi-dealloc-visitor.c
> @@ -26,6 +26,7 @@ struct QapiDeallocVisitor
>   {
>       Visitor visitor;
>       QTAILQ_HEAD(, StackEntry) stack;
> +    bool is_list_head;
>   };
>
>   static QapiDeallocVisitor *to_qov(Visitor *v)
> @@ -70,15 +71,24 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp)
>
>   static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp)
>   {
> +    QapiDeallocVisitor *qov = to_qov(v);
> +    qov->is_list_head = true;
>   }
>
> -static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **list,
> +static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
>                                              Error **errp)
>   {
> -    GenericList *retval = *list;
> -    g_free(retval->value);
> -    *list = retval->next;
> -    return retval;
> +    GenericList *list = *listp;
> +    QapiDeallocVisitor *qov = to_qov(v);
> +
> +    if (!qov->is_list_head) {
> +        *listp = list->next;
> +        g_free(list);
> +        return *listp;
> +    }
> +
> +    qov->is_list_head = false;
> +    return list;
>   }
>
>   static void qapi_dealloc_end_list(Visitor *v, Error **errp)

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types Luiz Capitulino
@ 2011-09-29 12:50   ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:50 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   scripts/qapi-types.py |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
> index fc0f7af..4797a70 100644
> --- a/scripts/qapi-types.py
> +++ b/scripts/qapi-types.py
> @@ -254,6 +254,8 @@ for expr in exprs:
>       ret = "\n"
>       if expr.has_key('type'):
>           ret += generate_struct(expr['type'], "", expr['data']) + "\n"
> +        ret += generate_type_cleanup_decl(expr['type'] + "List")
> +        fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n")
>           ret += generate_type_cleanup_decl(expr['type'])
>           fdef.write(generate_type_cleanup(expr['type']) + "\n")
>       elif expr.has_key('union'):

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions Luiz Capitulino
@ 2011-09-29 12:51   ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:51 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> ---
>   test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
>   1 files changed, 29 insertions(+), 0 deletions(-)
>
> diff --git a/test-qmp-commands.c b/test-qmp-commands.c
> index f142cc6..7db38b6 100644
> --- a/test-qmp-commands.c
> +++ b/test-qmp-commands.c
> @@ -98,6 +98,34 @@ static void test_dispatch_cmd_io(void)
>       QDECREF(req);
>   }
>
> +/* test generated dealloc functions for generated types */
> +static void test_dealloc_types(void)
> +{
> +    UserDefOne *ud1test, *ud1a, *ud1b;
> +    UserDefOneList *ud1list;
> +
> +    ud1test = g_malloc0(sizeof(UserDefOne));
> +    ud1test->integer = 42;
> +    ud1test->string = strdup("hi there 42");
> +
> +    qapi_free_UserDefOne(ud1test);
> +
> +    ud1a = g_malloc0(sizeof(UserDefOne));
> +    ud1a->integer = 43;
> +    ud1a->string = strdup("hi there 43");
> +
> +    ud1b = g_malloc0(sizeof(UserDefOne));
> +    ud1b->integer = 44;
> +    ud1b->string = strdup("hi there 44");

Minor nit: this should be g_strdup.

Regards,

Anthony Liguori

> +
> +    ud1list = g_malloc0(sizeof(UserDefOneList));
> +    ud1list->value = ud1a;
> +    ud1list->next = g_malloc0(sizeof(UserDefOneList));
> +    ud1list->next->value = ud1b;
> +
> +    qapi_free_UserDefOneList(ud1list);
> +}
> +
>   int main(int argc, char **argv)
>   {
>       g_test_init(&argc,&argv, NULL);
> @@ -105,6 +133,7 @@ int main(int argc, char **argv)
>       g_test_add_func("/0.15/dispatch_cmd", test_dispatch_cmd);
>       g_test_add_func("/0.15/dispatch_cmd_error", test_dispatch_cmd_error);
>       g_test_add_func("/0.15/dispatch_cmd_io", test_dispatch_cmd_io);
> +    g_test_add_func("/0.15/dealloc_types", test_dealloc_types);
>
>       module_call_init(MODULE_INIT_QAPI);
>       g_test_run();

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists Luiz Capitulino
@ 2011-09-29 12:51   ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:51 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Previously our logic for keeping track of when we're visiting the head
> of a list was done via a global bool. This can be overwritten if dealing
> with nested lists, so use stack entries to track this instead.
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   qapi/qapi-dealloc-visitor.c |   28 +++++++++++++++++++++-------
>   1 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/qapi/qapi-dealloc-visitor.c b/qapi/qapi-dealloc-visitor.c
> index 6b586ad..a154523 100644
> --- a/qapi/qapi-dealloc-visitor.c
> +++ b/qapi/qapi-dealloc-visitor.c
> @@ -19,6 +19,7 @@
>   typedef struct StackEntry
>   {
>       void *value;
> +    bool is_list_head;
>       QTAILQ_ENTRY(StackEntry) node;
>   } StackEntry;
>
> @@ -39,6 +40,11 @@ static void qapi_dealloc_push(QapiDeallocVisitor *qov, void *value)
>       StackEntry *e = g_malloc0(sizeof(*e));
>
>       e->value = value;
> +
> +    /* see if we're just pushing a list head tracker */
> +    if (value == NULL) {
> +        e->is_list_head = true;
> +    }
>       QTAILQ_INSERT_HEAD(&qov->stack, e, node);
>   }
>
> @@ -72,7 +78,7 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp)
>   static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp)
>   {
>       QapiDeallocVisitor *qov = to_qov(v);
> -    qov->is_list_head = true;
> +    qapi_dealloc_push(qov, NULL);
>   }
>
>   static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
> @@ -80,19 +86,27 @@ static GenericList *qapi_dealloc_next_list(Visitor *v, GenericList **listp,
>   {
>       GenericList *list = *listp;
>       QapiDeallocVisitor *qov = to_qov(v);
> +    StackEntry *e = QTAILQ_FIRST(&qov->stack);
>
> -    if (!qov->is_list_head) {
> -        *listp = list->next;
> -        g_free(list);
> -        return *listp;
> +    if (e&&  e->is_list_head) {
> +        e->is_list_head = false;
> +        return list;
>       }
>
> -    qov->is_list_head = false;
> -    return list;
> +    if (list) {
> +        list = list->next;
> +        g_free(*listp);
> +        return list;
> +    }
> +
> +    return NULL;
>   }
>
>   static void qapi_dealloc_end_list(Visitor *v, Error **errp)
>   {
> +    QapiDeallocVisitor *qov = to_qov(v);
> +    void *obj = qapi_dealloc_pop(qov);
> +    assert(obj == NULL); /* should've been list head tracker with no payload */
>   }
>
>   static void qapi_dealloc_type_str(Visitor *v, char **obj, const char *name,

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration Luiz Capitulino
@ 2011-09-29 12:53   ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:53 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> From: Michael Roth<mdroth@linux.vnet.ibm.com>
>
> Modify logic such that we never assign values to the list head argument
> to progress through the list on subsequent iterations, instead rely only
> on having our return value passed back in as an argument on the next
> call. Also update QMP I/O visitors and test cases accordingly, and add a
> missing test case for QmpOutputVisitor.
>
> Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> ---
>   qapi/qmp-input-visitor.c  |    4 +-
>   qapi/qmp-output-visitor.c |   20 +++++++++++++++---
>   scripts/qapi-visit.py     |    4 +-
>   test-visitor.c            |   48 +++++++++++++++++++++++++++++++++++++-------
>   4 files changed, 60 insertions(+), 16 deletions(-)
>
> diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
> index fcf8bf9..8cbc0ab 100644
> --- a/qapi/qmp-input-visitor.c
> +++ b/qapi/qmp-input-visitor.c
> @@ -144,8 +144,6 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list,
>           }
>           (*list)->next = entry;
>       }
> -    *list = entry;
> -
>
>       return entry;
>   }
> @@ -240,9 +238,11 @@ static void qmp_input_type_enum(Visitor *v, int *obj, const char *strings[],
>
>       if (strings[value] == NULL) {
>           error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
> +        g_free(enum_str);
>           return;
>       }
>
> +    g_free(enum_str);
>       *obj = value;
>   }
>
> diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
> index 4419a31..d67724e 100644
> --- a/qapi/qmp-output-visitor.c
> +++ b/qapi/qmp-output-visitor.c
> @@ -20,6 +20,7 @@
>   typedef struct QStackEntry
>   {
>       QObject *value;
> +    bool is_list_head;
>       QTAILQ_ENTRY(QStackEntry) node;
>   } QStackEntry;
>
> @@ -45,6 +46,9 @@ static void qmp_output_push_obj(QmpOutputVisitor *qov, QObject *value)
>       QStackEntry *e = g_malloc0(sizeof(*e));
>
>       e->value = value;
> +    if (qobject_type(e->value) == QTYPE_QLIST) {
> +        e->is_list_head = true;
> +    }
>       QTAILQ_INSERT_HEAD(&qov->stack, e, node);
>   }
>
> @@ -122,12 +126,20 @@ static void qmp_output_start_list(Visitor *v, const char *name, Error **errp)
>       qmp_output_push(qov, list);
>   }
>
> -static GenericList *qmp_output_next_list(Visitor *v, GenericList **list,
> +static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp,
>                                            Error **errp)
>   {
> -    GenericList *retval = *list;
> -    *list = retval->next;
> -    return retval;
> +    GenericList *list = *listp;
> +    QmpOutputVisitor *qov = to_qov(v);
> +    QStackEntry *e = QTAILQ_FIRST(&qov->stack);
> +
> +    assert(e);
> +    if (e->is_list_head) {
> +        e->is_list_head = false;
> +        return list;
> +    }
> +
> +    return list ? list->next : NULL;
>   }
>
>   static void qmp_output_end_list(Visitor *v, Error **errp)
> diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
> index 252230e..62de83d 100644
> --- a/scripts/qapi-visit.py
> +++ b/scripts/qapi-visit.py
> @@ -79,11 +79,11 @@ def generate_visit_list(name, members):
>
>   void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
>   {
> -    GenericList *i;
> +    GenericList *i, **head = (GenericList **)obj;
>
>       visit_start_list(m, name, errp);
>
> -    for (i = visit_next_list(m, (GenericList **)obj, errp); i; i = visit_next_list(m,&i, errp)) {
> +    for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m,&i, errp)) {
>           %(name)sList *native_i = (%(name)sList *)i;
>           visit_type_%(name)s(m,&native_i->value, NULL, errp);
>       }
> diff --git a/test-visitor.c b/test-visitor.c
> index b7717de..847ce14 100644
> --- a/test-visitor.c
> +++ b/test-visitor.c
> @@ -27,11 +27,11 @@ static void visit_type_TestStruct(Visitor *v, TestStruct **obj, const char *name
>
>   static void visit_type_TestStructList(Visitor *m, TestStructList ** obj, const char *name, Error **errp)
>   {
> -    GenericList *i;
> +    GenericList *i, **head = (GenericList **)obj;
>
>       visit_start_list(m, name, errp);
>
> -    for (i = visit_next_list(m, (GenericList **)obj, errp); i; i = visit_next_list(m,&i, errp)) {
> +    for (*head = i = visit_next_list(m, head, errp); i; i = visit_next_list(m,&i, errp)) {
>           TestStructList *native_i = (TestStructList *)i;
>           visit_type_TestStruct(m,&native_i->value, NULL, errp);
>       }
> @@ -50,6 +50,8 @@ static void test_visitor_core(void)
>       TestStructList *lts = NULL;
>       Error *err = NULL;
>       QObject *obj;
> +    QList *qlist;
> +    QDict *qdict;
>       QString *str;
>       int64_t value = 0;
>
> @@ -96,7 +98,9 @@ static void test_visitor_core(void)
>       g_assert(pts->y == 84);
>
>       qobject_decref(obj);
> +    g_free(pts);
>
> +    /* test list input visitor */
>       obj = qobject_from_json("[{'x': 42, 'y': 84}, {'x': 12, 'y': 24}]");
>       mi = qmp_input_visitor_new(obj);
>       v = qmp_input_get_visitor(mi);
> @@ -110,14 +114,41 @@ static void test_visitor_core(void)
>       g_assert(lts->value->x == 42);
>       g_assert(lts->value->y == 84);
>
> -    lts = lts->next;
> -    g_assert(lts != NULL);
> -    g_assert(lts->value->x == 12);
> -    g_assert(lts->value->y == 24);
> +    g_assert(lts->next != NULL);
> +    g_assert(lts->next->value->x == 12);
> +    g_assert(lts->next->value->y == 24);
> +    g_assert(lts->next->next == NULL);
>
> -    g_assert(lts->next == NULL);
> +    qobject_decref(obj);
>
> +    /* test list output visitor */
> +    mo = qmp_output_visitor_new();
> +    v = qmp_output_get_visitor(mo);
> +    visit_type_TestStructList(v,&lts, NULL,&err);
> +    if (err) {
> +        g_error("%s", error_get_pretty(err));
> +    }
> +    obj = qmp_output_get_qobject(mo);
> +    g_print("obj: %s\n", qstring_get_str(qobject_to_json(obj)));
> +
> +    qlist = qobject_to_qlist(obj);
> +    assert(qlist);
> +    obj = qlist_pop(qlist);
> +    qdict = qobject_to_qdict(obj);
> +    assert(qdict);
> +    assert(qdict_get_int(qdict, "x") == 42);
> +    assert(qdict_get_int(qdict, "y") == 84);
> +    qobject_decref(obj);
> +
> +    obj = qlist_pop(qlist);
> +    qdict = qobject_to_qdict(obj);
> +    assert(qdict);
> +    assert(qdict_get_int(qdict, "x") == 12);
> +    assert(qdict_get_int(qdict, "y") == 24);
>       qobject_decref(obj);
> +
> +    qmp_output_visitor_cleanup(mo);
> +    QDECREF(qlist);
>   }
>
>   /* test deep nesting with refs to other user-defined types */
> @@ -286,7 +317,8 @@ static void test_nested_enums(void)
>       g_assert(nested_enums_cpy->has_enum2 == false);
>       g_assert(nested_enums_cpy->has_enum4 == true);
>
> -    qobject_decref(obj);
> +    qmp_output_visitor_cleanup(mo);
> +    qmp_input_visitor_cleanup(mi);
>       qapi_free_NestedEnumsOne(nested_enums);
>       qapi_free_NestedEnumsOne(nested_enums_cpy);
>   }

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 12/21] qapi: Convert query-version Luiz Capitulino
@ 2011-09-29 12:54   ` Anthony Liguori
  2011-09-29 14:32     ` Luiz Capitulino
  0 siblings, 1 reply; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:54 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> The original conversion was done by Anthony Liguori. This commit
> is just a rebase.

For all of the rest of the patches, you can add my Signed-off-by: before your 
SoB.  Then you don't need to have the disclaimer in the commit message.

Regards,

Anthony Liguori

>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> ---
>   hmp.c            |   13 +++++++++++++
>   hmp.h            |    1 +
>   monitor.c        |   46 +++-------------------------------------------
>   qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
>   qmp-commands.hx  |    6 ++++++
>   qmp.c            |   16 ++++++++++++++++
>   6 files changed, 76 insertions(+), 43 deletions(-)
>
> diff --git a/hmp.c b/hmp.c
> index 47e1ff7..bb6c86f 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
>       }
>       qapi_free_NameInfo(info);
>   }
> +
> +void hmp_info_version(Monitor *mon)
> +{
> +    VersionInfo *info;
> +
> +    info = qmp_query_version(NULL);
> +
> +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
> +                   info->package);
> +
> +    qapi_free_VersionInfo(info);
> +}
> diff --git a/hmp.h b/hmp.h
> index 5fe73f1..2aa75a2 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -18,5 +18,6 @@
>   #include "qapi-types.h"
>
>   void hmp_info_name(Monitor *mon);
> +void hmp_info_version(Monitor *mon);
>
>   #endif
> diff --git a/monitor.c b/monitor.c
> index 8af0e27..9edc38c 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -730,37 +730,6 @@ help:
>       help_cmd(mon, "info");
>   }
>
> -static void do_info_version_print(Monitor *mon, const QObject *data)
> -{
> -    QDict *qdict;
> -    QDict *qemu;
> -
> -    qdict = qobject_to_qdict(data);
> -    qemu = qdict_get_qdict(qdict, "qemu");
> -
> -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> -                  qdict_get_int(qemu, "major"),
> -                  qdict_get_int(qemu, "minor"),
> -                  qdict_get_int(qemu, "micro"),
> -                  qdict_get_str(qdict, "package"));
> -}
> -
> -static void do_info_version(Monitor *mon, QObject **ret_data)
> -{
> -    const char *version = QEMU_VERSION;
> -    int major = 0, minor = 0, micro = 0;
> -    char *tmp;
> -
> -    major = strtol(version,&tmp, 10);
> -    tmp++;
> -    minor = strtol(tmp,&tmp, 10);
> -    tmp++;
> -    micro = strtol(tmp,&tmp, 10);
> -
> -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
> -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
> -}
> -
>   static QObject *get_cmd_dict(const char *name)
>   {
>       const char *p;
> @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
>           .args_type  = "",
>           .params     = "",
>           .help       = "show the version of QEMU",
> -        .user_print = do_info_version_print,
> -        .mhandler.info_new = do_info_version,
> +        .mhandler.info = hmp_info_version,
>       },
>       {
>           .name       = "network",
> @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
>
>   static const mon_cmd_t qmp_query_cmds[] = {
>       {
> -        .name       = "version",
> -        .args_type  = "",
> -        .params     = "",
> -        .help       = "show the version of QEMU",
> -        .user_print = do_info_version_print,
> -        .mhandler.info_new = do_info_version,
> -    },
> -    {
>           .name       = "commands",
>           .args_type  = "",
>           .params     = "",
> @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
>
>   static QObject *get_qmp_greeting(void)
>   {
> -    QObject *ver;
> +    QObject *ver = NULL;
>
> -    do_info_version(NULL,&ver);
> +    qmp_marshal_input_query_version(NULL, NULL,&ver);
>       return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
>   }
>
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3585324..3c0ac4e 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -23,3 +23,40 @@
>   # Since 0.14.0
>   ##
>   { 'command': 'query-name', 'returns': 'NameInfo' }
> +
> +##
> +# @VersionInfo:
> +#
> +# A description of QEMU's version.
> +#
> +# @qemu.major:  The major version of QEMU
> +#
> +# @qemu.minor:  The minor version of QEMU
> +#
> +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
> +#               version of 50 signifies a development branch.  A micro version
> +#               greater than or equal to 90 signifies a release candidate for
> +#               the next minor version.  A micro version of less than 50
> +#               signifies a stable release.
> +#
> +# @package:     QEMU will always set this field to an empty string.  Downstream
> +#               versions of QEMU should set this to a non-empty string.  The
> +#               exact format depends on the downstream however it highly
> +#               recommended that a unique name is used.
> +#
> +# Since: 0.14.0
> +##
> +{ 'type': 'VersionInfo',
> +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
> +           'package': 'str'} }
> +
> +##
> +# @query-version:
> +#
> +# Returns the current version of QEMU.
> +#
> +# Returns:  A @VersionInfo object describing the current version of QEMU.
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'query-version', 'returns': 'VersionInfo' }
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 7b3839e..9f067ea 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1053,6 +1053,12 @@ Example:
>
>   EQMP
>
> +    {
> +        .name       = "query-version",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_version,
> +    },
> +
>   SQMP
>   query-commands
>   --------------
> diff --git a/qmp.c b/qmp.c
> index 8aa9c66..f978ea4 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
>
>       return info;
>   }
> +
> +VersionInfo *qmp_query_version(Error **err)
> +{
> +    VersionInfo *info = g_malloc0(sizeof(*info));
> +    const char *version = QEMU_VERSION;
> +    char *tmp;
> +
> +    info->qemu.major = strtol(version,&tmp, 10);
> +    tmp++;
> +    info->qemu.minor = strtol(tmp,&tmp, 10);
> +    tmp++;
> +    info->qemu.micro = strtol(tmp,&tmp, 10);
> +    info->package = g_strdup(QEMU_PKGVERSION);
> +
> +    return info;
> +}

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions
  2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
                   ` (20 preceding siblings ...)
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 21/21] qapi: Convert system_powerdown Luiz Capitulino
@ 2011-09-29 12:55 ` Anthony Liguori
  2011-09-29 13:52   ` Luiz Capitulino
  21 siblings, 1 reply; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 12:55 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, armbru, qemu-devel, mdroth

On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> This series is a bundle of three things:
>
>   1. Patches 01 to 04 add the middle mode feature to the current QMP server.
>      That mode allows for the current server to support QAPI commands. The
>      Original author is Anthony, you can find his original post here:
>
>          http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg00374.html
>
>   2. Patches 05 to 10 are fixes from Anthony and Michael to the QAPI
>      handling of the list type.
>
>   3. Patches 11 to 21 are simple monitor commands conversions to the QAPI.
>      This is just a rebase of a previous conversion work by Anthony.

Great series!

Other than the one minor comment re: strdup and commit messages, I think it's 
ready to go.

Regards,

Anthony Liguori

>
>   Makefile                    |   12 ++
>   Makefile.objs               |    3 +
>   Makefile.target             |    6 +-
>   error.c                     |    4 +
>   hmp-commands.hx             |   11 +-
>   hmp.c                       |  116 ++++++++++++++++++
>   hmp.h                       |   31 +++++
>   monitor.c                   |  273 +++++--------------------------------------
>   qapi-schema.json            |  273 +++++++++++++++++++++++++++++++++++++++++++
>   qapi/qapi-dealloc-visitor.c |   34 +++++-
>   qapi/qapi-types-core.h      |    3 +
>   qapi/qmp-input-visitor.c    |    4 +-
>   qapi/qmp-output-visitor.c   |   20 +++-
>   qemu-char.c                 |   35 ++----
>   qerror.c                    |   33 +++++
>   qerror.h                    |    2 +
>   qmp-commands.hx             |   57 +++++++--
>   qmp.c                       |   92 +++++++++++++++
>   scripts/qapi-commands.py    |   98 ++++++++++++---
>   scripts/qapi-types.py       |    5 +
>   scripts/qapi-visit.py       |    4 +-
>   scripts/qapi.py             |    4 +-
>   test-qmp-commands.c         |   29 +++++
>   test-visitor.c              |   48 +++++++--
>   vl.c                        |   12 ++
>   25 files changed, 877 insertions(+), 332 deletions(-)
>
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions
  2011-09-29 12:55 ` [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Anthony Liguori
@ 2011-09-29 13:52   ` Luiz Capitulino
  2011-09-29 20:15     ` Michael Roth
  0 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-29 13:52 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: kwolf, armbru, qemu-devel, mdroth

On Thu, 29 Sep 2011 07:55:37 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> > This series is a bundle of three things:
> >
> >   1. Patches 01 to 04 add the middle mode feature to the current QMP server.
> >      That mode allows for the current server to support QAPI commands. The
> >      Original author is Anthony, you can find his original post here:
> >
> >          http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg00374.html
> >
> >   2. Patches 05 to 10 are fixes from Anthony and Michael to the QAPI
> >      handling of the list type.
> >
> >   3. Patches 11 to 21 are simple monitor commands conversions to the QAPI.
> >      This is just a rebase of a previous conversion work by Anthony.
> 
> Great series!
> 
> Other than the one minor comment re: strdup and commit messages, I think it's 
> ready to go.

Actually, I've found a few small problems with the enumeration in
patch 14:

 1. I'm not using VmRunStatus internally in QEMU, I'm using RunState (which
    has to be dropped, right? - Is VmRunStatus a good name btw?)

 2. RunState has a RSTATE_NO_STATE enum, which is used for initialization. To
    have that in VmRunStatus I had to add a 'no-status' value in the schema,
    is that ok?

 3. The code generator is replacing "-" by "_" (eg. 'no-status becomes
    'no_status') but I have already fixed this and will include the patch
    in v2

Also, it would be nice if Michael could review how I'm doing lists in
patches 16 and 17.

Thanks!

> 
> Regards,
> 
> Anthony Liguori
> 
> >
> >   Makefile                    |   12 ++
> >   Makefile.objs               |    3 +
> >   Makefile.target             |    6 +-
> >   error.c                     |    4 +
> >   hmp-commands.hx             |   11 +-
> >   hmp.c                       |  116 ++++++++++++++++++
> >   hmp.h                       |   31 +++++
> >   monitor.c                   |  273 +++++--------------------------------------
> >   qapi-schema.json            |  273 +++++++++++++++++++++++++++++++++++++++++++
> >   qapi/qapi-dealloc-visitor.c |   34 +++++-
> >   qapi/qapi-types-core.h      |    3 +
> >   qapi/qmp-input-visitor.c    |    4 +-
> >   qapi/qmp-output-visitor.c   |   20 +++-
> >   qemu-char.c                 |   35 ++----
> >   qerror.c                    |   33 +++++
> >   qerror.h                    |    2 +
> >   qmp-commands.hx             |   57 +++++++--
> >   qmp.c                       |   92 +++++++++++++++
> >   scripts/qapi-commands.py    |   98 ++++++++++++---
> >   scripts/qapi-types.py       |    5 +
> >   scripts/qapi-visit.py       |    4 +-
> >   scripts/qapi.py             |    4 +-
> >   test-qmp-commands.c         |   29 +++++
> >   test-visitor.c              |   48 +++++++--
> >   vl.c                        |   12 ++
> >   25 files changed, 877 insertions(+), 332 deletions(-)
> >
> >
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version
  2011-09-29 12:54   ` Anthony Liguori
@ 2011-09-29 14:32     ` Luiz Capitulino
  2011-09-29 14:42       ` Anthony Liguori
  0 siblings, 1 reply; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-29 14:32 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: kwolf, armbru, qemu-devel, mdroth

On Thu, 29 Sep 2011 07:54:57 -0500
Anthony Liguori <aliguori@us.ibm.com> wrote:

> On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> > The original conversion was done by Anthony Liguori. This commit
> > is just a rebase.
> 
> For all of the rest of the patches, you can add my Signed-off-by: before your 
> SoB.  Then you don't need to have the disclaimer in the commit message.

And I let the author as being me?

> 
> Regards,
> 
> Anthony Liguori
> 
> >
> > Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> > ---
> >   hmp.c            |   13 +++++++++++++
> >   hmp.h            |    1 +
> >   monitor.c        |   46 +++-------------------------------------------
> >   qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
> >   qmp-commands.hx  |    6 ++++++
> >   qmp.c            |   16 ++++++++++++++++
> >   6 files changed, 76 insertions(+), 43 deletions(-)
> >
> > diff --git a/hmp.c b/hmp.c
> > index 47e1ff7..bb6c86f 100644
> > --- a/hmp.c
> > +++ b/hmp.c
> > @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
> >       }
> >       qapi_free_NameInfo(info);
> >   }
> > +
> > +void hmp_info_version(Monitor *mon)
> > +{
> > +    VersionInfo *info;
> > +
> > +    info = qmp_query_version(NULL);
> > +
> > +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> > +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
> > +                   info->package);
> > +
> > +    qapi_free_VersionInfo(info);
> > +}
> > diff --git a/hmp.h b/hmp.h
> > index 5fe73f1..2aa75a2 100644
> > --- a/hmp.h
> > +++ b/hmp.h
> > @@ -18,5 +18,6 @@
> >   #include "qapi-types.h"
> >
> >   void hmp_info_name(Monitor *mon);
> > +void hmp_info_version(Monitor *mon);
> >
> >   #endif
> > diff --git a/monitor.c b/monitor.c
> > index 8af0e27..9edc38c 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -730,37 +730,6 @@ help:
> >       help_cmd(mon, "info");
> >   }
> >
> > -static void do_info_version_print(Monitor *mon, const QObject *data)
> > -{
> > -    QDict *qdict;
> > -    QDict *qemu;
> > -
> > -    qdict = qobject_to_qdict(data);
> > -    qemu = qdict_get_qdict(qdict, "qemu");
> > -
> > -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
> > -                  qdict_get_int(qemu, "major"),
> > -                  qdict_get_int(qemu, "minor"),
> > -                  qdict_get_int(qemu, "micro"),
> > -                  qdict_get_str(qdict, "package"));
> > -}
> > -
> > -static void do_info_version(Monitor *mon, QObject **ret_data)
> > -{
> > -    const char *version = QEMU_VERSION;
> > -    int major = 0, minor = 0, micro = 0;
> > -    char *tmp;
> > -
> > -    major = strtol(version,&tmp, 10);
> > -    tmp++;
> > -    minor = strtol(tmp,&tmp, 10);
> > -    tmp++;
> > -    micro = strtol(tmp,&tmp, 10);
> > -
> > -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
> > -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
> > -}
> > -
> >   static QObject *get_cmd_dict(const char *name)
> >   {
> >       const char *p;
> > @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
> >           .args_type  = "",
> >           .params     = "",
> >           .help       = "show the version of QEMU",
> > -        .user_print = do_info_version_print,
> > -        .mhandler.info_new = do_info_version,
> > +        .mhandler.info = hmp_info_version,
> >       },
> >       {
> >           .name       = "network",
> > @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
> >
> >   static const mon_cmd_t qmp_query_cmds[] = {
> >       {
> > -        .name       = "version",
> > -        .args_type  = "",
> > -        .params     = "",
> > -        .help       = "show the version of QEMU",
> > -        .user_print = do_info_version_print,
> > -        .mhandler.info_new = do_info_version,
> > -    },
> > -    {
> >           .name       = "commands",
> >           .args_type  = "",
> >           .params     = "",
> > @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
> >
> >   static QObject *get_qmp_greeting(void)
> >   {
> > -    QObject *ver;
> > +    QObject *ver = NULL;
> >
> > -    do_info_version(NULL,&ver);
> > +    qmp_marshal_input_query_version(NULL, NULL,&ver);
> >       return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
> >   }
> >
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 3585324..3c0ac4e 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -23,3 +23,40 @@
> >   # Since 0.14.0
> >   ##
> >   { 'command': 'query-name', 'returns': 'NameInfo' }
> > +
> > +##
> > +# @VersionInfo:
> > +#
> > +# A description of QEMU's version.
> > +#
> > +# @qemu.major:  The major version of QEMU
> > +#
> > +# @qemu.minor:  The minor version of QEMU
> > +#
> > +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
> > +#               version of 50 signifies a development branch.  A micro version
> > +#               greater than or equal to 90 signifies a release candidate for
> > +#               the next minor version.  A micro version of less than 50
> > +#               signifies a stable release.
> > +#
> > +# @package:     QEMU will always set this field to an empty string.  Downstream
> > +#               versions of QEMU should set this to a non-empty string.  The
> > +#               exact format depends on the downstream however it highly
> > +#               recommended that a unique name is used.
> > +#
> > +# Since: 0.14.0
> > +##
> > +{ 'type': 'VersionInfo',
> > +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
> > +           'package': 'str'} }
> > +
> > +##
> > +# @query-version:
> > +#
> > +# Returns the current version of QEMU.
> > +#
> > +# Returns:  A @VersionInfo object describing the current version of QEMU.
> > +#
> > +# Since: 0.14.0
> > +##
> > +{ 'command': 'query-version', 'returns': 'VersionInfo' }
> > diff --git a/qmp-commands.hx b/qmp-commands.hx
> > index 7b3839e..9f067ea 100644
> > --- a/qmp-commands.hx
> > +++ b/qmp-commands.hx
> > @@ -1053,6 +1053,12 @@ Example:
> >
> >   EQMP
> >
> > +    {
> > +        .name       = "query-version",
> > +        .args_type  = "",
> > +        .mhandler.cmd_new = qmp_marshal_input_query_version,
> > +    },
> > +
> >   SQMP
> >   query-commands
> >   --------------
> > diff --git a/qmp.c b/qmp.c
> > index 8aa9c66..f978ea4 100644
> > --- a/qmp.c
> > +++ b/qmp.c
> > @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
> >
> >       return info;
> >   }
> > +
> > +VersionInfo *qmp_query_version(Error **err)
> > +{
> > +    VersionInfo *info = g_malloc0(sizeof(*info));
> > +    const char *version = QEMU_VERSION;
> > +    char *tmp;
> > +
> > +    info->qemu.major = strtol(version,&tmp, 10);
> > +    tmp++;
> > +    info->qemu.minor = strtol(tmp,&tmp, 10);
> > +    tmp++;
> > +    info->qemu.micro = strtol(tmp,&tmp, 10);
> > +    info->package = g_strdup(QEMU_PKGVERSION);
> > +
> > +    return info;
> > +}
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version
  2011-09-29 14:32     ` Luiz Capitulino
@ 2011-09-29 14:42       ` Anthony Liguori
  0 siblings, 0 replies; 37+ messages in thread
From: Anthony Liguori @ 2011-09-29 14:42 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: kwolf, mdroth, Anthony Liguori, armbru, qemu-devel

On 09/29/2011 09:32 AM, Luiz Capitulino wrote:
> On Thu, 29 Sep 2011 07:54:57 -0500
> Anthony Liguori<aliguori@us.ibm.com>  wrote:
>
>> On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
>>> The original conversion was done by Anthony Liguori. This commit
>>> is just a rebase.
>>
>> For all of the rest of the patches, you can add my Signed-off-by: before your
>> SoB.  Then you don't need to have the disclaimer in the commit message.
>
> And I let the author as being me?

Sure.

Regards,

Anthony Liguori

>
>>
>> Regards,
>>
>> Anthony Liguori
>>
>>>
>>> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
>>> ---
>>>    hmp.c            |   13 +++++++++++++
>>>    hmp.h            |    1 +
>>>    monitor.c        |   46 +++-------------------------------------------
>>>    qapi-schema.json |   37 +++++++++++++++++++++++++++++++++++++
>>>    qmp-commands.hx  |    6 ++++++
>>>    qmp.c            |   16 ++++++++++++++++
>>>    6 files changed, 76 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/hmp.c b/hmp.c
>>> index 47e1ff7..bb6c86f 100644
>>> --- a/hmp.c
>>> +++ b/hmp.c
>>> @@ -24,3 +24,16 @@ void hmp_info_name(Monitor *mon)
>>>        }
>>>        qapi_free_NameInfo(info);
>>>    }
>>> +
>>> +void hmp_info_version(Monitor *mon)
>>> +{
>>> +    VersionInfo *info;
>>> +
>>> +    info = qmp_query_version(NULL);
>>> +
>>> +    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
>>> +                   info->qemu.major, info->qemu.minor, info->qemu.micro,
>>> +                   info->package);
>>> +
>>> +    qapi_free_VersionInfo(info);
>>> +}
>>> diff --git a/hmp.h b/hmp.h
>>> index 5fe73f1..2aa75a2 100644
>>> --- a/hmp.h
>>> +++ b/hmp.h
>>> @@ -18,5 +18,6 @@
>>>    #include "qapi-types.h"
>>>
>>>    void hmp_info_name(Monitor *mon);
>>> +void hmp_info_version(Monitor *mon);
>>>
>>>    #endif
>>> diff --git a/monitor.c b/monitor.c
>>> index 8af0e27..9edc38c 100644
>>> --- a/monitor.c
>>> +++ b/monitor.c
>>> @@ -730,37 +730,6 @@ help:
>>>        help_cmd(mon, "info");
>>>    }
>>>
>>> -static void do_info_version_print(Monitor *mon, const QObject *data)
>>> -{
>>> -    QDict *qdict;
>>> -    QDict *qemu;
>>> -
>>> -    qdict = qobject_to_qdict(data);
>>> -    qemu = qdict_get_qdict(qdict, "qemu");
>>> -
>>> -    monitor_printf(mon, "%" PRId64 ".%" PRId64 ".%" PRId64 "%s\n",
>>> -                  qdict_get_int(qemu, "major"),
>>> -                  qdict_get_int(qemu, "minor"),
>>> -                  qdict_get_int(qemu, "micro"),
>>> -                  qdict_get_str(qdict, "package"));
>>> -}
>>> -
>>> -static void do_info_version(Monitor *mon, QObject **ret_data)
>>> -{
>>> -    const char *version = QEMU_VERSION;
>>> -    int major = 0, minor = 0, micro = 0;
>>> -    char *tmp;
>>> -
>>> -    major = strtol(version,&tmp, 10);
>>> -    tmp++;
>>> -    minor = strtol(tmp,&tmp, 10);
>>> -    tmp++;
>>> -    micro = strtol(tmp,&tmp, 10);
>>> -
>>> -    *ret_data = qobject_from_jsonf("{ 'qemu': { 'major': %d, 'minor': %d, \
>>> -        'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION);
>>> -}
>>> -
>>>    static QObject *get_cmd_dict(const char *name)
>>>    {
>>>        const char *p;
>>> @@ -2866,8 +2835,7 @@ static const mon_cmd_t info_cmds[] = {
>>>            .args_type  = "",
>>>            .params     = "",
>>>            .help       = "show the version of QEMU",
>>> -        .user_print = do_info_version_print,
>>> -        .mhandler.info_new = do_info_version,
>>> +        .mhandler.info = hmp_info_version,
>>>        },
>>>        {
>>>            .name       = "network",
>>> @@ -3159,14 +3127,6 @@ static const mon_cmd_t qmp_cmds[] = {
>>>
>>>    static const mon_cmd_t qmp_query_cmds[] = {
>>>        {
>>> -        .name       = "version",
>>> -        .args_type  = "",
>>> -        .params     = "",
>>> -        .help       = "show the version of QEMU",
>>> -        .user_print = do_info_version_print,
>>> -        .mhandler.info_new = do_info_version,
>>> -    },
>>> -    {
>>>            .name       = "commands",
>>>            .args_type  = "",
>>>            .params     = "",
>>> @@ -5172,9 +5132,9 @@ void monitor_resume(Monitor *mon)
>>>
>>>    static QObject *get_qmp_greeting(void)
>>>    {
>>> -    QObject *ver;
>>> +    QObject *ver = NULL;
>>>
>>> -    do_info_version(NULL,&ver);
>>> +    qmp_marshal_input_query_version(NULL, NULL,&ver);
>>>        return qobject_from_jsonf("{'QMP':{'version': %p,'capabilities': []}}",ver);
>>>    }
>>>
>>> diff --git a/qapi-schema.json b/qapi-schema.json
>>> index 3585324..3c0ac4e 100644
>>> --- a/qapi-schema.json
>>> +++ b/qapi-schema.json
>>> @@ -23,3 +23,40 @@
>>>    # Since 0.14.0
>>>    ##
>>>    { 'command': 'query-name', 'returns': 'NameInfo' }
>>> +
>>> +##
>>> +# @VersionInfo:
>>> +#
>>> +# A description of QEMU's version.
>>> +#
>>> +# @qemu.major:  The major version of QEMU
>>> +#
>>> +# @qemu.minor:  The minor version of QEMU
>>> +#
>>> +# @qemu.micro:  The micro version of QEMU.  By current convention, a micro
>>> +#               version of 50 signifies a development branch.  A micro version
>>> +#               greater than or equal to 90 signifies a release candidate for
>>> +#               the next minor version.  A micro version of less than 50
>>> +#               signifies a stable release.
>>> +#
>>> +# @package:     QEMU will always set this field to an empty string.  Downstream
>>> +#               versions of QEMU should set this to a non-empty string.  The
>>> +#               exact format depends on the downstream however it highly
>>> +#               recommended that a unique name is used.
>>> +#
>>> +# Since: 0.14.0
>>> +##
>>> +{ 'type': 'VersionInfo',
>>> +  'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
>>> +           'package': 'str'} }
>>> +
>>> +##
>>> +# @query-version:
>>> +#
>>> +# Returns the current version of QEMU.
>>> +#
>>> +# Returns:  A @VersionInfo object describing the current version of QEMU.
>>> +#
>>> +# Since: 0.14.0
>>> +##
>>> +{ 'command': 'query-version', 'returns': 'VersionInfo' }
>>> diff --git a/qmp-commands.hx b/qmp-commands.hx
>>> index 7b3839e..9f067ea 100644
>>> --- a/qmp-commands.hx
>>> +++ b/qmp-commands.hx
>>> @@ -1053,6 +1053,12 @@ Example:
>>>
>>>    EQMP
>>>
>>> +    {
>>> +        .name       = "query-version",
>>> +        .args_type  = "",
>>> +        .mhandler.cmd_new = qmp_marshal_input_query_version,
>>> +    },
>>> +
>>>    SQMP
>>>    query-commands
>>>    --------------
>>> diff --git a/qmp.c b/qmp.c
>>> index 8aa9c66..f978ea4 100644
>>> --- a/qmp.c
>>> +++ b/qmp.c
>>> @@ -26,3 +26,19 @@ NameInfo *qmp_query_name(Error **errp)
>>>
>>>        return info;
>>>    }
>>> +
>>> +VersionInfo *qmp_query_version(Error **err)
>>> +{
>>> +    VersionInfo *info = g_malloc0(sizeof(*info));
>>> +    const char *version = QEMU_VERSION;
>>> +    char *tmp;
>>> +
>>> +    info->qemu.major = strtol(version,&tmp, 10);
>>> +    tmp++;
>>> +    info->qemu.minor = strtol(tmp,&tmp, 10);
>>> +    tmp++;
>>> +    info->qemu.micro = strtol(tmp,&tmp, 10);
>>> +    info->package = g_strdup(QEMU_PKGVERSION);
>>> +
>>> +    return info;
>>> +}
>>
>
>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev Luiz Capitulino
@ 2011-09-29 19:17   ` Michael Roth
  0 siblings, 0 replies; 37+ messages in thread
From: Michael Roth @ 2011-09-29 19:17 UTC (permalink / raw)
  To: Luiz Capitulino, qemu-devel; +Cc: kwolf, aliguori, armbru

Looks good, tested qmp/hmp commands.

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com>

On Wed, 28 Sep 2011 11:44:40 -0300, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> The original conversion was done by Anthony Liguori. This commit
> is just a rebase.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  hmp.c            |   13 +++++++++++++
>  hmp.h            |    1 +
>  monitor.c        |   11 +----------
>  qapi-schema.json |   26 ++++++++++++++++++++++++++
>  qemu-char.c      |   35 +++++++++++------------------------
>  qmp-commands.hx  |    6 ++++++
>  6 files changed, 58 insertions(+), 34 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 1cd40ae..91de86c 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -80,3 +80,16 @@ void hmp_info_uuid(Monitor *mon)
>      monitor_printf(mon, "%s\n", info->UUID);
>      qapi_free_UuidInfo(info);
>  }
> +
> +void hmp_info_chardev(Monitor *mon)
> +{
> +    ChardevInfoList *char_info, *info;
> +
> +    char_info = qmp_query_chardev(NULL);
> +    for (info = char_info; info; info = info->next) {
> +        monitor_printf(mon, "%s: filename=%s\n", info->value->label,
> +                                                 info->value->filename);
> +    }
> +
> +    qapi_free_ChardevInfoList(char_info);
> +}
> diff --git a/hmp.h b/hmp.h
> index 49a5971..7388f9a 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -22,5 +22,6 @@ void hmp_info_version(Monitor *mon);
>  void hmp_info_kvm(Monitor *mon);
>  void hmp_info_status(Monitor *mon);
>  void hmp_info_uuid(Monitor *mon);
> +void hmp_info_chardev(Monitor *mon);
> 
>  #endif
> diff --git a/monitor.c b/monitor.c
> index d294bc9..66b3004 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2777,8 +2777,7 @@ static const mon_cmd_t info_cmds[] = {
>          .args_type  = "",
>          .params     = "",
>          .help       = "show the character devices",
> -        .user_print = qemu_chr_info_print,
> -        .mhandler.info_new = qemu_chr_info,
> +        .mhandler.info = hmp_info_chardev,
>      },
>      {
>          .name       = "block",
> @@ -3060,14 +3059,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
>          .mhandler.info_new = do_info_commands,
>      },
>      {
> -        .name       = "chardev",
> -        .args_type  = "",
> -        .params     = "",
> -        .help       = "show the character devices",
> -        .user_print = qemu_chr_info_print,
> -        .mhandler.info_new = qemu_chr_info,
> -    },
> -    {
>          .name       = "block",
>          .args_type  = "",
>          .params     = "",
> diff --git a/qapi-schema.json b/qapi-schema.json
> index b678f07..2ebcb1c 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -176,3 +176,29 @@
>  ##
>  { 'command': 'query-uuid', 'returns': 'UuidInfo' }
> 
> +##
> +# @ChardevInfo:
> +#
> +# Information about a character device.
> +#
> +# @label: the label of the character device
> +#
> +# @filename: the filename of the character device
> +#
> +# Notes: @filename is encoded using the QEMU command line character device
> +#        encoding.  See the QEMU man page for details.
> +#
> +# Since: 0.14.0
> +##
> +{ 'type': 'ChardevInfo', 'data': {'label': 'str', 'filename': 'str'} }
> +
> +##
> +# @query-chardev:
> +#
> +# Returns information about current character devices.
> +#
> +# Returns: a list of @ChardevInfo
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
> diff --git a/qemu-char.c b/qemu-char.c
> index 09d2309..8bdbcfd 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -31,7 +31,7 @@
>  #include "hw/usb.h"
>  #include "hw/baum.h"
>  #include "hw/msmouse.h"
> -#include "qemu-objects.h"
> +#include "qmp-commands.h"
> 
>  #include <unistd.h>
>  #include <fcntl.h>
> @@ -2650,35 +2650,22 @@ void qemu_chr_delete(CharDriverState *chr)
>      g_free(chr);
>  }
> 
> -static void qemu_chr_qlist_iter(QObject *obj, void *opaque)
> +ChardevInfoList *qmp_query_chardev(Error **errp)
>  {
> -    QDict *chr_dict;
> -    Monitor *mon = opaque;
> -
> -    chr_dict = qobject_to_qdict(obj);
> -    monitor_printf(mon, "%s: filename=%s\n", qdict_get_str(chr_dict, "label"),
> -                                         qdict_get_str(chr_dict, "filename"));
> -}
> -
> -void qemu_chr_info_print(Monitor *mon, const QObject *ret_data)
> -{
> -    qlist_iter(qobject_to_qlist(ret_data), qemu_chr_qlist_iter, mon);
> -}
> -
> -void qemu_chr_info(Monitor *mon, QObject **ret_data)
> -{
> -    QList *chr_list;
> +    ChardevInfoList *chr_list = NULL;
>      CharDriverState *chr;
> 
> -    chr_list = qlist_new();
> -
>      QTAILQ_FOREACH(chr, &chardevs, next) {
> -        QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }",
> -                                          chr->label, chr->filename);
> -        qlist_append_obj(chr_list, obj);
> +        ChardevInfoList *info = g_malloc0(sizeof(*info));
> +        info->value = g_malloc0(sizeof(*info->value));
> +        info->value->label = g_strdup(chr->label);
> +        info->value->filename = g_strdup(chr->filename);
> +
> +        info->next = chr_list;
> +        chr_list = info;
>      }
> 
> -    *ret_data = QOBJECT(chr_list);
> +    return chr_list;
>  }
> 
>  CharDriverState *qemu_chr_find(const char *name)
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 4fef25f..dfc02af 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1120,6 +1120,12 @@ Example:
> 
>  EQMP
> 
> +    {
> +        .name       = "query-chardev",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_chardev,
> +    },
> +
>  SQMP
>  query-block
>  -----------
> -- 
> 1.7.7.rc0.72.g4b5ea
> 

-- 
Sincerely,
Mike Roth
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands Luiz Capitulino
@ 2011-09-29 19:25   ` Michael Roth
  0 siblings, 0 replies; 37+ messages in thread
From: Michael Roth @ 2011-09-29 19:25 UTC (permalink / raw)
  To: Luiz Capitulino, qemu-devel; +Cc: kwolf, aliguori, armbru

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com>

On Wed, 28 Sep 2011 11:44:41 -0300, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  monitor.c        |   40 +++++++++++++++-------------------------
>  qapi-schema.json |   23 +++++++++++++++++++++++
>  qmp-commands.hx  |    6 ++++++
>  3 files changed, 44 insertions(+), 25 deletions(-)
> 
> diff --git a/monitor.c b/monitor.c
> index 66b3004..d546bad 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -730,39 +730,37 @@ help:
>      help_cmd(mon, "info");
>  }
> 
> -static QObject *get_cmd_dict(const char *name)
> +static CommandInfoList *alloc_cmd_entry(const char *cmd_name)
>  {
> -    const char *p;
> +    CommandInfoList *info;
> 
> -    /* Remove '|' from some commands */
> -    p = strchr(name, '|');
> -    if (p) {
> -        p++;
> -    } else {
> -        p = name;
> -    }
> +    info = g_malloc0(sizeof(*info));
> +    info->value = g_malloc0(sizeof(*info->value));
> +    info->value->name = g_strdup(cmd_name);
> 
> -    return qobject_from_jsonf("{ 'name': %s }", p);
> +    return info;
>  }
> 
> -static void do_info_commands(Monitor *mon, QObject **ret_data)
> +CommandInfoList *qmp_query_commands(Error **errp)
>  {
> -    QList *cmd_list;
> +    CommandInfoList *info, *cmd_list = NULL;
>      const mon_cmd_t *cmd;
> 
> -    cmd_list = qlist_new();
> -
>      for (cmd = qmp_cmds; cmd->name != NULL; cmd++) {
> -        qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
> +        info = alloc_cmd_entry(cmd->name);
> +        info->next = cmd_list;
> +        cmd_list = info;
>      }
> 
>      for (cmd = qmp_query_cmds; cmd->name != NULL; cmd++) {
>          char buf[128];
>          snprintf(buf, sizeof(buf), "query-%s", cmd->name);
> -        qlist_append_obj(cmd_list, get_cmd_dict(buf));
> +        info = alloc_cmd_entry(buf);
> +        info->next = cmd_list;
> +        cmd_list = info;
>      }
> 
> -    *ret_data = QOBJECT(cmd_list);
> +    return cmd_list;
>  }
> 
>  /* get the current CPU defined by the user */
> @@ -3051,14 +3049,6 @@ static const mon_cmd_t qmp_cmds[] = {
> 
>  static const mon_cmd_t qmp_query_cmds[] = {
>      {
> -        .name       = "commands",
> -        .args_type  = "",
> -        .params     = "",
> -        .help       = "list QMP available commands",
> -        .user_print = monitor_user_noop,
> -        .mhandler.info_new = do_info_commands,
> -    },
> -    {
>          .name       = "block",
>          .args_type  = "",
>          .params     = "",
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 2ebcb1c..b26dd25 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -202,3 +202,26 @@
>  # Since: 0.14.0
>  ##
>  { 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
> +
> +##
> +# @CommandInfo:
> +#
> +# Information about a QMP command
> +#
> +# @name: The command name
> +#
> +# Since: 0.14.0
> +##
> +{ 'type': 'CommandInfo', 'data': {'name': 'str'} }
> +
> +##
> +# @query-commands:
> +#
> +# Return a list of supported QMP commands by this server
> +#
> +# Returns: A list of @CommandInfo for all supported commands
> +#
> +# Since: 0.14.0
> +##
> +{ 'command': 'query-commands', 'returns': ['CommandInfo'] }
> +
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index dfc02af..0fda5c3 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1090,6 +1090,12 @@ Note: This example has been shortened as the real response is too long.
> 
>  EQMP
> 
> +    {
> +        .name       = "query-commands",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_commands,
> +    },
> +
>  SQMP
>  query-chardev
>  -------------
> -- 
> 1.7.7.rc0.72.g4b5ea
> 

-- 
Sincerely,
Mike Roth
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH 14/21] qapi: Convert query-status
  2011-09-28 14:44 ` [Qemu-devel] [PATCH 14/21] qapi: Convert query-status Luiz Capitulino
@ 2011-09-29 20:11   ` Michael Roth
  0 siblings, 0 replies; 37+ messages in thread
From: Michael Roth @ 2011-09-29 20:11 UTC (permalink / raw)
  To: Luiz Capitulino, qemu-devel; +Cc: kwolf, aliguori, armbru

On Wed, 28 Sep 2011 11:44:38 -0300, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> The original conversion was done by Anthony Liguori. This commit
> is just a rebase.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  hmp.c            |   19 +++++++++++++++
>  hmp.h            |    1 +
>  monitor.c        |   41 +--------------------------------
>  qapi-schema.json |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  qmp-commands.hx  |    6 +++++
>  vl.c             |   12 +++++++++
>  6 files changed, 106 insertions(+), 40 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 94a7f74..9e7f07e 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -53,3 +53,22 @@ void hmp_info_kvm(Monitor *mon)
>      qapi_free_KvmInfo(info);
>  }
> 
> +void hmp_info_status(Monitor *mon)
> +{
> +    StatusInfo *info;
> +
> +    info = qmp_query_status(NULL);
> +
> +    monitor_printf(mon, "VM status: %s%s",
> +                   info->running ? "running" : "paused",
> +                   info->singlestep ? " (single step mode)" : "");
> +
> +    if (!info->running && info->status != VM_RUN_STATUS_PAUSED) {
> +        monitor_printf(mon, " (%s)", VmRunStatus_lookup[info->status]);
> +    }
> +
> +    monitor_printf(mon, "\n");
> +
> +    qapi_free_StatusInfo(info);
> +}
> +
> diff --git a/hmp.h b/hmp.h
> index a93ac1f..df4242f 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -20,5 +20,6 @@
>  void hmp_info_name(Monitor *mon);
>  void hmp_info_version(Monitor *mon);
>  void hmp_info_kvm(Monitor *mon);
> +void hmp_info_status(Monitor *mon);
> 
>  #endif
> diff --git a/monitor.c b/monitor.c
> index edb56b9..f641504 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2544,36 +2544,6 @@ static int do_inject_nmi(Monitor *mon, const QDict *qdict, QObject **ret_data)
>  }
>  #endif
> 
> -static void do_info_status_print(Monitor *mon, const QObject *data)
> -{
> -    QDict *qdict;
> -    const char *status;
> -
> -    qdict = qobject_to_qdict(data);
> -
> -    monitor_printf(mon, "VM status: ");
> -    if (qdict_get_bool(qdict, "running")) {
> -        monitor_printf(mon, "running");
> -        if (qdict_get_bool(qdict, "singlestep")) {
> -            monitor_printf(mon, " (single step mode)");
> -        }
> -    } else {
> -        monitor_printf(mon, "paused");
> -    }
> -
> -    status = qdict_get_str(qdict, "status");
> -    if (strcmp(status, "paused") && strcmp(status, "running")) {
> -        monitor_printf(mon, " (%s)", status);
> -    }
> -
> -    monitor_printf(mon, "\n");
> -}
> -
> -static void do_info_status(Monitor *mon, QObject **ret_data)
> -{
> -    *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i, 'status': %s }", runstate_is_running(), singlestep, runstate_as_string());
> -}
> -
>  static qemu_acl *find_acl(Monitor *mon, const char *name)
>  {
>      qemu_acl *acl = qemu_acl_find(name);
> @@ -2966,8 +2936,7 @@ static const mon_cmd_t info_cmds[] = {
>          .args_type  = "",
>          .params     = "",
>          .help       = "show the current VM status (running|paused)",
> -        .user_print = do_info_status_print,
> -        .mhandler.info_new = do_info_status,
> +        .mhandler.info = hmp_info_status,
>      },
>      {
>          .name       = "pcmcia",
> @@ -3149,14 +3118,6 @@ static const mon_cmd_t qmp_query_cmds[] = {
>          .mhandler.info_new = do_pci_info,
>      },
>      {
> -        .name       = "status",
> -        .args_type  = "",
> -        .params     = "",
> -        .help       = "show the current VM status (running|paused)",
> -        .user_print = do_info_status_print,
> -        .mhandler.info_new = do_info_status,
> -    },
> -    {
>          .name       = "mice",
>          .args_type  = "",
>          .params     = "",
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 641f12d..de0f807 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -85,3 +85,70 @@
>  ##
>  { 'command': 'query-kvm', 'returns': 'KvmInfo' }
> 
> +##
> +# @VmRunStatus
> +#
> +# An enumation of VM run status.
> +#

Maybe add a description for no-status here for completeness

> +# @debug: QEMU is running on a debugger
> +#
> +# @inmigrate: guest is paused waiting for an incoming migration
> +#
> +# @internal-error: An internal error that prevents further guest execution
> +# has occurred
> +#
> +# @io-error: the last IOP has failed and the device is configured to pause
> +# on I/O errors
> +#
> +# @paused: guest has been paused via the 'stop' command
> +#
> +# @postmigrate: guest is paused following a successful 'migrate'
> +#
> +# @prelaunch: QEMU was started with -S and guest has not started
> +#
> +# @finish-migrate: guest is paused to finish the migration process
> +#
> +# @restore-vm: guest is paused to restore VM state
> +#
> +# @running: guest is actively running
> +#
> +# @save-vm: guest is paused to save the VM state
> +#
> +# @shutdown: guest is shut down (and -no-shutdown is in use)
> +#
> +# @watchdog: the watchdog action is configured to pause and has been triggered
> +##
> +{ 'enum': 'VmRunStatus',
> +  'data': [ 'no-status', 'debug', 'inmigrate', 'internal-error', 'io-error',
> +            'paused', 'postmigrate', 'prelaunch', 'finish-migrate',
> +            'restore-vm', 'running', 'save-vm', 'shutdown', 'watchdog' ] }
> +
> +##
> +# @StatusInfo:
> +#
> +# Information about VCPU run state
> +#
> +# @running: true if all VCPUs are runnable, false if not runnable
> +#
> +# @singlestep: true if VCPUs are in single-step mode
> +#
> +# @status: the @VmRunStatus
> +#
> +# Since:  0.14.0
> +#
> +# Notes: @singlestep is enabled through the GDB stub
> +##
> +{ 'type': 'StatusInfo',
> +  'data': {'running': 'bool', 'singlestep': 'bool', 'status': 'VmRunStatus'} }
> +
> +##
> +# @query-status:
> +#
> +# Query the run status of all VCPUs
> +#
> +# Returns: @StatusInfo reflecting all VCPUs
> +#
> +# Since:  0.14.0
> +##
> +{ 'command': 'query-status', 'returns': 'StatusInfo' }
> +
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 9f9751d..afa95bd 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1609,6 +1609,12 @@ Example:
>  <- { "return": { "running": true, "singlestep": false, "status": "running" } }
> 
>  EQMP
> +    

Whitespace

> +    {
> +        .name       = "query-status",
> +        .args_type  = "",
> +        .mhandler.cmd_new = qmp_marshal_input_query_status,
> +    },
> 
>  SQMP
>  query-mice
> diff --git a/vl.c b/vl.c
> index bd4a5ce..b7bef59 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -147,6 +147,7 @@ int main(int argc, char **argv)
>  #include "qemu-config.h"
>  #include "qemu-objects.h"
>  #include "qemu-options.h"
> +#include "qmp-commands.h"
>  #ifdef CONFIG_VIRTFS
>  #include "fsdev/qemu-fsdev.h"
>  #endif
> @@ -434,6 +435,17 @@ int runstate_is_running(void)
>      return runstate_check(RSTATE_RUNNING);
>  }
> 
> +StatusInfo *qmp_query_status(Error **errp)
> +{
> +    StatusInfo *info = g_malloc0(sizeof(*info));
> +
> +    info->running = runstate_is_running();
> +    info->singlestep = singlestep;
> +    info->status = current_run_state;
> +
> +    return info;
> +}
> +
>  /***********************************************************/
>  /* real time host monotonic timer */
> 
> -- 
> 1.7.7.rc0.72.g4b5ea
> 

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com>

-- 
Sincerely,
Mike Roth
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions
  2011-09-29 13:52   ` Luiz Capitulino
@ 2011-09-29 20:15     ` Michael Roth
  2011-09-29 20:57       ` Luiz Capitulino
  0 siblings, 1 reply; 37+ messages in thread
From: Michael Roth @ 2011-09-29 20:15 UTC (permalink / raw)
  To: Luiz Capitulino, Anthony Liguori; +Cc: kwolf, qemu-devel, armbru

On Thu, 29 Sep 2011 10:52:30 -0300, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> On Thu, 29 Sep 2011 07:55:37 -0500
> Anthony Liguori <aliguori@us.ibm.com> wrote:
> 
> > On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> > > This series is a bundle of three things:
> > >
> > >   1. Patches 01 to 04 add the middle mode feature to the current QMP server.
> > >      That mode allows for the current server to support QAPI commands. The
> > >      Original author is Anthony, you can find his original post here:
> > >
> > >          http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg00374.html
> > >
> > >   2. Patches 05 to 10 are fixes from Anthony and Michael to the QAPI
> > >      handling of the list type.
> > >
> > >   3. Patches 11 to 21 are simple monitor commands conversions to the QAPI.
> > >      This is just a rebase of a previous conversion work by Anthony.
> > 
> > Great series!
> > 
> > Other than the one minor comment re: strdup and commit messages, I think it's 
> > ready to go.
> 
> Actually, I've found a few small problems with the enumeration in
> patch 14:
> 
>  1. I'm not using VmRunStatus internally in QEMU, I'm using RunState (which
>     has to be dropped, right? - Is VmRunStatus a good name btw?)

Ideally, yes, especially since you're directly assigning enum values from
RunState to VmRunStatus. VmRunStatus seems reasonable to me, though if you call
it RunState you can just drop the previous declaration of RunState to convert
everythin over to using the schema definition.

> 
>  2. RunState has a RSTATE_NO_STATE enum, which is used for initialization. To
>     have that in VmRunStatus I had to add a 'no-status' value in the schema,
>     is that ok?


Seems fine to me... the visitor routine assumes enumeration for schema-defined
enums starts at 0, so if that corresponds to RSTATE_NO_STATE you're fine.

> 
>  3. The code generator is replacing "-" by "_" (eg. 'no-status becomes
>     'no_status') but I have already fixed this and will include the patch
>     in v2

Sounds good.

> 
> Also, it would be nice if Michael could review how I'm doing lists in
> patches 16 and 17.
> 

Sure, reviewed those and they look good. Also did some quick tests on all the converted commands and didn't notice any other issues.

> Thanks!
> 
> > 
> > Regards,
> > 
> > Anthony Liguori
> > 
> > >
> > >   Makefile                    |   12 ++
> > >   Makefile.objs               |    3 +
> > >   Makefile.target             |    6 +-
> > >   error.c                     |    4 +
> > >   hmp-commands.hx             |   11 +-
> > >   hmp.c                       |  116 ++++++++++++++++++
> > >   hmp.h                       |   31 +++++
> > >   monitor.c                   |  273 +++++--------------------------------------
> > >   qapi-schema.json            |  273 +++++++++++++++++++++++++++++++++++++++++++
> > >   qapi/qapi-dealloc-visitor.c |   34 +++++-
> > >   qapi/qapi-types-core.h      |    3 +
> > >   qapi/qmp-input-visitor.c    |    4 +-
> > >   qapi/qmp-output-visitor.c   |   20 +++-
> > >   qemu-char.c                 |   35 ++----
> > >   qerror.c                    |   33 +++++
> > >   qerror.h                    |    2 +
> > >   qmp-commands.hx             |   57 +++++++--
> > >   qmp.c                       |   92 +++++++++++++++
> > >   scripts/qapi-commands.py    |   98 ++++++++++++---
> > >   scripts/qapi-types.py       |    5 +
> > >   scripts/qapi-visit.py       |    4 +-
> > >   scripts/qapi.py             |    4 +-
> > >   test-qmp-commands.c         |   29 +++++
> > >   test-visitor.c              |   48 +++++++--
> > >   vl.c                        |   12 ++
> > >   25 files changed, 877 insertions(+), 332 deletions(-)
> > >
> > >
> > 
> 

-- 
Sincerely,
Mike Roth
IBM Linux Technology Center

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions
  2011-09-29 20:15     ` Michael Roth
@ 2011-09-29 20:57       ` Luiz Capitulino
  0 siblings, 0 replies; 37+ messages in thread
From: Luiz Capitulino @ 2011-09-29 20:57 UTC (permalink / raw)
  To: Michael Roth; +Cc: kwolf, Anthony Liguori, qemu-devel, armbru

On Thu, 29 Sep 2011 15:15:17 -0500
Michael Roth <mdroth@linux.vnet.ibm.com> wrote:

> On Thu, 29 Sep 2011 10:52:30 -0300, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> > On Thu, 29 Sep 2011 07:55:37 -0500
> > Anthony Liguori <aliguori@us.ibm.com> wrote:
> > 
> > > On 09/28/2011 09:44 AM, Luiz Capitulino wrote:
> > > > This series is a bundle of three things:
> > > >
> > > >   1. Patches 01 to 04 add the middle mode feature to the current QMP server.
> > > >      That mode allows for the current server to support QAPI commands. The
> > > >      Original author is Anthony, you can find his original post here:
> > > >
> > > >          http://lists.gnu.org/archive/html/qemu-devel/2011-09/msg00374.html
> > > >
> > > >   2. Patches 05 to 10 are fixes from Anthony and Michael to the QAPI
> > > >      handling of the list type.
> > > >
> > > >   3. Patches 11 to 21 are simple monitor commands conversions to the QAPI.
> > > >      This is just a rebase of a previous conversion work by Anthony.
> > > 
> > > Great series!
> > > 
> > > Other than the one minor comment re: strdup and commit messages, I think it's 
> > > ready to go.
> > 
> > Actually, I've found a few small problems with the enumeration in
> > patch 14:
> > 
> >  1. I'm not using VmRunStatus internally in QEMU, I'm using RunState (which
> >     has to be dropped, right? - Is VmRunStatus a good name btw?)
> 
> Ideally, yes, especially since you're directly assigning enum values from
> RunState to VmRunStatus. VmRunStatus seems reasonable to me, though if you call
> it RunState you can just drop the previous declaration of RunState to convert
> everythin over to using the schema definition.

Yes, that's probably a good idea. I've called it VmRunStatus because RunState
is a too generic name for a public API.

> 
> > 
> >  2. RunState has a RSTATE_NO_STATE enum, which is used for initialization. To
> >     have that in VmRunStatus I had to add a 'no-status' value in the schema,
> >     is that ok?
> 
> 
> Seems fine to me... the visitor routine assumes enumeration for schema-defined
> enums starts at 0, so if that corresponds to RSTATE_NO_STATE you're fine.

I've talked with Anthony about this and we decided to drop RSTATE_NO_STATE
because it doesn't make sense to be part of the protocol.

> 
> > 
> >  3. The code generator is replacing "-" by "_" (eg. 'no-status becomes
> >     'no_status') but I have already fixed this and will include the patch
> >     in v2
> 
> Sounds good.
> 
> > 
> > Also, it would be nice if Michael could review how I'm doing lists in
> > patches 16 and 17.
> > 
> 
> Sure, reviewed those and they look good. Also did some quick tests on all the converted commands and didn't notice any other issues.

Thanks a lot!

Will send v2 soon.

> 
> > Thanks!
> > 
> > > 
> > > Regards,
> > > 
> > > Anthony Liguori
> > > 
> > > >
> > > >   Makefile                    |   12 ++
> > > >   Makefile.objs               |    3 +
> > > >   Makefile.target             |    6 +-
> > > >   error.c                     |    4 +
> > > >   hmp-commands.hx             |   11 +-
> > > >   hmp.c                       |  116 ++++++++++++++++++
> > > >   hmp.h                       |   31 +++++
> > > >   monitor.c                   |  273 +++++--------------------------------------
> > > >   qapi-schema.json            |  273 +++++++++++++++++++++++++++++++++++++++++++
> > > >   qapi/qapi-dealloc-visitor.c |   34 +++++-
> > > >   qapi/qapi-types-core.h      |    3 +
> > > >   qapi/qmp-input-visitor.c    |    4 +-
> > > >   qapi/qmp-output-visitor.c   |   20 +++-
> > > >   qemu-char.c                 |   35 ++----
> > > >   qerror.c                    |   33 +++++
> > > >   qerror.h                    |    2 +
> > > >   qmp-commands.hx             |   57 +++++++--
> > > >   qmp.c                       |   92 +++++++++++++++
> > > >   scripts/qapi-commands.py    |   98 ++++++++++++---
> > > >   scripts/qapi-types.py       |    5 +
> > > >   scripts/qapi-visit.py       |    4 +-
> > > >   scripts/qapi.py             |    4 +-
> > > >   test-qmp-commands.c         |   29 +++++
> > > >   test-visitor.c              |   48 +++++++--
> > > >   vl.c                        |   12 ++
> > > >   25 files changed, 877 insertions(+), 332 deletions(-)
> > > >
> > > >
> > > 
> > 
> 

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2011-09-29 20:57 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 14:44 [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 01/21] error: let error_is_type take a NULL error Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 02/21] qerror: add qerror_report_err() Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 03/21] qapi: add code generation support for middle mode Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 04/21] qapi: use middle mode in QMP server Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 05/21] qapi: fixup command generation for functions that return list types Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic Luiz Capitulino
2011-09-29 12:49   ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types Luiz Capitulino
2011-09-29 12:50   ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions Luiz Capitulino
2011-09-29 12:51   ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists Luiz Capitulino
2011-09-29 12:51   ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration Luiz Capitulino
2011-09-29 12:53   ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 11/21] qapi: convert query-name Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 12/21] qapi: Convert query-version Luiz Capitulino
2011-09-29 12:54   ` Anthony Liguori
2011-09-29 14:32     ` Luiz Capitulino
2011-09-29 14:42       ` Anthony Liguori
2011-09-28 14:44 ` [Qemu-devel] [PATCH 13/21] qapi: Convert query-kvm Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 14/21] qapi: Convert query-status Luiz Capitulino
2011-09-29 20:11   ` Michael Roth
2011-09-28 14:44 ` [Qemu-devel] [PATCH 15/21] qapi: Convert query-uuid Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev Luiz Capitulino
2011-09-29 19:17   ` Michael Roth
2011-09-28 14:44 ` [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands Luiz Capitulino
2011-09-29 19:25   ` Michael Roth
2011-09-28 14:44 ` [Qemu-devel] [PATCH 18/21] qapi: Convert quit Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 19/21] qapi: Convert stop Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 20/21] qapi: Convert system_reset Luiz Capitulino
2011-09-28 14:44 ` [Qemu-devel] [PATCH 21/21] qapi: Convert system_powerdown Luiz Capitulino
2011-09-29 12:55 ` [Qemu-devel] [PATCH v1 00/21]: First round of QAPI conversions Anthony Liguori
2011-09-29 13:52   ` Luiz Capitulino
2011-09-29 20:15     ` Michael Roth
2011-09-29 20:57       ` Luiz Capitulino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.