[CRIU] [PATCH 1/3] mount: Handle deleted bindmounts for regular files

Pavel Emelyanov xemul at parallels.com
Tue Sep 1 02:30:02 PDT 2015


On 08/26/2015 05:15 PM, Cyrill Gorcunov wrote:
> Reported-by: Andrey Wagin <avagin at gmail.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Some comment saying why it's enough to stat() on restore time would be good.
And one more comment inline.

> ---
>  mount.c | 35 ++++++++++++++++++++++++++++++-----
>  1 file changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/mount.c b/mount.c
> index 04b99d990bfe..2a2dc7aafc97 100644
> --- a/mount.c
> +++ b/mount.c
> @@ -1970,6 +1970,7 @@ static int do_bind_mount(struct mount_info *mi)
>  {
>  	bool shared = 0;
>  	bool force_private_remount = false;
> +	struct stat st;
>  
>  	if (!mi->need_plugin) {
>  		char *root, *cut_root, rpath[PATH_MAX];
> @@ -1996,9 +1997,26 @@ do_bind:
>  		pr_info("\tBind %s to %s\n", root, mi->mountpoint);
>  
>  		if (unlikely(mi->deleted)) {
> -			if (mkdir(root, 0700)) {
> -				pr_perror("Can't re-create deleted %s\n", root);
> +			if (stat(mi->mountpoint, &st)) {
> +				pr_perror("Can't fetch stat on %s", mi->mountpoint);
>  				return -1;
> +			} else {
> +				if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) {
> +					pr_err("Unsupported st_mode 0%o deleted root %s\n",
> +					       (int)st.st_mode, root);
> +					return -1;
> +				}
> +			}
> +			if (S_ISDIR(st.st_mode)) {
> +				if (mkdir(root, 0700)) {
> +					pr_perror("Can't re-create deleted directory %s\n", root);
> +					return -1;
> +				}
> +			} else if (S_ISREG(st.st_mode)) {
> +				if (open(root, O_WRONLY | O_CREAT | O_TRUNC, 0644) < 0) {
> +					pr_perror("Can't re-create deleted file %s\n", root);
> +					return -1;
> +				}
>  			}

Too complicated :) Why not just

   if (stat()) {
          error();
          return -1;
   }

   if (S_ISDIR())
          mkdir();
   else if (S_ISREG())
          open();
   else {
        error();
        return -1;
   }

?

>  		}
>  
> @@ -2008,9 +2026,16 @@ do_bind:
>  		}
>  
>  		if (unlikely(mi->deleted)) {
> -			if (rmdir(root)) {
> -				pr_perror("Can't remove deleted %s\n", root);
> -				return -1;
> +			if (S_ISDIR(st.st_mode)) {
> +				if (rmdir(root)) {
> +					pr_perror("Can't remove deleted directory %s\n", root);
> +					return -1;
> +				}
> +			} else if (S_ISREG(st.st_mode)) {
> +				if (unlink(root)) {
> +					pr_perror("Can't unlink deleted file %s\n", root);
> +					return -1;
> +				}
>  			}
>  		}
>  	} else {
> 



More information about the CRIU mailing list