qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions
@ 2009-11-01 14:51 Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file Luiz Capitulino
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

 Hi,

 I'm sending in this series some info handlers conversions I have in my queue,
as they depend on the QJSON module this submission is for review-only.

 The only issue I have here is error handling on calls to qobject_from_jsonf(),
I'm calling assert() but we should have a wrapper for this.

 If someone is willing to help with the conversions, please, take a look
at Monitor Protocol wiki page:

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

 Thanks.

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

* [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 2/8] Makefile: move QObject objs to their own entry Luiz Capitulino
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

An easy way to include all QEMU objects.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu-objects.h |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
 create mode 100644 qemu-objects.h

diff --git a/qemu-objects.h b/qemu-objects.h
new file mode 100644
index 0000000..e1d1e0c
--- /dev/null
+++ b/qemu-objects.h
@@ -0,0 +1,24 @@
+/*
+ * Include all QEMU objects.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ *  Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * 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 */
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 2/8] Makefile: move QObject objs to their own entry
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 3/8] QDict: Introduce qdict_get_qbool() Luiz Capitulino
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

Other subsystems will need to link against them.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 6fcbcaa..56f0301 100644
--- a/Makefile
+++ b/Makefile
@@ -70,6 +70,10 @@ 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 qjson.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
@@ -104,6 +108,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
@@ -135,7 +140,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 qjson.o
 obj-y += qemu-config.o
 
 obj-$(CONFIG_BRLAPI) += baum.o
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 3/8] QDict: Introduce qdict_get_qbool()
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 2/8] Makefile: move QObject objs to their own entry Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 4/8] monitor: Convert do_info_migrate() to QObject Luiz Capitulino
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

This is a helper function that does type checking before retrieving
a QBool from the dictionary.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile |    2 +-
 qdict.c  |   15 +++++++++++++++
 qdict.h  |    1 +
 3 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 56f0301..424639a 100644
--- a/Makefile
+++ b/Makefile
@@ -227,7 +227,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 qjson.o qstring.o qint.o qdict.o qlist.o qfloat.o qbool.o qemu-malloc.o
diff --git a/qdict.c b/qdict.c
index a302f4c..6cd6c87 100644
--- a/qdict.c
+++ b/qdict.c
@@ -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'
  *
diff --git a/qdict.h b/qdict.h
index 3102ca2..dc70ee5 100644
--- a/qdict.h
+++ b/qdict.h
@@ -34,6 +34,7 @@ QDict *qobject_to_qdict(const QObject *obj);
 
 /* 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);
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 4/8] monitor: Convert do_info_migrate() to QObject
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
                   ` (2 preceding siblings ...)
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 3/8] QDict: Introduce qdict_get_qbool() Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 5/8] monitor: Convert bdrv_info() " Luiz Capitulino
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

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

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

IMPORTANT: as a QInt stores a int64_t integer, those RAM values
are going to 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, the following is an
example of the returned QDict:

{ "status": "active", "ram":
   { "transferred": 885030912, "remaining": 198529024, "total": 1082392576 } }

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 migration.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 migration.h |    3 +-
 monitor.c   |    3 +-
 3 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/migration.c b/migration.c
index b20beb7..da33506 100644
--- a/migration.c
+++ b/migration.c
@@ -18,6 +18,7 @@
 #include "sysemu.h"
 #include "block.h"
 #include "qemu_socket.h"
+#include "qemu-objects.h"
 
 //#define DEBUG_MIGRATION
 
@@ -149,29 +150,71 @@ void do_migrate_set_downtime(Monitor *mon, const QDict *qdict)
     max_downtime = (uint64_t)d;
 }
 
-void do_info_migrate(Monitor *mon)
+void migration_user_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 "} }", NULL, 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' }", NULL);
             break;
         case MIG_STATE_ERROR:
-            monitor_printf(mon, "failed\n");
+            *ret_data = qobject_from_jsonf("{ 'status': 'failed' }", NULL);
             break;
         case MIG_STATE_CANCELLED:
-            monitor_printf(mon, "cancelled\n");
+            *ret_data = qobject_from_jsonf("{ 'status': 'cancelled' }", NULL);
             break;
         }
+        assert(*ret_data != NULL);
     }
 }
 
diff --git a/migration.h b/migration.h
index 2d28b8f..7666c4b 100644
--- a/migration.h
+++ b/migration.h
@@ -60,7 +60,8 @@ uint64_t migrate_max_downtime(void);
 
 void do_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 
-void do_info_migrate(Monitor *mon);
+void migration_user_print(Monitor *mon, const QObject *data);
+void do_info_migrate(Monitor *mon, QObject **ret_data);
 
 int exec_start_incoming_migration(const char *host_port);
 
diff --git a/monitor.c b/monitor.c
index 109ff5c..667dd7c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2177,7 +2177,8 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show migration status",
-        .mhandler.info = do_info_migrate,
+        .user_print = migration_user_print,
+        .mhandler.info_new = do_info_migrate,
     },
     {
         .name       = "balloon",
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 5/8] monitor: Convert bdrv_info() to QObject
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
                   ` (3 preceding siblings ...)
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 4/8] monitor: Convert do_info_migrate() to QObject Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 6/8] monitor: Convert qemu_chr_info() " Luiz Capitulino
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

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
- "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

This commit should not change user output, the following is an
example of the returned QList:

[ { "device": "ide0-hd0", "type": "hd", "removable": 0,
    "file": "/tmp/foobar", "ro": 0, "drv": "qcow2", "encrypted": 0 }
  { "device": "floppy0", "type": "floppy", "removable": 1,
  "locked": 0 } ]

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile  |    2 +-
 block.c   |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
 block.h   |    4 +-
 monitor.c |    3 +-
 4 files changed, 109 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile
index 424639a..5196cfc 100644
--- a/Makefile
+++ b/Makefile
@@ -77,7 +77,7 @@ qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o qjson.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
 
diff --git a/block.c b/block.c
index fa0de25..c6ba7c2 100644
--- a/block.c
+++ b/block.c
@@ -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>
@@ -1075,43 +1076,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",
+                        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"));
+    }
+
+    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_user_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:
+ *
+ * - "device": device name
+ * - "type": device type
+ * - "removable": 1 if the device is removable 0 otherwise
+ * - "locked": 1 if the device is locked 0 otherwise
+ * - "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 }
+ *   { "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";
             break;
         case BDRV_TYPE_CDROM:
-            monitor_printf(mon, "cdrom");
+            type = "cdrom";
             break;
         case BDRV_TYPE_FLOPPY:
-            monitor_printf(mon, "floppy");
+            type = "floppy";
             break;
         }
-        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 }", NULL,
+                                    bs->device_name, type, bs->removable,
+                                    bs->locked);
+        assert(bs_obj != NULL);
+
         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 }", NULL,
+                                     bs->filename, bs->read_only,
+                                     bs->drv->format_name,
+                                     bdrv_is_encrypted(bs));
+            assert(obj != NULL);
             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. */
diff --git a/block.h b/block.h
index a966afb..99dc360 100644
--- a/block.h
+++ b/block.h
@@ -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_user_print(Monitor *mon, const QObject *data);
+void bdrv_info(Monitor *mon, QObject **ret_data);
 void bdrv_info_stats(Monitor *mon);
 
 void bdrv_init(void);
diff --git a/monitor.c b/monitor.c
index 667dd7c..b9fed9f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1979,7 +1979,8 @@ static const mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the block devices",
-        .mhandler.info = bdrv_info,
+        .user_print = bdrv_user_print,
+        .mhandler.info_new = bdrv_info,
     },
     {
         .name       = "blockstats",
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 6/8] monitor: Convert qemu_chr_info() to QObject
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
                   ` (4 preceding siblings ...)
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 5/8] monitor: Convert bdrv_info() " Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 7/8] monitor: Convert pci_device_hot_add() " Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 8/8] monitor: Convert do_info_status() " Luiz Capitulino
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

Each device is represented by a QDict. The returned QObject is a QList
of all devices.

The QDict contains the following:

- "label": device's label
- "filename": device's file

This commit should not change user output, the following is an
example of the returned QList:

[ { "label": "monitor", "filename", "stdio" },
  { "label": "serial0", "filename": "vc" } ]

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c   |    3 ++-
 qemu-char.c |   43 +++++++++++++++++++++++++++++++++++++++++--
 qemu-char.h |    4 +++-
 3 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index b9fed9f..4e19fdf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1972,7 +1972,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_print,
+        .mhandler.info_new = qemu_chr_info,
     },
     {
         .name       = "block",
diff --git a/qemu-char.c b/qemu-char.c
index 40bd7e8..fa23111 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -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>
@@ -2472,13 +2473,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)
 {
+    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_print(Monitor *mon, const QObject *ret_data)
+{
+    qlist_iter(qobject_to_qlist(ret_data), qemu_chr_print_qlist, mon);
+}
+
+/**
+ * qemu_chr_info(): Character devices information
+ *
+ * Each device is represented by a QDict. The returned QObject is a QList
+ * of all devices.
+ *
+ * The QDict contains the following:
+ *
+ * - "label": device's label
+ * - "filename": device's file
+ *
+ * Example:
+ *
+ * [ { "label": "monitor", "filename", "stdio" },
+ *   { "label": "serial0", "filename": "vc" } ]
+ */
+void qemu_chr_info(Monitor *mon, QObject **ret_data)
+{
+    QList *chr_list;
     CharDriverState *chr;
 
+    chr_list = qlist_new();
+
     QTAILQ_FOREACH(chr, &chardevs, next) {
-        monitor_printf(mon, "%s: filename=%s\n", chr->label, chr->filename);
+        QObject *obj = qobject_from_jsonf("{ 'label': %s, 'filename': %s }",
+                                          NULL, chr->label, chr->filename);
+        qlist_append_obj(chr_list, obj);
     }
+
+    *ret_data = QOBJECT(chr_list);
 }
 
 CharDriverState *qemu_chr_find(const char *name)
diff --git a/qemu-char.h b/qemu-char.h
index 05fe15d..1a7736f 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -5,6 +5,7 @@
 #include "qemu-queue.h"
 #include "qemu-option.h"
 #include "qemu-config.h"
+#include "qobject.h"
 
 /* character device */
 
@@ -88,7 +89,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_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;
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 7/8] monitor: Convert pci_device_hot_add() to QObject
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
                   ` (5 preceding siblings ...)
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 6/8] monitor: Convert qemu_chr_info() " Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 8/8] monitor: Convert do_info_status() " Luiz Capitulino
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

Return a QDict with the following device information:

- "domain": domain number
- "bus": bus number
- "slot": slot number
- "function": function number

This commit should not change user output, the following is an
example of the returned QDict:

{ "domain": 0, "bus": 0, "slot": 5, "function": 0 }

Please, note that this is only in case of success. In error
conditions the handler still calls monitor_printf() directly,
as errors are not being converted yet.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/pci-hotplug.c |   38 ++++++++++++++++++++++++++++++++++----
 qemu-monitor.hx  |    3 ++-
 sysemu.h         |    3 ++-
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 15a2dfb..f3ff346 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -33,6 +33,7 @@
 #include "scsi-disk.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_add_user_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,9 @@ 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 }", NULL,
+        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);
 }
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index bb01c14..f540880 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -802,7 +802,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_add_user_print,
+        .mhandler.cmd_new = pci_device_hot_add,
     },
 #endif
 
diff --git a/sysemu.h b/sysemu.h
index 96804b4..62958dc 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -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_add_user_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,
-- 
1.6.5.2.101.gcd0f8

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

* [Qemu-devel] [PATCH 8/8] monitor: Convert do_info_status() to QObject
  2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
                   ` (6 preceding siblings ...)
  2009-11-01 14:51 ` [Qemu-devel] [PATCH 7/8] monitor: Convert pci_device_hot_add() " Luiz Capitulino
@ 2009-11-01 14:51 ` Luiz Capitulino
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2009-11-01 14:51 UTC (permalink / raw)
  To: qemu-devel

Return a QString with status information.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/monitor.c b/monitor.c
index 4e19fdf..78a2df5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1678,16 +1678,38 @@ static void do_inject_nmi(Monitor *mon, const QDict *qdict)
 }
 #endif
 
-static void do_info_status(Monitor *mon)
+static void monitor_print_status(Monitor *mon, const QObject *data)
 {
+    QString *qs;
+
+    qs = qobject_to_qstring(data);
+    monitor_printf(mon, "VM status: %s\n", qstring_get_str(qs));
+}
+
+/**
+ * do_info_status(): VM status
+ *
+ * Return a QString with status information.
+ *
+ * Example:
+ *
+ * "running"
+ */
+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);
 }
 
 /**
@@ -2119,7 +2141,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 = monitor_print_status,
+        .mhandler.info_new = do_info_status,
     },
     {
         .name       = "pcmcia",
-- 
1.6.5.2.101.gcd0f8

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

end of thread, other threads:[~2009-11-01 14:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-01 14:51 [Qemu-devel] [RFC 0/8]: Some 'info' handlers conversions Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 1/8] Introduce qemu-objects.h header file Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 2/8] Makefile: move QObject objs to their own entry Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 3/8] QDict: Introduce qdict_get_qbool() Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 4/8] monitor: Convert do_info_migrate() to QObject Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 5/8] monitor: Convert bdrv_info() " Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 6/8] monitor: Convert qemu_chr_info() " Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 7/8] monitor: Convert pci_device_hot_add() " Luiz Capitulino
2009-11-01 14:51 ` [Qemu-devel] [PATCH 8/8] monitor: Convert do_info_status() " Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).