render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 583928aa5c4d1b28304aa6484ad20cd2036407ae Mon Sep 17 00:00:00 2001
Message-Id: <583928aa5c4d1b28304aa6484ad20cd2036407ae@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:29 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2BindMount
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 cda8ed0646d82f95d4424cfadfb9233037b1d815)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <c99f93d93fe7a944219b860a2a76b18303c27479.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroupv2.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 074e6ec110..90ce660908 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -21,6 +21,7 @@
 
 #ifdef __linux__
 # include <mntent.h>
+# include <sys/mount.h>
 #endif /* __linux__ */
 
 #include "internal.h"
@@ -462,6 +463,38 @@ virCgroupV2HasEmptyTasks(virCgroupPtr cgroup,
 }
 
 
+static int
+virCgroupV2BindMount(virCgroupPtr group,
+                     const char *oldroot,
+                     const char *mountopts)
+{
+    VIR_AUTOFREE(char *) opts = NULL;
+    VIR_AUTOFREE(char *) src = NULL;
+
+    VIR_DEBUG("Mounting cgroups at '%s'", group->unified.mountPoint);
+
+    if (virFileMakePath(group->unified.mountPoint) < 0) {
+        virReportSystemError(errno, _("Unable to create directory %s"),
+                             group->unified.mountPoint);
+        return -1;
+    }
+
+    if (virAsprintf(&opts, "mode=755,size=65536%s", mountopts) < 0)
+        return -1;
+
+    if (virAsprintf(&src, "%s%s", oldroot, group->unified.mountPoint) < 0)
+        return -1;
+
+    if (mount(src, group->unified.mountPoint, "none", MS_BIND, NULL) < 0) {
+        virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'"),
+                             src, group->unified.mountPoint);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -481,6 +514,7 @@ virCgroupBackend virCgroupV2Backend = {
     .remove = virCgroupV2Remove,
     .addTask = virCgroupV2AddTask,
     .hasEmptyTasks = virCgroupV2HasEmptyTasks,
+    .bindMount = virCgroupV2BindMount,
 };
 
 
-- 
2.22.0