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(a)redhat.com>
---
src/conf/virsecretobj.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
src/conf/virsecretobj.h | 7 +++++++
2 files changed, 51 insertions(+)
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index b808902..7f103e3 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -430,3 +430,47 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
virObjectUnlock(secrets);
return ret;
}
+
+
+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;
+}
diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h
index 290e91b..7f0d40a 100644
--- a/src/conf/virsecretobj.h
+++ b/src/conf/virsecretobj.h
@@ -73,4 +73,11 @@ virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets,
const char *configDir,
virSecretDefPtr *oldDef);
+typedef bool (*virSecretObjListACLFilter)(virConnectPtr conn,
+ virSecretDefPtr def);
+
+int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
+ virSecretObjListACLFilter filter,
+ virConnectPtr conn);
+
#endif /* __VIRSECRETOBJ_H__ */
--
2.5.5