提交 bb1fba62 编写于 作者: J John Ferlan

secret: Introduce virSecretObjListGetUUIDs

Add function to return counted listed of uuids to from the hashed secrets
object list. This will replace the guts of secretConnectListSecrets.
上级 d12c6721
......@@ -436,6 +436,9 @@ struct virSecretObjListGetHelperData {
virConnectPtr conn;
virSecretObjListACLFilter filter;
int got;
char **uuids;
int nuuids;
bool error;
};
......@@ -447,11 +450,27 @@ virSecretObjListGetHelper(void *payload,
struct virSecretObjListGetHelperData *data = opaque;
virSecretObjPtr obj = payload;
if (data->error)
return 0;
if (data->nuuids >= 0 && data->got == data->nuuids)
return 0;
virObjectLock(obj);
if (data->filter && !data->filter(data->conn, obj->def))
goto cleanup;
if (data->uuids) {
char *uuidstr;
if (VIR_ALLOC_N(uuidstr, VIR_UUID_STRING_BUFLEN) < 0)
goto cleanup;
virUUIDFormat(obj->def->uuid, uuidstr);
data->uuids[data->got] = uuidstr;
}
data->got++;
cleanup:
......@@ -466,7 +485,8 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
virConnectPtr conn)
{
struct virSecretObjListGetHelperData data = {
.conn = conn, .filter = filter, .got = 0 };
.conn = conn, .filter = filter, .got = 0,
.uuids = NULL, .nuuids = -1, .error = false };
virObjectLock(secrets);
virHashForEach(secrets->objs, virSecretObjListGetHelper, &data);
......@@ -591,3 +611,34 @@ virSecretObjListExport(virConnectPtr conn,
VIR_FREE(data.secrets);
return ret;
}
int
virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
char **uuids,
int nuuids,
virSecretObjListACLFilter filter,
virConnectPtr conn)
{
int ret = -1;
struct virSecretObjListGetHelperData data = {
.conn = conn, .filter = filter, .got = 0,
.uuids = uuids, .nuuids = nuuids, .error = false };
virObjectLock(secrets);
virHashForEach(secrets->objs, virSecretObjListGetHelper, &data);
virObjectUnlock(secrets);
if (data.error)
goto cleanup;
ret = data.got;
cleanup:
if (ret < 0) {
while (data.got)
VIR_FREE(data.uuids[--data.got]);
}
return ret;
}
......@@ -86,4 +86,10 @@ int virSecretObjListExport(virConnectPtr conn,
virSecretObjListACLFilter filter,
unsigned int flags);
int virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
char **uuids,
int nuuids,
virSecretObjListACLFilter filter,
virConnectPtr conn);
#endif /* __VIRSECRETOBJ_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册