qdev: HotplugHandler: Provide unplug callback

It is to be called for actual device removal and
will allow to separate request and removal handling
phases of x86-CPU devices and also it's a handler
to be called for synchronously removable devices.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
master
Igor Mammedov 2014-09-26 09:28:20 +00:00 committed by Andreas Färber
parent 14d5a28fb6
commit 181a2c6323
3 changed files with 34 additions and 2 deletions

View File

@ -34,6 +34,17 @@ void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
} }
} }
void hotplug_handler_unplug(HotplugHandler *plug_handler,
DeviceState *plugged_dev,
Error **errp)
{
HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
if (hdc->unplug) {
hdc->unplug(plug_handler, plugged_dev, errp);
}
}
static const TypeInfo hotplug_handler_info = { static const TypeInfo hotplug_handler_info = {
.name = TYPE_HOTPLUG_HANDLER, .name = TYPE_HOTPLUG_HANDLER,
.parent = TYPE_INTERFACE, .parent = TYPE_INTERFACE,

View File

@ -227,8 +227,17 @@ void qdev_unplug(DeviceState *dev, Error **errp)
qdev_hot_removed = true; qdev_hot_removed = true;
if (dev->parent_bus && dev->parent_bus->hotplug_handler) { if (dev->parent_bus && dev->parent_bus->hotplug_handler) {
hotplug_handler_unplug_request(dev->parent_bus->hotplug_handler, HotplugHandlerClass *hdc;
dev, errp);
/* 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);
}
} else { } else {
assert(dc->unplug != NULL); assert(dc->unplug != NULL);
if (dc->unplug(dev) < 0) { /* legacy handler */ if (dc->unplug(dev) < 0) { /* legacy handler */

View File

@ -50,6 +50,9 @@ typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
* @unplug_request: unplug request callback. * @unplug_request: unplug request callback.
* Used as a means to initiate device unplug for devices that * Used as a means to initiate device unplug for devices that
* require asynchronous unplug handling. * require asynchronous unplug handling.
* @unplug: unplug callback.
* Used for device removal with devices that implement
* asynchronous and synchronous (suprise) removal.
*/ */
typedef struct HotplugHandlerClass { typedef struct HotplugHandlerClass {
/* <private> */ /* <private> */
@ -58,6 +61,7 @@ typedef struct HotplugHandlerClass {
/* <public> */ /* <public> */
hotplug_fn plug; hotplug_fn plug;
hotplug_fn unplug_request; hotplug_fn unplug_request;
hotplug_fn unplug;
} HotplugHandlerClass; } HotplugHandlerClass;
/** /**
@ -77,4 +81,12 @@ void hotplug_handler_plug(HotplugHandler *plug_handler,
void hotplug_handler_unplug_request(HotplugHandler *plug_handler, void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
DeviceState *plugged_dev, DeviceState *plugged_dev,
Error **errp); Error **errp);
/**
* hotplug_handler_unplug:
*
* Calls #HotplugHandlerClass.unplug callback of @plug_handler.
*/
void hotplug_handler_unplug(HotplugHandler *plug_handler,
DeviceState *plugged_dev,
Error **errp);
#endif #endif