[CRIU] [PATCH 5/5] mnt: Clean roots yard from criu process

Pavel Emelyanov xemul at parallels.com
Mon Sep 21 04:12:16 PDT 2015


So here it is. If root task dies on restore the roots yard
dir remains unrmdired :( Since we already know its name, we
can remove one from criu. By the time we get to this place
the sub mount namespace(s) are already dead and yard dir
is empty. But umounting should be done by tasks after
successfull restore, so keep depopulation there.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-restore.c    |  6 +++---
 include/mount.h |  1 +
 mount.c         | 13 +++++++++----
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/cr-restore.c b/cr-restore.c
index d3cc50c..4171155 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1546,9 +1546,6 @@ static int restore_task_with_children(void *_arg)
 	return 0;
 
 err_fini_mnt:
-	if (current->parent == NULL)
-		depopulate_roots_yard();
-
 err:
 	if (current->parent == NULL)
 		futex_abort_and_wake(&task_entries->nr_in_progress);
@@ -1835,6 +1832,8 @@ static int restore_root_task(struct pstree_item *init)
 	 */
 	task_entries->nr_threads -= atomic_read(&task_entries->nr_zombies);
 
+	cleanup_mnt_ns();
+
 	ret = stop_usernsd();
 	if (ret < 0)
 		goto out_kill;
@@ -1919,6 +1918,7 @@ out_kill:
 
 out:
 	fini_cgroup();
+	cleanup_mnt_ns();
 	stop_usernsd();
 	__restore_switch_stage(CR_STATE_FAIL);
 	pr_err("Restoring FAILED.\n");
diff --git a/include/mount.h b/include/mount.h
index ca27593..08edfa2 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -118,5 +118,6 @@ extern int depopulate_roots_yard(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);
+extern void cleanup_mnt_ns(void);
 
 #endif /* __CR_MOUNT_H__ */
diff --git a/mount.c b/mount.c
index c882fff..3ded7a4 100644
--- a/mount.c
+++ b/mount.c
@@ -2744,14 +2744,19 @@ int depopulate_roots_yard(void)
 		pr_perror("Can't unmount %s", mnt_roots);
 		ret = 1;
 	}
-	if (rmdir(mnt_roots)) {
-		pr_perror("Can't remove the directory %s", mnt_roots);
-		ret = 1;
-	}
 
 	return ret;
 }
 
+void cleanup_mnt_ns(void)
+{
+	if (mnt_roots == NULL)
+		return;
+
+	if (rmdir(mnt_roots))
+		pr_perror("Can't remove the directory %s", mnt_roots);
+}
+
 int prepare_mnt_ns(void)
 {
 	int ret = -1;
-- 
1.9.3




More information about the CRIU mailing list