From patchwork Mon Jun 25 22:43:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 167248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 25A941007D7 for ; Tue, 26 Jun 2012 08:45:21 +1000 (EST) Received: from localhost ([::1]:58070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjI23-0002QB-1X for incoming@patchwork.ozlabs.org; Mon, 25 Jun 2012 18:45:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjI1v-0002Q6-EJ for qemu-devel@nongnu.org; Mon, 25 Jun 2012 18:45:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SjI1t-0001RZ-EY for qemu-devel@nongnu.org; Mon, 25 Jun 2012 18:45:10 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:60213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjI1t-0001PF-6x for qemu-devel@nongnu.org; Mon, 25 Jun 2012 18:45:09 -0400 Received: from /spool/local by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 25 Jun 2012 16:45:05 -0600 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 25 Jun 2012 16:44:57 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 37DFC3E4004E for ; Mon, 25 Jun 2012 22:44:34 +0000 (WET) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q5PMi2J1164196 for ; Mon, 25 Jun 2012 16:44:12 -0600 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q5PMhl1b009007 for ; Mon, 25 Jun 2012 16:43:47 -0600 Received: from titi.austin.rr.com (sig-9-65-39-74.mts.ibm.com [9.65.39.74]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q5PMhieU008832; Mon, 25 Jun 2012 16:43:46 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 25 Jun 2012 17:43:41 -0500 Message-Id: <1340664222-25098-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1340664222-25098-1-git-send-email-aliguori@us.ibm.com> References: <1340664222-25098-1-git-send-email-aliguori@us.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12062522-2398-0000-0000-000007E46643 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.110.151 Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Markus Armbruster , Amit Shah , Paolo Bonzini , Andreas Faerber Subject: [Qemu-devel] [PATCH 3/4] vl: add -object option to create QOM objects from the command line X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This will create a new QOM object in the '/objects' path. Note that properties are set in order which allows for simple objects to be initialized entirely with this option and then realized. This option is roughly equivalent to -device but for things that are not devices. Signed-off-by: Anthony Liguori --- qemu-config.c | 10 ++++++++++ qemu-options.hx | 8 ++++++++ vl.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 0 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index bb3bff4..8135430 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -614,6 +614,15 @@ QemuOptsList qemu_boot_opts = { }, }; +QemuOptsList qemu_object_opts = { + .name = "object", + .implied_opt_name = "qom-type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc = { + { } + }, +}; + static QemuOptsList *vm_config_groups[32] = { &qemu_drive_opts, &qemu_chardev_opts, @@ -629,6 +638,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_machine_opts, &qemu_boot_opts, &qemu_iscsi_opts, + &qemu_object_opts, NULL, }; diff --git a/qemu-options.hx b/qemu-options.hx index 8b66264..20cfe1c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2743,6 +2743,14 @@ DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "-qtest-log LOG specify tracing options\n", QEMU_ARCH_ALL) +DEF("object", HAS_ARG, QEMU_OPTION_object, + "-object TYPENAME[,PROP1=VALUE1,...]\n" + " create an new object of type TYPENAME setting properties\n" + " in the order they are specified. Note that the 'id'\n" + " property must be set. These objects are placed in the\n" + " '/objects' path.\n", + QEMU_ARCH_ALL) + HXCOMM This is the last statement. Insert new options before this line! STEXI @end table diff --git a/vl.c b/vl.c index 1329c30..ac25153 100644 --- a/vl.c +++ b/vl.c @@ -161,6 +161,7 @@ int main(int argc, char **argv) #include "arch_init.h" #include "ui/qemu-spice.h" +#include "qapi/string-input-visitor.h" //#define DEBUG_NET //#define DEBUG_SLIRP @@ -2255,6 +2256,53 @@ static void free_and_trace(gpointer mem) free(mem); } +static int object_set_property(const char *name, const char *value, void *opaque) +{ + Object *obj = OBJECT(opaque); + StringInputVisitor *siv; + Error *local_err = NULL; + + if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0) { + return 0; + } + + siv = string_input_visitor_new(value); + object_property_set(obj, string_input_get_visitor(siv), name, &local_err); + string_input_visitor_cleanup(siv); + + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return 0; +} + +static int object_create(QemuOpts *opts, void *opaque) +{ + const char *type = qemu_opt_get(opts, "qom-type"); + const char *id = qemu_opts_id(opts); + Object *obj; + + g_assert(type != NULL); + + if (id == NULL) { + qerror_report(QERR_MISSING_PARAMETER, "id"); + return -1; + } + + obj = object_new(type); + if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { + return -1; + } + + object_property_add_child(container_get(object_get_root(), "/objects"), + id, obj, NULL); + + return 0; +} + int qemu_init_main_loop(void) { return main_loop_init(); @@ -3199,6 +3247,9 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_qtest_log: qtest_log = optarg; break; + case QEMU_OPTION_object: + opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); + break; default: os_parse_cmd_args(popt->index, optarg); } @@ -3206,6 +3257,10 @@ int main(int argc, char **argv, char **envp) } loc_set_none(); + if (qemu_opts_foreach(qemu_find_opts("object"), object_create, NULL, 0) != 0) { + exit(1); + } + if (machine->hw_version) { qemu_set_version(machine->hw_version); }