[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 36/36] qdev: HotplugHandler: add support for unpl
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH v2 36/36] qdev: HotplugHandler: add support for unplugging BUS-less devices |
Date: |
Fri, 26 Sep 2014 09:28:41 +0000 |
Signed-off-by: Igor Mammedov <address@hidden>
---
v2:
merged in Paolo's suggestion to reduce indentation in patch
---
hw/core/qdev.c | 61 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 27 deletions(-)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index bc45a59..215effb 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -223,9 +223,28 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int
alias_id,
dev->alias_required_for_version = required_for_version;
}
+static HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
+{
+ HotplugHandler *hotplug_ctrl = NULL;
+
+ if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
+ hotplug_ctrl = dev->parent_bus->hotplug_handler;
+ } else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
+ MachineState *machine = MACHINE(qdev_get_machine());
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+ if (mc->get_hotplug_handler) {
+ hotplug_ctrl = mc->get_hotplug_handler(machine, dev);
+ }
+ }
+ return hotplug_ctrl;
+}
+
void qdev_unplug(DeviceState *dev, Error **errp)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
+ HotplugHandler *hotplug_ctrl;
+ HotplugHandlerClass *hdc;
if (dev->parent_bus && !qbus_is_hotpluggable(dev->parent_bus)) {
error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
@@ -240,20 +259,18 @@ void qdev_unplug(DeviceState *dev, Error **errp)
qdev_hot_removed = true;
- if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
- HotplugHandlerClass *hdc;
-
- /* If device supports async unplug just request it to be done,
- * otherwise just remove it synchronously */
- hdc = HOTPLUG_HANDLER_GET_CLASS(dev->parent_bus->hotplug_handler);
- if (hdc->unplug_request) {
- hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler,
- dev, errp);
- } else {
- hotplug_handler_unplug(dev->parent_bus->hotplug_handler, dev,
errp);
- }
+ hotplug_ctrl = qdev_get_hotplug_handler(dev);
+ /* hotplggable device MUST have HotplugHandler, if it doesn't
+ * then something is very wrong with it */
+ g_assert(hotplug_ctrl);
+
+ /* If device supports async unplug just request it to be done,
+ * otherwise just remove it synchronously */
+ hdc = HOTPLUG_HANDLER_GET_CLASS(hotplug_ctrl);
+ if (hdc->unplug_request) {
+ hotplug_handler_unplug_request(hotplug_ctrl, dev, errp);
} else {
- assert(0);
+ hotplug_handler_unplug(hotplug_ctrl, dev, errp);
}
}
@@ -831,6 +848,7 @@ static void device_set_realized(Object *obj, bool value,
Error **errp)
{
DeviceState *dev = DEVICE(obj);
DeviceClass *dc = DEVICE_GET_CLASS(dev);
+ HotplugHandler *hotplug_ctrl;
BusState *bus;
Error *local_err = NULL;
@@ -858,20 +876,9 @@ static void device_set_realized(Object *obj, bool value,
Error **errp)
goto fail;
}
- if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
- hotplug_handler_plug(dev->parent_bus->hotplug_handler,
- dev, &local_err);
- } else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {
- HotplugHandler *hotplug_ctrl;
- MachineState *machine = MACHINE(qdev_get_machine());
- MachineClass *mc = MACHINE_GET_CLASS(machine);
-
- if (mc->get_hotplug_handler) {
- hotplug_ctrl = mc->get_hotplug_handler(machine, dev);
- if (hotplug_ctrl) {
- hotplug_handler_plug(hotplug_ctrl, dev, &local_err);
- }
- }
+ hotplug_ctrl = qdev_get_hotplug_handler(dev);
+ if (hotplug_ctrl) {
+ hotplug_handler_plug(hotplug_ctrl, dev, &local_err);
}
if (local_err != NULL) {
--
1.8.3.1
- [Qemu-devel] [PATCH v4 24/36] s390x: convert s390-virtio to hotplug handler API, (continued)
- [Qemu-devel] [PATCH v2 25/36] s390x: convert virtio-ccw to hotplug handler API, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 26/36] scsi: set SCSI BUS itself as default HotplugHandler, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 31/36] usb-bot: drop not needed "allow_hotplug = 0", Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 33/36] usb: convert usb-ccid to hotplug handler API, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 32/36] usb-storage: drop not needed "allow_hotplug = 0", Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 34/36] usb: convert usb devices to hotplug handler API, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 11/36] test: usb: usb-uas hotplug test, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 36/36] qdev: HotplugHandler: add support for unplugging BUS-less devices,
Igor Mammedov <=
- [Qemu-devel] [PATCH v2 35/36] qdev: drop legacy hotplug fields/methods, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 19/36] target-i386: ICC bus: drop BusState.allow_hotplug, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 28/36] scsi: convert virtio-scsi HBA to hotplug handler API, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 30/36] usb-bot: mark device as non hotpluggable, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 27/36] scsi: convert pvscsi HBA to hotplug handler API, Igor Mammedov, 2014/09/26
- [Qemu-devel] [PATCH v2 29/36] scsi: cleanup not used anymore SCSIBusInfo{hotplug, hot_unplug} fields, Igor Mammedov, 2014/09/26
- Re: [Qemu-devel] [PATCH v2 00/36] complete conversion to hotplug-handler API, Cornelia Huck, 2014/09/26
- Re: [Qemu-devel] [PATCH v2 00/36] complete conversion to hotplug-handler API, Paolo Bonzini, 2014/09/26
- Re: [Qemu-devel] [PATCH v2 00/36] complete conversion to hotplug-handler API, Gerd Hoffmann, 2014/09/29