From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:35721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwKGn-0002fG-9L for qemu-devel@nongnu.org; Wed, 24 Aug 2011 16:41:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwKGl-0007q4-UQ for qemu-devel@nongnu.org; Wed, 24 Aug 2011 16:41:53 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:45544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwKGl-0007po-OK for qemu-devel@nongnu.org; Wed, 24 Aug 2011 16:41:51 -0400 Received: by yxt3 with SMTP id 3so1330521yxt.4 for ; Wed, 24 Aug 2011 13:41:46 -0700 (PDT) Message-ID: <4E556207.9020408@codemonkey.ws> Date: Wed, 24 Aug 2011 15:41:43 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <1314211389-28915-1-git-send-email-aliguori@us.ibm.com> <1314211389-28915-5-git-send-email-aliguori@us.ibm.com> <20110824172804.435eca1a@doriath> In-Reply-To: <20110824172804.435eca1a@doriath> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 04/14] qapi: convert query-name List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: Kevin Wolf , Anthony Liguori , qemu-devel@nongnu.org, Michael Roth On 08/24/2011 03:28 PM, Luiz Capitulino wrote: > On Wed, 24 Aug 2011 13:42:59 -0500 > Anthony Liguori wrote: > >> A simple example conversion 'info name'. This also adds the new files for >> QMP and HMP. > > The QAPI makes QMP commands real good! > > (more comments below). Thanks :-) > >> >> Signed-off-by: Anthony Liguori >> --- >> Makefile.objs | 1 + >> hmp.c | 26 ++++++++++++++++++++++++++ >> hmp.h | 22 ++++++++++++++++++++++ >> monitor.c | 27 +++++---------------------- >> qapi-schema.json | 23 +++++++++++++++++++++++ >> qmp.c | 28 ++++++++++++++++++++++++++++ >> 6 files changed, 105 insertions(+), 22 deletions(-) >> create mode 100644 hmp.c >> create mode 100644 hmp.h >> create mode 100644 qmp.c >> >> diff --git a/Makefile.objs b/Makefile.objs >> index c02431f..570dda7 100644 >> --- a/Makefile.objs >> +++ b/Makefile.objs >> @@ -397,6 +397,7 @@ qapi-nested-y += qmp-registry.o qmp-dispatch.o >> qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y)) >> >> common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y) >> +common-obj-y += qmp.o hmp.o >> >> ###################################################################### >> # guest agent >> diff --git a/hmp.c b/hmp.c >> new file mode 100644 >> index 0000000..47e1ff7 >> --- /dev/null >> +++ b/hmp.c >> @@ -0,0 +1,26 @@ >> +/* >> + * Human Monitor Interface >> + * >> + * Copyright IBM, Corp. 2011 >> + * >> + * Authors: >> + * Anthony Liguori >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2. See >> + * the COPYING file in the top-level directory. >> + * >> + */ >> + >> +#include "hmp.h" >> +#include "qmp-commands.h" >> + >> +void hmp_info_name(Monitor *mon) >> +{ >> + NameInfo *info; >> + >> + info = qmp_query_name(NULL); >> + if (info->has_name) { >> + monitor_printf(mon, "%s\n", info->name); >> + } >> + qapi_free_NameInfo(info); >> +} >> diff --git a/hmp.h b/hmp.h >> new file mode 100644 >> index 0000000..5fe73f1 >> --- /dev/null >> +++ b/hmp.h >> @@ -0,0 +1,22 @@ >> +/* >> + * Human Monitor Interface >> + * >> + * Copyright IBM, Corp. 2011 >> + * >> + * Authors: >> + * Anthony Liguori >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2. See >> + * the COPYING file in the top-level directory. >> + * >> + */ >> + >> +#ifndef HMP_H >> +#define HMP_H >> + >> +#include "qemu-common.h" >> +#include "qapi-types.h" >> + >> +void hmp_info_name(Monitor *mon); >> + >> +#endif >> diff --git a/monitor.c b/monitor.c >> index ef204c0..6a3a3d2 100644 >> --- a/monitor.c >> +++ b/monitor.c >> @@ -61,6 +61,8 @@ >> #include "trace.h" >> #endif >> #include "ui/qemu-spice.h" >> +#include "qmp-commands.h" >> +#include "hmp.h" >> >> //#define DEBUG >> //#define DEBUG_COMPLETION >> @@ -757,24 +759,6 @@ static void do_info_version(Monitor *mon, QObject **ret_data) >> 'micro': %d }, 'package': %s }", major, minor, micro, QEMU_PKGVERSION); >> } >> >> -static void do_info_name_print(Monitor *mon, const QObject *data) >> -{ >> - QDict *qdict; >> - >> - qdict = qobject_to_qdict(data); >> - if (qdict_size(qdict) == 0) { >> - return; >> - } >> - >> - monitor_printf(mon, "%s\n", qdict_get_str(qdict, "name")); >> -} >> - >> -static void do_info_name(Monitor *mon, QObject **ret_data) >> -{ >> - *ret_data = qemu_name ? qobject_from_jsonf("{'name': %s }", qemu_name) : >> - qobject_from_jsonf("{}"); >> -} >> - >> static QObject *get_cmd_dict(const char *name) >> { >> const char *p; >> @@ -3069,8 +3053,7 @@ static const mon_cmd_t info_cmds[] = { >> .args_type = "", >> .params = "", >> .help = "show the current VM name", >> - .user_print = do_info_name_print, >> - .mhandler.info_new = do_info_name, >> + .mhandler.info = hmp_info_name, >> }, >> { >> .name = "uuid", >> @@ -3266,8 +3249,8 @@ static const mon_cmd_t qmp_query_cmds[] = { >> .args_type = "", >> .params = "", >> .help = "show the current VM name", >> - .user_print = do_info_name_print, >> - .mhandler.info_new = do_info_name, >> + .mhandler.cmd_new = qmp_marshal_input_query_name, >> + .qapi = true, >> }, >> { >> .name = "uuid", >> diff --git a/qapi-schema.json b/qapi-schema.json >> index 7fcefdb..654409b 100644 >> --- a/qapi-schema.json >> +++ b/qapi-schema.json >> @@ -1,3 +1,26 @@ >> # -*- Mode: Python -*- >> # >> # QAPI Schema >> + >> +## >> +# @NameInfo: >> +# >> +# Guest name information. >> +# >> +# @name: #optional The name of the guest > > Isn't it the VM name? VM and guest are synonyms, no? I think guest sounds a bit more polite :-) >> +# >> +# Since 0.14.0 >> +## >> +{ 'type': 'NameInfo', 'data': {'*name': 'str'} } > > Is the type name ('NameInfo' in this case) going to be public in libqmp? If yes, > Isn't VmNameInfo better? For libqmp, it would be exposed probably as QmpNameInfo. But for the most part, the names are mechanically derived from the commands for better or worse. >> + >> +## >> +# @query-name: >> +# >> +# Return the name information of a guest. >> +# >> +# Returns: @NameInfo of the guest >> +# >> +# Since 0.14.0 >> +## >> +{ 'command': 'query-name', 'returns': 'NameInfo' } >> + >> diff --git a/qmp.c b/qmp.c >> new file mode 100644 >> index 0000000..8aa9c66 >> --- /dev/null >> +++ b/qmp.c >> @@ -0,0 +1,28 @@ >> +/* >> + * QEMU Management Protocol >> + * >> + * Copyright IBM, Corp. 2011 >> + * >> + * Authors: >> + * Anthony Liguori >> + * >> + * This work is licensed under the terms of the GNU GPL, version 2. See >> + * the COPYING file in the top-level directory. >> + * >> + */ >> + >> +#include "qemu-common.h" >> +#include "sysemu.h" >> +#include "qmp-commands.h" >> + >> +NameInfo *qmp_query_name(Error **errp) >> +{ >> + NameInfo *info = g_malloc0(sizeof(*info)); >> + >> + if (qemu_name) { >> + info->has_name = true; >> + info->name = g_strdup(qemu_name); >> + } > > Isn't it better to keep using qemu_malloc()& friends but change its > current implementation to use the glib malloc functions? You're behind on qemu-devel, qemu_malloc() is no more :-) Regards, Anthony Liguori > > >> + >> + return info; >> +} > >