[CRIU] [PATCH 22/78] infect: Move parasite_args* into infect.c

Cyrill Gorcunov gorcunov at openvz.org
Mon Nov 7 08:36:07 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

This is the code that lets caller place arguments into memory
shared between parasite and compel (or caller).

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/aio.c                      |  3 ++-
 criu/cr-dump.c                  |  2 ++
 criu/include/infect.h           | 13 +++++++++++++
 criu/include/parasite-syscall.h | 10 ----------
 criu/include/parasite.h         |  3 +--
 criu/infect.c                   | 15 +++++++++++++--
 criu/mem.c                      |  3 ++-
 criu/parasite-syscall.c         | 37 +++++++++++++------------------------
 criu/vdso.c                     |  3 ++-
 9 files changed, 48 insertions(+), 41 deletions(-)

diff --git a/criu/aio.c b/criu/aio.c
index 540fe641c018..c031e39190d9 100644
--- a/criu/aio.c
+++ b/criu/aio.c
@@ -11,6 +11,7 @@
 #include "parasite.h"
 #include "parasite-syscall.h"
 #include "images/mm.pb-c.h"
+#include "infect.h"
 
 #define NR_IOEVENTS_IN_NPAGES(npages) ((PAGE_SIZE * npages - sizeof(struct aio_ring)) / sizeof(struct io_event))
 
@@ -104,7 +105,7 @@ int parasite_collect_aios(struct parasite_ctl *ctl, struct vm_area_list *vmas)
 	 *    creation.
 	 */
 
-	aa = parasite_args_s(ctl, aio_rings_args_size(vmas));
+	aa = compel_parasite_args_s(ctl, aio_rings_args_size(vmas));
 	pa = &aa->ring[0];
 	list_for_each_entry(vma, &vmas->h, list) {
 		if (!vma_area_is(vma, VMA_AREA_AIORING))
diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 2e5564ad2a9f..a92fd5551530 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -715,6 +715,8 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 	struct proc_status_creds *creds;
 	struct parasite_dump_cgroup_args cgroup_args, *info = NULL;
 
+	BUILD_BUG_ON(sizeof(cgroup_args) < PARASITE_ARG_SIZE_MIN);
+
 	pr_info("\n");
 	pr_info("Dumping core (pid: %d)\n", pid);
 	pr_info("----------------------------------------\n");
diff --git a/criu/include/infect.h b/criu/include/infect.h
index 1d1a2131bd87..5ab38425fba5 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -34,4 +34,17 @@ extern int compel_stop_daemon(struct parasite_ctl *ctl);
 extern int compel_cure_remote(struct parasite_ctl *ctl);
 extern int compel_cure_local(struct parasite_ctl *ctl);
 extern int compel_cure(struct parasite_ctl *ctl);
+
+#define PARASITE_ARG_SIZE_MIN	( 1 << 12)
+
+#define compel_parasite_args(ctl, type)					\
+	({								\
+	 	void *___ret;						\
+		BUILD_BUG_ON(sizeof(type) > PARASITE_ARG_SIZE_MIN);	\
+		___ret = compel_parasite_args_p(ctl);			\
+	 	___ret;							\
+	})
+
+extern void *compel_parasite_args_p(struct parasite_ctl *ctl);
+extern void *compel_parasite_args_s(struct parasite_ctl *ctl, int args_size);
 #endif
diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h
index 271c05f27800..ec4bef4d61a7 100644
--- a/criu/include/parasite-syscall.h
+++ b/criu/include/parasite-syscall.h
@@ -55,16 +55,6 @@ struct proc_posix_timers_stat;
 extern int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args,
 		struct parasite_ctl *ctl, struct pstree_item *);
 
-#define parasite_args(ctl, type)					\
-	({								\
-	 	void *___ret;						\
-		BUILD_BUG_ON(sizeof(type) > PARASITE_ARG_SIZE_MIN);	\
-		___ret = parasite_args_p(ctl);				\
-	 	___ret;							\
-	})
-
-extern void *parasite_args_p(struct parasite_ctl *ctl);
-extern void *parasite_args_s(struct parasite_ctl *ctl, int args_size);
 extern int parasite_send_fd(struct parasite_ctl *ctl, int fd);
 
 /*
diff --git a/criu/include/parasite.h b/criu/include/parasite.h
index d248bbc5ea74..b103279c1679 100644
--- a/criu/include/parasite.h
+++ b/criu/include/parasite.h
@@ -2,7 +2,6 @@
 #define __CR_PARASITE_H__
 
 #define PARASITE_STACK_SIZE	(16 << 10)
-#define PARASITE_ARG_SIZE_MIN	( 1 << 12)
 #define PARASITE_START_AREA_MIN	(4096)
 
 #define PARASITE_MAX_SIZE	(64 << 10)
@@ -267,7 +266,7 @@ struct parasite_dump_cgroup_args {
 	 *
 	 * The string is null terminated.
 	 */
-	char contents[PARASITE_ARG_SIZE_MIN];
+	char contents[1 << 12];
 };
 
 /* the parasite prefix is added by gen_offsets.sh */
diff --git a/criu/infect.c b/criu/infect.c
index 809edf8f87ed..bef2c9ff0a24 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -394,7 +394,7 @@ static int parasite_init_daemon(struct parasite_ctl *ctl)
 
 	*ctl->addr_cmd = PARASITE_CMD_INIT_DAEMON;
 
-	args = parasite_args(ctl, struct parasite_init_args);
+	args = compel_parasite_args(ctl, struct parasite_init_args);
 
 	args->sigframe = (uintptr_t)ctl->rsigframe;
 	args->log_level = log_get_loglevel();
@@ -699,7 +699,7 @@ int compel_cure_remote(struct parasite_ctl *ctl)
 
 		*ctl->addr_cmd = PARASITE_CMD_UNMAP;
 
-		args = parasite_args(ctl, struct parasite_unmap_args);
+		args = compel_parasite_args(ctl, struct parasite_unmap_args);
 		args->parasite_start = (uintptr_t)ctl->remote_map;
 		args->parasite_len = ctl->map_length;
 		if (parasite_unmap(ctl, ctl->parasite_ip))
@@ -746,3 +746,14 @@ int compel_cure(struct parasite_ctl *ctl)
 	return ret;
 }
 
+void *compel_parasite_args_p(struct parasite_ctl *ctl)
+{
+	return ctl->addr_args;
+}
+
+void *compel_parasite_args_s(struct parasite_ctl *ctl, int args_size)
+{
+	BUG_ON(args_size > ctl->args_size);
+	return compel_parasite_args_p(ctl);
+}
+
diff --git a/criu/mem.c b/criu/mem.c
index 809b6376331a..05d24471e66f 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -27,6 +27,7 @@
 #include "files-reg.h"
 #include "pagemap-cache.h"
 #include "fault-injection.h"
+#include "infect.h"
 
 #include "protobuf.h"
 #include "images/pagemap.pb-c.h"
@@ -206,7 +207,7 @@ static struct parasite_dump_pages_args *prep_dump_pages_args(struct parasite_ctl
 	struct parasite_vma_entry *p_vma;
 	struct vma_area *vma;
 
-	args = parasite_args_s(ctl, dump_pages_args_size(vma_area_list));
+	args = compel_parasite_args_s(ctl, dump_pages_args_size(vma_area_list));
 
 	p_vma = pargs_vmas(args);
 	args->nr_vmas = 0;
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 1774b2838849..487b65ba5142 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -197,17 +197,6 @@ int __parasite_execute_syscall(struct parasite_ctl *ctl,
 	return err;
 }
 
-void *parasite_args_p(struct parasite_ctl *ctl)
-{
-	return ctl->addr_args;
-}
-
-void *parasite_args_s(struct parasite_ctl *ctl, int args_size)
-{
-	BUG_ON(args_size > ctl->args_size);
-	return parasite_args_p(ctl);
-}
-
 static int parasite_run_in_thread(pid_t pid, unsigned int cmd,
 					struct parasite_ctl *ctl,
 					struct thread_ctx *octx)
@@ -400,10 +389,10 @@ int parasite_dump_thread_leader_seized(struct parasite_ctl *ctl, int pid, CoreEn
 	int ret;
 
 	if (seized_native(ctl)) {
-		args = parasite_args(ctl, struct parasite_dump_thread);
+		args = compel_parasite_args(ctl, struct parasite_dump_thread);
 		pc = args->creds;
 	} else {
-		args_c = parasite_args(ctl, struct parasite_dump_thread_compat);
+		args_c = compel_parasite_args(ctl, struct parasite_dump_thread_compat);
 		pc = args_c->creds;
 	}
 
@@ -440,10 +429,10 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
 	BUG_ON(id == 0); /* Leader is dumped in dump_task_core_all */
 
 	if (seized_native(ctl)) {
-		args = parasite_args(ctl, struct parasite_dump_thread);
+		args = compel_parasite_args(ctl, struct parasite_dump_thread);
 		pc = args->creds;
 	} else {
-		args_c = parasite_args(ctl, struct parasite_dump_thread_compat);
+		args_c = compel_parasite_args(ctl, struct parasite_dump_thread_compat);
 		pc = args_c->creds;
 	}
 
@@ -503,9 +492,9 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_imgset *cr_
 	bool native_task = seized_native(ctl);
 
 	if (native_task)
-		args = parasite_args(ctl, struct parasite_dump_sa_args);
+		args = compel_parasite_args(ctl, struct parasite_dump_sa_args);
 	else
-		args_c = parasite_args(ctl, struct parasite_dump_sa_args_compat);
+		args_c = compel_parasite_args(ctl, struct parasite_dump_sa_args_compat);
 
 	ret = parasite_execute_daemon(PARASITE_CMD_DUMP_SIGACTS, ctl);
 	if (ret < 0)
@@ -555,9 +544,9 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct pstree_item *i
 	int ret;
 
 	if (seized_native(ctl))
-		args = parasite_args(ctl, struct parasite_dump_itimers_args);
+		args = compel_parasite_args(ctl, struct parasite_dump_itimers_args);
 	else
-		args_c = parasite_args(ctl, struct parasite_dump_itimers_args_compat);
+		args_c = compel_parasite_args(ctl, struct parasite_dump_itimers_args_compat);
 
 	ret = parasite_execute_daemon(PARASITE_CMD_DUMP_ITIMERS, ctl);
 	if (ret < 0)
@@ -646,7 +635,7 @@ int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args,
 		args_size = posix_timers_dump_size(proc_args->timer_n);
 	else
 		args_size = posix_timers_compat_dump_size(proc_args->timer_n);
-	args = parasite_args_s(ctl, args_size);
+	args = compel_parasite_args_s(ctl, args_size);
 
 	set_posix_timer_arg(args, ctl, timer_n, proc_args->timer_n);
 
@@ -677,7 +666,7 @@ int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_mis
 {
 	struct parasite_dump_misc *ma;
 
-	ma = parasite_args(ctl, struct parasite_dump_misc);
+	ma = compel_parasite_args(ctl, struct parasite_dump_misc);
 	if (parasite_execute_daemon(PARASITE_CMD_DUMP_MISC, ctl) < 0)
 		return -1;
 
@@ -689,7 +678,7 @@ struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd, in
 {
 	struct parasite_tty_args *p;
 
-	p = parasite_args(ctl, struct parasite_tty_args);
+	p = compel_parasite_args(ctl, struct parasite_tty_args);
 	p->fd = fd;
 	p->type = type;
 
@@ -707,7 +696,7 @@ int parasite_drain_fds_seized(struct parasite_ctl *ctl,
 	struct parasite_drain_fd *args;
 
 	size = drain_fds_size(dfds);
-	args = parasite_args_s(ctl, size);
+	args = compel_parasite_args_s(ctl, size);
 	args->nr_fds = nr_fds;
 	memcpy(&args->fds, dfds->fds + off, sizeof(int) * nr_fds);
 
@@ -1012,7 +1001,7 @@ int parasite_dump_cgroup(struct parasite_ctl *ctl, struct parasite_dump_cgroup_a
 	int ret;
 	struct parasite_dump_cgroup_args *ca;
 
-	ca = parasite_args(ctl, struct parasite_dump_cgroup_args);
+	ca = compel_parasite_args(ctl, struct parasite_dump_cgroup_args);
 	ret = parasite_execute_daemon(PARASITE_CMD_DUMP_CGROUP, ctl);
 	if (ret) {
 		pr_err("Parasite failed to dump /proc/self/cgroup\n");
diff --git a/criu/vdso.c b/criu/vdso.c
index da6e9655e945..bd39cf0fe4ed 100644
--- a/criu/vdso.c
+++ b/criu/vdso.c
@@ -19,6 +19,7 @@
 #include "log.h"
 #include "mem.h"
 #include "vma.h"
+#include "infect.h"
 
 #ifdef LOG_PREFIX
 # undef LOG_PREFIX
@@ -46,7 +47,7 @@ int parasite_fixup_vdso(struct parasite_ctl *ctl, pid_t pid,
 	struct vma_area *vma;
 	off_t off;
 
-	args = parasite_args(ctl, struct parasite_vdso_vma_entry);
+	args = compel_parasite_args(ctl, struct parasite_vdso_vma_entry);
 	if (kdat.pmap == PM_FULL) {
 		BUG_ON(vdso_pfn == VDSO_BAD_PFN);
 		fd = open_proc(pid, "pagemap");
-- 
2.7.4



More information about the CRIU mailing list