From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsZIk-0007Yg-AM for qemu-devel@nongnu.org; Wed, 13 May 2015 12:14:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsZIh-0003Fd-2G for qemu-devel@nongnu.org; Wed, 13 May 2015 12:14:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsZIg-0003FL-TV for qemu-devel@nongnu.org; Wed, 13 May 2015 12:14:27 -0400 From: "Daniel P. Berrange" Date: Wed, 13 May 2015 17:14:04 +0100 Message-Id: <1431533649-23115-4-git-send-email-berrange@redhat.com> In-Reply-To: <1431533649-23115-1-git-send-email-berrange@redhat.com> References: <1431533649-23115-1-git-send-email-berrange@redhat.com> Subject: [Qemu-devel] [PATCH v4 3/8] vl: create (most) objects before creating chardev backends List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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 --- 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); } -- 2.1.0