Commit 0afffc9d authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

mnt: add --enable-external-sharing flag

With this flag, external shared bind mounts are attempted to be resolved
automatically.

v2: don't always assume when the sharing matches that the mount matches
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent aebfabb5
...@@ -205,6 +205,7 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -205,6 +205,7 @@ int main(int argc, char *argv[], char *envp[])
{ "feature", required_argument, 0, 1063 }, { "feature", required_argument, 0, 1063 },
{ "skip-mnt", required_argument, 0, 1064}, { "skip-mnt", required_argument, 0, 1064},
{ "enable-fs", required_argument, 0, 1065}, { "enable-fs", required_argument, 0, 1065},
{ "enable-external-sharing", no_argument, 0, 1066 },
{ }, { },
}; };
...@@ -426,6 +427,9 @@ int main(int argc, char *argv[], char *envp[]) ...@@ -426,6 +427,9 @@ int main(int argc, char *argv[], char *envp[])
if (!add_fsname_auto(optarg)) if (!add_fsname_auto(optarg))
return 1; return 1;
break; break;
case 1066:
opts.enable_external_sharing = true;
break;
case 'M': case 'M':
{ {
char *aux; char *aux;
...@@ -654,6 +658,8 @@ usage: ...@@ -654,6 +658,8 @@ usage:
" add external mount mapping\n" " add external mount mapping\n"
" -M|--ext-mount-map auto\n" " -M|--ext-mount-map auto\n"
" attempt to autodetect external mount mapings\n" " attempt to autodetect external mount mapings\n"
" --enable-external-sharing\n"
" allow autoresolving mounts with external sharing\n"
" --manage-cgroups dump or restore cgroups the process is in\n" " --manage-cgroups dump or restore cgroups the process is in\n"
" --cgroup-root [controller:]/newroot\n" " --cgroup-root [controller:]/newroot\n"
" change the root cgroup the controller will be\n" " change the root cgroup the controller will be\n"
......
...@@ -63,6 +63,7 @@ struct cr_options { ...@@ -63,6 +63,7 @@ struct cr_options {
char *new_global_cg_root; char *new_global_cg_root;
struct list_head new_cgroup_roots; struct list_head new_cgroup_roots;
bool autodetect_ext_mounts; bool autodetect_ext_mounts;
bool enable_external_sharing;
bool aufs; /* auto-deteced, not via cli */ bool aufs; /* auto-deteced, not via cli */
}; };
......
...@@ -130,6 +130,7 @@ struct mount_info { ...@@ -130,6 +130,7 @@ struct mount_info {
struct ns_id *nsid; struct ns_id *nsid;
struct ext_mount *external; struct ext_mount *external;
bool internal_sharing;
/* tree linkage */ /* tree linkage */
struct mount_info *parent; struct mount_info *parent;
......
...@@ -731,6 +731,14 @@ static int resolve_external_mounts(struct mount_info *info) ...@@ -731,6 +731,14 @@ static int resolve_external_mounts(struct mount_info *info)
if (!match) if (!match)
continue; continue;
if (m->flags & MS_SHARED) {
if (!opts.enable_external_sharing)
continue;
if (m->shared_id != match->shared_id)
m->internal_sharing = true;
}
size = strlen(match->mountpoint + 1) + strlen(m->root) + 1; size = strlen(match->mountpoint + 1) + strlen(m->root) + 1;
p = xmalloc(sizeof(char) * size); p = xmalloc(sizeof(char) * size);
if (!p) if (!p)
...@@ -1437,6 +1445,11 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img) ...@@ -1437,6 +1445,11 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img)
me.with_plugin = true; me.with_plugin = true;
} }
if (pm->internal_sharing) {
me.has_internal_sharing = true;
me.internal_sharing = true;
}
if (pm->external) { if (pm->external) {
/* /*
* For external mount points dump the mapping's * For external mount points dump the mapping's
...@@ -1778,6 +1791,7 @@ static int restore_ext_mount(struct mount_info *mi) ...@@ -1778,6 +1791,7 @@ static int restore_ext_mount(struct mount_info *mi)
static int do_bind_mount(struct mount_info *mi) static int do_bind_mount(struct mount_info *mi)
{ {
bool shared = 0; bool shared = 0;
bool force_private_remount = false;
if (!mi->need_plugin) { if (!mi->need_plugin) {
char *root, rpath[PATH_MAX]; char *root, rpath[PATH_MAX];
...@@ -1791,6 +1805,7 @@ static int do_bind_mount(struct mount_info *mi) ...@@ -1791,6 +1805,7 @@ static int do_bind_mount(struct mount_info *mi)
* to proper location in the namespace we restore. * to proper location in the namespace we restore.
*/ */
root = mi->root; root = mi->root;
force_private_remount = mi->internal_sharing;
goto do_bind; goto do_bind;
} }
...@@ -1827,7 +1842,7 @@ do_bind: ...@@ -1827,7 +1842,7 @@ do_bind:
* shared - the mount is in the same shared group with mi->bind * shared - the mount is in the same shared group with mi->bind
* mi->shared_id && !shared - create a new shared group * mi->shared_id && !shared - create a new shared group
*/ */
if (restore_shared_options(mi, !shared && !mi->master_id, if (restore_shared_options(mi, force_private_remount || (!shared && !mi->master_id),
mi->shared_id && !shared, mi->shared_id && !shared,
mi->master_id)) mi->master_id))
return -1; return -1;
...@@ -2139,6 +2154,9 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid) ...@@ -2139,6 +2154,9 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
if (!pm->source) if (!pm->source)
goto err; goto err;
if (me->has_internal_sharing)
pm->internal_sharing = me->internal_sharing;
/* FIXME: abort unsupported early */ /* FIXME: abort unsupported early */
pm->fstype = decode_fstype(me->fstype, me->fsname); pm->fstype = decode_fstype(me->fstype, me->fsname);
......
...@@ -39,4 +39,5 @@ message mnt_entry { ...@@ -39,4 +39,5 @@ message mnt_entry {
optional bool ext_mount = 13; optional bool ext_mount = 13;
optional string fsname = 14; optional string fsname = 14;
optional bool internal_sharing = 15;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment