linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sage Weil <sage@newdream.net>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file
Date: Mon, 22 Nov 2010 11:09:34 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.1011221108170.2462@cobra.newdream.net> (raw)
In-Reply-To: <4CE5D48A.6090009@cn.fujitsu.com>

On Fri, 19 Nov 2010, Li Zefan wrote:
> We've done the check for src_offset and src_length, and We should
> also check dest_offset, otherwise we'll corrupt the destination
> file:
> 
>   (After cloning file1 to file2 with unaligned dest_offset)
>   # cat /mnt/file2
>   cat: /mnt/file2: Input/output error
> 
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
>  fs/btrfs/ioctl.c |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 463d91b..81b47bd 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1669,12 +1669,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
>  		olen = len = src->i_size - off;
>  	/* if we extend to eof, continue to block boundary */
>  	if (off + len == src->i_size)
> -		len = ((src->i_size + bs-1) & ~(bs-1))
> -			- off;
> +		len = ALIGN(src->i_size, bs) - off;
>  
>  	/* verify the end result is block aligned */
> -	if ((off & (bs-1)) ||
> -	    ((off + len) & (bs-1)))
> +	if (!IS_ALIGNED(off, bs) || !IS_ALIGNED(off + len, bs) ||
> +	    !IS_ALIGNED(destoff, bs))
>  		goto out_unlock;
>  
>  	/* do any pending delalloc/csum calc on src, one way or

Looks good.

Reviewed-by: Sage Weil <sage@newdream.net>


      parent reply	other threads:[~2010-11-22 19:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-19  1:36 [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file Li Zefan
2010-11-19  1:36 ` [PATCH 2/2] btrfs: Set file size correctly in file clone Li Zefan
2010-11-22 19:10   ` Sage Weil
2010-11-22 19:09 ` Sage Weil [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.1011221108170.2462@cobra.newdream.net \
    --to=sage@newdream.net \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).