[CRIU] [PATCH v2] dump: open global image files with global helpers

Kinsbursky Stanislav skinsbursky at openvz.org
Wed Mar 21 06:22:40 EDT 2012


From: Stanislav Kinsbursky <skinsbursky at openvz.org>

v2: added unlink of global files prior to dump stage.

Now global image files has not pid numbers in it's name.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
 cr-dump.c         |   22 ++++++++++++++++++++--
 cr-restore.c      |    4 ++--
 cr-show.c         |    2 +-
 include/crtools.h |    4 ++--
 sockets.c         |    2 +-
 5 files changed, 26 insertions(+), 8 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 2ffd02b..4c52fb0 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1090,7 +1090,7 @@ static int dump_pstree(pid_t pid, const struct list_head *pstree_list)
 	pr_info("Dumping pstree (pid: %d)\n", pid);
 	pr_info("----------------------------------------\n");
 
-	pstree_fd = open_image(CR_FD_PSTREE, O_RDWR | O_CREAT | O_EXCL, pid);
+	pstree_fd = open_image(CR_FD_PSTREE, O_RDWR | O_CREAT | O_EXCL);
 	if (pstree_fd < 0)
 		return -1;
 
@@ -1410,6 +1410,20 @@ err_free:
 	return ret;
 }
 
+static int unlink_global_image_files(void)
+{
+	char path[PATH_MAX];
+
+	snprintf(path, PATH_MAX, fdset_template[CR_FD_SK_QUEUES].fmt);
+	if (unlinkat(image_dir_fd, path, 0) && errno != ENOENT)
+		goto err;
+	return 0;
+
+err:
+	pr_perror("Unable to unlink %s", path);
+	return -1;
+}
+
 int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 {
 	LIST_HEAD(pstree_list);
@@ -1440,6 +1454,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 
 	collect_sockets();
 
+	if (unlink_global_image_files())
+		goto err;
+
 	list_for_each_entry(item, &pstree_list, list) {
 		struct cr_fdset *cr_fdset = NULL;
 
@@ -1453,8 +1470,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 		 * 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(CR_FD_DESC_SK_QUEUES, cr_fdset))
 			goto err;
 
 		if (dump_one_task(item, cr_fdset))
diff --git a/cr-restore.c b/cr-restore.c
index 71e5de1..d48385e 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1320,7 +1320,7 @@ static int restore_task_with_children(void *_arg)
 
 	pr_info("%d: Starting restore\n", me->pid);
 
-	fd = open_image_ro_nocheck(FMT_FNAME_PSTREE, pstree_pid);
+	fd = open_glob_image_ro_nocheck(FMT_FNAME_PSTREE);
 	if (fd < 0) {
 		pr_perror("%d: Can't reopen pstree image", me->pid);
 		exit(1);
@@ -1443,7 +1443,7 @@ static int restore_all_tasks(pid_t pid, struct cr_options *opts)
 	int pstree_fd = -1;
 	u32 type = 0;
 
-	pstree_fd = open_image_ro(CR_FD_PSTREE, pstree_pid);
+	pstree_fd = open_glob_image_ro(CR_FD_PSTREE);
 	if (pstree_fd < 0)
 		return -1;
 
diff --git a/cr-show.c b/cr-show.c
index eeb7042..2852389 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -551,7 +551,7 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
 	LIST_HEAD(pstree_list);
 	int i, ret = -1;
 
-	cr_fdset = cr_show_fdset_open(pid, CR_FD_DESC_PSTREE | CR_FD_DESC_SK_QUEUES);
+	cr_fdset = cr_glob_fdset_open(CR_FD_DESC_PSTREE | CR_FD_DESC_SK_QUEUES, NULL);
 	if (!cr_fdset)
 		goto out;
 
diff --git a/include/crtools.h b/include/crtools.h
index 4e96ea3..788cc9a 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -79,7 +79,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
 #define FMT_FNAME_CORE		"core-%d.img"
 #define FMT_FNAME_CORE_OUT	"core-%d.img.out"
 #define FMT_FNAME_PIPES		"pipes-%d.img"
-#define FMT_FNAME_PSTREE	"pstree-%d.img"
+#define FMT_FNAME_PSTREE	"pstree.img"
 #define FMT_FNAME_SHMEM		"shmem-%d.img"
 #define FMT_FNAME_SIGACTS	"sigacts-%d.img"
 #define FMT_FNAME_UNIXSK	"unixsk-%d.img"
@@ -91,7 +91,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
 #define FMT_FNAME_IPCNS_SHM	"ipcns-shm-%d.img"
 #define FMT_FNAME_IPCNS_MSG	"ipcns-msg-%d.img"
 #define FMT_FNAME_IPCNS_SEM	"ipcns-sem-%d.img"
-#define FMT_FNAME_SK_QUEUES	"sk-queues-%d.img"
+#define FMT_FNAME_SK_QUEUES	"sk-queues.img"
 
 /*
  * FIXME -- this is required for legacy image copy only.
diff --git a/sockets.c b/sockets.c
index f1896fa..8bf4c15 100644
--- a/sockets.c
+++ b/sockets.c
@@ -1186,7 +1186,7 @@ err:
 	if (ret)
 		return ret;
 
-	unix_pool.img_fd = open_image_ro(CR_FD_SK_QUEUES, pstree_pid);
+	unix_pool.img_fd = open_glob_image_ro(CR_FD_SK_QUEUES);
 	if (unix_pool.img_fd < 0)
 		return -1;
 	ret = read_sockets_queues(&unix_pool);


More information about the CRIU mailing list