From c5c65fe17acf1a67943f0fed1b8f403718337c19 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 21 Sep 2015 14:08:41 +0300 Subject: [PATCH] mnt: Create roots in criu context In case root task restore failure we'll have to remove the roots yard dir from criu, so we have to create one by criu to at least have the dit name. It's OK to do it in criu, since the yards is created in the opts.root which is the same for any mnt ns we deal with on restore. Signed-off-by: Pavel Emelyanov --- include/mount.h | 1 + mount.c | 36 ++++++++++++++++++++++++++---------- namespaces.c | 8 ++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/mount.h b/include/mount.h index 76a8e2442..6018dd791 100644 --- a/include/mount.h +++ b/include/mount.h @@ -117,5 +117,6 @@ extern int fini_mnt_ns(void); extern char *rst_get_mnt_root(int mnt_id); extern int ext_mount_add(char *key, char *val); +extern int mntns_maybe_create_roots(void); #endif /* __CR_MOUNT_H__ */ diff --git a/mount.c b/mount.c index 88a6026ce..16d662ece 100644 --- a/mount.c +++ b/mount.c @@ -2529,16 +2529,6 @@ static int read_mnt_ns_img(void) if (nsid->nd != &mnt_ns_desc) continue; - if (nsid->type != NS_ROOT) { - BUG_ON(nsid->type == NS_CRIU); - /* - * If we have more than one (root) namespace, - * then we'll need the roots yard. - */ - if (create_mnt_roots()) - return -1; - } - if (collect_mnt_from_image(&pms, nsid)) return -1; } @@ -2568,6 +2558,32 @@ char *rst_get_mnt_root(int mnt_id) return path; } +int mntns_maybe_create_roots(void) +{ + struct ns_id *ns; + + if (!(root_ns_mask & CLONE_NEWNS)) + return 0; + + for (ns = ns_ids; ns != NULL; ns = ns->next) { + if (ns->nd != &mnt_ns_desc) + continue; + + if (ns->type != NS_ROOT) { + BUG_ON(ns->type == NS_CRIU); + + /* + * If we have more than one (root) namespace, + * then we'll need the roots yard. + */ + return create_mnt_roots(); + } + } + + /* No "other" mntns found, just go ahead, we don't need roots yard. */ + return 0; +} + static int do_restore_task_mnt_ns(struct ns_id *nsid, struct pstree_item *current) { char path[PATH_MAX]; diff --git a/namespaces.c b/namespaces.c index bb38459b3..135230e08 100644 --- a/namespaces.c +++ b/namespaces.c @@ -1321,8 +1321,16 @@ int prepare_namespace_before_tasks(void) if (netns_keep_nsfd()) goto err_netns; + if (mntns_maybe_create_roots()) + goto err_mnt; + return 0; +err_mnt: + /* + * Nothing, netns' descriptor will be closed + * on criu exit + */ err_netns: stop_usernsd(); err_unds: