render / rpms / libvirt

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