Prepare for hash table volume lists by creating the object infrastructure
for a Volume Object and Volume Object List
The _virStorageVolObj will contain just a pointer to the "current"
(and live) volume definition.
The _virStorageVolObjList will contain three hash tables, one for
each of the lookup options allowed for a volume.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virstorageobj.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 1eaa53423..8a1c6f782 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -39,11 +39,18 @@ VIR_LOG_INIT("conf.virstorageobj");
static virClassPtr virStoragePoolObjClass;
static virClassPtr virStoragePoolObjListClass;
+static virClassPtr virStorageVolObjClass;
+static virClassPtr virStorageVolObjListClass;
static void
virStoragePoolObjDispose(void *opaque);
static void
virStoragePoolObjListDispose(void *opaque);
+static void
+virStorageVolObjDispose(void *opaque);
+static void
+virStorageVolObjListDispose(void *opaque);
+
struct _virStorageVolDefList {
@@ -51,6 +58,32 @@ struct _virStorageVolDefList {
virStorageVolDefPtr *objs;
};
+typedef struct _virStorageVolObj virStorageVolObj;
+typedef virStorageVolObj *virStorageVolObjPtr;
+struct _virStorageVolObj {
+ virObjectLockable parent;
+
+ virStorageVolDefPtr voldef;
+};
+
+typedef struct _virStorageVolObjList virStorageVolObjList;
+typedef virStorageVolObjList *virStorageVolObjListPtr;
+struct _virStorageVolObjList {
+ virObjectRWLockable parent;
+
+ /* key string -> virStorageVolObj mapping
+ * for (1), lockless lookup-by-key */
+ virHashTable *objsKey;
+
+ /* name string -> virStorageVolObj mapping
+ * for (1), lockless lookup-by-name */
+ virHashTable *objsName;
+
+ /* path string -> virStorageVolObj mapping
+ * for (1), lockless lookup-by-path */
+ virHashTable *objsPath;
+};
+
struct _virStoragePoolObj {
virObjectLockable parent;
@@ -80,6 +113,103 @@ struct _virStoragePoolObjList {
static int
+virStorageVolObjOnceInit(void)
+{
+ if (!(virStorageVolObjClass = virClassNew(virClassForObjectLockable(),
+ "virStorageVolObj",
+ sizeof(virStorageVolObj),
+ virStorageVolObjDispose)))
+ return -1;
+
+ if (!(virStorageVolObjListClass = virClassNew(virClassForObjectRWLockable(),
+ "virStorageVolObjList",
+ sizeof(virStorageVolObjList),
+ virStorageVolObjListDispose)))
+ return -1;
+
+ return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virStorageVolObj)
+
+
+static virStorageVolObjPtr ATTRIBUTE_UNUSED
+virStorageVolObjNew(void)
+{
+ virStorageVolObjPtr obj;
+
+ if (virStorageVolObjInitialize() < 0)
+ return NULL;
+
+ if (!(obj = virObjectLockableNew(virStorageVolObjClass)))
+ return NULL;
+
+ virObjectLock(obj);
+ return obj;
+}
+
+
+static void ATTRIBUTE_UNUSED
+virStorageVolObjEndAPI(virStorageVolObjPtr *obj)
+{
+ if (!*obj)
+ return;
+
+ virObjectUnlock(*obj);
+ virObjectUnref(*obj);
+ *obj = NULL;
+}
+
+
+static void
+virStorageVolObjDispose(void *opaque)
+{
+ virStorageVolObjPtr obj = opaque;
+
+ if (!obj)
+ return;
+
+ virStorageVolDefFree(obj->voldef);
+}
+
+
+static virStorageVolObjListPtr ATTRIBUTE_UNUSED
+virStorageVolObjListNew(void)
+{
+ virStorageVolObjListPtr vols;
+
+ if (virStorageVolObjInitialize() < 0)
+ return NULL;
+
+ if (!(vols = virObjectRWLockableNew(virStorageVolObjListClass)))
+ return NULL;
+
+ if (!(vols->objsKey = virHashCreate(10, virObjectFreeHashData)) ||
+ !(vols->objsName = virHashCreate(10, virObjectFreeHashData)) ||
+ !(vols->objsPath = virHashCreate(10, virObjectFreeHashData))) {
+ virObjectUnref(vols);
+ return NULL;
+ }
+
+ return vols;
+}
+
+
+static void
+virStorageVolObjListDispose(void *opaque)
+{
+ virStorageVolObjListPtr vols = opaque;
+
+ if (!vols)
+ return;
+
+ virHashFree(vols->objsKey);
+ virHashFree(vols->objsName);
+ virHashFree(vols->objsPath);
+}
+
+
+static int
virStoragePoolObjOnceInit(void)
{
if (!(virStoragePoolObjClass = virClassNew(virClassForObjectLockable(),
--
2.13.6