提交 850792f2 编写于 作者: J John Ferlan

secret: Split apart NumOfSecrets and GetUUIDs callback function

Rather than overloading one function - split apart the logic to have
separate interfaces and local/private structures to manage the data
for which the helper is collecting.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 05f3a911
...@@ -433,7 +433,36 @@ virSecretObjListAdd(virSecretObjListPtr secrets, ...@@ -433,7 +433,36 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
} }
struct virSecretObjListGetHelperData { struct virSecretCountData {
virConnectPtr conn;
virSecretObjListACLFilter aclfilter;
int count;
};
static int
virSecretObjListNumOfSecretsCallback(void *payload,
const void *name ATTRIBUTE_UNUSED,
void *opaque)
{
struct virSecretCountData *data = opaque;
virSecretObjPtr obj = payload;
virSecretDefPtr def;
virObjectLock(obj);
def = obj->def;
if (data->aclfilter && !data->aclfilter(data->conn, def))
goto cleanup;
data->count++;
cleanup:
virObjectUnlock(obj);
return 0;
}
struct virSecretListData {
virConnectPtr conn; virConnectPtr conn;
virSecretObjListACLFilter aclfilter; virSecretObjListACLFilter aclfilter;
int nuuids; int nuuids;
...@@ -444,11 +473,11 @@ struct virSecretObjListGetHelperData { ...@@ -444,11 +473,11 @@ struct virSecretObjListGetHelperData {
static int static int
virSecretObjListGetHelper(void *payload, virSecretObjListGetUUIDsCallback(void *payload,
const void *name ATTRIBUTE_UNUSED, const void *name ATTRIBUTE_UNUSED,
void *opaque) void *opaque)
{ {
struct virSecretObjListGetHelperData *data = opaque; struct virSecretListData *data = opaque;
virSecretObjPtr obj = payload; virSecretObjPtr obj = payload;
virSecretDefPtr def; virSecretDefPtr def;
...@@ -473,11 +502,9 @@ virSecretObjListGetHelper(void *payload, ...@@ -473,11 +502,9 @@ virSecretObjListGetHelper(void *payload,
} }
virUUIDFormat(def->uuid, uuidstr); virUUIDFormat(def->uuid, uuidstr);
data->uuids[data->nuuids] = uuidstr; data->uuids[data->nuuids++] = uuidstr;
} }
data->nuuids++;
cleanup: cleanup:
virObjectUnlock(obj); virObjectUnlock(obj);
return 0; return 0;
...@@ -489,15 +516,14 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets, ...@@ -489,15 +516,14 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
virSecretObjListACLFilter aclfilter, virSecretObjListACLFilter aclfilter,
virConnectPtr conn) virConnectPtr conn)
{ {
struct virSecretObjListGetHelperData data = { struct virSecretCountData data = {
.conn = conn, .aclfilter = aclfilter, .nuuids = 0, .conn = conn, .aclfilter = aclfilter, .count = 0 };
.uuids = NULL, .maxuuids = -1, .error = false };
virObjectLock(secrets); virObjectLock(secrets);
virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data);
virObjectUnlock(secrets); virObjectUnlock(secrets);
return data.nuuids; return data.count;
} }
...@@ -626,12 +652,12 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets, ...@@ -626,12 +652,12 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
virSecretObjListACLFilter aclfilter, virSecretObjListACLFilter aclfilter,
virConnectPtr conn) virConnectPtr conn)
{ {
struct virSecretObjListGetHelperData data = { struct virSecretListData data = {
.conn = conn, .aclfilter = aclfilter, .nuuids = 0, .conn = conn, .aclfilter = aclfilter, .uuids = uuids, .nuuids = 0,
.uuids = uuids, .maxuuids = maxuuids, .error = false }; .maxuuids = maxuuids, .error = false };
virObjectLock(secrets); virObjectLock(secrets);
virHashForEach(secrets->objs, virSecretObjListGetHelper, &data); virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data);
virObjectUnlock(secrets); virObjectUnlock(secrets);
if (data.error) if (data.error)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册