[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/4] qdev: Introduce qdev_force_unplug.



This function will be use to force a device to be ejected without the guest
cooperation.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 hw/qdev.c |   23 ++++++++++++++++++++---
 hw/qdev.h |    3 +++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 6a8f6bd..c95d4c2 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -184,24 +184,41 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
     dev->alias_required_for_version = required_for_version;
 }
 
-void qdev_unplug(DeviceState *dev, Error **errp)
+static void qdev_unplug_common(DeviceState *dev, Error **errp, bool force)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
+    qdev_event unplug;
 
     if (!dev->parent_bus->allow_hotplug) {
         error_set(errp, QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
         return;
     }
-    assert(dc->unplug != NULL);
+
+    if (force) {
+        unplug = dc->force_unplug;
+    } else {
+        unplug = dc->unplug;
+    }
+    assert(unplug != NULL);
 
     qdev_hot_removed = true;
 
-    if (dc->unplug(dev) < 0) {
+    if (unplug(dev) < 0) {
         error_set(errp, QERR_UNDEFINED_ERROR);
         return;
     }
 }
 
+void qdev_force_unplug(DeviceState *dev, Error **errp)
+{
+    qdev_unplug_common(dev, errp, true);
+}
+
+void qdev_unplug(DeviceState *dev, Error **errp)
+{
+    qdev_unplug_common(dev, errp, false);
+}
+
 static int qdev_reset_one(DeviceState *dev, void *opaque)
 {
     device_reset(dev);
diff --git a/hw/qdev.h b/hw/qdev.h
index 4e90119..404c560 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -54,6 +54,7 @@ typedef struct DeviceClass {
     /* Private to qdev / bus.  */
     qdev_initfn init;
     qdev_event unplug;
+    qdev_event force_unplug;
     qdev_event exit;
     BusInfo *bus_info;
 } DeviceClass;
@@ -150,6 +151,8 @@ void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version);
 void qdev_unplug(DeviceState *dev, Error **errp);
+/* Unplug a device without the guest cooperation. */
+void qdev_force_unplug(DeviceState *dev, Error **errp);
 void qdev_free(DeviceState *dev);
 int qdev_simple_unplug_cb(DeviceState *dev);
 void qdev_machine_creation_done(void);
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.