[libvirt] [PATCH 09/14] secret: Split apart NumOfSecrets and GetUUIDs callback function

Pavel Hrdina phrdina at redhat.com
Tue Apr 25 10:05:30 UTC 2017


On Mon, Apr 24, 2017 at 02:00:18PM -0400, John Ferlan wrote:
> 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: John Ferlan <jferlan at redhat.com>
> ---
>  src/conf/virsecretobj.c | 98 +++++++++++++++++++++++++++++++------------------
>  src/conf/virsecretobj.h |  6 +--
>  2 files changed, 65 insertions(+), 39 deletions(-)
> 
> diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
> index c410a6b..3717552 100644
> --- a/src/conf/virsecretobj.c
> +++ b/src/conf/virsecretobj.c
> @@ -415,9 +415,54 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
>  }
>  
>  
> -struct virSecretObjListGetHelperData {
> +struct secretCountData {

This doesn't follow our naming rules, all struct should be prefixed with *vir*.

>      virConnectPtr conn;
> -    virSecretObjListACLFilter filter;
> +    virSecretObjListACLFilter aclfilter;
> +    int count;
> +};
> +
> +static int
> +virSecretObjListNumOfSecretsCallback(void *payload,
> +                                     const void *name ATTRIBUTE_UNUSED,
> +                                     void *opaque)
> +{
> +    struct secretCountData *data = opaque;
> +    virSecretObjPtr obj = payload;
> +    virSecretDefPtr def;
> +
> +    virObjectLock(obj);
> +    def = obj->def;
> +
> +    if (data->aclfilter && !data->aclfilter(data->conn, def))
> +        goto cleanup;

This follows previous patch, in this case having separate variable for
virSecretDefPtr doesn't give us any benefit, just a noise in the code.

> +
> +    data->count++;
> +
> + cleanup:
> +    virObjectUnlock(obj);
> +    return 0;
> +}
> +
> +
> +int
> +virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
> +                             virSecretObjListACLFilter aclfilter,
> +                             virConnectPtr conn)
> +{
> +    struct secretCountData data = {
> +        .conn = conn, .aclfilter = aclfilter, .count = 0 };
> +
> +    virObjectLock(secrets);
> +    virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data);
> +    virObjectUnlock(secrets);
> +
> +    return data.count;
> +}

Unnecessary movement of function.

> +
> +
> +struct secretListData {

This should be virSecretListData.

> +    virConnectPtr conn;
> +    virSecretObjListACLFilter aclfilter;
>      int nuuids;
>      char **uuids;
>      int maxuuids;

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170425/ac72a178/attachment-0001.sig>


More information about the libvir-list mailing list