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

Kirill Tkhai ktkhai at virtuozzo.com
Tue Mar 28 08:38:58 PDT 2017


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 at virtuozzo.com>
---
 criu/include/namespaces.h |    7 +++++++
 criu/namespaces.c         |    6 +++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

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;
 }
 



More information about the CRIU mailing list