[CRIU] [PATCH 6/6] pstree: Delete checks of always existing pstree_item::ids on restore
Kirill Tkhai
ktkhai at virtuozzo.com
Thu May 11 04:51:14 PDT 2017
pid, net, ipc, uts, mnt ids exist always, and we check
for them when we are reading ids img (see previous
patch "pstree: Check for always existing task ids").
Also, pstree_item::ids exist always too (we populate
them even for dead tasks, see read_pstree_image()).
So, delete the excess checks and simplify the code.
Also, in restore_one_alive_task() check for has_user_ns_id
instead of ids, as ids always exist.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/cr-restore.c | 2 +-
criu/mount.c | 47 ++++++++++++++++++++++-------------------------
criu/net.c | 22 ++++++++++------------
3 files changed, 33 insertions(+), 38 deletions(-)
diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 230b5e470..9da6d72e2 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -954,7 +954,7 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
if (restore_task_net_ns(current))
return -1;
- if (current->ids && set_user_ns(current->ids->user_ns_id) < 0)
+ if (current->ids->has_user_ns_id && set_user_ns(current->ids->user_ns_id) < 0)
return -1;
if (setup_uffd(pid, ta))
diff --git a/criu/mount.c b/criu/mount.c
index 2ea3d5dce..cc6455aae 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2724,36 +2724,33 @@ static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *curren
int restore_task_mnt_ns(struct pstree_item *current)
{
+ unsigned int id = current->ids->mnt_ns_id;
+ struct ns_id *nsid;
+
if ((root_ns_mask & CLONE_NEWNS) == 0)
return 0;
+ /*
+ * Regardless of the namespace a task wants to
+ * live in, by that point they all will live in
+ * root's one (see prepare_pstree_kobj_ids() +
+ * get_clone_mask()). So if the current task's
+ * target namespace is the root's one -- it's
+ * already there, otherwise it will have to do
+ * setns().
+ */
+ if (current->parent && id == current->parent->ids->mnt_ns_id)
+ return 0;
- if (current->ids && current->ids->has_mnt_ns_id) {
- unsigned int id = current->ids->mnt_ns_id;
- struct ns_id *nsid;
-
- /*
- * Regardless of the namespace a task wants to
- * live in, by that point they all will live in
- * root's one (see prepare_pstree_kobj_ids() +
- * get_clone_mask()). So if the current task's
- * target namespace is the root's one -- it's
- * already there, otherwise it will have to do
- * setns().
- */
- if (current->parent && id == current->parent->ids->mnt_ns_id)
- return 0;
-
- nsid = lookup_ns_by_id(id, &mnt_ns_desc);
- if (nsid == NULL) {
- pr_err("Can't find mount namespace %d\n", id);
- return -1;
- }
+ nsid = lookup_ns_by_id(id, &mnt_ns_desc);
+ if (nsid == NULL) {
+ pr_err("Can't find mount namespace %d\n", id);
+ return -1;
+ }
- BUG_ON(nsid->type == NS_CRIU);
+ BUG_ON(nsid->type == NS_CRIU);
- if (do_restore_task_mnt_ns(nsid, current))
- return -1;
- }
+ if (do_restore_task_mnt_ns(nsid, current))
+ return -1;
return 0;
}
diff --git a/criu/net.c b/criu/net.c
index aa50ebfc7..821a83750 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2194,21 +2194,19 @@ static int do_restore_task_net_ns(struct ns_id *nsid, struct pstree_item *curren
int restore_task_net_ns(struct pstree_item *current)
{
- if (current->ids && current->ids->has_net_ns_id) {
- unsigned int id = current->ids->net_ns_id;
- struct ns_id *nsid;
+ unsigned int id = current->ids->net_ns_id;
+ struct ns_id *nsid;
- nsid = lookup_ns_by_id(id, &net_ns_desc);
- if (nsid == NULL) {
- pr_err("Can't find mount namespace %d\n", id);
- return -1;
- }
+ nsid = lookup_ns_by_id(id, &net_ns_desc);
+ if (nsid == NULL) {
+ pr_err("Can't find mount namespace %d\n", id);
+ return -1;
+ }
- BUG_ON(nsid->type == NS_CRIU);
+ BUG_ON(nsid->type == NS_CRIU);
- if (do_restore_task_net_ns(nsid, current))
- return -1;
- }
+ if (do_restore_task_net_ns(nsid, current))
+ return -1;
return 0;
}
More information about the CRIU
mailing list