From: "Andreas Färber" <afaerber@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>,
Anthony Liguori <anthony@codemonkey.ws>
Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 18/21] qdev: convert busses to QEMU Object Model
Date: Thu, 24 May 2012 18:48:27 +0200 [thread overview]
Message-ID: <4FBE665B.8070900@suse.de> (raw)
In-Reply-To: <1335958273-769-19-git-send-email-pbonzini@redhat.com>
Am 02.05.2012 13:31, schrieb Paolo Bonzini:
> From: Anthony Liguori <aliguori@us.ibm.com>
>
> This is far less interesting than it sounds. We simply add an Object to each
> BusState and then register the types appropriately. Most of the interesting
> refactoring will follow in the next patches.
>
> Since we're changing fundamental type names (BusInfo -> BusClass), it all needs
> to convert at once. Fortunately, not a lot of code is affected.
>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Thanks, I applied this to qom-next with two changes:
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-next
First, I enforced all new TypeInfos to be static const rather than just
static. If someone has time to fix up all the static ones in the code
base to not set bad examples that would be appreciated - they needed to
be writable originally while transitioning from qdev to QOM.
Second, I applied the following patch on top, backporting
object_delete() / object_finalize() from "qbus: initialize in standard
way", since we introduce object_new() usage here:
diff --git a/hw/pci.c b/hw/pci.c
index c5d3100..b2afcf6 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -295,7 +295,7 @@ PCIBus *pci_bus_new(DeviceState *parent, const char
*name,
PCIBus *bus;
bus = g_malloc0(sizeof(*bus));
- bus->qbus.qdev_allocated = 1;
+ bus->qbus.glib_allocated = true;
pci_bus_new_inplace(bus, parent, name, address_space_mem,
address_space_io, devfn_min);
return bus;
diff --git a/hw/qdev.c b/hw/qdev.c
index 63baa0a..63012b5 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -423,7 +423,7 @@ BusState *qbus_create(const char *typename,
DeviceState *parent, const char *nam
BusState *bus;
bus = BUS(object_new(typename));
- bus->qdev_allocated = 1;
+ bus->qom_allocated = true;
do_qbus_create_inplace(bus, typename, parent, name);
return bus;
}
@@ -443,8 +443,13 @@ void qbus_free(BusState *bus)
qemu_unregister_reset(qbus_reset_all_fn, bus);
}
g_free((void*)bus->name);
- if (bus->qdev_allocated) {
- g_free(bus);
+ if (bus->qom_allocated) {
+ object_delete(OBJECT(bus));
+ } else {
+ object_finalize(OBJECT(bus));
+ if (bus->glib_allocated) {
+ g_free(bus);
+ }
}
}
diff --git a/hw/qdev.h b/hw/qdev.h
index 0da4b74..f3dd004 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -100,12 +100,19 @@ struct BusClass {
int (*reset)(BusState *bus);
};
+/**
+ * BusState:
+ * @qom_allocated: Indicates whether the object was allocated by QOM.
+ * @glib_allocated: Indicates whether the object was initialized in-place
+ * yet is expected to be freed with g_free().
+ */
struct BusState {
Object obj;
DeviceState *parent;
const char *name;
int allow_hotplug;
- int qdev_allocated;
+ bool qom_allocated;
+ bool glib_allocated;
QTAILQ_HEAD(ChildrenHead, DeviceState) children;
QLIST_ENTRY(BusState) sibling;
};
diff --git a/hw/sysbus.c b/hw/sysbus.c
index 369ee44..2347f51 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -274,7 +274,7 @@ static void main_system_bus_create(void)
main_system_bus = g_malloc0(system_bus_info.instance_size);
qbus_create_inplace(main_system_bus, TYPE_SYSTEM_BUS, NULL,
"main-system-bus");
- main_system_bus->qdev_allocated = 1;
+ main_system_bus->glib_allocated = true;
}
BusState *sysbus_get_default(void)
I admit that qom_allocated vs. glib_allocated is slightly ugly but it is
more correct. If memory serves me correctly there was talk of
hotplugging PCI host controllers on pseries for passthrough or
something, so properly cleaning up seems worth the additional ~four bytes.
Fix-ups welcome - maybe use an enum or, better, fix the PCIBus
allocation scheme so that we can drop glib_allocated (SysBus is asserted
not to be freed).
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:[~2012-05-24 16:51 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-02 11:30 [Qemu-devel] [PATCH 00/21] qbus QOM conversion, rebased on top of my patches Paolo Bonzini
2012-05-02 11:30 ` [Qemu-devel] [PATCH 01/21] qom: documentation addition Paolo Bonzini
2012-05-02 11:59 ` Andreas Färber
2012-05-11 2:08 ` Andreas Färber
2012-05-02 11:30 ` [Qemu-devel] [PATCH 02/21] qom: add object_class_get_parent Paolo Bonzini
2012-05-02 12:21 ` Andreas Färber
2012-05-11 2:25 ` Andreas Färber
2012-05-02 11:30 ` [Qemu-devel] [PATCH 03/21] qom: add class_base_init Paolo Bonzini
2012-05-14 21:34 ` Andreas Färber
2012-05-02 11:30 ` [Qemu-devel] [PATCH 04/21] qom: make Object a type Paolo Bonzini
2012-05-16 8:16 ` Andreas Färber
2012-05-23 16:53 ` Andreas Färber
2012-05-02 11:30 ` [Qemu-devel] [PATCH 05/21] qom: assert that public types have a non-NULL parent field Paolo Bonzini
2012-05-02 12:35 ` Andreas Färber
2012-05-23 17:01 ` Andreas Färber
2012-05-02 11:30 ` [Qemu-devel] [PATCH 06/21] qdev: push "type" property up to Object Paolo Bonzini
2012-05-23 17:06 ` Andreas Färber
2012-05-23 17:18 ` Paolo Bonzini
2012-05-23 17:40 ` Andreas Färber
2012-05-23 18:00 ` Paolo Bonzini
2012-05-02 11:30 ` [Qemu-devel] [PATCH 07/21] qdev: fix -device foo,? Paolo Bonzini
2012-05-11 14:03 ` Andreas Färber
2012-05-14 20:11 ` Anthony Liguori
2012-05-02 11:31 ` [Qemu-devel] [PATCH 08/21] qdev: use object_property_print in info qtree Paolo Bonzini
2012-05-11 14:20 ` Andreas Färber
2012-05-11 14:45 ` Paolo Bonzini
2012-05-12 0:23 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 09/21] qdev: move bus properties to a separate global Paolo Bonzini
2012-05-23 23:39 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 10/21] qdev: do not propagate properties to subclasses Paolo Bonzini
2012-05-23 23:46 ` Andreas Färber
2012-05-24 1:34 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 11/21] qdev: move bus properties to abstract superclasses Paolo Bonzini
2012-05-02 12:29 ` Anthony Liguori
2012-05-02 13:21 ` Paolo Bonzini
2012-05-02 20:00 ` Anthony Liguori
2012-05-02 21:50 ` Paolo Bonzini
2012-05-03 12:45 ` Anthony Liguori
2012-05-03 12:56 ` Paolo Bonzini
2012-05-02 11:31 ` [Qemu-devel] [PATCH 12/21] pc: add back PCI.rombar compat property Paolo Bonzini
2012-05-02 11:38 ` Michael S. Tsirkin
2012-05-02 11:41 ` Paolo Bonzini
2012-05-02 11:44 ` Michael S. Tsirkin
2012-05-02 11:31 ` [Qemu-devel] [PATCH 13/21] qdev: clean up global properties Paolo Bonzini
2012-05-24 16:27 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 14/21] qdev: remove qdev_prop_set_defaults Paolo Bonzini
2012-05-02 12:30 ` Anthony Liguori
2012-05-24 16:30 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 15/21] qdev: fix adding of ptr properties Paolo Bonzini
2012-05-12 12:34 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 16/21] qdev: use wrapper for qdev_get_path Paolo Bonzini
2012-05-24 16:31 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 17/21] qdev: move sysbus initialization to sysbus.c Paolo Bonzini
2012-05-24 16:32 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 18/21] qdev: convert busses to QEMU Object Model Paolo Bonzini
2012-05-24 16:48 ` Andreas Färber [this message]
2012-05-02 11:31 ` [Qemu-devel] [PATCH 19/21] qdev: connect busses with their parent devices Paolo Bonzini
2012-05-24 16:49 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 20/21] qbus: make child devices links Paolo Bonzini
2012-05-24 16:51 ` Andreas Färber
2012-05-02 11:31 ` [Qemu-devel] [PATCH 21/21] qbus: initialize in standard way Paolo Bonzini
2012-05-24 16:52 ` Andreas Färber
2012-05-04 16:15 ` [Qemu-devel] [PATCH 00/21] qbus QOM conversion, rebased on top of my patches Paolo Bonzini
2012-05-23 15:43 ` Paolo Bonzini
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=4FBE665B.8070900@suse.de \
--to=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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).