[CRIU] [PATCH 09/13] mounts: prepare to create a temporary directory for restoring non-root mntns

Pavel Emelyanov xemul at parallels.com
Tue Mar 11 12:45:39 PDT 2014


On 03/11/2014 07:18 PM, Andrey Vagin wrote:
> All non-root namespaces will be restored as sub-trees of the root tree.
> 
> This patch adds helpers to create a temporary directory and mount tmpfs
> in it, then create directories for each non-root mount namespace.
> 
> tmpfs is quite useful here to simplify destroying this construction,
> we don't need to unmount each namespace separately.

Why destroying? Do we optimize the error path?
One comment below.

> @@ -1413,6 +1483,34 @@ static int populate_mnt_ns(int ns_pid, struct mount_info *mis)
>  	return mnt_tree_for_each(pms, do_mount_one);
>  }
>  
> +int fini_mnt_ns()
> +{
> +	char *mnt_roots = get_mnt_roots(false);
> +	int ret = 0;
> +
> +	if (mnt_roots == NULL)
> +		return 0;
> +
> +	if (mount("none", mnt_roots, "none", MS_REC|MS_PRIVATE, NULL)) {
> +		pr_perror("Can't remount root with MS_PRIVATE");
> +		ret = 1;
> +	}
> +	/*
> +	 * Don't exit after a first error, becuase this function
> +	 * can be used to rollback in a error case
> +	 */
> +	if (umount2(mnt_roots, MNT_DETACH)) {

I don't like the MNT_DETACH flag. It creates an impression, that we
just let the mountpoint hang unattached in memory for undefined amount
of time. Why are we sure this will be freed?

> +		pr_perror("Can't unmount %s", mnt_roots);
> +		ret = 1;
> +	}
> +	if (rmdir(mnt_roots)) {
> +		pr_perror("Can't remove the directory %s", mnt_roots);
> +		ret = 1;
> +	}
> +
> +	return ret;
> +}
> +
>  int prepare_mnt_ns(int ns_pid)
>  {
>  	int ret = -1;
> 




More information about the CRIU mailing list