[CRIU] [PATCH v3 8/8] dump: move fd dump itself to separated function

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Mar 5 13:01:30 EST 2012


Fd entry itself will be dumped for sockets soon.

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

---
 cr-dump.c |   62 ++++++++++++++++++++++++++++++++-----------------------------
 1 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index cd7d22f..0e9f2f8 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -88,31 +88,14 @@ err:
 	return ret;
 }
 
-static int dump_one_reg_file(struct fd_parms *p,
-			     struct cr_fdset *cr_fdset,
-			     bool do_close_lfd)
+static int dump_one_fd_entry(const struct fd_parms *p,
+			     char *path,
+			     struct cr_fdset *cr_fdset)
 {
 	struct fdinfo_entry e;
-	char fd_str[128];
-	int len;
-	int ret = -1;
-
-	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", p->lfd);
-	len = readlink(fd_str, big_buffer, sizeof(big_buffer) - 1);
-	if (len < 0) {
-		pr_perror("Can't readlink %s", fd_str);
-		goto err;
-	}
-
-	big_buffer[len] = '\0';
-	pr_info("Dumping path for %lx fd via self %d [%s]\n",
-		p->fd_name, p->lfd, big_buffer);
-
-	if (do_close_lfd)
-		close(p->lfd);
 
 	e.type	= p->type;
-	e.len	= len;
+	e.len	= strlen(path);
 	e.flags = p->flags;
 	e.pos	= p->pos;
 	e.addr	= p->fd_name;
@@ -129,23 +112,44 @@ static int dump_one_reg_file(struct fd_parms *p,
 
 		entry = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
 		if (!entry)
-			goto err;
+			return -1;
 
 		/* Now it might have completely new ID here */
 		e.id	= entry->u.id;
 	}
 
 	pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
-		p->type, len, p->flags, p->pos, p->fd_name);
+		p->type, e.len, p->flags, p->pos, p->fd_name);
 
 	if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e))
-		goto err;
-	if (write_img_buf(cr_fdset->fds[CR_FD_FDINFO], big_buffer, e.len))
-		goto err;
+		return -1;
+	if (write_img_buf(cr_fdset->fds[CR_FD_FDINFO], path, e.len))
+		return -1;
+	return 0;
+}
 
-	ret = 0;
-err:
-	return ret;
+static int dump_one_reg_file(struct fd_parms *p,
+			     struct cr_fdset *cr_fdset,
+			     bool do_close_lfd)
+{
+	char fd_str[128];
+	int len;
+
+	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", p->lfd);
+	len = readlink(fd_str, big_buffer, sizeof(big_buffer) - 1);
+	if (len < 0) {
+		pr_perror("Can't readlink %s", fd_str);
+		return -1;
+	}
+
+	big_buffer[len] = '\0';
+	pr_info("Dumping path for %lx fd via self %d [%s]\n",
+		p->fd_name, p->lfd, big_buffer);
+
+	if (do_close_lfd)
+		close(p->lfd);
+
+	return dump_one_fd_entry(p, big_buffer, cr_fdset);
 }
 
 static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)



More information about the CRIU mailing list