From patchwork Thu Jul 23 09:18:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6851891 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AB64C9FD76 for ; Thu, 23 Jul 2015 09:18:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCC2220651 for ; Thu, 23 Jul 2015 09:18:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2D032076A for ; Thu, 23 Jul 2015 09:18:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752501AbbGWJSl (ORCPT ); Thu, 23 Jul 2015 05:18:41 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:29708 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752208AbbGWJS0 (ORCPT ); Thu, 23 Jul 2015 05:18:26 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="98767478" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Jul 2015 17:21:55 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t6N9GQKe025125; Thu, 23 Jul 2015 17:16:26 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 23 Jul 2015 17:18:14 +0800 From: Qu Wenruo To: CC: Subject: [PATCH 4/4] btrfs: convert: Avoid allocating metadata extent crossing stripe boundary Date: Thu, 23 Jul 2015 17:18:10 +0800 Message-ID: <1437643090-13920-5-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <1437643090-13920-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1437643090-13920-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As convert implement its own alloc extent, avoid such metadata problem too. Reported-by: Chris Murphy Reported-by: Zhao Lei Signed-off-by: Zhao Lei Signed-off-by: Qu Wenruo --- btrfs-convert.c | 15 ++++++++++++--- ctree.h | 2 +- extent-tree.c | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/btrfs-convert.c b/btrfs-convert.c index b89c685..c97068e 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -207,7 +207,8 @@ static int cache_free_extents(struct btrfs_root *root, ext2_filsys ext2_fs) } static int custom_alloc_extent(struct btrfs_root *root, u64 num_bytes, - u64 hint_byte, struct btrfs_key *ins) + u64 hint_byte, struct btrfs_key *ins, + int metadata) { u64 start; u64 end; @@ -246,6 +247,14 @@ static int custom_alloc_extent(struct btrfs_root *root, u64 num_bytes, continue; } + if (metadata) { + BUG_ON(num_bytes != root->nodesize); + if (check_crossing_stripes(start, num_bytes)) { + last = round_down(start + num_bytes, + BTRFS_STRIPE_LEN); + continue; + } + } clear_extent_dirty(&root->fs_info->free_space_cache, start, start + num_bytes - 1, 0); @@ -1280,7 +1289,7 @@ static int create_ext2_image(struct btrfs_root *root, ext2_filsys ext2_fs, * special, we can't rely on relocate_extents_range to relocate it. */ for (last_byte = 0; last_byte < first_free; last_byte += sectorsize) { - ret = custom_alloc_extent(root, sectorsize, 0, &key); + ret = custom_alloc_extent(root, sectorsize, 0, &key, 0); if (ret) goto fail; ret = copy_disk_extent(root, key.objectid, last_byte, @@ -1938,7 +1947,7 @@ static int relocate_one_reference(struct btrfs_trans_handle *trans, ret = get_state_private(reloc_tree, bytenr, &new_pos); BUG_ON(ret); } else { - ret = custom_alloc_extent(root, sectorsize, 0, &key); + ret = custom_alloc_extent(root, sectorsize, 0, &key, 0); if (ret) goto fail; new_pos = key.objectid; diff --git a/ctree.h b/ctree.h index 227a00b..bcad2b9 100644 --- a/ctree.h +++ b/ctree.h @@ -946,7 +946,7 @@ struct btrfs_block_group_cache { struct btrfs_extent_ops { int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes, - u64 hint_byte, struct btrfs_key *ins); + u64 hint_byte, struct btrfs_key *ins, int metadata); int (*free_extent)(struct btrfs_root *root, u64 bytenr, u64 num_bytes); }; diff --git a/extent-tree.c b/extent-tree.c index 6f07e4b..0c8152a 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2654,7 +2654,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, if (info->extent_ops) { struct btrfs_extent_ops *ops = info->extent_ops; - ret = ops->alloc_extent(root, num_bytes, hint_byte, ins); + ret = ops->alloc_extent(root, num_bytes, hint_byte, ins, !data); BUG_ON(ret); goto found; }