[CRIU] [PATCH 2/3] mnt: Add mi->root resolving helper

Pavel Emelyanov xemul at parallels.com
Fri Sep 18 02:17:09 PDT 2015


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 mount.c | 97 +++++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 52 insertions(+), 45 deletions(-)

diff --git a/mount.c b/mount.c
index 1afdbec..945cd1c 100644
--- a/mount.c
+++ b/mount.c
@@ -2331,6 +2331,56 @@ static int rst_collect_local_mntns(void)
 	return 0;
 }
 
+static int get_mp_root(MntEntry *me, struct mount_info *mi)
+{
+	struct ext_mount *em = NULL;
+
+	if (!me->ext_mount) {
+		mi->root = xstrdup(me->root);
+		if (!mi->root)
+			return -1;
+
+		goto out;
+	}
+
+	/*
+	 * External mount point -- get the reverse mapping
+	 * from the command line and put into root's place
+	 */
+
+	em = ext_mount_lookup(me->root);
+	if (!em) {
+		if (!opts.autodetect_ext_mounts) {
+			pr_err("No mapping for %s mountpoint\n", me->mountpoint);
+			return -1;
+		}
+
+		/*
+		 * Make up an external mount entry for this
+		 * mount point, since we couldn't find a user
+		 * supplied one.
+		 */
+		em = xmalloc(sizeof(struct ext_mount));
+		if (!em)
+			return -1;
+
+		/*
+		 * Put a : in here since those are invalid on
+		 * the cli, so we know it's autogenerated in
+		 * debugging.
+		 */
+		em->key = AUTODETECTED_MOUNT;
+		em->val = mi->source;
+	}
+
+	mi->external = em;
+	mi->root = em->val;
+out:
+	pr_debug("\t\tWill mount %d from %s%s\n",
+			mi->mnt_id, mi->root, em ? " (E)" : "");
+	return 0;
+}
+
 static int get_mp_mountpoint(MntEntry *me, struct mount_info *mi, char *root, int root_len)
 {
 	int len;
@@ -2408,51 +2458,8 @@ 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->ext_mount) {
-			struct ext_mount *em;
-
-			/*
-			 * External mount point -- get the reverse mapping
-			 * from the command line and put into root's place
-			 */
-
-			em = ext_mount_lookup(me->root);
-			if (!em) {
-				if (!opts.autodetect_ext_mounts) {
-					pr_err("No mapping for %s mountpoint\n", me->mountpoint);
-					goto err;
-				}
-
-				/*
-				 * Make up an external mount entry for this
-				 * mount point, since we couldn't find a user
-				 * supplied one.
-				 */
-				em = xmalloc(sizeof(struct ext_mount));
-				if (!em)
-					goto err;
-
-				em->val = pm->source;
-
-				/*
-				 * Put a : in here since those are invalid on
-				 * the cli, so we know it's autogenerated in
-				 * debugging.
-				 */
-				em->key = AUTODETECTED_MOUNT;
-			}
-
-			pm->external = em;
-			pm->root = em->val;
-			pr_debug("Mountpoint %s will have root from %s\n",
-					me->mountpoint, pm->root);
-
-		} else {
-			pr_debug("\t\tGetting root for %d\n", pm->mnt_id);
-			pm->root = xstrdup(me->root);
-			if (!pm->root)
-				goto err;
-		}
+		if (get_mp_root(me, pm))
+			goto err;
 
 		if (get_mp_mountpoint(me, pm, root, root_len))
 			goto err;
-- 
1.9.3




More information about the CRIU mailing list