[CRIU] [PATCH 1/3] mnt: Add mi->mountpoint resolving helper

Pavel Emelyanov xemul at parallels.com
Fri Sep 18 02:16:34 PDT 2015


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

diff --git a/mount.c b/mount.c
index a5a0d2e..1afdbec 100644
--- a/mount.c
+++ b/mount.c
@@ -2331,6 +2331,31 @@ static int rst_collect_local_mntns(void)
 	return 0;
 }
 
+static int get_mp_mountpoint(MntEntry *me, struct mount_info *mi, char *root, int root_len)
+{
+	int len;
+
+	len  = strlen(me->mountpoint) + root_len + 1;
+	mi->mountpoint = xmalloc(len);
+	if (!mi->mountpoint)
+		return -1;
+
+	/*
+	 * For bind-mounts we would also fix the root here
+	 * too, but bind-mounts restore merges mountpoint
+	 * and root paths together, so there's no need in
+	 * that.
+	 */
+
+	strcpy(mi->mountpoint, root);
+	strcpy(mi->mountpoint + root_len, me->mountpoint);
+
+	mi->ns_mountpoint = mi->mountpoint + root_len;
+
+	pr_debug("\t\tWill mount %d @ %s\n", mi->mnt_id, mi->mountpoint);
+	return 0;
+}
+
 static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 {
 	MntEntry *me = NULL;
@@ -2349,7 +2374,6 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 
 	while (1) {
 		struct mount_info *pm;
-		int len;
 
 		ret = pb_read_one_eof(img, &me, PB_MNT);
 		if (ret <= 0)
@@ -2430,22 +2454,8 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
 				goto err;
 		}
 
-		len  = strlen(me->mountpoint) + root_len + 1;
-		pm->mountpoint = xmalloc(len);
-		if (!pm->mountpoint)
+		if (get_mp_mountpoint(me, pm, root, root_len))
 			goto err;
-		pm->ns_mountpoint = pm->mountpoint + root_len;
-		/*
-		 * For bind-mounts we would also fix the root here
-		 * too, but bind-mounts restore merges mountpoint
-		 * and root paths together, so there's no need in
-		 * that.
-		 */
-
-		strcpy(pm->mountpoint, root);
-		strcpy(pm->mountpoint + root_len, me->mountpoint);
-
-		pr_debug("\t\tGetting mpt for %d %s\n", pm->mnt_id, pm->mountpoint);
 
 		pr_debug("\t\tGetting opts for %d\n", pm->mnt_id);
 		pm->options = xstrdup(me->options);
-- 
1.9.3



More information about the CRIU mailing list