[CRIU] [PATCH 2/5] mnt: add --enable-external-sharing flag
Pavel Emelyanov
xemul at parallels.com
Thu Apr 9 09:49:14 PDT 2015
On 04/09/2015 07:32 PM, Tycho Andersen wrote:
> With this flag, external shared bind mounts are attempted to be resolved
> automatically.
Just a question -- what if we specify external mount map manually, would
the sharing/slavery get resolved?
> v2: don't always assume when the sharing matches that the mount matches
>
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> ---
> crtools.c | 6 ++++++
> include/cr_options.h | 1 +
> include/proc_parse.h | 1 +
> mount.c | 20 +++++++++++++++++++-
> protobuf/mnt.proto | 1 +
> 5 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/crtools.c b/crtools.c
> index a6ee2d7..fe77f39 100644
> --- a/crtools.c
> +++ b/crtools.c
> @@ -204,6 +204,7 @@ int main(int argc, char *argv[], char *envp[])
> { "inherit-fd", required_argument, 0, 1062 },
> { "feature", required_argument, 0, 1063 },
> { "skip-mnt", required_argument, 0, 1064},
> + { "enable-external-sharing", no_argument, 0, 1065 },
> { },
> };
>
> @@ -421,6 +422,9 @@ int main(int argc, char *argv[], char *envp[])
> if (!add_skip_mount(optarg))
> return 1;
> break;
> + case 1065:
> + opts.enable_external_sharing = true;
> + break;
> case 'M':
> {
> char *aux;
> @@ -649,6 +653,8 @@ usage:
> " add external mount mapping\n"
> " -M|--ext-mount-map auto\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"
> " --cgroup-root [controller:]/newroot\n"
> " change the root cgroup the controller will be\n"
> diff --git a/include/cr_options.h b/include/cr_options.h
> index f1cfc84..29be2c8 100644
> --- a/include/cr_options.h
> +++ b/include/cr_options.h
> @@ -63,6 +63,7 @@ struct cr_options {
> char *new_global_cg_root;
> struct list_head new_cgroup_roots;
> bool autodetect_ext_mounts;
> + bool enable_external_sharing;
> bool aufs; /* auto-deteced, not via cli */
> };
>
> diff --git a/include/proc_parse.h b/include/proc_parse.h
> index a0fee1f..e5d59d2 100644
> --- a/include/proc_parse.h
> +++ b/include/proc_parse.h
> @@ -130,6 +130,7 @@ struct mount_info {
> struct ns_id *nsid;
>
> struct ext_mount *external;
> + bool internal_sharing;
>
> /* tree linkage */
> struct mount_info *parent;
> diff --git a/mount.c b/mount.c
> index 154c389..fc334cf 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -734,6 +734,14 @@ static int resolve_external_mounts(struct mount_info *info)
> if (!match)
> 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;
> p = xmalloc(sizeof(char) * size);
> if (!p)
> @@ -1312,6 +1320,11 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img)
> me.with_plugin = true;
> }
>
> + if (pm->internal_sharing) {
> + me.has_internal_sharing = true;
> + me.internal_sharing = true;
> + }
> +
> if (pm->external) {
> /*
> * For external mount points dump the mapping's
> @@ -1653,6 +1666,7 @@ static int restore_ext_mount(struct mount_info *mi)
> static int do_bind_mount(struct mount_info *mi)
> {
> bool shared = 0;
> + bool force_private_remount = false;
>
> if (!mi->need_plugin) {
> char *root, rpath[PATH_MAX];
> @@ -1666,6 +1680,7 @@ static int do_bind_mount(struct mount_info *mi)
> * to proper location in the namespace we restore.
> */
> root = mi->root;
> + force_private_remount = mi->internal_sharing;
> goto do_bind;
> }
>
> @@ -1702,7 +1717,7 @@ do_bind:
> * shared - the mount is in the same shared group with mi->bind
> * 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->master_id))
> return -1;
> @@ -2014,6 +2029,9 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
> if (!pm->source)
> goto err;
>
> + if (me->has_internal_sharing)
> + pm->internal_sharing = me->internal_sharing;
> +
> /* FIXME: abort unsupported early */
> pm->fstype = decode_fstype(me->fstype);
>
> diff --git a/protobuf/mnt.proto b/protobuf/mnt.proto
> index 343bd6d..3244411 100644
> --- a/protobuf/mnt.proto
> +++ b/protobuf/mnt.proto
> @@ -35,4 +35,5 @@ message mnt_entry {
>
> optional bool with_plugin = 12;
> optional bool ext_mount = 13;
> + optional bool internal_sharing = 14;
> }
>
More information about the CRIU
mailing list