[CRIU] [crtools-bot for Cyrill Gorcunov ] parasite: Code grouping
in parasite_infect_seized
Cyrill Gorcunov
gorcunov at openvz.org
Tue Feb 14 08:18:09 EST 2012
The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit 293d999e4f1fa27dd2662c285bc705067a0829a8
Author: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon Feb 13 23:17:51 2012 +0400
parasite: Code grouping in parasite_infect_seized
- mmap_seized returns only NULL on error, drop
redumdant test
- setup control block in one group
- no need for err_free label, xfree handles NULL easily
- prepare registers for munmap_seized call on error path
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
Acked-by: Pavel Emelyanov <xemul at parallels.com>
---
parasite-syscall.c | 37 ++++++++++++++++++-------------------
1 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/parasite-syscall.c b/parasite-syscall.c
index fd0de11..14b17c5 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -551,35 +551,29 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, int pid_dir, struct list_
goto err;
}
- /* Setup control block */
- ctl->pid = pid;
-
if (ptrace(PTRACE_GETREGS, pid, NULL, ®s))
- pr_err_jmp(err_free);
+ pr_err_jmp(err);
vma_area = get_vma_by_ip(vma_area_list, regs.ip);
if (!vma_area) {
pr_err("No suitable VMA found to run parasite "
"bootstrap code (pid: %d)\n", pid);
- goto err_free;
+ goto err;
}
regs_orig = regs;
parasite_setup_regs(vma_area->vma.start, ®s);
ctl->remote_map = mmap_seized(pid, ®s, NULL, (size_t)parasite_size,
- PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_ANONYMOUS | MAP_SHARED, -1, 0);
-
- if (!ctl->remote_map || (long)ctl->remote_map < 0) {
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_ANONYMOUS | MAP_SHARED, -1, 0);
+ if (!ctl->remote_map) {
pr_err("Can't allocate memory for parasite blob (pid: %d)\n", pid);
goto err_restore_regs;
}
ctl->map_length = round_up(parasite_size, PAGE_SIZE);
- ctl->parasite_ip = PARASITE_HEAD_ADDR((unsigned long)ctl->remote_map);
-
snprintf(fname, sizeof(fname), "map_files/%p-%p",
ctl->remote_map, ctl->remote_map + ctl->map_length);
fd = openat(pid_dir, fname, O_RDWR);
@@ -589,7 +583,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, int pid_dir, struct list_
}
ctl->local_map = mmap(NULL, parasite_size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_FILE, fd, 0);
+ MAP_SHARED | MAP_FILE, fd, 0);
close(fd);
if (ctl->local_map == MAP_FAILED) {
@@ -602,8 +596,11 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, int pid_dir, struct list_
jerr(ptrace(PTRACE_SETREGS, pid, NULL, ®s_orig), err_munmap_restore);
- ctl->addr_cmd = (void *)PARASITE_CMD_ADDR((unsigned long)ctl->local_map);
- ctl->addr_args = (void *)PARASITE_ARGS_ADDR((unsigned long)ctl->local_map);
+ /* Setup control block */
+ ctl->pid = pid;
+ ctl->parasite_ip = PARASITE_HEAD_ADDR((unsigned long)ctl->remote_map);
+ ctl->addr_cmd = (void *)PARASITE_CMD_ADDR((unsigned long)ctl->local_map);
+ ctl->addr_args = (void *)PARASITE_ARGS_ADDR((unsigned long)ctl->local_map);
ret = parasite_init(ctl, pid);
if (ret) {
@@ -614,7 +611,7 @@ struct parasite_ctl *parasite_infect_seized(pid_t pid, int pid_dir, struct list_
ret = parasite_set_logfd(ctl, pid);
if (ret) {
pr_err("%d: Can't set a logging descriptor\n", pid);
- goto err_munmap_restore;
+ goto err_fini;
}
return ctl;
@@ -624,17 +621,19 @@ err_fini:
&args, sizeof(args));
if (ret)
pr_panic("Can't finalize parasite (pid: %d) task\n", ctl->pid);
+
err_munmap_restore:
- regs = regs_orig, regs.ip = vma_area->vma.start;
+ regs = regs_orig;
+ parasite_setup_regs(vma_area->vma.start, ®s);
if (munmap_seized(pid, ®s, ctl->remote_map, ctl->map_length))
pr_panic("mmap_seized failed (pid: %d)\n", pid);
+
err_restore_regs:
if (ptrace(PTRACE_SETREGS, pid, NULL, ®s_orig))
pr_panic("PTRACE_SETREGS failed (pid: %d)\n", pid);
-err_free:
- if (ctl)
- free(ctl);
+
err:
+ xfree(ctl);
return NULL;
}
More information about the CRIU
mailing list