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

Submitted by Andrei Vagin on April 28, 2016, 4:53 p.m.

Details

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

Commit Message

Andrei Vagin April 28, 2016, 4:53 p.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

Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
---
 criu/include/mount.h |  1 +
 criu/mount.c         | 45 ++++++++++++++++++++++-----------------------
 criu/proc_parse.c    |  4 ++++
 3 files changed, 27 insertions(+), 23 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 d82270e..78fe3a3 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)
 {
 	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;
 	}
@@ -2746,6 +2739,7 @@  void mnt_entry_free(struct mount_info *mi)
 		xfree(mi->mountpoint);
 		xfree(mi->source);
 		xfree(mi->options);
+		xfree(mi->fsname);
 		xfree(mi);
 	}
 }
@@ -2958,6 +2952,11 @@  static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 
 		/* FIXME: abort unsupported early */
 		pm->fstype = decode_fstype(me->fstype, me->fsname);
+		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 04ab14e..00939b5 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -1301,6 +1301,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 5, 2016, 12:13 p.m.
>  
> -struct fstype *find_fstype_by_name(char *fst)
> -{
> -	return __find_fstype_by_name(fst, false);
> -}
> -
>  static struct fstype *decode_fstype(u32 fst, char *fsname)

The fsname arguments becomes unused.

>  {
>  	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;
>  	}
> @@ -2746,6 +2739,7 @@ void mnt_entry_free(struct mount_info *mi)
>  		xfree(mi->mountpoint);
>  		xfree(mi->source);
>  		xfree(mi->options);
> +		xfree(mi->fsname);
>  		xfree(mi);
>  	}
>  }
> @@ -2958,6 +2952,11 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
>  
>  		/* FIXME: abort unsupported early */

Here should go

	if (me->fsname && me->fstype != AUTO) {
		pr_err("Error in image\n");
		goto err;
	}

or smth like this.


>  		pm->fstype = decode_fstype(me->fstype, me->fsname);
> +		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 04ab14e..00939b5 100644
> --- a/criu/proc_parse.c
> +++ b/criu/proc_parse.c
> @@ -1301,6 +1301,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
>