[v2,32/57] pid_ns: Implement pid_ns_root_off()

Submitted by Kirill Tkhai on March 28, 2017, 3:38 p.m.

Details

Message ID 149071553835.12770.16471749593949743565.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai March 28, 2017, 3:38 p.m.
Implement a helper receiving number of levels between
pid namespace level NS_CRIU and NS_ROOT.

v2: Pre-dump tasks pid_ns in predump_task_ns_ids()

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/namespaces.h |    7 +++++++
 criu/namespaces.c         |    6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index 820b16d1..8764a898 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -257,5 +257,12 @@  extern int add_ns_shared_cb(int (*actor)(void *data), void *data);
 
 extern struct ns_id *get_socket_ns(int lfd);
 extern struct ns_id *lookup_ns_by_kid(unsigned int kid, struct ns_desc *nd);
+/* Number of levels of pid_ns between NS_CRIU and NS_ROOT */
+static inline int pid_ns_root_off(void)
+{
+	if (root_ns_mask & CLONE_NEWPID)
+		return 1;
+	return 0;
+}
 
 #endif /* __CR_NS_H__ */
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 5a610668..9d517815 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -676,10 +676,11 @@  struct collect_image_info nsfile_cinfo = {
 /*
  * Same as dump_task_ns_ids(), but
  * a) doesn't keep IDs (don't need them)
- * b) generates them for mount and netns only
+ * b) generates them for mount, netns and pid_ns only
  *    mnt ones are needed for open_mount() in
  *    inotify pred-dump
  *    net ones are needed for parasite socket
+ *    pid is need for pid_ns_root_off()
  */
 
 int predump_task_ns_ids(struct pstree_item *item)
@@ -692,6 +693,9 @@  int predump_task_ns_ids(struct pstree_item *item)
 	if (!get_ns_id(pid, &mnt_ns_desc, NULL))
 		return -1;
 
+	if (!get_ns_id(pid, &pid_ns_desc, NULL))
+		return -1;
+
 	return 0;
 }