[libvirt] [PATCH 19/53] vircgroup: introduce virCgroupV2SetOwner

Michal Privoznik mprivozn at redhat.com
Thu Oct 4 15:26:33 UTC 2018


On 10/02/2018 10:44 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
>  src/util/vircgroupv2.c | 52 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
> index e30f438015..fec5d28835 100644
> --- a/src/util/vircgroupv2.c
> +++ b/src/util/vircgroupv2.c
> @@ -495,6 +495,57 @@ virCgroupV2BindMount(virCgroupPtr group,
>  }
>  
>  
> +static int
> +virCgroupV2SetOwner(virCgroupPtr cgroup,
> +                    uid_t uid,
> +                    gid_t gid,
> +                    int controllers ATTRIBUTE_UNUSED)
> +{
> +    int ret = -1;
> +    VIR_AUTOFREE(char *) base = NULL;
> +    DIR *dh = NULL;
> +    int direrr;
> +
> +    struct dirent *de;

Useless empty line;

> +
> +    if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
> +                    cgroup->unified.placement) < 0) {
> +        goto cleanup;
> +    }
> +
> +    if (virDirOpen(&dh, base) < 0)
> +        goto cleanup;
> +
> +    while ((direrr = virDirRead(dh, &de, base)) > 0) {
> +        VIR_AUTOFREE(char *) entry = NULL;
> +
> +        if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0)
> +            goto cleanup;
> +
> +        if (chown(entry, uid, gid) < 0) {
> +            virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
> +                                 entry, uid, gid);
> +            goto cleanup;
> +        }
> +    }

Or virFileChownFiles().

> +
> +    if (direrr < 0)
> +        goto cleanup;
> +
> +    if (chown(base, uid, gid) < 0) {
> +        virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
> +                             base, uid, gid);
> +        goto cleanup;
> +    }
> +
> +    ret = 0;
> +
> + cleanup:
> +    VIR_DIR_CLOSE(dh);
> +    return ret;
> +}
> +
> +
>  virCgroupBackend virCgroupV2Backend = {
>      .type = VIR_CGROUP_BACKEND_TYPE_V2,
>  
> @@ -515,6 +566,7 @@ virCgroupBackend virCgroupV2Backend = {
>      .addTask = virCgroupV2AddTask,
>      .hasEmptyTasks = virCgroupV2HasEmptyTasks,
>      .bindMount = virCgroupV2BindMount,
> +    .setOwner = virCgroupV2SetOwner,
>  };
>  
>  
> 


ACK

Michal




More information about the libvir-list mailing list