[CRIU] [PATCH 3/9] mntns: pivot_root() can move the current root to a non-shared mount

Andrew Vagin avagin at parallels.com
Tue Oct 28 00:45:35 PDT 2014


On Mon, Oct 27, 2014 at 10:21:05PM +0400, Pavel Emelyanov wrote:
> On 10/23/2014 05:49 PM, Andrey Vagin wrote:
> > So we need to create a temporary private mount for the old root.
> > 
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> >  mount.c | 27 +++++++++++++++++++++++----
> >  1 file changed, 23 insertions(+), 4 deletions(-)
> > 
> > diff --git a/mount.c b/mount.c
> > index 07f6db4..ac89baa 100644
> > --- a/mount.c
> > +++ b/mount.c
> > @@ -1465,6 +1465,7 @@ static int clean_mnt_ns(struct mount_info *mntinfo_tree)
> >  static int cr_pivot_root(char *root)
> >  {
> >  	char put_root[] = "crtools-put-root.XXXXXX";
> > +	int exit_code = -1;
> >  
> >  	pr_info("Move the root to %s\n", root ? : ".");
> >  
> > @@ -1480,11 +1481,19 @@ static int cr_pivot_root(char *root)
> >  		return -1;
> >  	}
> >  
> > +	if (mount(put_root, put_root, NULL, MS_BIND, NULL)) {
> 
> I have a subtle feeling that we've discussed that already. Shouldn't the
> MS_REC be here? Otherwise we loose any mountpoints below the --root one.

pivot_root(new_root, put_old)

It was about new_root. put_old is a temporary directory, which is
created in this function.

> 
> > +		pr_perror("Unable to mount tmpfs in %s", put_root);
> > +		goto err_root;
> > +	}
> > +
> > +	if (mount(NULL, put_root, NULL, MS_PRIVATE, NULL)) {
> > +		pr_perror("Can't remount %s with MS_PRIVATE", put_root);
> > +		goto err_tmpfs;
> > +	}
> > +
> >  	if (pivot_root(".", put_root)) {
> >  		pr_perror("pivot_root(., %s) failed", put_root);
> > -		if (rmdir(put_root))
> > -			pr_perror("Can't remove the directory %s", put_root);
> > -		return -1;
> > +		goto err_tmpfs;
> >  	}
> >  
> >  	if (mount("none", put_root, "none", MS_REC|MS_PRIVATE, NULL)) {
> > @@ -1492,16 +1501,26 @@ static int cr_pivot_root(char *root)
> >  		return -1;
> >  	}
> >  
> > +	exit_code = 0;
> > +
> >  	if (umount2(put_root, MNT_DETACH)) {
> >  		pr_perror("Can't umount %s", put_root);
> >  		return -1;
> >  	}
> > +
> > +err_tmpfs:
> > +	if (umount2(put_root, MNT_DETACH)) {
> > +		pr_perror("Can't umount %s", put_root);
> > +		return -1;
> > +	}
> > +
> > +err_root:
> >  	if (rmdir(put_root)) {
> >  		pr_perror("Can't remove the directory %s", put_root);
> >  		return -1;
> >  	}
> >  
> > -	return 0;
> > +	return exit_code;
> >  }
> >  
> >  struct mount_info *mnt_entry_alloc()
> > 
> 


More information about the CRIU mailing list