Patchwork [1/3] qdev: allow devices being tagged as not hotpluggable.

login
register
mail settings
Submitter Gerd Hoffmann
Date Nov. 18, 2010, 10:45 a.m.
Message ID <1290077118-11577-2-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/72075/
State New
Headers show

Comments

Gerd Hoffmann - Nov. 18, 2010, 10:45 a.m.
This patch adds a field to DeviceInfo to tag devices as being not
hotpluggable.  Any attempt to plug-in or -out such a device will
throw an error.

This check is done in addition to the check whenever the bus supports
hotplug, i.e. there is no need to tag devices which sit on busses
without hotplug support (ISA for example).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   16 +++++++++++++---
 hw/qdev.h |    1 +
 qerror.c  |    4 ++++
 qerror.h  |    3 +++
 4 files changed, 21 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index 35858cb..5ef5346 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -234,9 +234,15 @@  DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
     }
-    if (qdev_hotplug && !bus->allow_hotplug) {
-        qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
-        return NULL;
+    if (qdev_hotplug) {
+        if (!bus->allow_hotplug) {
+            qerror_report(QERR_BUS_NO_HOTPLUG, bus->name);
+            return NULL;
+        }
+        if (info->no_hotplug) {
+            qerror_report(QERR_DEVICE_NO_HOTPLUG, info->name);
+            return NULL;
+        }
     }
 
     /* create device, set properties */
@@ -303,6 +309,10 @@  int qdev_unplug(DeviceState *dev)
         qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
         return -1;
     }
+    if (dev->info->no_hotplug) {
+        qerror_report(QERR_DEVICE_NO_HOTPLUG, dev->info->name);
+        return -1;
+    }
     assert(dev->info->unplug != NULL);
 
     return dev->info->unplug(dev);
diff --git a/hw/qdev.h b/hw/qdev.h
index 579328a..5b57b2b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -144,6 +144,7 @@  struct DeviceInfo {
     size_t size;
     Property *props;
     int no_user;
+    int no_hotplug;
 
     /* callbacks */
     qdev_resetfn reset;
diff --git a/qerror.c b/qerror.c
index ac2cdaf..9d0cdeb 100644
--- a/qerror.c
+++ b/qerror.c
@@ -101,6 +101,10 @@  static const QErrorStringTable qerror_table[] = {
         .desc      = "Device '%(device)' has no child bus",
     },
     {
+        .error_fmt = QERR_DEVICE_NO_HOTPLUG,
+        .desc      = "Device '%(device)' does not support hotplugging",
+    },
+    {
         .error_fmt = QERR_DUPLICATE_ID,
         .desc      = "Duplicate ID '%(id)' for %(object)",
     },
diff --git a/qerror.h b/qerror.h
index 943a24b..b0f69da 100644
--- a/qerror.h
+++ b/qerror.h
@@ -90,6 +90,9 @@  QError *qobject_to_qerror(const QObject *obj);
 #define QERR_DEVICE_NO_BUS \
     "{ 'class': 'DeviceNoBus', 'data': { 'device': %s } }"
 
+#define QERR_DEVICE_NO_HOTPLUG \
+    "{ 'class': 'DeviceNoHotplug', 'data': { 'device': %s } }"
+
 #define QERR_DUPLICATE_ID \
     "{ 'class': 'DuplicateId', 'data': { 'id': %s, 'object': %s } }"