diff --git a/cr-dump.c b/cr-dump.c index d8ad0fc81..1700d9dc0 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -1803,7 +1803,7 @@ int cr_dump_tasks(pid_t pid) if (collect_file_locks()) goto err; - if (dump_mnt_namespaces() < 0) + if (collect_mnt_namespaces() < 0) goto err; if (collect_sockets(pid)) @@ -1818,6 +1818,10 @@ int cr_dump_tasks(pid_t pid) goto err; } + /* MNT namespaces are dumped after files to save remapped links */ + if (dump_mnt_namespaces() < 0) + goto err; + if (dump_verify_tty_sids()) goto err; diff --git a/mount.c b/mount.c index 50171a342..a8133d782 100644 --- a/mount.c +++ b/mount.c @@ -996,20 +996,12 @@ err: return NULL; } -static int dump_mnt_ns(struct ns_id *ns, struct mount_info *pms, void *a) +static int dump_mnt_ns(struct ns_id *ns, struct mount_info *pms) { - int *n = a; struct mount_info *pm; int img_fd = -1, ret = -1; int ns_id = ns->id; - (*n)++; - if (*n == 2 && check_mnt_id()) { - pr_err("Nested mount namespaces are not supported " - "without mnt_id in fdinfo\n"); - goto err; - } - if (validate_mounts(pms, true)) goto err; @@ -1018,7 +1010,7 @@ static int dump_mnt_ns(struct ns_id *ns, struct mount_info *pms, void *a) if (img_fd < 0) goto err; - for (pm = pms; pm; pm = pm->next) + for (pm = pms; pm && pm->nsid == ns; pm = pm->next) if (dump_one_mountpoint(pm, img_fd)) goto err_i; @@ -2122,8 +2114,29 @@ int collect_mnt_namespaces(void) int dump_mnt_namespaces(void) { + struct ns_id *nsid = NULL; + struct mount_info *m; int n = 0; - return walk_mnt_ns(dump_mnt_ns, &n); + + if (!(root_ns_mask & CLONE_NEWNS)) + return 0; + + for (m = mntinfo; m; m = m->next) { + if (m->nsid == nsid) + continue; + + if (++n == 2 && check_mnt_id()) { + pr_err("Nested mount namespaces are not supported " + "without mnt_id in fdinfo\n"); + return -1; + } + + if (dump_mnt_ns(m->nsid, m)) + return -1; + + nsid = m->nsid; + } + return 0; } struct ns_desc mnt_ns_desc = NS_DESC_ENTRY(CLONE_NEWNS, "mnt");