[CRIU] [PATCH] mnt: disable the use of pivot_root in case of ramdisk
Andrew Vagin
avagin at odin.com
Thu Dec 17 05:20:51 PST 2015
On Sat, Oct 31, 2015 at 11:51:27PM +0100, ismael wrote:
> Le Thu, 29 Oct 2015 13:55:08 +0300,
> Andrew Vagin <avagin at odin.com> a écrit :
>
> > On Mon, Oct 26, 2015 at 11:01:11PM +0100, Ismaël FEZZAZ wrote:
> > > Signed-off-by: Ismael Fezzaz <i.fezzaz at gmail.com>
> > > ---
> > > crtools.c | 5 +++++
> > > include/cr_options.h | 1 +
> > > mount.c | 19 +++++++++++++++++++
> > > 3 files changed, 25 insertions(+)
> > >
> > > diff --git a/crtools.c b/crtools.c
> > > index d3812a1..6d60421 100644
> > > --- a/crtools.c
> > > +++ b/crtools.c
> > > @@ -253,6 +253,7 @@ int main(int argc, char *argv[], char *envp[])
> > > { "freeze-cgroup", required_argument, 0, 1068 },
> > > { "ghost-limit", required_argument, 0, 1069 },
> > > { "irmap-scan-path", required_argument, 0,
> > > 1070 },
> > > + { "ramdisk", no_argument, 0, 1071 },
> > > { },
> > > };
> > >
> > > @@ -498,6 +499,9 @@ int main(int argc, char *argv[], char *envp[])
> > > if (irmap_scan_path_add(optarg))
> > > return -1;
> > > break;
> > > + case 10701:
> > > + opts.ramdisk = true;
> > > + break;
> > > case 'M':
> > > {
>
> The option number in the switch was wrong, here is the fixed version.
> Sorry for that.
>
> Signed-off-by: Ismael Fezzaz <i.fezzaz at gmail.com>
> ---
> crtools.c | 5 +++++
> include/cr_options.h | 1 +
> mount.c | 19 +++++++++++++++++++
> 3 files changed, 25 insertions(+)
>
> diff --git a/crtools.c b/crtools.c
> index d3812a1..865b6fc 100644
> --- a/crtools.c
> +++ b/crtools.c
> @@ -253,6 +253,7 @@ int main(int argc, char *argv[], char *envp[])
> { "freeze-cgroup", required_argument, 0, 1068 },
> { "ghost-limit", required_argument, 0, 1069 },
> { "irmap-scan-path", required_argument, 0, 1070 },
> + { "ramdisk", no_argument , 0, 1071 },
> { },
> };
>
> @@ -498,6 +499,9 @@ int main(int argc, char *argv[], char *envp[])
> if (irmap_scan_path_add(optarg))
> return -1;
> break;
> + case 1071:
> + opts.ramdisk = true;
> + break;
> case 'M':
> {
> char *aux;
> @@ -747,6 +751,7 @@ usage:
> " --enable-fs FSNAMES a comma separated list of filesystem names or \"all\".\n"
> " force criu to (try to) dump/restore these filesystem's\n"
> " mountpoints even if fs is not supported.\n"
> +" --ramdisk disable 'pivot_root'.\n"
> "\n"
> "* Logging:\n"
> " -o|--log-file FILE log file name\n"
> diff --git a/include/cr_options.h b/include/cr_options.h
> index eac7283..eb89076 100644
> --- a/include/cr_options.h
> +++ b/include/cr_options.h
> @@ -95,6 +95,7 @@ struct cr_options {
> bool overlayfs;
> size_t ghost_limit;
> struct list_head irmap_scan_paths;
> + bool ramdisk;
> };
>
> extern struct cr_options opts;
> diff --git a/mount.c b/mount.c
> index aea9807..b8f1b26 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -2246,6 +2246,25 @@ static int cr_pivot_root(char *root)
> }
> }
>
> + if (opts.ramdisk) {
cr_pivot_root() is called twice:
1. to switch root of the root mount namespace
2. to switch root of a sub-mount namespace
This code should be executed only for the first case. And pivot_root
should be used to restore sub-namespaces, because it allow to clean up
of extra mounts.
> + if (mount(".", "/", NULL, MS_MOVE, NULL)) {
> + pr_perror("moving . to / failed");
> + return -1;
> + }
> +
> + if (chroot(".")) {
> + pr_perror("chroot . failed");
> + return -1;
> + }
> +
> + if (chdir("/")) {
> + pr_perror("chdir / failed");
> + return -1;
> + }
> +
> + return 0;
> + }
> +
> if (mkdtemp(put_root) == NULL) {
> pr_perror("Can't create a temporary directory");
> return -1;
> --
> 1.9.1
More information about the CRIU
mailing list