From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFuE6-0000zB-BK for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:46:58 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFuE1-0000s7-D8 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:46:57 -0500 Received: from [199.232.76.173] (port=43292 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFuE1-0000rq-23 for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:46:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56871) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NFuE0-0007Lm-Jg for qemu-devel@nongnu.org; Wed, 02 Dec 2009 13:46:52 -0500 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 nB2Ikpsc009531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Dec 2009 13:46:51 -0500 Date: Wed, 2 Dec 2009 20:44:11 +0200 From: "Michael S. Tsirkin" Message-ID: <20091202184410.GC3984@redhat.com> References: <20091202134153.GC18193@redhat.com> <20091202181911.GB3949@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 06/41] virtio: Use DO_UPCAST instead of a cast List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org On Wed, Dec 02, 2009 at 07:42:35PM +0100, Juan Quintela wrote: > "Michael S. Tsirkin" wrote: > > On Wed, Dec 02, 2009 at 07:19:17PM +0100, Juan Quintela wrote: > >> "Michael S. Tsirkin" wrote: > >> > On Wed, Dec 02, 2009 at 01:04:04PM +0100, Juan Quintela wrote: > >> >> virtio_common_init() creates a struct with the right size, DO_UPCAST > >> >> is the appropiate thing here > >> >> > >> >> Signed-off-by: Juan Quintela > >> > > >> > BTW why not container_of? That one does not require > >> > field to be at the beginning of structure. > >> > >> VirtIO devices (and PCIDevices) are declared in this way: > >> > >> typedef struct VirtIOBalloon > >> { > >> VirtIODevice vdev; > >> VirtQueue *ivq, *dvq; > >> uint32_t num_pages; > >> uint32_t actual; > >> } VirtIOBalloon; > >> > >> > >> I.e. the virtioDevice is always the 1st element, otherwise things don't > >> work. There are code that requires it to be the 1st element. > > > > I know. But I think we should slowly fix these assumptions, and not > > introduce more of them. IOW: don't use DO_UPCAST. > > It is inherent in how to implement OOP in C. You want to use things as > pci devices and as pci specific devices. Then you need to put the pci > common fields at the beggining. Yes, for virtio devices they want to be > pci and virtio devices, but neither pci or virtio nor qemu in general > allow to be derived of two types (a.k.a. as multiple inheritance). > > I think that we should continue using DO_UPCAST() until there are some > design that allows you to change that. This particular case "requires" > that VirtioDevice is the 1st field of the struct. If you change the > code enough to make container_of() work, doing the > s/DO_UPCAST/container_of/ is going to be the less of your problems. > > Later, Juan. I don't understand. container_of is just more generic than DO_UPCAST. So why *ever* use DO_UPCAST? Let's get rid of it. -- MST