Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NsJCg-000388-0j for qemu-devel@nongnu.org; Thu, 18 Mar 2010 13:08:14 -0400 Received: from [199.232.76.173] (port=51370 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsJCe-00036i-9B for qemu-devel@nongnu.org; Thu, 18 Mar 2010 13:08:12 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NsJCc-0007Sj-8r for qemu-devel@nongnu.org; Thu, 18 Mar 2010 13:08:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16817) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NsJCb-0007Sa-PN for qemu-devel@nongnu.org; Thu, 18 Mar 2010 13:08:10 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2IH88pM013508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Mar 2010 13:08:08 -0400 From: Juan Quintela In-Reply-To: <4BA2569A.3040600@redhat.com> (Gerd Hoffmann's message of "Thu, 18 Mar 2010 17:36:42 +0100") References: <20100318064015.GA16973@redhat.com> <4BA24A26.5030602@redhat.com> <4BA2569A.3040600@redhat.com> Date: Thu, 18 Mar 2010 18:08:06 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org, "Michael S. Tsirkin" Gerd Hoffmann wrote: > Hi, > >> But I still think that this is independent that VirtIO being 1st (or >> not) memer of VirtIOBlock. > > There is no strong reason for this other than memory allocation. As > long as virtio_common_init() does the allocation there is no way > around VirtIODevice being the first member. If this changes (and we > must change it if we want embed VirtIODevice and superclasses into > other structs) no reason is left. It is, a 1st look at virtio-pci.c shows static void virtio_pci_reset(DeviceState *d) { VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev); virtio_reset(proxy->vdev); msix_reset(&proxy->pci_dev); } We have to call virtio_reset() that needs a virtio object, and the only thing that we have is a VirtIOPCIProxy. We would have to implement something like: struct VirtioPCIProxy_fields { .... current VirtioPCIProxy fields } struct VirtioPCIProxy { struct VirtioPCIProxy_fields fields; struct VirtIODevice vdev; } struct VirtioBlockPCI { struct VirtiPCIProxy_fields field; struct VirtIOBlock vdev; } Why? All code in virtio.c wants/need a VirtIODevice. All code in virtio-pci.c wants a VirtIODevice also, it is not interested in the specific bits. I can't see how you want to mov VirtIODevice from the 1st place of VirtIOBlock (and similars) without having to rewrite all of virtio-pci.c for each device. > Just changing it for the snake of change isn't a good reason > either. But if it helps cleaning the code we can change it without > running into trouble. You can't cast VirtIODevice to VirtIOBlock any > more, but you don't really want to anyway for type checking reasons. As I have show, from the time that virtio-pci only uses the virtio.c functions (and needs VirtIODevice fields), I don't see how to embed it and share the current functions in virtio-pci.c. Notice that what we really want is create the devices in .qdev.name = "virtio-balloon-pci", .qdev.size = sizeof(VirtIOPCIProxy), as .qdev.name = "virtio-balloon-pci", .qdev.size = sizeof(VirtIOPCIProxy) + sizeof(VirtIOBlock) - sizeof(VirtIODevice), And having a single definition of: struct VirtioPCIProxy { struct VirtIODevice vdev; } Yes, it is ugly/subtle as hell, but no other simple way. You allocate the struct on each virtio-*.c file, where you know the size, and no embed. Or you embed the struct, and replicate lots of code to have it type safe. Any of the two options are worse than current way IMHO. Having to export VirtIOBlock only to know its size looks wrong in addition. Depending on size of the last element is ... too hackish? Later, Juan.