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: