提交 5249d076 编写于 作者: J John Ferlan

secret: Introduce virSecretObjListNumOfSecrets

Add function to count the hashed secret obj list with filters. This
will replace the guts of secret_driver's secretConnectNumOfSecrets.
上级 d4287b98
...@@ -430,3 +430,47 @@ virSecretObjListAdd(virSecretObjListPtr secrets, ...@@ -430,3 +430,47 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
virObjectUnlock(secrets); virObjectUnlock(secrets);
return ret; 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;
}
...@@ -73,4 +73,11 @@ virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets, ...@@ -73,4 +73,11 @@ virSecretObjPtr virSecretObjListAdd(virSecretObjListPtr secrets,
const char *configDir, const char *configDir,
virSecretDefPtr *oldDef); virSecretDefPtr *oldDef);
typedef bool (*virSecretObjListACLFilter)(virConnectPtr conn,
virSecretDefPtr def);
int virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
virSecretObjListACLFilter filter,
virConnectPtr conn);
#endif /* __VIRSECRETOBJ_H__ */ #endif /* __VIRSECRETOBJ_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册