mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 00:45:18 +00:00
secret: Introduce virSecretObjListNumOfSecrets
Add function to count the hashed secret obj list with filters. This will replace the guts of secret_driver's secretConnectNumOfSecrets.
This commit is contained in:
parent
d4287b985c
commit
5249d0761d
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user