From patchwork Fri Apr 17 14:22:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 462064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A66501401DA for ; Sat, 18 Apr 2015 00:27:25 +1000 (AEST) Received: from localhost ([::1]:41660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj7Eo-0003lA-Ph for incoming@patchwork.ozlabs.org; Fri, 17 Apr 2015 10:27:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj7BW-0005AP-Ji for qemu-devel@nongnu.org; Fri, 17 Apr 2015 10:24:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yj7BS-0003C8-9a for qemu-devel@nongnu.org; Fri, 17 Apr 2015 10:23:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yj7BS-0003C4-4h for qemu-devel@nongnu.org; Fri, 17 Apr 2015 10:23:54 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id D24497D for ; Fri, 17 Apr 2015 14:23:53 +0000 (UTC) Received: from localhost.localdomain.com (vpn1-5-19.ams2.redhat.com [10.36.5.19]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3HENPZC011852; Fri, 17 Apr 2015 10:23:51 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Fri, 17 Apr 2015 15:22:06 +0100 Message-Id: <1429280557-8887-4-git-send-email-berrange@redhat.com> In-Reply-To: <1429280557-8887-1-git-send-email-berrange@redhat.com> References: <1429280557-8887-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gerd Hoffmann , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v1 RFC 03/34] qom: create objects in two phases 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 Some types of object must be created before chardevs, other types of object must be created after chardevs. As such there is no option but to create objects in two phases. This takes the decision to create as many object types as possible in the first phase, and only delay those which have a dependency on the chardevs. Hopefully the set which need delaying will remain small. Signed-off-by: Daniel P. Berrange --- vl.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 74c2681..8aac4ee 100644 --- a/vl.c +++ b/vl.c @@ -2591,6 +2591,22 @@ static int machine_set_property(const char *name, const char *value, return 0; } + +static bool object_create_phase1(const char *type) +{ + /* rng-egd requires that -chardev is processed first, + * so we must delay it until phase2 */ + if (g_str_equal(type, "rng-egd")) { + return false; + } + return true; +} + +static bool object_create_phase2(const char *type) +{ + return !object_create_phase1(type); +} + static int object_create(QemuOpts *opts, void *opaque) { Error *err = NULL; @@ -2599,6 +2615,7 @@ static int object_create(QemuOpts *opts, void *opaque) void *dummy = NULL; OptsVisitor *ov; QDict *pdict; + bool (*type_predicate)(const char *) = opaque; ov = opts_visitor_new(opts); pdict = qemu_opts_to_qdict(opts, NULL); @@ -2613,6 +2630,9 @@ static int object_create(QemuOpts *opts, void *opaque) if (err) { goto out; } + if (!type_predicate(type)) { + goto out; + } qdict_del(pdict, "id"); visit_type_str(opts_get_visitor(ov), &id, "id", &err); @@ -4008,6 +4028,12 @@ int main(int argc, char **argv, char **envp) socket_init(); + if (qemu_opts_foreach(qemu_find_opts("object"), + object_create, + object_create_phase1, 0) != 0) { + exit(1); + } + if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) exit(1); #ifdef CONFIG_VIRTFS @@ -4027,7 +4053,8 @@ int main(int argc, char **argv, char **envp) } if (qemu_opts_foreach(qemu_find_opts("object"), - object_create, NULL, 0) != 0) { + object_create, + object_create_phase2, 0) != 0) { exit(1); }