c480ed
From c7f704deec7b42ec02ae13a678474b3ca62fecbd Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <c7f704deec7b42ec02ae13a678474b3ca62fecbd@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:30 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2SetOwner
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit 525ac6885b508759f8618f136f04554c95138ae8)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <778612847c720bc6567b98708532175ada48ce44.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 27 +++++++++++++++++++++++++++
c480ed
 1 file changed, 27 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 90ce660908..27519d80e3 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -495,6 +495,32 @@ virCgroupV2BindMount(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2SetOwner(virCgroupPtr cgroup,
c480ed
+                    uid_t uid,
c480ed
+                    gid_t gid,
c480ed
+                    int controllers ATTRIBUTE_UNUSED)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) base = NULL;
c480ed
+
c480ed
+    if (virAsprintf(&base, "%s%s", cgroup->unified.mountPoint,
c480ed
+                    cgroup->unified.placement) < 0) {
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virFileChownFiles(base, uid, gid) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (chown(base, uid, gid) < 0) {
c480ed
+        virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
c480ed
+                             base, uid, gid);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -515,6 +541,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .addTask = virCgroupV2AddTask,
c480ed
     .hasEmptyTasks = virCgroupV2HasEmptyTasks,
c480ed
     .bindMount = virCgroupV2BindMount,
c480ed
+    .setOwner = virCgroupV2SetOwner,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed