Commit e4335cf0 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

pstree: Make pstree_item::pid pointer and move virt and node to array

So, after the patch struct pid will look as:

struct pid {
        struct pstree_item *item;
        pid_t real;
        int state;
        struct {
                pid_t virt;
                struct rb_node node;
        } ns[1];
};

travis-ci: success for Make pstree_item::pid allocated dynamically
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent 9af2eff9
...@@ -70,7 +70,7 @@ static int run_shell_scripts(const char *action) ...@@ -70,7 +70,7 @@ static int run_shell_scripts(const char *action)
int pid; int pid;
char root_item_pid[16]; char root_item_pid[16];
pid = root_item->pid.real; pid = root_item->pid->real;
if (pid != -1) { if (pid != -1) {
snprintf(root_item_pid, sizeof(root_item_pid), "%d", pid); snprintf(root_item_pid, sizeof(root_item_pid), "%d", pid);
if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) { if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
......
...@@ -579,12 +579,12 @@ static int autofs_dup_pipe(struct pstree_item *task, ...@@ -579,12 +579,12 @@ static int autofs_dup_pipe(struct pstree_item *task,
if (dup_fle(task, ple, new_fd, flags) < 0) { if (dup_fle(task, ple, new_fd, flags) < 0) {
pr_err("Failed to add fd %d to process %d\n", pr_err("Failed to add fd %d to process %d\n",
new_fd, task->pid.virt); new_fd, task->pid->ns[0].virt);
return -1; return -1;
} }
pr_info("autofs: added pipe fd %d, flags %#x to %d\n", pr_info("autofs: added pipe fd %d, flags %#x to %d\n",
new_fd, flags, task->pid.virt); new_fd, flags, task->pid->ns[0].virt);
return new_fd; return new_fd;
} }
...@@ -851,12 +851,12 @@ static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master, ...@@ -851,12 +851,12 @@ static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master,
ple = find_fle_by_fd(&rsti(master)->fds, pipe_fd); ple = find_fle_by_fd(&rsti(master)->fds, pipe_fd);
if (!ple) { if (!ple) {
pr_err("Failed to find pipe fd %d in process %d\n", pr_err("Failed to find pipe fd %d in process %d\n",
pipe_fd, master->pid.virt); pipe_fd, master->pid->ns[0].virt);
return NULL; return NULL;
} }
if (ple->fe->type != FD_TYPES__PIPE) { if (ple->fe->type != FD_TYPES__PIPE) {
pr_err("Fd %d in process %d is not a pipe: %d\n", pipe_fd, pr_err("Fd %d in process %d is not a pipe: %d\n", pipe_fd,
master->pid.virt, ple->fe->type); master->pid->ns[0].virt, ple->fe->type);
return NULL; return NULL;
} }
return ple; return ple;
...@@ -874,7 +874,7 @@ static int autofs_create_fle(struct pstree_item *task, FdinfoEntry *fe, ...@@ -874,7 +874,7 @@ static int autofs_create_fle(struct pstree_item *task, FdinfoEntry *fe,
le = (void *)ALIGN((long)le, sizeof(int)); le = (void *)ALIGN((long)le, sizeof(int));
futex_init(&le->real_pid); futex_init(&le->real_pid);
le->pid = task->pid.virt; le->pid = task->pid->ns[0].virt;
le->fe = fe; le->fe = fe;
collect_gen_fd(le, rst_info); collect_gen_fd(le, rst_info);
...@@ -955,7 +955,7 @@ static int autofs_add_mount_info(void *data) ...@@ -955,7 +955,7 @@ static int autofs_add_mount_info(void *data)
entry->fd = autofs_dup_pipe(master, ple, entry->fd); entry->fd = autofs_dup_pipe(master, ple, entry->fd);
if (entry->fd < 0) { if (entry->fd < 0) {
pr_err("Failed to find free fd in process %d\n", pr_err("Failed to find free fd in process %d\n",
master->pid.virt); master->pid->ns[0].virt);
return -1; return -1;
} }
} }
......
...@@ -640,7 +640,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_ ...@@ -640,7 +640,7 @@ int dump_task_cgroup(struct pstree_item *item, u32 *cg_id, struct parasite_dump_
struct cg_set *cs; struct cg_set *cs;
if (item) if (item)
pid = item->pid.real; pid = item->pid->real;
else else
pid = getpid(); pid = getpid();
......
...@@ -1095,7 +1095,7 @@ int cr_check(void) ...@@ -1095,7 +1095,7 @@ int cr_check(void)
if (root_item == NULL) if (root_item == NULL)
return -1; return -1;
root_item->pid.real = getpid(); root_item->pid->real = getpid();
if (collect_pstree_ids()) if (collect_pstree_ids())
return -1; return -1;
......
...@@ -591,7 +591,7 @@ static int dump_task_kobj_ids(struct pstree_item *item) ...@@ -591,7 +591,7 @@ static int dump_task_kobj_ids(struct pstree_item *item)
{ {
int new; int new;
struct kid_elem elem; struct kid_elem elem;
int pid = item->pid.real; int pid = item->pid->real;
TaskKobjIdsEntry *ids = item->ids; TaskKobjIdsEntry *ids = item->ids;
elem.pid = pid; elem.pid = pid;
...@@ -639,7 +639,7 @@ int get_task_ids(struct pstree_item *item) ...@@ -639,7 +639,7 @@ int get_task_ids(struct pstree_item *item)
task_kobj_ids_entry__init(item->ids); task_kobj_ids_entry__init(item->ids);
if (item->pid.state != TASK_DEAD) { if (item->pid->state != TASK_DEAD) {
ret = dump_task_kobj_ids(item); ret = dump_task_kobj_ids(item);
if (ret) if (ret)
goto err_free; goto err_free;
...@@ -694,7 +694,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl, ...@@ -694,7 +694,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
{ {
struct cr_img *img; struct cr_img *img;
CoreEntry *core = item->core[0]; CoreEntry *core = item->core[0];
pid_t pid = item->pid.real; pid_t pid = item->pid->real;
int ret = -1; int ret = -1;
struct proc_status_creds *creds; struct proc_status_creds *creds;
struct parasite_dump_cgroup_args cgroup_args, *info = NULL; struct parasite_dump_cgroup_args cgroup_args, *info = NULL;
...@@ -709,7 +709,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl, ...@@ -709,7 +709,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
creds = dmpi(item)->pi_creds; creds = dmpi(item)->pi_creds;
if (creds->seccomp_mode != SECCOMP_MODE_DISABLED) { if (creds->seccomp_mode != SECCOMP_MODE_DISABLED) {
pr_info("got seccomp mode %d for %d\n", creds->seccomp_mode, item->pid.virt); pr_info("got seccomp mode %d for %d\n", creds->seccomp_mode, item->pid->ns[0].virt);
core->tc->has_seccomp_mode = true; core->tc->has_seccomp_mode = true;
core->tc->seccomp_mode = creds->seccomp_mode; core->tc->seccomp_mode = creds->seccomp_mode;
...@@ -721,7 +721,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl, ...@@ -721,7 +721,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
strlcpy((char *)core->tc->comm, stat->comm, TASK_COMM_LEN); strlcpy((char *)core->tc->comm, stat->comm, TASK_COMM_LEN);
core->tc->flags = stat->flags; core->tc->flags = stat->flags;
core->tc->task_state = item->pid.state; core->tc->task_state = item->pid->state;
core->tc->exit_code = 0; core->tc->exit_code = 0;
ret = parasite_dump_thread_leader_seized(ctl, pid, core); ret = parasite_dump_thread_leader_seized(ctl, pid, core);
...@@ -766,24 +766,25 @@ err: ...@@ -766,24 +766,25 @@ err:
static int collect_pstree_ids_predump(void) static int collect_pstree_ids_predump(void)
{ {
struct pstree_item *item; struct pstree_item *item;
struct pid pid;
struct { struct {
struct pstree_item i; struct pstree_item i;
struct dmp_info d; struct dmp_info d;
} crt = { }; } crt = { .i.pid = &pid, };
/* /*
* This thing is normally done inside * This thing is normally done inside
* write_img_inventory(). * write_img_inventory().
*/ */
crt.i.pid.state = TASK_ALIVE; crt.i.pid->state = TASK_ALIVE;
crt.i.pid.real = getpid(); crt.i.pid->real = getpid();
if (predump_task_ns_ids(&crt.i)) if (predump_task_ns_ids(&crt.i))
return -1; return -1;
for_each_pstree_item(item) { for_each_pstree_item(item) {
if (item->pid.state == TASK_DEAD) if (item->pid->state == TASK_DEAD)
continue; continue;
if (predump_task_ns_ids(item)) if (predump_task_ns_ids(item))
...@@ -827,9 +828,9 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, ...@@ -827,9 +828,9 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl,
pr_err("Can't dump thread for pid %d\n", pid); pr_err("Can't dump thread for pid %d\n", pid);
goto err; goto err;
} }
pstree_insert_pid(tid->virt, tid); pstree_insert_pid(tid->ns[0].virt, tid);
img = open_image(CR_FD_CORE, O_DUMP, tid->virt); img = open_image(CR_FD_CORE, O_DUMP, tid->ns[0].virt);
if (!img) if (!img)
goto err; goto err;
...@@ -856,7 +857,7 @@ static int dump_one_zombie(const struct pstree_item *item, ...@@ -856,7 +857,7 @@ static int dump_one_zombie(const struct pstree_item *item,
core->tc->task_state = TASK_DEAD; core->tc->task_state = TASK_DEAD;
core->tc->exit_code = pps->exit_code; core->tc->exit_code = pps->exit_code;
img = open_image(CR_FD_CORE, O_DUMP, item->pid.virt); img = open_image(CR_FD_CORE, O_DUMP, item->pid->ns[0].virt);
if (!img) if (!img)
goto err; goto err;
...@@ -980,8 +981,8 @@ static int dump_task_threads(struct parasite_ctl *parasite_ctl, ...@@ -980,8 +981,8 @@ static int dump_task_threads(struct parasite_ctl *parasite_ctl,
for (i = 0; i < item->nr_threads; i++) { for (i = 0; i < item->nr_threads; i++) {
/* Leader is already dumped */ /* Leader is already dumped */
if (item->pid.real == item->threads[i].real) { if (item->pid->real == item->threads[i].real) {
item->threads[i].virt = item->pid.virt; item->threads[i].ns[0].virt = item->pid->ns[0].virt;
continue; continue;
} }
if (dump_task_thread(parasite_ctl, item, i)) if (dump_task_thread(parasite_ctl, item, i))
...@@ -1011,17 +1012,17 @@ static int fill_zombies_pids(struct pstree_item *item) ...@@ -1011,17 +1012,17 @@ static int fill_zombies_pids(struct pstree_item *item)
* Pids read here are virtual -- caller has set up * Pids read here are virtual -- caller has set up
* the proc of target pid namespace. * the proc of target pid namespace.
*/ */
if (parse_children(item->pid.virt, &ch, &nr) < 0) if (parse_children(item->pid->ns[0].virt, &ch, &nr) < 0)
return -1; return -1;
/* /*
* Step 1 -- filter our ch's pid of alive tasks * Step 1 -- filter our ch's pid of alive tasks
*/ */
list_for_each_entry(child, &item->children, sibling) { list_for_each_entry(child, &item->children, sibling) {
if (child->pid.virt < 0) if (child->pid->ns[0].virt < 0)
continue; continue;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
if (ch[i] == child->pid.virt) { if (ch[i] == child->pid->ns[0].virt) {
ch[i] = -1; ch[i] = -1;
break; break;
} }
...@@ -1036,12 +1037,12 @@ static int fill_zombies_pids(struct pstree_item *item) ...@@ -1036,12 +1037,12 @@ static int fill_zombies_pids(struct pstree_item *item)
*/ */
i = 0; i = 0;
list_for_each_entry(child, &item->children, sibling) { list_for_each_entry(child, &item->children, sibling) {
if (child->pid.virt > 0) if (child->pid->ns[0].virt > 0)
continue; continue;
for (; i < nr; i++) { for (; i < nr; i++) {
if (ch[i] < 0) if (ch[i] < 0)
continue; continue;
child->pid.virt = ch[i]; child->pid->ns[0].virt = ch[i];
ch[i] = -1; ch[i] = -1;
break; break;
} }
...@@ -1069,12 +1070,12 @@ static int dump_zombies(void) ...@@ -1069,12 +1070,12 @@ static int dump_zombies(void)
*/ */
for_each_pstree_item(item) { for_each_pstree_item(item) {
if (item->pid.state != TASK_DEAD) if (item->pid->state != TASK_DEAD)
continue; continue;
if (item->pid.virt < 0) { if (item->pid->ns[0].virt < 0) {
if (!pidns) if (!pidns)
item->pid.virt = item->pid.real; item->pid->ns[0].virt = item->pid->real;
else if (root_item == item) { else if (root_item == item) {
pr_err("A root task is dead\n"); pr_err("A root task is dead\n");
goto err; goto err;
...@@ -1083,7 +1084,7 @@ static int dump_zombies(void) ...@@ -1083,7 +1084,7 @@ static int dump_zombies(void)
} }
pr_info("Obtaining zombie stat ... \n"); pr_info("Obtaining zombie stat ... \n");
if (parse_pid_stat(item->pid.virt, &pps_buf) < 0) if (parse_pid_stat(item->pid->ns[0].virt, &pps_buf) < 0)
goto err; goto err;
item->sid = pps_buf.sid; item->sid = pps_buf.sid;
...@@ -1104,7 +1105,7 @@ err: ...@@ -1104,7 +1105,7 @@ err:
static int pre_dump_one_task(struct pstree_item *item) static int pre_dump_one_task(struct pstree_item *item)
{ {
pid_t pid = item->pid.real; pid_t pid = item->pid->real;
struct vm_area_list vmas; struct vm_area_list vmas;
struct parasite_ctl *parasite_ctl; struct parasite_ctl *parasite_ctl;
int ret = -1; int ret = -1;
...@@ -1118,12 +1119,12 @@ static int pre_dump_one_task(struct pstree_item *item) ...@@ -1118,12 +1119,12 @@ static int pre_dump_one_task(struct pstree_item *item)
pr_info("Pre-dumping task (pid: %d)\n", pid); pr_info("Pre-dumping task (pid: %d)\n", pid);
pr_info("========================================\n"); pr_info("========================================\n");
if (item->pid.state == TASK_STOPPED) { if (item->pid->state == TASK_STOPPED) {
pr_warn("Stopped tasks are not supported\n"); pr_warn("Stopped tasks are not supported\n");
return 0; return 0;
} }
if (item->pid.state == TASK_DEAD) if (item->pid->state == TASK_DEAD)
return 0; return 0;
ret = collect_mappings(pid, &vmas, NULL); ret = collect_mappings(pid, &vmas, NULL);
...@@ -1157,7 +1158,7 @@ static int pre_dump_one_task(struct pstree_item *item) ...@@ -1157,7 +1158,7 @@ static int pre_dump_one_task(struct pstree_item *item)
goto err_cure; goto err_cure;
} }
item->pid.virt = misc.pid; item->pid->ns[0].virt = misc.pid;
mdc.pre_dump = true; mdc.pre_dump = true;
...@@ -1180,7 +1181,7 @@ err_cure: ...@@ -1180,7 +1181,7 @@ err_cure:
static int dump_one_task(struct pstree_item *item) static int dump_one_task(struct pstree_item *item)
{ {
pid_t pid = item->pid.real; pid_t pid = item->pid->real;
struct vm_area_list vmas; struct vm_area_list vmas;
struct parasite_ctl *parasite_ctl; struct parasite_ctl *parasite_ctl;
int ret, exit_code = -1; int ret, exit_code = -1;
...@@ -1197,7 +1198,7 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1197,7 +1198,7 @@ static int dump_one_task(struct pstree_item *item)
pr_info("Dumping task (pid: %d)\n", pid); pr_info("Dumping task (pid: %d)\n", pid);
pr_info("========================================\n"); pr_info("========================================\n");
if (item->pid.state == TASK_DEAD) if (item->pid->state == TASK_DEAD)
/* /*
* zombies are dumped separately in dump_zombies() * zombies are dumped separately in dump_zombies()
*/ */
...@@ -1286,21 +1287,21 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1286,21 +1287,21 @@ static int dump_one_task(struct pstree_item *item)
goto err_cure_imgset; goto err_cure_imgset;
} }
item->pid.virt = misc.pid; item->pid->ns[0].virt = misc.pid;
pstree_insert_pid(item->pid.virt, &item->pid); pstree_insert_pid(item->pid->ns[0].virt, item->pid);
item->sid = misc.sid; item->sid = misc.sid;
item->pgid = misc.pgid; item->pgid = misc.pgid;
pr_info("sid=%d pgid=%d pid=%d\n", pr_info("sid=%d pgid=%d pid=%d\n",
item->sid, item->pgid, item->pid.virt); item->sid, item->pgid, item->pid->ns[0].virt);
if (item->sid == 0) { if (item->sid == 0) {
pr_err("A session leader of %d(%d) is outside of its pid namespace\n", pr_err("A session leader of %d(%d) is outside of its pid namespace\n",
item->pid.real, item->pid.virt); item->pid->real, item->pid->ns[0].virt);
goto err_cure; goto err_cure;
} }
cr_imgset = cr_task_imgset_open(item->pid.virt, O_DUMP); cr_imgset = cr_task_imgset_open(item->pid->ns[0].virt, O_DUMP);
if (!cr_imgset) if (!cr_imgset)
goto err_cure; goto err_cure;
...@@ -1449,9 +1450,9 @@ static int cr_pre_dump_finish(int ret) ...@@ -1449,9 +1450,9 @@ static int cr_pre_dump_finish(int ret)
if (!ctl) if (!ctl)
continue; continue;
pr_info("\tPre-dumping %d\n", item->pid.virt); pr_info("\tPre-dumping %d\n", item->pid->ns[0].virt);
timing_start(TIME_MEMWRITE); timing_start(TIME_MEMWRITE);
ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid.virt); ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid->ns[0].virt);
if (ret < 0) if (ret < 0)
goto err; goto err;
...@@ -1500,7 +1501,7 @@ int cr_pre_dump_tasks(pid_t pid) ...@@ -1500,7 +1501,7 @@ int cr_pre_dump_tasks(pid_t pid)
root_item = alloc_pstree_item(); root_item = alloc_pstree_item();
if (!root_item) if (!root_item)
goto err; goto err;
root_item->pid.real = pid; root_item->pid->real = pid;
if (!opts.track_mem) { if (!opts.track_mem) {
pr_info("Enforcing memory tracking for pre-dump.\n"); pr_info("Enforcing memory tracking for pre-dump.\n");
...@@ -1655,7 +1656,7 @@ int cr_dump_tasks(pid_t pid) ...@@ -1655,7 +1656,7 @@ int cr_dump_tasks(pid_t pid)
root_item = alloc_pstree_item(); root_item = alloc_pstree_item();
if (!root_item) if (!root_item)
goto err; goto err;
root_item->pid.real = pid; root_item->pid->real = pid;
pre_dump_ret = run_scripts(ACT_PRE_DUMP); pre_dump_ret = run_scripts(ACT_PRE_DUMP);
if (pre_dump_ret != 0) { if (pre_dump_ret != 0) {
......
This diff is collapsed.
...@@ -195,7 +195,7 @@ int send_criu_rpc_script(enum script_actions act, char *name, int fd) ...@@ -195,7 +195,7 @@ int send_criu_rpc_script(enum script_actions act, char *name, int fd)
* checking this. * checking this.
*/ */
cn.has_pid = true; cn.has_pid = true;
cn.pid = root_item->pid.real; cn.pid = root_item->pid->real;
break; break;
default: default:
break; break;
...@@ -568,7 +568,7 @@ static int restore_using_req(int sk, CriuOpts *req) ...@@ -568,7 +568,7 @@ static int restore_using_req(int sk, CriuOpts *req)
success = true; success = true;
exit: exit:
if (send_criu_restore_resp(sk, success, if (send_criu_restore_resp(sk, success,
root_item ? root_item->pid.real : -1) == -1) { root_item ? root_item->pid->real : -1) == -1) {
pr_perror("Can't send response"); pr_perror("Can't send response");
success = false; success = false;
} }
......
...@@ -318,11 +318,11 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p) ...@@ -318,11 +318,11 @@ int note_file_lock(struct pid *pid, int fd, int lfd, struct fd_parms *p)
continue; continue;
} }
fl->real_owner = pid->virt; fl->real_owner = pid->ns[0].virt;
fl->owners_fd = fd; fl->owners_fd = fd;
pr_info("Found lock entry %d.%d %d vs %d\n", pr_info("Found lock entry %d.%d %d vs %d\n",
pid->real, pid->virt, fd, pid->real, pid->ns[0].virt, fd,
fl->fl_owner); fl->fl_owner);
} }
......
...@@ -383,7 +383,7 @@ static int open_remap_dead_process(struct reg_file_info *rfi, ...@@ -383,7 +383,7 @@ static int open_remap_dead_process(struct reg_file_info *rfi,
if (!helper) if (!helper)
return -1; return -1;
if (helper->pid.state != TASK_UNDEF) { if (helper->pid->state != TASK_UNDEF) {
pr_info("Skipping helper for restoring /proc/%d; pid exists\n", rfe->remap_id); pr_info("Skipping helper for restoring /proc/%d; pid exists\n", rfe->remap_id);
return 0; return 0;
} }
...@@ -392,11 +392,11 @@ static int open_remap_dead_process(struct reg_file_info *rfi, ...@@ -392,11 +392,11 @@ static int open_remap_dead_process(struct reg_file_info *rfi,
helper->sid = root_item->sid; helper->sid = root_item->sid;
helper->pgid = root_item->pgid; helper->pgid = root_item->pgid;
helper->pid.virt = rfe->remap_id; helper->pid->ns[0].virt = rfe->remap_id;
helper->parent = root_item; helper->parent = root_item;
list_add_tail(&helper->sibling, &root_item->children); list_add_tail(&helper->sibling, &root_item->children);
pr_info("Added a helper for restoring /proc/%d\n", helper->pid.virt); pr_info("Added a helper for restoring /proc/%d\n", helper->pid->ns[0].virt);
return 0; return 0;
} }
...@@ -822,14 +822,14 @@ int dead_pid_conflict(void) ...@@ -822,14 +822,14 @@ int dead_pid_conflict(void)
* If the dead PID was given to a main thread of another * If the dead PID was given to a main thread of another
* process, this is handled during restore. * process, this is handled during restore.
*/ */
item = container_of(node, struct pstree_item, pid); item = node->item;
if (item->pid.real == item->threads[i].real || if (item->pid->real == item->threads[i].real ||
item->threads[i].virt != pid) item->threads[i].ns[0].virt != pid)
continue; continue;
} }
pr_err("Conflict with a dead task with the same PID as of this thread (virt %d, real %d).\n", pr_err("Conflict with a dead task with the same PID as of this thread (virt %d, real %d).\n",
node->virt, node->real); node->ns[0].virt, node->real);
return -1; return -1;
} }
......
...@@ -322,7 +322,7 @@ static int fill_fd_params(struct pid *owner_pid, int fd, int lfd, ...@@ -322,7 +322,7 @@ static int fill_fd_params(struct pid *owner_pid, int fd, int lfd,
{ {
int ret; int ret;
struct statfs fsbuf; struct statfs fsbuf;
struct fdinfo_common fdinfo = { .mnt_id = -1, .owner = owner_pid->virt }; struct fdinfo_common fdinfo = { .mnt_id = -1, .owner = owner_pid->ns[0].virt };
if (fstat(lfd, &p->stat) < 0) { if (fstat(lfd, &p->stat) < 0) {
pr_perror("Can't stat fd %d", lfd); pr_perror("Can't stat fd %d", lfd);
...@@ -529,7 +529,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, ...@@ -529,7 +529,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
int off, nr_fds = min((int) PARASITE_MAX_FDS, dfds->nr_fds); int off, nr_fds = min((int) PARASITE_MAX_FDS, dfds->nr_fds);
pr_info("\n"); pr_info("\n");
pr_info("Dumping opened files (pid: %d)\n", item->pid.real); pr_info("Dumping opened files (pid: %d)\n", item->pid->real);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
lfds = xmalloc(nr_fds * sizeof(int)); lfds = xmalloc(nr_fds * sizeof(int));
...@@ -555,7 +555,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, ...@@ -555,7 +555,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
goto err; goto err;
for (i = 0; i < nr_fds; i++) { for (i = 0; i < nr_fds; i++) {
ret = dump_one_file(&item->pid, dfds->fds[i + off], ret = dump_one_file(item->pid, dfds->fds[i + off],
lfds[i], opts + i, img, ctl); lfds[i], opts + i, img, ctl);
close(lfds[i]); close(lfds[i]);
if (ret) if (ret)
...@@ -747,7 +747,7 @@ int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple, ...@@ -747,7 +747,7 @@ int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
if (!e) if (!e)
return -1; return -1;
return collect_fd(task->pid.virt, e, rsti(task)); return collect_fd(task->pid->ns[0].virt, e, rsti(task));
} }
int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id) int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id)
...@@ -781,7 +781,7 @@ int prepare_fd_pid(struct pstree_item *item) ...@@ -781,7 +781,7 @@ int prepare_fd_pid(struct pstree_item *item)
{ {
int ret = 0; int ret = 0;
struct cr_img *img; struct cr_img *img;
pid_t pid = item->pid.virt; pid_t pid = item->pid->ns[0].virt;
struct rst_info *rst_info = rsti(item); struct rst_info *rst_info = rsti(item);
INIT_LIST_HEAD(&rst_info->used); INIT_LIST_HEAD(&rst_info->used);
...@@ -793,7 +793,7 @@ int prepare_fd_pid(struct pstree_item *item) ...@@ -793,7 +793,7 @@ int prepare_fd_pid(struct pstree_item *item)
if (item->ids == NULL) /* zombie */ if (item->ids == NULL) /* zombie */
return 0; return 0;
if (rsti(item)->fdt && rsti(item)->fdt->pid != item->pid.virt) if (rsti(item)->fdt && rsti(item)->fdt->pid != item->pid->ns[0].virt)
return 0; return 0;
img = open_image(CR_FD_FDINFO, O_RSTR, item->ids->files_id); img = open_image(CR_FD_FDINFO, O_RSTR, item->ids->files_id);
...@@ -1176,7 +1176,7 @@ int prepare_fds(struct pstree_item *me) ...@@ -1176,7 +1176,7 @@ int prepare_fds(struct pstree_item *me)
futex_inc_and_wake(&fdt->fdt_lock); futex_inc_and_wake(&fdt->fdt_lock);
futex_wait_while_lt(&fdt->fdt_lock, fdt->nr); futex_wait_while_lt(&fdt->fdt_lock, fdt->nr);
if (fdt->pid != me->pid.virt) { if (fdt->pid != me->pid->ns[0].virt) {
pr_info("File descriptor table is shared with %d\n", fdt->pid); pr_info("File descriptor table is shared with %d\n", fdt->pid);
futex_wait_until(&fdt->fdt_lock, fdt->nr + 1); futex_wait_until(&fdt->fdt_lock, fdt->nr + 1);
goto out; goto out;
...@@ -1189,7 +1189,7 @@ int prepare_fds(struct pstree_item *me) ...@@ -1189,7 +1189,7 @@ int prepare_fds(struct pstree_item *me)
continue; continue;
} }
ret = open_fdinfos(me->pid.virt, &rsti(me)->fds, state); ret = open_fdinfos(me->pid->ns[0].virt, &rsti(me)->fds, state);
if (ret) if (ret)
break; break;
...@@ -1197,7 +1197,7 @@ int prepare_fds(struct pstree_item *me) ...@@ -1197,7 +1197,7 @@ int prepare_fds(struct pstree_item *me)
* Now handle TTYs. Slaves are delayed to be sure masters * Now handle TTYs. Slaves are delayed to be sure masters
* are already opened. * are already opened.
*/ */
ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_slaves, state); ret = open_fdinfos(me->pid->ns[0].virt, &rsti(me)->tty_slaves, state);
if (ret) if (ret)
break; break;
...@@ -1206,7 +1206,7 @@ int prepare_fds(struct pstree_item *me) ...@@ -1206,7 +1206,7 @@ int prepare_fds(struct pstree_item *me)
* to be already restored, thus we store them in a separate * to be already restored, thus we store them in a separate
* list and restore at the very end. * list and restore at the very end.
*/ */
ret = open_fdinfos(me->pid.virt, &rsti(me)->eventpoll, state); ret = open_fdinfos(me->pid->ns[0].virt, &rsti(me)->eventpoll, state);
if (ret) if (ret)
break; break;
} }
...@@ -1224,7 +1224,7 @@ int prepare_fds(struct pstree_item *me) ...@@ -1224,7 +1224,7 @@ int prepare_fds(struct pstree_item *me)
* Opening current TTYs require session to be already set up, * Opening current TTYs require session to be already set up,
* thus slave peers already handled now it's time for cttys, * thus slave peers already handled now it's time for cttys,
*/ */
ret = open_fdinfos(me->pid.virt, &rsti(me)->tty_ctty, state); ret = open_fdinfos(me->pid->ns[0].virt, &rsti(me)->tty_ctty, state);
if (ret) if (ret)
break; break;
} }
...@@ -1310,7 +1310,7 @@ out: ...@@ -1310,7 +1310,7 @@ out:
int prepare_fs_pid(struct pstree_item *item) int prepare_fs_pid(struct pstree_item *item)
{ {
pid_t pid = item->pid.virt; pid_t pid = item->pid->ns[0].virt;
struct rst_info *ri = rsti(item); struct rst_info *ri = rsti(item);
struct cr_img *img; struct cr_img *img;
FsEntry *fe; FsEntry *fe;
...@@ -1361,15 +1361,15 @@ int shared_fdt_prepare(struct pstree_item *item) ...@@ -1361,15 +1361,15 @@ int shared_fdt_prepare(struct pstree_item *item)
futex_init(&fdt->fdt_lock); futex_init(&fdt->fdt_lock);
fdt->nr = 1; fdt->nr = 1;
fdt->pid = parent->pid.virt; fdt->pid = parent->pid->ns[0].virt;
} else } else
fdt = rsti(parent)->fdt; fdt = rsti(parent)->fdt;
rsti(item)->fdt = fdt; rsti(item)->fdt = fdt;
rsti(item)->service_fd_id = fdt->nr; rsti(item)->service_fd_id = fdt->nr;
fdt->nr++; fdt->nr++;
if (pid_rst_prio(item->pid.virt, fdt->pid)) if (pid_rst_prio(item->pid->ns[0].virt, fdt->pid))
fdt->pid = item->pid.virt; fdt->pid = item->pid->ns[0].virt;
return 0; return 0;
} }
...@@ -1667,7 +1667,7 @@ int inherit_fd_fini() ...@@ -1667,7 +1667,7 @@ int inherit_fd_fini()
int open_transport_socket(void) int open_transport_socket(void)
{ {
struct fdt *fdt = rsti(current)->fdt; struct fdt *fdt = rsti(current)->fdt;
pid_t pid = current->pid.virt; pid_t pid = current->pid->ns[0].virt;
struct sockaddr_un saddr; struct sockaddr_un saddr;
int sock, slen; int sock, slen;
......
...@@ -407,7 +407,7 @@ static int tmpfs_dump(struct mount_info *pm) ...@@ -407,7 +407,7 @@ static int tmpfs_dump(struct mount_info *pm)
sprintf(tmpfs_path, "/proc/self/fd/%d", fd); sprintf(tmpfs_path, "/proc/self/fd/%d", fd);
if (root_ns_mask & CLONE_NEWUSER) if (root_ns_mask & CLONE_NEWUSER)
userns_pid = root_item->pid.real; userns_pid = root_item->pid->real;
ret = cr_system_userns(-1, img_raw_fd(img), -1, "tar", (char *[]) ret = cr_system_userns(-1, img_raw_fd(img), -1, "tar", (char *[])
{ "tar", "--create", { "tar", "--create",
......
...@@ -107,10 +107,11 @@ int write_img_inventory(InventoryEntry *he) ...@@ -107,10 +107,11 @@ int write_img_inventory(InventoryEntry *he)
int prepare_inventory(InventoryEntry *he) int prepare_inventory(InventoryEntry *he)
{ {
struct pid pid;
struct { struct {
struct pstree_item i; struct pstree_item i;
struct dmp_info d; struct dmp_info d;
} crt = { }; } crt = { .i.pid = &pid };
pr_info("Perparing image inventory (version %u)\n", CRTOOLS_IMAGES_V1); pr_info("Perparing image inventory (version %u)\n", CRTOOLS_IMAGES_V1);
...@@ -122,8 +123,8 @@ int prepare_inventory(InventoryEntry *he) ...@@ -122,8 +123,8 @@ int prepare_inventory(InventoryEntry *he)
he->has_lsmtype = true; he->has_lsmtype = true;
he->lsmtype = host_lsm_type(); he->lsmtype = host_lsm_type();
crt.i.pid.state = TASK_ALIVE; crt.i.pid->state = TASK_ALIVE;
crt.i.pid.real = getpid(); crt.i.pid->real = getpid();
if (get_task_ids(&crt.i)) if (get_task_ids(&crt.i))
return -1; return -1;
......
...@@ -13,16 +13,17 @@ struct pid { ...@@ -13,16 +13,17 @@ struct pid {
*/ */
pid_t real; pid_t real;
int state; /* TASK_XXX constants */
/* /*
* The @virt pid is one which used in the image itself and keeps * The @virt pid is one which used in the image itself and keeps
* the pid value to be restored. This pid fetched from the * the pid value to be restored. This pid fetched from the
* dumpee context, because the dumpee might have own pid namespace. * dumpee context, because the dumpee might have own pid namespace.
*/ */
pid_t virt; struct {
pid_t virt;
int state; /* TASK_XXX constants */ struct rb_node node;
} ns[1]; /* Must be at the end of struct pid */
struct rb_node node;
}; };
#define TASK_UNDEF 0x0 #define TASK_UNDEF 0x0
......
...@@ -15,7 +15,7 @@ struct pstree_item { ...@@ -15,7 +15,7 @@ struct pstree_item {
struct list_head children; /* list of my children */ struct list_head children; /* list of my children */
struct list_head sibling; /* linkage in my parent's children list */ struct list_head sibling; /* linkage in my parent's children list */
struct pid pid; struct pid *pid;
pid_t pgid; pid_t pgid;
pid_t sid; pid_t sid;
pid_t born_sid; pid_t born_sid;
...@@ -66,7 +66,7 @@ static inline bool is_alive_state(int state) ...@@ -66,7 +66,7 @@ static inline bool is_alive_state(int state)
static inline bool task_alive(struct pstree_item *i) static inline bool task_alive(struct pstree_item *i)
{ {
return is_alive_state(i->pid.state); return is_alive_state(i->pid->state);
} }
extern void free_pstree(struct pstree_item *root_item); extern void free_pstree(struct pstree_item *root_item);
......
...@@ -237,7 +237,7 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino) ...@@ -237,7 +237,7 @@ char *irmap_lookup(unsigned int s_dev, unsigned long i_ino)
* irmap_predump_prep, so we just go ahead and scan. * irmap_predump_prep, so we just go ahead and scan.
*/ */
if (!doing_predump && if (!doing_predump &&
__mntns_get_root_fd(root_item->pid.real) < 0) __mntns_get_root_fd(root_item->pid->real) < 0)
goto out; goto out;
timing_start(TIME_IRMAP_RESOLVE); timing_start(TIME_IRMAP_RESOLVE);
...@@ -333,7 +333,7 @@ int irmap_predump_prep(void) ...@@ -333,7 +333,7 @@ int irmap_predump_prep(void)
*/ */
doing_predump = true; doing_predump = true;
return __mntns_get_root_fd(root_item->pid.real) < 0 ? -1 : 0; return __mntns_get_root_fd(root_item->pid->real) < 0 ? -1 : 0;
} }
int irmap_predump_run(void) int irmap_predump_run(void)
......
...@@ -278,7 +278,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, ...@@ -278,7 +278,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
unsigned long pmc_size; unsigned long pmc_size;
pr_info("\n"); pr_info("\n");
pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, item->pid.real); pr_info("Dumping pages (type: %d pid: %d)\n", CR_FD_PAGES, item->pid->real);
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
timing_start(TIME_MEMDUMP); timing_start(TIME_MEMDUMP);
...@@ -292,7 +292,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, ...@@ -292,7 +292,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
pmc_size = max(vma_area_list->priv_longest, pmc_size = max(vma_area_list->priv_longest,
vma_area_list->shared_longest); vma_area_list->shared_longest);
if (pmc_init(&pmc, item->pid.real, &vma_area_list->h, if (pmc_init(&pmc, item->pid->real, &vma_area_list->h,
pmc_size * PAGE_SIZE)) pmc_size * PAGE_SIZE))
return -1; return -1;
...@@ -315,11 +315,11 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, ...@@ -315,11 +315,11 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
* right here. For pre-dumps the pp will be taken by the * right here. For pre-dumps the pp will be taken by the
* caller and handled later. * caller and handled later.
*/ */
ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid.virt); ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid->ns[0].virt);
if (ret < 0) if (ret < 0)
goto out_pp; goto out_pp;
} else { } else {
ret = check_parent_page_xfer(CR_FD_PAGEMAP, item->pid.virt); ret = check_parent_page_xfer(CR_FD_PAGEMAP, item->pid->ns[0].virt);
if (ret < 0) if (ret < 0)
goto out_pp; goto out_pp;
...@@ -349,7 +349,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item, ...@@ -349,7 +349,7 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
if (!map) if (!map)
goto out_xfer; goto out_xfer;
if (vma_area_is(vma_area, VMA_ANON_SHARED)) if (vma_area_is(vma_area, VMA_ANON_SHARED))
ret = add_shmem_area(item->pid.real, vma_area->e, map); ret = add_shmem_area(item->pid->real, vma_area->e, map);
else { else {
again: again:
ret = generate_iovs(vma_area, pp, map, &off, ret = generate_iovs(vma_area, pp, map, &off,
...@@ -382,7 +382,7 @@ again: ...@@ -382,7 +382,7 @@ again:
* Step 4 -- clean up * Step 4 -- clean up
*/ */
ret = task_reset_dirty_track(item->pid.real); ret = task_reset_dirty_track(item->pid->real);
out_xfer: out_xfer:
if (!mdc->pre_dump) if (!mdc->pre_dump)
xfer.close(&xfer); xfer.close(&xfer);
...@@ -445,7 +445,7 @@ int parasite_dump_pages_seized(struct pstree_item *item, ...@@ -445,7 +445,7 @@ int parasite_dump_pages_seized(struct pstree_item *item,
int prepare_mm_pid(struct pstree_item *i) int prepare_mm_pid(struct pstree_item *i)
{ {
pid_t pid = i->pid.virt; pid_t pid = i->pid->ns[0].virt;
int ret = -1, vn = 0; int ret = -1, vn = 0;
struct cr_img *img; struct cr_img *img;
struct rst_info *ri = rsti(i); struct rst_info *ri = rsti(i);
...@@ -531,7 +531,7 @@ static int map_private_vma(struct pstree_item *t, ...@@ -531,7 +531,7 @@ static int map_private_vma(struct pstree_item *t,
struct vma_area *p = *pvma; struct vma_area *p = *pvma;
if (vma_area_is(vma, VMA_FILE_PRIVATE)) { if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
ret = vma->vm_open(t->pid.virt, vma); ret = vma->vm_open(t->pid->ns[0].virt, vma);
if (ret < 0) { if (ret < 0) {
pr_err("Can't fixup VMA's fd\n"); pr_err("Can't fixup VMA's fd\n");
return -1; return -1;
...@@ -695,7 +695,7 @@ static int restore_priv_vma_content(struct pstree_item *t) ...@@ -695,7 +695,7 @@ static int restore_priv_vma_content(struct pstree_item *t)
vma = list_first_entry(vmas, struct vma_area, list); vma = list_first_entry(vmas, struct vma_area, list);
ret = open_page_read(t->pid.virt, &pr, PR_TASK); ret = open_page_read(t->pid->ns[0].virt, &pr, PR_TASK);
if (ret <= 0) if (ret <= 0)
return -1; return -1;
...@@ -913,7 +913,7 @@ int unmap_guard_pages(struct pstree_item *t) ...@@ -913,7 +913,7 @@ int unmap_guard_pages(struct pstree_item *t)
int open_vmas(struct pstree_item *t) int open_vmas(struct pstree_item *t)
{ {
int pid = t->pid.virt; int pid = t->pid->ns[0].virt;
struct vma_area *vma; struct vma_area *vma;
struct vm_area_list *vmas = &rsti(t)->vmas; struct vm_area_list *vmas = &rsti(t)->vmas;
......
...@@ -150,9 +150,9 @@ static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpat ...@@ -150,9 +150,9 @@ static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpat
* to make sure we stat the correct file * to make sure we stat the correct file
*/ */
if (mntns_root == -1) { if (mntns_root == -1) {
mntns_root = __mntns_get_root_fd(root_item->pid.real); mntns_root = __mntns_get_root_fd(root_item->pid->real);
if (mntns_root < 0) { if (mntns_root < 0) {
pr_err("Unable to get the root file descriptor of pid %d\n", root_item->pid.real); pr_err("Unable to get the root file descriptor of pid %d\n", root_item->pid->real);
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
} }
...@@ -2679,7 +2679,7 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren ...@@ -2679,7 +2679,7 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren
{ {
int fd; int fd;
fd = open_proc(root_item->pid.virt, "fd/%d", nsid->mnt.ns_fd); fd = open_proc(root_item->pid->ns[0].virt, "fd/%d", nsid->mnt.ns_fd);
if (fd < 0) if (fd < 0)
return -1; return -1;
...@@ -3196,7 +3196,7 @@ int mntns_get_root_fd(struct ns_id *mntns) ...@@ -3196,7 +3196,7 @@ int mntns_get_root_fd(struct ns_id *mntns)
if (!mntns->ns_populated) { if (!mntns->ns_populated) {
int fd; int fd;
fd = open_proc(root_item->pid.virt, "fd/%d", mntns->mnt.root_fd); fd = open_proc(root_item->pid->ns[0].virt, "fd/%d", mntns->mnt.root_fd);
if (fd < 0) if (fd < 0)
return -1; return -1;
......
...@@ -309,7 +309,7 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, ...@@ -309,7 +309,7 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid,
int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd) int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
{ {
pid_t pid = i->pid.virt; pid_t pid = i->pid->ns[0].virt;
struct ns_id *nsid; struct ns_id *nsid;
nsid = lookup_ns_by_id(id, nd); nsid = lookup_ns_by_id(id, nd);
...@@ -401,7 +401,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd ...@@ -401,7 +401,7 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
if (pid != getpid()) { if (pid != getpid()) {
type = NS_OTHER; type = NS_OTHER;
if (pid == root_item->pid.real) { if (pid == root_item->pid->real) {
BUG_ON(root_ns_mask & nd->cflag); BUG_ON(root_ns_mask & nd->cflag);
pr_info("Will take %s namespace in the image\n", nd->str); pr_info("Will take %s namespace in the image\n", nd->str);
root_ns_mask |= nd->cflag; root_ns_mask |= nd->cflag;
...@@ -549,7 +549,7 @@ static int open_ns_fd(struct file_desc *d) ...@@ -549,7 +549,7 @@ static int open_ns_fd(struct file_desc *d)
return -1; return -1;
} }
snprintf(path, sizeof(path) - 1, "/proc/%d/ns/%s", item->pid.virt, nd->str); snprintf(path, sizeof(path) - 1, "/proc/%d/ns/%s", item->pid->ns[0].virt, nd->str);
path[sizeof(path) - 1] = '\0'; path[sizeof(path) - 1] = '\0';
fd = open(path, nfi->nfe->flags); fd = open(path, nfi->nfe->flags);
...@@ -593,7 +593,7 @@ struct collect_image_info nsfile_cinfo = { ...@@ -593,7 +593,7 @@ struct collect_image_info nsfile_cinfo = {
int predump_task_ns_ids(struct pstree_item *item) int predump_task_ns_ids(struct pstree_item *item)
{ {
int pid = item->pid.real; int pid = item->pid->real;
if (!__get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns)) if (!__get_ns_id(pid, &net_ns_desc, NULL, &dmpi(item)->netns))
return -1; return -1;
...@@ -606,7 +606,7 @@ int predump_task_ns_ids(struct pstree_item *item) ...@@ -606,7 +606,7 @@ int predump_task_ns_ids(struct pstree_item *item)
int dump_task_ns_ids(struct pstree_item *item) int dump_task_ns_ids(struct pstree_item *item)
{ {
int pid = item->pid.real; int pid = item->pid->real;
TaskKobjIdsEntry *ids = item->ids; TaskKobjIdsEntry *ids = item->ids;
ids->has_pid_ns_id = true; ids->has_pid_ns_id = true;
...@@ -790,7 +790,7 @@ int collect_user_ns(struct ns_id *ns, void *oarg) ...@@ -790,7 +790,7 @@ int collect_user_ns(struct ns_id *ns, void *oarg)
* mappings, which are used for convirting local id-s to * mappings, which are used for convirting local id-s to
* userns id-s (userns_uid(), userns_gid()) * userns id-s (userns_uid(), userns_gid())
*/ */
if (dump_user_ns(root_item->pid.real, root_item->ids->user_ns_id)) if (dump_user_ns(root_item->pid->real, root_item->ids->user_ns_id))
return -1; return -1;
return 0; return 0;
...@@ -994,7 +994,7 @@ static int do_dump_namespaces(struct ns_id *ns) ...@@ -994,7 +994,7 @@ static int do_dump_namespaces(struct ns_id *ns)
int dump_namespaces(struct pstree_item *item, unsigned int ns_flags) int dump_namespaces(struct pstree_item *item, unsigned int ns_flags)
{ {
struct pid *ns_pid = &item->pid; struct pid *ns_pid = item->pid;
struct ns_id *ns; struct ns_id *ns;
int pid, nr = 0; int pid, nr = 0;
int ret = 0; int ret = 0;
...@@ -1010,9 +1010,9 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags) ...@@ -1010,9 +1010,9 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags)
* net namespace with this is still open * net namespace with this is still open
*/ */
pr_info("Dumping %d(%d)'s namespaces\n", ns_pid->virt, ns_pid->real); pr_info("Dumping %d(%d)'s namespaces\n", ns_pid->ns[0].virt, ns_pid->real);
if ((ns_flags & CLONE_NEWPID) && ns_pid->virt != 1) { if ((ns_flags & CLONE_NEWPID) && ns_pid->ns[0].virt != 1) {
pr_err("Can't dump a pid namespace without the process init\n"); pr_err("Can't dump a pid namespace without the process init\n");
return -1; return -1;
} }
...@@ -1472,10 +1472,10 @@ int prepare_userns(struct pstree_item *item) ...@@ -1472,10 +1472,10 @@ int prepare_userns(struct pstree_item *item)
if (ret < 0) if (ret < 0)
return -1; return -1;
if (write_id_map(item->pid.real, e->uid_map, e->n_uid_map, "uid_map")) if (write_id_map(item->pid->real, e->uid_map, e->n_uid_map, "uid_map"))
return -1; return -1;
if (write_id_map(item->pid.real, e->gid_map, e->n_gid_map, "gid_map")) if (write_id_map(item->pid->real, e->gid_map, e->n_gid_map, "gid_map"))
return -1; return -1;
return 0; return 0;
...@@ -1644,11 +1644,11 @@ err_out: ...@@ -1644,11 +1644,11 @@ err_out:
int prepare_namespace(struct pstree_item *item, unsigned long clone_flags) int prepare_namespace(struct pstree_item *item, unsigned long clone_flags)
{ {
pid_t pid = item->pid.virt; pid_t pid = item->pid->ns[0].virt;
int id; int id;
pr_info("Restoring namespaces %d flags 0x%lx\n", pr_info("Restoring namespaces %d flags 0x%lx\n",
item->pid.virt, clone_flags); item->pid->ns[0].virt, clone_flags);
if ((clone_flags & CLONE_NEWUSER) && prepare_userns_creds()) if ((clone_flags & CLONE_NEWUSER) && prepare_userns_creds())
return -1; return -1;
......
...@@ -1774,7 +1774,7 @@ int network_lock_internal() ...@@ -1774,7 +1774,7 @@ int network_lock_internal()
"COMMIT\n"; "COMMIT\n";
int ret = 0, nsret; int ret = 0, nsret;
if (switch_ns(root_item->pid.real, &net_ns_desc, &nsret)) if (switch_ns(root_item->pid->real, &net_ns_desc, &nsret))
return -1; return -1;
...@@ -1798,7 +1798,7 @@ static int network_unlock_internal() ...@@ -1798,7 +1798,7 @@ static int network_unlock_internal()
"COMMIT\n"; "COMMIT\n";
int ret = 0, nsret; int ret = 0, nsret;
if (switch_ns(root_item->pid.real, &net_ns_desc, &nsret)) if (switch_ns(root_item->pid->real, &net_ns_desc, &nsret))
return -1; return -1;
......
...@@ -652,7 +652,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id, ...@@ -652,7 +652,7 @@ int parasite_dump_thread_seized(struct parasite_ctl *ctl, int id,
return -1; return -1;
} }
tid->virt = args->tid; tid->ns[0].virt = args->tid;
return dump_thread_core(pid, core, args); return dump_thread_core(pid, core, args);
} }
......
...@@ -2220,7 +2220,7 @@ int parse_threads(int pid, struct pid **_t, int *_n) ...@@ -2220,7 +2220,7 @@ int parse_threads(int pid, struct pid **_t, int *_n)
return -1; return -1;
} }
t = tmp; t = tmp;
t[nr - 1].virt = -1; t[nr - 1].ns[0].virt = -1;
} }
t[nr - 1].real = atoi(de->d_name); t[nr - 1].real = atoi(de->d_name);
t[nr - 1].state = TASK_THREAD; t[nr - 1].state = TASK_THREAD;
......
This diff is collapsed.
...@@ -49,7 +49,7 @@ static int collect_filter_for_pstree(struct pstree_item *item) ...@@ -49,7 +49,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
struct sock_filter buf[BPF_MAXINSNS]; struct sock_filter buf[BPF_MAXINSNS];
void *m; void *m;
if (item->pid.state == TASK_DEAD || if (item->pid->state == TASK_DEAD ||
dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER) dmpi(item)->pi_creds->seccomp_mode != SECCOMP_MODE_FILTER)
return 0; return 0;
...@@ -57,7 +57,7 @@ static int collect_filter_for_pstree(struct pstree_item *item) ...@@ -57,7 +57,7 @@ static int collect_filter_for_pstree(struct pstree_item *item)
int len; int len;
struct seccomp_info *info, *inherited = NULL; struct seccomp_info *info, *inherited = NULL;
len = ptrace(PTRACE_SECCOMP_GET_FILTER, item->pid.real, i, buf); len = ptrace(PTRACE_SECCOMP_GET_FILTER, item->pid->real, i, buf);
if (len < 0) { if (len < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
/* end of the search */ /* end of the search */
......
...@@ -437,7 +437,7 @@ static inline bool child_collected(struct pstree_item *i, pid_t pid) ...@@ -437,7 +437,7 @@ static inline bool child_collected(struct pstree_item *i, pid_t pid)
struct pstree_item *c; struct pstree_item *c;
list_for_each_entry(c, &i->children, sibling) list_for_each_entry(c, &i->children, sibling)
if (c->pid.real == pid) if (c->pid->real == pid)
return true; return true;
return false; return false;
...@@ -449,7 +449,7 @@ static int collect_children(struct pstree_item *item) ...@@ -449,7 +449,7 @@ static int collect_children(struct pstree_item *item)
pid_t *ch; pid_t *ch;
int ret, i, nr_children, nr_inprogress; int ret, i, nr_children, nr_inprogress;
ret = parse_children(item->pid.real, &ch, &nr_children); ret = parse_children(item->pid->real, &ch, &nr_children);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -488,7 +488,7 @@ static int collect_children(struct pstree_item *item) ...@@ -488,7 +488,7 @@ static int collect_children(struct pstree_item *item)
goto free; goto free;
} }
ret = seize_wait_task(pid, item->pid.real, creds); ret = seize_wait_task(pid, item->pid->real, creds);
if (ret < 0) { if (ret < 0) {
/* /*
* Here is a race window between parse_children() and seize(), * Here is a race window between parse_children() and seize(),
...@@ -509,9 +509,9 @@ static int collect_children(struct pstree_item *item) ...@@ -509,9 +509,9 @@ static int collect_children(struct pstree_item *item)
processes_to_wait--; processes_to_wait--;
dmpi(c)->pi_creds = creds; dmpi(c)->pi_creds = creds;
c->pid.real = pid; c->pid->real = pid;
c->parent = item; c->parent = item;
c->pid.state = ret; c->pid->state = ret;
list_add_tail(&c->sibling, &item->children); list_add_tail(&c->sibling, &item->children);
/* Here is a recursive call (Depth-first search) */ /* Here is a recursive call (Depth-first search) */
...@@ -528,7 +528,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st) ...@@ -528,7 +528,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st)
{ {
int i; int i;
if (item->pid.state == TASK_DEAD) if (item->pid->state == TASK_DEAD)
return; return;
/* /*
...@@ -536,7 +536,7 @@ static void unseize_task_and_threads(const struct pstree_item *item, int st) ...@@ -536,7 +536,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. * the item->state is the state task was in when we seized one.
*/ */
unseize_task(item->pid.real, item->pid.state, st); unseize_task(item->pid->real, item->pid->state, st);
if (st == TASK_DEAD) if (st == TASK_DEAD)
return; return;
...@@ -553,7 +553,7 @@ static void pstree_wait(struct pstree_item *root_item) ...@@ -553,7 +553,7 @@ static void pstree_wait(struct pstree_item *root_item)
for_each_pstree_item(item) { for_each_pstree_item(item) {
if (item->pid.state == TASK_DEAD) if (item->pid->state == TASK_DEAD)
continue; continue;
for (i = 0; i < item->nr_threads; i++) { for (i = 0; i < item->nr_threads; i++) {
...@@ -607,14 +607,14 @@ void pstree_switch_state(struct pstree_item *root_item, int st) ...@@ -607,14 +607,14 @@ void pstree_switch_state(struct pstree_item *root_item, int st)
static pid_t item_ppid(const struct pstree_item *item) static pid_t item_ppid(const struct pstree_item *item)
{ {
item = item->parent; item = item->parent;
return item ? item->pid.real : -1; return item ? item->pid->real : -1;
} }
static inline bool thread_collected(struct pstree_item *i, pid_t tid) static inline bool thread_collected(struct pstree_item *i, pid_t tid)
{ {
int t; int t;
if (i->pid.real == tid) /* thread leader is collected as task */ if (i->pid->real == tid) /* thread leader is collected as task */
return true; return true;
for (t = 0; t < i->nr_threads; t++) for (t = 0; t < i->nr_threads; t++)
...@@ -678,11 +678,11 @@ static int collect_threads(struct pstree_item *item) ...@@ -678,11 +678,11 @@ static int collect_threads(struct pstree_item *item)
struct pid *threads = NULL; struct pid *threads = NULL;
int nr_threads = 0, i = 0, ret, nr_inprogress, nr_stopped = 0; int nr_threads = 0, i = 0, ret, nr_inprogress, nr_stopped = 0;
ret = parse_threads(item->pid.real, &threads, &nr_threads); ret = parse_threads(item->pid->real, &threads, &nr_threads);
if (ret < 0) if (ret < 0)
goto err; goto err;
if ((item->pid.state == TASK_DEAD) && (nr_threads > 1)) { if ((item->pid->state == TASK_DEAD) && (nr_threads > 1)) {
pr_err("Zombies with threads are not supported\n"); pr_err("Zombies with threads are not supported\n");
goto err; goto err;
} }
...@@ -693,7 +693,7 @@ static int collect_threads(struct pstree_item *item) ...@@ -693,7 +693,7 @@ static int collect_threads(struct pstree_item *item)
return -1; return -1;
if (item->nr_threads == 0) { if (item->nr_threads == 0) {
item->threads[0].real = item->pid.real; item->threads[0].real = item->pid->real;
item->nr_threads = 1; item->nr_threads = 1;
item->threads[0].item = NULL; item->threads[0].item = NULL;
} }
...@@ -709,7 +709,7 @@ static int collect_threads(struct pstree_item *item) ...@@ -709,7 +709,7 @@ static int collect_threads(struct pstree_item *item)
nr_inprogress++; nr_inprogress++;
pr_info("\tSeizing %d's %d thread\n", pr_info("\tSeizing %d's %d thread\n",
item->pid.real, pid); item->pid->real, pid);
if (!opts.freeze_cgroup && seize_catch_task(pid)) if (!opts.freeze_cgroup && seize_catch_task(pid))
continue; continue;
...@@ -810,7 +810,7 @@ static int collect_task(struct pstree_item *item) ...@@ -810,7 +810,7 @@ static int collect_task(struct pstree_item *item)
if (ret < 0) if (ret < 0)
goto err_close; goto err_close;
if ((item->pid.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"); pr_err("Zombie with children?! O_o Run, run, run!\n");
goto err_close; goto err_close;
} }
...@@ -818,7 +818,7 @@ static int collect_task(struct pstree_item *item) ...@@ -818,7 +818,7 @@ static int collect_task(struct pstree_item *item)
if (pstree_alloc_cores(item)) if (pstree_alloc_cores(item))
goto err_close; goto err_close;
pr_info("Collected %d in %d state\n", item->pid.real, item->pid.state); pr_info("Collected %d in %d state\n", item->pid->real, item->pid->state);
return 0; return 0;
err_close: err_close:
...@@ -828,7 +828,7 @@ err_close: ...@@ -828,7 +828,7 @@ err_close:
int collect_pstree(void) int collect_pstree(void)
{ {
pid_t pid = root_item->pid.real; pid_t pid = root_item->pid->real;
int ret = -1; int ret = -1;
struct proc_status_creds *creds; struct proc_status_creds *creds;
...@@ -863,7 +863,7 @@ int collect_pstree(void) ...@@ -863,7 +863,7 @@ int collect_pstree(void)
processes_to_wait--; processes_to_wait--;
pr_info("Seized task %d, state %d\n", pid, ret); pr_info("Seized task %d, state %d\n", pid, ret);
root_item->pid.state = ret; root_item->pid->state = ret;
dmpi(root_item)->pi_creds = creds; dmpi(root_item)->pi_creds = creds;
ret = collect_task(root_item); ret = collect_task(root_item);
......
...@@ -1001,7 +1001,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) ...@@ -1001,7 +1001,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
* checkpoint complete process tree together with * checkpoint complete process tree together with
* the process which keeps the master peer. * the process which keeps the master peer.
*/ */
if (root_item->sid != root_item->pid.virt) { if (root_item->sid != root_item->pid->ns[0].virt) {
pr_debug("Restore inherited group %d\n", pr_debug("Restore inherited group %d\n",
getpgid(getppid())); getpgid(getppid()));
if (tty_set_prgp(fd, getpgid(getppid()))) if (tty_set_prgp(fd, getpgid(getppid())))
...@@ -1242,10 +1242,10 @@ static int tty_find_restoring_task(struct tty_info *info) ...@@ -1242,10 +1242,10 @@ static int tty_find_restoring_task(struct tty_info *info)
* for us. * for us.
*/ */
item = find_first_sid(info->tie->sid); item = find_first_sid(info->tie->sid);
if (item && item->pid.virt == item->sid) { if (item && item->pid->ns[0].virt == item->sid) {
pr_info("Set a control terminal %#x to %d\n", pr_info("Set a control terminal %#x to %d\n",
info->tfe->id, info->tie->sid); info->tfe->id, info->tie->sid);
return prepare_ctl_tty(item->pid.virt, return prepare_ctl_tty(item->pid->ns[0].virt,
rsti(item), rsti(item),
info->tfe->id); info->tfe->id);
} }
...@@ -1651,7 +1651,7 @@ int dump_verify_tty_sids(void) ...@@ -1651,7 +1651,7 @@ int dump_verify_tty_sids(void)
if (!ret && dinfo->sid) { if (!ret && dinfo->sid) {
struct pstree_item *item = find_first_sid(dinfo->sid); struct pstree_item *item = find_first_sid(dinfo->sid);
if (!item || item->pid.virt != dinfo->sid) { if (!item || item->pid->ns[0].virt != dinfo->sid) {
if (!opts.shell_job) { if (!opts.shell_job) {
pr_err("Found dangling tty with sid %d pgid %d (%s) on peer fd %d.\n", pr_err("Found dangling tty with sid %d pgid %d (%s) on peer fd %d.\n",
dinfo->sid, dinfo->pgrp, dinfo->sid, dinfo->pgrp,
......
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