[CRIU] [PATCH v2] parasite-syscall: some cleanup

Kinsbursky Stanislav skinsbursky at openvz.org
Tue Feb 21 11:19:06 EST 2012


v2: command is set prior to parasite_execute() call now

Removed redundant on-stack variables typeof parasite_status_t and memcpy
between them and parasite_ctl->addr_args object. Ando a lot of cleanup done
around.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 cr-dump.c                  |    2 +
 include/parasite-syscall.h |    2 +
 parasite-syscall.c         |   84 +++++++++++++++++++++-----------------------
 3 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 642755e..930c399 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1174,7 +1174,7 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset)
 		goto err;
 	}
 
-	ret = parasite_dump_misc_seized(parasite_ctl, &misc);
+	ret = parasite_dump_misc_seized(parasite_ctl);
 	if (ret) {
 		pr_err("Can't dump misc (pid: %d)\n", pid);
 		goto err;
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 83ec588..95d743e 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -32,7 +32,7 @@ extern int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdse
 extern int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset);
 
 struct parasite_dump_misc;
-extern int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_misc *misc);
+extern int parasite_dump_misc_seized(struct parasite_ctl *ctl);
 extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,
 				      struct list_head *vma_area_list,
 				      struct cr_fdset *cr_fdset);
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 02a50fa..414ae0f 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -36,6 +36,10 @@ static const char code_syscall[] = {0x0f, 0x05, 0xcc, 0xcc,
 #define code_syscall_size	(round_up(sizeof(code_syscall), sizeof(long)))
 #define parasite_size		(round_up(sizeof(parasite_blob), sizeof(long)))
 
+#define PARASITE_SET_CMD(ctl, cmd) {	\
+	*(long *)ctl->addr_cmd = cmd;	\
+}
+
 static int can_run_syscall(unsigned long ip, unsigned long start, unsigned long end)
 {
 	return ip >= start && ip < (end - code_syscall_size);
@@ -226,27 +230,21 @@ err:
 	return ret;
 }
 
-static int parasite_execute(unsigned long cmd, struct parasite_ctl *ctl,
-			    parasite_status_t *args, int args_size)
+static int parasite_execute(struct parasite_ctl *ctl)
 {
 	int ret;
-
 	user_regs_struct_t regs = ctl->regs_orig;
 
-	memcpy(ctl->addr_cmd, &cmd, sizeof(cmd));
-	memcpy(ctl->addr_args, args, args_size);
-
 	parasite_setup_regs(ctl->parasite_ip, &regs);
 
 	ret = __parasite_execute(ctl, &regs);
 
-	memcpy(args, ctl->addr_args, args_size);
-	if (!ret)
-		ret = args->ret;
+	if (ret) {
+		parasite_status_t *args = ctl->addr_args;
 
-	if (ret)
 		pr_err("Parasite exited with %d ret (%li at %li)\n",
 		       ret, args->sys_ret, args->line);
+	}
 
 	return ret;
 }
@@ -356,8 +354,7 @@ static int parasite_file_cmd(char *what, int cmd, int type,
 			     struct parasite_ctl *ctl,
 			     struct cr_fdset *cr_fdset)
 {
-	parasite_status_t args = { };
-	int ret = -1;
+	int ret;
 
 	pr_info("\n");
 	pr_info("Dumping %s (pid: %d)\n", what, ctl->pid);
@@ -367,7 +364,8 @@ static int parasite_file_cmd(char *what, int cmd, int type,
 	if (ret < 0)
 		goto out;
 
-	ret = parasite_execute(cmd, ctl, (parasite_status_t *)&args, sizeof(args));
+	PARASITE_SET_CMD(ctl, cmd);
+	ret = parasite_execute(ctl);
 
 	fchmod(cr_fdset->fds[type], CR_FD_PERM);
 out:
@@ -378,24 +376,23 @@ out:
 
 static int parasite_init(struct parasite_ctl *ctl, pid_t pid)
 {
-	struct parasite_init_args args = { };
-
-	args.sun_len = get_socket_name(&args.saddr, pid);
+	struct parasite_init_args *args = ctl->addr_args;
 
-	return parasite_execute(PARASITE_CMD_INIT, ctl,
-				(parasite_status_t *)&args, sizeof(args));
+	args->sun_len = get_socket_name(&args->saddr, pid);
+	PARASITE_SET_CMD(ctl, PARASITE_CMD_INIT);
+	return parasite_execute(ctl);
 }
 
 static int parasite_set_logfd(struct parasite_ctl *ctl, pid_t pid)
 {
-	parasite_status_t args = { };
 	int ret;
 
 	ret = parasite_send_fd(ctl, get_logfd());
 	if (ret)
 		return ret;
 
-	ret = parasite_execute(PARASITE_CMD_SET_LOGFD, ctl, &args, sizeof(args));
+	PARASITE_SET_CMD(ctl, PARASITE_CMD_SET_LOGFD);
+	ret = parasite_execute(ctl);
 	if (ret < 0)
 		return ret;
 
@@ -414,11 +411,10 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_f
 				 CR_FD_ITIMERS, ctl, cr_fdset);
 }
 
-int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_misc *misc)
+int parasite_dump_misc_seized(struct parasite_ctl *ctl)
 {
-	return parasite_execute(PARASITE_CMD_DUMP_MISC, ctl,
-				(parasite_status_t *)misc,
-				sizeof(struct parasite_dump_misc));
+	PARASITE_SET_CMD(ctl, PARASITE_CMD_DUMP_MISC);
+	return parasite_execute(ctl);
 }
 
 /*
@@ -428,8 +424,7 @@ int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_mis
 int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_area_list,
 			       struct cr_fdset *cr_fdset)
 {
-	struct parasite_dump_pages_args parasite_dumppages = { };
-	parasite_status_t *st = &parasite_dumppages.status;
+	struct parasite_dump_pages_args *parasite_dumppages = ctl->addr_args;
 	unsigned long nrpages_dumped = 0;
 	struct vma_area *vma_area;
 	int ret = -1;
@@ -446,12 +441,13 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
 	if (ret < 0)
 		goto out;
 
-	ret = parasite_execute(PARASITE_CMD_DUMPPAGES_INIT, ctl, st, sizeof(*st));
+	PARASITE_SET_CMD(ctl, PARASITE_CMD_DUMPPAGES_INIT);
+	ret = parasite_execute(ctl);
 	if (ret < 0) {
 		pr_panic("Dumping pages failed with %li (%li) at %li\n",
-				parasite_dumppages.status.ret,
-				parasite_dumppages.status.sys_ret,
-				parasite_dumppages.status.line);
+				parasite_dumppages->status.ret,
+				parasite_dumppages->status.sys_ret,
+				parasite_dumppages->status.line);
 		goto out;
 	}
 
@@ -472,35 +468,35 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl, struct list_head *vma_a
 			continue;
 
 		pr_info_vma(vma_area);
-		parasite_dumppages.vma_entry = vma_area->vma;
+		parasite_dumppages->vma_entry = vma_area->vma;
 
 		if (vma_area_is(vma_area, VMA_ANON_PRIVATE) ||
 		    vma_area_is(vma_area, VMA_FILE_PRIVATE))
-			parasite_dumppages.fd_type = PG_PRIV;
+			parasite_dumppages->fd_type = PG_PRIV;
 		else if (vma_area_is(vma_area, VMA_ANON_SHARED))
-			parasite_dumppages.fd_type = PG_SHARED;
+			parasite_dumppages->fd_type = PG_SHARED;
 		else {
 			pr_warning("Unexpected VMA area found\n");
 			continue;
 		}
 
-		ret = parasite_execute(PARASITE_CMD_DUMPPAGES, ctl,
-				       (parasite_status_t *) &parasite_dumppages,
-				       sizeof(parasite_dumppages));
+		PARASITE_SET_CMD(ctl, PARASITE_CMD_DUMPPAGES);
+		ret = parasite_execute(ctl);
 		if (ret) {
 			pr_panic("Dumping pages failed with %li (%li) at %li\n",
-				 parasite_dumppages.status.ret,
-				 parasite_dumppages.status.sys_ret,
-				 parasite_dumppages.status.line);
+				 parasite_dumppages->status.ret,
+				 parasite_dumppages->status.sys_ret,
+				 parasite_dumppages->status.line);
 
 			goto out;
 		}
 
-		pr_info("  (dumped: %16li pages)\n", parasite_dumppages.nrpages_dumped);
-		nrpages_dumped += parasite_dumppages.nrpages_dumped;
+		pr_info("  (dumped: %16li pages)\n", parasite_dumppages->nrpages_dumped);
+		nrpages_dumped += parasite_dumppages->nrpages_dumped;
 	}
 
-	parasite_execute(PARASITE_CMD_DUMPPAGES_FINI, ctl, st, sizeof(*st));
+	PARASITE_SET_CMD(ctl, PARASITE_CMD_DUMPPAGES_FINI);
+	parasite_execute(ctl);
 
 	if (write_img(cr_fdset->fds[CR_FD_PAGES], &zero_page_entry))
 		goto out;
@@ -521,11 +517,11 @@ out:
 
 int parasite_cure_seized(struct parasite_ctl *ctl)
 {
-	parasite_status_t args = { };
 	int ret = 0;
 
 	if (ctl->parasite_ip) {
-		if (parasite_execute(PARASITE_CMD_FINI, ctl, &args, sizeof(args))) {
+		PARASITE_SET_CMD(ctl, PARASITE_CMD_FINI);
+		if (parasite_execute(ctl)) {
 			pr_err("Can't finalize parasite (pid: %d) task\n", ctl->pid);
 			ret = -1;
 		}



More information about the CRIU mailing list