libvirt/SOURCES/libvirt-vircgroup-introduce...

70 lines
2.0 KiB
Diff

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