[CRIU] [crtools-bot for Pavel Emelyanov ] dump/restore: Rework final-state switch

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


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

    dump/restore: Rework final-state switch
    
    Remove CR_TASK_XXX states, use the TASK_XXX ones (for image). This is
    required to unseize tasks properly in the next patches.
    
    Plus, make sure that pstree_list and the seized set coincide (i.e.
    handle error in collect_task).
    
    Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c         |    5 +++--
 crtools.c         |    4 ++--
 include/crtools.h |    7 +------
 include/ptrace.h  |    2 +-
 ptrace.c          |   10 ++++++----
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 2e6fe53..0d5bb3a 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -845,7 +845,7 @@ static int get_children(struct pstree_item *item)
 	return parse_children(item, &item->children, &item->nr_children);
 }
 
-static void unseize_task_and_threads(struct pstree_item *item, enum cr_task_state st)
+static void unseize_task_and_threads(struct pstree_item *item, int st)
 {
 	int i;
 
@@ -900,7 +900,7 @@ err:
 		if (item->pid == item->threads[i])
 			continue;
 
-		unseize_task(item->threads[i], CR_TASK_STOP /* FIXME */);
+		unseize_task(item->threads[i], TASK_ALIVE);
 	}
 
 	return -1;
@@ -957,6 +957,7 @@ static struct pstree_item *collect_task(pid_t pid, pid_t ppid, struct list_head
 
 err_close:
 	close_pid_proc();
+	unseize_task(pid, item->state);
 err_free:
 	xfree(item->children);
 	xfree(item->threads);
diff --git a/crtools.c b/crtools.c
index 01703cd..bd29b5e 100644
--- a/crtools.c
+++ b/crtools.c
@@ -308,13 +308,13 @@ int main(int argc, char *argv[])
 	memzero_p(&zero_page_entry);
 
 	/* Default options */
-	opts.final_state = CR_TASK_KILL;
+	opts.final_state = TASK_DEAD;
 
 	for (opt = getopt_long(argc - 1, argv + 1, short_opts, NULL, &idx); opt != -1;
 	     opt = getopt_long(argc - 1, argv + 1, short_opts, NULL, &idx)) {
 		switch (opt) {
 		case 's':
-			opts.final_state = CR_TASK_STOP;
+			opts.final_state = TASK_STOPPED;
 			break;
 		case 'p':
 			pid = atoi(optarg);
diff --git a/include/crtools.h b/include/crtools.h
index 47d51e0..175f371 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -47,13 +47,8 @@ enum {
 	CR_FD_MAX
 };
 
-enum cr_task_state {
-	CR_TASK_STOP,
-	CR_TASK_KILL,
-};
-
 struct cr_options {
-	enum cr_task_state	final_state;
+	int			final_state;
 	char			*show_dump_file;
 	bool			leader_only;
 	bool			show_pages_content;
diff --git a/include/ptrace.h b/include/ptrace.h
index 87f4528..f094238 100644
--- a/include/ptrace.h
+++ b/include/ptrace.h
@@ -33,7 +33,7 @@
 #define PTRACE_O_TRACEEXIT	0x00000040
 
 extern int seize_task(pid_t pid, pid_t ppid);
-extern int unseize_task(pid_t pid, enum cr_task_state st);
+extern int unseize_task(pid_t pid, int state);
 extern int ptrace_peek_area(pid_t pid, void *dst, void *addr, long bytes);
 extern int ptrace_poke_area(pid_t pid, void *src, void *addr, long bytes);
 extern int ptrace_swap_area(pid_t pid, void *dst, void *src, long bytes);
diff --git a/ptrace.c b/ptrace.c
index f7850bd..b26bdca 100644
--- a/ptrace.c
+++ b/ptrace.c
@@ -20,12 +20,14 @@
 #include "ptrace.h"
 #include "proc_parse.h"
 
-int unseize_task(pid_t pid, enum cr_task_state st)
+int unseize_task(pid_t pid, int st)
 {
-	if (st == CR_TASK_KILL)
+	if (st == TASK_DEAD)
 		kill(pid, SIGKILL);
-	else if (st == CR_TASK_STOP)
+	else if (st == TASK_STOPPED)
 		kill(pid, SIGSTOP);
+	else if (st == TASK_ALIVE)
+		/* do nothing */ ;
 	else
 		pr_err("Unknown final state %d\n", st);
 
@@ -110,7 +112,7 @@ int seize_task(pid_t pid, pid_t ppid)
 
 	pr_err("SEIZE %d: unsupported stop signal %d\n", pid, si.si_signo);
 err:
-	unseize_task(pid, CR_TASK_STOP);
+	unseize_task(pid, TASK_STOPPED);
 	return -1;
 }
 


More information about the CRIU mailing list