From: "Andreas Färber" <afaerber@suse.de>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property
Date: Wed, 12 Dec 2012 17:51:18 +0100 [thread overview]
Message-ID: <50C8B606.4000102@suse.de> (raw)
In-Reply-To: <20121212142905.GA5334@otherpad.lan.raisama.net>
Am 12.12.2012 15:29, schrieb Eduardo Habkost:
> On Mon, Nov 26, 2012 at 01:12:16AM +0100, Andreas Färber wrote:
>> Based on earlier patches by Paolo and me, introduce the QOM realizefn at
>> device level only, as requested by Anthony.
>>
>> For now this just wraps the qdev initfn.
...which it deprecates.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> Cc: Anthony Liguori <anthony@codemonkey.ws>
>> ---
>> hw/qdev-core.h | 4 +++
>> hw/qdev.c | 100 ++++++++++++++++++++++++++++++++++++++++++--------------
>> 2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)
>>
>> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
>> index f0d3a5e..580a811 100644
>> --- a/hw/qdev-core.h
>> +++ b/hw/qdev-core.h
>> @@ -29,6 +29,8 @@ enum {
>> typedef int (*qdev_initfn)(DeviceState *dev);
>> typedef int (*qdev_event)(DeviceState *dev);
>> typedef void (*qdev_resetfn)(DeviceState *dev);
>> +typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
>> +typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
>>
>> struct VMStateDescription;
>>
>> @@ -47,6 +49,8 @@ typedef struct DeviceClass {
>> const struct VMStateDescription *vmsd;
>>
>> /* Private to qdev / bus. */
>> + DeviceRealize realize;
>> + DeviceUnrealize unrealize;
>> qdev_initfn init;
>> qdev_event unplug;
>> qdev_event exit;
>> diff --git a/hw/qdev.c b/hw/qdev.c
>> index bce6ad5..d7b6320 100644
>> --- a/hw/qdev.c
>> +++ b/hw/qdev.c
>> @@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
>> Return 0 on success. */
>> int qdev_init(DeviceState *dev)
>> {
>> - DeviceClass *dc = DEVICE_GET_CLASS(dev);
>> - int rc;
>> + Error *local_err = NULL;
>>
>> assert(!dev->realized);
>>
>> - rc = dc->init(dev);
>> - if (rc < 0) {
>> + object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
>> + if (local_err != NULL) {
>> + error_free(local_err);
>> object_delete(OBJECT(dev));
>> - return rc;
>> + return -1;
>> }
>> + return 0;
>> +}
>>
>> - if (!OBJECT(dev)->parent) {
>> - static int unattached_count = 0;
>> - gchar *name = g_strdup_printf("device[%d]", unattached_count++);
>> -
>> - object_property_add_child(container_get(qdev_get_machine(),
>> - "/unattached"),
>> - name, OBJECT(dev), NULL);
>> - g_free(name);
>> - }
>> +static void device_realize(DeviceState *dev, Error **err)
>> +{
>> + DeviceClass *dc = DEVICE_GET_CLASS(dev);
>>
>> - if (qdev_get_vmsd(dev)) {
>> - vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
>> - dev->instance_id_alias,
>> - dev->alias_required_for_version);
>> - }
>> - dev->realized = true;
>> - if (dev->hotplugged) {
>> - device_reset(dev);
>> + if (dc->init) {
>> + int rc = dc->init(dev);
>> + if (rc < 0) {
>> + error_setg(err, "Device initialization failed.");
>> + return;
>> + }
>> }
>> - return 0;
>> }
> [...]
>> +static void device_class_init(ObjectClass *oc, void *data)
>> +{
>> + DeviceClass *dc = DEVICE_CLASS(oc);
>> + dc->realize = device_realize;
>> +}
>> +
> [...]
>
> Stupid question: what exactly is the difference in capabilities and
> semantics between DeviceClass.init() and DeviceClass.realize()? They
> look exactly the same to me, from a first look. On which cases would
> somebody use the former instead of the latter, and why?
Wherever possible, users should use the new DeviceClass::realize.
"init" or "initfn" clashes with QOM's instance_init name-wise.
As shown in this series, instance_init can be used in devices today
already, without having realize.
The distinction between instance_init and realize is that the former
initializes simple variables, sets up properties and anything the user
may want to modify, then realize processes these variables and is able
to fail and report the cause of failure (unlike DeviceClass::init).
In the isa patch after all the boring QOM'ish preparations, isa-device's
class_init overwrites DeviceClass:realize, thereby no longer invoking
any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus,
etc. would need to be done in further steps, but a) this is work, b) the
series shouldn't get too long for review/merge and c) it all depends on
in which class and thereby with which signature we want to have realize
- DeviceClass::realize(DeviceState *, Error **) or
ObjectClass::realize(Object *, Error **).
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:[~2012-12-12 16:51 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-26 0:12 [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM Andreas Färber
2012-11-26 7:20 ` Paolo Bonzini
2012-11-26 11:52 ` Andreas Färber
2012-11-26 12:04 ` Paolo Bonzini
2012-11-26 0:12 ` [Qemu-devel] [RFC 02/34] qbus: QOM'ify qbus_realize() Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 03/34] qdev: Fold state enum into bool realized Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property Andreas Färber
2012-12-12 14:29 ` Eduardo Habkost
2012-12-12 16:51 ` Andreas Färber [this message]
2012-12-12 18:16 ` Eduardo Habkost
2012-12-12 18:25 ` Andreas Färber
2012-12-12 18:44 ` Eduardo Habkost
2012-11-26 0:12 ` [Qemu-devel] [RFC 05/34] isa: Split off instance_init for ISADevice Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 06/34] applesmc: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 07/34] cirrus_vga: QOM'ify ISA Cirrus VGA Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 08/34] debugcon: QOM'ify ISA debug console Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 09/34] fdc: QOM'ify ISA floppy controller Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 10/34] i82374: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [PATCH 11/34] i8259: Fix PIC_COMMON() macro Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 12/34] i8259: QOM cleanups Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 13/34] ide: QOM'ify ISA IDE Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 14/34] m48t59: QOM'ify ISA M48T59 NVRAM Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify Andreas Färber
2013-04-22 15:42 ` Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 16/34] ne2000-isa: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 17/34] parallel: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 18/34] pc: QOM'ify port 92 Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 19/34] pckbd: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 20/34] pcspk: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 21/34] sb16: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 22/34] serial: QOM'ify ISA serial Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 23/34] sga: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 24/34] vga-isa: QOM'ify ISA VGA Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 25/34] vmmouse: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 26/34] vmport: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 27/34] wdt_ib700: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 28/34] isa: Use realizefn for ISADevice Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 29/34] i8254: QOM'ify Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 30/34] kvm/i8254: QOM'ify some more Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 31/34] i8254: Convert PITCommonState to QOM realizefn Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 32/34] i8259: QOM'ify some more Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 33/34] kvm/i8259: " Andreas Färber
2012-11-26 0:12 ` [Qemu-devel] [RFC 34/34] i8259: Convert PICCommonState to use QOM realizefn Andreas Färber
2012-12-04 22:19 ` [Qemu-devel] [RFC 00/34] QOM realize, device-only plus ISA conversion Andreas Färber
2013-01-02 14:48 ` 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=50C8B606.4000102@suse.de \
--to=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.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 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).