<div dir="ltr"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 18, 2018 at 5:45 PM, Pavel Hrdina <span dir="ltr"><<a href="mailto:phrdina@redhat.com" target="_blank">phrdina@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Pavel Hrdina <<a href="mailto:phrdina@redhat.com" target="_blank">phrdina@redhat.com</a>><br></blockquote><div><br></div><div>Reviewed-by: Fabiano Fidêncio <<a href="mailto:fidencio@redhat.com" target="_blank">fidencio@redhat.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
---<br>
src/util/vircgroup.c | 102 +-----------------------------<wbr>--<br>
src/util/vircgroupbackend.h | 6 ++<br>
src/util/vircgroupv1.c | 113 ++++++++++++++++++++++++++++++<wbr>++++++<br>
3 files changed, 120 insertions(+), 101 deletions(-)<br>
<br>
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c<br>
index f5ae23836f..29faf5fb2c 100644<br>
--- a/src/util/vircgroup.c<br>
+++ b/src/util/vircgroup.c<br>
@@ -3181,35 +3181,6 @@ virCgroupKillPainfully(virCgro<wbr>upPtr group)<br>
}<br>
<br>
<br>
-static char *<br>
-virCgroupIdentifyRoot(virCgro<wbr>upPtr group)<br>
-{<br>
- char *ret = NULL;<br>
- size_t i;<br>
-<br>
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
- char *tmp;<br>
- if (!group->controllers[i].mountP<wbr>oint)<br>
- continue;<br>
- if (!(tmp = strrchr(group->controllers[i].<wbr>mountPoint, '/'))) {<br>
- virReportError(VIR_ERR_INTERNA<wbr>L_ERROR,<br>
- _("Could not find directory separator in %s"),<br>
- group->controllers[i].mountPo<wbr>int);<br>
- return NULL;<br>
- }<br>
-<br>
- if (VIR_STRNDUP(ret, group->controllers[i].mountPoi<wbr>nt,<br>
- tmp - group->controllers[i].mountPoi<wbr>nt) < 0)<br>
- return NULL;<br>
- return ret;<br>
- }<br>
-<br>
- virReportError(VIR_ERR_INTERNA<wbr>L_ERROR, "%s",<br>
- _("Could not find any mounted controllers"));<br>
- return NULL;<br>
-}<br>
-<br>
-<br>
/**<br>
* virCgroupGetCpuCfsQuota:<br>
*<br>
@@ -3304,78 +3275,7 @@ int<br>
virCgroupBindMount(virCgroupP<wbr>tr group, const char *oldroot,<br>
const char *mountopts)<br>
{<br>
- size_t i;<br>
- VIR_AUTOFREE(char *) opts = NULL;<br>
- VIR_AUTOFREE(char *) root = NULL;<br>
-<br>
- if (!(root = virCgroupIdentifyRoot(group)))<br>
- return -1;<br>
-<br>
- VIR_DEBUG("Mounting cgroups at '%s'", root);<br>
-<br>
- if (virFileMakePath(root) < 0) {<br>
- virReportSystemError(errno,<br>
- _("Unable to create directory %s"),<br>
- root);<br>
- return -1;<br>
- }<br>
-<br>
- if (virAsprintf(&opts,<br>
- "mode=755,size=65536%s", mountopts) < 0)<br>
- return -1;<br>
-<br>
- if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {<br>
- virReportSystemError(errno,<br>
- _("Failed to mount %s on %s type %s"),<br>
- "tmpfs", root, "tmpfs");<br>
- return -1;<br>
- }<br>
-<br>
- for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
- if (!group->controllers[i].mountP<wbr>oint)<br>
- continue;<br>
-<br>
- if (!virFileExists(group->control<wbr>lers[i].mountPoint)) {<br>
- VIR_AUTOFREE(char *) src = NULL;<br>
- if (virAsprintf(&src, "%s%s",<br>
- oldroot,<br>
- group->controllers[i].mountPoi<wbr>nt) < 0)<br>
- return -1;<br>
-<br>
- VIR_DEBUG("Create mount point '%s'",<br>
- group->controllers[i].mountPoi<wbr>nt);<br>
- if (virFileMakePath(group->contro<wbr>llers[i].mountPoint) < 0) {<br>
- virReportSystemError(errno,<br>
- _("Unable to create directory %s"),<br>
- group->controllers[i].mountPo<wbr>int);<br>
- return -1;<br>
- }<br>
-<br>
- if (mount(src, group->controllers[i].mountPoi<wbr>nt, "none", MS_BIND,<br>
- NULL) < 0) {<br>
- virReportSystemError(errno,<br>
- _("Failed to bind cgroup '%s' on '%s'"),<br>
- src, group->controllers[i].mountPoi<wbr>nt);<br>
- return -1;<br>
- }<br>
- }<br>
-<br>
- if (group->controllers[i].linkPoi<wbr>nt) {<br>
- VIR_DEBUG("Link mount point '%s' to '%s'",<br>
- group->controllers[i].mountPoi<wbr>nt,<br>
- group->controllers[i].linkPoin<wbr>t);<br>
- if (symlink(group->controllers[i]<wbr>.mountPoint,<br>
- group->controllers[i].linkPoin<wbr>t) < 0) {<br>
- virReportSystemError(errno,<br>
- _("Unable to symlink directory %s to %s"),<br>
- group->controllers[i].mountPo<wbr>int,<br>
- group->controllers[i].linkPoi<wbr>nt);<br>
- return -1;<br>
- }<br>
- }<br>
- }<br>
-<br>
- return 0;<br>
+ return group->backend->bindMount(grou<wbr>p, oldroot, mountopts);<br>
}<br>
<br>
<br>
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h<br>
index 1964a48ff0..70deb47461 100644<br>
--- a/src/util/vircgroupbackend.h<br>
+++ b/src/util/vircgroupbackend.h<br>
@@ -118,6 +118,11 @@ typedef int<br>
(*virCgroupHasEmptyTasksCB)(v<wbr>irCgroupPtr cgroup,<br>
int controller);<br>
<br>
+typedef int<br>
+(*virCgroupBindMountCB)(virCg<wbr>roupPtr group,<br>
+ const char *oldroot,<br>
+ const char *mountopts);<br>
+<br>
struct _virCgroupBackend {<br>
virCgroupBackendType type;<br>
<br>
@@ -138,6 +143,7 @@ struct _virCgroupBackend {<br>
virCgroupRemoveCB remove;<br>
virCgroupAddTaskCB addTask;<br>
virCgroupHasEmptyTasksCB hasEmptyTasks;<br>
+ virCgroupBindMountCB bindMount;<br>
};<br>
typedef struct _virCgroupBackend virCgroupBackend;<br>
typedef virCgroupBackend *virCgroupBackendPtr;<br>
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c<br>
index 57bcb6a685..0514ba392d 100644<br>
--- a/src/util/vircgroupv1.c<br>
+++ b/src/util/vircgroupv1.c<br>
@@ -24,6 +24,9 @@<br>
# include <mntent.h><br>
#endif<br>
#include <sys/stat.h><br>
+#if defined HAVE_SYS_MOUNT_H<br>
+# include <sys/mount.h><br>
+#endif<br>
<br>
#include "internal.h"<br>
<br>
@@ -754,6 +757,115 @@ virCgroupV1HasEmptyTasks(virCg<wbr>roupPtr cgroup,<br>
}<br>
<br>
<br>
+static char *<br>
+virCgroupV1IdentifyRoot(virCg<wbr>roupPtr group)<br>
+{<br>
+ char *ret = NULL;<br>
+ size_t i;<br>
+<br>
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
+ char *tmp;<br>
+ if (!group->controllers[i].mountP<wbr>oint)<br>
+ continue;<br>
+ if (!(tmp = strrchr(group->controllers[i].<wbr>mountPoint, '/'))) {<br>
+ virReportError(VIR_ERR_INTERNA<wbr>L_ERROR,<br>
+ _("Could not find directory separator in %s"),<br>
+ group->controllers[i].mountPo<wbr>int);<br>
+ return NULL;<br>
+ }<br>
+<br>
+ if (VIR_STRNDUP(ret, group->controllers[i].mountPoi<wbr>nt,<br>
+ tmp - group->controllers[i].mountPoi<wbr>nt) < 0)<br>
+ return NULL;<br>
+ return ret;<br>
+ }<br>
+<br>
+ virReportError(VIR_ERR_INTERNA<wbr>L_ERROR, "%s",<br>
+ _("Could not find any mounted v1 controllers"));<br>
+ return NULL;<br>
+}<br>
+<br>
+<br>
+static int<br>
+virCgroupV1BindMount(virCgrou<wbr>pPtr group,<br>
+ const char *oldroot,<br>
+ const char *mountopts)<br>
+{<br>
+ size_t i;<br>
+ VIR_AUTOFREE(char *) opts = NULL;<br>
+ VIR_AUTOFREE(char *) root = NULL;<br>
+<br>
+ if (!(root = virCgroupV1IdentifyRoot(group)<wbr>))<br>
+ return -1;<br>
+<br>
+ VIR_DEBUG("Mounting cgroups at '%s'", root);<br>
+<br>
+ if (virFileMakePath(root) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("Unable to create directory %s"),<br>
+ root);<br>
+ return -1;<br>
+ }<br>
+<br>
+ if (virAsprintf(&opts,<br>
+ "mode=755,size=65536%s", mountopts) < 0)<br>
+ return -1;<br>
+<br>
+ if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("Failed to mount %s on %s type %s"),<br>
+ "tmpfs", root, "tmpfs");<br>
+ return -1;<br>
+ }<br>
+<br>
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {<br>
+ if (!group->controllers[i].mountP<wbr>oint)<br>
+ continue;<br>
+<br>
+ if (!virFileExists(group->control<wbr>lers[i].mountPoint)) {<br>
+ VIR_AUTOFREE(char *) src = NULL;<br>
+ if (virAsprintf(&src, "%s%s",<br>
+ oldroot,<br>
+ group->controllers[i].mountPoi<wbr>nt) < 0)<br>
+ return -1;<br>
+<br>
+ VIR_DEBUG("Create mount point '%s'",<br>
+ group->controllers[i].mountPoi<wbr>nt);<br>
+ if (virFileMakePath(group->contro<wbr>llers[i].mountPoint) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("Unable to create directory %s"),<br>
+ group->controllers[i].mountPo<wbr>int);<br>
+ return -1;<br>
+ }<br>
+<br>
+ if (mount(src, group->controllers[i].mountPoi<wbr>nt, "none", MS_BIND,<br>
+ NULL) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("Failed to bind cgroup '%s' on '%s'"),<br>
+ src, group->controllers[i].mountPoi<wbr>nt);<br>
+ return -1;<br>
+ }<br>
+ }<br>
+<br>
+ if (group->controllers[i].linkPoi<wbr>nt) {<br>
+ VIR_DEBUG("Link mount point '%s' to '%s'",<br>
+ group->controllers[i].mountPoi<wbr>nt,<br>
+ group->controllers[i].linkPoin<wbr>t);<br>
+ if (symlink(group->controllers[i]<wbr>.mountPoint,<br>
+ group->controllers[i].linkPoin<wbr>t) < 0) {<br>
+ virReportSystemError(errno,<br>
+ _("Unable to symlink directory %s to %s"),<br>
+ group->controllers[i].mountPo<wbr>int,<br>
+ group->controllers[i].linkPoi<wbr>nt);<br>
+ return -1;<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+<br>
virCgroupBackend virCgroupV1Backend = {<br>
.type = VIR_CGROUP_BACKEND_TYPE_V1,<br>
<br>
@@ -773,6 +885,7 @@ virCgroupBackend virCgroupV1Backend = {<br>
.remove = virCgroupV1Remove,<br>
.addTask = virCgroupV1AddTask,<br>
.hasEmptyTasks = virCgroupV1HasEmptyTasks,<br>
+ .bindMount = virCgroupV1BindMount,<br>
};<br>
<span class="m_-6942434379486921202gmail-HOEnZb"><font color="#888888"> <br>
<br>
-- <br>
2.17.1<br>
<br>
--<br>
libvir-list mailing list<br>
<a href="mailto:libvir-list@redhat.com" target="_blank">libvir-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvir-list" rel="noreferrer" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/libvir-list</a><br>
</font></span></blockquote></div><br></div></div></div>