Received: from eggs.gnu.org ([2001:4830:134:3::10]:53764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcr6A-00075T-Eu for qemu-devel@nongnu.org; Thu, 25 Aug 2016 05:37:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcr68-00054N-VJ for qemu-devel@nongnu.org; Thu, 25 Aug 2016 05:37:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcr68-00054D-Mw for qemu-devel@nongnu.org; Thu, 25 Aug 2016 05:37:20 -0400 From: "Dr. David Alan Gilbert (git)" Date: Thu, 25 Aug 2016 10:37:13 +0100 Message-Id: <1472117833-10236-3-git-send-email-dgilbert@redhat.com> In-Reply-To: <1472117833-10236-1-git-send-email-dgilbert@redhat.com> References: <1472117833-10236-1-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 2/2] qom: Implement qom-get HMP command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, lcapitulino@redhat.com, afaerber@suse.de, armbru@redhat.com Cc: pbonzini@redhat.com, arei.gonglei@huawei.com, kwolf@redhat.com From: "Dr. David Alan Gilbert" Reimplement it based on qmp_qom_get() to avoid converting QObjects back to strings. Inspired-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber Slight fix for bit-rot: Signed-off-by: Dr. David Alan Gilbert --- hmp-commands.hx | 13 +++++++++++++ hmp.c | 23 +++++++++++++++++++++++ hmp.h | 1 + 3 files changed, 37 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 848efee..73f0372 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1736,6 +1736,19 @@ Print QOM properties of object at location @var{pa= th} ETEXI =20 { + .name =3D "qom-get", + .args_type =3D "path:s,property:s", + .params =3D "path property", + .help =3D "print QOM property", + .mhandler.cmd =3D hmp_qom_get, + }, + +STEXI +@item qom-get @var{path} @var{property} +Print QOM property @var{property} of object at location @var{path} +ETEXI + + { .name =3D "qom-set", .args_type =3D "path:s,property:s,value:s", .params =3D "path property value", diff --git a/hmp.c b/hmp.c index cc2056e..17e6b06 100644 --- a/hmp.c +++ b/hmp.c @@ -2064,6 +2064,29 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict= ) hmp_handle_error(mon, &err); } =20 +void hmp_qom_get(Monitor *mon, const QDict *qdict) +{ + const char *path =3D qdict_get_str(qdict, "path"); + const char *property =3D qdict_get_str(qdict, "property"); + Error *err =3D NULL; + Object *obj; + char *value; + + obj =3D object_resolve_path(path, NULL); + if (obj =3D=3D NULL) { + error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); + hmp_handle_error(mon, &err); + return; + } + value =3D object_property_print(obj, property, true, &err); + if (err =3D=3D NULL) { + monitor_printf(mon, "%s\n", value); + g_free(value); + } + hmp_handle_error(mon, &err); +} + void hmp_qom_set(Monitor *mon, const QDict *qdict) { const char *path =3D qdict_get_str(qdict, "path"); diff --git a/hmp.h b/hmp.h index 0876ec0..882f339 100644 --- a/hmp.h +++ b/hmp.h @@ -103,6 +103,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict)= ; void hmp_info_memdev(Monitor *mon, const QDict *qdict); void hmp_info_memory_devices(Monitor *mon, const QDict *qdict); void hmp_qom_list(Monitor *mon, const QDict *qdict); +void hmp_qom_get(Monitor *mon, const QDict *qdict); void hmp_qom_set(Monitor *mon, const QDict *qdict); void object_add_completion(ReadLineState *rs, int nb_args, const char *s= tr); void object_del_completion(ReadLineState *rs, int nb_args, const char *s= tr); --=20 2.7.4