linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: add dummy extent if dst offset excceeds file end in file clone
@ 2011-08-24  6:13 Li Zefan
  0 siblings, 0 replies; only message in thread
From: Li Zefan @ 2011-08-24  6:13 UTC (permalink / raw)
  To: linux-btrfs@vger.kernel.org; +Cc: Sage Weil

 # touch /mnt/dst
 # clone_range -d 4096 /mnt/src /mnt/dst
 # umount /mnt
 # btrfs-debug-tree /dev/sda7
 ...
        item 10 key (258 INODE_REF 256) itemoff 3283 itemsize 13
                inode ref index 3 namelen 3 name: tmp
        item 11 key (258 EXTENT_DATA 4096) itemoff 3230 itemsize 53
                extent data disk byte 12632064 nr 49152
                extent data offset 0 nr 49152 ram 49152
                extent compression 0

You can see there's no file extent with range [0, 4096]. Check this by
btrfsck:

 # btrfsck /dev/sda7
 root 5 inode 258 errors 100
 ...

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

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 970977a..660a6c8 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2220,6 +2220,12 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
 	    !IS_ALIGNED(destoff, bs))
 		goto out_unlock;
 
+	if (destoff > inode->i_size) {
+		ret = btrfs_cont_expand(inode, inode->i_size, destoff);
+		if (ret)
+			goto out_unlock;
+	}
+
 	/* do any pending delalloc/csum calc on src, one way or
 	   another, and lock file content */
 	while (1) {
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-24  6:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-24  6:13 [PATCH] Btrfs: add dummy extent if dst offset excceeds file end in file clone Li Zefan

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).