Received: from eggs.gnu.org ([2001:4830:134:3::10]:40064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVyPN-0002WS-4l for qemu-devel@nongnu.org; Mon, 22 Sep 2014 03:51:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVyPH-0005zY-Py for qemu-devel@nongnu.org; Mon, 22 Sep 2014 03:51:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60516) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVyPH-0005yl-I4 for qemu-devel@nongnu.org; Mon, 22 Sep 2014 03:51:35 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8M7pTTu028712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 22 Sep 2014 03:51:29 -0400 From: Markus Armbruster References: <1411063146-24058-1-git-send-email-jsnow@redhat.com> <1411063146-24058-3-git-send-email-jsnow@redhat.com> <87mw9wq79a.fsf@blackfin.pond.sub.org> <1411292054.3666.78.camel@localhost.localdomain> Date: Mon, 22 Sep 2014 09:51:26 +0200 In-Reply-To: <1411292054.3666.78.camel@localhost.localdomain> (Marcel Apfelbaum's message of "Sun, 21 Sep 2014 12:34:14 +0300") Message-ID: <87y4tcum81.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [RFC v2 2/3] Add units-per-idebus property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcel Apfelbaum Cc: John Snow , qemu-devel@nongnu.org Marcel Apfelbaum writes: > On Fri, 2014-09-19 at 11:39 +0200, Markus Armbruster wrote: >> John Snow writes: >> >> > Signed-off-by: John Snow [...] >> > @@ -1583,6 +1584,7 @@ static void machine_class_init(ObjectClass *oc, void *data) >> > mc->hot_add_cpu = qm->hot_add_cpu; >> > mc->kvm_type = qm->kvm_type; >> > mc->block_default_type = qm->block_default_type; >> > + mc->units_per_idebus = qm->units_per_idebus; >> > mc->max_cpus = qm->max_cpus; >> > mc->no_serial = qm->no_serial; >> > mc->no_parallel = qm->no_parallel; >> >> Not sufficient! You missed the duplicated code in >> pc_generic_machine_class_init(). That something was missing was quite >> obvious in my testing, although what was missing was not. This is the >> fix I mentioned above. >> >> Marcel, you touched both copies recently. Do you know why we need two >> of them? And why do we copy from QEMUMachine to MachineClass member by >> member? Why can't we just point from MachineClass to QEMUMachine? Or >> at least embed the struct so we can copy it wholesale? > Hi Markus, > > I'll try to explain the design: > 1. MachineClass should not be aware of QEMUMachine. The objective here is to > eliminate QEMUMachine and it should not be part of MachineClass at any cost. > 2. The plan is like this: > - The machine types that are not yet QOMified will be QOMified on the fly > by qemu_register_machine (vl.c) that calls machine_class_init and matches > QEMUMachine fields with MachineClass fields. > - This mechanism will be removed when all machines are QOMified. (never? :) ) Okay %-) > - Machines that are QOMified will not reach this code at all, but follow > the normal QOM path. > As you can see, by design there is no duplication. > > Now let's get to PC machines case: > - This is a "weird" use case of hybrid QOMifying. > - All that the author wanted was to have all the PC machines > derive from type TYPE_PC_MACHINE, but didn't have the time/resources/will > to go over every PC machine and QOMify it. But he did need the common class. > - His implementation: > - He couldn't use the generic qemu_register_machine because the PC machines > would not have derived from MACHINE_PC_TYPE. > - So he used the following logic: > - from the vl.c point of view, the PC machines are QOMified, so the > PC machines registration *does not reach vl.c". > - from the PC machines point of view, they remained not QOMified. > - qemu_register_pc_machine mimics vl.c registration *only for pc machines* > and has to copy the fields by itself. Plus, it gives the PC machines a common > base class, the thing he was interested in in the first place. Artifact of this hackery: two identical static functions: vl.c's machine_class_init() and pc.c's pc_generic_machine_class_init(). Trap for the unwary, and it caught John. Unless there are plans to get rid of pc_generic_machine_class_init() fairly soon, I'd recommend to give machine_class_init() external linkage with a suitable comment, and drop pc_generic_machine_class_init(). > I hope it helped, Sure did! I checked the CodeTransitions Wiki page. It covers this work, and points to http://wiki.qemu.org/Features/QOM/Machine for more information. Good.