From patchwork Wed Aug 24 06:13:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 1091062 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7O6Ch0t015067 for ; Wed, 24 Aug 2011 06:12:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750952Ab1HXGMk (ORCPT ); Wed, 24 Aug 2011 02:12:40 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:63569 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750795Ab1HXGMk (ORCPT ); Wed, 24 Aug 2011 02:12:40 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id A9C37170124; Wed, 24 Aug 2011 14:12:37 +0800 (CST) Received: from mailserver.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id p7O6CaRq027464; Wed, 24 Aug 2011 14:12:36 +0800 Received: from [10.167.225.230] ([10.167.225.230]) by mailserver.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2011082414113634-29053 ; Wed, 24 Aug 2011 14:11:36 +0800 Message-ID: <4E549679.3010807@cn.fujitsu.com> Date: Wed, 24 Aug 2011 14:13:13 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc14 Thunderbird/3.1.4 MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: Sage Weil Subject: [PATCH] Btrfs: add dummy extent if dst offset excceeds file end in file clone X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-24 14:11:36, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-24 14:11:37, Serialize complete at 2011-08-24 14:11:37 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 24 Aug 2011 06:12:43 +0000 (UTC) # 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 --- 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) {