[CRIU] [PATCH 1/3] mount: cut a common part of sources for bind-mounts

Pavel Emelyanov xemul at parallels.com
Thu Apr 10 04:05:28 PDT 2014


On 04/10/2014 02:52 PM, Andrey Vagin wrote:

A couple of examples and "What for?" answer would form nice comment.

> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  mount.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/mount.c b/mount.c
> index 3a37033..c7fba51 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -1137,11 +1137,22 @@ static int restore_ext_mount(struct mount_info *mi)
>  
>  static int do_bind_mount(struct mount_info *mi)
>  {
> -	char rpath[PATH_MAX];
>  	bool shared = mi->shared_id && mi->shared_id == mi->bind->shared_id;
>  
>  	if (!mi->need_plugin) {
> -		snprintf(rpath, sizeof(rpath), "%s%s", mi->bind->mountpoint, mi->root);
> +		char rpath[PATH_MAX];
> +		int tok = 0;
> +
> +		/* Cut common part of root */
> +		while (mi->root[tok] == mi->bind->root[tok]) {
> +			tok++;
> +			if (mi->bind->root[tok] == '\0')
> +				break;
> +			BUG_ON(mi->root[tok] == '\0');
> +		}
> +
> +		snprintf(rpath, sizeof(rpath), "%s/%s",
> +				mi->bind->mountpoint, mi->root + tok);
>  		pr_info("\tBind %s to %s\n", rpath, mi->mountpoint);
>  
>  		if (mount(rpath, mi->mountpoint, NULL,
> 




More information about the CRIU mailing list