Message ID | 20151012090008.10877.13169.stgit@bahia.huguette.org |
---|---|
State | New |
Headers | show |
On Mon, 12 Oct 2015 11:00:13 +0200 Greg Kurz <gkurz@linux.vnet.ibm.com> wrote: > 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(+) > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > index 4ab04aa31e78..2b2339c7c6ad 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -287,6 +287,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) > return; > } > > + if (dc->unpluggable && !dc->unpluggable(dev, errp)) { I think I'd prefer something like "unplug_is_blocked" or so. Makes it more obvious that this is something that is rather the exception. > + return; > + } > + > qdev_hot_removed = true; > > hotplug_ctrl = qdev_get_hotplug_handler(dev);
On Thu, 15 Oct 2015 17:14:36 +0200 Cornelia Huck <cornelia.huck@de.ibm.com> wrote: > On Mon, 12 Oct 2015 11:00:13 +0200 > Greg Kurz <gkurz@linux.vnet.ibm.com> wrote: > > > 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(+) > > > > diff --git a/hw/core/qdev.c b/hw/core/qdev.c > > index 4ab04aa31e78..2b2339c7c6ad 100644 > > --- a/hw/core/qdev.c > > +++ b/hw/core/qdev.c > > @@ -287,6 +287,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) > > return; > > } > > > > + if (dc->unpluggable && !dc->unpluggable(dev, errp)) { > > I think I'd prefer something like "unplug_is_blocked" or so. Makes it > more obvious that this is something that is rather the exception. > It makes sense indeed. I'll do that for next version. > > + return; > > + } > > + > > qdev_hot_removed = true; > > > > hotplug_ctrl = qdev_get_hotplug_handler(dev);
diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 4ab04aa31e78..2b2339c7c6ad 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -287,6 +287,10 @@ void qdev_unplug(DeviceState *dev, Error **errp) return; } + if (dc->unpluggable && !dc->unpluggable(dev, errp)) { + return; + } + qdev_hot_removed = true; hotplug_ctrl = qdev_get_hotplug_handler(dev); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 038b54d94b27..5df0db1a5b68 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -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 (*HotUnpluggable)(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. + * @unpluggable: 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 @@ -120,6 +123,7 @@ typedef struct DeviceClass { void (*reset)(DeviceState *dev); DeviceRealize realize; DeviceUnrealize unrealize; + HotUnpluggable unpluggable; /* 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(+)