Skip to contentSkip to conversation

: First round of QAPI conversions

PATCH Superseded Luiz Capitulino 4 participants 37 messages Sep 28, 2011 – Sep 29, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover : First round of QAPI conversions

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(-)
#1 lore raw

PATCH 1/21 error: let error_is_type take a NULL error

From: Anthony Liguori <[email protected]>

---
 error.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
error.c +4 -0
index b802752..68c0039 100644
@@ -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': '");
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#2 lore raw

PATCH 2/21 qerror: add qerror_report_err()

In reply to Luiz Capitulino

From: Anthony Liguori <[email protected]>

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.

---
 qerror.c |   33 +++++++++++++++++++++++++++++++++
 qerror.h |    2 ++
 2 files changed, 35 insertions(+), 0 deletions(-)
qerror.c +33 -0
index c591a54..68998d4 100644
@@ -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
  */
qerror.h +2 -0
index d407001..d4bfcfd 100644
@@ -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__)
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#3 lore raw

PATCH 3/21 qapi: add code generation support for middle mode

In reply to Luiz Capitulino

From: Anthony Liguori <[email protected]>

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.

---
 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(-)
qapi/qapi-types-core.h +3 -0
index a79bc2b..27e6be0 100644
@@ -17,4 +17,7 @@
 #include "qemu-common.h"
 #include "error.h"
 
+/* FIXME this is temporary until we remove middle mode */
+#include "monitor.h"
+
 #endif
scripts/qapi-commands.py +65 -14

150 lines not on this page · raw message

scripts/qapi-types.py +3 -0
index cece325..fc0f7af 100644
@@ -268,3 +268,6 @@ fdecl.write('''
 
 fdecl.flush()
 fdecl.close()
+
+fdef.flush()
+fdef.close()
scripts/qapi.py +3 -1
index 56af232..5299976 100644
@@ -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'
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#4 lore raw

PATCH 4/21 qapi: use middle mode in QMP server

In reply to Luiz Capitulino

From: Anthony Liguori <[email protected]>

Use the new middle mode within the existing QMP server.

---
 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
Makefile +12 -0
index 6ed3194..55ee79c 100644
@@ -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
 
Makefile.objs +2 -0
index 1c65087..441d797 100644
@@ -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
 
Makefile.target +3 -3
index 88d2f1f..b5ed5df 100644
@@ -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
monitor.c +4 -5
index 8ec2c5e..150fe45 100644
@@ -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;
qapi-schema.json new file +3 -0
new file mode 100644
index 0000000..7fcefdb
@@ -0,0 +1,3 @@
+# -*- Mode: Python -*-
+#
+# QAPI Schema
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#5 lore raw

PATCH 5/21 qapi: fixup command generation for functions that return list types

In reply to Luiz Capitulino

From: Anthony Liguori <[email protected]>

---
 scripts/qapi-commands.py |   23 +++++++++++++++--------
 1 files changed, 15 insertions(+), 8 deletions(-)
scripts/qapi-commands.py +15 -8
index 2776804..c947ba4 100644
@@ -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
 
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#6 lore raw

PATCH 6/21 qapi: dealloc visitor, fix premature free and iteration logic

In reply to Luiz Capitulino

From: Michael Roth <[email protected]>

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).

---
 qapi/qapi-dealloc-visitor.c |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)
qapi/qapi-dealloc-visitor.c +15 -5
index f629061..6b586ad 100644
@@ -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)
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by on v1 6/21
#7 lore raw

Re: [Qemu-devel] [PATCH 06/21] qapi: dealloc visitor, fix premature free and iteration logic

Quoted 12 lines · Luiz Capitulino

From: Michael Roth<[email protected]>

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.

Quoted 8 lines

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).

Regards,

Anthony Liguori

Quoted 46 lines
---
  qapi/qapi-dealloc-visitor.c |   20 +++++++++++++++-----
  1 files changed, 15 insertions(+), 5 deletions(-)
qapi/qapi-dealloc-visitor.c +15 -5
index f629061..6b586ad 100644
@@ -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)
#8 lore raw

PATCH 7/21 qapi: generate qapi_free_* functions for *List types

In reply to Luiz Capitulino

From: Michael Roth <[email protected]>

---
 scripts/qapi-types.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
scripts/qapi-types.py +2 -0
index fc0f7af..4797a70 100644
@@ -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'):
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by on v1 7/21
#9 lore raw

Re: [Qemu-devel] [PATCH 07/21] qapi: generate qapi_free_* functions for *List types

Quoted 4 lines · Luiz Capitulino

From: Michael Roth<[email protected]>

Regards,

Anthony Liguori

Quoted 17 lines
---
  scripts/qapi-types.py |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
scripts/qapi-types.py +2 -0
index fc0f7af..4797a70 100644
@@ -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'):
#10 lore raw

PATCH 8/21 qapi: add test cases for generated free functions

In reply to Luiz Capitulino

From: Michael Roth <[email protected]>

---
 test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
test-qmp-commands.c +29 -0
index f142cc6..7db38b6 100644
@@ -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();
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#11 lore raw

Re: [Qemu-devel] [PATCH 08/21] qapi: add test cases for generated free functions

Quoted 25 lines · Luiz Capitulino

From: Michael Roth<[email protected]>

---
  test-qmp-commands.c |   29 +++++++++++++++++++++++++++++
  1 files changed, 29 insertions(+), 0 deletions(-)
test-qmp-commands.c +9 -0
index f142cc6..7db38b6 100644
@@ -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");

test-qmp-commands.c static void test_dispatch_cmd_io(void) · line 119

Quoted 10 lines
test-qmp-commands.c +10 -0
+
+    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

Quoted 20 lines
test-qmp-commands.c +10 -0
+
+    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();
#12 lore raw

PATCH 9/21 qapi: dealloc visitor, support freeing of nested lists

In reply to Luiz Capitulino

From: Michael Roth <[email protected]>

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.

---
 qapi/qapi-dealloc-visitor.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)
qapi/qapi-dealloc-visitor.c +21 -7
index 6b586ad..a154523 100644
@@ -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,
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by on v1 9/21
#13 lore raw

Re: [Qemu-devel] [PATCH 09/21] qapi: dealloc visitor, support freeing of nested lists

Quoted 8 lines · Luiz Capitulino

From: Michael Roth<[email protected]>

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.

Regards,

Anthony Liguori

Quoted 71 lines
---
  qapi/qapi-dealloc-visitor.c |   28 +++++++++++++++++++++-------
  1 files changed, 21 insertions(+), 7 deletions(-)
qapi/qapi-dealloc-visitor.c +21 -7
index 6b586ad..a154523 100644
@@ -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,
#14 lore raw

PATCH 10/21 qapi: modify visitor code generation for list iteration

In reply to Luiz Capitulino

From: Michael Roth <[email protected]>

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.

---
 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(-)
qapi/qmp-input-visitor.c +2 -2
index fcf8bf9..8cbc0ab 100644
@@ -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;
 }
 
qapi/qmp-output-visitor.c +16 -4
index 4419a31..d67724e 100644
@@ -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)
scripts/qapi-visit.py +2 -2
index 252230e..62de83d 100644
@@ -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);
     }
test-visitor.c +40 -8

85 lines not on this page · raw message

Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by on v1 10/21
#15 lore raw

Re: [Qemu-devel] [PATCH 10/21] qapi: modify visitor code generation for list iteration

Quoted 10 lines · Luiz Capitulino

From: Michael Roth<[email protected]>

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.

Regards,

Anthony Liguori

Quoted 191 lines
---
  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(-)
qapi/qmp-input-visitor.c +2 -2
index fcf8bf9..8cbc0ab 100644
@@ -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;
  }
 
qapi/qmp-output-visitor.c +16 -4
index 4419a31..d67724e 100644
@@ -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)
scripts/qapi-visit.py +2 -2
index 252230e..62de83d 100644
@@ -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);
      }
test-visitor.c +40 -8
index b7717de..847ce14 100644
@@ -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);
  }
#16 lore raw

PATCH 11/21 qapi: convert query-name

In reply to Luiz Capitulino

From: Anthony Liguori <[email protected]>

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

---
 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
Makefile.objs +1 -0
index 441d797..c90a3cb 100644
@@ -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
hmp.c new file +26 -0
new file mode 100644
index 0000000..47e1ff7
@@ -0,0 +1,26 @@
+/*
+ * Human Monitor Interface
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * 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);
+}
hmp.h new file +22 -0
new file mode 100644
index 0000000..5fe73f1
@@ -0,0 +1,22 @@
+/*
+ * Human Monitor Interface
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * 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
monitor.c +3 -28
index 150fe45..8af0e27 100644
@@ -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     = "",
qapi-schema.json +22 -0
index 7fcefdb..3585324 100644
@@ -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' }
qmp-commands.hx +6 -0
index d83bce5..7b3839e 100644
@@ -1780,6 +1780,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-name",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_name,
+    },
+
 SQMP
 query-uuid
 ----------
qmp.c new file +28 -0
new file mode 100644
index 0000000..8aa9c66
@@ -0,0 +1,28 @@
+/*
+ * QEMU Management Protocol
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *
+ * 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;
+}
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#17 lore raw

PATCH 12/21 qapi: Convert query-version

In reply to Luiz Capitulino

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

---
 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(-)
hmp.c +13 -0
index 47e1ff7..bb6c86f 100644
@@ -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);
+}
hmp.h +1 -0
index 5fe73f1..2aa75a2 100644
@@ -18,5 +18,6 @@
 #include "qapi-types.h"
 
 void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
 #endif
monitor.c +3 -43

71 lines not on this page · raw message

qapi-schema.json +37 -0
index 3585324..3c0ac4e 100644
@@ -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' }
qmp-commands.hx +6 -0
index 7b3839e..9f067ea 100644
@@ -1053,6 +1053,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
 SQMP
 query-commands
 --------------
qmp.c +16 -0
index 8aa9c66..f978ea4 100644
@@ -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;
+}
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#18 lore raw

Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version

Quoted 2 lines · Luiz Capitulino

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

Quoted 208 lines
---
  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(-)
hmp.c +13 -0
index 47e1ff7..bb6c86f 100644
@@ -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);
+}
hmp.h +1 -0
index 5fe73f1..2aa75a2 100644
@@ -18,5 +18,6 @@
  #include "qapi-types.h"
 
  void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
  #endif
monitor.c +3 -43
index 8af0e27..9edc38c 100644
@@ -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);
  }
 
qapi-schema.json +37 -0
index 3585324..3c0ac4e 100644
@@ -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' }
qmp-commands.hx +6 -0
index 7b3839e..9f067ea 100644
@@ -1053,6 +1053,12 @@ Example:
 
  EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
  SQMP
  query-commands
  --------------
qmp.c +16 -0
index 8aa9c66..f978ea4 100644
@@ -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;
+}
#19 lore raw

Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version

Quoted 6 lines · On Thu, 29 Sep 2011 07:54:57 -0500 Anthony Liguori <[email protected]> wrote:
Quoted 2 lines · Luiz Capitulino

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?

Quoted 214 lines

Regards,

Anthony Liguori

Quoted 208 lines
---
  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(-)
hmp.c +13 -0
index 47e1ff7..bb6c86f 100644
@@ -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);
+}
hmp.h +1 -0
index 5fe73f1..2aa75a2 100644
@@ -18,5 +18,6 @@
  #include "qapi-types.h"
 
  void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
  #endif
monitor.c +3 -43
index 8af0e27..9edc38c 100644
@@ -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);
  }
 
qapi-schema.json +37 -0
index 3585324..3c0ac4e 100644
@@ -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' }
qmp-commands.hx +6 -0
index 7b3839e..9f067ea 100644
@@ -1053,6 +1053,12 @@ Example:
 
  EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
  SQMP
  query-commands
  --------------
qmp.c +16 -0
index 8aa9c66..f978ea4 100644
@@ -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;
+}
#20 lore raw

Re: [Qemu-devel] [PATCH 12/21] qapi: Convert query-version

Quoted 11 lines · Luiz Capitulino
Quoted 6 lines · On Thu, 29 Sep 2011 07:54:57 -0500 Anthony Liguori<[email protected]> wrote:
Quoted 2 lines · Luiz Capitulino

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

Quoted 217 lines
Quoted 215 lines

Regards,

Anthony Liguori

Quoted 208 lines
---
   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(-)
hmp.c +13 -0
index 47e1ff7..bb6c86f 100644
@@ -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);
+}
hmp.h +1 -0
index 5fe73f1..2aa75a2 100644
@@ -18,5 +18,6 @@
   #include "qapi-types.h"
 
   void hmp_info_name(Monitor *mon);
+void hmp_info_version(Monitor *mon);
 
   #endif
monitor.c +3 -43
index 8af0e27..9edc38c 100644
@@ -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);
   }
 
qapi-schema.json +37 -0
index 3585324..3c0ac4e 100644
@@ -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' }
qmp-commands.hx +6 -0
index 7b3839e..9f067ea 100644
@@ -1053,6 +1053,12 @@ Example:
 
   EQMP
 
+    {
+        .name       = "query-version",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_version,
+    },
+
   SQMP
   query-commands
   --------------
qmp.c +16 -0
index 8aa9c66..f978ea4 100644
@@ -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;
+}
#21 lore raw

PATCH 13/21 qapi: Convert query-kvm

In reply to Luiz Capitulino

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

---
 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(-)
hmp.c +16 -0
index bb6c86f..94a7f74 100644
@@ -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);
+}
+
hmp.h +1 -0
index 2aa75a2..a93ac1f 100644
@@ -19,5 +19,6 @@
 
 void hmp_info_name(Monitor *mon);
 void hmp_info_version(Monitor *mon);
+void hmp_info_kvm(Monitor *mon);
 
 #endif
monitor.c +1 -35
index 9edc38c..edb56b9 100644
@@ -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     = "",
qapi-schema.json +25 -0
index 3c0ac4e..641f12d 100644
@@ -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' }
+
qmp-commands.hx +6 -0
index 9f067ea..9f9751d 100644
@@ -1570,6 +1570,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-kvm",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_kvm,
+    },
+
 SQMP
 query-status
 ------------
qmp.c +13 -0
index f978ea4..8f7f666 100644
@@ -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;
+}
+
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#22 lore raw

PATCH 14/21 qapi: Convert query-status

In reply to Luiz Capitulino

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

---
 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(-)
hmp.c +19 -0
index 94a7f74..9e7f07e 100644
@@ -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);
+}
+
hmp.h +1 -0
index a93ac1f..df4242f 100644
@@ -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
monitor.c +1 -40

59 lines not on this page · raw message

qapi-schema.json +67 -0

70 lines not on this page · raw message

qmp-commands.hx +6 -0
index 9f9751d..afa95bd 100644
@@ -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
vl.c +12 -0
index bd4a5ce..b7bef59 100644
@@ -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 */
 
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by Tested-by on v1 14/21
#23 lore raw

Re: [Qemu-devel] [PATCH 14/21] qapi: Convert query-status

Quoted 122 lines · Luiz Capitulino

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

---
 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(-)
hmp.c +19 -0
index 94a7f74..9e7f07e 100644
@@ -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);
+}
+
hmp.h +1 -0
index a93ac1f..df4242f 100644
@@ -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
monitor.c +1 -40
index edb56b9..f641504 100644
@@ -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     = "",
qapi-schema.json +0 -0
index 641f12d..de0f807 100644

qapi-schema.json line 92

Quoted 8 lines
qapi-schema.json +5 -0
@@ -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

Quoted 67 lines
qapi-schema.json +62 -0
+# @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' }
+
qmp-commands.hx +0 -0
index 9f9751d..afa95bd 100644

qmp-commands.hx Example: · line 1612

Quoted 4 lines
qmp-commands.hx +1 -0
@@ -1609,6 +1609,12 @@ Example:
 <- { "return": { "running": true, "singlestep": false, "status": "running" } }
 
 EQMP
+    

Whitespace

Quoted 41 lines
qmp-commands.hx +5 -0
+    {
+        .name       = "query-status",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_status,
+    },
 
 SQMP
 query-mice
vl.c +12 -0
index bd4a5ce..b7bef59 100644
@@ -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 */
 
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Signature · 3 lines
Sincerely,
Mike Roth
IBM Linux Technology Center
#24 lore raw

PATCH 15/21 qapi: Convert query-uuid

In reply to Luiz Capitulino

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

---
 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(-)
hmp.c +8 -0
index 9e7f07e..1cd40ae 100644
@@ -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);
+}
hmp.h +1 -0
index df4242f..49a5971 100644
@@ -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
monitor.c +1 -27
index f641504..d294bc9 100644
@@ -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     = "",
qapi-schema.json +24 -0
index de0f807..b678f07 100644
@@ -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' }
+
qmp-commands.hx +6 -0
index afa95bd..4fef25f 100644
@@ -1821,6 +1821,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-uuid",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_uuid,
+    },
+
 SQMP
 query-migrate
 -------------
qmp.c +15 -0
index 8f7f666..58337c7 100644
@@ -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;
+}
+
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#25 lore raw

PATCH 16/21 qapi: Convert query-chardev

In reply to Luiz Capitulino

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

---
 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(-)
hmp.c +13 -0
index 1cd40ae..91de86c 100644
@@ -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);
+}
hmp.h +1 -0
index 49a5971..7388f9a 100644
@@ -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
monitor.c +1 -10
index d294bc9..66b3004 100644
@@ -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     = "",
qapi-schema.json +26 -0
index b678f07..2ebcb1c 100644
@@ -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'] }
qemu-char.c +11 -24
index 09d2309..8bdbcfd 100644
@@ -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)
qmp-commands.hx +6 -0
index 4fef25f..dfc02af 100644
@@ -1120,6 +1120,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-chardev",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_chardev,
+    },
+
 SQMP
 query-block
 -----------
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by Tested-by on v1 16/21
#26 lore raw

Re: [Qemu-devel] [PATCH 16/21] qapi: Convert query-chardev

Looks good, tested qmp/hmp commands.

Quoted 187 lines · Luiz Capitulino

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

---
 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(-)
hmp.c +13 -0
index 1cd40ae..91de86c 100644
@@ -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);
+}
hmp.h +1 -0
index 49a5971..7388f9a 100644
@@ -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
monitor.c +1 -10
index d294bc9..66b3004 100644
@@ -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     = "",
qapi-schema.json +26 -0
index b678f07..2ebcb1c 100644
@@ -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'] }
qemu-char.c +11 -24
index 09d2309..8bdbcfd 100644
@@ -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)
qmp-commands.hx +6 -0
index 4fef25f..dfc02af 100644
@@ -1120,6 +1120,12 @@ Example:
 
 EQMP
 
+    {
+        .name       = "query-chardev",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_chardev,
+    },
+
 SQMP
 query-block
 -----------
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Signature · 3 lines
Sincerely,
Mike Roth
IBM Linux Technology Center
#27 lore raw

PATCH 17/21 qapi: Convert query-commands

In reply to Luiz Capitulino
---
 monitor.c        |   40 +++++++++++++++-------------------------
 qapi-schema.json |   23 +++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 3 files changed, 44 insertions(+), 25 deletions(-)
monitor.c +15 -25
index 66b3004..d546bad 100644
@@ -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     = "",
qapi-schema.json +23 -0
index 2ebcb1c..b26dd25 100644
@@ -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'] }
+
qmp-commands.hx +6 -0
index dfc02af..0fda5c3 100644
@@ -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
 -------------
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Reviewed-by Tested-by on v1 17/21
#28 lore raw

Re: [Qemu-devel] [PATCH 17/21] qapi: Convert query-commands

Quoted 132 lines · Luiz Capitulino
---
 monitor.c        |   40 +++++++++++++++-------------------------
 qapi-schema.json |   23 +++++++++++++++++++++++
 qmp-commands.hx  |    6 ++++++
 3 files changed, 44 insertions(+), 25 deletions(-)
monitor.c +15 -25
index 66b3004..d546bad 100644
@@ -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     = "",
qapi-schema.json +23 -0
index 2ebcb1c..b26dd25 100644
@@ -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'] }
+
qmp-commands.hx +6 -0
index dfc02af..0fda5c3 100644
@@ -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
 -------------
Signature · 1 line
1.7.7.rc0.72.g4b5ea
Signature · 3 lines
Sincerely,
Mike Roth
IBM Linux Technology Center
#29 lore raw

PATCH 18/21 qapi: Convert quit

In reply to Luiz Capitulino

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

---
 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(-)
hmp-commands.hx +1 -1
index 9e1cca8..2163e6f 100644
@@ -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
hmp.c +6 -0
index 91de86c..1f7000a 100644
@@ -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);
+}
hmp.h +1 -0
index 7388f9a..a3dfafd 100644
@@ -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
monitor.c +0 -12
index d546bad..42c754a 100644
@@ -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)
 {
qapi-schema.json +11 -0
index b26dd25..d6a60d2 100644
@@ -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' }
qmp-commands.hx +1 -4
index 0fda5c3..151a5fa 100644
@@ -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
qmp.c +6 -0
index 58337c7..1d380b6 100644
@@ -70,3 +70,9 @@ UuidInfo *qmp_query_uuid(Error **errp)
     return info;
 }
 
+void qmp_quit(Error **err)
+{
+    no_shutdown = 0;
+    qemu_system_shutdown_request();
+}
+
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#30 lore raw

PATCH 19/21 qapi: Convert stop

In reply to Luiz Capitulino

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

---
 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(-)
hmp-commands.hx +1 -2
index 2163e6f..3ad1ce7 100644
@@ -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
hmp.c +5 -0
index 1f7000a..871f858 100644
@@ -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);
+}
hmp.h +1 -0
index a3dfafd..cb21cce 100644
@@ -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
monitor.c +0 -9
index 42c754a..b4a58b1 100644
@@ -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 {
qapi-schema.json +12 -0
index d6a60d2..830a508 100644
@@ -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' }
qmp-commands.hx +1 -4
index 151a5fa..2ccddee 100644
@@ -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
qmp.c +5 -0
index 1d380b6..e17c8b2 100644
@@ -76,3 +76,8 @@ void qmp_quit(Error **err)
     qemu_system_shutdown_request();
 }
 
+void qmp_stop(Error **errp)
+{
+    vm_stop(RSTATE_PAUSED);
+}
+
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#31 lore raw

PATCH 20/21 qapi: Convert system_reset

In reply to Luiz Capitulino

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

---
 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(-)
hmp-commands.hx +1 -2
index 3ad1ce7..b2f5cd1 100644
@@ -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
hmp.c +5 -0
index 871f858..d8b4de6 100644
@@ -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);
+}
hmp.h +1 -0
index cb21cce..a49a6e6 100644
@@ -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
monitor.c +0 -10
index b4a58b1..de6a865 100644
@@ -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,
qapi-schema.json +9 -0
index 830a508..e14f2f7 100644
@@ -248,3 +248,12 @@
 #         state
 ##
 { 'command': 'stop' }
+
+##
+# @system_reset:
+#
+# Performs a hard reset of a guest.
+#
+# Since: 0.14.0
+##
+{ 'command': 'system_reset' }
qmp-commands.hx +1 -4
index 2ccddee..ea96191 100644
@@ -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
qmp.c +4 -0
index e17c8b2..6767640 100644
@@ -81,3 +81,7 @@ void qmp_stop(Error **errp)
     vm_stop(RSTATE_PAUSED);
 }
 
+void qmp_system_reset(Error **errp)
+{
+    qemu_system_reset_request();
+}
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#32 lore raw

PATCH 21/21 qapi: Convert system_powerdown

In reply to Luiz Capitulino

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

---
 hmp-commands.hx  |    3 +--
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 qapi-schema.json |   14 ++++++++++++++
 qmp.c            |    5 +++++
 5 files changed, 26 insertions(+), 2 deletions(-)
hmp-commands.hx +1 -2
index b2f5cd1..07b493c 100644
@@ -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
hmp.c +5 -0
index d8b4de6..13146a4 100644
@@ -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);
+}
hmp.h +1 -0
index a49a6e6..92433cf 100644
@@ -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
qapi-schema.json +14 -0
index e14f2f7..413fcd5 100644
@@ -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' }
qmp.c +5 -0
index 6767640..aa43207 100644
@@ -85,3 +85,8 @@ void qmp_system_reset(Error **errp)
 {
     qemu_system_reset_request();
 }
+
+void qmp_system_powerdown(Error **erp)
+{
+    qemu_system_powerdown_request();
+}
Signature · 1 line
1.7.7.rc0.72.g4b5ea
#33 lore raw
In reply to Luiz Capitulino
Quoted 6 lines · Luiz Capitulino

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:

Quoted 7 lines

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

Quoted 29 lines
  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(-)
#34 lore raw
Quoted 12 lines · On Thu, 29 Sep 2011 07:55:37 -0500 Anthony Liguori <[email protected]> wrote:
Quoted 11 lines · Luiz Capitulino

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.

Quoted 7 lines
Quoted 2 lines

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!

Quoted 35 lines

Regards,

Anthony Liguori

Quoted 29 lines
  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(-)
#35 lore raw
Quoted 20 lines · Luiz Capitulino
Quoted 17 lines · On Thu, 29 Sep 2011 07:55:37 -0500 Anthony Liguori <[email protected]> wrote:
Quoted 6 lines · Luiz Capitulino

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:

Quoted 7 lines

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!

Quoted 8 lines
Quoted 2 lines

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.

Quoted 4 lines

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.

Quoted 4 lines

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.

Quoted 4 lines

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.

Quoted 38 lines

Thanks!

Quoted 35 lines

Regards,

Anthony Liguori

Quoted 29 lines
  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(-)
Signature · 3 lines
Sincerely,
Mike Roth
IBM Linux Technology Center
#36 lore raw
Quoted 27 lines · On Thu, 29 Sep 2011 15:15:17 -0500 Michael Roth <[email protected]>…
Quoted 26 lines · Luiz Capitulino
Quoted 12 lines · On Thu, 29 Sep 2011 07:55:37 -0500 Anthony Liguori <[email protected]> wrote:
Quoted 11 lines · Luiz Capitulino

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.

Quoted 7 lines
Quoted 2 lines

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:

Quoted 7 lines
Quoted 2 lines

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.

Quoted 9 lines
Quoted 5 lines

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.

Quoted 6 lines
Quoted 5 lines

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

Quoted 8 lines

Sounds good.

Quoted 4 lines

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.

Quoted 40 lines
Quoted 39 lines

Thanks!

Quoted 35 lines

Regards,

Anthony Liguori

Quoted 29 lines
  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(-)