Commit 4b1f8d08 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

parasite: Refactor code to follow calling convention

It happened some routines in parasite service code
were not following calling convention so I fixed the
callers and added a comment about adding new code here.

At the same time the 3 error code madness is dropped
as being requested by Pavel -- now we return one error
code only.

The PARASITE_ERR_ codes were dropped as well due to
become redundant.

The status of parasite service routine is set via
SET_PARASITE_RET helper. In case if there is no error --
just return 0. The calling code should not expect to
find anything sane in parasite_status_t because parasite
code might not touch it at all.

Same time, due to this convention the parasite's
dump_socket_queue is getting rid of third @err
member, because it's now returned as a regular
error code.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 94735bbd
......@@ -16,19 +16,6 @@
#define PARASITE_MAX_SIZE (64 << 10)
/* we need own error code for diagnostics */
#define PARASITE_ERR_FAIL -1024
#define PARASITE_ERR_OPEN -1025
#define PARASITE_ERR_MMAP -1026
#define PARASITE_ERR_MINCORE -1027
#define PARASITE_ERR_MUNMAP -1028
#define PARASITE_ERR_CLOSE -1029
#define PARASITE_ERR_WRITE -1030
#define PARASITE_ERR_MPROTECT -1031
#define PARASITE_ERR_SIGACTION -1032
#define PARASITE_ERR_GETITIMER -1033
#define PARASITE_ERR_IOCTL -1034
enum {
PARASITE_CMD_INIT,
PARASITE_CMD_SET_LOGFD,
......@@ -48,16 +35,14 @@ enum {
};
typedef struct {
long ret; /* custom ret code */
long sys_ret; /* syscall ret code */
long ret; /* ret code */
long line; /* where we're failed */
} parasite_status_t;
#define SET_PARASITE_STATUS(st, ret_code, sys_ret_code) \
do { \
(st)->ret = ret_code, \
(st)->sys_ret = sys_ret_code, \
(st)->line = __LINE__; \
#define SET_PARASITE_RET(st, err) \
do { \
(st)->ret = err, \
(st)->line = __LINE__; \
} while (0)
struct parasite_init_args {
......
......@@ -248,19 +248,21 @@ static int parasite_execute_by_pid(unsigned long cmd, struct parasite_ctl *ctl,
}
memcpy(ctl->addr_cmd, &cmd, sizeof(cmd));
memcpy(ctl->addr_args, args, args_size);
if (args)
memcpy(ctl->addr_args, args, args_size);
parasite_setup_regs(ctl->parasite_ip, &regs);
ret = __parasite_execute(ctl, pid, &regs);
memcpy(args, ctl->addr_args, args_size);
if (!ret)
ret = args->ret;
if (args)
memcpy(args, ctl->addr_args, args_size);
BUG_ON(ret && !args);
if (ret)
pr_err("Parasite exited with %d ret (%li at %li)\n",
ret, args->sys_ret, args->line);
ret, args->ret, args->line);
if (ctl->pid != pid)
if (ptrace(PTRACE_SETREGS, pid, NULL, &regs_orig)) {
......@@ -542,9 +544,8 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
ret = parasite_execute(PARASITE_CMD_DUMPPAGES_INIT, ctl, st, sizeof(*st));
if (ret < 0) {
pr_err("Dumping pages failed with %li (%li) at %li\n",
pr_err("Dumping pages failed with %li at %li\n",
parasite_dumppages.status.ret,
parasite_dumppages.status.sys_ret,
parasite_dumppages.status.line);
goto out;
}
......@@ -582,9 +583,8 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
(parasite_status_t *) &parasite_dumppages,
sizeof(parasite_dumppages));
if (ret) {
pr_err("Dumping pages failed with %li (%li) at %li\n",
pr_err("Dumping pages failed with %li at %li\n",
parasite_dumppages.status.ret,
parasite_dumppages.status.sys_ret,
parasite_dumppages.status.line);
goto out;
......@@ -594,7 +594,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
nrpages_dumped += parasite_dumppages.nrpages_dumped;
}
parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, st, sizeof(*st));
parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, NULL, 0);
if (write_img(cr_fdset->fds[CR_FD_PAGES], &zero_page_entry))
goto out;
......@@ -620,11 +620,7 @@ int parasite_cure_seized(struct parasite_ctl *ctl)
if (ctl->parasite_ip) {
ctl->signals_blocked = 0;
if (parasite_execute(PARASITE_CMD_FINI, ctl, &args, sizeof(args))) {
pr_err("Can't finalize parasite (pid: %d) task\n", ctl->pid);
ret = -1;
}
parasite_execute(PARASITE_CMD_FINI, ctl, NULL, 0);
}
if (ctl->remote_map) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment