[CRIU] [PATCH] restore: call close_old_fds() beofre prepare_namespace_before_tasks

Andrey Vagin avagin at openvz.org
Tue Nov 17 03:45:27 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

Currently prepare_namespace_before_tasks() opens the host netns,
but close_old_fds closes it.

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Reported-by: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 cr-restore.c    | 17 +++++++++++------
 files.c         |  2 +-
 include/files.h |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index 1465856..9017dd8 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1508,12 +1508,6 @@ static int restore_task_with_children(void *_arg)
 		}
 	}
 
-	if (!(ca->clone_flags & CLONE_FILES)) {
-		ret = close_old_fds(current);
-		if (ret)
-			goto err_fini_mnt;
-	}
-
 	/* Restore root task */
 	if (current->parent == NULL) {
 		if (restore_finish_stage(CR_STATE_RESTORE_NS) < 0)
@@ -1535,6 +1529,9 @@ static int restore_task_with_children(void *_arg)
 
 		if (restore_finish_stage(CR_STATE_RESTORE_SHARED) < 0)
 			goto err_fini_mnt;
+	} else if (!(ca->clone_flags & CLONE_FILES)) {
+		if (close_old_fds())
+			goto err_fini_mnt;
 	}
 
 	if (restore_task_mnt_ns(current))
@@ -1805,6 +1802,14 @@ static int restore_root_task(struct pstree_item *init)
 		return -1;
 	}
 
+	/*
+	 * Call close_old_fds() here, because prepare_namespace_before_tasks()
+	 * will open file descriotos which are required for restoring namespaces.
+	 * For example, it's ns_fd in net.c.
+	 */
+	if (close_old_fds())
+		return -1;
+
 	if (prepare_namespace_before_tasks())
 		return -1;
 
diff --git a/files.c b/files.c
index da6a5ae..17a31a5 100644
--- a/files.c
+++ b/files.c
@@ -1011,7 +1011,7 @@ static int open_fdinfos(int pid, struct list_head *list, int state)
 
 static struct inherit_fd *inherit_fd_lookup_fd(int fd, const char *caller);
 
-int close_old_fds(struct pstree_item *me)
+int close_old_fds()
 {
 	DIR *dir;
 	struct dirent *de;
diff --git a/include/files.h b/include/files.h
index db7e108..52936ff 100644
--- a/include/files.h
+++ b/include/files.h
@@ -156,7 +156,7 @@ extern int restore_fs(struct pstree_item *);
 extern int prepare_fs_pid(struct pstree_item *);
 extern int set_fd_flags(int fd, int flags);
 
-extern int close_old_fds(struct pstree_item *me);
+extern int close_old_fds(void);
 #ifndef AT_EMPTY_PATH
 #define AT_EMPTY_PATH 0x1000
 #endif
-- 
2.4.3



More information about the CRIU mailing list