[CRIU] [PATCH 03/13] mounts: allow to customize root path for cr_pivot_root

Pavel Emelyanov xemul at parallels.com
Wed Apr 9 04:54:55 PDT 2014


On 04/09/2014 04:13 AM, Andrey Vagin wrote:
> We are going to restore nested mount namespaces and we will need to
> change root for each of them.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  mount.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/mount.c b/mount.c
> index a89342d..4844967 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -1262,11 +1262,16 @@ static int clean_mnt_ns(void)
>  	return mnt_tree_for_each_reverse(mntinfo_tree, do_umount_one);
>  }
>  
> -static int cr_pivot_root(void)
> +static int cr_pivot_root(char *root)
>  {
>  	char put_root[] = "crtools-put-root.XXXXXX";
>  
> -	pr_info("Move the root to %s\n", opts.root);
> +	pr_info("Move the root to %s\n", root);
> +
> +	if (chdir(root)) {

This will lead to strange effects if root is relative. We already
have one chdir() in prepare_mnt_ns() before calling this one.

> +		pr_perror("chdir(%s) failed", root);
> +		return -1;
> +	}
>  
>  	if (mkdtemp(put_root) == NULL) {
>  		pr_perror("Can't create a temporary directory");
> @@ -1285,6 +1290,11 @@ static int cr_pivot_root(void)
>  		return -1;
>  	}
>  
> +	if (mount("none", put_root, "none", MS_REC|MS_PRIVATE, NULL)) {

There's already one right above.

> +		pr_perror("Can't remount root with MS_PRIVATE");
> +		return -1;
> +	}
> +
>  	if (umount2(put_root, MNT_DETACH)) {
>  		pr_perror("Can't umount %s", put_root);
>  		return -1;
> @@ -1504,7 +1514,7 @@ int prepare_mnt_ns(int ns_pid)
>  		goto out;
>  
>  	if (opts.root)
> -		ret = cr_pivot_root();
> +		ret = cr_pivot_root(opts.root);
>  out:
>  	return ret;
>  }
> 




More information about the CRIU mailing list