All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file
@ 2010-11-19  1:36 Li Zefan
  2010-11-19  1:36 ` [PATCH 2/2] btrfs: Set file size correctly in file clone Li Zefan
  2010-11-22 19:09 ` [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file Sage Weil
  0 siblings, 2 replies; 4+ messages in thread
From: Li Zefan @ 2010-11-19  1:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: sage

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
-- 
1.6.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs: Set file size correctly in file clone
  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 ` Li Zefan
  2010-11-22 19:10   ` Sage Weil
  2010-11-22 19:09 ` [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file Sage Weil
  1 sibling, 1 reply; 4+ messages in thread
From: Li Zefan @ 2010-11-19  1:36 UTC (permalink / raw)
  To: linux-btrfs; +Cc: sage

Set src_offset = 0, src_length = 20K, dest_offset = 20K. And the
original filesize of the dest file 'file2' is 30K:

  # ls -l /mnt/file2
  -rw-r--r-- 1 root root 30720 Nov 18 16:42 /mnt/file2

Now clone file1 to file2, the dest file should be 40K, but it
still shows 30K:

  # ls -l /mnt/file2
  -rw-r--r-- 1 root root 30720 Nov 18 16:42 /mnt/file2

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 fs/btrfs/ioctl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 81b47bd..6b4bfa7 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1873,8 +1873,8 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
 			 * but shouldn't round up the file size
 			 */
 			endoff = new_key.offset + datal;
-			if (endoff > off+olen)
-				endoff = off+olen;
+			if (endoff > destoff+olen)
+				endoff = destoff+olen;
 			if (endoff > inode->i_size)
 				btrfs_i_size_write(inode, endoff);
 
-- 
1.6.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file
  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:09 ` Sage Weil
  1 sibling, 0 replies; 4+ messages in thread
From: Sage Weil @ 2010-11-22 19:09 UTC (permalink / raw)
  To: Li Zefan; +Cc: linux-btrfs

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>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] btrfs: Set file size correctly in file clone
  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
  0 siblings, 0 replies; 4+ messages in thread
From: Sage Weil @ 2010-11-22 19:10 UTC (permalink / raw)
  To: Li Zefan; +Cc: linux-btrfs

On Fri, 19 Nov 2010, Li Zefan wrote:
> Set src_offset = 0, src_length = 20K, dest_offset = 20K. And the
> original filesize of the dest file 'file2' is 30K:
> 
>   # ls -l /mnt/file2
>   -rw-r--r-- 1 root root 30720 Nov 18 16:42 /mnt/file2
> 
> Now clone file1 to file2, the dest file should be 40K, but it
> still shows 30K:
> 
>   # ls -l /mnt/file2
>   -rw-r--r-- 1 root root 30720 Nov 18 16:42 /mnt/file2
> 
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
>  fs/btrfs/ioctl.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 81b47bd..6b4bfa7 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1873,8 +1873,8 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
>  			 * but shouldn't round up the file size
>  			 */
>  			endoff = new_key.offset + datal;
> -			if (endoff > off+olen)
> -				endoff = off+olen;
> +			if (endoff > destoff+olen)
> +				endoff = destoff+olen;
>  			if (endoff > inode->i_size)
>  				btrfs_i_size_write(inode, endoff);

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-11-22 19:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 1/2] btrfs: Check if dest_offset is block-size aligned before cloning file Sage Weil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.