From patchwork Mon Sep 22 11:26:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 37674 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1E4A920C03 for ; Mon, 22 Sep 2014 11:28:07 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id q1sf3201383lam.10 for ; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=UJ7jBDT8SrXZh96Z6pfSiyxqvlcU2v0ofkFzY5EJuIM=; b=I0HZExTIapi/A5m1LKyO31ZPBHwQMRLxxcUrgfRq0Kdm13+q6XX5Xqt+OyBGsyTDzq /m0VR2nPfIQNJ0iRkqmpG1kkZ72P/HhgXsWEyTZnVOVNd2y+tJIFdElGvqQYBET1xZ+6 Wl/BKOKpbNmrPnPLD1dYbps15J1wPnRaCmmpxV0Hv+S5J6/E6m1K1HqlninCz8gqrPlb /FQCXAv13o8kol2j8Hu1jgcalMyEot+MSIjv3g8rQFzU2JTOf1p+6oFxB4o7HLO5YA5D F7oYpwArqNJvdXE0NgyXH9Ol9HlnwFjBu9c0VQScJTq3QHS+zV0zbm2NjqW8YlBLtBSo 9Yiw== X-Gm-Message-State: ALoCoQn9G8BG4eMKKvGKwbzqbDB4yVkA1AB4rZJThIrBMer2Iaw9Nn/zA85FViOy26C04gS6zcGK X-Received: by 10.180.108.70 with SMTP id hi6mr1973505wib.4.1411385286908; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.166 with SMTP id an6ls530609lac.71.gmail; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) X-Received: by 10.112.198.131 with SMTP id jc3mr13380025lbc.42.1411385286590; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com [209.85.215.44]) by mx.google.com with ESMTPS id jd1si14025725lbc.118.2014.09.22.04.28.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Sep 2014 04:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id q1so6519919lam.31 for ; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) X-Received: by 10.112.75.233 with SMTP id f9mr1885517lbw.102.1411385286215; Mon, 22 Sep 2014 04:28:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp217552lbb; Mon, 22 Sep 2014 04:28:05 -0700 (PDT) X-Received: by 10.224.125.4 with SMTP id w4mr21666840qar.20.1411385285109; Mon, 22 Sep 2014 04:28:05 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l10si8702748qac.103.2014.09.22.04.28.04 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 22 Sep 2014 04:28:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:44991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW1mm-0006tV-8o for patch@linaro.org; Mon, 22 Sep 2014 07:28:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW1lm-0005sw-OV for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:27:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XW1lf-0003Uf-PR for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:27:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XW1lf-0003PV-J4 for qemu-devel@nongnu.org; Mon, 22 Sep 2014 07:26:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8MBQmwr008782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 22 Sep 2014 07:26:48 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8MBQeoU008311; Mon, 22 Sep 2014 07:26:45 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org, marcel.a@redhat.com, afaerber@suse.de, mst@redhat.com, peter.maydell@linaro.org, lersek@redhat.com Date: Mon, 22 Sep 2014 13:26:34 +0200 Message-Id: <1411385195-13495-2-git-send-email-lersek@redhat.com> In-Reply-To: <1411385195-13495-1-git-send-email-lersek@redhat.com> References: <1411385195-13495-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] save registration order of machine types 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Commit 261747f1 ("vl: Use MachineClass instead of global QEMUMachine list") broke the ordering of the machine types in the user-visible output of qemu-system-XXXX -M \? This occurred because registration was rebased from a manually maintained linked list to GLib hash tables: qemu_register_machine() type_register() type_register_internal() type_table_add() g_hash_table_insert() and because the listing was rebased accordingly, from the traversal of the list to the traversal of the hash table (rendered as an ad-hoc list): machine_parse() object_class_get_list(TYPE_MACHINE) object_class_foreach() g_hash_table_foreach() The current order is a "random" one, for practical purposes, which is annoying for users. The first idea to restore ordering is to sort the ad-hoc list in machine_parse() by "MachineClass.name". Such a name-based ordering would have to be reverse, so that more recent versioned machine types appear higher on the list than older versioned machine types (eg. with qemu-system-x86_64). However, such a reverse sort wreaks havoc between non-versioned machine types (such as those of qemu-system-aarch64). The behavior prior to commit 261747f1 was that: (1) when a given function called qemu_register_machine() several times in sequence, such as in: machine_init(some_machine_init) some_machine_init() qemu_register_machine(...) qemu_register_machine(...) qemu_register_machine(...) then those registration calls influenced the relative order of those machine types directly, and (2) the ordering between functions passed to machine_init() was unspecified. We can restore this behavior by capturing the serial number of the qemu_register_machine() invocation in the MachineClass that it registers. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1145042 Signed-off-by: Laszlo Ersek --- include/hw/boards.h | 2 ++ include/sysemu/sysemu.h | 2 ++ hw/i386/pc.c | 2 ++ vl.c | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/include/hw/boards.h b/include/hw/boards.h index dfb6718..0665ca7 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -41,6 +41,7 @@ struct QEMUMachine { const char *default_boot_order; GlobalProperty *compat_props; const char *hw_version; + unsigned registration_order; }; void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, @@ -102,6 +103,7 @@ struct MachineClass { HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); + unsigned registration_order; }; /** diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index d8539fd..5958b6b 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -24,6 +24,8 @@ int qemu_uuid_parse(const char *str, uint8_t *uuid); #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" #define UUID_NONE "00000000-0000-0000-0000-000000000000" +extern unsigned machtype_registration_order; + bool runstate_check(RunState state); void runstate_set(RunState new_state); int runstate_is_running(void); diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 2c2e9dc..95ccce3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1537,6 +1537,7 @@ static void pc_generic_machine_class_init(ObjectClass *oc, void *data) mc->default_boot_order = qm->default_boot_order; mc->compat_props = qm->compat_props; mc->hw_version = qm->hw_version; + mc->registration_order = qm->registration_order; } void qemu_register_pc_machine(QEMUMachine *m) @@ -1549,6 +1550,7 @@ void qemu_register_pc_machine(QEMUMachine *m) .class_data = (void *)m, }; + m->registration_order = machtype_registration_order++; type_register(&ti); g_free(name); } diff --git a/vl.c b/vl.c index dc792fe..b62d9b2 100644 --- a/vl.c +++ b/vl.c @@ -1596,8 +1596,11 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->default_boot_order = qm->default_boot_order; mc->compat_props = qm->compat_props; mc->hw_version = qm->hw_version; + mc->registration_order = qm->registration_order; } +unsigned machtype_registration_order; + int qemu_register_machine(QEMUMachine *m) { char *name = g_strconcat(m->name, TYPE_MACHINE_SUFFIX, NULL); @@ -1608,6 +1611,7 @@ int qemu_register_machine(QEMUMachine *m) .class_data = (void *)m, }; + m->registration_order = machtype_registration_order++; type_register(&ti); g_free(name);