[CRIU] [PATCH] mount: detect the newinstance option for devpts

Andrey Vagin avagin at openvz.org
Tue Apr 1 03:44:32 PDT 2014


The devpts instance was mounted w/o the newinstance option if,
the device number is equal to the root /dev/pts.

I think this condition is strong enough to not mount devpts in a
temporary place.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/fs-magic.h |  4 ++++
 mount.c            | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/include/fs-magic.h b/include/fs-magic.h
index d31a939..9db3ee9 100644
--- a/include/fs-magic.h
+++ b/include/fs-magic.h
@@ -29,4 +29,8 @@
 # define SOCKFS_MAGIC		0x534f434b
 #endif
 
+#ifndef DEVPTS_SUPER_MAGIC
+#define DEVPTS_SUPER_MAGIC	0x1cd1
+#endif
+
 #endif /* __CR_FS_MAGIC_H__ */
diff --git a/mount.c b/mount.c
index 10d1378..71fbf97 100644
--- a/mount.c
+++ b/mount.c
@@ -23,6 +23,7 @@
 #include "proc_parse.h"
 #include "image.h"
 #include "namespaces.h"
+#include "fs-magic.h"
 #include "protobuf.h"
 #include "protobuf/mnt.pb-c.h"
 
@@ -578,6 +579,61 @@ out:
 	return NULL;
 }
 
+/* Is it mounted w or w/o the newinstance option */
+static int devpts_dump(struct mount_info *pm)
+{
+	static const char newinstance[] = ",newinstance";
+	static struct stat host_st = {};
+	struct stat st;
+	DIR *fdir = NULL;
+	char *buf;
+	int len;
+
+	if (host_st.st_dev == 0) {
+		struct statfs fst;
+
+		if (statfs("/dev/pts", &fst)) {
+			pr_perror("Unable to statefs /dev/pts");
+			return -1;
+		}
+		if (fst.f_type != DEVPTS_SUPER_MAGIC) {
+			pr_err("devpts isn't mount on the host\n");
+			return -1;
+		}
+
+		/* The root /dev/pts is mounted w/o newinstance, isn't it? */
+		if (stat("/dev/pts", &host_st)) {
+			pr_perror("Unable to state /dev/pts");
+			return -1;
+		}
+	}
+
+	fdir = open_mountpoint(pm);
+	if (fdir == NULL)
+		return -1;
+
+	if (fstat(dirfd(fdir), &st)) {
+		pr_perror("Unable to statfs %d:%s",
+				pm->mnt_id, pm->mountpoint);
+		close_mountpoint(fdir);
+		return -1;
+	}
+	close_mountpoint(fdir);
+
+	if (host_st.st_dev == st.st_dev)
+		return 0;
+
+	len = strlen(pm->options);
+	buf = xrealloc(pm->options, len + sizeof(newinstance));
+	if (buf == NULL)
+		return -1;
+	memcpy(buf, newinstance, sizeof(newinstance));
+
+	pm->options = buf;
+
+	return 0;
+}
+
 static int tmpfs_dump(struct mount_info *pm)
 {
 	int ret = -1;
@@ -694,6 +750,7 @@ static struct fstype fstypes[] = {
 		.restore = tmpfs_restore,
 	}, {
 		.name = "devpts",
+		.dump = devpts_dump,
 		.code = FSTYPE__DEVPTS,
 	}, {
 		.name = "simfs",
-- 
1.8.5.3



More information about the CRIU mailing list