Commit 871b7367 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by Cyrill Gorcunov

crtools: Merge fdset allocation into prep

They always go in pairs so there's no need in two calls.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 15209d3f
......@@ -1223,18 +1223,15 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
pstree_switch_state(&pstree_list, CR_TASK_STOP, opts->leader_only);
list_for_each_entry(item, &pstree_list, list) {
cr_fdset = alloc_cr_fdset();
if (!cr_fdset)
goto err;
if (item->pid == pid) {
if (prep_cr_fdset_for_dump(cr_fdset, item->pid, CR_FD_DESC_ALL))
cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_ALL);
if (!cr_fdset)
goto err;
if (dump_pstree(pid, &pstree_list, cr_fdset))
goto err;
} else {
if (prep_cr_fdset_for_dump(cr_fdset, item->pid, CR_FD_DESC_NOPSTREE))
cr_fdset = prep_cr_fdset_for_dump(item->pid, CR_FD_DESC_NOPSTREE);
if (!cr_fdset)
goto err;
}
......@@ -1249,14 +1246,10 @@ int cr_dump_tasks(pid_t pid, struct cr_options *opts)
if (item->pid == item->threads[i])
continue;
cr_fdset_thread = alloc_cr_fdset();
cr_fdset_thread = prep_cr_fdset_for_dump(item->threads[i], CR_FD_DESC_CORE);
if (!cr_fdset_thread)
goto err;
if (prep_cr_fdset_for_dump(cr_fdset_thread,
item->threads[i], CR_FD_DESC_CORE))
goto err;
if (dump_task_thread(item->threads[i], cr_fdset_thread))
goto err;
......
......@@ -497,15 +497,10 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
LIST_HEAD(pstree_list);
int i, ret = -1;
cr_fdset = alloc_cr_fdset();
cr_fdset = prep_cr_fdset_for_restore(pid, CR_FD_DESC_USE(CR_FD_PSTREE));
if (!cr_fdset)
goto out;
ret = prep_cr_fdset_for_restore(cr_fdset, pid,
CR_FD_DESC_USE(CR_FD_PSTREE));
if (ret)
goto out;
ret = collect_pstree(&pstree_list, pid, cr_fdset);
if (ret)
goto out;
......@@ -522,14 +517,10 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
list_for_each_entry(item, &pstree_list, list) {
cr_fdset = alloc_cr_fdset();
cr_fdset = prep_cr_fdset_for_restore(item->pid, CR_FD_DESC_NOPSTREE);
if (!cr_fdset)
goto out;
ret = prep_cr_fdset_for_restore(cr_fdset, item->pid, CR_FD_DESC_NOPSTREE);
if (ret)
goto out;
lseek(cr_fdset->fds[CR_FD_CORE], MAGIC_OFFSET, SEEK_SET);
show_core(cr_fdset->fds[CR_FD_CORE], opts->show_pages_content);
......@@ -542,13 +533,8 @@ static int cr_show_all(unsigned long pid, struct cr_options *opts)
if (item->threads[i] == item->pid)
continue;
cr_fdset_th = alloc_cr_fdset();
if (!cr_fdset)
goto out;
ret = prep_cr_fdset_for_restore(cr_fdset_th,
item->threads[i], CR_FD_DESC_CORE);
if (ret)
cr_fdset_th = prep_cr_fdset_for_restore(item->threads[i], CR_FD_DESC_CORE);
if (!cr_fdset_th)
goto out;
pr_info("\n");
......
......@@ -87,7 +87,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
},
};
struct cr_fdset *alloc_cr_fdset(void)
static struct cr_fdset *alloc_cr_fdset(void)
{
struct cr_fdset *cr_fdset;
unsigned int i;
......@@ -99,13 +99,14 @@ struct cr_fdset *alloc_cr_fdset(void)
return cr_fdset;
}
int prep_cr_fdset_for_dump(struct cr_fdset *cr_fdset, int pid,
unsigned long use_mask)
struct cr_fdset *prep_cr_fdset_for_dump(int pid, unsigned long use_mask)
{
unsigned int i;
int ret = -1;
char path[PATH_MAX];
struct cr_fdset *cr_fdset;
cr_fdset = alloc_cr_fdset();
if (!cr_fdset)
goto err;
......@@ -134,20 +135,19 @@ int prep_cr_fdset_for_dump(struct cr_fdset *cr_fdset, int pid,
write_ptr_safe(ret, &fdset_template[i].magic, err);
cr_fdset->fds[i] = ret;
}
ret = 0;
err:
return ret;
return cr_fdset;
}
int prep_cr_fdset_for_restore(struct cr_fdset *cr_fdset, int pid,
unsigned long use_mask)
struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask)
{
unsigned int i;
int ret = -1;
char path[PATH_MAX];
u32 magic;
struct cr_fdset *cr_fdset;
cr_fdset = alloc_cr_fdset();
if (!cr_fdset)
goto err;
......@@ -176,10 +176,8 @@ int prep_cr_fdset_for_restore(struct cr_fdset *cr_fdset, int pid,
cr_fdset->fds[i] = ret;
}
ret = 0;
err:
return ret;
return cr_fdset;
}
void close_cr_fdset(struct cr_fdset *cr_fdset)
......
......@@ -85,11 +85,8 @@ int cr_restore_tasks(pid_t 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);
struct cr_fdset *alloc_cr_fdset(void);
int prep_cr_fdset_for_dump(struct cr_fdset *cr_fdset, int pid,
unsigned long use_mask);
int prep_cr_fdset_for_restore(struct cr_fdset *cr_fdset, int pid,
unsigned long use_mask);
struct cr_fdset *prep_cr_fdset_for_dump(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 free_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