@@ -287,6 +287,10 @@ void qdev_unplug(DeviceState *dev, Error **errp)
return;
}
+ if (dc->unplug_is_blocked && !dc->unplug_is_blocked(dev, errp)) {
+ return;
+ }
+
qdev_hot_removed = true;
hotplug_ctrl = qdev_get_hotplug_handler(dev);
@@ -38,6 +38,7 @@ typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
typedef void (*BusRealize)(BusState *bus, Error **errp);
typedef void (*BusUnrealize)(BusState *bus, Error **errp);
+typedef bool (*HotUnplugBlocked)(DeviceState *dev, Error **errp);
struct VMStateDescription;
@@ -48,6 +49,8 @@ struct VMStateDescription;
* property is changed to %true. The default invokes @init if not %NULL.
* @unrealize: Callback function invoked when the #DeviceState:realized
* property is changed to %false.
+ * @unplug_is_blocked: Callback function invoked by qdev_unplug(). Return %false
+ * to block hotunplug.
* @init: Callback function invoked when the #DeviceState::realized property
* is changed to %true. Deprecated, new types inheriting directly from
* TYPE_DEVICE should use @realize instead, new leaf types should consult
@@ -133,6 +136,7 @@ typedef struct DeviceClass {
void (*reset)(DeviceState *dev);
DeviceRealize realize;
DeviceUnrealize unrealize;
+ HotUnplugBlocked unplug_is_blocked;
/* device state */
const struct VMStateDescription *vmsd;
This handler allows to ask a device instance if it can be hot-unplugged. It is to be defined in device classes where hot-unpluggability depends on the device state (for example, virtio-9p devices cannot be unplugged if the 9p share is mounted in the guest). Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com> --- hw/core/qdev.c | 4 ++++ include/hw/qdev-core.h | 4 ++++ 2 files changed, 8 insertions(+)