[CRIU] [PATCH 2/2] restore: don't collect mounts if mntns isn't restored

Andrei Vagin avagin at openvz.org
Thu Apr 27 17:59:31 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

Currently it is only used to get a file descriptor to the mount
namespace root, but if we have only one mntns, we can open "/".

Cc: Pavel Emelyanov <xemul at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/fsnotify.c |  1 -
 criu/mount.c    | 28 ++++++++--------------------
 2 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/criu/fsnotify.c b/criu/fsnotify.c
index a127218..6bc840c 100644
--- a/criu/fsnotify.c
+++ b/criu/fsnotify.c
@@ -532,7 +532,6 @@ static char *get_mark_path(const char *who, struct file_remap *remap,
 		char *path = ".";
 		uint32_t mnt_id = f_handle->has_mnt_id ? f_handle->mnt_id : -1;
 
-
 		/* irmap cache is collected in the root namespaces. */
 		mntns_root = mntns_get_root_by_mnt_id(mnt_id);
 
diff --git a/criu/mount.c b/criu/mount.c
index 7ff0767..a3f471f 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2457,22 +2457,6 @@ out:
 	return exit_code;
 }
 
-static int rst_collect_local_mntns(enum ns_type typ)
-{
-	struct ns_id *nsid;
-
-	nsid = rst_new_ns_id(0, getpid(), &mnt_ns_desc, typ);
-	if (!nsid)
-		return -1;
-
-	mntinfo = collect_mntinfo(nsid, false);
-	if (!mntinfo)
-		return -1;
-
-	nsid->ns_populated = true;
-	return 0;
-}
-
 static int get_mp_root(MntEntry *me, struct mount_info *mi)
 {
 	char *ext = NULL;
@@ -2967,7 +2951,7 @@ int prepare_mnt_ns(void)
 	struct ns_id *nsid;
 
 	if (!(root_ns_mask & CLONE_NEWNS))
-		return rst_collect_local_mntns(NS_CRIU);
+		return 0;
 
 	pr_info("Restoring mount namespace\n");
 
@@ -3144,6 +3128,8 @@ set_root:
 
 int mntns_get_root_fd(struct ns_id *mntns)
 {
+	if (!(root_ns_mask & CLONE_NEWNS))
+		return __mntns_get_root_fd(0);
 	/*
 	 * All namespaces are restored from the root task and during the
 	 * CR_STATE_FORKING stage the root task has two file descriptors for
@@ -3194,10 +3180,12 @@ struct ns_id *lookup_nsid_by_mnt_id(int mnt_id)
 
 int mntns_get_root_by_mnt_id(int mnt_id)
 {
-	struct ns_id *mntns;
+	struct ns_id *mntns = NULL;
 
-	mntns = lookup_nsid_by_mnt_id(mnt_id);
-	BUG_ON(mntns == NULL);
+	if (root_ns_mask & CLONE_NEWNS) {
+		mntns = lookup_nsid_by_mnt_id(mnt_id);
+		BUG_ON(mntns == NULL);
+	}
 
 	return mntns_get_root_fd(mntns);
 }
-- 
2.9.3



More information about the CRIU mailing list