[1/4,v4] mount: don't add a separate entry for each enabled file systems

Submitted by Andrei Vagin on May 6, 2016, 2:05 a.m.

Details

Message ID 1462500311-18305-1-git-send-email-avagin@openvz.org
State Rejected
Series "Series without cover letter"
Headers show

Commit Message

Andrei Vagin May 6, 2016, 2:05 a.m.
From: Andrew Vagin <avagin@virtuozzo.com>

It isn't required and we will not have a limit for enabled file systems.

v2: clean up
v3: add a shortcut to get a mount file system
v4: fix comments from Pavel

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
---
 criu/include/mount.h |  1 +
 criu/mount.c         | 55 ++++++++++++++++++++++++++++------------------------
 criu/proc_parse.c    |  4 ++++
 3 files changed, 35 insertions(+), 25 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/mount.h b/criu/include/mount.h
index b3bbdce..59e7f9a 100644
--- a/criu/include/mount.h
+++ b/criu/include/mount.h
@@ -56,6 +56,7 @@  struct mount_info {
 	struct fstype		*fstype;
 	char			*source;
 	char			*options;
+	char			*fsname;
 	union {
 		bool		mounted;
 		bool		dumped;
diff --git a/criu/mount.c b/criu/mount.c
index 431341e..d5e009b 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -1679,11 +1679,14 @@  static int always_fail(struct mount_info *pm)
 	return -1;
 }
 
-static struct fstype fstypes[32] = {
+static struct fstype fstypes[] = {
 	{
 		.name = "unsupported",
 		.code = FSTYPE__UNSUPPORTED,
 	}, {
+		.name = "auto_cr",
+		.code = FSTYPE__AUTO,
+	}, {
 		.name = "proc",
 		.code = FSTYPE__PROC,
 	}, {
@@ -1811,7 +1814,7 @@  bool add_fsname_auto(const char *names)
 	return fsauto_names != NULL;
 }
 
-static struct fstype *__find_fstype_by_name(char *fst, bool force_auto)
+struct fstype *find_fstype_by_name(char *fst)
 {
 	int i;
 
@@ -1825,37 +1828,20 @@  static struct fstype *__find_fstype_by_name(char *fst, bool force_auto)
 	for (i = 1; i < ARRAY_SIZE(fstypes); i++) {
 		struct fstype *fstype = fstypes + i;
 
-		if (!fstype->name) {
-			if (!force_auto && !fsname_is_auto(fst))
-				break;
-
-			fstype->name = xstrdup(fst);
-			fstype->code = FSTYPE__AUTO;
-			return fstype;
-		}
-
 		if (!strcmp(fstype->name, fst))
 			return fstype;
 	}
 
-	if (i == ARRAY_SIZE(fstypes)) /* ensure we have a room for auto */
-		pr_err_once("fstypes[] overflow!\n");
+	if (fsname_is_auto(fst))
+		return &fstypes[1];
 
 	return &fstypes[0];
 }
 
-struct fstype *find_fstype_by_name(char *fst)
-{
-	return __find_fstype_by_name(fst, false);
-}
-
-static struct fstype *decode_fstype(u32 fst, char *fsname)
+static struct fstype *decode_fstype(u32 fst)
 {
 	int i;
 
-	if (fst == FSTYPE__AUTO)
-		return __find_fstype_by_name(fsname, true);
-
 	if (fst == FSTYPE__UNSUPPORTED)
 		goto uns;
 
@@ -1882,7 +1868,7 @@  static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img)
 	me.fstype		= pm->fstype->code;
 
 	if (me.fstype == FSTYPE__AUTO)
-		me.fsname = pm->fstype->name;
+		me.fsname = pm->fsname;
 
 	if (pm->parent && !pm->dumped && !pm->need_plugin && !pm->external &&
 	    pm->fstype->dump && fsroot_mounted(pm)) {
@@ -2280,6 +2266,13 @@  static int do_simple_mount(struct mount_info *mi, const char *src, const
 	return mount(src, mi->mountpoint, fstype, mountflags, mi->options);
 }
 
+static char *mnt_fsname(struct mount_info *mi)
+{
+	if (mi->fstype->code == FSTYPE__AUTO)
+		return mi->fsname;
+	return mi->fstype->name;
+}
+
 static int do_new_mount(struct mount_info *mi)
 {
 	unsigned long sflags = mi->sb_flags;
@@ -2302,7 +2295,7 @@  static int do_new_mount(struct mount_info *mi)
 	if (remount_ro)
 		sflags &= ~MS_RDONLY;
 
-	if (do_mount(mi, src, tp->name, sflags) < 0) {
+	if (do_mount(mi, src, mnt_fsname(mi), sflags) < 0) {
 		pr_perror("Can't mount at %s", mi->mountpoint);
 		return -1;
 	}
@@ -2739,6 +2732,7 @@  void mnt_entry_free(struct mount_info *mi)
 		xfree(mi->mountpoint);
 		xfree(mi->source);
 		xfree(mi->options);
+		xfree(mi->fsname);
 		xfree(mi);
 	}
 }
@@ -2949,8 +2943,19 @@  static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 		if (!pm->options)
 			goto err;
 
+		if (me->fstype != FSTYPE__AUTO && me->fsname) {
+			pr_err("fsname can't be set only for FSTYPE__AUTO mounts\n");
+			goto err;
+		}
+
 		/* FIXME: abort unsupported early */
-		pm->fstype = decode_fstype(me->fstype, me->fsname);
+		pm->fstype = decode_fstype(me->fstype);
+
+		if (me->fsname) {
+			pm->fsname = xstrdup(me->fsname);
+			if (!pm->fsname)
+				goto err;
+		}
 
 		if (get_mp_root(me, pm))
 			goto err;
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 174b540..ec1a7f1 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1277,6 +1277,10 @@  static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
 
 	cure_path(new->source);
 
+	new->fsname = xstrdup(*fsname);
+	if (!new->fsname)
+		goto err;
+
 	/*
 	 * The kernel reports "subtypes" sometimes and the valid
 	 * type-vs-subtype delimiter is the dot symbol. We disregard

Comments

Pavel Emelianov May 6, 2016, 12:12 p.m.
This one applied.