[CRIU] [PATCH] dump: merge collect and dump stage for processes tree
Kinsbursky Stanislav
skinsbursky at openvz.org
Wed Mar 21 06:12:30 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
This is a cleanup patch. This tree is merged only once. So it's image file can
be opened by opne_image() call and dumped right after collect stage.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 39 ++++++++++++++++++++-------------------
1 files changed, 20 insertions(+), 19 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 5ef7d61..2ffd02b 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1012,7 +1012,9 @@ static int collect_subtree(pid_t pid, pid_t ppid, struct list_head *pstree_list,
return 0;
}
-static int collect_pstree(pid_t pid, struct list_head *pstree_list,
+static int dump_pstree(pid_t pid, const struct list_head *pstree_list);
+
+static int collect_dump_pstree(pid_t pid, struct list_head *pstree_list,
const struct cr_options *opts)
{
int ret, attempts = 5;
@@ -1070,21 +1072,28 @@ try_again:
}
}
- return ret;
+ if (ret)
+ return ret;
+
+ return dump_pstree(pid, pstree_list);
}
-static int dump_pstree(pid_t pid, const struct list_head *pstree_list,
- const struct cr_fdset *cr_fdset)
+static int dump_pstree(pid_t pid, const struct list_head *pstree_list)
{
const struct pstree_item *item;
struct pstree_entry e;
unsigned long i;
int ret = -1;
+ int pstree_fd;
pr_info("\n");
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);
+ if (pstree_fd < 0)
+ return -1;
+
list_for_each_entry(item, pstree_list, list) {
pr_info("Process: %d (%d children)\n",
@@ -1094,14 +1103,13 @@ static int dump_pstree(pid_t pid, const struct list_head *pstree_list,
e.nr_children = item->nr_children;
e.nr_threads = item->nr_threads;
- if (write_img(cr_fdset->fds[CR_FD_PSTREE], &e))
+ if (write_img(pstree_fd, &e))
goto err;
pr_info("Children:");
for (i = 0; i < item->nr_children; i++) {
pr_info(" %d", item->children[i]);
- if (write_img(cr_fdset->fds[CR_FD_PSTREE],
- &item->children[i]))
+ if (write_img(pstree_fd, &item->children[i]))
goto err;
}
pr_info("\n");
@@ -1109,8 +1117,7 @@ static int dump_pstree(pid_t pid, const struct list_head *pstree_list,
pr_info("Threads:\n");
for (i = 0; i < item->nr_threads; i++) {
pr_info(" %d", item->threads[i]);
- if (write_img(cr_fdset->fds[CR_FD_PSTREE],
- &item->threads[i]))
+ if (write_img(pstree_fd, &item->threads[i]))
goto err;
}
pr_info("\n");
@@ -1119,6 +1126,7 @@ static int dump_pstree(pid_t pid, const struct list_head *pstree_list,
err:
pr_info("----------------------------------------\n");
+ close(pstree_fd);
return ret;
}
@@ -1405,7 +1413,6 @@ err_free:
int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
{
LIST_HEAD(pstree_list);
- struct cr_fdset *cr_fdset = NULL;
struct pstree_item *item;
int i, ret = -1;
@@ -1416,7 +1423,7 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
pr_info("Dumping process (pid: %d)\n", pid);
pr_info("========================================\n");
- if (collect_pstree(pid, &pstree_list, opts))
+ if (collect_dump_pstree(pid, &pstree_list, opts))
goto err;
if (opts->namespaces_flags) {
@@ -1433,14 +1440,9 @@ 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), cr_fdset);
- 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) {
+ struct cr_fdset *cr_fdset = NULL;
+
cr_fdset = cr_dump_fdset_open(item->pid, CR_FD_DESC_NONE, NULL);
if (!cr_fdset)
goto err;
@@ -1468,7 +1470,6 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
err:
pstree_switch_state(&pstree_list, opts);
free_pstree(&pstree_list);
- close_cr_fdset(&cr_fdset);
return ret;
}
More information about the CRIU
mailing list