summary refs log tree commit diff stats
path: root/hw/qdev.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2011-12-12 14:29:25 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2011-12-15 09:20:47 -0600
commit85ed303bfe1f67a4c18ffe51916e73cffd7d9e9b (patch)
tree8d0188741f650e031c3f841778e6a1d07e1e21c5 /hw/qdev.c
parent222f23f508a8d778f56eddef14752dfd26d225b4 (diff)
downloadfocaccia-qemu-85ed303bfe1f67a4c18ffe51916e73cffd7d9e9b.tar.gz
focaccia-qemu-85ed303bfe1f67a4c18ffe51916e73cffd7d9e9b.zip
qom: add a reference count to qdev objects
To ensure that a device isn't removed from the graph until all of its links are
broken.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev.c')
-rw-r--r--hw/qdev.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index 106407f226..fdc984312c 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev)
     }
     assert(dev->info->unplug != NULL);
 
+    if (dev->ref != 0) {
+        qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
+        return -1;
+    }
+
     qdev_hot_removed = true;
 
     return dev->info->unplug(dev);
@@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
 
     return strdup(path);
 }
+
+void qdev_ref(DeviceState *dev)
+{
+    dev->ref++;
+}
+
+void qdev_unref(DeviceState *dev)
+{
+    g_assert(dev->ref > 0);
+    dev->ref--;
+}