[v3,18/55] ids: Copy unexisted ids from root_item

Submitted by Kirill Tkhai on April 10, 2017, 8:18 a.m.

Details

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

Commit Message

Kirill Tkhai April 10, 2017, 8:18 a.m.
ids were introduced sequentially, so some old image
may not have some id. Copy them from root_item.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/pstree.c |   47 +++++++++++++++++++----------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/pstree.c b/criu/pstree.c
index d6d71bb3c..0e8a16f1e 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -495,22 +495,25 @@  static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
 
 	if (ret <= 0)
 		return ret;
-
-	if ((*ids)->has_mnt_ns_id) {
-		if (rst_add_ns_id((*ids)->mnt_ns_id, pid, &mnt_ns_desc))
-			return -1;
-	}
-	if ((*ids)->has_net_ns_id) {
-		if (rst_add_ns_id((*ids)->net_ns_id, pid, &net_ns_desc))
-			return -1;
-	}
-	if ((*ids)->has_user_ns_id) {
-		if (rst_add_ns_id((*ids)->user_ns_id, pid, &user_ns_desc))
-			return -1;
+	ret = 0;
+#define ADD_OR_COPY_ID(ids, name)								\
+	if (!ret) {										\
+		if ((*ids)->has_##name##_ns_id)							\
+			ret = rst_add_ns_id((*ids)->name##_ns_id, pid, &name##_ns_desc);	\
+		else if (root_item && root_item->ids && root_item->ids->has_##name##_ns_id) {	\
+			(*ids)->has_##name##_ns_id = true;						\
+			(*ids)->name##_ns_id = root_item->ids->name##_ns_id;			\
+		}										\
 	}
-	if ((*ids)->has_pid_ns_id) {
-		if (rst_add_ns_id((*ids)->pid_ns_id, pid, &pid_ns_desc))
-			return -1;
+	ADD_OR_COPY_ID(ids, mnt);
+	ADD_OR_COPY_ID(ids, net);
+	ADD_OR_COPY_ID(ids, user);
+	ADD_OR_COPY_ID(ids, pid);
+	ADD_OR_COPY_ID(ids, ipc);
+	ADD_OR_COPY_ID(ids, uts);
+	ADD_OR_COPY_ID(ids, cgroup);
+
+	if (!ret && (*ids)->has_pid_ns_id) {
 		if (!top_pid_ns) {
 			/*
 			 * If top_pid_ns is not set, this means that here is old dump,
@@ -520,20 +523,8 @@  static int read_pstree_ids(pid_t pid, TaskKobjIdsEntry **ids)
 			top_pid_ns = lookup_ns_by_id((*ids)->pid_ns_id, &pid_ns_desc);
 		}
 	}
-	if ((*ids)->has_ipc_ns_id) {
-		if (rst_add_ns_id((*ids)->ipc_ns_id, pid, &ipc_ns_desc))
-			return -1;
-	}
-	if ((*ids)->has_uts_ns_id) {
-		if (rst_add_ns_id((*ids)->uts_ns_id, pid, &uts_ns_desc))
-			return -1;
-	}
-	if ((*ids)->has_cgroup_ns_id) {
-		if (rst_add_ns_id((*ids)->cgroup_ns_id, pid, &cgroup_ns_desc))
-			return -1;
-	}
 
-	return 0;
+	return ret;
 }
 
 static int read_pstree_image(pid_t *pid_max)