Btrfs: add dummy extent if dst offset excceeds file end in
authorLi Zefan <lizf@cn.fujitsu.com>
Sun, 11 Sep 2011 14:52:25 +0000 (10:52 -0400)
committerChris Mason <chris.mason@oracle.com>
Sun, 11 Sep 2011 14:52:25 +0000 (10:52 -0400)
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>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ioctl.c

index 028a4b8c12cdbebd2fbaf272cf6f859d9b39ebf1..63b4de1626d221e012b7bf5a1a86cf058350019e 100644 (file)
@@ -2228,6 +2228,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) {