[CRIU] [PATCH 2/3] dump: move code for dumping threads in a separate function
Andrey Vagin
avagin at openvz.org
Fri Jun 7 16:42:30 EDT 2013
The next patch will add another version of this function,
which will use PTRACE_SETSIGMASK.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
parasite-syscall.c | 77 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 44 insertions(+), 33 deletions(-)
diff --git a/parasite-syscall.c b/parasite-syscall.c
index b61c93f..fe3241e 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -471,51 +471,62 @@ err:
return -1;
}
-int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
+static int dump_thread_in_two_stage(struct parasite_ctl *ctl, int id,
struct pid *tid, CoreEntry *core)
{
struct parasite_dump_thread *args;
+ user_regs_struct_t regs_orig;
+ pid_t pid = tid->real;
int ret;
args = parasite_args(ctl, struct parasite_dump_thread);
- if (id == 0)
- ret = parasite_execute_daemon(PARASITE_CMD_DUMP_THREAD, ctl);
- else {
- pid_t pid = tid->real;
- user_regs_struct_t regs_orig;
+ ret = ptrace(PTRACE_GETREGS, pid, NULL, ®s_orig);
+ if (ret) {
+ pr_perror("Can't obtain registers (pid: %d)", pid);
+ return -1;
+ }
- ret = ptrace(PTRACE_GETREGS, pid, NULL, ®s_orig);
- if (ret) {
- pr_perror("Can't obtain registers (pid: %d)", pid);
- return -1;
- }
+ ret = parasite_execute_trap_by_pid(PARASITE_CMD_INIT_THREAD, ctl,
+ pid, ®s_orig,
+ ctl->r_thread_stack, false);
+ if (ret) {
+ pr_err("Can't init thread in parasite %d\n", pid);
+ return -1;
+ }
- ret = parasite_execute_trap_by_pid(PARASITE_CMD_INIT_THREAD, ctl,
- pid, ®s_orig,
- ctl->r_thread_stack, false);
- if (ret) {
- pr_err("Can't init thread in parasite %d\n", pid);
- return -1;
- }
+ ret = get_task_regs(pid, regs_orig, core);
+ if (ret)
+ pr_err("Can't obtain regs for thread %d\n", pid);
- ret = get_task_regs(pid, regs_orig, core);
- if (ret)
- pr_err("Can't obtain regs for thread %d\n", pid);
+ if (parasite_execute_trap_by_pid(PARASITE_CMD_FINI_THREAD, ctl,
+ pid, ®s_orig,
+ ctl->r_thread_stack, true)) {
+ pr_err("FATAL: Can't fini thread in parasite %d\n", pid);
+ return -1;
+ }
+ if (ret)
+ return -1;
- if (parasite_execute_trap_by_pid(PARASITE_CMD_FINI_THREAD, ctl,
- pid, ®s_orig,
- ctl->r_thread_stack, true)) {
- pr_err("Can't init thread in parasite %d\n", pid);
- return -1;
- }
- if (ret)
- return -1;
+ memcpy(&core->thread_core->blk_sigset,
+ &args->blocked, sizeof(k_rtsigset_t));
- memcpy(&core->thread_core->blk_sigset,
- &args->blocked, sizeof(k_rtsigset_t));
- core->thread_core->has_blk_sigset = true;
- }
+ core->thread_core->has_blk_sigset = true;
+ return 0;
+}
+
+int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
+ struct pid *tid, CoreEntry *core)
+{
+ struct parasite_dump_thread *args;
+ int ret;
+
+ args = parasite_args(ctl, struct parasite_dump_thread);
+
+ if (id == 0)
+ ret = parasite_execute_daemon(PARASITE_CMD_DUMP_THREAD, ctl);
+ else
+ ret = dump_thread_in_two_stage(ctl, id, tid, core);
CORE_THREAD_ARCH_INFO(core)->clear_tid_addr = encode_pointer(args->tid_addr);
tid->virt = args->tid;
--
1.8.2
More information about the CRIU
mailing list