From: Juan Quintela <quintela@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Paul Brook <paul@codesourcery.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups
Date: Mon, 22 Mar 2010 23:16:21 +0100 [thread overview]
Message-ID: <m3k4t4atoq.fsf@trasno.mitica> (raw)
In-Reply-To: <20100322171945.GA19994@redhat.com> (Michael S. Tsirkin's message of "Mon, 22 Mar 2010 19:19:46 +0200")
"Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Mon, Mar 22, 2010 at 03:51:43PM +0000, Paul Brook wrote:
>> > > It's a classic OOP problem.
>> > >
>> > > VirtIOBlock is-a VirtIODevice, VirtIODevice is-a DeviceState
>> > >
>> > > VirtIOPCI is-a PCIDevice, PCIDevice is-a Device State.
>> > >
>> > > But VirtIODevice is-a VirtIOPCI device isn't always true so it can't be
>> > > an is-a relationship. Initially, this was true and that's why the code
>> > > was structured that way. Now that we have two type so of virtio
>> > > transports, we need to change the modelling. It needs to get inverted
>> > > into a has-a relationship. IOW, VirtIOPCI has-a VirtIODevice.
>> > >
>> > > When one device has-a one or more other devices, we model that as a Bus.
>> >
>> > Hmm. Is anything wrong with VirtIOPCIBlock which would be both a
>> > VirtIOBlock and VirtIOPCI device?
>>
>> You need to solve multiple inheritance with common (but divergent) ancestors.
>>
>> A single device may not have more than one DeviceState. i.e. the DeviceState
>> that is part of the VirtIOBlock must be the same as the DeviceState that is
>> part of the PCIDevice. However VirtIOBlock and PCIDevice can not know about
>> each other or about VirtIOPCIBlock.
>>
>> In the current code VirtIOPCIBlock already exists, though only for the
>> purposes of device creation/configuration. The remainder of the code and data
>> structures have clean separation between PCI and Virtio code.
>
> We can have VirtIOPCIBlock have a single DeviceState.
How?
That is the real problem he are having here.
struct VirtIODevice
{
..... No DeviceState at all
};
typedef struct VirtIOBlock
{
VirtIODevice vdev;
....
} VirtIOBlock;
typedef struct {
PCIDevice pci_dev;
VirtIODevice *vdev;
....
} VirtIOPCIProxy;
Not relevant fields for the discussion removed. Virtio-blk taken as an
example, but virtio-net/balloon/serial has the same structure.
Some virtio-pci functions (chosen to not be a vmstate one, but there are
more with this same structure).
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 a something that cames somehow from qdev or PCIDevice and we had
to also do something on the vdev.
Current situation:
- we have "sub-classes" of VirtIODevice (VirtIOBlock in this case).
Everything outside of virtio-blk only cares for VirtIODevice fields.
They are common for ol VirtIO* devices.
Moving VirtIODevice out of offset 0 brings us nothing, until this
reqeriment is removed.
- How do we arrive here? We have three "kinds" of virtio devices:
- pci ones (kvm)
- sysborg (not pci)
- s390
And they share the code except for how to access the bus.
Solutions:
- VirtIOPCIBus and hang devices from there (anthony). Why? because
this is a simulated pci bus, we can implement the features that we
need (not full pci) in the three showed architectures. We will have
VirtIOPCIBLock everywhere, and its VirtIOPCIBus implmentation will
hide the details. Notice that this will make VirtIODevices more
similar to the other kind of devices (see LSI example from Anthony in
other email in the thread, see also mst answer that VirtIO is not like
scsi either for the other point of view).
- Create something like:
struct VirtIOPCIBlock {
PCIDevice pci_dev;
VirtIODevice vdev;
<rest of VirtIOBlock fields>
}
this make lots of things easier, but makes impossible/very difficult
to: - share virtio-pci code (now we dont' have a common layaut
struct).
mst suggestion is to have something like:
struct VirtIOPCIBlock {
PCIDevice pci_dev;
VirtIODevice *vdev;
struct VirtIOBlock block;
}
and having vdev point to the right place. The same for all devices.
My question is how _requiring a zero_ offset for vdev inside
VirtIOBlock is ugly, but having this vdev pointer to an internal part
of the same struct is more elegant (in my book it is worse).
- Just replicate virtio-pci.c for each VirtIO* device and change the
types accordingly. This is way clearer in the sense of not having
pointers to inside the same struct, but it has obvious maintenance
nightmares.
If there are any better ideas around, I haven't seen them yet :-(
As Anthony described it: it is the best of two devils. My point to not
like the mst change: I really think that it would never be used, it is
just over-engenieering. Why do I think that? Because something like
Anthony suggestion (VirtPCIBlock) fits so much better with qemu/qdev
device model. Having that a VirtPCIBlock is-a VirtPCIProxy and a
VirtIODevice don't fit with the qemu model, I haven't seen any other
device that uses _double inheritance_. And here is where the matter of
the discussion with mst appears:
- having single inheritance makes everything simpler -> virtio has to
adapt to single inheritance (me)
- having multiple inheritance is "more natural" to virtio, then we have
to change all the system to be able to allow multiple inherintance,
even if it is more complex, and nothing else uses/needs it (mst).
Later, Juan.
(*): Note that this is VirtIO code, it will not ever use DO_UPCAST()
neither for PCIDevice stuff, just in case qdev requirement
disappears anytime soon.
next prev parent reply other threads:[~2010-03-22 22:16 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-16 18:51 [Qemu-devel] [PATCH 0/9] Virtio cleanups Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 1/9] qemu/pci: document msix_entries_nr field Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 2/9] virtio: Teach virtio-balloon about DO_UPCAST Juan Quintela
2010-03-18 7:29 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 3/9] virtio: Teach virtio-blk " Juan Quintela
2010-03-18 7:29 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 4/9] virtio: Teach virtio-net " Juan Quintela
2010-03-18 7:29 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 5/9] virtio: Use DO_UPCAST instead of a cast Juan Quintela
2010-03-18 7:30 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 6/9] virtio-pci: Remove duplicate test Juan Quintela
2010-03-18 7:25 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-18 8:26 ` Juan Quintela
2010-03-18 8:47 ` Michael S. Tsirkin
2010-03-18 8:59 ` Juan Quintela
2010-03-18 9:11 ` Michael S. Tsirkin
2010-03-18 11:40 ` Juan Quintela
2010-03-18 13:24 ` Michael S. Tsirkin
2010-03-18 13:47 ` Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 7/9] QLIST: Introduce QLIST_COPY_HEAD Juan Quintela
2010-03-16 18:51 ` [Qemu-devel] [PATCH 8/9] virtio-blk: change rq type to VirtIOBlockReq Juan Quintela
2010-03-18 7:27 ` [Qemu-devel] " Michael S. Tsirkin
2010-03-16 18:51 ` [Qemu-devel] [PATCH 9/9] virtio-blk: use QLIST for the list of requests Juan Quintela
2010-03-18 6:40 ` [Qemu-devel] Re: [PATCH 0/9] Virtio cleanups Michael S. Tsirkin
2010-03-18 7:36 ` Juan Quintela
2010-03-18 7:42 ` Michael S. Tsirkin
2010-03-18 8:36 ` Juan Quintela
2010-03-18 9:07 ` Michael S. Tsirkin
2010-03-18 11:53 ` Juan Quintela
2010-03-18 12:33 ` Michael S. Tsirkin
2010-03-18 13:43 ` Juan Quintela
2010-03-18 13:47 ` Michael S. Tsirkin
2010-03-18 14:21 ` Juan Quintela
2010-03-18 17:13 ` Michael S. Tsirkin
2010-03-19 1:41 ` Jamie Lokier
2010-03-21 14:31 ` Michael S. Tsirkin
2010-03-21 18:11 ` Jamie Lokier
2010-03-21 19:16 ` Michael S. Tsirkin
2010-03-22 1:06 ` Juan Quintela
2010-03-22 2:51 ` Anthony Liguori
2010-03-22 13:30 ` Paul Brook
2010-03-22 14:49 ` Anthony Liguori
2010-03-22 14:50 ` Michael S. Tsirkin
2010-03-22 15:03 ` Anthony Liguori
2010-03-22 15:17 ` Michael S. Tsirkin
2010-03-22 15:50 ` Anthony Liguori
2010-03-22 16:16 ` Paul Brook
2010-03-22 18:48 ` Anthony Liguori
2010-03-22 21:00 ` Paul Brook
2010-03-23 1:13 ` Anthony Liguori
2010-03-22 15:51 ` Paul Brook
2010-03-22 17:19 ` Michael S. Tsirkin
2010-03-22 22:16 ` Juan Quintela [this message]
2010-03-23 0:49 ` Paul Brook
2010-03-23 1:16 ` Anthony Liguori
2010-03-23 10:47 ` Michael S. Tsirkin
2010-03-23 11:11 ` Gerd Hoffmann
2010-03-23 11:40 ` Paul Brook
2010-03-23 11:58 ` Michael S. Tsirkin
2010-03-23 12:32 ` Juan Quintela
2010-03-21 19:57 ` Michael S. Tsirkin
2010-03-22 1:13 ` Juan Quintela
2010-03-22 8:37 ` Michael S. Tsirkin
2010-03-18 10:05 ` Michael S. Tsirkin
2010-03-18 15:43 ` Gerd Hoffmann
2010-03-18 16:20 ` Juan Quintela
2010-03-18 16:36 ` Gerd Hoffmann
2010-03-18 17:08 ` Juan Quintela
2010-03-18 17:21 ` Michael S. Tsirkin
2010-03-18 19:37 ` Juan Quintela
2010-03-18 20:07 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3k4t4atoq.fsf@trasno.mitica \
--to=quintela@redhat.com \
--cc=mst@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.