From 3c2eafb460eaca2ea2c3ae62b10f0da3cfa2d915 Mon Sep 17 00:00:00 2001 From: Saied Kazemi Date: Sun, 7 Sep 2014 23:15:58 -0700 Subject: [PATCH] Return AUFS root mountpoint if mnt_id is not found When reading mnt_id from /proc//fdinfo/ for AUFS files in the /proc//map_files directory, the mnt_id value can be for a mountpoint that is not visible in the process's mount namespace. In such a case, instead of failing use the process's root mountpoint. Signed-off-by: Saied Kazemi --- crtools.c | 5 +++++ mount.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crtools.c b/crtools.c index 1c31392..75ad209 100644 --- a/crtools.c +++ b/crtools.c @@ -176,6 +176,7 @@ int main(int argc, char *argv[], char *envp[]) { "exec-cmd", no_argument, 0, 1059}, { "manage-cgroups", no_argument, 0, 1060}, { "cgroup-root", required_argument, 0, 1061}, + { "aufs", no_argument, 0, 1062}, { }, }; @@ -399,6 +400,9 @@ int main(int argc, char *argv[], char *envp[]) case 'h': usage_error = false; goto usage; + case 1062: + opts.aufs = 1; + break; default: goto usage; } @@ -550,6 +554,7 @@ usage: " 'fpu','all'. To disable capability, prefix it with '^'.\n" " --exec-cmd execute the command specified after '--' on successful\n" " restore making it the parent of the restored process\n" +" --aufs root filesystem is an AUFS mountpoint\n" "\n" "* Special resources support:\n" " -x|--" USK_EXT_PARAM " allow external unix connections\n" diff --git a/mount.c b/mount.c index f7bb5f0..9e7df0b 100644 --- a/mount.c +++ b/mount.c @@ -137,20 +137,24 @@ int open_mount(unsigned int s_dev) return -ENOENT; } -static struct mount_info *__lookup_mnt_id(struct mount_info *list, int id) +static struct mount_info *__lookup_mnt_id(struct mount_info *list, int id, int root_ok) { struct mount_info *m; + struct mount_info *root_mount = NULL; - for (m = list; m != NULL; m = m->next) + for (m = list; m != NULL; m = m->next) { if (m->mnt_id == id) return m; + if (root_ok && is_root_mount(m)) + root_mount = m; + } - return NULL; + return root_ok ? root_mount : NULL; } struct mount_info *lookup_mnt_id(unsigned int id) { - return __lookup_mnt_id(mntinfo, id); + return __lookup_mnt_id(mntinfo, id, opts.aufs ? 1 : 0); } struct mount_info *lookup_mnt_sdev(unsigned int s_dev) @@ -251,7 +255,7 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list) struct mount_info *p; pr_debug("\t\tWorking on %d->%d\n", m->mnt_id, m->parent_mnt_id); - p = __lookup_mnt_id(list, m->parent_mnt_id); + p = __lookup_mnt_id(list, m->parent_mnt_id, 0); if (!p) { /* This should be / */ if (root == NULL && is_root_mount(m)) { -- 1.9.1