Commit cf0550ce authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

dump: Images opening rework

Rename prep_cr_fdset_for_dump into cr_fdset_open and make it reentable, i.e.
every next enter will open more files in the same fdset. Required for zombies
and makes the code cleaner.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent cfbb9239
...@@ -1035,7 +1035,7 @@ static int dump_task_threads(struct pstree_item *item) ...@@ -1035,7 +1035,7 @@ static int dump_task_threads(struct pstree_item *item)
if (item->pid == item->threads[i]) if (item->pid == item->threads[i])
continue; continue;
cr_fdset_thread = prep_cr_fdset_for_dump(item->threads[i], CR_FD_DESC_CORE); cr_fdset_thread = cr_fdset_open(item->threads[i], CR_FD_DESC_CORE, NULL);
if (!cr_fdset_thread) if (!cr_fdset_thread)
goto err; goto err;
...@@ -1075,6 +1075,10 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset) ...@@ -1075,6 +1075,10 @@ static int dump_one_task(struct pstree_item *item, struct cr_fdset *cr_fdset)
if (ret < 0) if (ret < 0)
goto err; goto err;
cr_fdset = cr_fdset_open(item->pid, CR_FD_DESC_NOPSTREE, cr_fdset);
if (!cr_fdset)
goto err;
ret = collect_mappings(pid, pid_dir, &vma_area_list); ret = collect_mappings(pid, pid_dir, &vma_area_list);
if (ret) { if (ret) {
pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret); pr_err("Collect mappings (pid: %d) failed with %d\n", pid, ret);
...@@ -1178,16 +1182,17 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts) ...@@ -1178,16 +1182,17 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
collect_sockets(); collect_sockets();
list_for_each_entry(item, &pstree_list, list) { list_for_each_entry(item, &pstree_list, list) {
cr_fdset = cr_fdset_open(item->pid, CR_FD_DESC_NONE, NULL);
if (!cr_fdset)
goto err;
if (item->pid == pid) { if (item->pid == pid) {
cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_ALL); cr_fdset = cr_fdset_open(item->pid,
CR_FD_DESC_USE(CR_FD_PSTREE), cr_fdset);
if (!cr_fdset) if (!cr_fdset)
goto err; goto err;
if (dump_pstree(pid, &pstree_list, cr_fdset)) if (dump_pstree(pid, &pstree_list, cr_fdset))
goto err; goto err;
} else {
cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_NOPSTREE);
if (!cr_fdset)
goto err;
} }
if (dump_one_task(item, cr_fdset)) if (dump_one_task(item, cr_fdset))
......
...@@ -106,20 +106,23 @@ static struct cr_fdset *alloc_cr_fdset(void) ...@@ -106,20 +106,23 @@ static struct cr_fdset *alloc_cr_fdset(void)
return cr_fdset; return cr_fdset;
} }
struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask) struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *cr_fdset)
{ {
unsigned int i; unsigned int i;
int ret = -1; int ret = -1;
char path[PATH_MAX]; char path[PATH_MAX];
struct cr_fdset *cr_fdset;
if (cr_fdset == NULL) {
cr_fdset = alloc_cr_fdset(); cr_fdset = alloc_cr_fdset();
if (!cr_fdset) if (!cr_fdset)
goto err; goto err;
}
for (i = 0; i < CR_FD_MAX; i++) { for (i = 0; i < CR_FD_MAX; i++) {
if (!(use_mask & CR_FD_DESC_USE(i))) if (!(use_mask & CR_FD_DESC_USE(i)))
continue; continue;
if (cr_fdset->fds[i] != -1)
continue;
ret = get_image_path(path, sizeof(path), ret = get_image_path(path, sizeof(path),
fdset_template[i].fmt, pid); fdset_template[i].fmt, pid);
......
...@@ -88,7 +88,7 @@ int cr_restore_tasks(pid_t pid, struct cr_options *opts); ...@@ -88,7 +88,7 @@ int cr_restore_tasks(pid_t pid, struct cr_options *opts);
int cr_show(unsigned long pid, struct cr_options *opts); int cr_show(unsigned long pid, struct cr_options *opts);
int convert_to_elf(char *elf_path, int fd_core); int convert_to_elf(char *elf_path, int fd_core);
struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask); struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask); struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask);
void close_cr_fdset(struct cr_fdset **cr_fdset); void close_cr_fdset(struct cr_fdset **cr_fdset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment