From patchwork Wed Aug 24 06:13:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 1091072 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7O6CtIA023485 for ; Wed, 24 Aug 2011 06:12:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752704Ab1HXGMx (ORCPT ); Wed, 24 Aug 2011 02:12:53 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:62147 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751024Ab1HXGMw (ORCPT ); Wed, 24 Aug 2011 02:12:52 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 762F217010C; Wed, 24 Aug 2011 14:12:41 +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 p7O6CdTH027476; Wed, 24 Aug 2011 14:12:40 +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 2011082414113995-29054 ; Wed, 24 Aug 2011 14:11:39 +0800 Message-ID: <4E54967C.5020205@cn.fujitsu.com> Date: Wed, 24 Aug 2011 14:13:16 +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: calc file extent num_bytes correctly 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:40, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2011-08-24 14:11:40, Serialize complete at 2011-08-24 14:11:40 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 (demeter1.kernel.org [140.211.167.41]); Wed, 24 Aug 2011 06:13:20 +0000 (UTC) # touch /mnt/dst # clone_range -s 8192 -l 4096 /mnt/src /mnt/dst # ls -l /mnt/dst -rw-r--r-- 1 root root 4096 dst # umount /mnt # btrfs-debug-tree /dev/sda7 ... item 11 key (258 EXTENT_DATA 0) itemoff 3230 itemsize 53 extent data disk byte 12582912 nr 49152 extent data offset 8192 nr 12288 ram 49152 extent compression 0 num_bytes should be 4096 not 12288. Signed-off-by: Li Zefan --- fs/btrfs/ioctl.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 660a6c8..3351b1b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2331,14 +2331,21 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, if (type == BTRFS_FILE_EXTENT_REG || type == BTRFS_FILE_EXTENT_PREALLOC) { + /* + * a | --- range to clone ---| b + * | ------------- extent ------------- | + */ + + /* substract range b */ + if (key.offset + datal > off + len) + datal = off + len - key.offset; + + /* substract range a */ if (off > key.offset) { datao += off - key.offset; datal -= off - key.offset; } - if (key.offset + datal > off + len) - datal = off + len - key.offset; - ret = btrfs_drop_extents(trans, inode, new_key.offset, new_key.offset + datal,