From patchwork Wed May 20 15:51:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 474563 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 BB206140293 for ; Thu, 21 May 2015 02:04:14 +1000 (AEST) Received: from localhost ([::1]:53156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv6Tc-0007S0-1w for incoming@patchwork.ozlabs.org; Wed, 20 May 2015 12:04:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv6TJ-0007AT-5a for qemu-devel@nongnu.org; Wed, 20 May 2015 12:03:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yv6TD-0007Lp-Mv for qemu-devel@nongnu.org; Wed, 20 May 2015 12:03:53 -0400 Received: from cantor2.suse.de ([195.135.220.15]:59227 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yv6TD-0007LR-AY for qemu-devel@nongnu.org; Wed, 20 May 2015 12:03:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 01EE2ABB1; Wed, 20 May 2015 16:03:45 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Wed, 20 May 2015 17:51:41 +0200 Message-Id: <1432137106-8295-8-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1432137106-8295-1-git-send-email-afaerber@suse.de> References: <1432137106-8295-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PULL 07/12] vl: Create (most) objects before creating chardev backends 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: "Daniel P. Berrange" 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 right away before anyother backends are created, and only delay creation of those few which have an explicit dependency on the chardevs. Hopefully the set which need delaying will remain small over time. Signed-off-by: Daniel P. Berrange Reviewed-by: Paolo Bonzini Signed-off-by: Andreas Färber --- vl.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/vl.c b/vl.c index 15bccc4..b7c7511 100644 --- a/vl.c +++ b/vl.c @@ -2601,6 +2601,33 @@ static int machine_set_property(const char *name, const char *value, return 0; } + +/* + * Initial object creation happens before all other + * QEMU data types are created. The majority of objects + * can be created at this point. The rng-egd object + * cannot be created here, as it depends on the chardev + * already existing. + */ +static bool object_create_initial(const char *type) +{ + if (g_str_equal(type, "rng-egd")) { + return false; + } + return true; +} + + +/* + * The remainder of object creation happens after the + * creation of chardev, fsdev and device data types. + */ +static bool object_create_delayed(const char *type) +{ + return !object_create_initial(type); +} + + static int object_create(QemuOpts *opts, void *opaque) { Error *err = NULL; @@ -2609,6 +2636,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); @@ -2623,6 +2651,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); @@ -4031,6 +4062,12 @@ int main(int argc, char **argv, char **envp) socket_init(); + if (qemu_opts_foreach(qemu_find_opts("object"), + object_create, + object_create_initial, 0) != 0) { + exit(1); + } + if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0) exit(1); #ifdef CONFIG_VIRTFS @@ -4050,7 +4087,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_delayed, 0) != 0) { exit(1); }