[CRIU] [PATCH 2/5] mnt: Create roots in criu context

Pavel Emelyanov xemul at parallels.com
Mon Sep 21 04:08:41 PDT 2015


In case root task restore failure we'll have to remove the
roots yard dir from criu, so we have to create one by
criu to at least have the dit name.

It's OK to do it in criu, since the yards is created in
the opts.root which is the same for any mnt ns we deal
with on restore.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/mount.h |  1 +
 mount.c         | 36 ++++++++++++++++++++++++++----------
 namespaces.c    |  8 ++++++++
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/include/mount.h b/include/mount.h
index 76a8e24..6018dd7 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -117,5 +117,6 @@ extern int fini_mnt_ns(void);
 
 extern char *rst_get_mnt_root(int mnt_id);
 extern int ext_mount_add(char *key, char *val);
+extern int mntns_maybe_create_roots(void);
 
 #endif /* __CR_MOUNT_H__ */
diff --git a/mount.c b/mount.c
index 0bff365..55e2d92 100644
--- a/mount.c
+++ b/mount.c
@@ -2535,16 +2535,6 @@ static int read_mnt_ns_img(void)
 		if (nsid->nd != &mnt_ns_desc)
 			continue;
 
-		if (nsid->type != NS_ROOT) {
-			BUG_ON(nsid->type == NS_CRIU);
-			/*
-			 * If we have more than one (root) namespace,
-			 * then we'll need the roots yard.
-			 */
-			if (create_mnt_roots())
-				return -1;
-		}
-
 		if (collect_mnt_from_image(&pms, nsid))
 			return -1;
 	}
@@ -2574,6 +2564,32 @@ char *rst_get_mnt_root(int mnt_id)
 	return path;
 }
 
+int mntns_maybe_create_roots(void)
+{
+	struct ns_id *ns;
+
+	if (!(root_ns_mask & CLONE_NEWNS))
+		return 0;
+
+	for (ns = ns_ids; ns != NULL; ns = ns->next) {
+		if (ns->nd != &mnt_ns_desc)
+			continue;
+
+		if (ns->type != NS_ROOT) {
+			BUG_ON(ns->type == NS_CRIU);
+
+			/*
+			 * If we have more than one (root) namespace,
+			 * then we'll need the roots yard.
+			 */
+			return create_mnt_roots();
+		}
+	}
+
+	/* No "other" mntns found, just go ahead, we don't need roots yard. */
+	return 0;
+}
+
 static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *current)
 {
 	char path[PATH_MAX];
diff --git a/namespaces.c b/namespaces.c
index bb38459..135230e 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -1321,8 +1321,16 @@ int prepare_namespace_before_tasks(void)
 	if (netns_keep_nsfd())
 		goto err_netns;
 
+	if (mntns_maybe_create_roots())
+		goto err_mnt;
+
 	return 0;
 
+err_mnt:
+	/*
+	 * Nothing, netns' descriptor will be closed
+	 * on criu exit
+	 */
 err_netns:
 	stop_usernsd();
 err_unds:
-- 
1.9.3




More information about the CRIU mailing list