[CRIU] [PATCH 3/3] util: Add make_yard helper

Pavel Emelyanov xemul at parallels.com
Tue Sep 22 04:50:20 PDT 2015


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cgroup.c       |  9 +--------
 include/util.h |  2 ++
 mount.c        |  6 +-----
 util.c         | 17 ++++++++++++++++-
 4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index 7bdccf8..e1288c7 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -1154,15 +1154,8 @@ static int prepare_cgroup_sfd(CgroupEntry *ce)
 		return -1;
 	}
 
-	if (mount("none", cg_yard, "tmpfs", 0, NULL)) {
-		pr_perror("Can't mount tmpfs in cgyard");
+	if (make_yard(cg_yard))
 		goto err;
-	}
-
-	if (mount("none", cg_yard, NULL, MS_PRIVATE, NULL)) {
-		pr_perror("Can't make cgyard private");
-		goto err;
-	}
 
 	pr_debug("Opening %s as cg yard\n", cg_yard);
 	i = open(cg_yard, O_DIRECTORY);
diff --git a/include/util.h b/include/util.h
index f2300a9..21a21b8 100644
--- a/include/util.h
+++ b/include/util.h
@@ -261,4 +261,6 @@ void split(char *str, char token, char ***out, int *n);
 
 int fd_has_data(int lfd);
 
+int make_yard(char *path);
+
 #endif /* __CR_UTIL_H__ */
diff --git a/mount.c b/mount.c
index 34d11e8..7226616 100644
--- a/mount.c
+++ b/mount.c
@@ -2652,11 +2652,7 @@ static int populate_roots_yard(void)
 	if (mnt_roots == NULL)
 		return 0;
 
-	if (mount("none", mnt_roots, "tmpfs", 0, NULL)) {
-		pr_perror("Unable to mount tmpfs in %s", mnt_roots);
-		return -1;
-	}
-	if (mount("none", mnt_roots, NULL, MS_PRIVATE, NULL))
+	if (make_yard(mnt_roots))
 		return -1;
 
 	for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
diff --git a/util.c b/util.c
index b916eca..75758b7 100644
--- a/util.c
+++ b/util.c
@@ -14,7 +14,7 @@
 #include <sys/sendfile.h>
 #include <fcntl.h>
 #include <poll.h>
-
+#include <sys/mount.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/ptrace.h>
@@ -845,3 +845,18 @@ int fd_has_data(int lfd)
 
 	return ret;
 }
+
+int make_yard(char *path)
+{
+	if (mount("none", path, "tmpfs", 0, NULL)) {
+		pr_perror("Unable to mount tmpfs in %s", path);
+		return -1;
+	}
+
+	if (mount("none", path, NULL, MS_PRIVATE, NULL)) {
+		pr_perror("Unable to mark yard as private");
+		return -1;
+	}
+
+	return 0;
+}
-- 
1.9.3




More information about the CRIU mailing list