From patchwork Wed Jul 6 10:37:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoguang Wang X-Patchwork-Id: 9216057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8330C60467 for ; Wed, 6 Jul 2016 10:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 745652880F for ; Wed, 6 Jul 2016 10:40:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68AE228816; Wed, 6 Jul 2016 10:40:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 607062880F for ; Wed, 6 Jul 2016 10:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753076AbcGFKkK (ORCPT ); Wed, 6 Jul 2016 06:40:10 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:11906 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1753039AbcGFKkJ (ORCPT ); Wed, 6 Jul 2016 06:40:09 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="657568" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 06 Jul 2016 18:40:02 +0800 Received: from localhost.localdomain (unknown [10.167.226.107]) by cn.fujitsu.com (Postfix) with ESMTP id CD0284056401; Wed, 6 Jul 2016 18:40:00 +0800 (CST) From: Wang Xiaoguang To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 1/2] btrfs: use correct offset for reloc_inode in prealloc_file_extent_cluster() Date: Wed, 6 Jul 2016 18:37:52 +0800 Message-Id: <20160706103753.4908-1-wangxg.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: CD0284056401.AED4A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wangxg.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In prealloc_file_extent_cluster(), btrfs_check_data_free_space() uses wrong file offset for reloc_inode, it uses cluster->start and cluster->end, which indeed are extent's bytenr. The correct value should be cluster->[start|end] minus block group's start bytenr. start bytenr cluster->start | | extent | extent | ...| extent | |----------------------------------------------------------------| | block group reloc_inode | Signed-off-by: Wang Xiaoguang --- fs/btrfs/relocation.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 0477dca..abc2f69 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3030,34 +3030,37 @@ int prealloc_file_extent_cluster(struct inode *inode, u64 num_bytes; int nr = 0; int ret = 0; + u64 prealloc_start, prealloc_end; BUG_ON(cluster->start != cluster->boundary[0]); inode_lock(inode); - ret = btrfs_check_data_free_space(inode, cluster->start, - cluster->end + 1 - cluster->start); + start = cluster->start - offset; + end = cluster->end - offset; + ret = btrfs_check_data_free_space(inode, start, end + 1 - start); if (ret) goto out; while (nr < cluster->nr) { - start = cluster->boundary[nr] - offset; + prealloc_start = cluster->boundary[nr] - offset; if (nr + 1 < cluster->nr) - end = cluster->boundary[nr + 1] - 1 - offset; + prealloc_end = cluster->boundary[nr + 1] - 1 - offset; else - end = cluster->end - offset; + prealloc_end = cluster->end - offset; - lock_extent(&BTRFS_I(inode)->io_tree, start, end); - num_bytes = end + 1 - start; - ret = btrfs_prealloc_file_range(inode, 0, start, + lock_extent(&BTRFS_I(inode)->io_tree, prealloc_start, + prealloc_end); + num_bytes = prealloc_end + 1 - prealloc_start; + ret = btrfs_prealloc_file_range(inode, 0, prealloc_start, num_bytes, num_bytes, - end + 1, &alloc_hint); - unlock_extent(&BTRFS_I(inode)->io_tree, start, end); + prealloc_end + 1, &alloc_hint); + unlock_extent(&BTRFS_I(inode)->io_tree, prealloc_start, + prealloc_end); if (ret) break; nr++; } - btrfs_free_reserved_data_space(inode, cluster->start, - cluster->end + 1 - cluster->start); + btrfs_free_reserved_data_space(inode, start, end + 1 - start); out: inode_unlock(inode); return ret;