[CRIU] [PATCH v2 4/5] compel: Add data argument to compel_wait_task()

Kirill Tkhai ktkhai at virtuozzo.com
Tue Apr 18 08:56:59 PDT 2017


Sometimes me want to pass some additional data to get_status().
For example, tell a handler which fields are need to be dumped
and which are not need.

So, add data argument to the function for the future uses in
such purposes.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 compel/include/uapi/infect.h |    4 ++--
 compel/src/lib/infect.c      |   10 +++++-----
 criu/include/proc_parse.h    |    2 +-
 criu/proc_parse.c            |    2 +-
 criu/seize.c                 |    6 +++---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/compel/include/uapi/infect.h b/compel/include/uapi/infect.h
index 585d11895..7b681b0cb 100644
--- a/compel/include/uapi/infect.h
+++ b/compel/include/uapi/infect.h
@@ -25,8 +25,8 @@ struct seize_task_status {
 };
 
 extern int compel_wait_task(int pid, int ppid,
-		int (*get_status)(int pid, struct seize_task_status *),
-		struct seize_task_status *st);
+		int (*get_status)(int pid, struct seize_task_status *, void *data),
+		struct seize_task_status *st, void *data);
 extern void compel_consume_seize_task_status(struct seize_task_status *ss);
 
 extern int compel_stop_task(int pid);
diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c
index e0aaf7720..9ade844cf 100644
--- a/compel/src/lib/infect.c
+++ b/compel/src/lib/infect.c
@@ -52,7 +52,7 @@ static inline void close_safe(int *pfd)
 	}
 }
 
-static int parse_pid_status(int pid, struct seize_task_status *ss)
+static int parse_pid_status(int pid, struct seize_task_status *ss, void *data)
 {
 	char aux[128];
 	FILE *f;
@@ -107,7 +107,7 @@ int compel_stop_task(int pid)
 
 	ret = compel_interrupt_task(pid);
 	if (ret == 0) {
-		ret = compel_wait_task(pid, -1, parse_pid_status, &ss);
+		ret = compel_wait_task(pid, -1, parse_pid_status, &ss, NULL);
 		if (ret != -1)
 			compel_consume_seize_task_status(&ss);
 	}
@@ -206,8 +206,8 @@ void compel_consume_seize_task_status(struct seize_task_status *ss)
  * up with someone else.
  */
 int compel_wait_task(int pid, int ppid,
-		int (*get_status)(int pid, struct seize_task_status *),
-		struct seize_task_status *ss)
+		int (*get_status)(int pid, struct seize_task_status *, void *),
+		struct seize_task_status *ss, void *data)
 {
 	siginfo_t si;
 	int status, nr_sigstop;
@@ -235,7 +235,7 @@ int compel_wait_task(int pid, int ppid,
 		wait_errno = errno;
 	}
 
-	ret2 = get_status(pid, ss);
+	ret2 = get_status(pid, ss, data);
 	if (ret2)
 		goto err;
 
diff --git a/criu/include/proc_parse.h b/criu/include/proc_parse.h
index 91f2adb51..213653117 100644
--- a/criu/include/proc_parse.h
+++ b/criu/include/proc_parse.h
@@ -95,7 +95,7 @@ extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
 extern unsigned int parse_pid_loginuid(pid_t pid, int *err, bool ignore_noent);
 extern int parse_pid_oom_score_adj(pid_t pid, int *err);
 extern int prepare_loginuid(unsigned int value, unsigned int loglevel);
-extern int parse_pid_status(pid_t pid, struct seize_task_status *);
+extern int parse_pid_status(pid_t pid, struct seize_task_status *, void *);
 extern int parse_file_locks(void);
 extern int get_fd_mntid(int fd, int *mnt_id);
 
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 5e9780a41..b5b065b65 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -981,7 +981,7 @@ static int cap_parse(char *str, unsigned int *res)
 	return 0;
 }
 
-int parse_pid_status(pid_t pid, struct seize_task_status *ss)
+int parse_pid_status(pid_t pid, struct seize_task_status *ss, void *data)
 {
 	struct proc_status_creds *cr = container_of(ss, struct proc_status_creds, s);
 	struct bfd f;
diff --git a/criu/seize.c b/criu/seize.c
index 1f2c4fae5..d761f1ec1 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -490,7 +490,7 @@ static int collect_children(struct pstree_item *item)
 			goto free;
 		}
 
-		ret = compel_wait_task(pid, item->pid->real, parse_pid_status, &creds->s);
+		ret = compel_wait_task(pid, item->pid->real, parse_pid_status, &creds->s, NULL);
 		if (ret < 0) {
 			/*
 			 * Here is a race window between parse_children() and seize(),
@@ -716,7 +716,7 @@ static int collect_threads(struct pstree_item *item)
 		if (!opts.freeze_cgroup && compel_interrupt_task(pid))
 			continue;
 
-		ret = compel_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s);
+		ret = compel_wait_task(pid, item_ppid(item), parse_pid_status, &t_creds.s, NULL);
 		if (ret < 0) {
 			/*
 			 * Here is a race window between parse_threads() and seize(),
@@ -859,7 +859,7 @@ int collect_pstree(void)
 	if (!creds)
 		goto err;
 
-	ret = compel_wait_task(pid, -1, parse_pid_status, &creds->s);
+	ret = compel_wait_task(pid, -1, parse_pid_status, &creds->s, NULL);
 	if (ret < 0)
 		goto err;
 



More information about the CRIU mailing list