Add function to return counted listed of uuids to from the hashed secrets object list. This will replace the guts of secretConnectListSecrets. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virsecretobj.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- src/conf/virsecretobj.h | 6 ++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 3b218d5..eab4e30 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -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; +} diff --git a/src/conf/virsecretobj.h b/src/conf/virsecretobj.h index 761f69e..50e31e0 100644 --- a/src/conf/virsecretobj.h +++ b/src/conf/virsecretobj.h @@ -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__ */ -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list