From patchwork Tue Apr 7 11:44:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 1267380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kaod.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xQZd0Fvlz9sSG for ; Tue, 7 Apr 2020 21:45:29 +1000 (AEST) Received: from localhost ([::1]:45772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLmfW-0003SB-NW for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 07:45:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55272) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLmfB-0003Rp-Bu for qemu-devel@nongnu.org; Tue, 07 Apr 2020 07:45:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLmf8-0007yp-WB for qemu-devel@nongnu.org; Tue, 07 Apr 2020 07:45:05 -0400 Received: from 6.mo173.mail-out.ovh.net ([46.105.43.93]:42492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLmf8-0007wF-Ji for qemu-devel@nongnu.org; Tue, 07 Apr 2020 07:45:02 -0400 Received: from player739.ha.ovh.net (unknown [10.108.35.59]) by mo173.mail-out.ovh.net (Postfix) with ESMTP id 4B8ED136841 for ; Tue, 7 Apr 2020 13:45:00 +0200 (CEST) Received: from kaod.org (82-64-250-170.subs.proxad.net [82.64.250.170]) (Authenticated sender: clg@kaod.org) by player739.ha.ovh.net (Postfix) with ESMTPSA id 56405D2B9B6E; Tue, 7 Apr 2020 11:44:53 +0000 (UTC) From: =?utf-8?q?C=C3=A9dric_Le_Goater?= To: "Dr . David Alan Gilbert" Subject: [RFC PATCH] qom: Implement qom-get HMP command Date: Tue, 7 Apr 2020 13:44:49 +0200 Message-Id: <20200407114449.482532-1-clg@kaod.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Ovh-Tracer-Id: 7474568006855920434 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduhedrudehgdeghecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpeevrogurhhitgcunfgvucfiohgrthgvrhcuoegtlhhgsehkrghougdrohhrgheqnecukfhppedtrddtrddtrddtpdekvddrieegrddvhedtrddujedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrjeefledrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpegtlhhgsehkrghougdrohhrghdprhgtphhtthhopehqvghmuhdquggvvhgvlhesnhhonhhgnhhurdhorhhg X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.105.43.93 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Eduardo Habkost , qemu-devel@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , =?utf-8?q?Andreas_F=C3=A4rber?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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ärber Slight fix for bit-rot: Signed-off-by: Dr. David Alan Gilbert [clg: updates for QEMU 5.0 ] Signed-off-by: Cédric Le Goater --- I would like to restart the discussion on qom-get command to understand what was the conclusion and see if things have changed since. Thanks, C. include/monitor/hmp.h | 1 + qom/qom-hmp-cmds.c | 23 +++++++++++++++++++++++ hmp-commands.hx | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index e33ca5a911a5..c986cfd28bc3 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -96,6 +96,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict); void hmp_info_numa(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 hmp_info_qom_tree(Monitor *mon, const QDict *dict); void object_add_completion(ReadLineState *rs, int nb_args, const char *str); diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index cd08233a4cfe..b14cf6e785f4 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -40,6 +40,29 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, err); } +void hmp_qom_get(Monitor *mon, const QDict *qdict) +{ + const char *path = qdict_get_str(qdict, "path"); + const char *property = qdict_get_str(qdict, "property"); + Error *err = NULL; + Object *obj; + char *value; + + obj = object_resolve_path(path, NULL); + if (obj == NULL) { + error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", path); + hmp_handle_error(mon, err); + return; + } + value = object_property_print(obj, property, true, &err); + if (err == 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 = qdict_get_str(qdict, "path"); diff --git a/hmp-commands.hx b/hmp-commands.hx index 7f0f3974ad90..4e39b9caed3e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1790,6 +1790,19 @@ SRST Print QOM properties of object at location *path* ERST + { + .name = "qom-get", + .args_type = "path:s,property:s", + .params = "path property", + .help = "print QOM property", + .cmd = hmp_qom_get, + }, + +SRST +``qom-get`` *path* *property* + Print QOM property *property* of object at location *path* +ERST + { .name = "qom-set", .args_type = "path:s,property:s,value:s",