[CRIU] [PATCH v2] dump: do not destroy global dump files on reopen

Kinsbursky Stanislav skinsbursky at openvz.org
Wed Mar 14 11:27:54 EDT 2012


v2: added close of fdset for processes tree.

Currently cr_dump_fdset_open() destroys existent file.
Thus for sockets queues new less cruel cr_dump_fdset_open() helper is
used.Oalso, processes tree dump moved outside tasks dump loop.

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

---
 cr-dump.c         |   17 +++++++++--------
 crtools.c         |    7 +++++++
 include/crtools.h |    1 +
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 6c71c84..9431c7f 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1434,26 +1434,27 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 
 	collect_sockets();
 
+	cr_fdset = cr_dump_fdset_open(pid, CR_FD_DESC_USE(CR_FD_PSTREE), NULL);
+	if (!cr_fdset)
+		goto err;
+	if (dump_pstree(pid, &pstree_list, cr_fdset))
+		goto err;
+	close_cr_fdset(&cr_fdset);
+
 	list_for_each_entry(item, &pstree_list, list) {
 		cr_fdset = cr_dump_fdset_open(item->pid, CR_FD_DESC_NONE, NULL);
 		if (!cr_fdset)
 			goto err;
 
-		if (item->pid == pid) {
-			if (!cr_dump_fdset_open(item->pid, CR_FD_DESC_USE(CR_FD_PSTREE), cr_fdset))
-				goto err;
-			if (dump_pstree(pid, &pstree_list, cr_fdset))
-				goto err;
-		}
-
 		/*
 		 * Prepare for socket queues in advance. They are not per-task,
 		 * but per-someother-task which makes restore tricky. Thus save
 		 * them in "global" image.
 		 * That's why we open the file with tree leader's pid for any
 		 * of it's children.
+		 * The file will be created only if it's not exist.
 		 */
-		if (!cr_dump_fdset_open(pid, CR_FD_DESC_USE(CR_FD_SK_QUEUES), cr_fdset))
+		if (!cr_glob_fdset_open(pid, CR_FD_DESC_USE(CR_FD_SK_QUEUES), cr_fdset))
 			goto err;
 
 		if (dump_one_task(item, cr_fdset))
diff --git a/crtools.c b/crtools.c
index 469a7b3..395fdc9 100644
--- a/crtools.c
+++ b/crtools.c
@@ -265,6 +265,13 @@ struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask)
 	return cr_fdset_open(pid, use_mask, O_RDONLY, NULL);
 }
 
+struct cr_fdset *cr_glob_fdset_open(int pid, unsigned long use_mask,
+				    struct cr_fdset *cr_fdset)
+{
+	return cr_fdset_open(pid, use_mask, O_RDWR | O_CREAT, cr_fdset);
+}
+
+
 static int parse_ns_string(const char *ptr, unsigned int *flags)
 {
 	const char *end = ptr + strlen(ptr);
diff --git a/include/crtools.h b/include/crtools.h
index ee35cc7..c09546b 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -129,6 +129,7 @@ int cr_check(void);
 
 struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
 struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask);
+struct cr_fdset *cr_glob_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
 void close_cr_fdset(struct cr_fdset **cr_fdset);
 
 void free_mappings(struct list_head *vma_area_list);



More information about the CRIU mailing list