Commit b0bd9204 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

pstree: move state from pstree_item to pid

I'm going to collect all pids in rbtree, but threads doesn't have
pstree-entries, so we need a field to distinguish pstree_item-s from
threads.
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 845b822c
......@@ -640,7 +640,7 @@ int get_task_ids(struct pstree_item *item)
task_kobj_ids_entry__init(item->ids);
if (item->state != TASK_DEAD) {
if (item->pid.state != TASK_DEAD) {
ret = dump_task_kobj_ids(item);
if (ret)
goto err_free;
......@@ -722,7 +722,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
strlcpy((char *)core->tc->comm, stat->comm, TASK_COMM_LEN);
core->tc->flags = stat->flags;
core->tc->task_state = item->state;
core->tc->task_state = item->pid.state;
core->tc->exit_code = 0;
ret = parasite_dump_thread_leader_seized(ctl, pid, core);
......@@ -777,14 +777,14 @@ static int collect_pstree_ids_predump(void)
* write_img_inventory().
*/
crt.i.state = TASK_ALIVE;
crt.i.pid.state = TASK_ALIVE;
crt.i.pid.real = getpid();
if (predump_task_ns_ids(&crt.i))
return -1;
for_each_pstree_item(item) {
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
continue;
if (predump_task_ns_ids(item))
......@@ -1069,7 +1069,7 @@ static int dump_zombies(void)
*/
for_each_pstree_item(item) {
if (item->state != TASK_DEAD)
if (item->pid.state != TASK_DEAD)
continue;
if (item->pid.virt < 0) {
......@@ -1117,12 +1117,12 @@ static int pre_dump_one_task(struct pstree_item *item, struct list_head *ctls)
pr_info("Pre-dumping task (pid: %d)\n", pid);
pr_info("========================================\n");
if (item->state == TASK_STOPPED) {
if (item->pid.state == TASK_STOPPED) {
pr_warn("Stopped tasks are not supported\n");
return 0;
}
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
return 0;
ret = collect_mappings(pid, &vmas);
......@@ -1194,7 +1194,7 @@ static int dump_one_task(struct pstree_item *item)
pr_info("Dumping task (pid: %d)\n", pid);
pr_info("========================================\n");
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
/*
* zombies are dumped separately in dump_zombies()
*/
......
......@@ -247,7 +247,7 @@ static int root_prepare_shared(void)
return -1;
for_each_pstree_item(pi) {
if (pi->state == TASK_HELPER)
if (pi->pid.state == TASK_HELPER)
continue;
ret = prepare_mm_pid(pi);
......@@ -804,7 +804,7 @@ static int collect_child_pids(int state, int *n)
list_for_each_entry(pi, &current->children, sibling) {
pid_t *child;
if (pi->state != state)
if (pi->pid.state != state)
continue;
child = rst_mem_alloc(sizeof(*child), RM_PRIVATE);
......@@ -1021,7 +1021,7 @@ static int wait_on_helpers_zombies(void)
pid_t pid = pi->pid.virt;
int status;
switch (pi->state) {
switch (pi->pid.state) {
case TASK_DEAD:
if (waitid(P_PID, pid, NULL, WNOWAIT | WEXITED) < 0) {
pr_perror("Wait on %d zombie failed", pid);
......@@ -1126,9 +1126,9 @@ static int restore_one_task(int pid, CoreEntry *core)
if (task_alive(current))
ret = restore_one_alive_task(pid, core);
else if (current->state == TASK_DEAD)
else if (current->pid.state == TASK_DEAD)
ret = restore_one_zombie(core);
else if (current->state == TASK_HELPER) {
else if (current->pid.state == TASK_HELPER) {
restore_finish_stage(CR_STATE_RESTORE);
if (wait_on_helpers_zombies()) {
pr_err("failed to wait on helpers and zombies\n");
......@@ -1204,7 +1204,7 @@ static inline int fork_with_pid(struct pstree_item *item)
int ret = -1;
pid_t pid = item->pid.virt;
if (item->state != TASK_HELPER) {
if (item->pid.state != TASK_HELPER) {
struct cr_img *img;
img = open_image(CR_FD_CORE, O_RSTR, pid);
......@@ -1220,15 +1220,15 @@ static inline int fork_with_pid(struct pstree_item *item)
if (check_core(ca.core, item))
return -1;
item->state = ca.core->tc->task_state;
item->pid.state = ca.core->tc->task_state;
rsti(item)->cg_set = ca.core->tc->cg_set;
rsti(item)->has_seccomp = ca.core->tc->seccomp_mode != SECCOMP_MODE_DISABLED;
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
rsti(item->parent)->nr_zombies++;
else if (!task_alive(item)) {
pr_err("Unknown task state %d\n", item->state);
pr_err("Unknown task state %d\n", item->pid.state);
return -1;
}
......@@ -1375,7 +1375,7 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
break;
BUG_ON(&pi->sibling == &current->children);
if (pi->state != TASK_HELPER)
if (pi->pid.state != TASK_HELPER)
break;
}
......@@ -1612,7 +1612,7 @@ static int restore_task_with_children(void *_arg)
if ( !(ca->clone_flags & CLONE_FILES))
close_safe(&ca->fd);
if (current->state != TASK_HELPER) {
if (current->pid.state != TASK_HELPER) {
ret = clone_service_fd(rsti(current)->service_fd_id);
if (ret)
goto err;
......@@ -1902,7 +1902,7 @@ static void finalize_restore(void)
xfree(ctl);
if (item->state == TASK_STOPPED)
if (item->pid.state == TASK_STOPPED)
kill(item->pid.real, SIGSTOP);
}
}
......
......@@ -111,7 +111,7 @@ int prepare_inventory(InventoryEntry *he)
he->has_ns_per_id = true;
he->lsmtype = host_lsm_type();
crt.i.state = TASK_ALIVE;
crt.i.pid.state = TASK_ALIVE;
crt.i.pid.real = getpid();
if (get_task_ids(&crt.i))
return -1;
......
......@@ -17,6 +17,8 @@ struct pid {
* dumpee context, because the dumpee might have own pid namespace.
*/
pid_t virt;
int state; /* TASK_XXX constants */
};
/*
......
......@@ -21,8 +21,6 @@ struct pstree_item {
pid_t sid;
pid_t born_sid;
int state; /* TASK_XXX constants */
int nr_threads; /* number of threads */
struct pid *threads; /* array of threads */
CoreEntry **core;
......@@ -60,7 +58,7 @@ static inline int shared_fdtable(struct pstree_item *item)
static inline bool task_alive(struct pstree_item *i)
{
return (i->state == TASK_ALIVE) || (i->state == TASK_STOPPED);
return (i->pid.state == TASK_ALIVE) || (i->pid.state == TASK_STOPPED);
}
extern void free_pstree(struct pstree_item *root_item);
......
......@@ -223,7 +223,7 @@ struct pstree_item *alloc_pstree_helper(void)
ret = alloc_pstree_item_with_rst();
if (ret) {
ret->state = TASK_HELPER;
ret->pid.state = TASK_HELPER;
rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS;
task_entries->nr_helpers++;
}
......@@ -560,7 +560,7 @@ static int prepare_pstree_ids(void)
if (!item->parent) /* skip the root task */
continue;
if (item->state == TASK_HELPER)
if (item->pid.state == TASK_HELPER)
continue;
if (item->sid != item->pid.virt) {
......@@ -595,7 +595,7 @@ static int prepare_pstree_ids(void)
/* Try to find helpers, who should be connected to the leader */
list_for_each_entry(child, &helpers, sibling) {
if (child->state != TASK_HELPER)
if (child->pid.state != TASK_HELPER)
continue;
if (child->sid != item->sid)
......
......@@ -48,7 +48,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
struct sock_filter buf[BPF_MAXINSNS];
void *m;
if (item->state == TASK_DEAD ||
if (item->pid.state == TASK_DEAD ||
dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER)
return 0;
......
......@@ -394,7 +394,7 @@ static int collect_children(struct pstree_item *item)
c->pid.real = pid;
c->parent = item;
c->state = ret;
c->pid.state = ret;
list_add_tail(&c->sibling, &item->children);
/* Here is a recursive call (Depth-first search) */
......@@ -411,7 +411,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
{
int i;
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
return;
/*
......@@ -419,7 +419,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
* the item->state is the state task was in when we seized one.
*/
unseize_task(item->pid.real, item->state, st);
unseize_task(item->pid.real, item->pid.state, st);
if (st == TASK_DEAD)
return;
......@@ -436,7 +436,7 @@ static void pstree_wait(struct pstree_item *root_item)
for_each_pstree_item(item) {
if (item->state == TASK_DEAD)
if (item->pid.state == TASK_DEAD)
continue;
for (i = 0; i < item->nr_threads; i++) {
......@@ -516,7 +516,7 @@ static int collect_threads(struct pstree_item *item)
if (ret < 0)
goto err;
if ((item->state == TASK_DEAD) && (nr_threads > 1)) {
if ((item->pid.state == TASK_DEAD) && (nr_threads > 1)) {
pr_err("Zombies with threads are not supported\n");
goto err;
}
......@@ -633,7 +633,7 @@ static int collect_task(struct pstree_item *item)
if (ret < 0)
goto err_close;
if ((item->state == TASK_DEAD) && !list_empty(&item->children)) {
if ((item->pid.state == TASK_DEAD) && !list_empty(&item->children)) {
pr_err("Zombie with children?! O_o Run, run, run!\n");
goto err_close;
}
......@@ -641,7 +641,7 @@ static int collect_task(struct pstree_item *item)
if (pstree_alloc_cores(item))
goto err_close;
pr_info("Collected %d in %d state\n", item->pid.real, item->state);
pr_info("Collected %d in %d state\n", item->pid.real, item->pid.state);
return 0;
err_close:
......@@ -680,7 +680,7 @@ int collect_pstree(pid_t pid)
if (ret < 0)
goto err;
pr_info("Seized task %d, state %d\n", pid, ret);
root_item->state = ret;
root_item->pid.state = ret;
ret = collect_task(root_item);
if (ret < 0)
......
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