[CRIU] [PATCH 02/28] dump: open global image files with global helpers

Kinsbursky Stanislav skinsbursky at openvz.org
Thu Mar 22 13:57:44 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 ad32975..10f3ac2 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1143,7 +1143,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;
 
@@ -1462,6 +1462,20 @@ err:
 	return -1;
 }
 
+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);
@@ -1497,6 +1511,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 	if (!shmems)
 		goto err;
 
+	if (unlink_global_image_files())
+		goto err;
+
 	list_for_each_entry(item, &pstree_list, list) {
 		struct cr_fdset *cr_fdset = NULL;
 
@@ -1510,8 +1527,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 22b6afb..6ede2b7 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1167,7 +1167,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);
@@ -1291,7 +1291,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 7483e35..56ff432 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -523,7 +523,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 3faba43..9b39c91 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -80,7 +80,7 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
 #define FMT_FNAME_CORE		"core-%d.img"
 #define FMT_FNAME_VMAS		"vmas-%d.img"
 #define FMT_FNAME_PIPES		"pipes-%d.img"
-#define FMT_FNAME_PSTREE	"pstree-%d.img"
+#define FMT_FNAME_PSTREE	"pstree.img"
 #define FMT_FNAME_SIGACTS	"sigacts-%d.img"
 #define FMT_FNAME_UNIXSK	"unixsk-%d.img"
 #define FMT_FNAME_INETSK	"inetsk-%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