: info handlers conversions to QObject
v2 cover : info handlers conversions to QObject
Hi,
This series covers almost half of the info handlers conversions to the
QObject style, the other half is a bit more complicated as some handlers can be defined by different machine types.
changelog
---------
v1 -> v2
- Rebase
- do_info_vnc(): drop keys with 'none' strings
v0 -> v1
- Minor fixes (indentation, casts, etc)
- Improved some documentation and changelogs
- Dropped do_info_network() conversion, it still needs work
PATCH v2 1/17 Introduce qemu-objects.h header file
An easy way to include all QEMU objects.
--- qemu-objects.h | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) create mode 100644 qemu-objects.h
qemu-objects.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Include all QEMU objects. +* +* Copyright (C) 2009 Red Hat Inc. +* +* Authors: +* Luiz Capitulino <[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 QEMU_OBJECTS_H +#define QEMU_OBJECTS_H + +#include "qobject.h" +#include "qint.h" +#include "qfloat.h" +#include "qbool.h" +#include "qstring.h" +#include "qdict.h" +#include "qlist.h" +#include "qjson.h" + +#endif /* QEMU_OBJECTS_H */
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 2/17 Makefile: move QObject objs to their own entry
In reply to Luiz CapitulinoOther subsystems will need to link against them.
--- Makefile | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
Makefile +7 -2
@@ -82,6 +82,12 @@ ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS)) recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES) ####################################################################### +# QObject +qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o +qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o +qobject-obj-y += qerror.o + +####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
@@ -120,6 +126,7 @@ net-obj-y += $(addprefix net/, $(net-nested-y)) obj-y = $(block-obj-y) obj-y += $(net-obj-y) +obj-y += $(qobject-obj-y) obj-y += readline.o console.o obj-y += tcg-runtime.o host-utils.o
@@ -152,8 +159,6 @@ obj-y += buffered_file.o migration.o migration-tcp.o qemu-sockets.o obj-y += qemu-char.o aio.o savevm.o obj-y += msmouse.o ps2.o obj-y += qdev.o qdev-properties.o -obj-y += qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o json-lexer.o -obj-y += json-streamer.o json-parser.o qjson.o qerror.o obj-y += qemu-config.o block-migration.o obj-$(CONFIG_BRLAPI) += baum.o
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 3/17 QDict: Introduce qdict_get_qbool()
In reply to Luiz CapitulinoThis is a helper function that does type checking before retrieving a QBool from the dictionary.
--- Makefile | 2 +- qdict.c | 15 +++++++++++++++ qdict.h | 1 + 3 files changed, 17 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -246,7 +246,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx check-qint: check-qint.o qint.o qemu-malloc.o check-qstring: check-qstring.o qstring.o qemu-malloc.o -check-qdict: check-qdict.o qdict.o qint.o qstring.o qemu-malloc.o +check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o
qdict.c +15 -0
@@ -12,6 +12,7 @@#include "qint.h" #include "qdict.h" +#include "qbool.h" #include "qstring.h" #include "qobject.h" #include "qemu-queue.h"
@@ -189,6 +190,20 @@ int64_t qdict_get_int(const QDict *qdict, const char *key) }/** +* qdict_get_bool(): Get a bool mapped by 'key' +* +* This function assumes that 'key' exists and it stores a +* QBool object. +* +* Return bool mapped by 'key'. +*/ +int qdict_get_bool (const QDict *qdict,const char *key) +{ +QObject *obj =qdict_get_obj (qdict, key,QTYPE_QBOOL ); +return qbool_get_int (qobject_to_qbool (obj)); +} + +/** * qdict_get_str(): Get a pointer to the stored string mapped * by 'key' *
qdict.h +1 -0
@@ -37,6 +37,7 @@ void qdict_iter(const QDict *qdict,/* High level helpers */ int64_t qdict_get_int (const QDict *qdict,const char *key); +int qdict_get_bool (const QDict *qdict,const char *key);const char *qdict_get_str (const QDict *qdict,const char *key);int64_t qdict_get_try_int (const QDict *qdict,const char *key,int64_t err_value);
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 4/17 QDict: Introduce qdict_get_qlist()
In reply to Luiz CapitulinoA helper function to get a QList from a QDict.
--- Makefile | 2 +- qdict.c | 13 +++++++++++++ qdict.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletions(-)
Makefile +1 -1
@@ -246,7 +246,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx check-qint: check-qint.o qint.o qemu-malloc.o check-qstring: check-qstring.o qstring.o qemu-malloc.o -check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o +check-qdict: check-qdict.o qdict.o qint.o qstring.o qbool.o qemu-malloc.o qlist.o check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o check-qfloat: check-qfloat.o qfloat.o qemu-malloc.o check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o qemu-malloc.o
qdict.c +13 -0
@@ -204,6 +204,19 @@ int qdict_get_bool(const QDict *qdict, const char *key) }/** +* qdict_get_qlist(): Get the QList mapped by 'key' +* +* This function assumes that 'key' exists and it stores a +* QList object. +* +* Return QList mapped by 'key'. +*/ +QList *qdict_get_qlist (const QDict *qdict,const char *key) +{ +return qobject_to_qlist (qdict_get_obj (qdict, key,QTYPE_QLIST )); +} + +/** * qdict_get_str(): Get a pointer to the stored string mapped * by 'key' *
qdict.h +2 -0
@@ -2,6 +2,7 @@#define QDICT_H #include "qobject.h" +#include "qlist.h" #include "qemu-queue.h" #include <stdint.h>
@@ -38,6 +39,7 @@ void qdict_iter(const QDict *qdict,/* High level helpers */ int64_t qdict_get_int (const QDict *qdict,const char *key);int qdict_get_bool (const QDict *qdict,const char *key); +QList *qdict_get_qlist (const QDict *qdict,const char *key);const char *qdict_get_str (const QDict *qdict,const char *key);int64_t qdict_get_try_int (const QDict *qdict,const char *key,int64_t err_value);
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 5/17 monitor: Fix do_info_balloon() output
In reply to Luiz CapitulinoNew monitor commands should always return values in bytes.
--- monitor.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
monitor.c +9 -3
@@ -1889,12 +1889,18 @@ static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data)static void monitor_print_balloon (Monitor *mon,const QObject *data) { -monitor_printf (mon,"balloon: actual=%d\n" , - (int )qint_get_int (qobject_to_qint (data))); +monitor_printf (mon,"balloon: actual=%" PRId64"\n" , +qint_get_int (qobject_to_qint (data)) >>20 ); }/** * do_info_balloon(): Balloon information +* +* Return a QInt with current ballooning value. +* +* Example: +* +* 1073741824 */ static void do_info_balloon (Monitor *mon,QObject **ret_data) {
@@ -1906,7 +1912,7 @@ static void do_info_balloon(Monitor *mon, QObject **ret_data)else if (actual ==0 )qemu_error_new (QERR_DEVICE_NOT_ACTIVE ,"balloon" );else - *ret_data =QOBJECT (qint_from_int ((int )(actual >>20 ))); + *ret_data =QOBJECT (qint_from_int (actual)); }static qemu_acl *find_acl (Monitor *mon,const char *name)
Signature · 1 line
1.6.6.rc1.5.ge21a85
Re: [Qemu-devel] [PATCH 05/17] monitor: Fix do_info_balloon() output
Quoted 33 lines · Luiz Capitulino
New monitor commands should always return values in bytes.
Signed-off-by Luiz Capitulino <[email protected]>--- monitor.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)monitor.c +8
-2@@ -1889,12 +1889,18 @@ static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data)static void monitor_print_balloon (Monitor *mon,const QObject *data) { -monitor_printf (mon,"balloon: actual=%d\n" , - (int )qint_get_int (qobject_to_qint (data))); +monitor_printf (mon,"balloon: actual=%" PRId64"\n" , +qint_get_int (qobject_to_qint (data)) >>20 ); }/** * do_info_balloon(): Balloon information +* +* Return a QInt with current ballooning value. +* +* Example: +* +* 1073741824 */ static void do_info_balloon (Monitor *mon,QObject **ret_data) {
monitor.c static void do_info_balloon(Monitor *mon, QObject **ret_data) · line 1917
Quoted 7 lines
monitor.c +1
-1@@ -1906,7 +1912,7 @@ static void do_info_balloon(Monitor *mon, QObject **ret_data)else if (actual ==0 )qemu_error_new (QERR_DEVICE_NOT_ACTIVE ,"balloon" );else - *ret_data =QOBJECT (qint_from_int ((int )(actual >>20 ))); + *ret_data =QOBJECT (qint_from_int (actual)); }
Returning a dictionary would allow us to extend this information more easily.
Regards,
Anthony Liguori
PATCH v2 6/17 monitor: Convert do_info_status() to QObject
In reply to Luiz CapitulinoReturn a QString with status information.
--- monitor.c | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-)
monitor.c +27 -6
@@ -1865,16 +1865,36 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) }#endif -static void do_info_status (Monitor *mon) +static void do_info_status_print (Monitor *mon,const QObject *data) { +monitor_printf (mon,"VM status: %s\n" , +qstring_get_str (qobject_to_qstring (data))); +} + +/** +* do_info_status(): VM status +* +* Return a QString with status information, which can be: +* +* - "running" +* - "running (single step mode)" +* - "paused" +*/ +static void do_info_status (Monitor *mon,QObject **ret_data) +{ +QString *qs; +if (vm_running) {if (singlestep) { -monitor_printf (mon,"VM status: running (single step mode)\n" ); + qs =qstring_from_str ("running (single step mode)" ); }else { -monitor_printf (mon,"VM status: running\n" ); + qs =qstring_from_str ("running" ); } - }else -monitor_printf (mon,"VM status: paused\n" ); + }else { + qs =qstring_from_str ("paused" ); + } + + *ret_data =QOBJECT (qs); }/**
@@ -2317,7 +2337,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM status (running|paused)", - .mhandler.info = do_info_status, + .user_print = do_info_status_print, + .mhandler.info_new = do_info_status, }, { .name = "pcmcia",
Signature · 1 line
1.6.6.rc1.5.ge21a85
Re: [Qemu-devel] [PATCH 06/17] monitor: Convert do_info_status() to QObject
Quoted 42 lines · Luiz Capitulino
Return a QString with status information.
Signed-off-by Luiz Capitulino <[email protected]>--- monitor.c | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-)monitor.c +20
-3@@ -1865,16 +1865,36 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict) }#endif -static void do_info_status (Monitor *mon) +static void do_info_status_print (Monitor *mon,const QObject *data) { +monitor_printf (mon,"VM status: %s\n" , +qstring_get_str (qobject_to_qstring (data))); +} + +/** +* do_info_status(): VM status +* +* Return a QString with status information, which can be: +* +* - "running" +* - "running (single step mode)" +* - "paused" +*/ +static void do_info_status (Monitor *mon,QObject **ret_data) +{ +QString *qs; +if (vm_running) {if (singlestep) { -monitor_printf (mon,"VM status: running (single step mode)\n" ); + qs =qstring_from_str ("running (single step mode)" ); }else { -monitor_printf (mon,"VM status: running\n" ); + qs =qstring_from_str ("running" );
monitor.c static void do_inject_nmi(Monitor *mon, const QDict *qdict) · line 1899
Quoted 10 lines
monitor.c +5
-2} - }else -monitor_printf (mon,"VM status: paused\n" ); + }else { + qs =qstring_from_str ("paused" ); + } + + *ret_data =QOBJECT (qs); }
Wouldn't this be better as "{'running': true, 'single-step': false}"?
Please send an incremental patch.
Regards,
Anthony Liguori
PATCH v2 7/17 monitor: Convert do_info_kvm() to QObject
In reply to Luiz CapitulinoReturn a QString with kvm status information.
--- monitor.c | 31 +++++++++++++++++++++++++------ 1 files changed, 25 insertions(+), 6 deletions(-)
monitor.c +25 -6
@@ -1738,17 +1738,35 @@ static void tlb_info(Monitor *mon)#endif -static void do_info_kvm (Monitor *mon) +static void do_info_kvm_print (Monitor *mon,const QObject *data) { +monitor_printf (mon,"kvm support: %s\n" , +qstring_get_str (qobject_to_qstring (data))); +} + +/** +* do_info_kvm(): Show KVM information +* +* Return a QString with KVM information, which can be: +* +* - "enabled" +* - "disabled" +* - "not compiled" +*/ +static void do_info_kvm (Monitor *mon,QObject **ret_data) +{ +QString *qs; +#ifdef CONFIG_KVM -monitor_printf (mon,"kvm support: " );if (kvm_enabled ()) -monitor_printf (mon,"enabled\n" ); + qs =qstring_from_str ("enabled" );else -monitor_printf (mon,"disabled\n" ); + qs =qstring_from_str ("disabled" );#else -monitor_printf (mon,"kvm support: not compiled\n" ); + qs =qstring_from_str ("not compiled" );#endif + + *ret_data =QOBJECT (qs); }static void do_info_numa (Monitor *mon)
@@ -2288,7 +2306,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show KVM information", - .mhandler.info = do_info_kvm, + .user_print = do_info_kvm_print, + .mhandler.info_new = do_info_kvm, }, { .name = "numa",
Signature · 1 line
1.6.6.rc1.5.ge21a85
Re: [Qemu-devel] [PATCH 07/17] monitor: Convert do_info_kvm() to QObject
Quoted 42 lines · Luiz Capitulino
Return a QString with kvm status information.
Signed-off-by Luiz Capitulino <[email protected]>--- monitor.c | 31 +++++++++++++++++++++++++------ 1 files changed, 25 insertions(+), 6 deletions(-)monitor.c +19
-4@@ -1738,17 +1738,35 @@ static void tlb_info(Monitor *mon)#endif -static void do_info_kvm (Monitor *mon) +static void do_info_kvm_print (Monitor *mon,const QObject *data) { +monitor_printf (mon,"kvm support: %s\n" , +qstring_get_str (qobject_to_qstring (data))); +} + +/** +* do_info_kvm(): Show KVM information +* +* Return a QString with KVM information, which can be: +* +* - "enabled" +* - "disabled" +* - "not compiled" +*/ +static void do_info_kvm (Monitor *mon,QObject **ret_data) +{ +QString *qs; +#ifdef CONFIG_KVM -monitor_printf (mon,"kvm support: " );if (kvm_enabled ()) -monitor_printf (mon,"enabled\n" ); + qs =qstring_from_str ("enabled" );else -monitor_printf (mon,"disabled\n" );
monitor.c static void tlb_info(Monitor *mon) · line 1772
Quoted 10 lines
monitor.c +4
-1+ qs =qstring_from_str ("disabled" );#else -monitor_printf (mon,"kvm support: not compiled\n" ); + qs =qstring_from_str ("not compiled" );#endif + + *ret_data =QOBJECT (qs); }
"{'enabled': true, 'present': false}"
Using a dictionary here is important as then we can extend it with more information (like the supported KVM features).
Regards,
Anthony Liguori
PATCH v2 8/17 monitor: Convert do_info_name() to QObject
In reply to Luiz CapitulinoReturn a QString with the current VM name.
--- monitor.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
monitor.c +9 -3
@@ -507,10 +507,15 @@ static void do_info_version(Monitor *mon, QObject **ret_data) *ret_data = QOBJECT(qstring_from_str(QEMU_VERSION QEMU_PKGVERSION)); } -static void do_info_name (Monitor *mon) +/** +* do_info_name(): Show VM name +* +* Return a QString with the current VM name. +*/ +static void do_info_name (Monitor *mon,QObject **ret_data) {if (qemu_name) -monitor_printf (mon,"%s\n" , qemu_name); + *ret_data =QOBJECT (qstring_from_str (qemu_name)); }/**
@@ -2385,7 +2390,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM name", - .mhandler.info = do_info_name, + .user_print = monitor_print_qobject, + .mhandler.info_new = do_info_name, }, { .name = "uuid",
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 9/17 monitor: Convert do_info_hpet() to QObject
In reply to Luiz CapitulinoReturn a QString with HPET information.
--- monitor.c | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-)
monitor.c +21 -3
@@ -548,10 +548,27 @@ static void do_info_commands(Monitor *mon, QObject **ret_data) }#if defined(TARGET_I386 ) -static void do_info_hpet (Monitor *mon) +static void do_info_hpet_print (Monitor *mon,const QObject *data) {monitor_printf (mon,"HPET is %s by QEMU\n" , - (no_hpet) ?"disabled" :"enabled" ); +qstring_get_str (qobject_to_qstring (data))); +} + +/** +* do_info_hpet(): Show HPET state +* +* Return a QString with HPET information, which can be: +* +* - "enabled" +* - "disabled" +*/ +static void do_info_hpet (Monitor *mon,QObject **ret_data) +{ +if (no_hpet) { + *ret_data =QOBJECT (qstring_from_str ("disabled" )); + }else { + *ret_data =QOBJECT (qstring_from_str ("enabled" )); + } }#endif
@@ -2296,7 +2313,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show state of HPET", - .mhandler.info = do_info_hpet, + .user_print = do_info_hpet_print, + .mhandler.info_new = do_info_hpet, },#endif {
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 10/17 monitor: Convert do_info_uuid() to QObject
In reply to Luiz CapitulinoThe returned QObject is a QString, snprintf() is used because the UUID_FMT is too complex for qobject_from_jsonf().
--- monitor.c | 15 ++++++++++++--- 1 files changed, 12 insertions(+), 3 deletions(-)
monitor.c +12 -3
@@ -572,13 +572,21 @@ static void do_info_hpet(Monitor *mon, QObject **ret_data) }#endif -static void do_info_uuid (Monitor *mon) +/** +* do_info_uuid(): Show VM UUID +* +* Return a QString with the current VM UUID. +*/ +static void do_info_uuid (Monitor *mon,QObject **ret_data) { -monitor_printf (mon,UUID_FMT "\n" , qemu_uuid[0 ], qemu_uuid[1 ], +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 (qstring_from_str (uuid)); }/* get the current CPU defined by the user */
@@ -2416,7 +2424,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the current VM UUID", - .mhandler.info = do_info_uuid, + .user_print = monitor_print_qobject, + .mhandler.info_new = do_info_uuid, },#if defined(TARGET_PPC ) {
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 11/17 monitor: Convert do_info_mice() to QObject
In reply to Luiz CapitulinoEach mouse is represented by a QDict, the returned QObject is a QList of all mice.
This commit should not change user output.
--- console.h | 3 +- monitor.c | 3 +- vl.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 9 deletions(-)
console.h +2 -1
@@ -44,7 +44,8 @@ struct MouseTransformInfo {int a[7 ]; }; -void do_info_mice (Monitor *mon); +void do_info_mice_print (Monitor *mon,const QObject *data); +void do_info_mice (Monitor *mon,QObject **ret_data);void do_mouse_set (Monitor *mon,const QDict *qdict);/* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
monitor.c +2 -1
@@ -2402,7 +2402,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show which guest mouse is receiving events", - .mhandler.info = do_info_mice, + .user_print = do_info_mice_print, + .mhandler.info_new = do_info_mice, }, { .name = "vnc",
vl.c +55 -7
86 lines not on this page · raw message
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 12/17 migration: Convert do_info_migrate() to QObject
In reply to Luiz CapitulinoReturn a QDict, which may contain more two QDicts, depending on the type of migration we're performing.
IMPORTANT: as a QInt stores a int64_t integer, RAM values are going to be stored as int64_t and not as uint64_t as they are today. If this is a problem QInt will have to be changed.
This commit should not change user output.
--- migration.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++------- migration.h | 4 +- monitor.c | 3 +- 3 files changed, 108 insertions(+), 17 deletions(-)
migration.c +103 -15
@@ -19,6 +19,7 @@#include "block.h" #include "qemu_socket.h" #include "block-migration.h" +#include "qemu-objects.h" //#define DEBUG_MIGRATION
@@ -163,37 +164,124 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict) max_downtime = (uint64_t )d; } -void do_info_migrate (Monitor *mon) +static void migrate_print_status (Monitor *mon,const char *name, +const QDict *status_dict) { +QDict *qdict; + + qdict =qobject_to_qdict (qdict_get (status_dict, name)); + +monitor_printf (mon,"transferred %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"transferred" ) >>10 ); +monitor_printf (mon,"remaining %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"remaining" ) >>10 ); +monitor_printf (mon,"total %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"total" ) >>10 ); +} + +void do_info_migrate_print (Monitor *mon,const QObject *data) +{ +QDict *qdict; + + qdict =qobject_to_qdict (data); + +monitor_printf (mon,"Migration status: %s\n" , +qdict_get_str (qdict,"status" )); + +if (qdict_haskey (qdict,"ram" )) { +migrate_print_status (mon,"ram" , qdict); + } + +if (qdict_haskey (qdict,"disk" )) { +migrate_print_status (mon,"disk" , qdict); + } +} + +static void migrate_put_status (QDict *qdict,const char *name, +uint64_t trans,uint64_t rem,uint64_t total) +{ +QObject *obj; + + obj =qobject_from_jsonf ("{ 'transferred': %" PRId64", " +"'remaining': %" PRId64", " +"'total': %" PRId64" }" , trans >>10 , + rem >>10 , total >>10 ); +assert (obj !=NULL ); + +qdict_put_obj (qdict, name, obj); +} + +/** +* do_info_migrate(): Migration status +* +* Return a QDict. If migration is active there will be another +* QDict with RAM migration status and if block migration is active +* another one with block migration status. +* +* The main QDict contains the following: +* +* - "status": migration status +* - "ram": only present if "status" is "active", it is a QDict with the +* following RAM information (in bytes): +* - "transferred": amount transferred +* - "remaining": amount remaining +* - "total": total +* - "disk": only present if it is a block migration, it is a QDict with +* the following disk information (in bytes): +* - "transferred": amount transferred +* - "remaining": amount remaining +* - "total": total +* +* Examples: +* +* 1. Migration is "completed": +* +* { "status": "completed" } +* +* 2. Migration is "active" and it is not a block migration: +* +* { "status": "active", +* "ram": { "transferred": 123, "remaining": 123, "total": 246 } } +* +* 3. Migration is "active" and it is a block migration: +* +* { "status": "active", +* "ram": { "total": 1057024, "remaining": 1053304, "transferred": 3720 }, +* "disk": { "total": 20971520, "remaining": 20880384, "transferred": 91136 }} +*/ +void do_info_migrate (Monitor *mon,QObject **ret_data) +{ +QDict *qdict;MigrationState *s = current_migration;if (s) { -monitor_printf (mon,"Migration status: " );switch (s->get_status (s)) {case MIG_STATE_ACTIVE : -monitor_printf (mon,"active\n" ); -monitor_printf (mon,"transferred ram: %" PRIu64" kbytes\n" ,ram_bytes_transferred () >>10 ); -monitor_printf (mon,"remaining ram: %" PRIu64" kbytes\n" ,ram_bytes_remaining () >>10 ); -monitor_printf (mon,"total ram: %" PRIu64" kbytes\n" ,ram_bytes_total () >>10 ); + qdict =qdict_new (); +qdict_put (qdict,"status" ,qstring_from_str ("active" )); + +migrate_put_status (qdict,"ram" ,ram_bytes_transferred (), +ram_bytes_remaining (),ram_bytes_total ()); +if (blk_mig_active ()) { -monitor_printf (mon,"transferred disk: %" PRIu64" kbytes\n" , -blk_mig_bytes_transferred () >>10 ); -monitor_printf (mon,"remaining disk: %" PRIu64" kbytes\n" , -blk_mig_bytes_remaining () >>10 ); -monitor_printf (mon,"total disk: %" PRIu64" kbytes\n" , -blk_mig_bytes_total () >>10 ); +migrate_put_status (qdict,"disk" ,blk_mig_bytes_transferred (), +blk_mig_bytes_remaining (), +blk_mig_bytes_total ()); } + + *ret_data =QOBJECT (qdict);break ;case MIG_STATE_COMPLETED : -monitor_printf (mon,"completed\n" ); + *ret_data =qobject_from_jsonf ("{ 'status': 'completed' }" );break ;case MIG_STATE_ERROR : -monitor_printf (mon,"failed\n" ); + *ret_data =qobject_from_jsonf ("{ 'status': 'failed' }" );break ;case MIG_STATE_CANCELLED : -monitor_printf (mon,"cancelled\n" ); + *ret_data =qobject_from_jsonf ("{ 'status': 'cancelled' }" );break ; } +assert (*ret_data !=NULL ); } }
migration.h +3 -1
@@ -62,7 +62,9 @@ uint64_t migrate_max_downtime(void);void do_migrate_set_downtime (Monitor *mon,const QDict *qdict); -void do_info_migrate (Monitor *mon); +void do_info_migrate_print (Monitor *mon,const QObject *data); + +void do_info_migrate (Monitor *mon,QObject **ret_data);int exec_start_incoming_migration (const char *host_port);
monitor.c +2 -1
@@ -2451,7 +2451,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show migration status", - .mhandler.info = do_info_migrate, + .user_print = do_info_migrate_print, + .mhandler.info_new = do_info_migrate, }, { .name = "balloon",
Signature · 1 line
1.6.6.rc1.5.ge21a85
Re: [Qemu-devel] [PATCH 12/17] migration: Convert do_info_migrate() to QObject
Quoted 83 lines · Luiz Capitulino
Return a QDict, which may contain more two QDicts, depending on the type of migration we're performing.
IMPORTANT: as a QInt stores a
int64_tinteger, RAM values are going to be stored asint64_tand not asuint64_tas they are today. If this is a problem QInt will have to be changed.This commit should not change user output.
Signed-off-by Luiz Capitulino <[email protected]>--- migration.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++------- migration.h | 4 +- monitor.c | 3 +- 3 files changed, 108 insertions(+), 17 deletions(-)migration.c +50
-1@@ -19,6 +19,7 @@#include "block.h" #include "qemu_socket.h" #include "block-migration.h" +#include "qemu-objects.h" //#define DEBUG_MIGRATION @@ -163,37 +164,124 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict) max_downtime = (uint64_t )d; } -void do_info_migrate (Monitor *mon) +static void migrate_print_status (Monitor *mon,const char *name, +const QDict *status_dict) { +QDict *qdict; + + qdict =qobject_to_qdict (qdict_get (status_dict, name)); + +monitor_printf (mon,"transferred %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"transferred" ) >>10 ); +monitor_printf (mon,"remaining %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"remaining" ) >>10 ); +monitor_printf (mon,"total %s: %" PRIu64" kbytes\n" , name, +qdict_get_int (qdict,"total" ) >>10 ); +} + +void do_info_migrate_print (Monitor *mon,const QObject *data) +{ +QDict *qdict; + + qdict =qobject_to_qdict (data); + +monitor_printf (mon,"Migration status: %s\n" , +qdict_get_str (qdict,"status" )); + +if (qdict_haskey (qdict,"ram" )) { +migrate_print_status (mon,"ram" , qdict); + } + +if (qdict_haskey (qdict,"disk" )) { +migrate_print_status (mon,"disk" , qdict); + } +} + +static void migrate_put_status (QDict *qdict,const char *name, +uint64_t trans,uint64_t rem,uint64_t total) +{ +QObject *obj; + + obj =qobject_from_jsonf ("{ 'transferred': %" PRId64", " +"'remaining': %" PRId64", " +"'total': %" PRId64" }" , trans >>10 , + rem >>10 , total >>10 ); +assert (obj !=NULL ); + +qdict_put_obj (qdict, name, obj); +} + +/** +* do_info_migrate(): Migration status +*
migration.c void do_migrate_set_downtime(Monitor *mon, const QDict *qdict) · line 226
Quoted 10 lines
migration.c +9
-0+* Return a QDict. If migration is active there will be another +* QDict with RAM migration status and if block migration is active +* another one with block migration status. +* +* The main QDict contains the following: +* +* - "status": migration status +* - "ram": only present if "status" is "active", it is a QDict with the +* following RAM information (in bytes):
The implementation in migrate_put_status disagrees with your documentation.
Regards,
Anthony Liguori
PATCH v2 13/17 block: Convert bdrv_info() to QObject
In reply to Luiz CapitulinoEach block device information is stored in a QDict and the returned QObject is a QList of all devices.
This commit should not change user output.
--- Makefile | 6 +- block.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- block.h | 4 +- monitor.c | 3 +- 4 files changed, 111 insertions(+), 25 deletions(-)
Makefile +3 -3
@@ -235,11 +235,11 @@ libqemu_common.a: $(obj-y) qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o qemu-tool.o $(block-obj-y) +qemu-img$(EXESUF): qemu-img.o qemu-tool.o $(block-obj-y) $(qobject-obj-y) -qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o $(block-obj-y) +qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o $(block-obj-y) $(qobject-obj-y) -qemu-io$(EXESUF): qemu-io.o qemu-tool.o cmd.o $(block-obj-y) +qemu-io$(EXESUF): qemu-io.o qemu-tool.o cmd.o $(block-obj-y) $(qobject-obj-y) qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@")
block.c +103 -20
152 lines not on this page · raw message
block.h +3 -1
@@ -4,6 +4,7 @@#include "qemu-aio.h" #include "qemu-common.h" #include "qemu-option.h" +#include "qobject.h" /* block.c */ typedef struct BlockDriver BlockDriver ;
@@ -45,7 +46,8 @@ typedef struct QEMUSnapshotInfo {#define BDRV_SECTOR_SIZE (1 << BDRV_SECTOR_BITS)#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1); -void bdrv_info (Monitor *mon); +void bdrv_info_print (Monitor *mon,const QObject *data); +void bdrv_info (Monitor *mon,QObject **ret_data);void bdrv_info_stats (Monitor *mon);void bdrv_init (void );
monitor.c +2 -1
@@ -2247,7 +2247,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the block devices", - .mhandler.info = bdrv_info, + .user_print = bdrv_info_print, + .mhandler.info_new = bdrv_info, }, { .name = "blockstats",
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 14/17 block: Convert bdrv_info_stats() to QObject
In reply to Luiz CapitulinoEach device statistic information is stored in a QDict and the returned QObject is a QList of all devices.
This commit should not change user output.
--- block.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------- block.h | 3 +- monitor.c | 3 +- 3 files changed, 75 insertions(+), 13 deletions(-)
block.c +72 -12
@@ -1261,22 +1261,82 @@ void bdrv_info(Monitor *mon, QObject **ret_data) *ret_data =QOBJECT (bs_list); } -/* The "info blockstats" command. */ -void bdrv_info_stats (Monitor *mon) +static void bdrv_stats_iter (QObject *data,void *opaque) { +QDict *qdict; +Monitor *mon = opaque; + + qdict =qobject_to_qdict (data); +monitor_printf (mon,"%s:" ,qdict_get_str (qdict,"device" )); + + qdict =qobject_to_qdict (qdict_get (qdict,"stats" )); +monitor_printf (mon," rd_bytes=%" PRId64 +" wr_bytes=%" PRId64 +" rd_operations=%" PRId64 +" wr_operations=%" PRId64 +"\n" , +qdict_get_int (qdict,"rd_bytes" ), +qdict_get_int (qdict,"wr_bytes" ), +qdict_get_int (qdict,"rd_operations" ), +qdict_get_int (qdict,"wr_operations" )); +} + +void bdrv_stats_print (Monitor *mon,const QObject *data) +{ +qlist_iter (qobject_to_qlist (data), bdrv_stats_iter, mon); +} + +/** +* bdrv_info_stats(): show block device statistics +* +* Each device statistic information is stored in a QDict and +* the returned QObject is a QList of all devices. +* +* The QDict contains the following: +* +* - "device": device name +* - "stats": QDict with the stats information, contains: +* - "rd_bytes": bytes read +* - "wr_bytes": bytes written +* - "rd_operations": read operations +* - "wr_operations": write operations +* +* Example: +* +* [ { "device": "ide0-hd0", +* "stats": { "rd_bytes": 512, +* "wr_bytes": 0, +* "rd_operations": 1, +* "wr_operations": 0 } }, +* { "device": "ide1-cd0", +* "stats": { "rd_bytes": 0, +* "wr_bytes": 0, +* "rd_operations": 0, +* "wr_operations": 0 } } ] +*/ +void bdrv_info_stats (Monitor *mon,QObject **ret_data) +{ +QObject *obj; +QList *devices;BlockDriverState *bs; + devices =qlist_new (); +for (bs = bdrv_first; bs !=NULL ; bs = bs->next) { -monitor_printf (mon,"%s:" -" rd_bytes=%" PRIu64 -" wr_bytes=%" PRIu64 -" rd_operations=%" PRIu64 -" wr_operations=%" PRIu64 -"\n" , - bs->device_name, - bs->rd_bytes, bs->wr_bytes, - bs->rd_ops, bs->wr_ops); - } + obj =qobject_from_jsonf ("{ 'device': %s, 'stats': {" +"'rd_bytes': %" PRId64"," +"'wr_bytes': %" PRId64"," +"'rd_operations': %" PRId64"," +"'wr_operations': %" PRId64 +"} }" , + bs->device_name, + bs->rd_bytes, bs->wr_bytes, + bs->rd_ops, bs->wr_ops); +assert (obj !=NULL ); +qlist_append_obj (devices, obj); + } + + *ret_data =QOBJECT (devices); }const char *bdrv_get_encrypted_filename (BlockDriverState *bs)
block.h +2 -1
@@ -48,7 +48,8 @@ typedef struct QEMUSnapshotInfo {void bdrv_info_print (Monitor *mon,const QObject *data);void bdrv_info (Monitor *mon,QObject **ret_data); -void bdrv_info_stats (Monitor *mon); +void bdrv_stats_print (Monitor *mon,const QObject *data); +void bdrv_info_stats (Monitor *mon,QObject **ret_data);void bdrv_init (void );void bdrv_init_with_whitelist (void );
monitor.c +2 -1
@@ -2255,7 +2255,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show block device statistics", - .mhandler.info = bdrv_info_stats, + .user_print = bdrv_stats_print, + .mhandler.info_new = bdrv_info_stats, }, { .name = "registers",
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 15/17 char: Convert qemu_chr_info() to QObject
In reply to Luiz CapitulinoEach device is represented by a QDict. The returned QObject is a QList of all devices.
This commit should not change user output.
--- monitor.c | 3 ++- qemu-char.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qemu-char.h | 4 +++- 3 files changed, 46 insertions(+), 4 deletions(-)
monitor.c +2 -1
@@ -2240,7 +2240,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the character devices", - .mhandler.info = qemu_chr_info, + .user_print = qemu_chr_info_print, + .mhandler.info_new = qemu_chr_info, }, { .name = "block",
qemu-char.c +41 -2
60 lines not on this page · raw message
qemu-char.h +3 -1
@@ -5,6 +5,7 @@#include "qemu-queue.h" #include "qemu-option.h" #include "qemu-config.h" +#include "qobject.h" /* character device */
@@ -87,7 +88,8 @@ int qemu_chr_can_read(CharDriverState *s);void qemu_chr_read (CharDriverState *s,uint8_t *buf,int len);int qemu_chr_get_msgfd (CharDriverState *s);void qemu_chr_accept_input (CharDriverState *s); -void qemu_chr_info (Monitor *mon); +void qemu_chr_info_print (Monitor *mon,const QObject *ret_data); +void qemu_chr_info (Monitor *mon,QObject **ret_data);CharDriverState *qemu_chr_find (const char *name);extern int term_escape_char;
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 16/17 PCI: Convert pci_device_hot_add() to QObject
In reply to Luiz CapitulinoReturn a QDict with information about the just added device.
This commit should not change user output.
Please, note that this patch does not do error handling conversion. In error conditions the handler still calls monitor_printf().
--- hw/pci-hotplug.c | 40 ++++++++++++++++++++++++++++++++++++---- qemu-monitor.hx | 3 ++- sysemu.h | 3 ++- 3 files changed, 40 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +36 -4
@@ -33,6 +33,7 @@#include "scsi.h" #include "virtio-blk.h" #include "qemu-config.h" +#include "qemu-objects.h" #if defined(TARGET_I386 ) static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
@@ -212,7 +213,36 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,return dev; } -void pci_device_hot_add (Monitor *mon,const QDict *qdict) +void pci_device_hot_add_print (Monitor *mon,const QObject *data) +{ +QDict *qdict; + +assert (qobject_type (data) ==QTYPE_QDICT ); + qdict =qobject_to_qdict (data); + +monitor_printf (mon,"OK domain %d, bus %d, slot %d, function %d\n" , + (int )qdict_get_int (qdict,"domain" ), + (int )qdict_get_int (qdict,"bus" ), + (int )qdict_get_int (qdict,"slot" ), + (int )qdict_get_int (qdict,"function" )); + +} + +/** +* pci_device_hot_add(): Hot add PCI device +* +* Return a QDict with the following device information: +* +* - "domain": domain number +* - "bus": bus number +* - "slot": slot number +* - "function": function number +* +* Example: +* +* { "domain": 0, "bus": 0, "slot": 5, "function": 0 } +*/ +void pci_device_hot_add (Monitor *mon,const QDict *qdict,QObject **ret_data) {PCIDevice *dev =NULL ;const char *pci_addr =qdict_get_str (qdict,"pci_addr" );
@@ -239,9 +269,11 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)monitor_printf (mon,"invalid type: %s\n" , type);if (dev) { -monitor_printf (mon,"OK domain %d, bus %d, slot %d, function %d\n" , -0 ,pci_bus_num (dev->bus),PCI_SLOT (dev->devfn), -PCI_FUNC (dev->devfn)); + *ret_data = +qobject_from_jsonf ("{ 'domain': 0, 'bus': %d, 'slot': %d, " +"'function': %d }" ,pci_bus_num (dev->bus), +PCI_SLOT (dev->devfn),PCI_FUNC (dev->devfn)); +assert (*ret_data !=NULL ); }else monitor_printf (mon,"failed to add %s\n" , opts); }
qemu-monitor.hx +2 -1
@@ -809,7 +809,8 @@ ETEXI .args_type = "pci_addr:s,type:s,opts:s?", .params = "auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", .help = "hot-add PCI device", - .mhandler.cmd = pci_device_hot_add, + .user_print = pci_device_hot_add_print, + .mhandler.cmd_new = pci_device_hot_add, }, #endif
sysemu.h +2 -1
@@ -212,7 +212,8 @@ extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);DriveInfo *add_init_drive (const char *opts);/* pci-hotplug */ -void pci_device_hot_add (Monitor *mon,const QDict *qdict); +void pci_device_hot_add_print (Monitor *mon,const QObject *data); +void pci_device_hot_add (Monitor *mon,const QDict *qdict,QObject **ret_data);void drive_hot_add (Monitor *mon,const QDict *qdict);void pci_device_hot_remove (Monitor *mon,const char *pci_addr); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict,
Signature · 1 line
1.6.6.rc1.5.ge21a85
PATCH v2 17/17 VNC: Convert do_info_vnc() to QObject
In reply to Luiz CapitulinoReturn a QDict with server information. Connected clients are returned as a QList of QDicts.
The new functions (vnc_qdict_remote_addr(), vnc_qdict_local_addr() and put_addr_qdict()) are used to insert 'host' and 'service' information in the returned QDict.
This patch is big, but I don't see how to split it.
--- console.h | 3 +- monitor.c | 3 +- vnc.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 165 insertions(+), 33 deletions(-)
console.h +2 -1
@@ -323,7 +323,8 @@ void vnc_display_init(DisplayState *ds);void vnc_display_close (DisplayState *ds);int vnc_display_open (DisplayState *ds,const char *display);int vnc_display_password (DisplayState *ds,const char *password); -void do_info_vnc (Monitor *mon); +void do_info_vnc_print (Monitor *mon,const QObject *data); +void do_info_vnc (Monitor *mon,QObject **ret_data);char *vnc_display_local_addr (DisplayState *ds);/* curses.c */
monitor.c +2 -1
@@ -2413,7 +2413,8 @@ static const mon_cmd_t info_cmds[] = { .args_type = "", .params = "", .help = "show the vnc server status", - .mhandler.info = do_info_vnc, + .user_print = do_info_vnc_print, + .mhandler.info_new = do_info_vnc, }, { .name = "name",
vnc.c +161 -31
231 lines not on this page · raw message
Signature · 1 line
1.6.6.rc1.5.ge21a85