[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/18] qom: add a reference count to qdev objects
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v2 01/18] qom: add a reference count to qdev objects |
Date: |
Fri, 2 Dec 2011 14:20:39 -0600 |
To ensure that a device isn't removed from the graph until all of its links are
broken.
Signed-off-by: Anthony Liguori <address@hidden>
---
hw/qdev.c | 16 ++++++++++++++++
hw/qdev.h | 26 ++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 106407f..fdc9843 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--;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 36a4198..2397b4e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -45,6 +45,12 @@ struct DeviceState {
QTAILQ_ENTRY(DeviceState) sibling;
int instance_id_alias;
int alias_required_for_version;
+
+ /**
+ * This tracks the number of references between devices. See @qdev_ref for
+ * more information.
+ */
+ uint32_t ref;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev);
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
extern struct BusInfo system_bus_info;
+/**
+ * @qdev_ref
+ *
+ * Increase the reference count of a device. A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_ref(DeviceState *dev);
+
+/**
+ * @qdef_unref
+ *
+ * Decrease the reference count of a device. A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_unref(DeviceState *dev);
+
#endif
--
1.7.4.1
- [Qemu-devel] [PATCH v2 00/18] qom: dynamic properties and composition tree (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 01/18] qom: add a reference count to qdev objects,
Anthony Liguori <=
- [Qemu-devel] [PATCH v2 02/18] qom: add new dynamic property infrastructure based on Visitors (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 03/18] qom: register legacy properties as new style properties (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 05/18] qdev: provide an interface to return canonical path from root (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 07/18] qom: add child properties (composition) (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 04/18] qom: introduce root device, Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 06/18] qdev: provide a path resolution (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 08/18] qom: add link properties (v2), Anthony Liguori, 2011/12/02
- [Qemu-devel] [PATCH v2 10/18] qmp: add qom-list command, Anthony Liguori, 2011/12/02