From patchwork Fri Oct 26 11:01:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 194438 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 580552C009A for ; Fri, 26 Oct 2012 22:13:16 +1100 (EST) Received: from localhost ([::1]:44453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRhh3-0001jC-8g for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2012 07:03:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRhgM-000095-Gu for qemu-devel@nongnu.org; Fri, 26 Oct 2012 07:02:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TRhgH-00031h-3s for qemu-devel@nongnu.org; Fri, 26 Oct 2012 07:02:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRhgG-00031K-Rf for qemu-devel@nongnu.org; Fri, 26 Oct 2012 07:02:25 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9QB2N3N001292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 26 Oct 2012 07:02:23 -0400 Received: from localhost (ovpn-113-78.phx2.redhat.com [10.3.113.78]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9QB2KqW030466; Fri, 26 Oct 2012 07:02:21 -0400 From: Amit Shah To: Anthony Liguori Date: Fri, 26 Oct 2012 16:31:39 +0530 Message-Id: <2e6c5c33faf5643de12a1a348a8663fe705e447a.1351248724.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Anthony Liguori , qemu list Subject: [Qemu-devel] [PATCH 3/8] 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 From: Anthony Liguori 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 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index cd1ec21..d695bdf 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -653,6 +653,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, @@ -669,6 +678,7 @@ static QemuOptsList *vm_config_groups[32] = { &qemu_boot_opts, &qemu_iscsi_opts, &qemu_sandbox_opts, + &qemu_object_opts, NULL, }; diff --git a/qemu-options.hx b/qemu-options.hx index 46f0539..b72151e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2852,6 +2852,14 @@ STEXI Enable FIPS 140-2 compliance mode. ETEXI +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 ee3c43a..eabf47b 100644 --- a/vl.c +++ b/vl.c @@ -168,6 +168,7 @@ int main(int argc, char **argv) #include "osdep.h" #include "ui/qemu-spice.h" +#include "qapi/string-input-visitor.h" //#define DEBUG_NET //#define DEBUG_SLIRP @@ -2357,6 +2358,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(); @@ -3308,6 +3356,9 @@ int main(int argc, char **argv, char **envp) if (!opts) { exit(0); } + break; + case QEMU_OPTION_object: + opts = qemu_opts_parse(qemu_find_opts("object"), optarg, 1); break; default: os_parse_cmd_args(popt->index, optarg); @@ -3319,6 +3370,9 @@ int main(int argc, char **argv, char **envp) if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) { exit(1); } + if (qemu_opts_foreach(qemu_find_opts("object"), object_create, NULL, 0) != 0) { + exit(1); + } if (machine == NULL) { fprintf(stderr, "No machine found.\n");