From patchwork Mon May 9 17:47:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 9048761 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5928E9F1C3 for ; Mon, 9 May 2016 17:49:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B508C2010E for ; Mon, 9 May 2016 17:49:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1FF0200FE for ; Mon, 9 May 2016 17:49:26 +0000 (UTC) Received: from localhost ([::1]:42697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpJ8-0005ya-9E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 13:49:26 -0400 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) Received: from work.redhat.com (vpn-203-24.tlv.redhat.com [10.35.203.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u49HlaY7028811; Mon, 9 May 2016 13:47:41 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 09 May 2016 17:47:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 2/3] vl.c: create devices by their creation priority flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, pbonzini@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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); }