[CRIU] [PATCH 20/78] infect: Move parasite_prep_ctl into infect.c
Cyrill Gorcunov
gorcunov at openvz.org
Mon Nov 7 08:36:05 PST 2016
From: Pavel Emelyanov <xemul at virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/cr-exec.c | 2 +-
criu/cr-restore.c | 2 +-
criu/include/infect.h | 3 +++
criu/include/parasite-syscall.h | 1 -
criu/infect.c | 47 +++++++++++++++++++++++++++++++++++++++
criu/parasite-syscall.c | 49 ++---------------------------------------
6 files changed, 54 insertions(+), 50 deletions(-)
diff --git a/criu/cr-exec.c b/criu/cr-exec.c
index 347e0955b11c..53f17e75bae2 100644
--- a/criu/cr-exec.c
+++ b/criu/cr-exec.c
@@ -167,7 +167,7 @@ int cr_exec(int pid, char **opt)
goto out_unseize;
}
- ctl = parasite_prep_ctl(pid);
+ ctl = compel_prepare(pid);
if (!ctl) {
pr_err("Can't prep ctl %d\n", pid);
goto out_unseize;
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 218851b95c8f..f8e1b3faa78a 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1646,7 +1646,7 @@ static void finalize_restore(void)
continue;
/* Unmap the restorer blob */
- ctl = parasite_prep_ctl(pid);
+ ctl = compel_prepare(pid);
if (ctl == NULL)
continue;
diff --git a/criu/include/infect.h b/criu/include/infect.h
index 9cfbfe08482a..fa6dac88cb1a 100644
--- a/criu/include/infect.h
+++ b/criu/include/infect.h
@@ -24,7 +24,10 @@ extern int compel_wait_task(int pid, int ppid,
#define TASK_ZOMBIE 0x6
struct parasite_ctl;
+struct thread_ctx;
+extern struct parasite_ctl *compel_prepare(int pid);
extern int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned long args_size);
+extern int compel_prepare_thread(int pid, struct thread_ctx *ctx);
#endif
diff --git a/criu/include/parasite-syscall.h b/criu/include/parasite-syscall.h
index 65d4217c2d86..9e151df87cae 100644
--- a/criu/include/parasite-syscall.h
+++ b/criu/include/parasite-syscall.h
@@ -98,7 +98,6 @@ extern struct parasite_ctl *parasite_infect_seized(pid_t pid,
struct vm_area_list *vma_area_list);
extern void parasite_ensure_args_size(unsigned long sz);
extern unsigned long get_exec_start(struct vm_area_list *);
-extern struct parasite_ctl *parasite_prep_ctl(pid_t pid);
extern int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size);
extern int parasite_dump_cgroup(struct parasite_ctl *ctl, struct parasite_dump_cgroup_args *cgroup);
diff --git a/criu/infect.c b/criu/infect.c
index d16a2900b454..c1cb31daf4e4 100644
--- a/criu/infect.c
+++ b/criu/infect.c
@@ -20,6 +20,9 @@
#include "infect.h"
#include "infect-priv.h"
+#define MEMFD_FNAME "CRIUMFD"
+#define MEMFD_FNAME_SZ sizeof(MEMFD_FNAME)
+
/* XXX will be removed soon */
extern int parasite_wait_ack(int sockfd, unsigned int cmd, struct ctl_msg *m);
@@ -527,3 +530,47 @@ err:
return -1;
}
+int compel_prepare_thread(int pid, struct thread_ctx *ctx)
+{
+ if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) {
+ pr_perror("can't get signal blocking mask for %d", pid);
+ return -1;
+ }
+
+ if (ptrace_get_regs(pid, &ctx->regs)) {
+ pr_perror("Can't obtain registers (pid: %d)", pid);
+ return -1;
+ }
+
+ return 0;
+}
+
+struct parasite_ctl *compel_prepare(int pid)
+{
+ struct parasite_ctl *ctl = NULL;
+
+ /*
+ * Control block early setup.
+ */
+ ctl = xzalloc(sizeof(*ctl));
+ if (!ctl) {
+ pr_err("Parasite control block allocation failed (pid: %d)\n", pid);
+ goto err;
+ }
+
+ ctl->tsock = -1;
+
+ if (compel_prepare_thread(pid, &ctl->orig))
+ goto err;
+
+ ctl->rpid = pid;
+
+ BUILD_BUG_ON(PARASITE_START_AREA_MIN < BUILTIN_SYSCALL_SIZE + MEMFD_FNAME_SZ);
+
+ return ctl;
+
+err:
+ xfree(ctl);
+ return NULL;
+}
+
diff --git a/criu/parasite-syscall.c b/criu/parasite-syscall.c
index 7b38365955d5..62c1d543d6fe 100644
--- a/criu/parasite-syscall.c
+++ b/criu/parasite-syscall.c
@@ -91,21 +91,6 @@ static inline int ptrace_set_regs(int pid, user_regs_struct_t *regs)
}
#endif
-static int get_thread_ctx(int pid, struct thread_ctx *ctx)
-{
- if (ptrace(PTRACE_GETSIGMASK, pid, sizeof(k_rtsigset_t), &ctx->sigmask)) {
- pr_perror("can't get signal blocking mask for %d", pid);
- return -1;
- }
-
- if (ptrace_get_regs(pid, &ctx->regs)) {
- pr_perror("Can't obtain registers (pid: %d)", pid);
- return -1;
- }
-
- return 0;
-}
-
static int restore_thread_ctx(int pid, struct thread_ctx *ctx)
{
int ret = 0;
@@ -481,7 +466,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
pc->cap_last_cap = kdat.last_cap;
- ret = get_thread_ctx(pid, &octx);
+ ret = compel_prepare_thread(pid, &octx);
if (ret)
return -1;
@@ -1071,36 +1056,6 @@ err:
return ret;
}
-/* If vma_area_list is NULL, a place for injecting syscall will not be set. */
-struct parasite_ctl *parasite_prep_ctl(pid_t pid)
-{
- struct parasite_ctl *ctl = NULL;
-
- /*
- * Control block early setup.
- */
- ctl = xzalloc(sizeof(*ctl));
- if (!ctl) {
- pr_err("Parasite control block allocation failed (pid: %d)\n", pid);
- goto err;
- }
-
- ctl->tsock = -1;
-
- if (get_thread_ctx(pid, &ctl->orig))
- goto err;
-
- ctl->rpid = pid;
-
- BUILD_BUG_ON(PARASITE_START_AREA_MIN < BUILTIN_SYSCALL_SIZE + MEMFD_FNAME_SZ);
-
- return ctl;
-
-err:
- xfree(ctl);
- return NULL;
-}
-
static int parasite_mmap_exchange(struct parasite_ctl *ctl, unsigned long size)
{
int fd;
@@ -1266,7 +1221,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, struct pstree_item *item,
return NULL;
}
- ctl = parasite_prep_ctl(pid);
+ ctl = compel_prepare(pid);
if (!ctl)
return NULL;
--
2.7.4
More information about the CRIU
mailing list