Skip to contentSkip to conversation

: info handlers conversions to QObject

PATCH In review Luiz Capitulino 3 participants 29 messages Nov 17, 2009 – Nov 30, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

cover : info handlers conversions to QObject

Hi,

Now that qjson has been merged, it's time to flush my queues..

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.

Detailed conversion status can be found at:

http://www.linux-kvm.org/page/MonitorProtocol

Thanks.

#1 lore raw

PATCH 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
new file mode 100644
index 0000000..e1d1e0c
@@ -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.5.2.180.gc5b3e
#2 lore raw

PATCH 2/17 Makefile: move QObject objs to their own entry

In reply to Luiz Capitulino

Other subsystems will need to link against them.

---
 Makefile |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
Makefile +6 -2
index d770e2a..dd48a35 100644
@@ -72,6 +72,11 @@ 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
+
+#######################################################################
 # 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
@@ -106,6 +111,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
@@ -137,8 +143,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
 obj-y += qemu-config.o block-migration.o
 
 obj-$(CONFIG_BRLAPI) += baum.o
Signature · 1 line
1.6.5.2.180.gc5b3e
#3 lore raw

PATCH 3/17 QDict: Introduce qdict_get_qbool()

In reply to Luiz Capitulino

This 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
index dd48a35..fa41ac9 100644
@@ -232,7 +232,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
index 0e04cb1..45e08be 100644
@@ -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
index 14b2633..1473c04 100644
@@ -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.5.2.180.gc5b3e
#4 lore raw

PATCH 4/17 QDict: Introduce qdict_get_qlist()

In reply to Luiz Capitulino

A 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
index fa41ac9..6be75a1 100644
@@ -232,7 +232,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
index 45e08be..ef73265 100644
@@ -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
index 1473c04..5fef1ea 100644
@@ -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.5.2.180.gc5b3e
#5 lore raw

PATCH 5/17 monitor: Convert do_info_status() to QObject

In reply to Luiz Capitulino

Return a QString with status information.

---
 monitor.c |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)
monitor.c +27 -6
index 3286ba2..72de320 100644
@@ -1678,16 +1678,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);
 }
 
 /**
@@ -2117,7 +2137,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.5.2.180.gc5b3e
#6 lore raw

PATCH 6/17 monitor: Convert do_info_kvm() to QObject

In reply to Luiz Capitulino

The returned QObject is a QString with kvm status information.

---
 monitor.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)
monitor.c +25 -6
index 72de320..1a37be3 100644
@@ -1551,17 +1551,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)
@@ -2088,7 +2106,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.5.2.180.gc5b3e
#7 lore raw

PATCH 7/17 monitor: Convert do_info_name() to QObject

In reply to Luiz Capitulino

The returned QObject is a QString.

---
 monitor.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
monitor.c +9 -3
index 1a37be3..5140198 100644
@@ -349,10 +349,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));
 }
 
 #if defined(TARGET_I386)
@@ -2185,7 +2190,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.5.2.180.gc5b3e
#8 lore raw

PATCH 8/17 monitor: Convert do_info_hpet() to QObject

In reply to Luiz Capitulino

The returned QObject is a QString.

---
 monitor.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
monitor.c +21 -3
index 5140198..9ecf5ff 100644
@@ -361,10 +361,27 @@ static void do_info_name(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
 
@@ -2096,7 +2113,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.5.2.180.gc5b3e
#9 lore raw

PATCH 9/17 monitor: Convert do_info_uuid() to QObject

In reply to Luiz Capitulino

The 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
index 9ecf5ff..c86c7a5 100644
@@ -385,13 +385,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 */
@@ -2216,7 +2224,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.5.2.180.gc5b3e
#10 lore raw

Re: [Qemu-devel] [PATCH 09/17] monitor: Convert do_info_uuid() to QObject

Quoted 2 lines · Luiz Capitulino

The returned QObject is a QString, snprintf() is used because the UUID_FMT is too complex for qobject_from_jsonf().

If this turns out to be a common problem, we should consider fixing it at the source: qobject_from_jsonf().

#11 lore raw

PATCH 10/17 migration: Convert do_info_migrate() to QObject

In reply to Luiz Capitulino

Return a QDict, which may contain another QDict if the migration process is active.

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 |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 migration.h |    4 ++-
 monitor.c   |    3 +-
 3 files changed, 57 insertions(+), 11 deletions(-)
migration.c +52 -9
index 3ae0be8..a01adc0 100644
@@ -18,6 +18,7 @@
 #include "sysemu.h"
 #include "block.h"
 #include "qemu_socket.h"
+#include "qemu-objects.h"
 
 //#define DEBUG_MIGRATION
 
@@ -157,29 +158,71 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict)
     max_downtime = (uint64_t)d;
 }
 
-void do_info_migrate(Monitor *mon)
+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")) {
+        QDict *qdict_ram = qobject_to_qdict(qdict_get(qdict, "ram"));
+        monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
+                       qdict_get_int(qdict_ram, "transferred") >> 10);
+        monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
+                       qdict_get_int(qdict_ram, "remaining") >> 10);
+        monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
+                       qdict_get_int(qdict_ram, "total") >> 10);
+    }
+}
+
+/**
+ * do_info_migrate(): Migration status
+ *
+ * Return a QDict. If migration is active there will be another
+ * QDict with RAM information.
+ *
+ * The main QDict contains the following:
+ *
+ * - "status": migration status
+ * - "ram": only present if "status" is "active", it is a QDict with the
+ *   following information (in bytes):
+ *          - "transferred": amount of RAM transferred
+ *          - "remaining": amount of RAM remaining
+ *          - "total": total RAM
+ *
+ * Examples:
+ *
+ * 1. If migration is "completed":
+ *
+ * { "status": "completed" }
+ *
+ * 2. If migration is "active":
+ *
+ * { "status": "active", "ram":
+ *             { "transferred": 123, "remaining": 123, "total": 246 } }
+ */
+void do_info_migrate(Monitor *mon, QObject **ret_data)
 {
     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);
+            *ret_data = qobject_from_jsonf("{ 'status': 'active', 'ram': { 'transferred': %" PRId64 ", 'remaining': %" PRId64 ", 'total': %" PRId64 "} }", ram_bytes_transferred(), ram_bytes_remaining(), ram_bytes_total());
             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
index 56adf05..08c3dcc 100644
@@ -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
index c86c7a5..1528f08 100644
@@ -2250,7 +2250,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.5.2.180.gc5b3e
#12 lore raw

PATCH 11/17 block: Convert bdrv_info() to QObject

In reply to Luiz Capitulino

Each 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  |    2 +-
 block.c   |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 block.h   |    4 +-
 monitor.c |    3 +-
 4 files changed, 109 insertions(+), 23 deletions(-)
Makefile +1 -1
index 6be75a1..3424cdb 100644
@@ -80,7 +80,7 @@ qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.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
-block-obj-y += nbd.o block.o aio.o aes.o osdep.o
+block-obj-y += nbd.o block.o aio.o aes.o osdep.o $(qobject-obj-y)
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
block.c +103 -20

152 lines not on this page · raw message

block.h +3 -1
index 2d4f066..3ca7112 100644
@@ -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;
@@ -41,7 +42,8 @@ typedef struct QEMUSnapshotInfo {
 
 #define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
 
-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
index 1528f08..e4fed10 100644
@@ -2047,7 +2047,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.5.2.180.gc5b3e
#13 lore raw

Re: [Qemu-devel] [PATCH 11/17] block: Convert bdrv_info() to QObject

Quoted 18 lines · Luiz Capitulino

Each 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  |    2 +-
 block.c   |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 block.h   |    4 +-
 monitor.c |    3 +-
 4 files changed, 109 insertions(+), 23 deletions(-)
Makefile +0 -0
index 6be75a1..3424cdb 100644

Makefile qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o · line 86

Quoted 8 lines
Makefile +1 -1
@@ -80,7 +80,7 @@ qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.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
-block-obj-y += nbd.o block.o aio.o aes.o osdep.o
+block-obj-y += nbd.o block.o aio.o aes.o osdep.o $(qobject-obj-y)
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 

Both $(block-obj-y) and $(qobject-obj-y) go into obj-y, which thus list all the $(qobject-obj-y) objects twice. Sure that's okay?

Quoted 21 lines
block.c +4 -1
index 6fdabff..fc4e2f2 100644
@@ -26,6 +26,7 @@
 #include "monitor.h"
 #include "block_int.h"
 #include "module.h"
+#include "qemu-objects.h"
 
 #ifdef CONFIG_BSD
 #include <sys/types.h>
@@ -1133,43 +1134,125 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
 }
 
-void bdrv_info(Monitor *mon)
+static void bdrv_print_dict(QObject *obj, void *opaque)
 {
+    QDict *bs_dict;
+    Monitor *mon = opaque;

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1150

Quoted 10 lines
block.c +10 -0
+
+    bs_dict = qobject_to_qdict(obj);
+
+    monitor_printf(mon, "%s: type=%s removable=%d",
+                        qdict_get_str(bs_dict, "device"),
+                        qdict_get_str(bs_dict, "type"),
+                        qdict_get_bool(bs_dict, "removable"));
+
+    if (qdict_get_bool(bs_dict, "removable")) {
+        monitor_printf(mon, " locked=%d", (int)qdict_get_bool(bs_dict, "locked"));

qdict_get_bool() returns int, no need to cast.

Quoted 29 lines
block.c +29 -0
+    }
+
+    if (qdict_haskey(bs_dict, "inserted")) {
+        QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
+
+        monitor_printf(mon, " file=");
+        monitor_print_filename(mon, qdict_get_str(qdict, "file"));
+        if (qdict_haskey(qdict, "backing_file")) {
+            monitor_printf(mon, " backing_file=");
+            monitor_print_filename(mon, qdict_get_str(qdict, "backing_file"));
+        }
+        monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
+                            qdict_get_bool(qdict, "ro"),
+                            qdict_get_str(qdict, "drv"),
+                            qdict_get_bool(qdict, "encrypted"));
+    } else {
+        monitor_printf(mon, " [not inserted]");
+    }
+
+    monitor_printf(mon, "\n");
+}
+
+void bdrv_info_print(Monitor *mon, const QObject *data)
+{
+    qlist_iter(qobject_to_qlist(data), bdrv_print_dict, mon);
+}
+
+/**
+ * bdrv_info(): Block devices information

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1189

Quoted 10 lines
block.c +10 -0
+ *
+ * Each block device information is stored in a QDict and the
+ * returned QObject is a QList of all devices.
+ *
+ * The QDict contains the following:
+ *
+ * - "device": device name
+ * - "type": device type
+ * - "removable": 1 if the device is removable 0 otherwise
+ * - "locked": 1 if the device is locked 0 otherwise

Use above and example below suggest that "locked" is only present if device is removable. Document?

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1201

Quoted 12 lines
block.c +12 -0
+ * - "inserted": only present if the device is inserted, it is a QDict
+ *    containing the following:
+ *          - "file": device file name
+ *          - "ro": 1 if read-only 0 otherwise
+ *          - "drv": driver format name
+ *          - "backing_file": backing file name if one is used
+ *          - "encrypted":  1 if encrypted 0 otherwise
+ *
+ * Example:
+ *
+ * [ { "device": "ide0-hd0", "type": "hd", "removable": 0,
+ *     "file": "/tmp/foobar", "ro": 0, "drv": "qcow2", "encrypted": 0 }

Shouldn't "file" & friends ne in nested dictionary "inserted"?

Quoted 20 lines
block.c +12 -3
+ *   { "device": "floppy0", "type": "floppy", "removable": 1,
+ *     "locked": 0 } ]
+ */
+void bdrv_info(Monitor *mon, QObject **ret_data)
+{
+    QList *bs_list;
     BlockDriverState *bs;
 
+    bs_list = qlist_new();
+
     for (bs = bdrv_first; bs != NULL; bs = bs->next) {
-        monitor_printf(mon, "%s:", bs->device_name);
-        monitor_printf(mon, " type=");
+        QObject *bs_obj;
+        const char *type = "unknown";
+
         switch(bs->type) {
         case BDRV_TYPE_HD:
-            monitor_printf(mon, "hd");
+            type = "hd";

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1226

Quoted 10 lines
block.c +2 -2
             break;
         case BDRV_TYPE_CDROM:
-            monitor_printf(mon, "cdrom");
+            type = "cdrom";
             break;
         case BDRV_TYPE_FLOPPY:
-            monitor_printf(mon, "floppy");
+            type = "floppy";
             break;
         }

This changes human-readable output for bad bs->type from "type=" to "type=unknown". Fine with me.

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1232

Quoted 10 lines
block.c +6 -4
-        monitor_printf(mon, " removable=%d", bs->removable);
-        if (bs->removable) {
-            monitor_printf(mon, " locked=%d", bs->locked);
-        }
+
+        bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
+                                    "'removable': %i, 'locked': %i }",
+                                    bs->device_name, type, bs->removable,
+                                    bs->locked);
+        assert(bs_obj != NULL);

Failure modes of qobject_from_jsonf()? I'm asking because depending on the answer assert() may not be appropriate here.

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1243

Quoted 13 lines
block.c +10 -2
+
         if (bs->drv) {
-            monitor_printf(mon, " file=");
-            monitor_print_filename(mon, bs->filename);
+            QObject *obj;
+            QDict *bs_dict = qobject_to_qdict(bs_obj);
+
+            obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
+                                     "'encrypted': %i }",
+                                     bs->filename, bs->read_only,
+                                     bs->drv->format_name,
+                                     bdrv_is_encrypted(bs));
+            assert(obj != NULL);

Ditto.

Quoted 59 lines
block.c +8 -8
             if (bs->backing_file[0] != '\0') {
-                monitor_printf(mon, " backing_file=");
-                monitor_print_filename(mon, bs->backing_file);
+                QDict *qdict = qobject_to_qdict(obj);
+                qdict_put(qdict, "backing_file",
+                          qstring_from_str(bs->backing_file));
             }
-            monitor_printf(mon, " ro=%d", bs->read_only);
-            monitor_printf(mon, " drv=%s", bs->drv->format_name);
-            monitor_printf(mon, " encrypted=%d", bdrv_is_encrypted(bs));
-        } else {
-            monitor_printf(mon, " [not inserted]");
+
+            qdict_put_obj(bs_dict, "inserted", obj);
         }
-        monitor_printf(mon, "\n");
+        qlist_append_obj(bs_list, bs_obj);
     }
+
+    *ret_data = QOBJECT(bs_list);
 }
 
 /* The "info blockstats" command. */
block.h +3 -1
index 2d4f066..3ca7112 100644
@@ -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;
@@ -41,7 +42,8 @@ typedef struct QEMUSnapshotInfo {
 
 #define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
 
-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
index 1528f08..e4fed10 100644
@@ -2047,7 +2047,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",
#14 lore raw

Re: [Qemu-devel] [PATCH 11/17] block: Convert bdrv_info() to QObject

Quoted 22 lines · On Fri, 20 Nov 2009 15:06:26 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 20 lines · Luiz Capitulino

Each 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  |    2 +-
 block.c   |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 block.h   |    4 +-
 monitor.c |    3 +-
 4 files changed, 109 insertions(+), 23 deletions(-)
Makefile +0 -0
index 6be75a1..3424cdb 100644
@@ -80,7 +80,7 @@ qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
 # block-obj-y is code used by both qemu system emulation and qemu-img
 
Quoted 9 lines

Makefile qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o · line 86

Quoted 6 lines
Makefile +1 -1
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
-block-obj-y += nbd.o block.o aio.o aes.o osdep.o
+block-obj-y += nbd.o block.o aio.o aes.o osdep.o $(qobject-obj-y)
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 

Both $(block-obj-y) and $(qobject-obj-y) go into obj-y, which thus list all the $(qobject-obj-y) objects twice. Sure that's okay?

$(qobject-obj-y) is a dependency of qemu- block tools, it can be moved
there then.

Quoted 25 lines
Quoted 25 lines
block.c +8 -1
index 6fdabff..fc4e2f2 100644
@@ -26,6 +26,7 @@
 #include "monitor.h"
 #include "block_int.h"
 #include "module.h"
+#include "qemu-objects.h"
 
 #ifdef CONFIG_BSD
 #include <sys/types.h>
@@ -1133,43 +1134,125 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     return bs->drv->bdrv_is_allocated(bs, sector_num, nb_sectors, pnum);
 }
 
-void bdrv_info(Monitor *mon)
+static void bdrv_print_dict(QObject *obj, void *opaque)
 {
+    QDict *bs_dict;
+    Monitor *mon = opaque;
+
+    bs_dict = qobject_to_qdict(obj);
+
+    monitor_printf(mon, "%s: type=%s removable=%d",
Quoted 8 lines

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1150

Quoted 6 lines
block.c +6 -0
+                        qdict_get_str(bs_dict, "device"),
+                        qdict_get_str(bs_dict, "type"),
+                        qdict_get_bool(bs_dict, "removable"));
+
+    if (qdict_get_bool(bs_dict, "removable")) {
+        monitor_printf(mon, " locked=%d", (int)qdict_get_bool(bs_dict, "locked"));

qdict_get_bool() returns int, no need to cast.

Right.

Quoted 34 lines
Quoted 34 lines
block.c +34 -0
+    }
+
+    if (qdict_haskey(bs_dict, "inserted")) {
+        QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
+
+        monitor_printf(mon, " file=");
+        monitor_print_filename(mon, qdict_get_str(qdict, "file"));
+        if (qdict_haskey(qdict, "backing_file")) {
+            monitor_printf(mon, " backing_file=");
+            monitor_print_filename(mon, qdict_get_str(qdict, "backing_file"));
+        }
+        monitor_printf(mon, " ro=%d drv=%s encrypted=%d",
+                            qdict_get_bool(qdict, "ro"),
+                            qdict_get_str(qdict, "drv"),
+                            qdict_get_bool(qdict, "encrypted"));
+    } else {
+        monitor_printf(mon, " [not inserted]");
+    }
+
+    monitor_printf(mon, "\n");
+}
+
+void bdrv_info_print(Monitor *mon, const QObject *data)
+{
+    qlist_iter(qobject_to_qlist(data), bdrv_print_dict, mon);
+}
+
+/**
+ * bdrv_info(): Block devices information
+ *
+ * Each block device information is stored in a QDict and the
+ * returned QObject is a QList of all devices.
+ *
+ * The QDict contains the following:
Quoted 8 lines

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1189

Quoted 5 lines
block.c +5 -0
+ *
+ * - "device": device name
+ * - "type": device type
+ * - "removable": 1 if the device is removable 0 otherwise
+ * - "locked": 1 if the device is locked 0 otherwise

Use above and example below suggest that "locked" is only present if device is removable. Document?

Yes.

Quoted 13 lines

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1201

Quoted 12 lines
block.c +12 -0
+ * - "inserted": only present if the device is inserted, it is a QDict
+ *    containing the following:
+ *          - "file": device file name
+ *          - "ro": 1 if read-only 0 otherwise
+ *          - "drv": driver format name
+ *          - "backing_file": backing file name if one is used
+ *          - "encrypted":  1 if encrypted 0 otherwise
+ *
+ * Example:
+ *
+ * [ { "device": "ide0-hd0", "type": "hd", "removable": 0,
+ *     "file": "/tmp/foobar", "ro": 0, "drv": "qcow2", "encrypted": 0 }
Quoted 1 line

Shouldn't "file" & friends ne in nested dictionary "inserted"?

Yes, will fix.

Quoted 11 lines

block.c int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, · line 1232

Quoted 10 lines
block.c +6 -4
-        monitor_printf(mon, " removable=%d", bs->removable);
-        if (bs->removable) {
-            monitor_printf(mon, " locked=%d", bs->locked);
-        }
+
+        bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
+                                    "'removable': %i, 'locked': %i }",
+                                    bs->device_name, type, bs->removable,
+                                    bs->locked);
+        assert(bs_obj != NULL);
Quoted 2 lines

Failure modes of qobject_from_jsonf()? I'm asking because depending on the answer assert() may not be appropriate here.

As far as I know it will fail on wrong syntax.

#15 lore raw

Re: [Qemu-devel] [PATCH 11/17] block: Convert bdrv_info() to QObject

Quoted 4 lines · Luiz Capitulino
Quoted 1 line · On Fri, 20 Nov 2009 15:06:26 +0100 Markus Armbruster <[email protected]> wrote:

Luiz Capitulino <[email protected]> writes:

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
block.c +0 -0
index 6fdabff..fc4e2f2 100644

[...]

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
block.c +6 -4
-        monitor_printf(mon, " removable=%d", bs->removable);
-        if (bs->removable) {
-            monitor_printf(mon, " locked=%d", bs->locked);
-        }
+
+        bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': %s, "
+                                    "'removable': %i, 'locked': %i }",
+                                    bs->device_name, type, bs->removable,
+                                    bs->locked);
+        assert(bs_obj != NULL);
Quoted 4 lines
Quoted 2 lines

Failure modes of qobject_from_jsonf()? I'm asking because depending on the answer assert() may not be appropriate here.

As far as I know it will fail on wrong syntax.

In that case, assert() catches a programming error. That's fine.

#16 lore raw

PATCH 12/17 char: Convert qemu_chr_info() to QObject

In reply to Luiz Capitulino

Each 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
index e4fed10..a0a9281 100644
@@ -2040,7 +2040,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
index 9957db1..48f54d8 100644
@@ -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.5.2.180.gc5b3e
#17 lore raw

Re: [Qemu-devel] [PATCH 12/17] char: Convert qemu_chr_info() to QObject

Quoted 39 lines · Luiz Capitulino

Each 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
index e4fed10..a0a9281 100644
@@ -2040,7 +2040,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 +1 -0
index 5a81e8f..7fcde98 100644
@@ -32,6 +32,7 @@
 #include "hw/usb.h"
 #include "hw/baum.h"
 #include "hw/msmouse.h"
+#include "qemu-objects.h"
 
 #include <unistd.h>
 #include <fcntl.h>

qemu-char.c void qemu_chr_close(CharDriverState *chr) · line 2469

Quoted 5 lines
qemu-char.c +1 -1
@@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr)
     qemu_free(chr);
 }
 
-void qemu_chr_info(Monitor *mon)
+static void qemu_chr_print_qlist(QObject *obj, void *opaque)

Why *_qlist? It prints a qdict, which happens to be a list element, but this function doesn't know that.

Quoted 13 lines
qemu-char.c +12 -0
 {
+    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_print_qlist, mon);
+}

[...]

#18 lore raw

Re: [Qemu-devel] [PATCH 12/17] char: Convert qemu_chr_info() to QObject

Quoted 44 lines · On Fri, 20 Nov 2009 15:10:20 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 42 lines · Luiz Capitulino

Each 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
index e4fed10..a0a9281 100644
@@ -2040,7 +2040,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 +1 -0
index 5a81e8f..7fcde98 100644
@@ -32,6 +32,7 @@
 #include "hw/usb.h"
 #include "hw/baum.h"
 #include "hw/msmouse.h"
+#include "qemu-objects.h"
 
 #include <unistd.h>
 #include <fcntl.h>
@@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr)
     qemu_free(chr);
 }
 
Quoted 5 lines

qemu-char.c void qemu_chr_close(CharDriverState *chr) · line 2469

Quoted 2 lines
qemu-char.c +1 -1
-void qemu_chr_info(Monitor *mon)
+static void qemu_chr_print_qlist(QObject *obj, void *opaque)

Why *_qlist? It prints a qdict, which happens to be a list element, but this function doesn't know that.

It does know, as it was written with the purpose of printing the elements
of a qlist.

#19 lore raw

Re: [Qemu-devel] [PATCH 12/17] char: Convert qemu_chr_info() to QObject

Quoted 21 lines · Luiz Capitulino
Quoted 18 lines · On Fri, 20 Nov 2009 15:10:20 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 16 lines · Luiz Capitulino

Each 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 +0 -0
index e4fed10..a0a9281 100644

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
monitor.c +0 -0
@@ -2465,13 +2466,51 @@ void qemu_chr_close(CharDriverState *chr)
     qemu_free(chr);
 }
 
Quoted 8 lines
Quoted 5 lines

monitor.c void qemu_chr_close(CharDriverState *chr) · line 2469

Quoted 2 lines
monitor.c +1 -1
-void qemu_chr_info(Monitor *mon)
+static void qemu_chr_print_qlist(QObject *obj, void *opaque)

Why *_qlist? It prints a qdict, which happens to be a list element, but this function doesn't know that.

It does know, as it was written with the purpose of printing the elements
of a qlist.

You knew it when you wrote it, but the function itself has nothing to do with lists.

Elsewhere, you call such functions *_dict(), which makes sense to me, because it prints a dictionary, or *_iter(), which I is also okay.

#20 lore raw

PATCH 13/17 PCI: Convert pci_device_hot_add() to QObject

In reply to Luiz Capitulino

Return 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 |   37 +++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 37 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +33 -4
index a254498..93802a2 100644
@@ -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,8 @@ 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
index 62e395b..b50a2da 100644
@@ -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
index b1887ef..4d685a0 100644
@@ -201,7 +201,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.5.2.180.gc5b3e
#21 lore raw

Re: [Qemu-devel] [PATCH 13/17] PCI: Convert pci_device_hot_add() to QObject

Quoted 34 lines · Luiz Capitulino

Return 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 |   37 +++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 37 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +3 -1
index a254498..93802a2 100644
@@ -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)
+{

hw/pci-hotplug.c static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, · line 227

Quoted 10 lines
hw/pci-hotplug.c +10 -0
+    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"));

Despite its name, qdict_get_int() doesn't return int, but int64_t (trap for the unwary, in my opinion), so these casts are actually needed. The're safe, because the values put into the dictionary never overflow the cast.

Would be nice if we could avoid this non-local argument and make the code more obviously correct, but it's probably not worth the bother.

Quoted 33 lines
hw/pci-hotplug.c +20 -3
+
+}
+
+/**
+ * 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,8 @@ 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);
 }

[...]

#22 lore raw

[Qemu-devel] Re: [PATCH 13/17] PCI: Convert pci_device_hot_add() to QObject

In reply to Luiz Capitulino
Quoted 28 lines · Luiz Capitulino

Return 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 |   37 +++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 37 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +1 -0
index a254498..93802a2 100644
@@ -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,

hw/pci-hotplug.c static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, · line 216

Quoted 5 lines
hw/pci-hotplug.c +1 -1
@@ -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)

it only prints - why the strange name?

Quoted 33 lines
hw/pci-hotplug.c +29 -0
+{
+    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");

hw/pci-hotplug.c void pci_device_hot_add(Monitor *mon, const QDict *qdict) · line 272

Quoted 7 lines
hw/pci-hotplug.c +1 -3
@@ -239,9 +269,8 @@ 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));

this line is waay too long.

qemu-monitor.hx ETEXI · line 810

Quoted 11 lines
hw/pci-hotplug.c +1 -0
+        assert(*ret_data != NULL);
     } else
         monitor_printf(mon, "failed to add %s\n", opts);
 }
qemu-monitor.hx +0 -0
index 62e395b..b50a2da 100644
@@ -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]...",

and this

Quoted 25 lines
qemu-monitor.hx +2 -1
         .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
index b1887ef..4d685a0 100644
@@ -201,7 +201,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.5.2.180.gc5b3e
#23 lore raw

[Qemu-devel] Re: [PATCH 13/17] PCI: Convert pci_device_hot_add() to QObject

Quoted 32 lines · On Mon, 23 Nov 2009 11:44:57 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 31 lines · Luiz Capitulino

Return 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 |   37 +++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 37 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +1 -0
index a254498..93802a2 100644
@@ -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;
 }
 
Quoted 4 lines

hw/pci-hotplug.c static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, · line 216

Quoted 2 lines
hw/pci-hotplug.c +1 -1
-void pci_device_hot_add(Monitor *mon, const QDict *qdict)
+void pci_device_hot_add_print(Monitor *mon, const QObject *data)

it only prints - why the strange name?

I'm adding the _print suffix to the functions which print
handler data, that's, handle_name + _print.

It may have strange results, indeed, but sometimes it's difficult
to come with good names as I'm converting several handlers.

Also, I'd like to have standard names and haven't decided for
one yet.

Quoted 35 lines
Quoted 35 lines
hw/pci-hotplug.c +29 -0
+{
+    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,8 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "invalid type: %s\n", type);
 
Quoted 7 lines

hw/pci-hotplug.c void pci_device_hot_add(Monitor *mon, const QDict *qdict) · line 272

Quoted 5 lines
hw/pci-hotplug.c +1 -3
     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));

this line is waay too long.

I can brake it, although I don't think the result is going to be
prettier.

Quoted 6 lines
Quoted 6 lines
hw/pci-hotplug.c +1 -0
+        assert(*ret_data != NULL);
     } else
         monitor_printf(mon, "failed to add %s\n", opts);
 }
qemu-monitor.hx +0 -0
index 62e395b..b50a2da 100644
Quoted 8 lines

qemu-monitor.hx ETEXI · line 810

Quoted 5 lines
qemu-monitor.hx +0 -0
@@ -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]...",

and this

This line is not part of the series.

#24 lore raw

[Qemu-devel] Re: [PATCH 13/17] PCI: Convert pci_device_hot_add() to QObject

Quoted 92 lines · Luiz Capitulino
Quoted 32 lines · On Mon, 23 Nov 2009 11:44:57 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 31 lines · Luiz Capitulino

Return 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 |   37 +++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 37 insertions(+), 6 deletions(-)
hw/pci-hotplug.c +1 -0
index a254498..93802a2 100644
@@ -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;
 }
 
Quoted 4 lines

hw/pci-hotplug.c static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, · line 216

Quoted 2 lines
hw/pci-hotplug.c +1 -1
-void pci_device_hot_add(Monitor *mon, const QDict *qdict)
+void pci_device_hot_add_print(Monitor *mon, const QObject *data)

it only prints - why the strange name?

I'm adding the _print suffix to the functions which print
handler data, that's, handle_name + _print.

It may have strange results, indeed, but sometimes it's difficult
to come with good names as I'm converting several handlers.

Also, I'd like to have standard names and haven't decided for
one yet.

Quoted 35 lines
Quoted 35 lines
hw/pci-hotplug.c +29 -0
+{
+    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,8 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "invalid type: %s\n", type);
 
Quoted 7 lines

hw/pci-hotplug.c void pci_device_hot_add(Monitor *mon, const QDict *qdict) · line 272

Quoted 5 lines
hw/pci-hotplug.c +1 -3
     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));

this line is waay too long.

Quoted 2 lines

I can brake it, although I don't think the result is going to be
prettier.

Here's one that looks decent to me.

        *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));
Quoted 1 line
Quoted 1 line

hw/pci-hotplug.c void pci_device_hot_add(Monitor *mon, const QDict *qdict) · line 273

Quoted 1 line
hw/pci-hotplug.c +1 -0
+        assert(*ret_data != NULL);

BTW, pls make this assert(*ret_data);

Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
hw/pci-hotplug.c +0 -0
     } else
         monitor_printf(mon, "failed to add %s\n", opts);
 }
qemu-monitor.hx +0 -0
index 62e395b..b50a2da 100644
Quoted 8 lines

qemu-monitor.hx ETEXI · line 810

Quoted 5 lines
qemu-monitor.hx +0 -0
@@ -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]...",

and this

This line is not part of the series.

#25 lore raw

PATCH 14/17 block: Convert bdrv_info_stats() to QObject

In reply to Luiz Capitulino

Each 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
index fc4e2f2..1fac98b 100644
@@ -1255,22 +1255,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
index 3ca7112..42087d2 100644
@@ -44,7 +44,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
index a0a9281..63274ba 100644
@@ -2056,7 +2056,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.5.2.180.gc5b3e
#26 lore raw

PATCH 15/17 VNC: Convert do_info_vnc() to QObject

In reply to Luiz Capitulino

Return 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     |  190 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 163 insertions(+), 33 deletions(-)
console.h +2 -1
index 9615f56..9958860 100644
@@ -322,7 +322,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
index 63274ba..fb2f1c8 100644
@@ -2212,7 +2212,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 +159 -31

229 lines not on this page · raw message

Signature · 1 line
1.6.5.2.180.gc5b3e
#27 lore raw

PATCH 16/17 net: Convert do_info_network() to QObject

In reply to Luiz Capitulino

Each VLAN is represented by a QDict, the returned QObject is a QList of all VLANs.

This commit should not change user output.

---
 monitor.c |    3 +-
 net.c     |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 net.h     |    3 +-
 3 files changed, 72 insertions(+), 6 deletions(-)
monitor.c +2 -1
index fb2f1c8..de7a0f1 100644
@@ -2033,7 +2033,8 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the network state",
-        .mhandler.info = do_info_network,
+        .user_print = do_info_network_print,
+        .mhandler.info_new = do_info_network,
     },
     {
         .name       = "chardev",
net.c +68 -4

93 lines not on this page · raw message

net.h +2 -1
index 4ffce91..66da212 100644
@@ -105,7 +105,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model);
 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
                         const char *default_model);
 
-void do_info_network(Monitor *mon);
+void do_info_network_print(Monitor *mon, const QObject *data);
+void do_info_network(Monitor *mon, QObject **ret_data);
 void do_set_link(Monitor *mon, const QDict *qdict);
 
 void do_info_usernet(Monitor *mon);
Signature · 1 line
1.6.5.2.180.gc5b3e
#28 lore raw

PATCH 17/17 monitor: Convert do_info_mice() to QObject

In reply to Luiz Capitulino

Each 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
index 9958860..dfc8ae4 100644
@@ -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
index de7a0f1..c73d948 100644
@@ -2206,7 +2206,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.5.2.180.gc5b3e