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

[libvirt] [PATCH 06/10] secret: Introduce virSecretObjListNumOfSecrets



Add function to count the hashed secret obj list with filters. This
will replace the guts of secret_driver's secretConnectNumOfSecrets.

Signed-off-by: John Ferlan <jferlan redhat com>
---
 src/conf/secret_conf.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 src/conf/secret_conf.h |  7 +++++++
 2 files changed, 51 insertions(+)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index d45910f..6f11317 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -469,6 +469,50 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
 }
 
 
+struct virSecretObjListGetHelperData {
+    virConnectPtr conn;
+    virSecretObjListACLFilter filter;
+    int got;
+};
+
+
+static int
+virSecretObjListGetHelper(void *payload,
+                          const void *name ATTRIBUTE_UNUSED,
+                          void *opaque)
+{
+    struct virSecretObjListGetHelperData *data = opaque;
+    virSecretObjPtr obj = payload;
+
+    virObjectLock(obj);
+
+    if (data->filter && !data->filter(data->conn, obj->def))
+        goto cleanup;
+
+    data->got++;
+
+ cleanup:
+    virObjectUnlock(obj);
+    return 0;
+}
+
+
+int
+virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
+                             virSecretObjListACLFilter filter,
+                             virConnectPtr conn)
+{
+    struct virSecretObjListGetHelperData data = {
+        .conn = conn, .filter = filter, .got = 0 };
+
+    virObjectLock(secrets);
+    virHashForEach(secrets->objs, virSecretObjListGetHelper, &data);
+    virObjectUnlock(secrets);
+
+    return data.got;
+}
+
+
 void
 virSecretDefFree(virSecretDefPtr def)
 {
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index 7e0651d..59eb339 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -92,6 +92,13 @@ virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets,
                                     const char *configDir,
                                     virSecretDefPtr *oldDef);
 
+typedef bool (*virSecretObjListACLFilter)(virConnectPtr conn,
+                                          virSecretDefPtr def);
+
+int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
+                                 virSecretObjListACLFilter filter,
+                                 virConnectPtr conn);
+
 void virSecretDefFree(virSecretDefPtr def);
 virSecretDefPtr virSecretDefParseString(const char *xml);
 virSecretDefPtr virSecretDefParseFile(const char *filename);
-- 
2.5.0


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