[1/7] mnt_ns: Move open_proc() up in prepare_mnt_ns()

Submitted by Kirill Tkhai on June 28, 2017, 3:53 p.m.

Details

Message ID 149866523697.31392.2192455230422864876.stgit@localhost.localdomain
State New
Series "Skip iteration on open files to find parent's leftovers (optimize child creation)"
Headers show

Commit Message

Kirill Tkhai June 28, 2017, 3:53 p.m.
The both branches need this, so move it up.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/mount.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index b7c4785b1..9a08506dd 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -3023,9 +3023,11 @@  int prepare_mnt_ns(void)
 			goto err;
 		}
 
-		if (nsid->type == NS_ROOT) {
-			int fd;
+		fd = open_proc(PROC_SELF, "ns/mnt");
+		if (fd < 0)
+			goto err;
 
+		if (nsid->type == NS_ROOT) {
 			/*
 			 * We need to create a mount namespace which will be
 			 * used to clean up remap files
@@ -3034,9 +3036,6 @@  int prepare_mnt_ns(void)
 			 * namespace, because there are file descriptors
 			 * linked with it (e.g. to bind-mount slave pty-s).
 			 */
-			fd = open_proc(PROC_SELF, "ns/mnt");
-			if (fd < 0)
-				goto err;
 			if (setns(rst, CLONE_NEWNS)) {
 				pr_perror("Can't restore mntns back");
 				goto err;
@@ -3045,9 +3044,7 @@  int prepare_mnt_ns(void)
 			rst = fd;
 		} else {
 			/* Pin one with a file descriptor */
-			nsid->mnt.ns_fd = open_proc(PROC_SELF, "ns/mnt");
-			if (nsid->mnt.ns_fd < 0)
-				goto err;
+			nsid->mnt.ns_fd = fd;
 		}
 
 		/* Set its root */