Received: from eggs.gnu.org ([2001:4830:134:3::10]:42994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpHZ-00031n-Nr for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azpHT-00046Y-Ep for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpHT-00046C-9u for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:43 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6ACA47049 for ; Mon, 9 May 2016 17:47:42 +0000 (UTC) From: Marcel Apfelbaum Date: Mon, 9 May 2016 20:47:35 +0300 Message-Id: <1462816056-17463-3-git-send-email-marcel@redhat.com> In-Reply-To: <1462816056-17463-1-git-send-email-marcel@redhat.com> References: <1462816056-17463-1-git-send-email-marcel@redhat.com> Subject: [Qemu-devel] [PATCH RFC 2/3] vl.c: create devices by their creation priority flag List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: marcel@redhat.com, pbonzini@redhat.com, mst@redhat.com Create the devices by their DeviceCreationPriority order instead of the input order, however devices with the same priority will be created in the same order as before. Signed-off-by: Marcel Apfelbaum --- vl.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/vl.c b/vl.c index 3629336..1c650b9 100644 --- a/vl.c +++ b/vl.c @@ -2341,20 +2341,58 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp) return qdev_device_help(opts); } -static int device_init_func(void *opaque, QemuOpts *opts, Error **errp) +static int device_insert_by_priority_func(void *opaque, QemuOpts *opts, + Error **errp) { - Error *err = NULL; - DeviceState *dev; + GList **dev_list = opaque; + GList *l; + int dev_prio = qdev_device_get_priority(opts, errp); - dev = qdev_device_add(opts, &err); - if (!dev) { - error_report_err(err); + if (dev_prio < 0) { return -1; } - object_unref(OBJECT(dev)); + + for (l = *dev_list; l != NULL; l = g_list_next(l)) { + int prio = qdev_device_get_priority((QemuOpts *)l->data, errp); + if (prio >= dev_prio) { + continue; + } + break; + } + + *dev_list = g_list_insert_before(*dev_list, l, opts); + return 0; } +static int devices_init(void) +{ + GList *dev_list, *l; + Error *err = NULL; + + if (qemu_opts_foreach(qemu_find_opts("device"), + device_insert_by_priority_func, &dev_list, &err)) { + goto out_err; + } + + for (l = dev_list; l != NULL; l = g_list_next(l)) { + DeviceState *dev = qdev_device_add((QemuOpts *)l->data, &err); + if (!dev) { + goto out_err; + } + + object_unref(OBJECT(dev)); + } + + g_list_free(dev_list); + return 0; + +out_err: + g_list_free(dev_list); + error_report_err(err); + return -1; +} + static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp) { Error *local_err = NULL; @@ -4535,8 +4573,7 @@ int main(int argc, char **argv, char **envp) igd_gfx_passthru(); /* init generic devices */ - if (qemu_opts_foreach(qemu_find_opts("device"), - device_init_func, NULL, NULL)) { + if (devices_init()) { exit(1); } -- 2.4.3