[CRIU] [PATCH 1/6] cr-dump: move parasite_drain_fds_seized out of dump_task_files

Andrey Vagin avagin at openvz.org
Fri Jan 18 14:51:09 EST 2013


File descriptors will be used for dumping file locks

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c | 74 +++++++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 46 insertions(+), 28 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 31eb4cf..3ace532 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -355,36 +355,23 @@ static int dump_one_file(struct parasite_ctl *ctl, int fd, int lfd, struct fd_op
 	return dump_unsupp_fd(&p);
 }
 
-static int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
-		struct parasite_drain_fd *dfds)
+static int dump_task_files(struct parasite_ctl *ctl, struct pstree_item *item,
+				struct parasite_drain_fd *dfds, int *lfds,
+				struct fd_opts *opts)
 {
-	int *lfds, fdinfo;
-	struct fd_opts *opts;
+	int fdinfo;
 	int i, ret = -1;
 
 	pr_info("\n");
 	pr_info("Dumping opened files (pid: %d)\n", ctl->pid);
 	pr_info("----------------------------------------\n");
 
-	lfds = xmalloc(dfds->nr_fds * sizeof(int));
-	if (!lfds)
-		goto err;
-
-	opts = xmalloc(dfds->nr_fds * sizeof(struct fd_opts));
-	if (!opts)
-		goto err1;
-
-	ret = parasite_drain_fds_seized(ctl, dfds, lfds, opts);
-	if (ret)
-		goto err2;
-
 	fdinfo = open_image(CR_FD_FDINFO, O_DUMP, item->ids->files_id);
 	if (fdinfo < 0)
 		goto err2;
 
 	for (i = 0; i < dfds->nr_fds; i++) {
 		ret = dump_one_file(ctl, dfds->fds[i], lfds[i], opts + i, fdinfo);
-		close(lfds[i]);
 		if (ret)
 			break;
 	}
@@ -393,10 +380,6 @@ static int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *
 
 	pr_info("----------------------------------------\n");
 err2:
-	xfree(opts);
-err1:
-	xfree(lfds);
-err:
 	return ret;
 }
 
@@ -1548,6 +1531,45 @@ err:
 	return ret;
 }
 
+static int dump_files_and_locks_seized(struct parasite_ctl *parasite_ctl,
+				struct pstree_item *item,
+				struct parasite_drain_fd *dfds,
+				const struct cr_fdset *cr_fdset)
+{
+	int *lfds, i, ret = -1;
+	struct fd_opts *fd_opts = NULL;
+
+	lfds = xmalloc(dfds->nr_fds * sizeof(int));
+	if (lfds == NULL)
+		return -1;
+
+	fd_opts = xmalloc(dfds->nr_fds * sizeof(struct fd_opts));
+	if (fd_opts  == NULL)
+		goto err_free;
+
+	ret = parasite_drain_fds_seized(parasite_ctl, dfds, lfds, fd_opts);
+	if (ret)
+		goto err_free;
+
+	ret = 0;
+	if (!shared_fdtable(item)) {
+
+		ret = dump_task_files(parasite_ctl, item, dfds, lfds, fd_opts);
+		if (ret) {
+			pr_err("Dump files failed with %d\n", ret);
+			goto err;
+		}
+	}
+
+err:
+	for (i = 0; i < dfds->nr_fds; i++)
+		close(lfds[i]);
+err_free:
+	xfree(lfds);
+	xfree(fd_opts);
+	return ret;
+}
+
 static int dump_one_task(struct pstree_item *item)
 {
 	pid_t pid = item->pid.real;
@@ -1630,13 +1652,9 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
-	if (!shared_fdtable(item)) {
-		ret = dump_task_files_seized(parasite_ctl, item, dfds);
-		if (ret) {
-			pr_err("Dump files (pid: %d) failed with %d\n", pid, ret);
-			goto err_cure;
-		}
-	}
+	ret = dump_files_and_locks_seized(parasite_ctl, item, dfds, cr_fdset);
+	if (ret)
+		goto err_cure;
 
 	if (opts.handle_file_locks) {
 		ret = dump_task_file_locks(parasite_ctl, cr_fdset, dfds);
-- 
1.7.11.7



More information about the CRIU mailing list