: First round of QAPI conversions
v2 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 12 are QAPI fixes by Anthony, Michael and me
3. Patches 13 to 26 are simple monitor commands conversions to the QAPI. This is just a rebase of a previous conversion work by Anthony.
changelog
---------
v2
o Fix the query-status conversion, which wasn't using the enum generated by the QAPI. This required some additional patches (16 to 18)
o Fix the QAPI not to change an hyphen by an underline for enum strings
o Change the QAPI to generate a _MAX value for enums
o Use g_strdup() instead of strdup()
o Improve commit logs
Makefile | 12 ++ Makefile.objs | 3 + Makefile.target | 6 +- error.c | 4 + gdbstub.c | 26 ++-- hmp-commands.hx | 11 +- hmp.c | 116 ++++++++++++++++++ hmp.h | 31 +++++ hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 2 +- hw/watchdog.c | 2 +- kvm-all.c | 2 +- migration.c | 6 +- monitor.c | 281 +++++-------------------------------------- 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 ++++++++++++++ savevm.c | 4 +- scripts/qapi-commands.py | 98 ++++++++++++--- scripts/qapi-types.py | 12 ++- scripts/qapi-visit.py | 4 +- scripts/qapi.py | 4 +- sysemu.h | 20 +--- test-qmp-commands.c | 29 +++++ test-visitor.c | 48 ++++++-- vl.c | 133 ++++++++++----------- 34 files changed, 959 insertions(+), 452 deletions(-)
PATCH v2 1/26 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
@@ -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
PATCH v2 2/26 qerror: add qerror_report_err()
In reply to Luiz CapitulinoFrom: 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
@@ -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
@@ -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
PATCH v2 3/26 qapi: add code generation support for middle mode
In reply to Luiz CapitulinoFrom: 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
@@ -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
@@ -268,3 +268,6 @@ fdecl.write(''' fdecl.flush() fdecl.close() + +fdef.flush() +fdef.close()
scripts/qapi.py +3 -1
@@ -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
PATCH v2 4/26 qapi: use middle mode in QMP server
In reply to Luiz CapitulinoFrom: 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@ +# -*- Mode: Python -*- +# +# QAPI Schema
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 5/26 qapi: fixup command generation for functions that return list types
In reply to Luiz CapitulinoFrom: Anthony Liguori <[email protected]>
--- scripts/qapi-commands.py | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)
scripts/qapi-commands.py +15 -8
@@ -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
PATCH v2 6/26 qapi: dealloc visitor, fix premature free and iteration logic
In reply to Luiz CapitulinoFrom: 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
@@ -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
PATCH v2 7/26 qapi: generate qapi_free_* functions for *List types
In reply to Luiz CapitulinoFrom: Michael Roth <[email protected]>
--- scripts/qapi-types.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
scripts/qapi-types.py +2 -0
@@ -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
PATCH v2 8/26 qapi: add test cases for generated free functions
In reply to Luiz CapitulinoFrom: Michael Roth <[email protected]>
--- test-qmp-commands.c | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-)
test-qmp-commands.c +29 -0
@@ -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 =g_strdup ("hi there 42" ); + +qapi_free_UserDefOne (ud1test); + + ud1a =g_malloc0 (sizeof (UserDefOne)); + ud1a->integer =43 ; + ud1a->string =g_strdup ("hi there 43" ); + + ud1b =g_malloc0 (sizeof (UserDefOne)); + ud1b->integer =44 ; + ud1b->string =g_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
PATCH v2 9/26 qapi: dealloc visitor, support freeing of nested lists
In reply to Luiz CapitulinoFrom: 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
@@ -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
PATCH v2 10/26 qapi: modify visitor code generation for list iteration
In reply to Luiz CapitulinoFrom: 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
@@ -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
@@ -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
@@ -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
PATCH v2 11/26 qapi: Don't use c_var() on enum strings
In reply to Luiz CapitulinoOtherwise if we have something like 'foo-bar' in the schema, it will be generated as 'foo_bar' in the string lookup table.
c_var() is good for C variables, but not for enum strings.
--- scripts/qapi-types.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
scripts/qapi-types.py +1 -1
@@ -70,7 +70,7 @@ const char *%(name)s_lookup[] = { ret += mcgen(''' "%(value)s", ''', - value=c_var(value).lower()) + value=value.lower()) ret += mcgen(''' NULL,
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 12/26 qapi: Automatically generate a _MAX value for enums
In reply to Luiz CapitulinoIt's the last value in the enum and is very useful for the C implementation.
--- scripts/qapi-types.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
scripts/qapi-types.py +4 -1
@@ -91,8 +91,11 @@ typedef enum %(name)s ''', name=name) + # append automatically generated _MAX value + enum_values = values + [ 'MAX' ] + i = 0 - for value in values: + for value in enum_values: enum_decl += mcgen(''' %(abbrev)s_%(value)s = %(i)d, ''',
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 13/26 qapi: convert query-name
In reply to Luiz CapitulinoFrom: 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 14/26 qapi: Convert query-version
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 15/26 qapi: Convert query-kvm
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 16/26 vl: Change qemu_vmstop_requested() to return a bool
In reply to Luiz CapitulinoThe stop reason is returned in the RunState argument. This is a preparation for a future commit which will convert the query-status command to the QAPI.
--- vl.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
vl.c +10 -6
@@ -1350,11 +1350,15 @@ static int qemu_debug_requested(void)return r; } -static RunState qemu_vmstop_requested (void ) +static bool qemu_vmstop_requested (RunState *r) { -RunState s = vmstop_requested; - vmstop_requested =RSTATE_NO_STATE ; -return s; +if (vmstop_requested !=RSTATE_NO_STATE ) { + *r = vmstop_requested; + vmstop_requested =RSTATE_NO_STATE ; +return true; + } + +return false; }void qemu_register_reset (QEMUResetHandler *func,void *opaque)
@@ -1567,7 +1571,7 @@ static void main_loop(void)#ifdef CONFIG_PROFILER int64_t ti;#endif -int r; +RunState r;qemu_main_loop_start ();
@@ -1606,7 +1610,7 @@ static void main_loop(void)monitor_protocol_event (QEVENT_POWERDOWN ,NULL );qemu_irq_raise (qemu_system_powerdown); } -if ((r =qemu_vmstop_requested ())) { +if (qemu_vmstop_requested (&r)) {vm_stop (r); } }
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 17/26 RunState: Drop the RSTATE_NO_STATE value
In reply to Luiz CapitulinoThe QAPI framework won't generate it, so we need to get rid of it.
In order to do that, this commit makes RSTATE_PRE_LAUNCH the initial state and change qemu_vmstop_requested() to use RSTATE_MAX.
--- sysemu.h | 1 - vl.c | 19 +++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-)
sysemu.h +0 -1
@@ -11,7 +11,6 @@/* vl.c */ typedef enum { - RSTATE_NO_STATE, RSTATE_DEBUG, /* qemu is running under gdb */ RSTATE_IN_MIGRATE, /* paused waiting for an incoming migration */ RSTATE_PANICKED, /* paused due to an internal error */
vl.c +7 -12
@@ -323,7 +323,7 @@ static int default_driver_check(QemuOpts *opts, void *opaque)/***********************************************************/ /* QEMU state */ -static RunState current_run_state =RSTATE_NO_STATE ; +static RunState current_run_state =RSTATE_PRE_LAUNCH ; typedef struct { RunState from;
@@ -332,10 +332,6 @@ typedef struct {static const RunStateTransition runstate_transitions_def[] = {/* from -> to */ - {RSTATE_NO_STATE ,RSTATE_RUNNING }, - {RSTATE_NO_STATE ,RSTATE_IN_MIGRATE }, - {RSTATE_NO_STATE ,RSTATE_PRE_LAUNCH }, - {RSTATE_DEBUG ,RSTATE_RUNNING }, {RSTATE_IN_MIGRATE ,RSTATE_RUNNING },
@@ -350,6 +346,7 @@ static const RunStateTransition runstate_transitions_def[] = { { RSTATE_POST_MIGRATE, RSTATE_RUNNING }, { RSTATE_PRE_LAUNCH, RSTATE_RUNNING }, + { RSTATE_PRE_LAUNCH, RSTATE_IN_MIGRATE }, { RSTATE_PRE_LAUNCH, RSTATE_POST_MIGRATE }, { RSTATE_PRE_MIGRATE, RSTATE_RUNNING },
@@ -424,8 +421,7 @@ void runstate_set(RunState new_state)const char *runstate_as_string (void ) { -assert (current_run_state >RSTATE_NO_STATE && - current_run_state <RSTATE_MAX ); +assert (current_run_state <RSTATE_MAX );return runstate_name_tbl[current_run_state]; }
@@ -1294,7 +1290,7 @@ static int shutdown_requested, shutdown_signal = -1;static pid_t shutdown_pid;static int powerdown_requested;static int debug_requested; -static RunState vmstop_requested =RSTATE_NO_STATE ; +static RunState vmstop_requested =RSTATE_MAX ;int qemu_shutdown_requested_get (void ) {
@@ -1350,11 +1346,12 @@ static int qemu_debug_requested(void)return r; } +/* We use RSTATE_MAX but any invalid value will do */ static bool qemu_vmstop_requested (RunState *r) { -if (vmstop_requested !=RSTATE_NO_STATE ) { +if (vmstop_requested <RSTATE_MAX ) { *r = vmstop_requested; - vmstop_requested =RSTATE_NO_STATE ; + vmstop_requested =RSTATE_MAX ;return true; }
@@ -3569,8 +3566,6 @@ int main(int argc, char **argv, char **envp) } }else if (autostart) {vm_start (); - }else { -runstate_set (RSTATE_PRE_LAUNCH ); }os_setup_post ();
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 18/26 RunState: Rename enum values as generated by the QAPI
In reply to Luiz CapitulinoNext commit will convert the query-status command to use the RunState type as generated by the QAPI.
In order to "transparently" replace the current enum by the QAPI one, we have to make some changes to some enum values.
As the changes are simple renames, I'll do them in one shot. The changes are:
- Rename the prefix from RSTATE_ to RUN_STATE_
- RUN_STATE_SAVEVM to RUN_STATE_SAVE_VM
- RUN_STATE_IN_MIGRATE to RUN_STATE_INMIGRATE
- RUN_STATE_PANICKED to RUN_STATE_INTERNAL_ERROR
- RUN_STATE_POST_MIGRATE to RUN_STATE_POSTMIGRATE
- RUN_STATE_PRE_LAUNCH to RUN_STATE_PRELAUNCH
- RUN_STATE_PRE_MIGRATE to RUN_STATE_PREMIGRATE
- RUN_STATE_RESTORE to RUN_STATE_RESTORE_VM
- RUN_STATE_PRE_MIGRATE to RUN_STATE_FINISH_MIGRATE
--- gdbstub.c | 26 ++++++------ hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 2 +- hw/watchdog.c | 2 +- kvm-all.c | 2 +- migration.c | 6 +- monitor.c | 10 ++-- savevm.c | 4 +- sysemu.h | 28 +++++++------- vl.c | 118 +++++++++++++++++++++++++++--------------------------- 11 files changed, 101 insertions(+), 101 deletions(-)
gdbstub.c +13 -13
@@ -2385,7 +2385,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)return ; }switch (state) { -case RSTATE_DEBUG : +case RUN_STATE_DEBUG :if (env->watchpoint_hit) {switch (env->watchpoint_hit->flags &BP_MEM_ACCESS ) {case BP_MEM_READ :
@@ -2408,25 +2408,25 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)tb_flush (env); ret =GDB_SIGNAL_TRAP ;break ; -case RSTATE_PAUSED : +case RUN_STATE_PAUSED : ret =GDB_SIGNAL_INT ;break ; -case RSTATE_SHUTDOWN : +case RUN_STATE_SHUTDOWN : ret =GDB_SIGNAL_QUIT ;break ; -case RSTATE_IO_ERROR : +case RUN_STATE_IO_ERROR : ret =GDB_SIGNAL_IO ;break ; -case RSTATE_WATCHDOG : +case RUN_STATE_WATCHDOG : ret =GDB_SIGNAL_ALRM ;break ; -case RSTATE_PANICKED : +case RUN_STATE_INTERNAL_ERROR : ret =GDB_SIGNAL_ABRT ;break ; -case RSTATE_SAVEVM : -case RSTATE_RESTORE : +case RUN_STATE_SAVE_VM : +case RUN_STATE_RESTORE_VM :return ; -case RSTATE_PRE_MIGRATE : +case RUN_STATE_FINISH_MIGRATE : ret =GDB_SIGNAL_XCPU ;break ;default :
@@ -2463,7 +2463,7 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) gdb_current_syscall_cb = cb; s->state =RS_SYSCALL ;#ifndef CONFIG_USER_ONLY -vm_stop (RSTATE_DEBUG ); +vm_stop (RUN_STATE_DEBUG );#endif s->state =RS_IDLE ;va_start (va, fmt);
@@ -2537,7 +2537,7 @@ static void gdb_read_byte(GDBState *s, int ch)if (runstate_is_running ()) {/* when the CPU is running, we cannot do anything except stop it when receiving a char */ -vm_stop (RSTATE_PAUSED ); +vm_stop (RUN_STATE_PAUSED ); } else#endif {
@@ -2799,7 +2799,7 @@ static void gdb_chr_event(void *opaque, int event) {switch (event) {case CHR_EVENT_OPENED : -vm_stop (RSTATE_PAUSED ); +vm_stop (RUN_STATE_PAUSED ); gdb_has_xml =0 ;break ;default :
@@ -2840,7 +2840,7 @@ static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len)static void gdb_sigterm_handler (int signal) {if (runstate_is_running ()) { -vm_stop (RSTATE_PAUSED ); +vm_stop (RUN_STATE_PAUSED ); } }#endif
hw/ide/core.c +1 -1
@@ -527,7 +527,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int op) s->bus->dma->ops->set_unit (s->bus->dma, s->unit); s->bus->error_status = op;bdrv_mon_event (s->bs,BDRV_ACTION_STOP , is_read); -vm_stop (RSTATE_IO_ERROR ); +vm_stop (RUN_STATE_IO_ERROR ); }else {if (op &BM_STATUS_DMA_RETRY ) {dma_buf_commit (s,0 );
hw/scsi-disk.c +1 -1
@@ -227,7 +227,7 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type) r->status |=SCSI_REQ_STATUS_RETRY | type;bdrv_mon_event (s->bs,BDRV_ACTION_STOP , is_read); -vm_stop (RSTATE_IO_ERROR ); +vm_stop (RUN_STATE_IO_ERROR ); }else {switch (error) {case ENOMEM :
hw/virtio-blk.c +1 -1
@@ -77,7 +77,7 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error, req->next = s->rq; s->rq = req;bdrv_mon_event (s->bs,BDRV_ACTION_STOP , is_read); -vm_stop (RSTATE_IO_ERROR ); +vm_stop (RUN_STATE_IO_ERROR ); }else {virtio_blk_req_complete (req,VIRTIO_BLK_S_IOERR );bdrv_acct_done (s->bs, &req->acct);
hw/watchdog.c +1 -1
@@ -132,7 +132,7 @@ void watchdog_perform_action(void)case WDT_PAUSE :/* same as 'stop' command in monitor */ watchdog_mon_event ("pause" ); -vm_stop (RSTATE_WATCHDOG ); +vm_stop (RUN_STATE_WATCHDOG );break ;case WDT_DEBUG :
kvm-all.c +1 -1
@@ -1014,7 +1014,7 @@ int kvm_cpu_exec(CPUState *env)if (ret <0 ) {cpu_dump_state (env, stderr, fprintf,CPU_DUMP_CODE ); -vm_stop (RSTATE_PANICKED ); +vm_stop (RUN_STATE_INTERNAL_ERROR ); } env->exit_request =0 ;
migration.c +3 -3
@@ -73,7 +73,7 @@ void process_incoming_migration(QEMUFile *f)if (autostart) {vm_start (); }else { -runstate_set (RSTATE_PRE_LAUNCH ); +runstate_set (RUN_STATE_PRELAUNCH ); } }
@@ -375,7 +375,7 @@ void migrate_fd_put_ready(void *opaque)int old_vm_running =runstate_is_running ();DPRINTF ("done iterating\n" ); -vm_stop (RSTATE_PRE_MIGRATE ); +vm_stop (RUN_STATE_FINISH_MIGRATE );if ((qemu_savevm_state_complete (s->mon, s->file)) <0 ) {if (old_vm_running) {
@@ -392,7 +392,7 @@ void migrate_fd_put_ready(void *opaque) state =MIG_STATE_ERROR ; }if (state ==MIG_STATE_COMPLETED ) { -runstate_set (RSTATE_POST_MIGRATE ); +runstate_set (RUN_STATE_POSTMIGRATE ); } s->state = state;notifier_list_notify (&migration_state_notifiers,NULL );
monitor.c +5 -5
@@ -1247,7 +1247,7 @@ static void do_singlestep(Monitor *mon, const QDict *qdict)*/ static int do_stop (Monitor *mon,const QDict *qdict,QObject **ret_data) { -vm_stop (RSTATE_PAUSED ); +vm_stop (RUN_STATE_PAUSED );return 0 ; }
@@ -1265,11 +1265,11 @@ static int do_cont(Monitor *mon, const QDict *qdict, QObject **ret_data) {struct bdrv_iterate_context context = { mon,0 }; -if (runstate_check (RSTATE_IN_MIGRATE )) { +if (runstate_check (RUN_STATE_INMIGRATE )) {qerror_report (QERR_MIGRATION_EXPECTED );return -1 ; - }else if (runstate_check (RSTATE_PANICKED ) || -runstate_check (RSTATE_SHUTDOWN )) { + }else if (runstate_check (RUN_STATE_INTERNAL_ERROR ) || +runstate_check (RUN_STATE_SHUTDOWN )) {qerror_report (QERR_RESET_REQUIRED );return -1 ; }
@@ -2767,7 +2767,7 @@ static void do_loadvm(Monitor *mon, const QDict *qdict)int saved_vm_running =runstate_is_running ();const char *name =qdict_get_str (qdict,"name" ); -vm_stop (RSTATE_RESTORE ); +vm_stop (RUN_STATE_RESTORE_VM );if (load_vmstate (name) ==0 && saved_vm_running) {vm_start ();
savevm.c +2 -2
@@ -1603,7 +1603,7 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f)int ret; saved_vm_running =runstate_is_running (); -vm_stop (RSTATE_SAVEVM ); +vm_stop (RUN_STATE_SAVE_VM );if (qemu_savevm_state_blocked (mon)) { ret = -EINVAL ;
@@ -1932,7 +1932,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) } saved_vm_running =runstate_is_running (); -vm_stop (RSTATE_SAVEVM ); +vm_stop (RUN_STATE_SAVE_VM );memset (sn,0 ,sizeof (*sn));
sysemu.h +14 -14
@@ -11,20 +11,20 @@/* vl.c */ typedef enum { -RSTATE_DEBUG ,/* qemu is running under gdb */ -RSTATE_IN_MIGRATE ,/* paused waiting for an incoming migration */ -RSTATE_PANICKED ,/* paused due to an internal error */ -RSTATE_IO_ERROR ,/* paused due to an I/O error */ -RSTATE_PAUSED ,/* paused by the user (ie. the 'stop' command) */ -RSTATE_POST_MIGRATE ,/* paused following a successful migration */ -RSTATE_PRE_LAUNCH ,/* qemu was started with -S and haven't started */ -RSTATE_PRE_MIGRATE ,/* paused preparing to finish migrate */ -RSTATE_RESTORE ,/* paused restoring the VM state */ -RSTATE_RUNNING ,/* qemu is running */ -RSTATE_SAVEVM ,/* paused saving VM state */ -RSTATE_SHUTDOWN ,/* guest shut down and -no-shutdown is in use */ -RSTATE_WATCHDOG ,/* watchdog fired and qemu is configured to pause */ -RSTATE_MAX +RUN_STATE_DEBUG ,/* qemu is running under gdb */ +RUN_STATE_INMIGRATE ,/* paused waiting for an incoming migration */ +RUN_STATE_INTERNAL_ERROR ,/* paused due to an internal error */ +RUN_STATE_IO_ERROR ,/* paused due to an I/O error */ +RUN_STATE_PAUSED ,/* paused by the user (ie. the 'stop' command) */ +RUN_STATE_POSTMIGRATE ,/* paused following a successful migration */ +RUN_STATE_PRELAUNCH ,/* qemu was started with -S and haven't started */ +RUN_STATE_FINISH_MIGRATE ,/* paused preparing to finish migrate */ +RUN_STATE_RESTORE_VM ,/* paused restoring the VM state */ +RUN_STATE_RUNNING ,/* qemu is running */ +RUN_STATE_SAVE_VM ,/* paused saving VM state */ +RUN_STATE_SHUTDOWN ,/* guest shut down and -no-shutdown is in use */ +RUN_STATE_WATCHDOG ,/* watchdog fired and qemu is configured to pause */ +RUN_STATE_MAX }RunState ;extern const char *bios_name;
vl.c +59 -59
212 lines not on this page · raw message
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 19/26 qapi: Convert query-status
In reply to Luiz CapitulinoPlease, note that the RunState type as defined in sysemu.h and its runstate_as_string() function are being dropped in favor of the RunState type generated by the QAPI.
--- hmp.c | 19 +++++++++++++++ hmp.h | 1 + monitor.c | 41 +-------------------------------- qapi-schema.json | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 6 +++++ sysemu.h | 19 +-------------- vl.c | 32 +++++++++----------------- 7 files changed, 106 insertions(+), 79 deletions(-)
hmp.c +19 -0
@@ -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 !=RUN_STATE_PAUSED ) { +monitor_printf (mon," (%s)" , RunState_lookup[info->status]); + } + +monitor_printf (mon,"\n" ); + +qapi_free_StatusInfo (info); +} +
hmp.h +1 -0
@@ -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
@@ -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
sysemu.h +1 -18
@@ -6,27 +6,11 @@#include "qemu-option.h" #include "qemu-queue.h" #include "qemu-timer.h" +#include "qapi-types.h" #include "notify.h" /* vl.c */ -typedef enum { -RUN_STATE_DEBUG ,/* qemu is running under gdb */ -RUN_STATE_INMIGRATE ,/* paused waiting for an incoming migration */ -RUN_STATE_INTERNAL_ERROR ,/* paused due to an internal error */ -RUN_STATE_IO_ERROR ,/* paused due to an I/O error */ -RUN_STATE_PAUSED ,/* paused by the user (ie. the 'stop' command) */ -RUN_STATE_POSTMIGRATE ,/* paused following a successful migration */ -RUN_STATE_PRELAUNCH ,/* qemu was started with -S and haven't started */ -RUN_STATE_FINISH_MIGRATE ,/* paused preparing to finish migrate */ -RUN_STATE_RESTORE_VM ,/* paused restoring the VM state */ -RUN_STATE_RUNNING ,/* qemu is running */ -RUN_STATE_SAVE_VM ,/* paused saving VM state */ -RUN_STATE_SHUTDOWN ,/* guest shut down and -no-shutdown is in use */ -RUN_STATE_WATCHDOG ,/* watchdog fired and qemu is configured to pause */ -RUN_STATE_MAX -}RunState ; -extern const char *bios_name;extern const char *qemu_name;
@@ -38,7 +22,6 @@ void runstate_init(void);bool runstate_check (RunState state);void runstate_set (RunState new_state);int runstate_is_running (void ); -const char *runstate_as_string (void );typedef struct vm_change_state_entry VMChangeStateEntry ;typedef void VMChangeStateHandler (void *opaque,int running,RunState state);
vl.c +11 -21
@@ -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
@@ -375,22 +376,6 @@ static const RunStateTransition runstate_transitions_def[] = {static bool runstate_valid_transitions[RUN_STATE_MAX ][RUN_STATE_MAX ]; -static const char *const runstate_name_tbl[RUN_STATE_MAX ] = { - [RUN_STATE_DEBUG ] ="debug" , - [RUN_STATE_INMIGRATE ] ="incoming-migration" , - [RUN_STATE_INTERNAL_ERROR ] ="internal-error" , - [RUN_STATE_IO_ERROR ] ="io-error" , - [RUN_STATE_PAUSED ] ="paused" , - [RUN_STATE_POSTMIGRATE ] ="post-migrate" , - [RUN_STATE_PRELAUNCH ] ="prelaunch" , - [RUN_STATE_FINISH_MIGRATE ] ="finish-migrate" , - [RUN_STATE_RESTORE_VM ] ="restore-vm" , - [RUN_STATE_RUNNING ] ="running" , - [RUN_STATE_SAVE_VM ] ="save-vm" , - [RUN_STATE_SHUTDOWN ] ="shutdown" , - [RUN_STATE_WATCHDOG ] ="watchdog" , -}; -bool runstate_check (RunState state) {return current_run_state == state;
@@ -419,15 +404,20 @@ void runstate_set(RunState new_state) current_run_state = new_state; } -const char *runstate_as_string (void ) +int runstate_is_running (void ) { -assert (current_run_state <RUN_STATE_MAX ); -return runstate_name_tbl[current_run_state]; +return runstate_check (RUN_STATE_RUNNING ); } -int runstate_is_running (void ) +StatusInfo *qmp_query_status (Error **errp) { -return runstate_check (RUN_STATE_RUNNING ); +StatusInfo *info =g_malloc0 (sizeof (*info)); + + info->running =runstate_is_running (); + info->singlestep = singlestep; + info->status = current_run_state; + +return info; }/***********************************************************/
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 20/26 qapi: Convert query-uuid
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 21/26 qapi: Convert query-chardev
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 22/26 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
@@ -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
@@ -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
@@ -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
PATCH v2 23/26 qapi: Convert quit
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 24/26 qapi: Convert stop
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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 (RUN_STATE_PAUSED ); -return 0 ; -} -static void encrypted_bdrv_it (void *opaque,BlockDriverState *bs);struct bdrv_iterate_context {
qapi-schema.json +12 -0
@@ -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
@@ -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
@@ -76,3 +76,8 @@ void qmp_quit(Error **err)qemu_system_shutdown_request (); } +void qmp_stop (Error **errp) +{ +vm_stop (RUN_STATE_PAUSED ); +} +
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 25/26 qapi: Convert system_reset
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -81,3 +81,7 @@ void qmp_stop(Error **errp)vm_stop (RUN_STATE_PAUSED ); } +void qmp_system_reset (Error **errp) +{ +qemu_system_reset_request (); +}
Signature · 1 line
1.7.7.rc0.72.g4b5ea
PATCH v2 26/26 qapi: Convert system_powerdown
In reply to Luiz Capitulino--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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