From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MyR4w-0007se-J3 for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:13:18 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MyR4p-0007rZ-Sx for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:13:16 -0400 Received: from [199.232.76.173] (port=36844 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyR4p-0007rM-K1 for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:13:11 -0400 Received: from mail-qy0-f199.google.com ([209.85.221.199]:45995) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MyR4p-0002Uf-9g for qemu-devel@nongnu.org; Thu, 15 Oct 2009 10:13:11 -0400 Received: by qyk37 with SMTP id 37so610406qyk.18 for ; Thu, 15 Oct 2009 07:13:10 -0700 (PDT) Message-ID: <4AD72DF0.408@codemonkey.ws> Date: Thu, 15 Oct 2009 09:13:04 -0500 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 08/10] monitor: Convert bdrv_info() to QObject References: <1255037747-3340-1-git-send-email-lcapitulino@redhat.com> <1255037747-3340-9-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255037747-3340-9-git-send-email-lcapitulino@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Luiz Capitulino wrote: > 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 > - "backing_file": backing file name if one is used > - "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 > - "encrypted": 1 if encrypted 0 otherwise > > The current implemention uses integers as booleans, to make > things simple those integers are stored in the QDict. Ideally, > we would have a QBool type and this is probably going to be > a requirement for the protocol. > > But the integers will do the job for now. > > 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 > --- > Makefile | 1 + > block.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- > block.h | 4 +- > monitor.c | 3 +- > 4 files changed, 118 insertions(+), 22 deletions(-) > > diff --git a/Makefile b/Makefile > index 182f176..d29d871 100644 > --- a/Makefile > +++ b/Makefile > @@ -62,6 +62,7 @@ recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES) > # 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 += qint.o qstring.o qlist.o qdict.o qmisc.o > block-obj-y += nbd.o block.o aio.o aes.o osdep.o > 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 33f3d65..31a58e4 100644 > --- a/block.c > +++ b/block.c > @@ -26,6 +26,10 @@ > #include "monitor.h" > #include "block_int.h" > #include "module.h" > +#include "qlist.h" > +#include "qdict.h" > +#include "qstring.h" > +#include "qmisc.h" > > #ifdef CONFIG_BSD > #include > @@ -1075,43 +1079,131 @@ 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; > + > + assert(qobject_type(obj) == QTYPE_QDICT); > + 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"), > + (int) qdict_get_int(bs_dict, "removable")); > This is a very common format. So much so, it probably makes sense to have: monitor_print_dict(mon, "device", bs_dict); > + > + if (qdict_get_int(bs_dict, "removable")) { > + monitor_printf(mon, " locked=%d",(int)qdict_get_int(bs_dict, "locked")); > + } > Which suggests that the dict entry should be locked, not removable. > + if (qdict_haskey(bs_dict, "inserted")) { > I guess you could flatten nested dicts. > + QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted")); > + monitor_printf(mon, " file=%s", qdict_get_str(qdict, "file")); > + if (qdict_haskey(qdict, "backing_file")) { > + monitor_printf(mon, " backing_file=%s", > + qdict_get_str(qdict, "backing_file")); > + } > + monitor_printf(mon, " ro=%d drv=%s encrypted=%d", > + (int) qdict_get_int(qdict, "ro"), > + qdict_get_str(qdict, "drv"), > + (int) qdict_get_int(qdict, "encrypted")); > + } else { > + monitor_printf(mon, " [not inserted]"); > This bit you would probably have to handle manually. Alternatively, you could build a compat dict from the new dict format and then print that with the monitor_print_dict function. Regards, Anthony Liguori