From nobody Mon Feb 9 14:01:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1538469933847380.21464450529345; Tue, 2 Oct 2018 01:45:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A64F86670; Tue, 2 Oct 2018 08:45:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32CE41C927; Tue, 2 Oct 2018 08:45:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D15EB181A71E; Tue, 2 Oct 2018 08:45:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w928j1E1031370 for ; Tue, 2 Oct 2018 04:45:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 09D2F10016DC; Tue, 2 Oct 2018 08:45:01 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F7F71001903 for ; Tue, 2 Oct 2018 08:44:56 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 2 Oct 2018 10:44:03 +0200 Message-Id: <98e86dd36736e0b4db2192de0751fcca789e5b78.1538469654.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/53] vircgroup: introduce virCgroupV2SetOwner X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 02 Oct 2018 08:45:32 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- 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, } =20 =20 +static int +virCgroupV2SetOwner(virCgroupPtr cgroup, + uid_t uid, + gid_t gid, + int controllers ATTRIBUTE_UNUSED) +{ + int ret =3D -1; + VIR_AUTOFREE(char *) base =3D NULL; + DIR *dh =3D NULL; + int direrr; + + struct dirent *de; + + if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint, + cgroup->unified.placement) < 0) { + goto cleanup; + } + + if (virDirOpen(&dh, base) < 0) + goto cleanup; + + while ((direrr =3D virDirRead(dh, &de, base)) > 0) { + VIR_AUTOFREE(char *) entry =3D 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; + } + } + + 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 =3D 0; + + cleanup: + VIR_DIR_CLOSE(dh); + return ret; +} + + virCgroupBackend virCgroupV2Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V2, =20 @@ -515,6 +566,7 @@ virCgroupBackend virCgroupV2Backend =3D { .addTask =3D virCgroupV2AddTask, .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, .bindMount =3D virCgroupV2BindMount, + .setOwner =3D virCgroupV2SetOwner, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list