[CRIU] [PATCH 4/4] mount: open_mount uses __open_mountpoint instead of own logic

Andrey Vagin avagin at openvz.org
Tue Apr 15 01:31:42 PDT 2014


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-restore.c |  4 ++++
 mount.c      | 20 ++++----------------
 2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index cd2f847..a3d423d 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1263,6 +1263,9 @@ static int restore_task_with_children(void *_arg)
 		if (close_old_fds(current))
 			exit(1);
 
+		if (mntns_collect_root(getpid()))
+			exit(1);
+
 		if (root_prepare_shared())
 			exit(1);
 	}
@@ -2527,6 +2530,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
 		goto err;
 
 	close_image_dir();
+	close_service_fd(ROOT_FD_OFF);
 
 	__gcov_flush();
 
diff --git a/mount.c b/mount.c
index 4b93858..a9e06e3 100644
--- a/mount.c
+++ b/mount.c
@@ -69,26 +69,14 @@ static inline int fsroot_mounted(struct mount_info *mi)
 	return is_root(mi->root);
 }
 
+static int __open_mountpoint(struct mount_info *pm, int mnt_fd);
 int open_mount(unsigned int s_dev)
 {
 	struct mount_info *i;
-	int mntns_root;
-
-	mntns_root = get_service_fd(ROOT_FD_OFF);
 
 	for (i = mntinfo; i != NULL; i = i->next)
-		if (s_dev == i->s_dev) {
-			if (mntns_root == -1) {
-				pr_debug("mpopen %s\n", i->mountpoint);
-				return open(i->mountpoint, O_RDONLY);
-			} else if (is_root_mount(i)) {
-				pr_debug("mpopen root\n");
-				return dup(mntns_root);
-			} else {
-				pr_debug("mpopen %d:%s\n", mntns_root, i->mountpoint + 1);
-				return openat(mntns_root, i->mountpoint + 1, O_RDONLY);
-			}
-		}
+		if (s_dev == i->s_dev)
+			return __open_mountpoint(i, -1);
 
 	return -ENOENT;
 }
@@ -488,7 +476,7 @@ static int __open_mountpoint(struct mount_info *pm, int mnt_fd)
 
 		mntns_root = get_service_fd(ROOT_FD_OFF);
 
-		snprintf(path, sizeof(path), ".%s", pm->mountpoint);
+		snprintf(path, sizeof(path), "./%s", pm->mountpoint);
 		mnt_fd = openat(mntns_root, path, O_RDONLY);
 		if (mnt_fd < 0) {
 			pr_perror("Can't open %s", pm->mountpoint);
-- 
1.8.5.3



More information about the CRIU mailing list