c480ed
From 583928aa5c4d1b28304aa6484ad20cd2036407ae Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <583928aa5c4d1b28304aa6484ad20cd2036407ae@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:07:29 +0200
c480ed
Subject: [PATCH] vircgroup: introduce virCgroupV2BindMount
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 cda8ed0646d82f95d4424cfadfb9233037b1d815)
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: <c99f93d93fe7a944219b860a2a76b18303c27479.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroupv2.c | 34 ++++++++++++++++++++++++++++++++++
c480ed
 1 file changed, 34 insertions(+)
c480ed
c480ed
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
c480ed
index 074e6ec110..90ce660908 100644
c480ed
--- a/src/util/vircgroupv2.c
c480ed
+++ b/src/util/vircgroupv2.c
c480ed
@@ -21,6 +21,7 @@
c480ed
 
c480ed
 #ifdef __linux__
c480ed
 # include <mntent.h>
c480ed
+# include <sys/mount.h>
c480ed
 #endif /* __linux__ */
c480ed
 
c480ed
 #include "internal.h"
c480ed
@@ -462,6 +463,38 @@ virCgroupV2HasEmptyTasks(virCgroupPtr cgroup,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV2BindMount(virCgroupPtr group,
c480ed
+                     const char *oldroot,
c480ed
+                     const char *mountopts)
c480ed
+{
c480ed
+    VIR_AUTOFREE(char *) opts = NULL;
c480ed
+    VIR_AUTOFREE(char *) src = NULL;
c480ed
+
c480ed
+    VIR_DEBUG("Mounting cgroups at '%s'", group->unified.mountPoint);
c480ed
+
c480ed
+    if (virFileMakePath(group->unified.mountPoint) < 0) {
c480ed
+        virReportSystemError(errno, _("Unable to create directory %s"),
c480ed
+                             group->unified.mountPoint);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    if (virAsprintf(&opts, "mode=755,size=65536%s", mountopts) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint) < 0)
c480ed
+        return -1;
c480ed
+
c480ed
+    if (mount(src, group->unified.mountPoint, "none", MS_BIND, NULL) < 0) {
c480ed
+        virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"),
c480ed
+                             src, group->unified.mountPoint);
c480ed
+        return -1;
c480ed
+    }
c480ed
+
c480ed
+    return 0;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV2Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
c480ed
 
c480ed
@@ -481,6 +514,7 @@ virCgroupBackend virCgroupV2Backend = {
c480ed
     .remove = virCgroupV2Remove,
c480ed
     .addTask = virCgroupV2AddTask,
c480ed
     .hasEmptyTasks = virCgroupV2HasEmptyTasks,
c480ed
+    .bindMount = virCgroupV2BindMount,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed