[CRIU] [PATCH 1/2] pids: Introduce vpid() helper

Pavel Emelyanov xemul at virtuozzo.com
Fri Feb 10 03:28:57 PST 2017


This is to avoid long item->pid->ns[0].virt for vpid(item).

This is
1) for f in $(git grep -l 'ns\[0\]'); do
           sed -e 's/\([a-zA-Z0-9_]\+\)->pid->ns\[0\].virt/vpid(\1)/g' -i $f;
   done
2) adding of vpid() routine
3) some manual fixlets

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/autofs.c         | 12 ++++++------
 criu/cr-dump.c        | 30 +++++++++++++++---------------
 criu/cr-restore.c     | 48 ++++++++++++++++++++++++------------------------
 criu/files-reg.c      |  2 +-
 criu/files.c          | 20 ++++++++++----------
 criu/include/pstree.h |  5 +++++
 criu/mem.c            | 12 ++++++------
 criu/mount.c          |  4 ++--
 criu/namespaces.c     |  8 ++++----
 criu/page-xfer.c      |  4 ++--
 criu/pstree.c         | 40 ++++++++++++++++++++--------------------
 criu/tty.c            |  8 ++++----
 12 files changed, 99 insertions(+), 94 deletions(-)

diff --git a/criu/autofs.c b/criu/autofs.c
index 1875fe7..af1c595 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -579,12 +579,12 @@ static int autofs_dup_pipe(struct pstree_item *task,
 
 	if (dup_fle(task, ple, new_fd, flags) < 0) {
 		pr_err("Failed to add fd %d to process %d\n",
-				new_fd, task->pid->ns[0].virt);
+				new_fd, vpid(task));
 		return -1;
 	}
 
 	pr_info("autofs: added pipe fd %d, flags %#x to %d\n",
-			new_fd, flags, task->pid->ns[0].virt);
+			new_fd, flags, vpid(task));
 	return new_fd;
 }
 
@@ -851,12 +851,12 @@ static struct fdinfo_list_entry *autofs_pipe_le(struct pstree_item *master,
 	ple = find_fle_by_fd(&rsti(master)->used, pipe_fd);
 	if (!ple) {
 		pr_err("Failed to find pipe fd %d in process %d\n",
-				pipe_fd, master->pid->ns[0].virt);
+				pipe_fd, vpid(master));
 		return NULL;
 	}
 	if (ple->fe->type != FD_TYPES__PIPE) {
 		pr_err("Fd %d in process %d is not a pipe: %d\n", pipe_fd,
-				master->pid->ns[0].virt, ple->fe->type);
+				vpid(master), ple->fe->type);
 		return NULL;
 	}
 	return ple;
@@ -873,7 +873,7 @@ static int autofs_create_fle(struct pstree_item *task, FdinfoEntry *fe,
 		return -1;
 	le = (void *)ALIGN((long)le, sizeof(int));
 
-	fle_init(le, task->pid->ns[0].virt, fe);
+	fle_init(le, vpid(task), fe);
 
 	collect_task_fd(le, rst_info);
 
@@ -967,7 +967,7 @@ static int autofs_add_mount_info(void *data)
 		entry->fd = autofs_dup_pipe(master, ple, entry->fd);
 		if (entry->fd < 0) {
 			pr_err("Failed to find free fd in process %d\n",
-					master->pid->ns[0].virt);
+					vpid(master));
 			return -1;
 		}
 	}
diff --git a/criu/cr-dump.c b/criu/cr-dump.c
index 5fa8c27..022e7db 100644
--- a/criu/cr-dump.c
+++ b/criu/cr-dump.c
@@ -717,7 +717,7 @@ static int dump_task_core_all(struct parasite_ctl *ctl,
 
 	creds = dmpi(item)->pi_creds;
 	if (creds->s.seccomp_mode != SECCOMP_MODE_DISABLED) {
-		pr_info("got seccomp mode %d for %d\n", creds->s.seccomp_mode, item->pid->ns[0].virt);
+		pr_info("got seccomp mode %d for %d\n", creds->s.seccomp_mode, vpid(item));
 		core->tc->has_seccomp_mode = true;
 		core->tc->seccomp_mode = creds->s.seccomp_mode;
 
@@ -865,7 +865,7 @@ static int dump_one_zombie(const struct pstree_item *item,
 	core->tc->task_state = TASK_DEAD;
 	core->tc->exit_code = pps->exit_code;
 
-	img = open_image(CR_FD_CORE, O_DUMP, item->pid->ns[0].virt);
+	img = open_image(CR_FD_CORE, O_DUMP, vpid(item));
 	if (!img)
 		goto err;
 
@@ -990,7 +990,7 @@ static int dump_task_threads(struct parasite_ctl *parasite_ctl,
 	for (i = 0; i < item->nr_threads; i++) {
 		/* Leader is already dumped */
 		if (item->pid->real == item->threads[i].real) {
-			item->threads[i].ns[0].virt = item->pid->ns[0].virt;
+			item->threads[i].ns[0].virt = vpid(item);
 			continue;
 		}
 		if (dump_task_thread(parasite_ctl, item, i))
@@ -1020,17 +1020,17 @@ static int fill_zombies_pids(struct pstree_item *item)
 	 * Pids read here are virtual -- caller has set up
 	 * the proc of target pid namespace.
 	 */
-	if (parse_children(item->pid->ns[0].virt, &ch, &nr) < 0)
+	if (parse_children(vpid(item), &ch, &nr) < 0)
 		return -1;
 
 	/*
 	 * Step 1 -- filter our ch's pid of alive tasks
 	 */
 	list_for_each_entry(child, &item->children, sibling) {
-		if (child->pid->ns[0].virt < 0)
+		if (vpid(child) < 0)
 			continue;
 		for (i = 0; i < nr; i++) {
-			if (ch[i] == child->pid->ns[0].virt) {
+			if (ch[i] == vpid(child)) {
 				ch[i] = -1;
 				break;
 			}
@@ -1045,7 +1045,7 @@ static int fill_zombies_pids(struct pstree_item *item)
 	 */
 	i = 0;
 	list_for_each_entry(child, &item->children, sibling) {
-		if (child->pid->ns[0].virt > 0)
+		if (vpid(child) > 0)
 			continue;
 		for (; i < nr; i++) {
 			if (ch[i] < 0)
@@ -1081,7 +1081,7 @@ static int dump_zombies(void)
 		if (item->pid->state != TASK_DEAD)
 			continue;
 
-		if (item->pid->ns[0].virt < 0) {
+		if (vpid(item) < 0) {
 			if (!pidns)
 				item->pid->ns[0].virt = item->pid->real;
 			else if (root_item == item) {
@@ -1092,7 +1092,7 @@ static int dump_zombies(void)
 		}
 
 		pr_info("Obtaining zombie stat ... \n");
-		if (parse_pid_stat(item->pid->ns[0].virt, &pps_buf) < 0)
+		if (parse_pid_stat(vpid(item), &pps_buf) < 0)
 			goto err;
 
 		item->sid = pps_buf.sid;
@@ -1297,20 +1297,20 @@ static int dump_one_task(struct pstree_item *item)
 	}
 
 	item->pid->ns[0].virt = misc.pid;
-	pstree_insert_pid(item->pid->ns[0].virt, item->pid);
+	pstree_insert_pid(vpid(item), item->pid);
 	item->sid = misc.sid;
 	item->pgid = misc.pgid;
 
 	pr_info("sid=%d pgid=%d pid=%d\n",
-		item->sid, item->pgid, item->pid->ns[0].virt);
+		item->sid, item->pgid, vpid(item));
 
 	if (item->sid == 0) {
 		pr_err("A session leader of %d(%d) is outside of its pid namespace\n",
-			item->pid->real, item->pid->ns[0].virt);
+			item->pid->real, vpid(item));
 		goto err_cure;
 	}
 
-	cr_imgset = cr_task_imgset_open(item->pid->ns[0].virt, O_DUMP);
+	cr_imgset = cr_task_imgset_open(vpid(item), O_DUMP);
 	if (!cr_imgset)
 		goto err_cure;
 
@@ -1463,9 +1463,9 @@ static int cr_pre_dump_finish(int ret)
 		if (!ctl)
 			continue;
 
-		pr_info("\tPre-dumping %d\n", item->pid->ns[0].virt);
+		pr_info("\tPre-dumping %d\n", vpid(item));
 		timing_start(TIME_MEMWRITE);
-		ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid->ns[0].virt);
+		ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, vpid(item));
 		if (ret < 0)
 			goto err;
 
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 785d724..72cfce4 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -454,7 +454,7 @@ static int restore_one_sigaction(int sig, struct cr_img *img, int pid)
 
 static int prepare_sigactions(void)
 {
-	int pid = current->pid->ns[0].virt;
+	int pid = vpid(current);
 	struct cr_img *img;
 	int sig, rst = 0;
 	int ret = 0;
@@ -505,7 +505,7 @@ static int __collect_child_pids(struct pstree_item *p, int state, unsigned int *
 			return -1;
 
 		(*n)++;
-		*child = pi->pid->ns[0].virt;
+		*child = vpid(pi);
 	}
 
 	return 0;
@@ -777,7 +777,7 @@ static int wait_on_helpers_zombies(void)
 	struct pstree_item *pi;
 
 	list_for_each_entry(pi, &current->children, sibling) {
-		pid_t pid = pi->pid->ns[0].virt;
+		pid_t pid = vpid(pi);
 		int status;
 
 		switch (pi->pid->state) {
@@ -808,7 +808,7 @@ static int restore_one_zombie(CoreEntry *core)
 	if (inherit_fd_fini() < 0)
 		return -1;
 
-	if (lazy_pages_setup_zombie(current->pid->ns[0].virt))
+	if (lazy_pages_setup_zombie(vpid(current)))
 		return -1;
 
 	prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
@@ -831,7 +831,7 @@ static int restore_one_zombie(CoreEntry *core)
 			signr = SIGABRT;
 		}
 
-		if (kill(current->pid->ns[0].virt, signr) < 0)
+		if (kill(vpid(current), signr) < 0)
 			pr_perror("Can't kill myself, will just exit");
 
 		exit_code = 0;
@@ -962,7 +962,7 @@ static inline int fork_with_pid(struct pstree_item *item)
 {
 	struct cr_clone_arg ca;
 	int ret = -1;
-	pid_t pid = item->pid->ns[0].virt;
+	pid_t pid = vpid(item);
 
 	if (item->pid->state != TASK_HELPER) {
 		if (open_core(pid, &ca.core))
@@ -1051,7 +1051,7 @@ static inline int fork_with_pid(struct pstree_item *item)
 	if (item == root_item) {
 		item->pid->real = ret;
 		pr_debug("PID: real %d virt %d\n",
-				item->pid->real, item->pid->ns[0].virt);
+				item->pid->real, vpid(item));
 	}
 
 err_unlock:
@@ -1108,7 +1108,7 @@ static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
 
 		/* Exited (with zero code) helpers are OK */
 		list_for_each_entry(pi, &current->children, sibling)
-			if (pi->pid->ns[0].virt == siginfo->si_pid)
+			if (vpid(pi) == siginfo->si_pid)
 				break;
 
 		BUG_ON(&pi->sibling == &current->children);
@@ -1186,8 +1186,8 @@ static void restore_sid(void)
 	 * we can call setpgid() on custom values.
 	 */
 
-	if (current->pid->ns[0].virt == current->sid) {
-		pr_info("Restoring %d to %d sid\n", current->pid->ns[0].virt, current->sid);
+	if (vpid(current) == current->sid) {
+		pr_info("Restoring %d to %d sid\n", vpid(current), current->sid);
 		sid = setsid();
 		if (sid != current->sid) {
 			pr_perror("Can't restore sid (%d)", sid);
@@ -1197,7 +1197,7 @@ static void restore_sid(void)
 		sid = getsid(getpid());
 		if (sid != current->sid) {
 			/* Skip the root task if it's not init */
-			if (current == root_item && root_item->pid->ns[0].virt != INIT_PID)
+			if (current == root_item && vpid(root_item) != INIT_PID)
 				return;
 			pr_err("Requested sid %d doesn't match inherited %d\n",
 					current->sid, sid);
@@ -1220,13 +1220,13 @@ static void restore_pgid(void)
 
 	pid_t pgid, my_pgid = current->pgid;
 
-	pr_info("Restoring %d to %d pgid\n", current->pid->ns[0].virt, my_pgid);
+	pr_info("Restoring %d to %d pgid\n", vpid(current), my_pgid);
 
 	pgid = getpgrp();
 	if (my_pgid == pgid)
 		return;
 
-	if (my_pgid != current->pid->ns[0].virt) {
+	if (my_pgid != vpid(current)) {
 		struct pstree_item *leader;
 
 		/*
@@ -1237,18 +1237,18 @@ static void restore_pgid(void)
 
 		leader = rsti(current)->pgrp_leader;
 		if (leader) {
-			BUG_ON(my_pgid != leader->pid->ns[0].virt);
+			BUG_ON(my_pgid != vpid(leader));
 			futex_wait_until(&rsti(leader)->pgrp_set, 1);
 		}
 	}
 
 	pr_info("\twill call setpgid, mine pgid is %d\n", pgid);
 	if (setpgid(0, my_pgid) != 0) {
-		pr_perror("Can't restore pgid (%d/%d->%d)", current->pid->ns[0].virt, pgid, current->pgid);
+		pr_perror("Can't restore pgid (%d/%d->%d)", vpid(current), pgid, current->pgid);
 		exit(1);
 	}
 
-	if (my_pgid == current->pid->ns[0].virt)
+	if (my_pgid == vpid(current))
 		futex_set_and_wake(&rsti(current)->pgrp_set, 1);
 }
 
@@ -1343,7 +1343,7 @@ static int restore_task_with_children(void *_arg)
 
 		current->pid->real = atoi(buf);
 		pr_debug("PID: real %d virt %d\n",
-				current->pid->real, current->pid->ns[0].virt);
+				current->pid->real, vpid(current));
 	}
 
 	if ( !(ca->clone_flags & CLONE_FILES))
@@ -1356,8 +1356,8 @@ static int restore_task_with_children(void *_arg)
 	}
 
 	pid = getpid();
-	if (current->pid->ns[0].virt != pid) {
-		pr_err("Pid %d do not match expected %d\n", pid, current->pid->ns[0].virt);
+	if (vpid(current) != pid) {
+		pr_err("Pid %d do not match expected %d\n", pid, vpid(current));
 		set_task_cr_err(EEXIST);
 		goto err;
 	}
@@ -1461,7 +1461,7 @@ static int restore_task_with_children(void *_arg)
 	if (restore_finish_stage(task_entries, CR_STATE_FORKING) < 0)
 		goto err;
 
-	if (restore_one_task(current->pid->ns[0].virt, ca->core))
+	if (restore_one_task(vpid(current), ca->core))
 		goto err;
 
 	return 0;
@@ -1771,7 +1771,7 @@ static int restore_root_task(struct pstree_item *init)
 	 * this later.
 	 */
 
-	if (init->pid->ns[0].virt == INIT_PID) {
+	if (vpid(init) == INIT_PID) {
 		if (!(root_ns_mask & CLONE_NEWPID)) {
 			pr_err("This process tree can only be restored "
 				"in a new pid namespace.\n"
@@ -2003,8 +2003,8 @@ out_kill:
 		struct pstree_item *pi;
 
 		for_each_pstree_item(pi)
-			if (pi->pid->ns[0].virt > 0)
-				kill(pi->pid->ns[0].virt, SIGKILL);
+			if (vpid(pi) > 0)
+				kill(vpid(pi), SIGKILL);
 	}
 
 out:
@@ -2038,7 +2038,7 @@ int prepare_dummy_task_state(struct pstree_item *pi)
 {
 	CoreEntry *core;
 
-	if (open_core(pi->pid->ns[0].virt, &core))
+	if (open_core(vpid(pi), &core))
 		return -1;
 
 	pi->pid->state = core->tc->task_state;
diff --git a/criu/files-reg.c b/criu/files-reg.c
index df270a6..3b93bb9 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -397,7 +397,7 @@ static int open_remap_dead_process(struct reg_file_info *rfi,
 	helper->ids = root_item->ids;
 	list_add_tail(&helper->sibling, &root_item->children);
 
-	pr_info("Added a helper for restoring /proc/%d\n", helper->pid->ns[0].virt);
+	pr_info("Added a helper for restoring /proc/%d\n", vpid(helper));
 
 	return 0;
 }
diff --git a/criu/files.c b/criu/files.c
index 1a76313..f97ad1b 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -747,7 +747,7 @@ int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
 	if (!e)
 		return -1;
 
-	return collect_fd(task->pid->ns[0].virt, e, rsti(task));
+	return collect_fd(vpid(task), e, rsti(task));
 }
 
 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)
 {
 	int ret = 0;
 	struct cr_img *img;
-	pid_t pid = item->pid->ns[0].virt;
+	pid_t pid = vpid(item);
 	struct rst_info *rst_info = rsti(item);
 
 	INIT_LIST_HEAD(&rst_info->used);
@@ -790,7 +790,7 @@ int prepare_fd_pid(struct pstree_item *item)
 	if (item->ids == NULL) /* zombie */
 		return 0;
 
-	if (rsti(item)->fdt && rsti(item)->fdt->pid != item->pid->ns[0].virt)
+	if (rsti(item)->fdt && rsti(item)->fdt->pid != vpid(item))
 		return 0;
 
 	img = open_image(CR_FD_FDINFO, O_RSTR, item->ids->files_id);
@@ -903,7 +903,7 @@ int recv_fd_from_peer(struct fdinfo_list_entry *fle)
 
 		pr_info("Further fle=%p, pid=%d\n", tmp, fle->pid);
 		if (!task_fle(current, tmp)) {
-			pr_err("Unexpected fle %p, pid=%d\n", tmp, current->pid->ns[0].virt);
+			pr_err("Unexpected fle %p, pid=%d\n", tmp, vpid(current));
 			return -1;
 		}
 		if (plant_fd(tmp, fd))
@@ -1171,7 +1171,7 @@ int prepare_fds(struct pstree_item *me)
 		futex_inc_and_wake(&fdt->fdt_lock);
 		futex_wait_while_lt(&fdt->fdt_lock, fdt->nr);
 
-		if (fdt->pid != me->pid->ns[0].virt) {
+		if (fdt->pid != vpid(me)) {
 			pr_info("File descriptor table is shared with %d\n", fdt->pid);
 			futex_wait_until(&fdt->fdt_lock, fdt->nr + 1);
 			goto out;
@@ -1261,7 +1261,7 @@ out:
 
 int prepare_fs_pid(struct pstree_item *item)
 {
-	pid_t pid = item->pid->ns[0].virt;
+	pid_t pid = vpid(item);
 	struct rst_info *ri = rsti(item);
 	struct cr_img *img;
 	FsEntry *fe;
@@ -1312,15 +1312,15 @@ int shared_fdt_prepare(struct pstree_item *item)
 
 		futex_init(&fdt->fdt_lock);
 		fdt->nr = 1;
-		fdt->pid = parent->pid->ns[0].virt;
+		fdt->pid = vpid(parent);
 	} else
 		fdt = rsti(parent)->fdt;
 
 	rsti(item)->fdt = fdt;
 	rsti(item)->service_fd_id = fdt->nr;
 	fdt->nr++;
-	if (pid_rst_prio(item->pid->ns[0].virt, fdt->pid))
-		fdt->pid = item->pid->ns[0].virt;
+	if (pid_rst_prio(vpid(item), fdt->pid))
+		fdt->pid = vpid(item);
 
 	return 0;
 }
@@ -1618,7 +1618,7 @@ int inherit_fd_fini()
 int open_transport_socket(void)
 {
 	struct fdt *fdt = rsti(current)->fdt;
-	pid_t pid = current->pid->ns[0].virt;
+	pid_t pid = vpid(current);
 	struct sockaddr_un saddr;
 	int sock, slen;
 
diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index f441d53..3e869de 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -31,6 +31,11 @@ struct pstree_item {
 	};
 };
 
+static inline pid_t vpid(const struct pstree_item *i)
+{
+	return i->pid->ns[0].virt;
+}
+
 enum {
 	FDS_EVENT_BIT	= 0,
 };
diff --git a/criu/mem.c b/criu/mem.c
index 0be3231..6ef57b2 100644
--- a/criu/mem.c
+++ b/criu/mem.c
@@ -344,11 +344,11 @@ static int __parasite_dump_pages_seized(struct pstree_item *item,
 		 * right here. For pre-dumps the pp will be taken by the
 		 * caller and handled later.
 		 */
-		ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, item->pid->ns[0].virt);
+		ret = open_page_xfer(&xfer, CR_FD_PAGEMAP, vpid(item));
 		if (ret < 0)
 			goto out_pp;
 	} else {
-		ret = check_parent_page_xfer(CR_FD_PAGEMAP, item->pid->ns[0].virt);
+		ret = check_parent_page_xfer(CR_FD_PAGEMAP, vpid(item));
 		if (ret < 0)
 			goto out_pp;
 
@@ -477,7 +477,7 @@ int parasite_dump_pages_seized(struct pstree_item *item,
 
 int prepare_mm_pid(struct pstree_item *i)
 {
-	pid_t pid = i->pid->ns[0].virt;
+	pid_t pid = vpid(i);
 	int ret = -1, vn = 0;
 	struct cr_img *img;
 	struct rst_info *ri = rsti(i);
@@ -563,7 +563,7 @@ static int map_private_vma(struct pstree_item *t,
 	struct vma_area *p = *pvma;
 
 	if (vma_area_is(vma, VMA_FILE_PRIVATE)) {
-		ret = vma->vm_open(t->pid->ns[0].virt, vma);
+		ret = vma->vm_open(vpid(t), vma);
 		if (ret < 0) {
 			pr_err("Can't fixup VMA's fd\n");
 			return -1;
@@ -731,7 +731,7 @@ static int restore_priv_vma_content(struct pstree_item *t)
 
 	vma = list_first_entry(vmas, struct vma_area, list);
 
-	ret = open_page_read(t->pid->ns[0].virt, &pr, PR_TASK);
+	ret = open_page_read(vpid(t), &pr, PR_TASK);
 	if (ret <= 0)
 		return -1;
 
@@ -961,7 +961,7 @@ int unmap_guard_pages(struct pstree_item *t)
 
 int open_vmas(struct pstree_item *t)
 {
-	int pid = t->pid->ns[0].virt;
+	int pid = vpid(t);
 	struct vma_area *vma;
 	struct vm_area_list *vmas = &rsti(t)->vmas;
 
diff --git a/criu/mount.c b/criu/mount.c
index cbbc154..e04d215 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2617,7 +2617,7 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren
 {
 	int fd;
 
-	fd = open_proc(root_item->pid->ns[0].virt, "fd/%d", nsid->mnt.ns_fd);
+	fd = open_proc(vpid(root_item), "fd/%d", nsid->mnt.ns_fd);
 	if (fd < 0)
 		return -1;
 
@@ -3062,7 +3062,7 @@ int mntns_get_root_fd(struct ns_id *mntns)
 	if (!mntns->ns_populated) {
 		int fd;
 
-		fd = open_proc(root_item->pid->ns[0].virt, "fd/%d", mntns->mnt.root_fd);
+		fd = open_proc(vpid(root_item), "fd/%d", mntns->mnt.root_fd);
 		if (fd < 0)
 			return -1;
 
diff --git a/criu/namespaces.c b/criu/namespaces.c
index b1cca98..92ae1d7 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -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)
 {
-	pid_t pid = i->pid->ns[0].virt;
+	pid_t pid = vpid(i);
 	struct ns_id *nsid;
 
 	nsid = lookup_ns_by_id(id, nd);
@@ -549,7 +549,7 @@ static int open_ns_fd(struct file_desc *d, int *new_fd)
 		return -1;
 	}
 
-	snprintf(path, sizeof(path) - 1, "/proc/%d/ns/%s", item->pid->ns[0].virt, nd->str);
+	snprintf(path, sizeof(path) - 1, "/proc/%d/ns/%s", vpid(item), nd->str);
 	path[sizeof(path) - 1] = '\0';
 
 	fd = open(path, nfi->nfe->flags);
@@ -1645,11 +1645,11 @@ err_out:
 
 int prepare_namespace(struct pstree_item *item, unsigned long clone_flags)
 {
-	pid_t pid = item->pid->ns[0].virt;
+	pid_t pid = vpid(item);
 	int id;
 
 	pr_info("Restoring namespaces %d flags 0x%lx\n",
-			item->pid->ns[0].virt, clone_flags);
+			vpid(item), clone_flags);
 
 	if ((clone_flags & CLONE_NEWUSER) && prepare_userns_creds())
 		return -1;
diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index d74c324..0b4826b 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -889,8 +889,8 @@ static int page_server_init_send(void)
 		if (!task_alive(pi))
 			continue;
 
-		if (page_pipe_from_pagemap(&pp, pi->pid->ns[0].virt)) {
-			pr_err("%d: failed to open page-read\n", pi->pid->ns[0].virt);
+		if (page_pipe_from_pagemap(&pp, vpid(pi))) {
+			pr_err("%d: failed to open page-read\n", vpid(pi));
 			return -1;
 		}
 
diff --git a/criu/pstree.c b/criu/pstree.c
index 833b3d0..5b6d3aa 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -283,10 +283,10 @@ int dump_pstree(struct pstree_item *root_item)
 	 * deeper in process tree, thus top-level checking for
 	 * leader is enough.
 	 */
-	if (root_item->pid->ns[0].virt != root_item->sid) {
+	if (vpid(root_item) != root_item->sid) {
 		if (!opts.shell_job) {
 			pr_err("The root process %d is not a session leader. "
-			       "Consider using --" OPT_SHELL_JOB " option\n", item->pid->ns[0].virt);
+			       "Consider using --" OPT_SHELL_JOB " option\n", vpid(item));
 			return -1;
 		}
 	}
@@ -296,10 +296,10 @@ int dump_pstree(struct pstree_item *root_item)
 		return -1;
 
 	for_each_pstree_item(item) {
-		pr_info("Process: %d(%d)\n", item->pid->ns[0].virt, item->pid->real);
+		pr_info("Process: %d(%d)\n", vpid(item), item->pid->real);
 
-		e.pid		= item->pid->ns[0].virt;
-		e.ppid		= item->parent ? item->parent->pid->ns[0].virt : 0;
+		e.pid		= vpid(item);
+		e.ppid		= item->parent ? vpid(item->parent) : 0;
 		e.pgid		= item->pgid;
 		e.sid		= item->sid;
 		e.n_threads	= item->nr_threads;
@@ -338,7 +338,7 @@ static int prepare_pstree_for_shell_job(void)
 	if (!opts.shell_job)
 		return 0;
 
-	if (root_item->sid == root_item->pid->ns[0].virt)
+	if (root_item->sid == vpid(root_item))
 		return 0;
 
 	/*
@@ -459,7 +459,7 @@ static int read_pstree_ids(struct pstree_item *pi)
 	int ret;
 	struct cr_img *img;
 
-	img = open_image(CR_FD_IDS, O_RSTR, pi->pid->ns[0].virt);
+	img = open_image(CR_FD_IDS, O_RSTR, vpid(pi));
 	if (!img)
 		return -1;
 
@@ -538,7 +538,7 @@ static int read_pstree_image(pid_t *pid_max)
 
 			pid = pstree_pid_by_virt(e->ppid);
 			if (!pid || pid->state == TASK_UNDEF || pid->state == TASK_THREAD) {
-				pr_err("Can't find a parent for %d\n", pi->pid->ns[0].virt);
+				pr_err("Can't find a parent for %d\n", vpid(pi));
 				pstree_entry__free_unpacked(e, NULL);
 				xfree(pi);
 				goto err;
@@ -634,7 +634,7 @@ static int prepare_pstree_ids(void)
 		 * a session leader himself -- this is a simple case, we
 		 * just proceed in a normal way.
 		 */
-		if (item->sid == root_item->sid || item->sid == item->pid->ns[0].virt)
+		if (item->sid == root_item->sid || item->sid == vpid(item))
 			continue;
 
 		leader = pstree_item_by_virt(item->sid);
@@ -658,7 +658,7 @@ static int prepare_pstree_ids(void)
 			list_add(&helper->sibling, &leader->children);
 
 			pr_info("Attach %d to the task %d\n",
-					helper->pid->ns[0].virt, leader->pid->ns[0].virt);
+					vpid(helper), vpid(leader));
 		} else {
 			helper = leader;
 			helper->sid = item->sid;
@@ -670,7 +670,7 @@ static int prepare_pstree_ids(void)
 		init_pstree_helper(helper);
 
 		pr_info("Add a helper %d for restoring SID %d\n",
-				helper->pid->ns[0].virt, helper->sid);
+				vpid(helper), helper->sid);
 
 		child = list_entry(item->sibling.prev, struct pstree_item, sibling);
 		item = child;
@@ -681,11 +681,11 @@ static int prepare_pstree_ids(void)
 		list_for_each_entry_safe_continue(child, tmp, &root_item->children, sibling) {
 			if (child->sid != helper->sid)
 				continue;
-			if (child->sid == child->pid->ns[0].virt)
+			if (child->sid == vpid(child))
 				continue;
 
 			pr_info("Attach %d to the temporary task %d\n",
-					child->pid->ns[0].virt, helper->pid->ns[0].virt);
+					vpid(child), vpid(helper));
 
 			child->parent = helper;
 			list_move(&child->sibling, &helper->children);
@@ -700,7 +700,7 @@ static int prepare_pstree_ids(void)
 		if (item->pid->state == TASK_HELPER)
 			continue;
 
-		if (item->sid != item->pid->ns[0].virt) {
+		if (item->sid != vpid(item)) {
 			struct pstree_item *parent;
 
 			if (item->parent->sid == item->sid)
@@ -708,15 +708,15 @@ static int prepare_pstree_ids(void)
 
 			/* the task could fork a child before and after setsid() */
 			parent = item->parent;
-			while (parent && parent->pid->ns[0].virt != item->sid) {
+			while (parent && vpid(parent) != item->sid) {
 				if (parent->born_sid != -1 && parent->born_sid != item->sid) {
 					pr_err("Can't determinate with which sid (%d or %d)"
 						"the process %d was born\n",
-						parent->born_sid, item->sid, parent->pid->ns[0].virt);
+						parent->born_sid, item->sid, vpid(parent));
 					return -1;
 				}
 				parent->born_sid = item->sid;
-				pr_info("%d was born with sid %d\n", parent->pid->ns[0].virt, item->sid);
+				pr_info("%d was born with sid %d\n", vpid(parent), item->sid);
 				parent = parent->parent;
 			}
 
@@ -736,7 +736,7 @@ static int prepare_pstree_ids(void)
 	for_each_pstree_item(item) {
 		struct pid *pid;
 
-		if (!item->pgid || item->pid->ns[0].virt == item->pgid)
+		if (!item->pgid || vpid(item) == item->pgid)
 			continue;
 
 		pid = pstree_pid_by_virt(item->pgid);
@@ -766,7 +766,7 @@ static int prepare_pstree_ids(void)
 		rsti(item)->pgrp_leader = helper;
 
 		pr_info("Add a helper %d for restoring PGID %d\n",
-				helper->pid->ns[0].virt, helper->pgid);
+				vpid(helper), helper->pgid);
 	}
 
 	return 0;
@@ -1004,6 +1004,6 @@ int pid_to_virt(pid_t real)
 
 	item = pstree_item_by_real(real);
 	if (item)
-		return item->pid->ns[0].virt;
+		return vpid(item);
 	return 0;
 }
diff --git a/criu/tty.c b/criu/tty.c
index 17d19f4..68ebb10 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -1010,7 +1010,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
 		 * checkpoint complete process tree together with
 		 * the process which keeps the master peer.
 		 */
-		if (root_item->sid != root_item->pid->ns[0].virt) {
+		if (root_item->sid != vpid(root_item)) {
 			pr_debug("Restore inherited group %d\n",
 				 getpgid(getppid()));
 			if (tty_set_prgp(fd, getpgid(getppid())))
@@ -1259,10 +1259,10 @@ static int tty_find_restoring_task(struct tty_info *info)
 		 * for us.
 		 */
 		item = find_first_sid(info->tie->sid);
-		if (item && item->pid->ns[0].virt == item->sid) {
+		if (item && vpid(item) == item->sid) {
 			pr_info("Set a control terminal %#x to %d\n",
 				info->tfe->id, info->tie->sid);
-			return prepare_ctl_tty(item->pid->ns[0].virt,
+			return prepare_ctl_tty(vpid(item),
 					       rsti(item),
 					       info->tfe->id);
 		}
@@ -1668,7 +1668,7 @@ int dump_verify_tty_sids(void)
 		if (!ret && dinfo->sid) {
 			struct pstree_item *item = find_first_sid(dinfo->sid);
 
-			if (!item || item->pid->ns[0].virt != dinfo->sid) {
+			if (!item || vpid(item) != dinfo->sid) {
 				if (!opts.shell_job) {
 					pr_err("Found dangling tty with sid %d pgid %d (%s) on peer fd %d.\n",
 					       dinfo->sid, dinfo->pgrp,
-- 
2.5.0



More information about the CRIU mailing list