From patchwork Wed Jun 29 14:41:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E240C433EF for ; Wed, 29 Jun 2022 14:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233545AbiF2Ol0 (ORCPT ); Wed, 29 Jun 2022 10:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232481AbiF2OlZ (ORCPT ); Wed, 29 Jun 2022 10:41:25 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D75313A734 for ; Wed, 29 Jun 2022 07:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513682; x=1688049682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fUuoIhB/O5nhEZHplhJZf6apHnNDub5hbyfqTcihtLI=; b=CBIBuGSOuH3NJWcxhbd3KH9R6up3inRCmd/zfxQQo0AxMeFDTmj8YDy4 vmF8zxSwUelgT4hrL2EU+BLQOOwBMwdf6Fmd+SB91kbxHuLqc7fYS/3GW eisDg4DQQUDiTygMIPpkgpzdwysnWY5Y06/oLFilRFLiUeZj+szXlb4We u9xTh5+P78cYgOkOiskHIYJGxr3KPQokYJGHiTM0hvyIrHj/ybYsfRFz1 CsDbCSw8JvzwvaIP3Tk2Q16hTyMk0VjHAurluHqwtc/XafN8KlvxpeG+P FvCYO+rIe5w3XR0VM9upa40b9Ipl+qKesq1got7vUNPW9uVdVzXbD5Cwi Q==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064882" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:22 +0800 IronPort-SDR: miGwLkT9+gJThNJTj/KIpZA0YiuN7AAsF0rJxwTfv1yPiw/9CbQBgVmaALrD7ndM5mwFiAOl59 H1F8I5NMmMS3+RaRE+t81ySqHZ8RkK8gfDGn47LzJQEPA04uxX+rQbHYzyr8U5Vvdn0iRyIlbN xXTcK5ADk+1yIN19eFg/4NlI2nakzvYWDQMJzWCoMvJiTRJk4GbUYsTQN6yiJGs3tBtpRNzHus 3hcLFAadeumnvUxXvYfm1uzBJMDP60EoJlNcu7c2jU0yOUqRRihMgiPBSi3uNy2kOPhfHZgnVV j6Ha2brsviMRuGEzzosrlqRM Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:00 -0700 IronPort-SDR: E3hU26Qcle2HMvVr+7K5GY28DauPegHuFgVak1iXP8VOS92sz0KH4TGU4Y/Yn/qKAcJCZNc20N VCNptoOahgGy6eG5VH3CQMlJTcQibN0YrGDix1g8izHk3FUS5T4F+JWPh2aUFWiLILs1mvdx+l uPXwH6N7KsE5DzUCQ9cQVfcQm7QhWj2WuKlrz66P+qMjj8FlMZE/3z71/HrZcelMDShsB3BuAs poXGbQG6K5nqTVcmKbKdRIaAsi+cBKjsMrFNWXSWwk5vSkS7Bv9yzgL5u5lH22uSraTTbUwZRb U5o= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:21 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 1/8] btrfs: add raid stripe tree definitions Date: Wed, 29 Jun 2022 07:41:07 -0700 Message-Id: <1ca2b7b2f61b32caae125e4001f83620fa1ddd0c.1656513330.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add definitions for the raid-stripe-tree. This tree will hold informatioin about the on-disk layout of the stripes in a RAID set. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.h | 29 +++++++++++++++++++++++++++++ include/uapi/linux/btrfs_tree.h | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 4e2569f84aab..18e2f186cb5e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1906,6 +1906,35 @@ BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); +BTRFS_SETGET_FUNCS(stripe_extent_devid, struct btrfs_stripe_extent, devid, 64); +BTRFS_SETGET_FUNCS(stripe_extent_physical, struct btrfs_stripe_extent, physical, 64); +BTRFS_SETGET_STACK_FUNCS(stack_stripe_extent_devid, struct btrfs_stripe_extent, devid, 64); +BTRFS_SETGET_STACK_FUNCS(stack_stripe_extent_physical, struct btrfs_stripe_extent, physical, 64); + +static inline struct btrfs_stripe_extent *btrfs_stripe_extent_nr( + struct btrfs_dp_stripe *dps, int nr) +{ + unsigned long offset = (unsigned long)dps; + + offset += offsetof(struct btrfs_dp_stripe, extents); + offset += nr * sizeof(struct btrfs_stripe_extent); + return (struct btrfs_stripe_extent *)offset; +} + +static inline u64 btrfs_stripe_extent_devid_nr(const struct extent_buffer *eb, + struct btrfs_dp_stripe *dps, + int nr) +{ + return btrfs_stripe_extent_devid(eb, btrfs_stripe_extent_nr(dps, nr)); +} + +static inline u64 btrfs_stripe_extent_physical_nr(const struct extent_buffer *eb, + struct btrfs_dp_stripe *dps, + int nr) +{ + return btrfs_stripe_extent_physical(eb, btrfs_stripe_extent_nr(dps, nr)); +} + /* struct btrfs_dev_extent */ BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index d4117152d907..070fc9266821 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -56,6 +56,9 @@ /* Holds the block group items for extent tree v2. */ #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL +/* tracks RAID stripes in block groups. */ +#define BTRFS_RAID_STRIPE_TREE_OBJECTID 12ULL + /* device stats in the device tree */ #define BTRFS_DEV_STATS_OBJECTID 0ULL @@ -264,6 +267,8 @@ */ #define BTRFS_QGROUP_RELATION_KEY 246 +#define BTRFS_RAID_STRIPE_KEY 247 + /* * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */ @@ -488,6 +493,18 @@ struct btrfs_free_space_header { __le64 num_bitmaps; } __attribute__ ((__packed__)); +struct btrfs_stripe_extent { + /* btrfs device-id this raid extent lives on */ + __le64 devid; + /* physical location on disk */ + __le64 physical; +} __attribute__ ((__packed__)); + +struct btrfs_dp_stripe { + /* array of stripe extents this stripe is composed of */ + DECLARE_FLEX_ARRAY(struct btrfs_stripe_extent, extents); +} __attribute__ ((__packed__)); + #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) From patchwork Wed Jun 29 14:41:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F1DC43334 for ; Wed, 29 Jun 2022 14:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbiF2Ol1 (ORCPT ); Wed, 29 Jun 2022 10:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233502AbiF2OlZ (ORCPT ); Wed, 29 Jun 2022 10:41:25 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8CA43AA54 for ; Wed, 29 Jun 2022 07:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513683; x=1688049683; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ia25dKYcIFBFcqSMdu6uFLjvDsqOwLPJ9BKxl66x2rE=; b=DIAUaVslKpZJ9OwbRoMpyUMsfIfKAoy3zizvChYubDLiffVhSZkCJl9h 916x5bJqH7690Obhio8S6qG1pnRNXgG4roxUyETchRWCQV5uOx1SAvgRx VZq7hTZWspSR89/c9c+0Rfyda8MWY1CQLmKL0Ym2Ljx6T0EMfTlY4lOmS Y7XHe9e7kf7uRWu3Xd+jkyFR7pPFOOTsQgV901qcqZBUiPc5Xva5zBfp1 hjLMX8s1Izk2yvE5jGyhbJx0ei9UcdQqQq3mm/131Gq2p003dohWLug4l 6Zak325oUN93+mfYLkaoMkTsNPBk3I5imTQw+zBQDIj2K4qu2diWrpHJC w==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064885" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:23 +0800 IronPort-SDR: NYAdobrUp+Hg2DC5d07DU69TvHGS7nwtTvBACMnxw2ihCNXJjyhAOSGhDD8EQDQfccPTdnd9vf j9INC38KyRWDUF6sc1jyRmfw9PVW2SvVi0E5taPJ5bRmfSSKlRSb3tLrSSGiK+m/SM1Kj0SOdo R5X1neqMnKg0QjiWQz1EoOC8ZqoUbASWLXZ+fCajuk1upoG89HilOu9wW5LUTwYZFmfVAe6h1h fvSaPB6rg699h9XCDRKzBSgI8DRfFaCsgPZ3HJfNLpB66iqiHqCqoMG4EviR5eKtuTOR/BJFfi Ybq+J4I7yxqmh49pFnzBzKaG Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:02 -0700 IronPort-SDR: gtDHrYIN20j4rt2r6v2P9AIUm5lgytUWHhXk365FgBjKFfXMQnK+I0fICH6SsY72/8sRT1SSqc 0NNhy6Dfsx6XUwIuC0R5bYntVJXqHhbK0kRw0YcUWsSQhwZBMTSwJK1sFXF+V+ork6L5k0JslI a04zWoo+qhxZVsHQG6cVXiQ/ZgXgxHKwqoHrEbYc8kM4opk5BY0B9nR9eOPzf0orzDB87568sn H6kMOsK2riAzarxBH5ZJw+EpvsuP6phC4Q5boAX0w/8Okb8uULzeC3qUIwBgKDUes4dArAZCjb 5oQ= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:22 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 2/8] btrfs: read raid-stripe-tree from disk Date: Wed, 29 Jun 2022 07:41:08 -0700 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we find a raid-stripe-tree on mount, read it from disk. Signed-off-by: Johannes Thumshirn --- fs/btrfs/block-rsv.c | 1 + fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 12 ++++++++++++ include/uapi/linux/btrfs.h | 1 + 4 files changed, 15 insertions(+) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index b3ee49b0b1e8..62c20c9d8c25 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -427,6 +427,7 @@ void btrfs_init_root_block_rsv(struct btrfs_root *root) case BTRFS_CSUM_TREE_OBJECTID: case BTRFS_EXTENT_TREE_OBJECTID: case BTRFS_FREE_SPACE_TREE_OBJECTID: + case BTRFS_RAID_STRIPE_TREE_OBJECTID: root->block_rsv = &fs_info->delayed_refs_rsv; break; case BTRFS_ROOT_TREE_OBJECTID: diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 18e2f186cb5e..376b9b112429 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -690,6 +690,7 @@ struct btrfs_fs_info { struct btrfs_root *uuid_root; struct btrfs_root *data_reloc_root; struct btrfs_root *block_group_root; + struct btrfs_root *stripe_root; /* the log root tree is a directory of all the other log roots */ struct btrfs_root *log_root_tree; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 70b388de4d66..45d1ea23a230 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1607,6 +1607,9 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info, return btrfs_grab_root(root) ? root : ERR_PTR(-ENOENT); } + if (objectid == BTRFS_RAID_STRIPE_TREE_OBJECTID) + return btrfs_grab_root(fs_info->stripe_root) ? + fs_info->stripe_root : ERR_PTR(-ENOENT); return NULL; } @@ -1679,6 +1682,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) btrfs_put_root(fs_info->fs_root); btrfs_put_root(fs_info->data_reloc_root); btrfs_put_root(fs_info->block_group_root); + btrfs_put_root(fs_info->stripe_root); btrfs_check_leaked_roots(fs_info); btrfs_extent_buffer_leak_debug_check(fs_info); kfree(fs_info->super_copy); @@ -2220,6 +2224,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root) free_root_extent_buffers(info->fs_root); free_root_extent_buffers(info->data_reloc_root); free_root_extent_buffers(info->block_group_root); + free_root_extent_buffers(info->stripe_root); if (free_chunk_root) free_root_extent_buffers(info->chunk_root); } @@ -2646,6 +2651,13 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) fs_info->uuid_root = root; } + location.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root = btrfs_read_tree_root(tree_root, &location); + if (!IS_ERR(root)) { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->stripe_root = root; + } + return 0; out: btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index f54dc91e4025..5ca789af5beb 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -310,6 +310,7 @@ struct btrfs_ioctl_fs_info_args { #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) +#define BTRFS_FEATURE_INCOMPAT_STRIPE_TREE (1ULL << 14) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Wed Jun 29 14:41:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 566FECCA47E for ; Wed, 29 Jun 2022 14:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233502AbiF2Ol1 (ORCPT ); Wed, 29 Jun 2022 10:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbiF2Ol0 (ORCPT ); Wed, 29 Jun 2022 10:41:26 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F13739148 for ; Wed, 29 Jun 2022 07:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513684; x=1688049684; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LQB17tOGq+Hu5Iab9EgPjnToHNtf6W5Fg2/gQJcppuw=; b=eXfCfMIe57r7mpK/L9DicYjHY0dWBvoVdJqF8hDIrIpLVNUvdOOahSF+ /dUNIZ2hvAKirfLhqviJgDsQym6fx3/mk3YO0NZeQmuMea74aDQf0Zj3C HLRwkEHEl2U7Tz8Fy+/qj1gz9hHqticQwRnlUVu9jE8V95n6hjzxBvYK0 XjWdo2fihVzlHPALxlqJh5KbI8iaCMkSiWxwgaqUEJ7SqakPH/i4LMyhK YlYVz+xYsTdHygDesyIR4f1aSofdKpFOhAslc8IWt3xpLhcOvaLg41TXZ 5mere0Uv4cmkYUskG1wS101lPoLwel8phyrYQslU1JZmMJ3ACMRY2X1WD g==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064888" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:24 +0800 IronPort-SDR: BlNJYpPMcLn3ePD7oNamKRD+zX3ZlIixleD/n9+detrvrcc2FDnOVWbWMoIqFGuXXI2ZZp2838 yU3vSJao6Z1csQAd77eQvREk4Fivpu37keiIzaeIySCed3aTi3qCchgEVfs54cV/SJxzFvr14B Y3yMufzdSAvTThOBwiStLzkD8Q8Vuwip0KLIH0UoVqfw9DYG9Fe9YQi4XjRtdwdHvCnRukBQ1j EJ8qQrZL98MJElNgQ+eyTqGQuP0SfwrW+fg4o25eLV35zM7AjAUDjKGg+/apUVJKHsCef9ODA+ naDI34d4VbDDf3lNexNFlJvk Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:03 -0700 IronPort-SDR: vktyign7enex1f62mWBAcGJsTUMO5j5FXsRetjQpec+ORNKjGioTSC09X29C9lZDOk7DHRwy23 NGsEOmW/OCQO2YZQrroojgiGiqalZPrxqRwQK66MDgy66IVp0/GAcdi4yHomUJSQHW2QAWgy10 hU3NCkjRiSp93jS0/N9wfnxRxoX+Gyij5jc/ji8L8QVYMaLlBBLAAC8/+nHarRI6CYeaAW4BRV Wtg9/tC3oE+zAEz9VvdQVU6PmLdil4rhVybDvVmCsmbujJw1L5/TILnsUcERpVz/ETQMvqywcN I7k= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:24 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 3/8] btrfs: add boilerplate code to insert raid extent Date: Wed, 29 Jun 2022 07:41:09 -0700 Message-Id: <9ee306b29058d042b4eac3e04c58c383e89d3dc6.1656513330.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to insert raid extents into the raid-stripe-tree on each write to a RAID1 block-group. Signed-off-by: Johannes Thumshirn --- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 3 + fs/btrfs/disk-io.c | 3 + fs/btrfs/extent-tree.c | 45 +++++++++ fs/btrfs/raid-stripe-tree.c | 188 ++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 65 +++++++++++++ fs/btrfs/volumes.c | 13 +++ fs/btrfs/volumes.h | 4 + fs/btrfs/zoned.c | 4 + 9 files changed, 326 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/raid-stripe-tree.c create mode 100644 fs/btrfs/raid-stripe-tree.h diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 99f9995670ea..4484831ac624 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -31,7 +31,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \ - subpage.o tree-mod-log.o + subpage.o tree-mod-log.o raid-stripe-tree.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 376b9b112429..2eb79afb4d83 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1092,6 +1092,9 @@ struct btrfs_fs_info { /* Updates are not protected by any lock */ struct btrfs_commit_stats commit_stats; + struct mutex stripe_update_lock; + struct rb_root stripe_update_tree; + #ifdef CONFIG_BTRFS_FS_REF_VERIFY spinlock_t ref_verify_lock; struct rb_root block_tree; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 45d1ea23a230..3d7c1b8d1cd5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3155,6 +3155,9 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) fs_info->bg_reclaim_threshold = BTRFS_DEFAULT_RECLAIM_THRESH; INIT_WORK(&fs_info->reclaim_bgs_work, btrfs_reclaim_bgs_work); + + mutex_init(&fs_info->stripe_update_lock); + fs_info->stripe_update_tree = RB_ROOT; } static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f97a0f28f464..e1738b3dfb21 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -36,6 +36,7 @@ #include "rcu-string.h" #include "zoned.h" #include "dev-replace.h" +#include "raid-stripe-tree.h" #undef SCRAMBLE_DELAYED_REFS @@ -1491,6 +1492,47 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, return ret; } +static int add_stripe_entry_for_delayed_ref(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_node *node) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct extent_map *em; + struct map_lookup *map; + int ret; + + if (!fs_info->stripe_root) + return 0; + + em = btrfs_get_chunk_map(fs_info, node->bytenr, node->num_bytes); + if (!em) { + btrfs_err(fs_info, + "cannot get chunk map for address %llu", + node->bytenr); + return -EINVAL; + } + + map = em->map_lookup; + + if (btrfs_need_stripe_tree_update(fs_info, map->type)) { + struct btrfs_ordered_stripe *stripe; + + stripe = btrfs_lookup_ordered_stripe(fs_info, node->bytenr); + if (!stripe) { + btrfs_err(fs_info, + "cannot get stripe extent for address %llu (%llu)", + node->bytenr, node->num_bytes); + free_extent_map(em); + return -EINVAL; + } + ASSERT(stripe->logical == node->bytenr); + ret = btrfs_insert_raid_extent(trans, stripe); + btrfs_put_ordered_stripe(fs_info, stripe); + } + free_extent_map(em); + + return ret; +} + static int run_delayed_data_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_node *node, struct btrfs_delayed_extent_op *extent_op, @@ -1521,6 +1563,9 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, flags, ref->objectid, ref->offset, &ins, node->ref_mod); + if (ret) + return ret; + ret = add_stripe_entry_for_delayed_ref(trans, node); } else if (node->action == BTRFS_ADD_DELAYED_REF) { ret = __btrfs_inc_extent_ref(trans, node, parent, ref_root, ref->objectid, ref->offset, diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c new file mode 100644 index 000000000000..360046a104c7 --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.c @@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include "ctree.h" +#include "transaction.h" +#include "disk-io.h" +#include "raid-stripe-tree.h" +#include "volumes.h" + +static struct rb_node *stripe_tree_insert(struct rb_root *root, u64 logical, + struct rb_node *node) +{ + struct rb_node **p = &root->rb_node; + struct btrfs_ordered_stripe *stripe; + struct rb_node *parent = NULL; + + while (*p) { + parent = *p; + stripe = rb_entry(*p, struct btrfs_ordered_stripe, rb_node); + + if (logical < stripe->logical) + p = &(*p)->rb_left; + else if (logical >= stripe->logical + stripe->num_bytes) + p = &(*p)->rb_right; + else + return parent; + } + + rb_link_node(node, parent, p); + rb_insert_color(node, root); + return NULL; +} + +static struct btrfs_ordered_stripe *btrfs_add_ordered_stripe( + struct btrfs_fs_info *fs_info, + u64 logical, + u64 length, int num_stripes, + struct btrfs_io_stripe *stripes) +{ + struct btrfs_ordered_stripe *stripe; + struct btrfs_io_stripe *tmp; + struct rb_node *node; + size_t size; + + size = num_stripes * sizeof(struct btrfs_io_stripe); + stripe = kzalloc(sizeof(struct btrfs_ordered_stripe), GFP_NOFS); + if (!stripe) + return ERR_PTR(-ENOMEM); + + spin_lock_init(&stripe->lock); + tmp = kmemdup(stripes, size, GFP_NOFS); + if (!tmp) { + kfree(stripe); + return ERR_PTR(-ENOMEM); + } + + stripe->logical = logical; + stripe->num_bytes = length; + stripe->num_stripes = num_stripes; + spin_lock(&stripe->lock); + stripe->stripes = tmp; + spin_unlock(&stripe->lock); + refcount_set(&stripe->ref, 1); + + mutex_lock(&fs_info->stripe_update_lock); + node = stripe_tree_insert(&fs_info->stripe_update_tree, logical, + &stripe->rb_node); + mutex_unlock(&fs_info->stripe_update_lock); + + if (node) { + btrfs_panic(fs_info, -EEXIST, + "inconsistency in ordered stripes at offset %llu", + logical); + kfree(stripe->stripes); + kfree(stripe); + return ERR_PTR(-EEXIST); + } + + return stripe; +} + +struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe(struct btrfs_fs_info *fs_info, + u64 logical) +{ + struct rb_root *root = &fs_info->stripe_update_tree; + struct btrfs_ordered_stripe *stripe; + struct rb_node *n = root->rb_node; + + mutex_lock(&fs_info->stripe_update_lock); + while (n) { + stripe = rb_entry(n, struct btrfs_ordered_stripe, rb_node); + + if (logical < stripe->logical) { + n = n->rb_left; + stripe = NULL; + } else if (logical >= stripe->logical + stripe->num_bytes) { + n = n->rb_right; + stripe = NULL; + } else { + break; + } + } + if (stripe) + btrfs_get_ordered_stripe(stripe); + mutex_unlock(&fs_info->stripe_update_lock); + + return stripe; +} + +void btrfs_remove_ordered_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_ordered_stripe *stripe) +{ + struct rb_node *node = &stripe->rb_node; + + mutex_lock(&fs_info->stripe_update_lock); + rb_erase(node, &fs_info->stripe_update_tree); + RB_CLEAR_NODE(node); + mutex_unlock(&fs_info->stripe_update_lock); + + spin_lock(&stripe->lock); + kfree(stripe->stripes); + spin_unlock(&stripe->lock); + kfree(stripe); +} + +int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, + struct btrfs_ordered_stripe *stripe) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_key stripe_key; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_dp_stripe *raid_stripe; + size_t item_size; + int ret; + + item_size = stripe->num_stripes * sizeof(struct btrfs_stripe_extent); + + raid_stripe = kzalloc(item_size, GFP_NOFS); + if (!raid_stripe) { + btrfs_abort_transaction(trans, -ENOMEM); + btrfs_end_transaction(trans); + return -ENOMEM; + } + + spin_lock(&stripe->lock); + for (int i = 0; i < stripe->num_stripes; i++) { + u64 devid = stripe->stripes[i].dev->devid; + u64 physical = stripe->stripes[i].physical; + struct btrfs_stripe_extent *stripe_extent = + &raid_stripe->extents[i]; + + btrfs_set_stack_stripe_extent_devid(stripe_extent, devid); + btrfs_set_stack_stripe_extent_physical(stripe_extent, physical); + } + spin_unlock(&stripe->lock); + + stripe_key.objectid = stripe->logical; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = stripe->num_bytes; + + ret = btrfs_insert_item(trans, stripe_root, &stripe_key, raid_stripe, + item_size); + if (ret) + btrfs_abort_transaction(trans, ret); + + kfree(raid_stripe); + + return ret; +} + +void btrfs_raid_stripe_update(struct work_struct *work) +{ + struct btrfs_io_context *bioc = + container_of(work, struct btrfs_io_context, stripe_update_work); + struct btrfs_ordered_stripe *stripe; + struct bio *bio = bioc->orig_bio; + struct btrfs_fs_info *fs_info = bioc->fs_info; + + stripe = btrfs_add_ordered_stripe(fs_info, bioc->logical, bioc->length, + bioc->num_stripes, bioc->stripes); + if (IS_ERR(stripe)) { + btrfs_bio_counter_dec(fs_info); + bio->bi_status = errno_to_blk_status(PTR_ERR(stripe)); + } + btrfs_put_bioc(bioc); +} + diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h new file mode 100644 index 000000000000..b9c40ef26dfa --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.h @@ -0,0 +1,65 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_RAID_STRIPE_TREE_H +#define BTRFS_RAID_STRIPE_TREE_H + +#include "volumes.h" + +struct btrfs_ordered_stripe { + struct rb_node rb_node; + + u64 logical; + u64 num_bytes; + int num_stripes; + struct btrfs_io_stripe *stripes; + spinlock_t lock; + refcount_t ref; +}; + +int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, + struct btrfs_ordered_stripe *stripe); +void btrfs_raid_stripe_update(struct work_struct *work); +struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe( + struct btrfs_fs_info *fs_info, + u64 logical); +void btrfs_remove_ordered_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_ordered_stripe *stripe); + +static inline void btrfs_get_ordered_stripe(struct btrfs_ordered_stripe *stripe) +{ + refcount_inc(&stripe->ref); +} + +static inline void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_ordered_stripe *stripe) +{ + if (refcount_dec_and_test(&stripe->ref)) + btrfs_remove_ordered_stripe(fs_info, stripe); +} + +static inline int btrfs_num_raid_stripes(u32 item_size) +{ + return item_size - offsetof(struct btrfs_dp_stripe, extents) / + sizeof(struct btrfs_stripe_extent); +} + +static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, + u64 map_type) +{ + u64 type = map_type & BTRFS_BLOCK_GROUP_TYPE_MASK; + u64 profile = map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK; + + if (!fs_info->stripe_root) + return false; + + // for now + if (type != BTRFS_BLOCK_GROUP_DATA) + return false; + + if (profile & BTRFS_BLOCK_GROUP_RAID1_MASK) + return true; + + return false; +} + +#endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 2d788a351c1f..b8d4e92c7196 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -33,6 +33,7 @@ #include "block-group.h" #include "discard.h" #include "zoned.h" +#include "raid-stripe-tree.h" #define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ BTRFS_BLOCK_GROUP_RAID10 | \ @@ -5897,6 +5898,7 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ bioc->fs_info = fs_info; bioc->tgtdev_map = (int *)(bioc->stripes + total_stripes); bioc->raid_map = (u64 *)(bioc->tgtdev_map + real_stripes); + INIT_WORK(&bioc->stripe_update_work, btrfs_raid_stripe_update); return bioc; } @@ -6623,6 +6625,7 @@ static void btrfs_end_bio_work(struct work_struct *work) static void btrfs_end_bioc(struct btrfs_io_context *bioc, bool async) { struct bio *orig_bio = bioc->orig_bio; + struct btrfs_fs_info *fs_info = bioc->fs_info; struct btrfs_bio *bbio = btrfs_bio(orig_bio); bbio->mirror_num = bioc->mirror_num; @@ -6642,6 +6645,12 @@ static void btrfs_end_bioc(struct btrfs_io_context *bioc, bool async) INIT_WORK(&bbio->end_io_work, btrfs_end_bio_work); queue_work(btrfs_end_io_wq(bioc), &bbio->end_io_work); } else { + if (btrfs_op(orig_bio) == BTRFS_MAP_WRITE && + btrfs_need_stripe_tree_update(fs_info, + bioc->map_type)) { + btrfs_get_bioc(bioc); + schedule_work(&bioc->stripe_update_work); + } bio_endio(orig_bio); } @@ -6667,6 +6676,8 @@ static void btrfs_end_bio(struct bio *bio) btrfs_dev_stat_inc_and_print(stripe->dev, BTRFS_DEV_STAT_FLUSH_ERRS); } + } else if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; } if (bio != bioc->orig_bio) @@ -6754,6 +6765,8 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, bioc->orig_bio = bio; bioc->private = bio->bi_private; bioc->end_io = bio->bi_end_io; + bioc->logical = logical; + bioc->length = length; atomic_set(&bioc->stripes_pending, total_devs); if ((bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) && diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 9537d82bb7a2..f22ea9c23faa 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -14,6 +14,7 @@ #define BTRFS_MAX_DATA_CHUNK_SIZE (10ULL * SZ_1G) extern struct mutex uuid_mutex; +struct btrfs_ordered_stripe; #define BTRFS_STRIPE_LEN SZ_64K @@ -463,6 +464,9 @@ struct btrfs_io_context { int mirror_num; int num_tgtdevs; int *tgtdev_map; + u64 logical; + u64 length; + struct work_struct stripe_update_work; /* * logical block numbers for the start of each stripe * The last one or two are p/q. These are sorted, diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 7a0f8fa44800..5cf6abeda588 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1641,6 +1641,10 @@ void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered) u64 *logical = NULL; int nr, stripe_len; + /* Filesystems with a stripe tree have their own l2p mapping */ + if (fs_info->stripe_root) + return; + /* Zoned devices should not have partitions. So, we can assume it is 0 */ ASSERT(!bdev_is_partition(ordered->bdev)); if (WARN_ON(!ordered->bdev)) From patchwork Wed Jun 29 14:41:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28AD7C433EF for ; Wed, 29 Jun 2022 14:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233553AbiF2Ol3 (ORCPT ); Wed, 29 Jun 2022 10:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233442AbiF2Ol1 (ORCPT ); Wed, 29 Jun 2022 10:41:27 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 861C93A1AD for ; Wed, 29 Jun 2022 07:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513686; x=1688049686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fDGlOEPYf8FRGIBDJNTU3gjuOSx06L1yIinxMPGK/ps=; b=Bs57sXpZtNsqlSntBWkjsXiruHEV8zLXPRGlPa0iaTq9odfpRdN/4mni BnS/4i3Atd6Zkc+tjGv8Br7Nkw0/yYnobw0IgHcJMEFYE4ymLc8rLpF4r KLkUUafqECXfTfQwPzuEgSzsFyjisTfvgi6WrPydvNxzx4WXZfS6CXgG5 huPRLZRGOBkqeT9adCn/spu+CvPpskdy0sPYmSzvhWPzdnFN25lBQaxVR VGg6XgBwV5Z9WYzzooo0WeXnJhcMfw4ppAWjNW70tm+MARKCs6vBFS890 RUObvj5z9nTo+K9azsFtGvP8+gzu3dBsYAOSNu1Dcv0oZP5GVauxy5jH1 A==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064889" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:25 +0800 IronPort-SDR: 78dHaPmm5+0h8ZhZv4w3R5HnzmlmhXnxJgeivI9Qtxn2oYM+ic4KM2Mj7Pyt6WxLABX0tqHH4I OUQmaPaBVEP5aX8zap4e+N/89vliQVgWNcPRQ95vOzn4PA8sFHXewqi+PBMdfmKZimF8U4o+VK 9KjskJ+7lv8qDsXYqiSC4lWTHzYieMd0uPuqEeqU0g+mmMFi7BHm4Ho2v1Le4pk+5ZDHWgDDzd ZNYHXrg9iZH6g6mzjf81kZeFfn5Ri/y/jCSBM5uWulW6WBGoH3viBN5ujydW7XVXVAAP9xds4X perTrDWIzWswQWtJo12V+qAa Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:04 -0700 IronPort-SDR: jrDuosRxT2h77ncGTOj8aBwC2A1tLpX33iOR2cjGM6eNxQnKW3K3AWANjJ96xrhBuGKJUTNVWg GNrxLcHGOZxcvXSrzX04uAzVm/ToNyF8C4qWzMddRMq9fUkVnukr9ARd185YhpCuzGrAT4GCFa qf/1XtpHYk20lv2A85LG7FrMscLof8jo++vSoRu/0n1srKodOpVd2uavZxFO7tuY9IAWLUBoCC XXf4AVcvOtw8YRAucfNVnIH7oiZyLt9H+XXa2/Vn3LaWFhMXpimX5oeEKQhdp5WKKAqKazIqDQ wNg= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:25 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 4/8] btrfs: add boilerplate code to insert stripe entries for preallocated extents Date: Wed, 29 Jun 2022 07:41:10 -0700 Message-Id: <63f578dd3ad1061561ecb761202a08d6092310d2.1656513330.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Signed-off-by: Johannes Thumshirn --- fs/btrfs/inode.c | 6 ++++++ fs/btrfs/raid-stripe-tree.c | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 2 ++ 3 files changed, 42 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9890782fe932..97e218a45165 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -55,6 +55,7 @@ #include "zoned.h" #include "subpage.h" #include "inode-item.h" +#include "raid-stripe-tree.h" struct btrfs_iget_args { u64 ino; @@ -9901,6 +9902,11 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent( if (qgroup_released < 0) return ERR_PTR(qgroup_released); + ret = btrfs_insert_preallocated_raid_stripe(inode->root->fs_info, + start, len); + if (ret) + goto free_qgroup; + if (trans) { ret = insert_reserved_file_extent(trans, inode, file_offset, &stack_fi, diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 360046a104c7..85d08f052a64 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -124,6 +124,40 @@ void btrfs_remove_ordered_stripe(struct btrfs_fs_info *fs_info, kfree(stripe); } +int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info, + u64 start, u64 len) +{ + struct btrfs_io_context *bioc = NULL; + struct btrfs_ordered_stripe *stripe; + u64 map_length = len; + int ret; + + if (!fs_info->stripe_root) + return 0; + + ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, start, &map_length, + &bioc, 0); + if (ret) + return ret; + + stripe = btrfs_lookup_ordered_stripe(fs_info, start); + if (!stripe) { + stripe = btrfs_add_ordered_stripe(fs_info, start, len, + bioc->num_stripes, + bioc->stripes); + if (IS_ERR(stripe)) + return PTR_ERR(stripe); + } else { + spin_lock(&stripe->lock); + memcpy(stripe->stripes, bioc->stripes, + bioc->num_stripes * sizeof(struct btrfs_io_stripe)); + spin_unlock(&stripe->lock); + btrfs_put_ordered_stripe(fs_info, stripe); + } + + return 0; +} + int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_stripe *stripe) { diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index b9c40ef26dfa..1644515fcecb 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -18,6 +18,8 @@ struct btrfs_ordered_stripe { int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_stripe *stripe); +int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info, + u64 start, u64 len); void btrfs_raid_stripe_update(struct work_struct *work); struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe( struct btrfs_fs_info *fs_info, From patchwork Wed Jun 29 14:41:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 099BDC433EF for ; Wed, 29 Jun 2022 14:41:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233565AbiF2Olb (ORCPT ); Wed, 29 Jun 2022 10:41:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233562AbiF2Ol3 (ORCPT ); Wed, 29 Jun 2022 10:41:29 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E08903AA4B for ; Wed, 29 Jun 2022 07:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513687; x=1688049687; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5rbiMmQZXSgKSX0UGG9T3A1/tEj32uac0hbWUvI6I84=; b=TZ2WzVWpeDoqUelTEL6V47Xeq5XcswqFXPWXORS8aqRDLG4Rejag6bP+ MizuShGLYMwCWQNdpXtEgvPojbbeWx8NnYHhYuzeDjxsWMmaSVRyiboFF E0nXQoSNmRIMViucXhG5nNzeX+5rrv68LPODzOV1NiCR5gAuftTlujpka lrQ7h3giYF2sgpf4rkP4Fdsgw/3OJ/KkRpHfleQ3JdaSrWs8CpqYzeQaU ck3gPmkC88IgEm2+q30a4ksh8uiiI/q7DQyjuNt5mdA3PJY5h9vC4S1Dt hl7piN+yuteurQfVdT1MkNQnHCt4xZCKX4V3kYRn11qF1mftJ9rSWPT+Q A==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064891" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:27 +0800 IronPort-SDR: vBTRQ8ycOPVYKNNjvu0lhMK+vZpJhKX+a2OpBgHvZ7D1oTsX1ARpQmrFdfQKhauQJZXXajtz/7 mZCNpcPJMD09ChNISUA3VGOPPk4xRsfzMs+RrDUEX8GECHjyn6KYm/cJRgMNE+XYplzVwUtukF vG941T76uuEcOQS7K6YVK47NKPnJ98nZZ/Yapg7r7PPVaTe2H6qt3tAIJG3g6HmIGMjVnKgaVX 3HGPeJo4i5oz2u5mZmc5m1nf/V/I3qGFec27YFEh/hgbgX3kZ7iqk6H7jYC7kjCwen3RswdfkJ tBWIJf9w2afGYmXyQcmE/IOL Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:05 -0700 IronPort-SDR: EU7bB+5xgwlciFOmWkoN7QD8T6rFbwItwoW5P+fVSFtgQuPPse9gu1Y6fag8/P1oBjEYHdmFJP Cq041tzmJLh7ZOoA4bOTiaNVRjC4aroXiypV/rbW7lHND5O5Og93W0FgAX+f8x6mXKYLXl6mEy fakjuHkvf0NN0CTWoXZ1W8Ysv0PTPgZwf3T4P5HWoPdSA8z5wUtkljOeBskNbSxC2qudLpf3S6 QZ1ohqVpOLOKVYZT79gem1/77N85Any6p0P+zjfok+YpItJuIlPsRJ5T8AtEQDDpm3PE88a2gn /hg= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:26 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 5/8] btrfs: add code to delete raid extent Date: Wed, 29 Jun 2022 07:41:11 -0700 Message-Id: <4e276266a91ba03a027e68316f9853d353672020.1656513330.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to delete entries from the raid-stripe-tree if the corresponding file extent got deleted. Signed-off-by: Johannes Thumshirn --- fs/btrfs/extent-tree.c | 8 ++++++++ fs/btrfs/raid-stripe-tree.c | 31 +++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 2 ++ 3 files changed, 41 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e1738b3dfb21..f62036790c2f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3225,6 +3225,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, } } + if (is_data) { + ret = btrfs_delete_raid_extent(trans, bytenr, num_bytes); + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } + } + ret = btrfs_del_items(trans, extent_root, path, path->slots[0], num_to_del); if (ret) { diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 85d08f052a64..a673aaf8e703 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -124,6 +124,37 @@ void btrfs_remove_ordered_stripe(struct btrfs_fs_info *fs_info, kfree(stripe); } +int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, + u64 length) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_path *path; + struct btrfs_key stripe_key; + int ret; + + if (!stripe_root) + return 0; + + stripe_key.objectid = start; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = length; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(trans, stripe_root, &stripe_key, path, -1, 1); + if (ret) + goto out; + + ret = btrfs_del_item(trans, stripe_root, path); +out: + btrfs_free_path(path); + return ret; + +} + int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info, u64 start, u64 len) { diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 1644515fcecb..d3cc24e37de1 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -16,6 +16,8 @@ struct btrfs_ordered_stripe { refcount_t ref; }; +int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, + u64 length); int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_stripe *stripe); int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info, From patchwork Wed Jun 29 14:41:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46581C43334 for ; Wed, 29 Jun 2022 14:41:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233570AbiF2Olc (ORCPT ); Wed, 29 Jun 2022 10:41:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233539AbiF2Ola (ORCPT ); Wed, 29 Jun 2022 10:41:30 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E5D13AA57 for ; Wed, 29 Jun 2022 07:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513689; x=1688049689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qNTPgRMxFMkhu0bhGuNQt17KfKUKms6w04bHkj1867A=; b=jkz/ccp7Cs9xoRpS6I3qAX9O4b6liA+EdAa2GLYiyjLskJddA+DI8Tvs 1beSPaa/b5hpNlL9Fdtdw4iRZ50p46b9wru+s8RB8exjo2ZwPTmXwbQF9 3PhkceOGtrIBBXslHF8IGcvV4Zu8Lae4sOZH+uCuPSY1PHuPdjPFznNFV GwlFCDjVMJqPFJFGfynb0KVsBJhr6zqPBouoDcyW3JzwntMJl8rGOjK+f Z1cVvmwf5wVGvc2wOp0pa0zczvkWs3/XVEO4Ap/AaYpDSj+4MdoaOPCut tk8PQ1jDORtvMH3fnuWXcPliNi1oDl0ziGCdOhzaY6VubKWu5RrpkEqxC g==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064896" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:28 +0800 IronPort-SDR: Sj+wkL7rTTZlNAeO2iuL/Ocaf5kVuA+NHJz1WqVCsJyaevEv8BphAP2bXc7Y8l11GlB6+aC/ms pgMQ559+u0rEe6LwPXkaGPnVjVM++kUQg1FjsJeiH4MnlcqijW0QR4JSKlQs6mAGz7A3l+cY6U 65LkyOaDAkmyWkjOVBhP0kqTSAGW/Gt+owz1ya5uyiz/OyFLkAagSgLkHSFQeGrFXt6CmrAsld M0tJqrrgiW4wDHO021WpJxSMkwb3lDRrFqU2xgvznjNqcrB0wY3xqWdOeFFkw0GAIFh80D0cai XvHd+/3ExXyXOSo+hNIxrJLs Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:07 -0700 IronPort-SDR: bkwn/CwKuF+ksk4VBK7Ovtn89rkKs5jO3/uWT+Eb+AeMwiT5wvHwW0yHn3/9ZGs3ZIawdKim9F WkW/1JAwVKttuMIjOuA8Hc8cwsAXnymPKGTDsOT7VD7/3xJYt0xKzV7I72NxNu4a13Q7yAxucP Jd1Frn87zHWKmpOClvwSfvJrGmtpFIMx5sp79yD6C60g25cHzoav9dZLmw6cQxeN7B4dsuWfnC qEhsa/pzC6IcE0zWWje4klvWKtvHqSwKGC0YuDs5i1Mj8baWsxEdrY1Sw8vuP2ZGqKL6tPIIT4 TpQ= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:28 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 6/8] btrfs: add code to read raid extent Date: Wed, 29 Jun 2022 07:41:12 -0700 Message-Id: <1f61c93be9354db6e53da4f404aa0f129f43a1e0.1656513330.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to lookup the physical address from the raid-stripe-tree when a read on an RAID volume formatted with the raid-stripe-tree was attempted. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 65 +++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 3 ++ fs/btrfs/volumes.c | 22 +++++++++++-- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index a673aaf8e703..5ee630a792fc 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -7,6 +7,7 @@ #include "disk-io.h" #include "raid-stripe-tree.h" #include "volumes.h" +#include "misc.h" static struct rb_node *stripe_tree_insert(struct rb_root *root, u64 logical, struct rb_node *node) @@ -251,3 +252,67 @@ void btrfs_raid_stripe_update(struct work_struct *work) btrfs_put_bioc(bioc); } +int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, + u64 logical, u64 length, u64 map_type, + u64 devid, u64 *physical) +{ + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_dp_stripe *raid_stripe; + struct btrfs_key stripe_key; + struct btrfs_key found_key; + struct btrfs_path *path; + struct extent_buffer *leaf; + u64 offset; + u64 found_logical, found_length; + int num_stripes; + int slot; + int ret; + int i; + + stripe_key.objectid = logical; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = length; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + num_stripes = btrfs_bg_type_to_factor(map_type); + + ret = btrfs_search_slot_for_read(stripe_root, &stripe_key, path, 0, 0); + if (ret < 0) { + goto out; + } + + if (ret == 1) + ret = 0; + + while (1) { + leaf = path->nodes[0]; + slot = path->slots[0]; + + btrfs_item_key_to_cpu(leaf, &found_key, slot); + found_logical = found_key.objectid; + found_length = found_key.offset; + + if (!in_range(logical, found_logical, found_length)) + goto next; + offset = logical - found_logical; + + raid_stripe = btrfs_item_ptr(leaf, slot, struct btrfs_dp_stripe); + for (i = 0; i < num_stripes; i++) { + if (btrfs_stripe_extent_devid_nr(leaf, raid_stripe, i) != devid) + continue; + *physical = btrfs_stripe_extent_physical_nr(leaf, raid_stripe, i) + offset; + goto out; + } +next: + ret = btrfs_next_item(stripe_root, path); + if (ret) + break; + } +out: + btrfs_free_path(path); + + return ret; +} diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index d3cc24e37de1..75e17cad283a 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -16,6 +16,9 @@ struct btrfs_ordered_stripe { refcount_t ref; }; +int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, + u64 logical, u64 length, u64 map_type, + u64 devid, u64 *physical); int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length); int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b8d4e92c7196..2569ef564c97 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6526,9 +6526,27 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, } for (i = 0; i < num_stripes; i++) { - bioc->stripes[i].physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + u64 physical; + bioc->stripes[i].dev = map->stripes[stripe_index].dev; + + if (fs_info->stripe_root && op == BTRFS_MAP_READ && + btrfs_need_stripe_tree_update(bioc->fs_info, + map->type)) { + ret = btrfs_get_raid_extent_offset(fs_info, logical, + map->stripe_len, + map->type, + bioc->stripes[i].dev->devid, + &physical); + if (ret) { + btrfs_put_bioc(bioc); + goto out; + } + } else { + physical = map->stripes[stripe_index].physical + + stripe_offset + stripe_nr * map->stripe_len; + } + bioc->stripes[i].physical = physical; stripe_index++; } From patchwork Wed Jun 29 14:41:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A82DC433EF for ; Wed, 29 Jun 2022 14:41:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbiF2Ole (ORCPT ); Wed, 29 Jun 2022 10:41:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbiF2Ola (ORCPT ); Wed, 29 Jun 2022 10:41:30 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4887E39148 for ; Wed, 29 Jun 2022 07:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513689; x=1688049689; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tQPWYcqzY8jouLyXuoKVAxy/EC9pFthgqLyhTw52EDo=; b=XPNumKC3ki0OtEulMc1WI4VvXMv2RuIxoJltVZZ9oKF210DhvJ+IBBU9 087yUcccKVMFwtYIb0StsGNMKXu0ZANmLMdJMoRZ8JfHAanGkv+nnrFYM fNqMtz+fZCrnvW8QcXf3lTsTnvrGvfEV7CfmjelQLFUmO8BYTe5ZrMc+T FV2MUSV86rV+eiE2d4nz3grCxm1nkBp0MDskSSC27U1S4RT1q3BkbjLTd LWie9FXavHqFGT2Xxc/v3l9bULX34GuT5o4RSFa1ZyBklokHZ6Z58ESdt G2/CkxLNJ8umGimRLRJwGWcu2S5qoBjllDMctC+FhdsSASZqvKRttMfiz g==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064898" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:29 +0800 IronPort-SDR: e5Yyopki96kKRMuttbefhJGw+V1TeiIST/90p6k0aATatHWv55I9fag0RfRip2TdoUvGrbFoQL qqIgMHqMtvphbO2C/EWdEMrju7XejBPQx/taZ8+PVrHV9tDcdf+kJozoQi/wTiGppELT7G891H pNY29bOtuRiM8BQYmkCzmvSTvjp6TksRfEpcV7pBgAv0/7hYSoio/LflMHgXQUbLb7icrsm5y0 aQ2+vT/0E+8dGZCgFGLtatE1QW7UZVbMLh9dp9RcksFPRVfg3P+QNT+ggg5D7yJ3ORmcksjnEL XzRS3WT8Y3GkJzP3HcbAJvbL Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:08 -0700 IronPort-SDR: y4dTlu9eoBDx2yggsUFwHPysF2dFMzyp+OmS2K/OLmQnDQMVWHXCzwtNtD/83c3gkZGW2KVCbL wBheJUSzU/5l9UJgPth5L9Gk+Ef1oIHEPZXhga10Npo2xaj+G2MYz2WB3J4M3v6Fp6x/6u7u7l snYxIyrNPdTPmQ9QcH2opLScpoZXh3G5sDxVxHK3rtHbn6+rETVvS4igw/qCsw7E9vCrfiyBR/ gBcw4JztcjP3xvKTYiWaOy/Wwj8LoYTcM9NvZ5tiapgv2Adq+ADJ8aEs79IUMY/o1svsCHUQ29 MRg= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:29 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 7/8] btrfs: zoned: allow zoned RAID1 Date: Wed, 29 Jun 2022 07:41:13 -0700 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we have a raid-stripe-tree, we can do RAID1 on zoned devices for data block-groups. For meta-data block-groups, we don't actually need anything special, as all meta-data I/O is protected by the btrfs_zoned_meta_io_lock() already. Signed-off-by: Johannes Thumshirn --- fs/btrfs/zoned.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 5cf6abeda588..e51e405342ad 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1463,6 +1463,41 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) cache->zone_capacity = min(caps[0], caps[1]); break; case BTRFS_BLOCK_GROUP_RAID1: + case BTRFS_BLOCK_GROUP_RAID1C3: + case BTRFS_BLOCK_GROUP_RAID1C4: + if (map->type & BTRFS_BLOCK_GROUP_DATA && + !fs_info->stripe_root) { + btrfs_err(fs_info, + "zoned: data RAID1 needs stripe_root"); + ret = -EIO; + goto out; + + } + + for (i = 0; i < map->num_stripes; i++) { + if (alloc_offsets[i] == WP_MISSING_DEV) + continue; + + if (i == 0) + continue; + + if (alloc_offsets[0] != alloc_offsets[i]) { + btrfs_err(fs_info, + "zoned: write pointer offset mismatch of zones in RAID profile"); + ret = -EIO; + goto out; + } + if (test_bit(0, active) != test_bit(i, active)) { + if (!btrfs_zone_activate(cache)) { + ret = -EIO; + goto out; + } + } + cache->zone_capacity = min(caps[0], caps[i]); + } + cache->zone_is_active = test_bit(0, active); + cache->alloc_offset = alloc_offsets[0]; + break; case BTRFS_BLOCK_GROUP_RAID0: case BTRFS_BLOCK_GROUP_RAID10: case BTRFS_BLOCK_GROUP_RAID5: From patchwork Wed Jun 29 14:41:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12900249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4779FC43334 for ; Wed, 29 Jun 2022 14:41:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232511AbiF2Olf (ORCPT ); Wed, 29 Jun 2022 10:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233562AbiF2Olc (ORCPT ); Wed, 29 Jun 2022 10:41:32 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2EFD39148 for ; Wed, 29 Jun 2022 07:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1656513691; x=1688049691; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OmW9eaWEWURaAWpxdVDrx0yLNbWXZ5OjFLUdIZkTrHU=; b=GsVZxVRfPbtnFcv4Ve8I/2M06nHG0GFwkiXRf9f6N5BbS86Y+/TGlyyv QrND2yey5wdewHSXIQHiF9tLiUbgtZUApcKJRkJhcgdU+AWdQ/x1K4pQc a6eezxynapMGIUFVjwu0DpDQ+zKHxbXIwg/KSAQqgJCF4XtmRMT24iKrD V7PnhoCu43d6gw3uEzvdGiOfAchZZoDuuk9foOf/sUOhFleilsC6fq2H4 MgiQUVYfum5yvCUf/fH6TBeXj+VFODMSOGFr2f2ht8YkISq6ik4v419Ib ElbxBz67eWSQdkEgNsd/CCok6sf7RJ9IvrNY77bRtm7cpsdCMK2MahXge g==; X-IronPort-AV: E=Sophos;i="5.92,231,1650902400"; d="scan'208";a="203064905" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 Jun 2022 22:41:31 +0800 IronPort-SDR: NlMHzXvtPuKZxJUcAvM9xdpL9S4eCnO0COLhbSJtfQbtHT5HX5ceS+4SbkZdW5+1egMBnwU8rU 3Lylc7HwfJc61Gqb6Zx2ivBX3bNJBxfPLwCZTonZ5oWklKmOIv+3Zwaf2KM6ghjpxWyoULq+Z+ wHZuV2n2IdpvW8M/y+yTsTmn5YjQJQoqTt6OCKFeRcWwe3ltie/kt7ZdEiBs9AyWzzstz4Gahr zP30cTEys6eXcTDTLZj4i6w0UpLag48M+HUymlEWChd81FVfBi2ZDWLW/lkWMmss9Ju7lhuwbH uOkwNcbIvlhHGVTNVkZmm5xI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 29 Jun 2022 06:59:09 -0700 IronPort-SDR: kZeYM2OML04M4vgZ99e2c08eGrvHwPkw3Kc/9VY0BKq2EeVQduDKsAsYEiNb/bB2efYXn4Z3fc cUsp6BqKTnLLhwvSGjHcm/5pDO3U3odRcLy3sXooN5C2kCAoqG6/3h4yfznnNXv4tgydjgAElU z4OAk5K9/N4eiFyF1Qq4DXsmVhVgdDrB/nB5lxZvRuNBSUgwjrB+4NM1S5Yf5Ar8y1JNwWH5Vt Zgz4s8TZt4QAKH7t6Tv9/UTUR6b3G8TkNEcpqHYwUhPuMPsP4CYUuvuZdI9Hcm5siZwQcegXpl tZ0= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 29 Jun 2022 07:41:30 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Damien Le Moal , Johannes Thumshirn , Qu Wenruo , Christoph Hellwig , Josef Bacik Subject: [PATCH RFC v2 8/8] btrfs: add raid stripe tree pretty printer Date: Wed, 29 Jun 2022 07:41:14 -0700 Message-Id: <62ec7adca017d2e9081cf053f00ed55fb3468143.1656513331.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Decode raid-stripe-tree entries on btrfs_print_tree(). Signed-off-by: Johannes Thumshirn --- fs/btrfs/print-tree.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index dd8777872143..10a39d5a7e40 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -6,6 +6,7 @@ #include "ctree.h" #include "disk-io.h" #include "print-tree.h" +#include "raid-stripe-tree.h" struct root_name_map { u64 id; @@ -25,6 +26,7 @@ static const struct root_name_map root_map[] = { { BTRFS_FREE_SPACE_TREE_OBJECTID, "FREE_SPACE_TREE" }, { BTRFS_BLOCK_GROUP_TREE_OBJECTID, "BLOCK_GROUP_TREE" }, { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" }, + { BTRFS_RAID_STRIPE_TREE_OBJECTID, "RAID_STRIPE_TREE" }, }; const char *btrfs_root_name(const struct btrfs_key *key, char *buf) @@ -184,6 +186,20 @@ static void print_uuid_item(struct extent_buffer *l, unsigned long offset, } } +static void print_raid_stripe_key(struct extent_buffer *eb, u32 item_size, + struct btrfs_dp_stripe *stripe) +{ + int num_stripes; + int i; + + num_stripes = btrfs_num_raid_stripes(item_size); + + for (i = 0; i < num_stripes; i++) + pr_info("\t\t\tstripe %d devid %llu physical %llu\n", i, + btrfs_stripe_extent_devid_nr(eb, stripe, i), + btrfs_stripe_extent_physical_nr(eb, stripe, i)); +} + /* * Helper to output refs and locking status of extent buffer. Useful to debug * race condition related problems. @@ -348,6 +364,11 @@ void btrfs_print_leaf(struct extent_buffer *l) print_uuid_item(l, btrfs_item_ptr_offset(l, i), btrfs_item_size(l, i)); break; + case BTRFS_RAID_STRIPE_KEY: + print_raid_stripe_key(l, btrfs_item_size(l, i), + btrfs_item_ptr(l, i, + struct btrfs_dp_stripe)); + break; } } }