[CRIU] [PATCH 1/2] mount: Prepare fstypes to contain more unsupported FSs

Pavel Emelyanov xemul at parallels.com
Wed Dec 4 07:51:10 PST 2013


We will need to parse btrfs stuff, but this one is not
in the supported list yet (as it's bound to hardware).

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/proc_parse.h |  1 +
 mount.c              | 68 +++++++++++++++++++++++++++++++++-------------------
 2 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/include/proc_parse.h b/include/proc_parse.h
index dd6e62a..a313d30 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -93,6 +93,7 @@ struct proc_status_creds {
 struct mount_info;
 struct fstype {
 	char *name;
+	int code;
 	int (*dump)(struct mount_info *pm);
 	int (*restore)(struct mount_info *pm);
 };
diff --git a/mount.c b/mount.c
index 22b8383..ebc5656 100644
--- a/mount.c
+++ b/mount.c
@@ -576,14 +576,34 @@ out:
 }
 
 static struct fstype fstypes[] = {
-	[FSTYPE__UNSUPPORTED]	= { "unsupported" },
-	[FSTYPE__PROC]		= { "proc" },
-	[FSTYPE__SYSFS]		= { "sysfs" },
-	[FSTYPE__DEVTMPFS]	= { "devtmpfs" },
-	[FSTYPE__BINFMT_MISC]	= { "binfmt_misc", binfmt_misc_dump },
-	[FSTYPE__TMPFS]		= { "tmpfs", tmpfs_dump, tmpfs_restore },
-	[FSTYPE__DEVPTS]	= { "devpts" },
-	[FSTYPE__SIMFS]		= { "simfs" },
+	{ 
+		.name = "unsupported",
+		.code = FSTYPE__UNSUPPORTED,
+	}, {
+		.name = "proc",
+		.code = FSTYPE__PROC,
+	}, {
+		.name = "sysfs",
+		.code = FSTYPE__SYSFS,
+	}, {
+		.name = "devtmpfs",
+		.code = FSTYPE__DEVTMPFS,
+	}, {
+		.name = "binfmt_misc",
+		.code = FSTYPE__BINFMT_MISC,
+		.dump = binfmt_misc_dump,
+	}, {
+		.name = "tmpfs",
+		.code = FSTYPE__TMPFS,
+		.dump = tmpfs_dump,
+		.restore = tmpfs_restore,
+	}, {
+		.name = "devpts",
+		.code = FSTYPE__DEVPTS,
+	}, {
+		.name = "simfs",
+		.code = FSTYPE__SIMFS,
+	}
 };
 
 struct fstype *find_fstype_by_name(char *fst)
@@ -605,18 +625,18 @@ struct fstype *find_fstype_by_name(char *fst)
 	return &fstypes[0];
 }
 
-static u32 encode_fstype(struct fstype *fst)
-{
-	return fst - fstypes;
-}
-
 static struct fstype *decode_fstype(u32 fst)
 {
+	int i;
 
-	if (fst >= ARRAY_SIZE(fstypes))
-		return &fstypes[0];
+	if (fst == FSTYPE__UNSUPPORTED)
+		goto uns;
 
-	return &fstypes[fst];
+	for (i = 0; i < ARRAY_SIZE(fstypes); i++)
+		if (fstypes[i].code == fst)
+			return fstypes + i;
+uns:
+	return &fstypes[0];
 }
 
 static int dump_one_mountpoint(struct mount_info *pm, int fd)
@@ -626,8 +646,14 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
 	pr_info("\t%d: %x:%s @ %s\n", pm->mnt_id, pm->s_dev,
 			pm->root, pm->mountpoint);
 
-	me.fstype		= encode_fstype(pm->fstype);
-	if (fstypes[me.fstype].dump && fstypes[me.fstype].dump(pm))
+	me.fstype		= pm->fstype->code;
+	if ((me.fstype == FSTYPE__UNSUPPORTED) && !is_root_mount(pm)) {
+		pr_err("FS mnt %s dev %#x root %s unsupported\n",
+				pm->mountpoint, pm->s_dev, pm->root);
+		return -1;
+	}
+
+	if (pm->fstype->dump && pm->fstype->dump(pm))
 		return -1;
 
 	me.mnt_id		= pm->mnt_id;
@@ -643,12 +669,6 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
 	me.master_id		= pm->master_id;
 	me.has_master_id	= true;
 
-	if (!me.fstype && !is_root_mount(pm)) {
-		pr_err("FS mnt %s dev %#x root %s unsupported\n",
-				pm->mountpoint, pm->s_dev, pm->root);
-		return -1;
-	}
-
 	if (pb_write_one(fd, &me, PB_MNT))
 		return -1;
 
-- 
1.8.3.1


More information about the CRIU mailing list