From patchwork Wed Feb 15 14:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141736 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 2C787C636D4 for ; Wed, 15 Feb 2023 14:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229701AbjBOOd6 (ORCPT ); Wed, 15 Feb 2023 09:33:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229668AbjBOOdz (ORCPT ); Wed, 15 Feb 2023 09:33:55 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD8C38B70 for ; Wed, 15 Feb 2023 06:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471621; x=1708007621; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Th0z3TBAN6emg+sUWcZJUMYenoGn48ne488/Ef3KsKc=; b=nKgnXHyVJJLwAVLF0EeHETfpUCHmQYoeLTBbPeWGvV4lR6Uy0p/5Ivkr D9Vuo4rNquFcSusFskHTtJpN3SG0CYlKk49VwBbzXGmOl761vcdmuKiG2 bzlBl9IdFk/gkvqr3NOD8N3ElNCVnJ1MeO2IXuHcKNnD7X8qb/bDqDCpl P793xL20VuCseNcNzaZ1Kv53V2WAq9KoaMqz2dZ86FXPDSUsZec0PsMX6 Fi2KCduiIHZmPPK/jaulGLoAknBshhPSGKZxeQhvdH7QjQ6nbh2B2YK0g szcoQsXok58FW6+JLSxhMkhQvvg+3v6BeeCVyq1WBaJJdlZ9q3C7BHgRD A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394063" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:40 +0800 IronPort-SDR: FTAtdxA0GpZ/pC/Ohcb2XMqv0uOBAkkpPKcmjaMSYmVewlbkc/CKnUkm02RwSPPjBSA1X2kChf hoDAKIJzhjVmuf5aw1FI7S1gTUyYi15WDvd+jYKSIE4AHqInH/zRbHFSX7AT77WWencR7X+Rdj +NXS3LtdWiZ2YmnYq4q5t5blFjmhvMI8K9/kJCiFG+QhbcecshkV6dwOHD1EXX97c4v5/qZ2NN piD2gyEzVfNUcHhBmp1tcC44xTukfvvFG9l+3ATbVcf+tV4i+0QcquZPCCNwovmH5TkKPifyng 3YE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:02 -0800 IronPort-SDR: iQT5xUZnn12Lo+ntEgDqZ+TkfFTD4R9QPD+gbE/GYYD/pkhLT/8oeZ+390EueKncNee5fyFEPE lNzASJl9oT2DM03CsJm6MOPJhyovrIAAO+CMwaUzrwMcVnEPmcRtCCn5HguZ9uhkV1sKbKIlqE tBWOYN4/evSz2477PM9TeIP69zejw9j5e7O1YDEHqUzPOLweumxVBPp8BDhbUWCpWKafm6u/qR t5pVI4XDzDYb1lCqb6YxZvnqz+sT5+wtdKr86rIez82p9zBJzVQ02L77DFTdmqgo6SsZ2cObOL wCY= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:40 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 01/13] btrfs: re-add trans parameter to insert_delayed_ref Date: Wed, 15 Feb 2023 06:33:22 -0800 Message-Id: <573cca0daf4c9178d9a2aaffe7c5f071e35e537a.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Re-add the trans parameter to insert_delayed_ref as it is needed again later in this series. This reverts commit bccf28752a99 ("btrfs: drop trans parameter of insert_delayed_ref") Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/delayed-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 886ffb232eac..7660ac642c81 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -598,7 +598,8 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, * Return 0 for insert. * Return >0 for merge. */ -static int insert_delayed_ref(struct btrfs_delayed_ref_root *root, +static int insert_delayed_ref(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_root *root, struct btrfs_delayed_ref_head *href, struct btrfs_delayed_ref_node *ref) { @@ -974,7 +975,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, head_ref = add_delayed_ref_head(trans, head_ref, record, action, &qrecord_inserted); - ret = insert_delayed_ref(delayed_refs, head_ref, &ref->node); + ret = insert_delayed_ref(trans, delayed_refs, head_ref, &ref->node); spin_unlock(&delayed_refs->lock); /* @@ -1066,7 +1067,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, head_ref = add_delayed_ref_head(trans, head_ref, record, action, &qrecord_inserted); - ret = insert_delayed_ref(delayed_refs, head_ref, &ref->node); + ret = insert_delayed_ref(trans, delayed_refs, head_ref, &ref->node); spin_unlock(&delayed_refs->lock); /* From patchwork Wed Feb 15 14:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141737 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 35B4AC636CC for ; Wed, 15 Feb 2023 14:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbjBOOd7 (ORCPT ); Wed, 15 Feb 2023 09:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjBOOd6 (ORCPT ); Wed, 15 Feb 2023 09:33:58 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CABF638EA5 for ; Wed, 15 Feb 2023 06:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471623; x=1708007623; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=48Cmk2aOaGJS0a991MSx59EPyaPSJ4uYMqgpkcDU7Zo=; b=DC6YGmA8w8LR7Uos1iljlf9bWtBjo3SrXUVoEBoVXL6QEZk3OKKkKB7U ZaCfrrMCSI5kMPs4x9B6u4HwuZPsiGm6ux2NVXSPrgwuv4s93wehFHNAj 1icyfWsLMMClYYRyPPCQHYN/LqzJJ1LqPfq6hF8SFtsUNskAhZE3YZGHG TR0rlfLVLin48aXX0qO6N6ClsIpmCoGNFPpg9izxU39Bo+DAf7+/qWbDk P+qlDqZpvYZE10pV3CfVQkDoojVKAOPaAJ1UevC3g3bFYeU0IyoAKZZG6 dMipf+wE+BFTP1WOc0qdALMjntT7uTMrR0DH/w486PSCqsR4XtCRGeijP w==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394064" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:41 +0800 IronPort-SDR: d/1ay7bnWicEs7Zyp8NrC0gHrIQEXZ53wl989kAXUiUh3LDmcbc2VBlVRiBfztnMNyt68Ko9xU LKtQyKvZiUkJiX1+oOKqP3/3fMVOY2nZy13YWdgOKWFVOO0HzSMT52xSOkPRobdZy26RVoJ7Qi 0RRFkkZ2l2/JLHfQ+9zZXLVjOzMf89AfzX14LnXJKB+s7Sa38Irqph8NzDxkd1UPLJ74Hf7+hv 7mcpdKhHIqb/MCQFS9NY/ZDzxqg4sDcSmGL3u0G1y/pa31B6jYHYxHTnxogfTaqcdX09f9bl/X +dU= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:03 -0800 IronPort-SDR: eIzhOwmbAGzVP8qMBOjrXlu1z+d6xX1C2ke0FAmYFnVNeISXpe2owMjueV2t7AC0Vh+ttkPp6P bmqYEDH9V50mHYxuEEaUpF0yyxZsgY+Zp3+1qQJF1qYqCsEkqRBPnVju+LWaeMAeG2yNhOLGF6 3heSFW3leoCR4P3cTHaxOwfaru4MCX97Xcp0qEW4Uck953hqYrcblW+e6jwlGDX1YmhWbzmk9t 1HpXPLu2CtXSZ7O+CGz2LJvrjSVCX/KVZoV7gE6tbFyF/lYE/0uuAHUNTUVoq7kA1Py46mxKZ8 N9E= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:41 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik , Anand Jain Subject: [PATCH v6 02/13] btrfs: add raid stripe tree definitions Date: Wed, 15 Feb 2023 06:33:23 -0800 Message-Id: <3b9e1dba6f3249434a617a56f1af010d9d3d4df5.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 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 information about the on-disk layout of the stripes in a RAID set. Each stripe extent has a 1:1 relationship with an on-disk extent item and is doing the logical to per-drive physical address translation for the extent item in question. Reviewed-by: Josef Bacik Reviewed-by: Anand Jain Signed-off-by: Johannes Thumshirn --- fs/btrfs/accessors.h | 29 +++++++++++++++++++++++++++++ include/uapi/linux/btrfs_tree.h | 20 ++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/accessors.h b/fs/btrfs/accessors.h index ceadfc5d6c66..6e753b63faae 100644 --- a/fs/btrfs/accessors.h +++ b/fs/btrfs/accessors.h @@ -306,6 +306,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(raid_stride_devid, struct btrfs_raid_stride, devid, 64); +BTRFS_SETGET_FUNCS(raid_stride_physical, struct btrfs_raid_stride, physical, 64); +BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_devid, struct btrfs_raid_stride, devid, 64); +BTRFS_SETGET_STACK_FUNCS(stack_raid_stride_physical, struct btrfs_raid_stride, physical, 64); + +static inline struct btrfs_raid_stride *btrfs_raid_stride_nr( + struct btrfs_stripe_extent *dps, int nr) +{ + unsigned long offset = (unsigned long)dps; + + offset += offsetof(struct btrfs_stripe_extent, strides); + offset += nr * sizeof(struct btrfs_raid_stride); + return (struct btrfs_raid_stride *)offset; +} + +static inline u64 btrfs_raid_stride_devid_nr(const struct extent_buffer *eb, + struct btrfs_stripe_extent *dps, + int nr) +{ + return btrfs_raid_stride_devid(eb, btrfs_raid_stride_nr(dps, nr)); +} + +static inline u64 btrfs_raid_stride_physical_nr(const struct extent_buffer *eb, + struct btrfs_stripe_extent *dps, + int nr) +{ + return btrfs_raid_stride_physical(eb, btrfs_raid_stride_nr(dps, nr)); +} + /* struct btrfs_dev_extent */ BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index ab38d0f411fa..64e6bf2a10d8 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -4,9 +4,8 @@ #include #include -#ifdef __KERNEL__ #include -#else +#ifndef __KERNEL__ #include #endif @@ -73,6 +72,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 @@ -281,6 +283,8 @@ */ #define BTRFS_QGROUP_RELATION_KEY 246 +#define BTRFS_RAID_STRIPE_KEY 247 + /* * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */ @@ -715,6 +719,18 @@ struct btrfs_free_space_header { __le64 num_bitmaps; } __attribute__ ((__packed__)); +struct btrfs_raid_stride { + /* btrfs device-id this raid extent lives on */ + __le64 devid; + /* physical location on disk */ + __le64 physical; +}; + +struct btrfs_stripe_extent { + /* array of raid strides this stripe is composed of */ + __DECLARE_FLEX_ARRAY(struct btrfs_raid_stride, strides); +}; + #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) From patchwork Wed Feb 15 14:33:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141739 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 ED086C64EC4 for ; Wed, 15 Feb 2023 14:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjBOOeH (ORCPT ); Wed, 15 Feb 2023 09:34:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbjBOOeD (ORCPT ); Wed, 15 Feb 2023 09:34:03 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9AB71E5E4 for ; Wed, 15 Feb 2023 06:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471632; x=1708007632; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Md7z+O++on9hq21DjFwROq/auSTZ1KSWoOE9rpq39CU=; b=dKzOmIZM0nOjM614Zhxb8hVG3qDebrIxx08atai/TZJ2+Z2jrxc5AcuX IJECy7ogLa1FZh77RxLDXQMOewJE4+BXO/u9qcaDd+ARbV0DYv0plgJ0s PYgcn8uVBxE9BZZsmHb6Z3j9YRZbZwQpzB8OvMHiBtBiUWHlt1O4t6kSn ifVhgfQ9bIfLzM2i4uCHMuSays2qUuVnykZ4RyFc/MfoEnhvIVdekqwnT HEdfV3Ra8kViw5mQGnXA7PlzFdbNY33hoJm8SiIFaiDfTPrlPh5o4xYhS IL+hAW9HU2Vp5XsOVoQkVSNWaXJrPQ3YID/D3hSIrmGnttsTBWzgupUx4 A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394065" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:42 +0800 IronPort-SDR: 9ih6JRlMWys++pUpl0SMpaqC6UC9VVMhiNgSAiaMGJ1LdwgnSstSuRFfYUtBqimTHGctx7jAPa 6/8LpHpnqWoziCW+CQ4vv4q2nsntcR2QlQNs/LW+kOPgKKkXdU+zk+bG75NJIrxWH/ixmdmq9V Yl5TqATqgfqtupltBj46NqR/EH8q0MIAfTxtFfbhl/qS5GMEDXCTPwGYpvD/D/wTH3A+7NdvQP EH/NjjcVPRvQalv3hUaxQGS+eNYQ058+8iW8MwzdVQZclC0hPIo8UFwjxdw8dgfPFhh8HemuCt AEs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:04 -0800 IronPort-SDR: g+zmDj3jHb1EfxnqgR+oJUv+Iowj6OMzM6mWRYWHJVFHflSSQkqzAkBY1PSHkyy2+/gJRufi84 s1pep7tU8lD2HMp3shlJPXBgxI7d+XSn7NPDkRDNpmhwd08LCKGa6TCsctQ4X3ZLzmw4tPs8wL 9svAEG47gHE2NRNs14G79KI7xgFqZ2VaqYVPgbjcO8f0tPbOlsfzMv7ygTtpLK8BmBebSTPwx4 LUEHKSUPyr4bMg8ET2JR0M4H3j6ByjCWgSKLSnyx1qjmJQwxs4P6yISsD9lnKvC8fZZkx8rgum oXA= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:42 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik , Anand Jain Subject: [PATCH v6 03/13] btrfs: read raid-stripe-tree from disk Date: Wed, 15 Feb 2023 06:33:24 -0800 Message-Id: <9e67acf1f844749ff72e25c8e9ac99b76b126b12.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 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. Reviewed-by: Josef Bacik Reviewed-by: Anand Jain Signed-off-by: Johannes Thumshirn --- fs/btrfs/block-rsv.c | 1 + fs/btrfs/disk-io.c | 19 +++++++++++++++++++ fs/btrfs/disk-io.h | 5 +++++ fs/btrfs/fs.h | 1 + include/uapi/linux/btrfs.h | 1 + 5 files changed, 27 insertions(+) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 5367a14d44d2..384987343a64 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -402,6 +402,7 @@ void btrfs_init_root_block_rsv(struct btrfs_root *root) case BTRFS_EXTENT_TREE_OBJECTID: case BTRFS_FREE_SPACE_TREE_OBJECTID: case BTRFS_BLOCK_GROUP_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/disk-io.c b/fs/btrfs/disk-io.c index b53f0e30ce2b..32d4b2c4a107 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1438,6 +1438,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; } @@ -1516,6 +1519,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); @@ -2051,6 +2055,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); } @@ -2503,6 +2508,20 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) fs_info->uuid_root = root; } + if (btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE)) { + location.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root = btrfs_read_tree_root(tree_root, &location); + if (IS_ERR(root)) { + if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) { + ret = PTR_ERR(root); + goto out; + } + } else { + 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/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 4d5772330110..c4de38374b62 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -107,6 +107,11 @@ static inline struct btrfs_root *btrfs_grab_root(struct btrfs_root *root) return NULL; } +static inline struct btrfs_root *btrfs_stripe_tree_root(struct btrfs_fs_info *fs_info) +{ + return fs_info->stripe_root; +} + void btrfs_put_root(struct btrfs_root *root); void btrfs_mark_buffer_dirty(struct extent_buffer *buf); int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 4c477eae6891..93f2499a9c5b 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -367,6 +367,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/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index b4f0f9531119..593fb7930a37 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -322,6 +322,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_RAID_STRIPE_TREE (1ULL << 14) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Wed Feb 15 14:33:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141740 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 4CB6FC636D4 for ; Wed, 15 Feb 2023 14:34:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjBOOeI (ORCPT ); Wed, 15 Feb 2023 09:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbjBOOeF (ORCPT ); Wed, 15 Feb 2023 09:34:05 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06A82392B3 for ; Wed, 15 Feb 2023 06:33:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471635; x=1708007635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J++Wx5HnD5La0Dq5pgmvelRsJZ0zUHpJz7BY9J6LJdo=; b=lnIyqcCJUS3O3fshysHsAtqG+JCJG8RJqKDGnUob2OYb4ctP/1BGlkyV V7RIFeJfmLhZlHc5CBrNzxmu6JCguWEzl2attyGf12RRV1nTh7QF4T+7A F+5No4kQg6V5bKQq+7sW17IkwoSxIQuRCZNtJ1zonoZQd+lDnpHS6U50G uLqc7t+Ifej9tVL1U5N6TX6ENcVay5bWODiPiIAXLzonlMLmQu0DnsUmh SLwhIMoubu7sCd9eqfjXWhp6zdLBkpyyIRGHVmj+gKz2UWo55L0bOyTUa fRPy1XeUU8eG0IRG1JlOPJQFIXQTxtTVnEHPfTVlVVA1PxeYRAekEsJXL Q==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394066" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:43 +0800 IronPort-SDR: ybGK4V0UrZ2060Eo1+nFxez1RNS13ynA/IjFOqQebx5T3HvCfaC4AeU/xvNx+3RbApwQhaHk4R G31ldVr+sSFNOXiNk5y1ryLuuJRyzP8h8tB3y9OW8GN372esIFdRLBOv73U+VMISHDiUnY3WVY roLHyjT0kJm0EjF/08IAkU5zwvtCJ8z5NRDIHxr1VpIwHgY4gWgBlNYdQ4Xk2hH2ke+q5o2k7A p2Xa1LhbQCzoLfEL9U1xDHtpvfvzXTHNzc+9nblpAeb2x6qqoxtcaEtKPggBu4Zb6aDrddz0PB 7pw= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:05 -0800 IronPort-SDR: RMvx8HJbVK+7x+Snv67u62Ga9GHiOrEdjXmzH72uA2qZ5BRCzoVVlJXjNihHG8/S9HMrRfJqIX HZKsVm2eRA08JLP6wVr/kQJg1e4uaBS2dAyfLXfHA7ES+tDqXZjC5jJADWXXYJBsAVbMzfv3Sq BBloQNTqnxljO9OF5PNIRQ6622VSq8GeZ5ZmHYw1mNk6lFisjTQOV9r9lhNLklllAwzf5+1JSI HKW6xS+DjO/870whHdpjFiJUzy6uuxfHdbB3yeNdg3XWiy1ekgqwInXu41mvumAWC6hbtvLKxB TFg= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:43 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [PATCH v6 04/13] btrfs: add support for inserting raid stripe extents Date: Wed, 15 Feb 2023 06:33:25 -0800 Message-Id: <18a62ab611da20f71b2e26af27ba473796d3a47a.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add support for inserting stripe extents into the raid stripe tree on completion of every write that needs an extra logical-to-physical translation when using RAID. Inserting the stripe extents happens after the data I/O has completed, this is done to a) support zone-append and b) rule out the possibility of a RAID-write-hole. This is done by creating in-memory ordered stripe extents, just like the in memory ordered extents, on I/O completion and the on-disk raid stripe extents get created once we're running the delayed_refs for the extent item this stripe extent is tied to. Signed-off-by: Johannes Thumshirn --- fs/btrfs/Makefile | 2 +- fs/btrfs/bio.c | 29 +++++ fs/btrfs/delayed-ref.c | 6 +- fs/btrfs/delayed-ref.h | 2 + fs/btrfs/disk-io.c | 3 + fs/btrfs/extent-tree.c | 60 +++++++++++ fs/btrfs/fs.h | 3 + fs/btrfs/inode.c | 15 ++- fs/btrfs/raid-stripe-tree.c | 204 ++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 71 +++++++++++++ fs/btrfs/volumes.c | 5 +- fs/btrfs/volumes.h | 12 +-- fs/btrfs/zoned.c | 3 + 13 files changed, 403 insertions(+), 12 deletions(-) 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 90d53209755b..3bb869a84e54 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -33,7 +33,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.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 extent-io-tree.o fs.o messages.o bio.o \ - lru_cache.o + lru_cache.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/bio.c b/fs/btrfs/bio.c index d8b90f95b157..0184d4a2ba56 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -15,6 +15,7 @@ #include "rcu-string.h" #include "zoned.h" #include "file-item.h" +#include "raid-stripe-tree.h" static struct bio_set btrfs_bioset; static struct bio_set btrfs_clone_bioset; @@ -348,6 +349,21 @@ static void btrfs_raid56_end_io(struct bio *bio) btrfs_put_bioc(bioc); } +static void btrfs_raid_stripe_update(struct work_struct *work) +{ + struct btrfs_bio *bbio = + container_of(work, struct btrfs_bio, end_io_work); + struct btrfs_io_stripe *stripe = bbio->bio.bi_private; + struct btrfs_io_context *bioc = stripe->bioc; + int ret; + + ret = btrfs_add_ordered_stripe(bioc); + if (ret) + bbio->bio.bi_status = errno_to_blk_status(ret); + btrfs_orig_bbio_end_io(bbio); + btrfs_put_bioc(bioc); +} + static void btrfs_orig_write_end_io(struct bio *bio) { struct btrfs_io_stripe *stripe = bio->bi_private; @@ -370,6 +386,16 @@ static void btrfs_orig_write_end_io(struct bio *bio) else bio->bi_status = BLK_STS_OK; + if (bio_op(bio) == REQ_OP_ZONE_APPEND) + stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; + + if (btrfs_need_stripe_tree_update(bioc->fs_info, bioc->map_type)) { + INIT_WORK(&bbio->end_io_work, btrfs_raid_stripe_update); + queue_work(btrfs_end_io_wq(bioc->fs_info, bio), + &bbio->end_io_work); + return; + } + btrfs_orig_bbio_end_io(bbio); btrfs_put_bioc(bioc); } @@ -381,6 +407,8 @@ static void btrfs_clone_write_end_io(struct bio *bio) if (bio->bi_status) { atomic_inc(&stripe->bioc->error); btrfs_log_dev_io_error(bio, stripe->dev); + } else if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + stripe->physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; } /* Pass on control to the original bio this one was cloned from */ @@ -440,6 +468,7 @@ static void btrfs_submit_mirrored_bio(struct btrfs_io_context *bioc, int dev_nr) bio->bi_private = &bioc->stripes[dev_nr]; bio->bi_iter.bi_sector = bioc->stripes[dev_nr].physical >> SECTOR_SHIFT; bioc->stripes[dev_nr].bioc = bioc; + bioc->size = bio->bi_iter.bi_size; btrfs_submit_dev_bio(bioc->stripes[dev_nr].dev, bio); } diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 7660ac642c81..261f52ad8e12 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -14,6 +14,7 @@ #include "space-info.h" #include "tree-mod-log.h" #include "fs.h" +#include "raid-stripe-tree.h" struct kmem_cache *btrfs_delayed_ref_head_cachep; struct kmem_cache *btrfs_delayed_tree_ref_cachep; @@ -637,8 +638,11 @@ static int insert_delayed_ref(struct btrfs_trans_handle *trans, exist->ref_mod += mod; /* remove existing tail if its ref_mod is zero */ - if (exist->ref_mod == 0) + if (exist->ref_mod == 0) { + btrfs_drop_ordered_stripe(trans->fs_info, exist->bytenr); drop_delayed_ref(root, href, exist); + } + spin_unlock(&href->lock); return ret; inserted: diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 2eb34abf700f..5096c1a1ed3e 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -51,6 +51,8 @@ struct btrfs_delayed_ref_node { /* is this node still in the rbtree? */ unsigned int is_head:1; unsigned int in_tree:1; + /* Do we need RAID stripe tree modifications? */ + unsigned int must_insert_stripe:1; }; struct btrfs_delayed_extent_op { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 32d4b2c4a107..8f625cc6738d 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3030,6 +3030,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); + + rwlock_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 824c657f59e8..36a1476cc901 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -42,6 +42,7 @@ #include "file-item.h" #include "orphan.h" #include "tree-checker.h" +#include "raid-stripe-tree.h" #undef SCRAMBLE_DELAYED_REFS @@ -1497,6 +1498,56 @@ static int __btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, return ret; } +static bool delayed_ref_needs_rst_update(struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_head *head) +{ + struct extent_map *em; + struct map_lookup *map; + bool ret = false; + + if (!btrfs_stripe_tree_root(fs_info)) + return ret; + + em = btrfs_get_chunk_map(fs_info, head->bytenr, head->num_bytes); + if (!em) + return ret; + + map = em->map_lookup; + + if (btrfs_need_stripe_tree_update(fs_info, map->type)) + ret = true; + + free_extent_map(em); + + 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 btrfs_ordered_stripe *stripe; + int ret = 0; + + 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); + return -EINVAL; + } + + ASSERT(stripe->logical == node->bytenr); + + ret = btrfs_insert_raid_extent(trans, stripe); + /* once for us */ + btrfs_put_ordered_stripe(fs_info, stripe); + /* once for the tree */ + btrfs_put_ordered_stripe(fs_info, stripe); + + 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, @@ -1527,11 +1578,17 @@ static int run_delayed_data_ref(struct btrfs_trans_handle *trans, flags, ref->objectid, ref->offset, &ins, node->ref_mod); + if (ret) + return ret; + if (node->must_insert_stripe) + 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, node->ref_mod, extent_op); } else if (node->action == BTRFS_DROP_DELAYED_REF) { + if (node->must_insert_stripe) + btrfs_drop_ordered_stripe(trans->fs_info, node->bytenr); ret = __btrfs_free_extent(trans, node, parent, ref_root, ref->objectid, ref->offset, node->ref_mod, @@ -1901,6 +1958,8 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_extent_op *extent_op; struct btrfs_delayed_ref_node *ref; + const bool need_rst_update = + delayed_ref_needs_rst_update(fs_info, locked_ref); int must_insert_reserved = 0; int ret; @@ -1951,6 +2010,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, locked_ref->extent_op = NULL; spin_unlock(&locked_ref->lock); + ref->must_insert_stripe = need_rst_update; ret = run_one_delayed_ref(trans, ref, extent_op, must_insert_reserved); diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 93f2499a9c5b..d0d80540b32b 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -791,6 +791,9 @@ struct btrfs_fs_info { struct lockdep_map btrfs_trans_pending_ordered_map; struct lockdep_map btrfs_ordered_extent_map; + rwlock_t 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/inode.c b/fs/btrfs/inode.c index 44e9acc77a74..c1e459f8a672 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -70,6 +70,7 @@ #include "verity.h" #include "super.h" #include "orphan.h" +#include "raid-stripe-tree.h" struct btrfs_iget_args { u64 ino; @@ -9508,12 +9509,17 @@ 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, true, qgroup_released); if (ret) - goto free_qgroup; + goto free_stripe_extent; return trans; } @@ -9531,7 +9537,7 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent( path = btrfs_alloc_path(); if (!path) { ret = -ENOMEM; - goto free_qgroup; + goto free_stripe_extent; } ret = btrfs_replace_file_extents(inode, path, file_offset, @@ -9539,9 +9545,12 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent( &trans); btrfs_free_path(path); if (ret) - goto free_qgroup; + goto free_stripe_extent; return trans; +free_stripe_extent: + btrfs_drop_ordered_stripe(inode->root->fs_info, start); + free_qgroup: /* * We have released qgroup data range at the beginning of the function, diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c new file mode 100644 index 000000000000..9d3e7bffe6f8 --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.c @@ -0,0 +1,204 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Western Digital Corporation or its affiliates. + */ + +#include + +#include "ctree.h" +#include "fs.h" +#include "accessors.h" +#include "transaction.h" +#include "disk-io.h" +#include "raid-stripe-tree.h" +#include "volumes.h" +#include "misc.h" +#include "disk-io.h" +#include "print-tree.h" + +static int ordered_stripe_cmp(const void *key, const struct rb_node *node) +{ + struct btrfs_ordered_stripe *stripe = + rb_entry(node, struct btrfs_ordered_stripe, rb_node); + const u64 *logical = key; + + if (*logical < stripe->logical) + return -1; + if (*logical >= stripe->logical + stripe->num_bytes) + return 1; + return 0; +} + +static int ordered_stripe_less(struct rb_node *rba, const struct rb_node *rbb) +{ + struct btrfs_ordered_stripe *stripe = + rb_entry(rba, struct btrfs_ordered_stripe, rb_node); + return ordered_stripe_cmp(&stripe->logical, rbb); +} + +int btrfs_add_ordered_stripe(struct btrfs_io_context *bioc) +{ + struct btrfs_fs_info *fs_info = bioc->fs_info; + struct btrfs_ordered_stripe *stripe; + struct btrfs_io_stripe *tmp; + u64 logical = bioc->logical; + u64 length = bioc->size; + struct rb_node *node; + size_t size; + + size = bioc->num_stripes * sizeof(struct btrfs_io_stripe); + stripe = kzalloc(sizeof(struct btrfs_ordered_stripe), GFP_NOFS); + if (!stripe) + return -ENOMEM; + + spin_lock_init(&stripe->lock); + tmp = kmemdup(bioc->stripes, size, GFP_NOFS); + if (!tmp) { + kfree(stripe); + return -ENOMEM; + } + + stripe->logical = logical; + stripe->num_bytes = length; + stripe->num_stripes = bioc->num_stripes; + spin_lock(&stripe->lock); + stripe->stripes = tmp; + spin_unlock(&stripe->lock); + refcount_set(&stripe->ref, 1); + + write_lock(&fs_info->stripe_update_lock); + node = rb_find_add(&stripe->rb_node, &fs_info->stripe_update_tree, + ordered_stripe_less); + if (node) { + struct btrfs_ordered_stripe *old = + rb_entry(node, struct btrfs_ordered_stripe, rb_node); + + btrfs_debug(fs_info, "logical: %llu, length: %llu already exists", + logical, length); + ASSERT(logical == old->logical); + + rb_replace_node(node, &stripe->rb_node, + &fs_info->stripe_update_tree); + } + write_unlock(&fs_info->stripe_update_lock); + + return 0; +} + +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 = NULL; + struct rb_node *node; + + read_lock(&fs_info->stripe_update_lock); + node = rb_find(&logical, root, ordered_stripe_cmp); + if (node) { + stripe = rb_entry(node, struct btrfs_ordered_stripe, rb_node); + refcount_inc(&stripe->ref); + } + read_unlock(&fs_info->stripe_update_lock); + + return stripe; +} + +void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_ordered_stripe *stripe) +{ + + if (refcount_dec_and_test(&stripe->ref)) { + struct rb_node *node; + + write_lock(&fs_info->stripe_update_lock); + + node = &stripe->rb_node; + rb_erase(node, &fs_info->stripe_update_tree); + RB_CLEAR_NODE(node); + + spin_lock(&stripe->lock); + kfree(stripe->stripes); + spin_unlock(&stripe->lock); + kfree(stripe); + write_unlock(&fs_info->stripe_update_lock); + } +} + +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 (!btrfs_stripe_tree_root(fs_info)) + return 0; + + ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, start, &map_length, + &bioc, 0); + if (ret) + return ret; + + bioc->size = len; + + stripe = btrfs_lookup_ordered_stripe(fs_info, start); + if (!stripe) { + ret = btrfs_add_ordered_stripe(bioc); + if (ret) + return ret; + } 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) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_key stripe_key; + struct btrfs_root *stripe_root = btrfs_stripe_tree_root(fs_info); + struct btrfs_stripe_extent *stripe_extent; + size_t item_size; + int ret; + + item_size = stripe->num_stripes * sizeof(struct btrfs_raid_stride); + + stripe_extent = kzalloc(item_size, GFP_NOFS); + if (!stripe_extent) { + 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_raid_stride *raid_stride = + &stripe_extent->strides[i]; + + btrfs_set_stack_raid_stride_devid(raid_stride, devid); + btrfs_set_stack_raid_stride_physical(raid_stride, 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, stripe_extent, + item_size); + if (ret) + btrfs_abort_transaction(trans, ret); + + kfree(stripe_extent); + + return ret; +} diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h new file mode 100644 index 000000000000..60d3f8489cc9 --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022 Western Digital Corporation or its affiliates. + */ + +#ifndef BTRFS_RAID_STRIPE_TREE_H +#define BTRFS_RAID_STRIPE_TREE_H + +#include "disk-io.h" +#include "messages.h" + +struct btrfs_io_context; + +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); +int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info, + u64 start, u64 len); +struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe( + struct btrfs_fs_info *fs_info, + u64 logical); +int btrfs_add_ordered_stripe(struct btrfs_io_context *bioc); +void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, + struct btrfs_ordered_stripe *stripe); + +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 (!btrfs_stripe_tree_root(fs_info)) + return false; + + if (type != BTRFS_BLOCK_GROUP_DATA) + return false; + + if (profile & BTRFS_BLOCK_GROUP_RAID1_MASK) + return true; + + return false; +} + +static inline void btrfs_drop_ordered_stripe(struct btrfs_fs_info *fs_info, + u64 logical) +{ + struct btrfs_ordered_stripe *stripe; + + if (!btrfs_stripe_tree_root(fs_info)) + return; + + stripe = btrfs_lookup_ordered_stripe(fs_info, logical); + if (!stripe) + return; + ASSERT(refcount_read(&stripe->ref) == 2); + /* once for us */ + btrfs_put_ordered_stripe(fs_info, stripe); + /* once for the tree */ + btrfs_put_ordered_stripe(fs_info, stripe); +} +#endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7823168c08a6..597aaac12254 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5899,6 +5899,7 @@ static void sort_parity_stripes(struct btrfs_io_context *bioc, int num_stripes) } static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_info, + u64 logical, int total_stripes, int real_stripes) { @@ -5922,6 +5923,7 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ refcount_set(&bioc->refs, 1); bioc->fs_info = fs_info; + bioc->logical = logical; bioc->tgtdev_map = (int *)(bioc->stripes + total_stripes); bioc->raid_map = (u64 *)(bioc->tgtdev_map + real_stripes); @@ -6526,7 +6528,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, goto out; } - bioc = alloc_btrfs_io_context(fs_info, num_alloc_stripes, tgtdev_indexes); + bioc = alloc_btrfs_io_context(fs_info, logical, num_alloc_stripes, + tgtdev_indexes); if (!bioc) { ret = -ENOMEM; goto out; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 7e51f2238f72..5d7547b5fa87 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -368,12 +368,10 @@ struct btrfs_fs_devices { struct btrfs_io_stripe { struct btrfs_device *dev; - union { - /* Block mapping */ - u64 physical; - /* For the endio handler */ - struct btrfs_io_context *bioc; - }; + /* Block mapping */ + u64 physical; + /* For the endio handler */ + struct btrfs_io_context *bioc; }; struct btrfs_discard_stripe { @@ -409,6 +407,8 @@ struct btrfs_io_context { int mirror_num; int num_tgtdevs; int *tgtdev_map; + u64 logical; + u64 size; /* * 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 f95b2c94d619..7e6cfc7a2918 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1692,6 +1692,9 @@ void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered) u64 chunk_start_phys; u64 logical; + /* Filesystems with a stripe tree have their own l2p mapping */ + ASSERT(!btrfs_stripe_tree_root(fs_info)); + em = btrfs_get_chunk_map(fs_info, orig_logical, 1); if (IS_ERR(em)) return; From patchwork Wed Feb 15 14:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141738 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 F375CC636D4 for ; Wed, 15 Feb 2023 14:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbjBOOeG (ORCPT ); Wed, 15 Feb 2023 09:34:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjBOOeD (ORCPT ); Wed, 15 Feb 2023 09:34:03 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EFBA27481 for ; Wed, 15 Feb 2023 06:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471637; x=1708007637; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DPLwugiUN11C/hYVLmrycfTWQUaMYko3yQ9Silebc68=; b=ppJSuIdeLL4iD6NGy0BvNd/2Y6o+6DbQIEzmDKdHiDWrM/XKfh3boIdQ 10Be7pMyxRq/dwbwnyaZsW8zl6ddLhoZ2+eclBglLuc3psSp0plAxEq4F MU71NfXtE+k/vYGzvPNhDOE1dAddhL3hsNA2qleeOOnn7TeB6kxBMG9e9 rwhMpzXn3D2delLdwM+0yKOkUm3ZbH209SqzqAVxw/WzDdzlC6xkCqqn8 vA6tFWeD9rfiaO36fE1Qnb4jCvkbnybxbaEHToMnq645/KIFpxExdM5Vu 5a4b2Gkxd4kqAdHbApPrwzbtkD+cg3IUAl7bX2TPxry1D6LJUY77ck7Cn A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394067" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:43 +0800 IronPort-SDR: qDTgJHuT6guBClUQARt7muABuRYpkG8ZdsUhzvcP7AtxJGJSjqShonNosLAK2ZJRsNDOZmLca+ OQyTrWaGErRmhMP+dbcVvHDw1XyH3ZlH+9C79mw1ckPEefE2Z6QA7WtLMETrfDk4ur/OAehP3n vW3NBkQU2u4NlZtmsUMGIGC50JlL8mArNh8Cb2nimX9mCe8VZfJA+JDTvBhXA55ITXQtQX5Jrw UKxPpBJvEA3jpVDo93qL/s6Ak+weUJ5Rh/roGrA7flYKYaHA/slhhygDCKY9owK8+PHsyl8VHz Xts= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:05 -0800 IronPort-SDR: mWPHSLHwnbQKJZcp5jsuNAvPAjnhRRMaZqv4QdbXSuURumdIdR4cvsrWeWmDRPhLVDcXR/CLF+ rfUm/lYi39mXDrD/XvmATdwoiU/v83tfeCTe4jW4qnxVJLlb0dBgADUTcJ58XjhbZChglRGdVy BJUMzQ0xcc81GCvhPG+bN4BIz360lma0m/qV0WfjTwPPLWtsPfBrRECNmzIIW3D2y7kf1IfQlc o6fI6yiGIl2DOdve2SWomt4efBqEihDf4yU5wFRC09J/ISr/WRzebPX6u68dA4Z62nL14ge7jm CJo= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:44 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [PATCH v6 05/13] btrfs: delete stripe extent on extent deletion Date: Wed, 15 Feb 2023 06:33:26 -0800 Message-Id: <0f6a7e34d297565230d92c253418f2addc4849ad.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As each stripe extent is tied to an extent item, delete the stripe extent once the corresponding extent item is 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 36a1476cc901..10827b7db13c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3238,6 +3238,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 9d3e7bffe6f8..8912389d7c2f 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -124,6 +124,37 @@ void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, } } +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 = btrfs_stripe_tree_root(fs_info); + 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 < 0) + 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 60d3f8489cc9..12d2f588b22d 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -22,6 +22,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 Feb 15 14:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141742 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 6D6A3C636CC for ; Wed, 15 Feb 2023 14:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjBOOeL (ORCPT ); Wed, 15 Feb 2023 09:34:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjBOOeG (ORCPT ); Wed, 15 Feb 2023 09:34:06 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A30F37F15 for ; Wed, 15 Feb 2023 06:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471643; x=1708007643; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IFVhtYJj3xd2FV2UwuwJM8XGjl+thv//67Y6H5Fz5P8=; b=dLs7VAN9d0gLoOr4oMfWNyOB8i8se1X2CisB0XhXdsL3oebGr2VS2JWd U2GLkoXQmvDNKCe76EfGU/RxZdeNZuNGMml6T7q60LT3BW4i5koRJEfht 4um23z5EmKVsl1dSHZ/B5MmOMtUWPTOUWVpj7PG7gZ/G6vjfnCirlEB9a KESyJJWyX0c2DyaIicdquDjoIWpzQ2JMdJdBFcuXpSRZfmhesz4xc9YqQ 7ixd+XMu2yZjBMQF/lyWsNH61cQwDPAOJOhUUNQ825MkkG8jiKwCwfzGe gOJZkGCYYEKPGpQfKL08P9P8rLE5FkC4ijfaCLFJefHb0u6ubgnUaA4cv A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394069" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:44 +0800 IronPort-SDR: D3GT1YeoxTwf4MCQG4my7SbNuBahCEljOWmRw9r2a8n5IfieLM7rtKmwkua/nevVehPOgi4sSi tIXRJrB54cna7aTnLB3bXYjjokc2WmIW3cDqI1tmhL0vTnRCQMxsZGSDl/uA9xYSEQBzwJxKgI jld9d64ya/YEHbx2qQ8SyX4MMKJQHva7Zs4Wafu0x7aE8dQchz1gCulnGPhfArGZ8kW/Azee5D xjUO9PvTtRsqoQBUJWGT6RrHsN3xdMmvwS5lEwYm/kmdMX8+JA6UmbZ/lsdFqmUl/4Fa5Wkldy N8g= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:06 -0800 IronPort-SDR: XH+/BzWaXFuLsLQlevAR0DyZ1zOtbetOcyH1G+UeFLgMa2JgTuxx5teAw7nHlpToPMpyedHw8n B8Z9fn4CgRFqEvlKPU5/tV6LKL4l7U4bhC/Y9ms6Sv+ts4TbLMYFxoQkRdEsLSFKeUuq5fpFuJ Sz+Rwrj6S3fkLT7c2FBGHyfRRfwcSXJMge5MWVPF2JXybXQb2uWG9AsTEs78FnXpRn4rzGM2wJ 9hSb3+FX5hKju/kUkdEm1IGGbGD99SZFCAJ5kGtEYa0GUOluLq3alCMH+wMVM0s+PoGEbiA2KW ozE= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:44 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 06/13] btrfs: lookup physical address from stripe extent Date: Wed, 15 Feb 2023 06:33:27 -0800 Message-Id: <781dfa6fe45c62122c814f17fee8e1287b5566eb.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Lookup the physical address from the raid stripe tree when a read on an RAID volume formatted with the raid stripe tree was attempted. If the requested logical address was not found in the stripe tree, it may still be in the in-memory ordered stripe tree, so fallback to searching the ordered stripe tree in this case. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 145 ++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 3 + fs/btrfs/volumes.c | 31 ++++++-- 3 files changed, 172 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 8912389d7c2f..f58b28157a9c 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -233,3 +233,148 @@ int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, return ret; } + +static bool btrfs_physical_from_ordered_stripe(struct btrfs_fs_info *fs_info, + u64 logical, u64 *length, + int num_stripes, + struct btrfs_io_stripe *stripe) +{ + struct btrfs_ordered_stripe *os; + u64 offset; + u64 found_end; + u64 end; + int i; + + os = btrfs_lookup_ordered_stripe(fs_info, logical); + if (!os) + return false; + + end = logical + *length; + found_end = os->logical + os->num_bytes; + if (end > found_end) + *length -= end - found_end; + + for (i = 0; i < num_stripes; i++) { + if (os->stripes[i].dev != stripe->dev) + continue; + + ASSERT(logical >= os->logical); + offset = logical - os->logical; + stripe->physical = os->stripes[i].physical + offset; + btrfs_put_ordered_stripe(fs_info, os); + break; + } + + return true; +} + +int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, + u64 logical, u64 *length, u64 map_type, + struct btrfs_io_stripe *stripe) +{ + struct btrfs_root *stripe_root = btrfs_stripe_tree_root(fs_info); + int num_stripes = btrfs_bg_type_to_factor(map_type); + struct btrfs_stripe_extent *stripe_extent; + struct btrfs_key stripe_key; + struct btrfs_key found_key; + struct btrfs_path *path; + struct extent_buffer *leaf; + u64 offset; + u64 found_logical; + u64 found_length; + u64 end; + u64 found_end; + int slot; + int ret; + int i; + + /* + * If we still have the stripe in the ordered stripe tree get it from + * there + */ + if (btrfs_physical_from_ordered_stripe(fs_info, logical, length, + num_stripes, stripe)) + return 0; + + stripe_key.objectid = logical; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = 0; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + ret = btrfs_search_slot(NULL, stripe_root, &stripe_key, path, 0, 0); + if (ret < 0) + goto free_path; + if (ret) { + if (path->slots[0] != 0) + path->slots[0]--; + } + + end = logical + *length; + + 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 (found_logical > end) + break; + + if (!in_range(logical, found_logical, found_length)) + goto next; + + offset = logical - found_logical; + found_end = found_logical + found_length; + + /* + * If we have a logically contiguous, but physically + * noncontinuous range, we need to split the bio. Record the + * length after which we must split the bio. + */ + if (end > found_end) + *length -= end - found_end; + + stripe_extent = + btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); + for (i = 0; i < num_stripes; i++) { + if (btrfs_raid_stride_devid_nr(leaf, + stripe_extent, i) != stripe->dev->devid) + continue; + stripe->physical = btrfs_raid_stride_physical_nr(leaf, + stripe_extent, i) + offset; + ret = 0; + goto out; + } + + /* + * If we're here, we haven't found the requested devid in the + * stripe. + */ + ret = -ENOENT; + goto out; +next: + ret = btrfs_next_item(stripe_root, path); + if (ret) + break; + } + +out: + if (ret > 0) + ret = -ENOENT; + if (ret && ret != -EIO) { + btrfs_err(fs_info, + "cannot find raid-stripe for logical [%llu, %llu]", + logical, logical + *length); + btrfs_print_tree(leaf, 1); + } + +free_path: + btrfs_free_path(path); + + return ret; +} diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 12d2f588b22d..9359df0ca3f1 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -22,6 +22,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, + struct btrfs_io_stripe *stripe); 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 597aaac12254..10e1173097dc 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -35,6 +35,7 @@ #include "relocation.h" #include "scrub.h" #include "super.h" +#include "raid-stripe-tree.h" #define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ BTRFS_BLOCK_GROUP_RAID10 | \ @@ -6324,12 +6325,21 @@ static u64 btrfs_max_io_len(struct map_lookup *map, enum btrfs_map_op op, return U64_MAX; } -static void set_io_stripe(struct btrfs_io_stripe *dst, const struct map_lookup *map, - u32 stripe_index, u64 stripe_offset, u64 stripe_nr) +static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, + u64 logical, u64 *length, struct btrfs_io_stripe *dst, + struct map_lookup *map, u32 stripe_index, + u64 stripe_offset, u64 stripe_nr) { dst->dev = map->stripes[stripe_index].dev; + + if (op == BTRFS_MAP_READ && + btrfs_need_stripe_tree_update(fs_info, map->type)) + return btrfs_get_raid_extent_offset(fs_info, logical, length, + map->type, dst); + dst->physical = map->stripes[stripe_index].physical + stripe_offset + stripe_nr * map->stripe_len; + return 0; } int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, @@ -6518,13 +6528,14 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, smap->dev = dev_replace->tgtdev; smap->physical = physical_to_patch_in_first_stripe; *mirror_num_ret = map->num_stripes + 1; + ret = 0; } else { - set_io_stripe(smap, map, stripe_index, stripe_offset, - stripe_nr); *mirror_num_ret = mirror_num; + ret = set_io_stripe(fs_info, op, logical, length, smap, + map, stripe_index, stripe_offset, + stripe_nr); } *bioc_ret = NULL; - ret = 0; goto out; } @@ -6536,8 +6547,14 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } for (i = 0; i < num_stripes; i++) { - set_io_stripe(&bioc->stripes[i], map, stripe_index, stripe_offset, - stripe_nr); + ret = set_io_stripe(fs_info, op, logical, length, + &bioc->stripes[i], map, stripe_index, + stripe_offset, stripe_nr); + if (ret) { + btrfs_put_bioc(bioc); + goto out; + } + stripe_index++; } From patchwork Wed Feb 15 14:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141741 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 89EFEC636D7 for ; Wed, 15 Feb 2023 14:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjBOOeJ (ORCPT ); Wed, 15 Feb 2023 09:34:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjBOOeG (ORCPT ); Wed, 15 Feb 2023 09:34:06 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30C6638B55 for ; Wed, 15 Feb 2023 06:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471643; x=1708007643; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kS5bXobcd6NfCD1W2BItNtdkyqBgpEkjK5VH+u/635c=; b=OMpEDmnLa2leJudFrazYyC4AprQTJA1YG7D/7t5iuSzUj36NC6oy67th no39q/5U4WEvZn+O8FJLhY1Ue8+XOumX+79LdDsblWNtRgqqe3JSOUtdH XrNvwXjbgbbHBXsntOYTUKD674DRYu4zHUqlJqIrMVKVb6t5LstlAZB8o CxcI04ILTGe0i0BKozG2epJQFN8Ju7AOVahysEwSx1hxEtxjrdY8O8bV/ Z/V3WsczIUov8fw1ii+x21c/D3Jn4RdztMXLPJQKztFobOQAGVuPPwlmR wChVPdPaiEEP1eZj/7mZU025PqFM2eTE+sQF0y68SpbkGpQJeOeQZ9AZW A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394070" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:45 +0800 IronPort-SDR: GKP185ch+wHvtAfttY0muq0PoV/Tg+qZtJbnjAFm0bd5sY019qWoIienQKqVvIvmaBxl1IRnZL 0i5NVkPZ+rN4lPxwDzQpGcuUJ4Ly8BAnkDgF/VM/WxIsM3+PJQfqtmV6zTR9yqAICrMtyK1jKm mTHAY2hXsJ5qjCdWyDIX2h31wS24FebKvJMzHtg3GQcH5DfbSP3ceibKcJ3o2sItPN9tUUO7dt /7uXWSPnNO50qrh+kUetn12aOmZkypGB3AgoygdwAu34BcHKdnY89FZj/D8HwdI/ET7Xk5/PMl URI= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:07 -0800 IronPort-SDR: WxYeXRGazjwyEXPSlIx/I+717PsBjxK4VHr8n5VrcVZ371TqXIetNxEf9yUqRg549m7A7HM/Y9 nt+WbQrzCiBOSZAUxwaOK3/x3vjplV1SfRcKGwUWQTfQjZhqUG0eYFi2geLBCl5Xx6is5tQUli h7VUX02JffDY4zto7xcpKjN7Yk7tWtJdMKHKqR+cjDIUCs4Slmq5F8OZZ/ZmhlhoBfLXVJUblD V1vb1wyROgwbeGVbXbFFImauWCz70rS4Ho3TfzE/9N2z7JJfzS9DdA/sC2SY1Jg5JIPwFaracR Ap4= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:45 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 07/13] btrfs: add raid stripe tree pretty printer Date: Wed, 15 Feb 2023 06:33:28 -0800 Message-Id: <2faac5aa69f3f74b33d3573084143485b5198971.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 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(). Reviewed-by: Josef Bacik 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 b93c96213304..d9506d54298b 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -9,6 +9,7 @@ #include "print-tree.h" #include "accessors.h" #include "tree-checker.h" +#include "raid-stripe-tree.h" struct root_name_map { u64 id; @@ -28,6 +29,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) @@ -187,6 +189,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_stripe_extent *stripe) +{ + int num_stripes; + int i; + + num_stripes = item_size / sizeof(struct btrfs_raid_stride); + + for (i = 0; i < num_stripes; i++) + pr_info("\t\t\tstride %d devid %llu physical %llu\n", i, + btrfs_raid_stride_devid_nr(eb, stripe, i), + btrfs_raid_stride_physical_nr(eb, stripe, i)); +} + /* * Helper to output refs and locking status of extent buffer. Useful to debug * race condition related problems. @@ -351,6 +367,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_stripe_extent)); + break; } } } From patchwork Wed Feb 15 14:33:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141745 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 2B945C636CC for ; Wed, 15 Feb 2023 14:34:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjBOOeO (ORCPT ); Wed, 15 Feb 2023 09:34:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbjBOOeH (ORCPT ); Wed, 15 Feb 2023 09:34:07 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1CD25E36 for ; Wed, 15 Feb 2023 06:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471645; x=1708007645; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ttot3fzdp/oAonDgvC1+5QIfcb61lVMJ+ph+f83JOsU=; b=SHF6tvJGLPX/5Aq+k4S9OCLmLFwBcYtqph/IDCkaX06ZGItzBVXb9LW8 noimpnzbO568jCyOWffb/aLjQGDcmuT080mj7K1z9HNEdqWqwiYtLsn7x h+tbPPc1vhb50ER4LYjbTamDU007gYnpwiLuYFcLD608fPVB2iZngZP7e 3KQORYEDC9Nay3uBSfL6YNNIh2HYpT3DCqkRzSCZjuFhirbYH5JiX3zuN fMooBzz3C02Pv0DzdYV0NA/iBV3MjUSEuwJT0HBJv8iWVb6cSFA2N/Tmp hPSryuS06eCcPiEUFOGrdMcFiV6ImUS0ex1kfs8MslaJyvloyDXbz9uwI Q==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394071" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:46 +0800 IronPort-SDR: 1rhx1kp0UZf9s5iCvc43Aw+jJTNJbnH9Po2Izei62rVqFQxmmiqpnEKFLoc/wYVriulaEjY95E YpW78LHpnJ78x48ttDZTWNzlmhm67j8EgNiyxrbGwEvNVO8XNM8Q21685NSLIlovsFY00jIzFE Q8GEKbj39gOoXjkiSfpVE9HtNuoaC+DHKDJbtgdId/I/bSZqSkRnuPtJnOSsOr0KA9AMJJ88ee U281OJtmFaYOLS0ypOp9+HsBqF+peca0cbAZH41f83HrQmF215/kqeQwrKn5FV0GkOVjw4/t4i IJE= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:07 -0800 IronPort-SDR: MzXJ9D9ztgqawo1JT93Thfjn66iy4anE5M6Vx6wm4ZHGLhbRQPXRxH/87MpNzMY42Tolse+E1q PwxBMVwbmldDQeydO9bB1nvvUKN9wLM0+KhS2suSFZRyIK68BUx86JNaIBwY/fTc+s0ybeCuMF SuUirXknj5/JPE2SQbq5OGd9wyqShl23r8zgP/DaV9CC0vYitjbZKM959Zkc84h+k31GBJH1/A ziGX+bWUmlUcJxFm+0Pkco6qRxwI5GkvTKQvgQax0AqAIphb4vUF1ZPiEPQHZxRbSbdFW0aUCl zCM= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:46 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 08/13] btrfs: zoned: allow zoned RAID Date: Wed, 15 Feb 2023 06:33:29 -0800 Message-Id: X-Mailer: git-send-email 2.39.0 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 RAID0/1/10 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. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 4 ++++ fs/btrfs/raid-stripe-tree.h | 10 +++++++++ fs/btrfs/volumes.c | 5 ++++- fs/btrfs/zoned.c | 45 +++++++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index f58b28157a9c..836299fe0ebe 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -270,10 +270,12 @@ static bool btrfs_physical_from_ordered_stripe(struct btrfs_fs_info *fs_info, int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, u64 logical, u64 *length, u64 map_type, + u32 stripe_index, struct btrfs_io_stripe *stripe) { struct btrfs_root *stripe_root = btrfs_stripe_tree_root(fs_info); int num_stripes = btrfs_bg_type_to_factor(map_type); + const bool is_dup = map_type & BTRFS_BLOCK_GROUP_DUP; struct btrfs_stripe_extent *stripe_extent; struct btrfs_key stripe_key; struct btrfs_key found_key; @@ -345,6 +347,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, if (btrfs_raid_stride_devid_nr(leaf, stripe_extent, i) != stripe->dev->devid) continue; + if (is_dup && (stripe_index - 1) != i) + continue; stripe->physical = btrfs_raid_stride_physical_nr(leaf, stripe_extent, i) + offset; ret = 0; diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 9359df0ca3f1..c7f6c5377aaa 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -24,6 +24,7 @@ struct btrfs_ordered_stripe { int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, u64 logical, u64 *length, u64 map_type, + u32 stripe_index, struct btrfs_io_stripe *stripe); int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length); @@ -50,9 +51,18 @@ static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, if (type != BTRFS_BLOCK_GROUP_DATA) return false; + if (profile & BTRFS_BLOCK_GROUP_DUP) + return true; + if (profile & BTRFS_BLOCK_GROUP_RAID1_MASK) return true; + if (profile & BTRFS_BLOCK_GROUP_RAID0) + return true; + + if (profile & BTRFS_BLOCK_GROUP_RAID10) + return true; + return false; } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 10e1173097dc..9db1cd1b9747 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6335,7 +6335,8 @@ static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (op == BTRFS_MAP_READ && btrfs_need_stripe_tree_update(fs_info, map->type)) return btrfs_get_raid_extent_offset(fs_info, logical, length, - map->type, dst); + map->type, stripe_index, + dst); dst->physical = map->stripes[stripe_index].physical + stripe_offset + stripe_nr * map->stripe_len; @@ -6521,6 +6522,8 @@ int __btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * I/O context structure. */ if (smap && num_alloc_stripes == 1 && + !(btrfs_need_stripe_tree_update(fs_info, map->type) && + op != BTRFS_MAP_READ) && !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1) && (!need_full_stripe(op) || !dev_replace_is_ongoing || !dev_replace->tgtdev)) { diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 7e6cfc7a2918..3c251151b5da 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1476,8 +1476,9 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &cache->runtime_flags); break; case BTRFS_BLOCK_GROUP_DUP: - if (map->type & BTRFS_BLOCK_GROUP_DATA) { - btrfs_err(fs_info, "zoned: profile DUP not yet supported on data bg"); + if (map->type & BTRFS_BLOCK_GROUP_DATA && + !btrfs_stripe_tree_root(fs_info)) { + btrfs_err(fs_info, "zoned: data DUP profile needs stripe_root"); ret = -EINVAL; goto out; } @@ -1515,8 +1516,48 @@ 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: case BTRFS_BLOCK_GROUP_RAID0: case BTRFS_BLOCK_GROUP_RAID10: + if (map->type & BTRFS_BLOCK_GROUP_DATA && + !btrfs_stripe_tree_root(fs_info)) { + btrfs_err(fs_info, + "zoned: data %s needs stripe_root", + btrfs_bg_type_to_raid_name(map->type)); + ret = -EIO; + goto out; + + } + + for (i = 0; i < map->num_stripes; i++) { + if (alloc_offsets[i] == WP_MISSING_DEV || + alloc_offsets[i] == WP_CONVENTIONAL) + 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; + } + } else { + if (test_bit(0, active)) + set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, + &cache->runtime_flags); + } + cache->zone_capacity = min(caps[0], caps[i]); + } + cache->alloc_offset = alloc_offsets[0]; + break; case BTRFS_BLOCK_GROUP_RAID5: case BTRFS_BLOCK_GROUP_RAID6: /* non-single profiles are not supported yet */ From patchwork Wed Feb 15 14:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141743 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 61877C64ED6 for ; Wed, 15 Feb 2023 14:34:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbjBOOeM (ORCPT ); Wed, 15 Feb 2023 09:34:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbjBOOeH (ORCPT ); Wed, 15 Feb 2023 09:34:07 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAB8539286 for ; Wed, 15 Feb 2023 06:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471646; x=1708007646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SOhqtTpOJUlLWBsw3r78n/BqZyjAZL3yWe9ThQ3HzjA=; b=SOrJGbLU/iHB1vwtSiqSuWmdKzhsOfQPLGqLHhfpEKXeb+mXWrSS0J5y mo/huwBXD6tro2rrLJdctu+fYa55yv9mQ1OXty03rHaquuoeHjpUVgyEd On5+bum0PaTaEruKAtZfjzZjo+aZlrJ2DyF0t/qa6MEDwiq1cVxTVLa6C b95E8PF5qoUaF7fMIKklfopl2TAhaw0HSkjNWJm8aAgOZ8oG3bX0Oc2cO /JzjDudEWfnO5KGA02TJrKoPH9aMRGFmLTzbDO/RyVV/EtACOFxeU3RxP 3tPuZQCDJy786V3tM6co/h9NjZ6mklAuXe2l9UhiCVNOFxB5w8E0cyq/X g==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394072" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:46 +0800 IronPort-SDR: CouU2ECZb/IhORaDSp/8RE+rN4Z2T4SJ0LZjvfrERgfVkw59JJPDGnZCTUhTF+LuJIPZFCtCs1 sPwDTpZQ2AZQxz3Np1rhQg+v4uADBgfTDdcsCdTChI1QCxJnIcehpUIA/kOBhcUToLahS2Zs9o RuAiCEokoeMjwCoOae5nI/BSbwjupZwTMBxqS09mceob7/NqowEktmm/+xxI2eNRb7fmLgisHk 2HSmHM4Ekgb+m8BOUIbIU0dBNH2FjCrQ0YxFXhK4DMoMt6CvE/oBmz59jfN6NZqJ016+kmsVli 9mw= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:08 -0800 IronPort-SDR: l8ojY+DwRUWPQQVXFwTCgvSsz/GAom1rffWnsZhSAVIRdlrTNxo4j3g7ZYnNX0qYdO1qGcEmEF UX6HlHquE6OsxMS20d0FHFKmSwcaKMXWZQOO1oFaOlvR8qm3zxT345cZiaYfj2xGTse4RlQ8YT SwC5HsmRtUiKflDlHb+2FjbRPeulV52tfi3KGD0AZbUbpbpEJ+zt6/f2SvKRWtKVXCkc8dwmZd k29mWAaxG6T+1MMa7/fMBG3c/W+/fX4erfIoMNV2y7L6pDLotYYsTqgxapT72/8PahtTvoE7XA tSM= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:47 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 09/13] btrfs: check for leaks of ordered stripes on umount Date: Wed, 15 Feb 2023 06:33:30 -0800 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Check if we're leaking any ordered stripes when unmounting a filesystem with an stripe tree. This check is gated behind CONFIG_BTRFS_DEBUG to not affect any production type systems. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 2 ++ fs/btrfs/raid-stripe-tree.c | 30 ++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 1 + 3 files changed, 33 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8f625cc6738d..181638af3c81 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -52,6 +52,7 @@ #include "relocation.h" #include "scrub.h" #include "super.h" +#include "raid-stripe-tree.h" #define BTRFS_SUPER_FLAG_SUPP (BTRFS_HEADER_FLAG_WRITTEN |\ BTRFS_HEADER_FLAG_RELOC |\ @@ -1522,6 +1523,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info) btrfs_put_root(fs_info->stripe_root); btrfs_check_leaked_roots(fs_info); btrfs_extent_buffer_leak_debug_check(fs_info); + btrfs_check_ordered_stripe_leak(fs_info); kfree(fs_info->super_copy); kfree(fs_info->super_for_commit); kfree(fs_info->subpage_info); diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 836299fe0ebe..391f69effd90 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -36,6 +36,36 @@ static int ordered_stripe_less(struct rb_node *rba, const struct rb_node *rbb) return ordered_stripe_cmp(&stripe->logical, rbb); } +void btrfs_check_ordered_stripe_leak(struct btrfs_fs_info *fs_info) +{ +#ifdef CONFIG_BTRFS_DEBUG + struct rb_node *node; + + if (!btrfs_stripe_tree_root(fs_info) || + RB_EMPTY_ROOT(&fs_info->stripe_update_tree)) + return; + + WARN_ON_ONCE(1); + write_lock(&fs_info->stripe_update_lock); + while ((node = rb_first_postorder(&fs_info->stripe_update_tree)) + != NULL) { + struct btrfs_ordered_stripe *stripe = + rb_entry(node, struct btrfs_ordered_stripe, rb_node); + + write_unlock(&fs_info->stripe_update_lock); + btrfs_err(fs_info, + "ordered_stripe [%llu, %llu] leaked, refcount=%d", + stripe->logical, stripe->logical + stripe->num_bytes, + refcount_read(&stripe->ref)); + while (refcount_read(&stripe->ref) > 1) + btrfs_put_ordered_stripe(fs_info, stripe); + btrfs_put_ordered_stripe(fs_info, stripe); + write_lock(&fs_info->stripe_update_lock); + } + write_unlock(&fs_info->stripe_update_lock); +#endif +} + int btrfs_add_ordered_stripe(struct btrfs_io_context *bioc) { struct btrfs_fs_info *fs_info = bioc->fs_info; diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index c7f6c5377aaa..371409351d60 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -38,6 +38,7 @@ struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe( int btrfs_add_ordered_stripe(struct btrfs_io_context *bioc); void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, struct btrfs_ordered_stripe *stripe); +void btrfs_check_ordered_stripe_leak(struct btrfs_fs_info *fs_info); static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, u64 map_type) From patchwork Wed Feb 15 14:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141744 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 59669C636D7 for ; Wed, 15 Feb 2023 14:34:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjBOOeN (ORCPT ); Wed, 15 Feb 2023 09:34:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbjBOOeH (ORCPT ); Wed, 15 Feb 2023 09:34:07 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF9B39288 for ; Wed, 15 Feb 2023 06:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471646; x=1708007646; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ReU2dIpqcxDBplx1Qs0jKo3zdn7/Yg+Hw8Jj23xMN4U=; b=kdaExewzBKaqcah+f5Ou/RvXN8egaRkbLU4jqTxUUNA9B4iUjZRaqeL5 gd4MLWo8MB/xqdhiAzgoqtN9OLcbnN+XbtZ3S9XSbAoOywqHKoxzsn0Y3 4gmT9ODym5QtanshZzVWrYUdfBR8j8ZkogdvoKAOk6tjDrCvHtftCg2AL B7Ekv2MNHWka6mxDp41YTCYUDGrvkdF4/A6ckDPkWenucDjbOKzNDOM9M L8+buo1q22xsb5ma9/BETeKGgj8LikaiZCxUzqIj358bKExMaZ3BspS0E U1MQ5fphKoZUHn/e0ueuiJOJZCFvuT4g2lg2hIhNOj5Jr8QCZOOtwNZsk g==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394076" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:47 +0800 IronPort-SDR: zKd+htoNr6MKaspzzGPQpEeKUBvU09Yb1eomOvR9lYGBMaWHfyiqNv5Kwm9KUFCyFz1KVtHS/f O7Dkm2Kww+HBxQqJ1rn7dpDbeMFomcVKG3OgP5bnIW/cjE2pIHzO9AKQ+9jaj9EcPDY1FR5AlJ Pqm2qRrVq71wcCNqbBCQTV4GGpEMzpY6FM5fQyWYaUMh8yhfUx+ULnJDOsVokxJM2A3A6FjFWj 5EmvVbS9dgL4VMsO1HlQ5VBo+XMRg4Nx0i9nFZAODM7BqafiNYXtXdctkMr7O76Jco6ZS7K+aN 6xs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:09 -0800 IronPort-SDR: CkyNTMcozIkhfoUxBOL0pouN3+cxKWZzx81MrbQ2JNgtujpOAxSDBzj1QMHM8PocZ2MK5TVaD5 Y1vG9d67Ujjn33uXzEEq1B95qD/3RfL3SVQb3hx9tAck8oyi/eU7WvYhI9wWKxstdBqTdGGzUx UvByH3i8So0dbK2oHO9AorzHs6sXL0IwerFWiPPl6LfPoUM6g/aJ5P8A4NU1M0rejGLQKntZV5 UNSK8swpJx0TJTW2idofvEE8UxSwd0R7t1EYO719D43/IUTIJGP2Ieym17wVLkELJC627bjDsV OtE= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:47 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 10/13] btrfs: add tracepoints for ordered stripes Date: Wed, 15 Feb 2023 06:33:31 -0800 Message-Id: <71d4e246d1e9f6e4876de242aaa9111d7d9db303.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add tracepoints to check the lifetime of btrfs_ordered_stripe entries. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 4 ++- fs/btrfs/super.c | 1 + include/trace/events/btrfs.h | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 391f69effd90..8799a7abaf38 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -112,6 +112,7 @@ int btrfs_add_ordered_stripe(struct btrfs_io_context *bioc) } write_unlock(&fs_info->stripe_update_lock); + trace_btrfs_ordered_stripe_add(fs_info, stripe); return 0; } @@ -127,6 +128,7 @@ struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe(struct btrfs_fs_info *f if (node) { stripe = rb_entry(node, struct btrfs_ordered_stripe, rb_node); refcount_inc(&stripe->ref); + trace_btrfs_ordered_stripe_lookup(fs_info, stripe); } read_unlock(&fs_info->stripe_update_lock); @@ -136,7 +138,7 @@ struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe(struct btrfs_fs_info *f void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info, struct btrfs_ordered_stripe *stripe) { - + trace_btrfs_ordered_stripe_put(fs_info, stripe); if (refcount_dec_and_test(&stripe->ref)) { struct rb_node *node; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 581845bc206a..3345eb0ffebc 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -59,6 +59,7 @@ #include "verity.h" #include "super.h" #include "extent-tree.h" +#include "raid-stripe-tree.h" #define CREATE_TRACE_POINTS #include diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 75d7d22c3a27..8efea1445dd9 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -33,6 +33,7 @@ struct btrfs_space_info; struct btrfs_raid_bio; struct raid56_bio_trace_info; struct find_free_extent_ctl; +struct btrfs_ordered_stripe; #define show_ref_type(type) \ __print_symbolic(type, \ @@ -2492,6 +2493,55 @@ DEFINE_EVENT(btrfs_raid56_bio, raid56_scrub_read_recover, TP_ARGS(rbio, bio, trace_info) ); +DECLARE_EVENT_CLASS(btrfs__ordered_stripe, + + TP_PROTO(const struct btrfs_fs_info *fs_info, + const struct btrfs_ordered_stripe *stripe), + + TP_ARGS(fs_info, stripe), + + TP_STRUCT__entry_btrfs( + __field( u64, logical ) + __field( u64, num_bytes ) + __field( int, num_stripes ) + __field( int, ref ) + ), + + TP_fast_assign_btrfs(fs_info, + __entry->logical = stripe->logical; + __entry->num_bytes = stripe->num_bytes; + __entry->num_stripes = stripe->num_stripes; + __entry->ref = refcount_read(&stripe->ref); + ), + + TP_printk_btrfs("logical=%llu, num_bytes=%llu, num_stripes=%d, ref=%d", + __entry->logical, __entry->num_bytes, + __entry->num_stripes, __entry->ref) +); + +DEFINE_EVENT(btrfs__ordered_stripe, btrfs_ordered_stripe_add, + + TP_PROTO(const struct btrfs_fs_info *fs_info, + const struct btrfs_ordered_stripe *stripe), + + TP_ARGS(fs_info, stripe) +); + +DEFINE_EVENT(btrfs__ordered_stripe, btrfs_ordered_stripe_lookup, + + TP_PROTO(const struct btrfs_fs_info *fs_info, + const struct btrfs_ordered_stripe *stripe), + + TP_ARGS(fs_info, stripe) +); + +DEFINE_EVENT(btrfs__ordered_stripe, btrfs_ordered_stripe_put, + + TP_PROTO(const struct btrfs_fs_info *fs_info, + const struct btrfs_ordered_stripe *stripe), + + TP_ARGS(fs_info, stripe) +); #endif /* _TRACE_BTRFS_H */ /* This part must be outside protection */ From patchwork Wed Feb 15 14:33:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141747 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 7391CC636CC for ; Wed, 15 Feb 2023 14:34:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbjBOOeQ (ORCPT ); Wed, 15 Feb 2023 09:34:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbjBOOeI (ORCPT ); Wed, 15 Feb 2023 09:34:08 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8AA392A7 for ; Wed, 15 Feb 2023 06:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471647; x=1708007647; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7XU4wLrOB0mDh21cJDSAGXcKCGiGV9CrA3HzDj/iXqU=; b=BVdAzoXjbU7uxGHsu8Rb/Sjy9SWBtu14hzu42L+N1op0FwWZDXF/3yfo oIhmprpJ7sxko62vhmX7dVsPxDhLW5OUT4bTHVgoKjKeVUBlqT8lh7WMb 2mkMXAMeLAH4bj+oLGIZ6F0RSC23RCYlZ3If1glRd3+7MKmDynmYAM96o Y+7v2m3enD9PVxO20/i+HSjdyz5ZY7G2652/QnCywesN2Jz2WTtiyCqYD Dib+AP5wTIXCvQpMifJz8LT9mX9ltrWUGV8K1l81TQ/sfmrowJMpT4KcL 1tpv+xTCRHL+0e7jPLjGpy7EIhkj3DMzW7oINsYE6fjcd4kUqWBtDYrB7 A==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394077" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:48 +0800 IronPort-SDR: HrWKqGV9S02bIiaqQNpdFsXyp6z2Fp5+K9nC43CcrQHTBJ7dTIYUuKm4N6k4njzuhnj+Z43Zms 2WBn1STAkjiOh+EP6AEpGB22av4jDTc6FrOhSDAj1tiQphUlujFDRWjXY8H/rmo86Vds33ydpG atBcYq/t0tsURd8d5li7CNZMi0HZ8dForEvgDaCFsx+dNzmj3rvmoclwvy9jQrAuUM52afvvCr i77+CmB4q8odC2EtSU4ItQTwjkVLSer03cbGru2vJuuISt92wbNnraMVyzcA3PanNw8fOxaXL9 XGc= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:10 -0800 IronPort-SDR: kpZVkw28MQrKtUY64evnH8jHCGoNjVHW6Sd9VDWvfQ0I2D6wvhPDE05DT6JS5sl48U7nLqQl7Z K6tClEdrKs8iT2CJ94vWKkePeoBdPC5Qj3KZ5PbnEbPEdUFkErsb4sOJgKobqWUd6c7DjMbeCy cduiNKna9PMoqGTvccf2bikhPDcw61SmbXwe1xuJk0KF1ZoZTh2uBrlkrAQlXebCHHh46JTMWs TgYmoM4SDz4BrIVFPdUGJAJdxjm/l00PwhwrZejhhGcGs+vJhk2UBRcXxVdj+gb/Yowu421fKU 2Bc= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:48 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 11/13] btrfs: announce presence of raid-stripe-tree in sysfs Date: Wed, 15 Feb 2023 06:33:32 -0800 Message-Id: <9782b6e409fd456f70cbc07f3eb07e3ca4659578.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If a filesystem with a raid-stripe-tree is mounted, show the RST feature in sysfs. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 8c5efa5813b3..8675bb6ddd67 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -296,6 +296,8 @@ BTRFS_FEAT_ATTR_INCOMPAT(zoned, ZONED); #ifdef CONFIG_BTRFS_DEBUG /* Remove once support for extent tree v2 is feature complete */ BTRFS_FEAT_ATTR_INCOMPAT(extent_tree_v2, EXTENT_TREE_V2); +/* Remove once support for raid stripe tree is feature complete */ +BTRFS_FEAT_ATTR_INCOMPAT(raid_stripe_tree, RAID_STRIPE_TREE); #endif #ifdef CONFIG_FS_VERITY BTRFS_FEAT_ATTR_COMPAT_RO(verity, VERITY); @@ -326,6 +328,7 @@ static struct attribute *btrfs_supported_feature_attrs[] = { #endif #ifdef CONFIG_BTRFS_DEBUG BTRFS_FEAT_ATTR_PTR(extent_tree_v2), + BTRFS_FEAT_ATTR_PTR(raid_stripe_tree), #endif #ifdef CONFIG_FS_VERITY BTRFS_FEAT_ATTR_PTR(verity), From patchwork Wed Feb 15 14:33:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141748 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 2C793C636D7 for ; Wed, 15 Feb 2023 14:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjBOOeS (ORCPT ); Wed, 15 Feb 2023 09:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229724AbjBOOeJ (ORCPT ); Wed, 15 Feb 2023 09:34:09 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD970392A8 for ; Wed, 15 Feb 2023 06:34:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471647; x=1708007647; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=48mzuJkCCBR9M4lhSSUdkDKYB5vx32qICyN3uBfqRf0=; b=LVOjkkzxJAEx8nEcCewl+7aGFftdAn6vDS4KsFuwE2W+dM9bxbGVaSvj iEaqtBHu5K5BDJWCzYDr4WfVa4eHUVHh894q7mmI3fd1P6kozXK4Eq3db qvWOgL5Amej3FXKu0U2WjGQt0rRREkTofP5AzCApINS+AbAMNYceLsRXn XF7a94glldFkLiHbtdaUy6n8AhVFDiTX7mPdQ4wkPc9TOe4/XFJ6ypzIN Rye7LnwA1UswTD1K59QhQzl7OAmZlTZzugYNMqcOaF0bXZKLmhkVSIYWx Xh3eGGXbfkrl3mejRrmxdvrm9ERO/fqF0qkHoCOCfh7E+RTNl4GgPP5jH Q==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394078" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:49 +0800 IronPort-SDR: O55iF9tfXuXttAuyA4R6xH+jvyaPuhbVN/KP47gfXLmr553rdqWatbOZuUB/wRgYzbA7OyXpp4 wCfygMBPOAGBMWD15zFkbTzHxoSCE8u5FXmpsT8XsKCXIMNRRiYDNuSeEr9+MRXNQguLxne7vE S4S8taAVEJhkk/yFmv65BAbDZZynOqGt8yvQq36bwdoJ3uVXYuYYrctDQfdENl9ijpplxWf67L l0oOIDDp52BBvyK4wWsMAzRIi+/ugpj/N+8H8ZaAGgoCzftxyDCl+VzNh3L/MBpOJdGSuQlMxU 1no= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:11 -0800 IronPort-SDR: pX3cthX8QpMDKgJ/ADxx6weDjj5SMUTssH+2mGE96RDVrtapmmoUP9AlifBV0ILqsu/Hj9ohaf qeqs+MFAuhfnAErMM3uqPBCq9SRPvJls5w38Bz3EpmMqNWcKBp3CTDhiT0Xfl7Dm4GK3enOwrO 0Lz3HL9y+uI4kjuXSrKCOn4G6jBIdxg8e2RBitrFs+MJ5LpfNPbdPqeH4rr/G3UlpTFyvEf3hH MgbGybK9iypdbkOzQYF/+m3fSxV5A4fWNnUAWTRpjzwwCeB/GaX2xh1yVqEha6L6JhYHwOfT9s l1o= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:49 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 12/13] btrfs: consult raid-stripe-tree when scrubbing Date: Wed, 15 Feb 2023 06:33:33 -0800 Message-Id: <2f2e8602e56431fe0032c0f234ac3ab77ece2c86.1676470614.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When scrubbing a filesystem which uses the raid-stripe-tree for logical to physical address translation, consult the RST to perform the address translation instead of relying on fixed block group offsets. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/scrub.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 69c93ae333f6..0fe529c3f5bc 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -24,6 +24,7 @@ #include "accessors.h" #include "file-item.h" #include "scrub.h" +#include "raid-stripe-tree.h" /* * This is only the first step towards a full-features scrub. It reads all @@ -2719,6 +2720,21 @@ static int scrub_extent(struct scrub_ctx *sctx, struct map_lookup *map, int ret; u8 csum[BTRFS_CSUM_SIZE]; u32 blocksize; + struct btrfs_io_stripe stripe; + const bool stripe_update = + btrfs_need_stripe_tree_update(sctx->fs_info, map->type); + + if (stripe_update) { + stripe.dev = src_dev; + ret = btrfs_get_raid_extent_offset(sctx->fs_info, logical, + (u64 *)&len, + map->type, mirror_num, + &stripe); + if (ret) + return ret; + + src_physical = stripe.physical; + } if (flags & BTRFS_EXTENT_FLAG_DATA) { if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) @@ -2772,8 +2788,21 @@ static int scrub_extent(struct scrub_ctx *sctx, struct map_lookup *map, return ret; len -= l; logical += l; - physical += l; - src_physical += l; + if (stripe_update && len) { + + ret = btrfs_get_raid_extent_offset(sctx->fs_info, + logical, (u64 *)&len, + map->type, mirror_num, + &stripe); + if (ret) + return ret; + + src_physical = stripe.physical; + physical = stripe.physical; + } else { + physical += l; + src_physical += l; + } } return 0; } From patchwork Wed Feb 15 14:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13141746 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 90305C636D4 for ; Wed, 15 Feb 2023 14:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbjBOOeO (ORCPT ); Wed, 15 Feb 2023 09:34:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBOOeI (ORCPT ); Wed, 15 Feb 2023 09:34:08 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11F3F392AF for ; Wed, 15 Feb 2023 06:34:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1676471647; x=1708007647; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/oYWgvLRe6h3xVTHAWcQzQ9KLDOuCczBrh6j4HxEJ7o=; b=Wf11cIr8oVgpVI7AZRNHXRiBtQVBnNenk3r9tW7MRhdSk6KgYhBb9tc9 l/OVVatYoy0FbNrevYjAfVxILef9BsYvLNrxijKB17ydgonva0ltcMR7m QpWWYsk7O0VlldtGFwxaXqadqsurcx3H2CStMZqeT0p9TWF4rUrDYV6+t AjIY3k0uNxWLeRYMbfSzjHU4KMBCvIJ6NmUzMxK8p0WlCNayzsIvkcMvt HXBJOaBUmARqQgU9gvkiAflQxcemtksN81fBVDPEj+aBoLyvYItKpG/Fk gtsHvNsyvSQNq8W7Hb4v0JNNoWLJFy7lvufVfgakSrgVr7oSPrHa2RcsJ w==; X-IronPort-AV: E=Sophos;i="5.97,299,1669046400"; d="scan'208";a="223394079" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2023 22:33:50 +0800 IronPort-SDR: VB1M/d3r/5Muaor1CJdseIu7/o9a8Bmgy67Pm+jB6YkzVtjmzFzCaD0yYyWd7HvnjnaBl7gL6r okwq0dV0W0T3Ng6i4HcuhKVZ2KTFk76tTeQ3zAqbITKykezJIkHNzdts4+KPRa1yPz4p014EoF i3EutVJvYjzYUuWVxbDkQHvE910MAROF1UXw5Ayrdb2SGweBKtN4XAyes6zzLDhTELAIghM2Q8 OxBlFVbMwt53srXAPfTihkuFiJQm32AWSoMDmp/zdem4zLN6Ce1BQ9k0QzwwauJMdD7SYVtzak mVs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 15 Feb 2023 05:45:11 -0800 IronPort-SDR: iLX7NFfIoE2/a3o57p+FVXhGd+FgY0/KpjAlBtVsBYraWJVIkCRQ6st5RtCjv8is49V1Rq6GwU N0gJ+9LQVy3FryOmeNCsPmqnaRK00g/SSVv3E0OHP1h0fqxxBhmA1op2J/1Y+oGXw3RWID6fx6 Ig4syq7Aozs6VvtS1766rvkc5b36FVuhBIbwDg0rSQwxheYMiHK5XPdIN+UcUZw7ENoyxlaok6 AP+eyTbfuydvUcnobuE4RLBYYpGTkoI+eI3VSrO0QAoMjnzWUMNaKESF2vVEPJAt3kE8kOYpL0 juk= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip01.wdc.com with ESMTP; 15 Feb 2023 06:33:50 -0800 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn , Josef Bacik Subject: [PATCH v6 13/13] btrfs: add raid-stripe-tree to features enabled with debug Date: Wed, 15 Feb 2023 06:33:34 -0800 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Until the RAID stripe tree code is well enough tested and feature complete, "hide" it behind CONFIG_BTRFS_DEBUG so only people who want to use it are actually using it. Reviewed-by: Josef Bacik Signed-off-by: Johannes Thumshirn --- fs/btrfs/fs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index d0d80540b32b..dd151538d2b1 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -214,7 +214,8 @@ enum { BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ BTRFS_FEATURE_INCOMPAT_RAID1C34 | \ BTRFS_FEATURE_INCOMPAT_ZONED | \ - BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) + BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 | \ + BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE) #else #define BTRFS_FEATURE_INCOMPAT_SUPP \ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \