[PATCH 03/10] secret: Add hashed virSecretObj and virSecretObjList

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add definitions and infrastucture required for a hashed virSecretObj
and virSecretObjList including the class, object, lock setup, and
disposal API's. Nothing will call these yet.

This infrastructure will replace the forward linked list logic
within the secret_driver.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/secret_conf.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/conf/secret_conf.h |   9 ++++
 2 files changed, 123 insertions(+), 1 deletion(-)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 4eebae5..675fc3f 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -1,7 +1,7 @@
 /*
  * secret_conf.c: internal <secret> XML handling
  *
- * Copyright (C) 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2014, 2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@
 #include "virerror.h"
 #include "virxml.h"
 #include "viruuid.h"
+#include "virhash.h"
 
 #define VIR_FROM_THIS VIR_FROM_SECRET
 
@@ -39,6 +40,118 @@ VIR_LOG_INIT("conf.secret_conf");
 VIR_ENUM_IMPL(virSecretUsage, VIR_SECRET_USAGE_TYPE_LAST,
               "none", "volume", "ceph", "iscsi")
 
+
+static virClassPtr virSecretObjClass;
+static void virSecretObjDispose(void *obj);
+static virClassPtr virSecretObjListClass;
+static void virSecretObjListDispose(void *obj);
+
+struct _virSecretObjList {
+    virObjectLockable parent;
+
+    /* uuid string -> virSecretObj  mapping
+     * for O(1), lockless lookup-by-uuid */
+    virHashTable *objs;
+};
+
+struct virSecretSearchData {
+    int usageType;
+    const char *usageID;
+};
+
+
+static int
+virSecretObjOnceInit(void)
+{
+    if (!(virSecretObjClass = virClassNew(virClassForObjectLockable(),
+                                          "virSecretObj",
+                                          sizeof(virSecretObj),
+                                          virSecretObjDispose)))
+        return -1;
+
+    if (!(virSecretObjListClass = virClassNew(virClassForObjectLockable(),
+                                              "virSecretObjList",
+                                              sizeof(virSecretObjList),
+                                              virSecretObjListDispose)))
+        return -1;
+
+    return 0;
+}
+
+
+VIR_ONCE_GLOBAL_INIT(virSecretObj)
+
+virSecretObjPtr
+virSecretObjNew(void)
+{
+    virSecretObjPtr secret;
+
+    if (virSecretObjInitialize() < 0)
+        return NULL;
+
+    if (!(secret = virObjectLockableNew(virSecretObjClass)))
+        return NULL;
+
+    return secret;
+}
+
+
+void
+virSecretObjEndAPI(virSecretObjPtr *secret)
+{
+    if (!*secret)
+        return;
+
+    virObjectUnlock(*secret);
+    virObjectUnref(*secret);
+    *secret = NULL;
+}
+
+
+virSecretObjListPtr
+virSecretObjListNew(void)
+{
+    virSecretObjListPtr secrets;
+
+    if (virSecretObjInitialize() < 0)
+        return NULL;
+
+    if (!(secrets = virObjectLockableNew(virSecretObjListClass)))
+        return NULL;
+
+    if (!(secrets->objs = virHashCreate(50, virObjectFreeHashData))) {
+        virObjectUnref(secrets);
+        return NULL;
+    }
+
+    return secrets;
+}
+
+
+static void
+virSecretObjDispose(void *obj)
+{
+    virSecretObjPtr secret = obj;
+
+    virSecretDefFree(secret->def);
+    if (secret->value != NULL) {
+        memset(secret->value, 0, secret->value_size);
+        VIR_FREE(secret->value);
+    }
+    VIR_FREE(secret->configFile);
+    VIR_FREE(secret->base64File);
+}
+
+
+static void
+virSecretObjListDispose(void *obj)
+{
+    virSecretObjListPtr secrets = obj;
+
+    virHashFree(secrets->objs);
+}
+
+
 void
 virSecretDefFree(virSecretDefPtr def)
 {
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index 8eedb40..76b805c 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -54,6 +54,15 @@ struct _virSecretObj {
     size_t value_size;
 };
 
+virSecretObjPtr virSecretObjNew(void);
+
+void virSecretObjEndAPI(virSecretObjPtr *secret);
+
+typedef struct _virSecretObjList virSecretObjList;
+typedef virSecretObjList *virSecretObjListPtr;
+
+virSecretObjListPtr virSecretObjListNew(void);
+
 void virSecretDefFree(virSecretDefPtr def);
 virSecretDefPtr virSecretDefParseString(const char *xml);
 virSecretDefPtr virSecretDefParseFile(const char *filename);
-- 
2.5.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]