From: "Andreas Färber" <afaerber@suse.de>
To: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
anthony@codemonkey.ws, "Michael S. Tsirkin" <mst@redhat.com>,
jlarrew@linux.vnet.ibm.com, qemu-devel@nongnu.org,
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Amit Shah <amit.shah@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
fred.konrad@greensocs.com
Subject: Re: [Qemu-devel] [PATCH RFT 2/5] virtio: Convert VirtioDevice to QOM realize/unrealize
Date: Sat, 08 Jun 2013 11:55:44 +0200 [thread overview]
Message-ID: <51B2FFA0.6020403@suse.de> (raw)
In-Reply-To: <CAEgOgz6xdH2XOCQ4vpus80Wus6gv-7zpZjbp4paVHg1Vjf3Z3A@mail.gmail.com>
Hi,
Am 08.06.2013 04:22, schrieb Peter Crosthwaite:
> On Sat, Jun 8, 2013 at 4:18 AM, Andreas Färber <afaerber@suse.de> wrote:
>> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
>> index dc6f4e4..409d315 100644
>> --- a/hw/9pfs/virtio-9p-device.c
>> +++ b/hw/9pfs/virtio-9p-device.c
[...]
>> @@ -136,12 +138,16 @@ static Property virtio_9p_properties[] = {
>> DEFINE_PROP_END_OF_LIST(),
>> };
>>
>> -static void virtio_9p_class_init(ObjectClass *klass, void *data)
>> +static void virtio_9p_class_init(ObjectClass *oc, void *data)
>> {
>> - DeviceClass *dc = DEVICE_CLASS(klass);
>> - VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
>> + DeviceClass *dc = DEVICE_CLASS(oc);
>> + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(oc);
>> + V9fsClass *v9c = VIRTIO_9P_CLASS(oc);
>> +
>> + v9c->parent_realize = dc->realize;
>> + dc->realize = virtio_9p_device_realize;
>> +
>> dc->props = virtio_9p_properties;
>> - vdc->init = virtio_9p_device_init;
>> vdc->get_features = virtio_9p_get_features;
>> vdc->get_config = virtio_9p_get_config;
>> }
>> @@ -151,6 +157,7 @@ static const TypeInfo virtio_device_info = {
>> .parent = TYPE_VIRTIO_DEVICE,
>> .instance_size = sizeof(V9fsState),
>> .class_init = virtio_9p_class_init,
>> + .class_size = sizeof(V9fsClass),
>> };
>>
>> static void virtio_9p_register_types(void)
>> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
>> index 1d6eedb..85699a7 100644
>> --- a/hw/9pfs/virtio-9p.h
>> +++ b/hw/9pfs/virtio-9p.h
>> @@ -227,6 +227,15 @@ typedef struct V9fsState
>> V9fsConf fsconf;
>> } V9fsState;
>>
>> +typedef struct V9fsClass {
>> + /*< private >*/
>> + VirtioDeviceClass parent_class;
>> + /*< public >*/
>> +
>> + DeviceRealize parent_realize;
>> +} V9fsClass;
>> +
>> +
>
> If applied tree-wide this change pattern is going to add a lot of
> boiler-plate to all devices. There is capability in QOM to access the
> overridden parent class functions already, so it can be made to work
> without every class having to do this save-and-call trick with
> overridden realize (and friends). How about this:
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 9190a7e..696702a 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -37,6 +37,18 @@ int qdev_hotplug = 0;
> static bool qdev_hot_added = false;
> static bool qdev_hot_removed = false;
>
> +void device_parent_realize(DeviceState *dev, Error **errp)
> +{
> + ObjectClass *class = object_get_class(dev);
> + DeviceClass *dc;
> +
> + class = object_class_get_parent(dc);
> + assert(class);
> + dc = DEVICE_CLASS(class);
> +
> + dc->realize(dev, errp);
> +}
> +
>
> And child class realize fns can call this to realize themselves as the
> parent would. Ditto for reset and unrealize. Then you would only need
> to define struct FooClass when creating new abstractions (or virtual
> functions if your C++).
Indeed, if you check the archives you will find that I suggested the
same in the context of ISA i8254/i8259 or CPUState. ;) Yet Anthony
specifically instructed me to do it this way, referring to GObject.
I then documented the expected process in qdev-core.h and object.h.
Regards,
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2013-06-08 9:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-07 18:18 [Qemu-devel] [PATCH RFT 0/5] QOM realize for virtio Andreas Färber
2013-06-07 18:18 ` [Qemu-devel] [PATCH RFT 1/5] virtio-blk-dataplane: Improve error reporting Andreas Färber
2013-06-10 11:39 ` Stefan Hajnoczi
2013-07-29 20:19 ` Andreas Färber
2013-06-07 18:18 ` [Qemu-devel] [PATCH RFT 2/5] virtio: Convert VirtioDevice to QOM realize/unrealize Andreas Färber
2013-06-08 2:22 ` Peter Crosthwaite
2013-06-08 9:55 ` Andreas Färber [this message]
2013-06-08 12:32 ` Peter Crosthwaite
2013-06-10 2:08 ` Anthony Liguori
2013-06-10 6:30 ` Michael S. Tsirkin
2013-06-12 9:15 ` Andreas Färber
2013-06-13 1:48 ` Peter Crosthwaite
2013-06-18 9:57 ` Peter Crosthwaite
2013-06-09 10:36 ` Michael S. Tsirkin
2013-06-07 18:18 ` [Qemu-devel] [PATCH RFT 3/5] virtio-console: QOM'ify VirtConsole Andreas Färber
2013-06-07 18:18 ` [Qemu-devel] [PATCH RFT 4/5] virtio-console: Use exitfn for virtserialport, too Andreas Färber
2013-07-29 23:25 ` Andreas Färber
2013-06-07 18:19 ` [Qemu-devel] [PATCH RFT 5/5] virtio-serial-port: Convert to QOM realize/unrealize Andreas Färber
2013-06-09 10:39 ` [Qemu-devel] [PATCH RFT 0/5] QOM realize for virtio Michael S. Tsirkin
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=51B2FFA0.6020403@suse.de \
--to=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=amit.shah@redhat.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=anthony@codemonkey.ws \
--cc=fred.konrad@greensocs.com \
--cc=jlarrew@linux.vnet.ibm.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).