[CRIU] [crtools-bot for Pavel Emelyanov ] dump: Restart seize in case reparent occurred

Cyrill Gorcunov gorcunov at openvz.org
Thu Mar 1 10:31:21 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit ae9f1bfdc4eb3b17f5f644220d4e63151059d322
Author: Pavel Emelyanov <xemul at parallels.com>
Date:   Thu Mar 1 19:12:35 2012 +0400

    dump: Restart seize in case reparent occurred
    
    This can happen while dumping a pid-namespace (we can't do it now), thus
    put this check not to forget one in the future.
    
    Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c         |   29 ++++++++++++++++++++++-------
 include/syscall.h |    4 ++++
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 36c5683..c5b2eef 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1010,14 +1010,31 @@ static int collect_subtree(pid_t pid, pid_t ppid, struct list_head *pstree_list,
 	return 0;
 }
 
-static int collect_pstree(pid_t pid, struct list_head *pstree_list, int leader_only)
+static int collect_pstree(pid_t pid, struct list_head *pstree_list,
+		struct cr_options *opts)
 {
 	int ret, attempts = 5;
 
 	while (1) {
-		ret = collect_subtree(pid, -1, pstree_list, leader_only);
-		if (ret == 0)
+		struct pstree_item *item;
+
+		ret = collect_subtree(pid, -1, pstree_list, opts->leader_only);
+		if (ret == 0) {
+			/*
+			 * Some tasks could have been reparented to
+			 * namespaces' reaper. Check this.
+			 */
+			if (opts->namespaces_flags & CLONE_NEWPID) {
+				item = list_first_entry(pstree_list,
+						struct pstree_item, list);
+				BUG_ON(item->pid != 1);
+
+				if (check_subtree(item))
+					goto try_again;
+			}
+
 			break;
+		}
 
 		/*
 		 * Old tasks can die and new ones can appear while we
@@ -1025,7 +1042,7 @@ static int collect_pstree(pid_t pid, struct list_head *pstree_list, int leader_o
 		 * just to restart the collection from the beginning
 		 * rather than trying to chase them.
 		 */
-
+try_again:
 		if (attempts == 0)
 			break;
 
@@ -1033,8 +1050,6 @@ static int collect_pstree(pid_t pid, struct list_head *pstree_list, int leader_o
 		pr_info("Trying to suspend tasks again\n");
 
 		while (!list_empty(pstree_list)) {
-			struct pstree_item *item;
-
 			item = list_first_entry(pstree_list,
 					struct pstree_item, list);
 			list_del(&item->list);
@@ -1389,7 +1404,7 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
 		pr_info("Dumping process (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
-	if (collect_pstree(pid, &pstree_list, opts->leader_only))
+	if (collect_pstree(pid, &pstree_list, opts))
 		goto err;
 
 	if (opts->namespaces_flags) {
diff --git a/include/syscall.h b/include/syscall.h
index 6f284aa..31a5d9a 100644
--- a/include/syscall.h
+++ b/include/syscall.h
@@ -414,6 +414,10 @@ sys_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx
 	return syscall5(__NR_kcmp, (long)pid1, (long)pid2, (long)type, idx1, idx2);
 }
 
+#ifndef CLONE_NEWPID
+#define CLONE_NEWPID	0x20000000
+#endif
+
 #ifndef CLONE_NEWUTS
 #define CLONE_NEWUTS	0x04000000
 #endif


More information about the CRIU mailing list