Add the initial infrastructure to define a new object which will be
a child of the virObjectLockable class that can be used to create an
object that has two hash tables for object consumers to be able to
utilize to store elements in one or two hash tables depending on the
need to have more than one lookup mechanism for the same object
TODO: Remove VIR_DEBUG's or add separately
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/libvirt_private.syms | 2 ++
src/util/virobject.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++-
src/util/virobject.h | 29 +++++++++++++++++++
3 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 92083e5..6861155 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2223,6 +2223,7 @@ virNumaSetupMemoryPolicy;
# util/virobject.h
virClassForObject;
virClassForObjectLockable;
+virClassForObjectPoolableHashTable;
virClassIsDerivedFrom;
virClassName;
virClassNew;
@@ -2234,6 +2235,7 @@ virObjectListFreeCount;
virObjectLock;
virObjectLockableNew;
virObjectNew;
+virObjectPoolableHashTableNew;
virObjectRef;
virObjectUnlock;
virObjectUnref;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index aea8a6d..d284dde 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -61,8 +61,11 @@ struct _virClass {
static virClassPtr virObjectClass;
static virClassPtr virObjectLockableClass;
+static virClassPtr virObjectPoolableHashTableClass;
static void virObjectLockableDispose(void *anyobj);
+static void virObjectPoolableHashTableDispose(void *anyobj);
+
static int
virObjectOnceInit(void)
@@ -79,6 +82,13 @@ virObjectOnceInit(void)
virObjectLockableDispose)))
return -1;
+ if (!(virObjectPoolableHashTableClass =
+ virClassNew(virObjectLockableClass,
+ "virObjectPoolableHashTable",
+ sizeof(virObjectPoolableHashTable),
+ virObjectPoolableHashTableDispose)))
+ return -1;
+
return 0;
}
@@ -96,6 +106,7 @@ virClassForObject(void)
if (virObjectInitialize() < 0)
return NULL;
+ VIR_DEBUG("virObjectClass=%p", virObjectClass);
return virObjectClass;
}
@@ -111,11 +122,29 @@ virClassForObjectLockable(void)
if (virObjectInitialize() < 0)
return NULL;
+ VIR_DEBUG("virObjectLockableClass=%p", virObjectLockableClass);
return virObjectLockableClass;
}
/**
+ * virClassForObjectPoolableHashTable:
+ *
+ * Returns the class instance for the virObjectPoolableHashTable type
+ */
+virClassPtr
+virClassForObjectPoolableHashTable(void)
+{
+ if (virObjectInitialize() < 0)
+ return NULL;
+
+ VIR_DEBUG("virObjectPoolableHashTableClass=%p",
+ virObjectPoolableHashTableClass);
+ return virObjectPoolableHashTableClass;
+}
+
+
+/**
* virClassNew:
* @parent: the parent class
* @name: the class name
@@ -139,6 +168,9 @@ virClassNew(virClassPtr parent,
{
virClassPtr klass;
+ VIR_DEBUG("parent=%p, name=%s, objectSize=%zu, dispose=%p",
+ parent, name, objectSize, dispose);
+
if (parent == NULL &&
STRNEQ(name, "virObject")) {
virReportInvalidNonNullArg(parent);
@@ -246,6 +278,7 @@ virObjectLockableNew(virClassPtr klass)
return NULL;
}
+ VIR_DEBUG("lockable new obj=%p", obj);
return obj;
}
@@ -255,10 +288,46 @@ virObjectLockableDispose(void *anyobj)
{
virObjectLockablePtr obj = anyobj;
+ VIR_DEBUG("lockable dispose obj=%p", obj);
virMutexDestroy(&obj->lock);
}
+void *
+virObjectPoolableHashTableNew(virClassPtr klass,
+ virObjectPoolableHashTableObjType objtype)
+{
+ virObjectPoolableHashTablePtr obj;
+
+ if (!virClassIsDerivedFrom(klass, virClassForObjectPoolableHashTable())) {
+ virReportInvalidArg(klass,
+ _("Class %s must derive from "
+ "virObjectPoolableHashTable"),
+ virClassName(klass));
+ return NULL;
+ }
+
+ if (!(obj = virObjectLockableNew(klass)))
+ return NULL;
+
+ obj->objtype = objtype;
+
+ VIR_DEBUG("poolable new obj=%p, type=%d",
+ obj, objtype);
+
+ return obj;
+
+}
+
+static void
+virObjectPoolableHashTableDispose(void *anyobj)
+{
+ virObjectPoolableHashTablePtr obj = anyobj;
+
+ VIR_DEBUG("poolable dispose obj=%p", obj);
+}
+
+
/**
* virObjectUnref:
* @anyobj: any instance of virObjectPtr
@@ -326,7 +395,8 @@ virObjectRef(void *anyobj)
static virObjectLockablePtr
virObjectGetLockableObj(void *anyobj)
{
- if (virObjectIsClass(anyobj, virObjectLockableClass))
+ if (virObjectIsClass(anyobj, virObjectLockableClass) ||
+ virObjectIsClass(anyobj, virObjectPoolableHashTableClass))
return anyobj;
VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLockableClass);
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 89f8050..30ce6a1 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -23,6 +23,7 @@
# define __VIR_OBJECT_H__
# include "internal.h"
+# include "virhash.h"
# include "virthread.h"
typedef struct _virClass virClass;
@@ -34,6 +35,9 @@ typedef virObject *virObjectPtr;
typedef struct _virObjectLockable virObjectLockable;
typedef virObjectLockable *virObjectLockablePtr;
+typedef struct _virObjectPoolableHashTable virObjectPoolableHashTable;
+typedef virObjectPoolableHashTable *virObjectPoolableHashTablePtr;
+
typedef void (*virObjectDisposeCallback)(void *obj);
/* Most code should not play with the contents of this struct; however,
@@ -60,9 +64,29 @@ struct _virObjectLockable {
virMutex lock;
};
+typedef enum {
+ VIR_OBJECTPOOLABLE_NODEDEVICE,
+ VIR_OBJECTPOOLABLE_INTERFACE,
+ VIR_OBJECTPOOLABLE_NWFILTER,
+ VIR_OBJECTPOOLABLE_VOLUME,
+ VIR_OBJECTPOOLABLE_BLOCK_STORAGE,
+ VIR_OBJECTPOOLABLE_SECRET,
+ VIR_OBJECTPOOLABLE_NETWORK,
+ VIR_OBJECTPOOLABLE_SNAPSHOT,
+ VIR_OBJECTPOOLABLE_DOMAIN,
+
+ VIR_OBJECTPOOLABLE_LAST
+} virObjectPoolableHashTableObjType;
+
+struct _virObjectPoolableHashTable {
+ virObjectLockable parent;
+ virObjectPoolableHashTableObjType objtype;
+};
+
virClassPtr virClassForObject(void);
virClassPtr virClassForObjectLockable(void);
+virClassPtr virClassForObjectPoolableHashTable(void);
# ifndef VIR_PARENT_REQUIRED
# define VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(1)
@@ -109,6 +133,11 @@ void *
virObjectLockableNew(virClassPtr klass)
ATTRIBUTE_NONNULL(1);
+void *
+virObjectPoolableHashTableNew(virClassPtr klass,
+ virObjectPoolableHashTableObjType objtype)
+ ATTRIBUTE_NONNULL(1);
+
void
virObjectLock(void *lockableobj)
ATTRIBUTE_NONNULL(1);
--
2.9.3