From patchwork Mon May 16 14:31:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850918 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 00C5AC433FE for ; Mon, 16 May 2022 14:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244563AbiEPOby (ORCPT ); Mon, 16 May 2022 10:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244456AbiEPObu (ORCPT ); Mon, 16 May 2022 10:31:50 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E04C527B02 for ; Mon, 16 May 2022 07:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711508; x=1684247508; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jFTV7i7Hh3OaUG5j4fuJXk1l0TFnopVwjp9A7WCDbMM=; b=Z9KR8i6OUuVYFHUG6MKxbGRGy7gqXaqWgTE5KmUoKgDsc0LcGokNzOlT 9ik8NdNSswZR9PfiwbqsH+rLRH7WBHWww+KBogfsqkEvx8CLX4f088Jvs 9anOIiDc/48KnV3jXB/mGFcghO3ma5prnMk6aaDoCBXlc40I/OKrIRyNP CMBeFtxKUNoN4Ml8ovSuaFr293Kps+3qSonxDqgCw2Vasec/CSgeoJXKq esIn6VLnMEC5debfdl2zDpW6uXq4XwKNAHljvowkk3qgcTR1JqbBiq5qu 26dVIsGiFgJgSeKcqyPiEeWPlAYmwCEBM9aTrBeR2+M21y11qUmugRYjy Q==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309209" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:47 +0800 IronPort-SDR: MNqj4YmeN8kTBl5PL2M22/AHgawnsfsFaA+S/ELK6Q6xEWy+R62UiSjDwgy9NJPN/RS1QHIlFA B1WprAv0ezF61F/uVKxHeWzuObDiO8brz6y3fc9ENyURQCmz+7xAU7cvQ1yQx24tvADRL9JysZ nj4Srnx/ffMBuKW+1MUZYHCmsXly2Daw8XZYrZuiOhwUO6bqZvRZbH+Hoet1XUk2wMShVe7b/G 8uulSvd3CwQ7GLuqJzX5STz00B/mVXbp0ZdnA7Z+dxg+fqE5p7mXizMDjJzUUwlra1lDzBG/31 VpQBOg6x7fjJD58UgWWV1alQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:29 -0700 IronPort-SDR: cJiXOciLLqW8t1ixOqTPTBoSRdmMsIHD7eeOGLdc421TMKDFE9gIoqfGoQHsfffpp/0opRKMv9 2se6isOQ1niKELK+FCJ0jWFdZgiB17RopIJEel5MwrlGYm+RNXVYqM9bQSdYyohiHeEdQPFKka F5FMLn73taeVMSz/pvYJb5FSjTqZOwM7GC3jTw8TtKOl6fiB+09jr3nlftJHpYTlvr54VfQ6fp pyGA3xsUIexVXxjrwGxIVPvPu+QlPqf8X+gDmhBhBrgDwU4wjEsS3RDpGiUlY/GBiov2kx1ZRY T9c= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:47 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 1/8] btrfs: add raid stripe tree definitions Date: Mon, 16 May 2022 07:31:36 -0700 Message-Id: <06a217ce02243fe88b9649d689df89eea7a570c7.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add definitions for the raid-stripe-tree. This tree will hold informatioin about the on-disk layout of the stripes in a RAID set. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.h | 28 ++++++++++++++++++++++++++++ include/uapi/linux/btrfs_tree.h | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 7328fb17b7f5..20aa2ebac7cd 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1878,6 +1878,34 @@ BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32); BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64); BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32); +BTRFS_SETGET_FUNCS(stripe_extent_devid, struct btrfs_stripe_extent, devid, 64); +BTRFS_SETGET_FUNCS(stripe_extent_offset, struct btrfs_stripe_extent, offset, 64); +BTRFS_SETGET_STACK_FUNCS(stack_stripe_extent_devid, struct btrfs_stripe_extent, devid, 64); +BTRFS_SETGET_STACK_FUNCS(stack_stripe_extent_offset, struct btrfs_stripe_extent, offset, 64); + +static inline struct btrfs_stripe_extent *btrfs_stripe_extent_nr( + struct btrfs_dp_stripe *dps, int nr) +{ + unsigned long offset = (unsigned long)dps; + offset += offsetof(struct btrfs_dp_stripe, extents); + offset += nr * sizeof(struct btrfs_stripe_extent); + return (struct btrfs_stripe_extent *)offset; +} + +static inline u64 btrfs_stripe_extent_devid_nr(const struct extent_buffer *eb, + struct btrfs_dp_stripe *dps, + int nr) +{ + return btrfs_stripe_extent_devid(eb, btrfs_stripe_extent_nr(dps, nr)); +} + +static inline u64 btrfs_stripe_extent_offset_nr(const struct extent_buffer *eb, + struct btrfs_dp_stripe *dps, + int nr) +{ + return btrfs_stripe_extent_offset(eb, btrfs_stripe_extent_nr(dps, nr)); +} + /* struct btrfs_dev_extent */ BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent, chunk_tree, 64); diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index b069752a8ecf..a2d28d83cc96 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -56,6 +56,9 @@ /* Holds the block group items for extent tree v2. */ #define BTRFS_BLOCK_GROUP_TREE_OBJECTID 11ULL +/* tracks RAID stripes in block groups. */ +#define BTRFS_RAID_STRIPE_TREE_OBJECTID 12ULL + /* device stats in the device tree */ #define BTRFS_DEV_STATS_OBJECTID 0ULL @@ -264,6 +267,8 @@ */ #define BTRFS_QGROUP_RELATION_KEY 246 +#define BTRFS_RAID_STRIPE_KEY 247 + /* * Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */ @@ -488,6 +493,18 @@ struct btrfs_free_space_header { __le64 num_bitmaps; } __attribute__ ((__packed__)); +struct btrfs_stripe_extent { + /* btrfs device-id this raid extent lives on */ + __le64 devid; + /* offset from the devextent start */ + __le64 offset; +} __attribute__ ((__packed__)); + +struct btrfs_dp_stripe { + /* array of stripe extents this stripe is comprised of */ + struct btrfs_stripe_extent extents; +} __attribute__ ((__packed__)); + #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0) #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) From patchwork Mon May 16 14:31:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850917 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 108BBC433F5 for ; Mon, 16 May 2022 14:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244473AbiEPObw (ORCPT ); Mon, 16 May 2022 10:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244468AbiEPObv (ORCPT ); Mon, 16 May 2022 10:31:51 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773501D30A for ; Mon, 16 May 2022 07:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711509; x=1684247509; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N7IaAZK2OhkBxOuVYjm43d/ypc+u7QsecE/jcO5Z1Sk=; b=XklpjfSqskxks95FeQOVsDXVP+RgDcFDf8N4A03Os7hqabhOdhdqBL3M jCtcgGYZP3Gks3v4wJ4zKWPOrQhguO7aIfzZUXKVXEzleJa52/EfogPUK 0h8nkUzgUuEki1KDs0S1QuCkiuAt+LJAygx15e2loGJzcFPHxV3FaIwpH SYzWL2vFgWlU9jd/GffYJJSLpgoifJDv9MDYWXaEJNTE3mv34BrUU5Np3 CnLdToxxH5eWH/BQ9eSuI8RjiUBtygkQr6T6XjbzOk21bJmuKBsz/KgN8 wln3g8MWOEBRZDQ+d7qL6dgo+PYkGI57hN5WoKNCnVinhFSibRuKU2Gib g==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309210" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:48 +0800 IronPort-SDR: G/QEK9wRtNVmij3XDdN/Y05g9Lbfi7Ckl64LL5MUtuyJx0o4uB9AFVOwmGn+G1g6qYr9qZKhKP alCVIO4gf87axStmK3/imUSpuVdOj/D4B8R7HSrXOmQ1X5W0DriZ4Z8+M5HI/BzIGo2/Z7TZ9n 3mF4MoOlP4jA8ycW3wpL9Mz7r2b6mM1D8yCoAnVjHRVPe+3KRDoffzqnSoUdW/mbFVoNHLPYrG lyDo0O46emw1tVW4wPy4ne/dc85EeVU2m/epn6PO11gsPnDqaa1cqjt87E5dMhJfG2RtZPMeWi 7OdO4vFQ5AE95PwZjfNKel28 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:29 -0700 IronPort-SDR: RmnJrJcV3CGzcAKEF/7zQIPWWa4O+mmmyEg6N5/Z2ORD8wkF12zypz4JzMJZ1X5+C5At7ohU3L b+mtRsVNzZpEQH67nekGnU/M3D/1jodqHm7oiM3q69UuaZWkZo36D5b7ec4CzUlbaMG5BO+8Ay tScUZL00et9sFEj+SKbBSxr9N8FBtrsRpmiZWkgCtWsHGYLZRdWw+QAzEb9d36PZ7RM8OW7awh lOC5Ftf7belCZtcb7vGJZBseGt39D4r4pMpnk3aA64l2EMlQpWtmHk+bDZhMeVPsdLszYeXeaL jZo= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:48 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 2/8] btrfs: move btrfs_io_context to volumes.h Date: Mon, 16 May 2022 07:31:37 -0700 Message-Id: <6bd71ff55e48686fc917736e686143ca7d5d2c64.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In preparation for upcoming changes, move 'struct btrfs_io_context' to volumes.h, so we can use it outside of volumes.c Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.h | 90 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index bd297f23d19e..894d289a3b50 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -32,6 +32,51 @@ struct btrfs_io_geometry { u64 raid56_stripe_offset; }; +struct btrfs_io_stripe { + struct btrfs_device *dev; + u64 physical; + u64 length; /* only used for discard mappings */ +}; + +/* + * Context for IO subsmission for device stripe. + * + * - Track the unfinished mirrors for mirror based profiles + * Mirror based profiles are SINGLE/DUP/RAID1/RAID10. + * + * - Contain the logical -> physical mapping info + * Used by submit_stripe_bio() for mapping logical bio + * into physical device address. + * + * - Contain device replace info + * Used by handle_ops_on_dev_replace() to copy logical bios + * into the new device. + * + * - Contain RAID56 full stripe logical bytenrs + */ +struct btrfs_io_context { + refcount_t refs; + atomic_t stripes_pending; + struct btrfs_fs_info *fs_info; + u64 map_type; /* get from map_lookup->type */ + bio_end_io_t *end_io; + struct bio *orig_bio; + void *private; + atomic_t error; + int max_errors; + int num_stripes; + int mirror_num; + int num_tgtdevs; + int *tgtdev_map; + /* + * logical block numbers for the start of each stripe + * The last one or two are p/q. These are sorted, + * so raid_map[0] is the start of our full stripe + */ + u64 *raid_map; + struct btrfs_io_stripe stripes[]; +}; + /* * Use sequence counter to get consistent device stat data on * 32-bit processors. @@ -354,51 +399,6 @@ static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio) } } -struct btrfs_io_stripe { - struct btrfs_device *dev; - u64 physical; - u64 length; /* only used for discard mappings */ -}; - -/* - * Context for IO subsmission for device stripe. - * - * - Track the unfinished mirrors for mirror based profiles - * Mirror based profiles are SINGLE/DUP/RAID1/RAID10. - * - * - Contain the logical -> physical mapping info - * Used by submit_stripe_bio() for mapping logical bio - * into physical device address. - * - * - Contain device replace info - * Used by handle_ops_on_dev_replace() to copy logical bios - * into the new device. - * - * - Contain RAID56 full stripe logical bytenrs - */ -struct btrfs_io_context { - refcount_t refs; - atomic_t stripes_pending; - struct btrfs_fs_info *fs_info; - u64 map_type; /* get from map_lookup->type */ - bio_end_io_t *end_io; - struct bio *orig_bio; - void *private; - atomic_t error; - int max_errors; - int num_stripes; - int mirror_num; - int num_tgtdevs; - int *tgtdev_map; - /* - * logical block numbers for the start of each stripe - * The last one or two are p/q. These are sorted, - * so raid_map[0] is the start of our full stripe - */ - u64 *raid_map; - struct btrfs_io_stripe stripes[]; -}; - struct btrfs_device_info { struct btrfs_device *dev; u64 dev_offset; From patchwork Mon May 16 14:31:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850920 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 D740CC433FE for ; Mon, 16 May 2022 14:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244358AbiEPOb5 (ORCPT ); Mon, 16 May 2022 10:31:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244499AbiEPObw (ORCPT ); Mon, 16 May 2022 10:31:52 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A712AF8 for ; Mon, 16 May 2022 07:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711510; x=1684247510; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ml4kXQTQWKd1I/2t4c1y5qyeT8AIR/c/+43rAipGW3A=; b=DrTsRr3yOSyYRD5VHT8YwdgWNNm3tNu45bVgRiuOpa/S8eX7R7ZnEPi/ YxpcdFLsYtA1/w45yDFWzA5r4yjKBDIlhuRCcNqGucBsFvXdPaQZAyjTL BhEJWwqiPGy3TbI2LhzUN9X9HF7zQfQ8XEkUYoaa3gzd7mqhT6CKRfOAP YTWKZEpjzn+uDi5+4lllXWurtgsUIM9anyLVNb07aFjlBPGqSndAmhhJg zlLijX5DS4oqVYDfBuHK4yOkbmywEvwCFFLeyIn0JCT7BamvW6ckqWr/A uVEkdWRJO2NqueDzi5sCax9DJpVt66dBvanDkyrMnBEfwE0lP7sQKuX3X g==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309212" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:48 +0800 IronPort-SDR: jzSfuTLw/TNWGN0n7YP2qqUUXk7alaxjgPDqkN9XBQfNqwp3MOMDYs4ygOAc64dSa2jYh9Q2xy I7WwQGW73XuzEiIf/ZsTTG92Nwt/ZfvtDpDxEEde2ZgBfSsdD4kWbKJg8rO1NkMOFuMATi0Fnf 1u/IXJXpo/TZ2P0Ku/KCx4FdH/Ia5pezxBEKR8DuECMb7kO7EgCZTyC/28cu6wesf47l16lJrD XvOEljrVOJAOetngPdhskgrqVlkrYDSM1jSlZKxM3blu9/ymLOM8BwIhdvNg1zR4oEvaZ/UyFR xyO7CegeALOGgoP/qotZPXi6 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:30 -0700 IronPort-SDR: gfDM21BsmFqueSCLY8vmNnSq41HmsviZLfYh5MGzpo947kbg7fkl2HV7+el3eXsa9i/BZdG6CF rIRHWPrf7m9OwUnm2LOBwHWASOhuNCxeiO9w9fzTpktvuemdTgu/zShWzLUZi286rEx+guFZQf gA1Y0ysly3Lv+Q7jUaJXs5PacnEkSpo9XZ8i4jxEEvtJr3R+ssYVsZOmn88a/9oYNBnP6wkoNr dhyDp8DUirAt7ASa3PkpO7Rf2lyoDF6ix/tCrWf7REmTLFQeUYjU8se01u0jHk7yEh5fl8sFQ9 9M0= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:48 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 3/8] btrfs: read raid-stripe-tree from disk Date: Mon, 16 May 2022 07:31:38 -0700 Message-Id: <2ccf8b77759a80a09d083446d5adb3d03947394b.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If we're discovering a raid-stripe-tree on mount, read it from disk. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 12 ++++++++++++ include/uapi/linux/btrfs.h | 1 + 3 files changed, 14 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 20aa2ebac7cd..1db669662f61 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -667,6 +667,7 @@ struct btrfs_fs_info { struct btrfs_root *uuid_root; struct btrfs_root *data_reloc_root; struct btrfs_root *block_group_root; + struct btrfs_root *stripe_root; /* the log root tree is a directory of all the other log roots */ struct btrfs_root *log_root_tree; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d456f426924c..c0f08917465a 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1706,6 +1706,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; } @@ -1784,6 +1787,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); @@ -2337,6 +2341,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); } @@ -2773,6 +2778,13 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) fs_info->uuid_root = root; } + location.objectid = BTRFS_RAID_STRIPE_TREE_OBJECTID; + root = btrfs_read_tree_root(tree_root, &location); + if (!IS_ERR(root)) { + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); + fs_info->stripe_root = root; + } + return 0; out: btrfs_warn(fs_info, "failed to read root (objectid=%llu): %d", diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index d956b2993970..4e0429fc4e87 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -310,6 +310,7 @@ struct btrfs_ioctl_fs_info_args { #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) +#define BTRFS_FEATURE_INCOMPAT_STRIPE_TREE (1ULL << 14) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Mon May 16 14:31:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850919 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 B1030C433F5 for ; Mon, 16 May 2022 14:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244571AbiEPObz (ORCPT ); Mon, 16 May 2022 10:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244524AbiEPObw (ORCPT ); Mon, 16 May 2022 10:31:52 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B1A27CD0 for ; Mon, 16 May 2022 07:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711510; x=1684247510; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CelhjqNeNdGGkBBYNLfa/DwOWgeZ/5gIhqceleUjmXI=; b=ls6ZiqLPabvt0e0gxIFdGD5qs7hN34JGzsxVEL1lPcl0cuOK/Cf/xYf9 Vt1w/HbycsjcBp8gL2zhyUtBn1vDv3OcTbKheQHVezs/KMf5P59kd5f/T mODRJxXRoIxyMaV5pHHQE/kykwW4tRfE+pZKMFbTRg6Iay7Gyl7z49dfC PqRJNORGFuL7lfhdw0JNKee1ACWmc0DdF2zJFdUMktBKg2MrJcoIN2pIZ gkjDh4KGWaySGWi/s/uZVfH5Oi6MzueToFxu/j65IDMNmmANIJj+4fhsW A7Q9vsdeiwBTMIaOY2WMGo3pzRC8464RYSsnuvp42LLqg1mJtZBPBlVhb w==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309213" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:49 +0800 IronPort-SDR: c2gofTRjvOdZL0gxrpCWNAQ8rvAQNWokoKZV0unGy36IWGkvtxDUlymF/pv4MprkxN4x6pbXVG t5gnhKWyE0Ws6+WchRPAI4sG4T3cn7FlEY4hMEJMsI+vxQAdxpVvpHFFvsS9JzF4B8rBxynOaL QZjL0eE6NZT4SVcSzzFiuffCDxIFXSUTouJHeNXxQ/k78oixHlBfz/RANiwcJ+a5eGI5tup/8h Egu5VOHL5btuadcyaiPW110HnmkGoJfkhozsrXqmc6cDjTbnCtIqASqmTzsLrKkAZhShLWB1s5 lOgoXyI4rzteTBRVe2LcURSo Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:31 -0700 IronPort-SDR: Qc2tpbrlHqb7t8qDBgglS5L5D6eBFNOPn2YNEcODHVqycLInt15LVj6EMcAc2k1/yN2V1AMBir K8e5zE4sIbo7YCezA6ac2JapZi6T720tQ0dw0punLwjJTmqsb7x/P82ulm+5JMgywvMIUAB1Tu toIMZ8uQJngdn+Xo/Io8v0HvOiLkDiKHPe0BKpcOPo6OU8jr50tXoKKKw9YtGBWSm96n9KZeqJ M2SW5w0kUXq3q0iGXYGgDJtNqCOWPiEQwgvIDhNpzDjQmlXGAPNvRGtCToPzuhoZiMyr8E8uNq z7Y= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:49 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 4/8] btrfs: add boilerplate code to insert raid extent Date: Mon, 16 May 2022 07:31:39 -0700 Message-Id: <35ea1d22a55d8dd30bc9f9dfcd4a48890bf7feaf.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to insert raid extents into the raid-stripe-tree on each write to a RAID1 block-group. Signed-off-by: Johannes Thumshirn --- fs/btrfs/Makefile | 2 +- fs/btrfs/raid-stripe-tree.c | 72 +++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 28 +++++++++++++++ fs/btrfs/volumes.c | 21 +++++++++++ fs/btrfs/volumes.h | 3 ++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/raid-stripe-tree.c create mode 100644 fs/btrfs/raid-stripe-tree.h diff --git a/fs/btrfs/Makefile b/fs/btrfs/Makefile index 4188ba3fd8c3..6b9a00ad532a 100644 --- a/fs/btrfs/Makefile +++ b/fs/btrfs/Makefile @@ -30,7 +30,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \ uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \ block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \ - subpage.o tree-mod-log.o + subpage.o tree-mod-log.o raid-stripe-tree.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c new file mode 100644 index 000000000000..426066bd7c0d --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "ctree.h" +#include "transaction.h" +#include "disk-io.h" +#include "raid-stripe-tree.h" +#include "volumes.h" + +static void btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, + struct btrfs_io_context *bioc) +{ + struct btrfs_fs_info *fs_info = bioc->fs_info; + struct btrfs_key stripe_key; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_dp_stripe *raid_stripe; + struct btrfs_stripe_extent *stripe_extent; + size_t item_size; + int ret; + int i; + + item_size = sizeof(struct btrfs_dp_stripe) - sizeof(struct btrfs_stripe_extent) + + bioc->num_stripes * sizeof(struct btrfs_stripe_extent); + + raid_stripe = kzalloc(item_size, GFP_NOFS); + if (!raid_stripe) { + btrfs_abort_transaction(trans, -ENOMEM); + return; + } + + stripe_extent = &raid_stripe->extents; + for (i = 0; i < bioc->num_stripes; i++) { + u64 devid = bioc->stripes[i].dev->devid; + u64 physical = bioc->stripes[i].physical; + + btrfs_set_stack_stripe_extent_devid(stripe_extent, devid); + btrfs_set_stack_stripe_extent_offset(stripe_extent, physical); + stripe_extent++; + } + + stripe_key.objectid = bioc->logical; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = bioc->length; + + ret = btrfs_insert_item(trans, stripe_root, &stripe_key, raid_stripe, + item_size); + if (ret) { + kfree(raid_stripe); + btrfs_abort_transaction(trans, ret); + return; + } + + kfree(raid_stripe); +} + +void btrfs_raid_stripe_tree_fn(struct work_struct *work) +{ + struct btrfs_io_context *bioc; + struct btrfs_fs_info *fs_info; + struct btrfs_root *root; + struct btrfs_trans_handle *trans = NULL; + + bioc = container_of(work, struct btrfs_io_context, stripe_update_work); + fs_info = bioc->fs_info; + root = fs_info->stripe_root; + + trans = btrfs_join_transaction(root); + + btrfs_insert_raid_extent(trans, bioc); + btrfs_end_transaction(trans); + + btrfs_put_bioc(bioc); +} diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h new file mode 100644 index 000000000000..320a110ecc66 --- /dev/null +++ b/fs/btrfs/raid-stripe-tree.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_RAID_STRIPE_TREE_H +#define BTRFS_RAID_STRIPE_TREE_H + +#include "volumes.h" + +void btrfs_raid_stripe_tree_fn(struct work_struct *work); + +static inline bool btrfs_need_stripe_tree_update(struct btrfs_io_context *bioc) +{ + u64 type = bioc->map_type & BTRFS_BLOCK_GROUP_TYPE_MASK; + u64 profile = bioc->map_type & BTRFS_BLOCK_GROUP_PROFILE_MASK; + + if (!bioc->fs_info->stripe_root) + return false; + + // for now + if (type != BTRFS_BLOCK_GROUP_DATA) + return false; + + if (profile & BTRFS_BLOCK_GROUP_RAID1_MASK) + return true; + + return false; +} + +#endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3fd17e87815a..36acef2ae5d8 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -33,6 +33,7 @@ #include "block-group.h" #include "discard.h" #include "zoned.h" +#include "raid-stripe-tree.h" #define BTRFS_BLOCK_GROUP_STRIPE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \ BTRFS_BLOCK_GROUP_RAID10 | \ @@ -5917,6 +5918,7 @@ static struct btrfs_io_context *alloc_btrfs_io_context(struct btrfs_fs_info *fs_ bioc->fs_info = fs_info; bioc->tgtdev_map = (int *)(bioc->stripes + total_stripes); bioc->raid_map = (u64 *)(bioc->tgtdev_map + real_stripes); + INIT_WORK(&bioc->stripe_update_work, btrfs_raid_stripe_tree_fn); return bioc; } @@ -6677,6 +6679,17 @@ static void btrfs_end_bio(struct bio *bio) } } + if (bio_op(bio) == REQ_OP_ZONE_APPEND) { + int i; + + for (i = 0; i < bioc->num_stripes; i++) { + if (bioc->stripes[i].dev->bdev != bio->bi_bdev) + continue; + bioc->stripes[i].physical = bio->bi_iter.bi_sector << SECTOR_SHIFT; + } + } + + if (bio == bioc->orig_bio) is_orig_bio = 1; @@ -6700,6 +6713,12 @@ static void btrfs_end_bio(struct bio *bio) * go over the max number of errors */ bio->bi_status = BLK_STS_OK; + + if (btrfs_op(bio) == BTRFS_MAP_WRITE && + btrfs_need_stripe_tree_update(bioc)) { + btrfs_get_bioc(bioc); + schedule_work(&bioc->stripe_update_work); + } } btrfs_end_bioc(bioc, bio); @@ -6788,6 +6807,8 @@ blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, bioc->orig_bio = first_bio; bioc->private = first_bio->bi_private; bioc->end_io = first_bio->bi_end_io; + bioc->logical = logical; + bioc->length = length; atomic_set(&bioc->stripes_pending, bioc->num_stripes); if ((bioc->map_type & BTRFS_BLOCK_GROUP_RAID56_MASK) && diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 894d289a3b50..4b4235b4432a 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -68,6 +68,9 @@ struct btrfs_io_context { int mirror_num; int num_tgtdevs; int *tgtdev_map; + u64 logical; + u64 length; + struct work_struct stripe_update_work; /* * logical block numbers for the start of each stripe * The last one or two are p/q. These are sorted, From patchwork Mon May 16 14:31:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850921 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 0FCD2C433F5 for ; Mon, 16 May 2022 14:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244568AbiEPOb6 (ORCPT ); Mon, 16 May 2022 10:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244527AbiEPObw (ORCPT ); Mon, 16 May 2022 10:31:52 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14F3126127 for ; Mon, 16 May 2022 07:31:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711510; x=1684247510; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YiY0Z3bgHLxnnf5g72kdJkcGbIgAF4jcYh/yhyMQGO8=; b=hq4Aa9PKcdpZitxBQY6KNd0+jn3hJtn1av1Zi8UlMkbz6Ga4ng2La0uu +D9JYvDfKX0+X2gEFgbb4JVdRaVyGGunBAyeRLHTbuSS+cpqSvXZzq7Rz inQ1D01z1awLWmB5TD/xrMsM5BtUWfRYSGNceCW7XWzDeXIzxfv6bbaKL S1flb4LkeaGjmjksghZL05JzJEROwdtOhWyeUX4+W6jn/H8oBqmAeo3FP hUzJPvpQMP7roejn9Li10MognsMekyWQk+ll5yBei092gR1+QiKZphPY0 ZdgXSBv66mbTO1sbyxF2UR8ufh3QihxqM3uub42dp4+3VGiRJqrQzRWt8 g==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309215" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:50 +0800 IronPort-SDR: EwDXZDwwurfVlBGpl3E52qoZ8kq2nohRIGgKTGHNKpSofj3p3GnOVFdM6vU5Gbm5ldvTp2vl4s Gladd+qnvAdidihuTK5f3GRED1ItJ1ZizUztOR96yY+QpH4gn8YOTnpFpLcHIFRh/nyl/eMO6H KWQVj5scmaczyMYDOPFFLhoe9qDOkmINbkC05pG+tf2z0QfLmI/u7qfi6zVn2jAfgcKZE9/Exx It/hPEOOmrjJY2BfjTEP+g+hE/jLi6J4N0Gm2OKBN2ZWPl/apQTfbhD288+mje+gZ5QQiwVjjn NTz8OnFI3dptDhTczzitnYLj Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:32 -0700 IronPort-SDR: uf+kuCyM54UTodEIsScfNhzPXHdbApwXu5QkSgSq3n2DGjJqWxJXjUAQZJiXPhx92Svn60161Q DNoK8shXUDvBL32bDy9yjovyADhX8Ibn71/cziaQS27BvEbu9iF6DqR/qXXGUJQqHl/FEnzhWy f973YjzqtcjbL2+dsf8TYHR9cHtBCl8YF4tWj7NxAA8hjrL3wyeKfq2cjixkTqXsebt1ctJDMY XNlDyQFPeF4Q9R5T7as+ljMtuJpFaOoAS4KvKr6JrywCHpzbOEF4GVZMqSDXhc7/8BLOR85gfp WwI= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:50 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 5/8] btrfs: add code to delete raid extent Date: Mon, 16 May 2022 07:31:40 -0700 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to delete entries from the raid-stripe-tree if the corresponding file extent got deleted. Signed-off-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 1 + fs/btrfs/extent-tree.c | 9 +++ fs/btrfs/file.c | 1 - fs/btrfs/raid-stripe-tree.c | 111 ++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 8 +++ 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 1e24695ede0a..b7b4e421e9b8 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -3623,6 +3623,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); BUG_ON(key.type != BTRFS_EXTENT_DATA_KEY && + key.type != BTRFS_RAID_STRIPE_KEY && key.type != BTRFS_EXTENT_CSUM_KEY); if (btrfs_leaf_free_space(leaf) >= ins_len) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f477035a2ac2..00af3e469881 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -36,6 +36,7 @@ #include "rcu-string.h" #include "zoned.h" #include "dev-replace.h" +#include "raid-stripe-tree.h" #undef SCRAMBLE_DELAYED_REFS @@ -3199,6 +3200,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/file.c b/fs/btrfs/file.c index bd329316945f..6021188dcb9a 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1009,7 +1009,6 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, btrfs_release_path(path); out: args->drop_end = found ? min(args->end, last_end) : args->end; - return ret; } diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 426066bd7c0d..370ea68fe343 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -6,6 +6,117 @@ #include "raid-stripe-tree.h" #include "volumes.h" +int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, + u64 length) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_path *path; + struct btrfs_key stripe_key; + struct btrfs_key found_key; + struct extent_buffer *leaf; + u64 end = start + length; + u64 found_start; + u64 found_end; + int slot; + int ret; + + if (!stripe_root) + return 0; + + stripe_key.objectid = start; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = end; + + 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; + if (ret == 0) + goto delete; + + leaf = path->nodes[0]; + slot = path->slots[0]; + btrfs_item_key_to_cpu(leaf, &found_key, slot); + found_start = found_key.objectid; + found_end = found_start + found_key.offset; + + /* + * | -- range to drop --| + * | ---------- extent ---------- | + */ +front_split: + if (start > found_start) { + struct btrfs_key front_key; + struct btrfs_dp_stripe *raid_stripe; + struct extent_buffer *front_leaf; + struct btrfs_stripe_extent *stripe_extent; + int num_stripes; + int i; + + front_key.objectid = found_start + length; + front_key.type = BTRFS_RAID_STRIPE_KEY; + front_key.offset = found_end - length; + + num_stripes = btrfs_num_raid_stripes(btrfs_item_size(leaf, slot)); + + ret = btrfs_duplicate_item(trans, stripe_root, path, &front_key); + if (ret == -EAGAIN) { + btrfs_release_path(path); + goto front_split; + } + if (ret < 0) + goto out; + front_leaf = path->nodes[0]; + + raid_stripe = btrfs_item_ptr(leaf, slot, struct btrfs_dp_stripe); + stripe_extent = &raid_stripe->extents; + for (i = 0; i < num_stripes; i++) { + u64 physical; + + physical = btrfs_stripe_extent_offset(leaf, stripe_extent); + btrfs_set_stripe_extent_offset(front_leaf, stripe_extent, + physical + length); + stripe_extent++; + } + + btrfs_mark_buffer_dirty(front_leaf); + } + + /* + * | -- range to drop --| + * | ---------- extent ---------- | + */ +tail_split: + if (end < found_end) { + struct btrfs_key tail_key; + + + tail_key.objectid = start; + tail_key.type = BTRFS_RAID_STRIPE_KEY; + tail_key.offset = found_end - end; + + ret = btrfs_duplicate_item(trans, stripe_root, path, &tail_key); + if (ret == -EAGAIN) { + btrfs_release_path(path); + goto tail_split; + } + if (ret < 0) + goto out; + btrfs_mark_buffer_dirty(path->nodes[0]); + } + +delete: + ret = btrfs_del_item(trans, stripe_root, path); +out: + btrfs_free_path(path); + return ret; + +} + static void btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 320a110ecc66..766634df8601 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -5,8 +5,16 @@ #include "volumes.h" +int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, + u64 length); void btrfs_raid_stripe_tree_fn(struct work_struct *work); +static inline int btrfs_num_raid_stripes(u32 item_size) +{ + return item_size - offsetof(struct btrfs_dp_stripe, extents) / + sizeof(struct btrfs_stripe_extent); +} + static inline bool btrfs_need_stripe_tree_update(struct btrfs_io_context *bioc) { u64 type = bioc->map_type & BTRFS_BLOCK_GROUP_TYPE_MASK; From patchwork Mon May 16 14:31:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850923 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 6C995C4332F for ; Mon, 16 May 2022 14:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244456AbiEPOcC (ORCPT ); Mon, 16 May 2022 10:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244540AbiEPObx (ORCPT ); Mon, 16 May 2022 10:31:53 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6D42612C for ; Mon, 16 May 2022 07:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711511; x=1684247511; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5bQ9dGl2bwCOdg8E2fT/giGQQuN9We3cgBr7X3BV+9g=; b=U77U87IsA1+7MKGuMW3CLhonY1/71KlRZkgC4P2+jv3zEp8H7eMPX9on wFeqUiOpZ9BfwGqCEqxMbkeyGYWrNiCUTYJ7PVNOZQqcYOCXrjZUAnIt5 Os2s9mcFyoYdzpanWb0nMklAIPlvmtfJBiHZ0mmtW2uP3inwD/M9VON1a oW3Gyy4Gfz05MzkqyeJ0+OrsX2vCc5Kvd1Pc6AHvTSCR7klNc4eYYSbG5 oqcx3ouWtXwflk1eNZJY1BfVJCvQyL/tGj/L9Ygq+Wi9OrmVzVnflUWe/ EAr0JoTyvm9tNCMVY3g15Pk9zxnGYoi77SptT+pNJeS5PnOQCNKMF5Xe3 w==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309216" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:51 +0800 IronPort-SDR: lSHn7rLScukiv+MoeJk++i+9lz0+NqzKc9/2SP4+DuzR9Vt3Eo6Bx0FKYRqZaYBfPNvFywPvTX R2tP5+OUblyu9YLwcOlX+dj4uk7nIyk0FvQ9r7kJxEQOePcarExaCR+FnEEsDz/Q9oR3axc1/t Z4XnHjDNgepDnrUYA4//gVOrxvdvA4UqLUMjoYWQz4DTt/GnSoiMaUN2xZI0xSsEm3GQRE9IOD 61luAI4qY+7EaVuWgHeBr0TMntYVCWdPYOGDlZ0cSUW5t6zuXVaCrl3A/6j7xQDgdvbcFGRQFY JOBbl5tNTrgWOGb0tK7GvwaQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:32 -0700 IronPort-SDR: XFJLJ9qZ4+0+N8EdrkFkPZUpqwVYMzwdV3F5Vrz+KlQfau6ETcjehGwkRR1VGHOCK3eFMGDkFK mOudVflpphwYldBxfxYcQXqPvOh6iXFzdg8qK34aNjsAl3HhtL5NyfoTFekQdgFhcGMbDRzlny BzL2kOAquoNg1be7Y7KCbl9ZcAlQdjjkryMQG7xXMKHx4lCx18XL/p2AsWnSEF42+gVHQ4NDMX xKx2Hph/HqXNOo3lMRXrILzT8H0Hua0+Qzc+rGcZgKdvOXoqytHcorcLk7EOhe3mhUH7I1EUQq yS8= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:51 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 6/8] btrfs: add code to read raid extent Date: Mon, 16 May 2022 07:31:41 -0700 Message-Id: <2aa8aae2f6394b774f480d877f2701fed6fd74c4.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add boilerplate code to lookup the physical address from the raid-stripe-tree when a read on an RAID volume formatted with the raid-stripe-tree was attempted. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 68 +++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 3 ++ fs/btrfs/volumes.c | 23 +++++++++++-- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 370ea68fe343..ecc8205be760 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -1,10 +1,78 @@ // SPDX-License-Identifier: GPL-2.0 +#include + #include "ctree.h" #include "transaction.h" #include "disk-io.h" #include "raid-stripe-tree.h" #include "volumes.h" +#include "misc.h" + +int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, + u64 logical, u64 length, u64 map_type, + u64 devid, u64 *physical) +{ + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_dp_stripe *raid_stripe; + struct btrfs_key stripe_key; + struct btrfs_key found_key; + struct btrfs_path *path; + struct extent_buffer *leaf; + u64 offset; + u64 found_logical, found_length; + int num_stripes; + int slot; + int ret; + int i; + + stripe_key.objectid = logical; + stripe_key.type = BTRFS_RAID_STRIPE_KEY; + stripe_key.offset = length; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + num_stripes = btrfs_bg_type_to_factor(map_type); + + ret = btrfs_search_slot_for_read(stripe_root, &stripe_key, path, 0, 0); + if (ret < 0) { + goto out; + } + + if (ret == 1) + ret = 0; + + while (1) { + leaf = path->nodes[0]; + slot = path->slots[0]; + + btrfs_item_key_to_cpu(leaf, &found_key, slot); + found_logical = found_key.objectid; + found_length = found_key.offset; + + if (!in_range(logical, found_logical, found_length)) + goto next; + offset = logical - found_logical; + + raid_stripe = btrfs_item_ptr(leaf, slot, struct btrfs_dp_stripe); + for (i = 0; i < num_stripes; i++) { + if (btrfs_stripe_extent_devid_nr(leaf, raid_stripe, i) != devid) + continue; + *physical = btrfs_stripe_extent_offset_nr(leaf, raid_stripe, i) + offset; + goto out; + } +next: + ret = btrfs_next_item(stripe_root, path); + if (ret) + break; + } +out: + btrfs_free_path(path); + + return ret; +} int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length) diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 766634df8601..1bfa6274eef8 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -5,6 +5,9 @@ #include "volumes.h" +int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, + u64 logical, u64 length, u64 map_type, + u64 devid, u64 *physical); int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 length); void btrfs_raid_stripe_tree_fn(struct work_struct *work); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 36acef2ae5d8..38329728425c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6559,11 +6559,29 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, ret = -ENOMEM; goto out; } + bioc->map_type = map->type; for (i = 0; i < num_stripes; i++) { - bioc->stripes[i].physical = map->stripes[stripe_index].physical + - stripe_offset + stripe_nr * map->stripe_len; + u64 physical; + bioc->stripes[i].dev = map->stripes[stripe_index].dev; + + if (fs_info->stripe_root && op == BTRFS_MAP_READ && + btrfs_need_stripe_tree_update(bioc)) { + ret = btrfs_get_raid_extent_offset(fs_info, logical, + map->stripe_len, + map->type, + bioc->stripes[i].dev->devid, + &physical); + if (ret) { + btrfs_put_bioc(bioc); + goto out; + } + } else { + physical = map->stripes[stripe_index].physical + + stripe_offset + stripe_nr * map->stripe_len; + } + bioc->stripes[i].physical = physical; stripe_index++; } @@ -6600,7 +6618,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, } *bioc_ret = bioc; - bioc->map_type = map->type; bioc->num_stripes = num_stripes; bioc->max_errors = max_errors; bioc->mirror_num = mirror_num; From patchwork Mon May 16 14:31:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850922 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 DB4BEC433EF for ; Mon, 16 May 2022 14:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244578AbiEPOcB (ORCPT ); Mon, 16 May 2022 10:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244550AbiEPObx (ORCPT ); Mon, 16 May 2022 10:31:53 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69C1527B02 for ; Mon, 16 May 2022 07:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711512; x=1684247512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xYsfZZk8FBwWUzYsUg1xtmfXBXttqN6OV0mvgf/mw1w=; b=TfMSCyV1eu5X+qXhVG3pXe4rI1mYMuECaPHirk34FPWfjRVJY9Td+sWK leNL1V3K9laSDGONEIjxPxIxfNx/A4+zW4bFHg6OS8ClPQG6wPn/Lb6uM g+ReLQxUFs5iRajMqTpqwQAHPEC+U0kpDcUL8VXty30/OG+Cv/OQ+QFrl f8NSZAvk0dExThsKybU1PAIHSHnQZldn0WTXZLvNw0POi8PeDQYSPuTce 01bp1hiQ/WfusRoFEWIKzbPfim3g2YSiIr0VxgoH4A+3QnUM3n60sPxr+ pIj753SS2256etVBT2ybtJMN+ZK9PWVUUbw14nLd8miAGMKiBphhPYdmM A==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309218" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:51 +0800 IronPort-SDR: gpjBlLpN8r2j0OaQcomdmOH0JAGS4Db4uTtlgdKIFv5yp6Jf4ZYQiNMlWRW9pHXVe4FKztGZAx /MB4+LlMVm5zhTevfUuFd9dPlsZoqAix0m7ms7S9aMdBmnA3jjQQQw4b2ooyxTF2LYOR79Hq9z E5hVy6OM4dMjGwsepdRt4XZN4C2EDT9MmLnbYFlR3Js4phcITKUumEgsf5RrHht+kE0Wup62k7 RFbqhT/AiX7owYjUivB1NiueGO/4jeXwyJLOC8lc8CFCfSINRPY3eNYRbVPU1KRcgRP7zaz5JI tw+0IE1euh96DIHMC4LMj/6D Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:33 -0700 IronPort-SDR: mn55gsO18ZOncTEF+vABpIIuhAF3ScOiN9z77yjCYnIPnMOoLa/5/UCnXh6T1KOCjgx0BTHRll HKBxSQDMo4pAkqXW4anlLuFVVQ4ewIjPgSVdR5sv1r+NocNzpsqMR4O7juoUGMF45RTtwCa2+H owgxKLiL2vj9rOP2Xt0oi8H3E+pG/iUCtiDAvkQWSXc2XrCdWceq5M6SSnZnTNb6EAv7WxYpIy S41bBmS/+P7b/6ij2ioNZbMiB/wpnsBnRKBd0EfTU811xUaxV73kXZe6f7l7nG+Qmv+L5dHAsd FAw= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:51 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 7/8] btrfs: zoned: allow zoned RAID1 Date: Mon, 16 May 2022 07:31:42 -0700 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When we have a raid-stripe-tree, we can do RAID1 on zoned devices for data block-groups. For meta-data block-groups, we don't actually need anything special, as all meta-data I/O is protected by the btrfs_zoned_meta_io_lock() already. Signed-off-by: Johannes Thumshirn --- fs/btrfs/zoned.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 1b1b310c3c51..d817a3349595 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1455,6 +1455,45 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new) cache->zone_capacity = min(caps[0], caps[1]); break; case BTRFS_BLOCK_GROUP_RAID1: + case BTRFS_BLOCK_GROUP_RAID1C3: + case BTRFS_BLOCK_GROUP_RAID1C4: + if (map->type & BTRFS_BLOCK_GROUP_DATA && + !fs_info->stripe_root) { + btrfs_err(fs_info, + "zoned: data RAID1 needs stripe_root"); + ret = -EIO; + goto out; + + } + + for (i = 0; i < map->num_stripes; i++) { + if (alloc_offsets[i] == WP_MISSING_DEV) { + btrfs_err(fs_info, + "zoned: cannot recover write pointer for zone %llu", + physical[0]); + ret = -EIO; + goto out; + } + if (i == 0) + continue; + + if (alloc_offsets[0] != alloc_offsets[i]) { + btrfs_err(fs_info, + "zoned: write pointer offset mismatch of zones in RAID profile"); + ret = -EIO; + goto out; + } + if (test_bit(0, active) != test_bit(i, active)) { + if (!btrfs_zone_activate(cache)) { + ret = -EIO; + goto out; + } + } + cache->zone_capacity = min(caps[0], caps[i]); + } + cache->zone_is_active = test_bit(0, active); + cache->alloc_offset = alloc_offsets[0]; + break; case BTRFS_BLOCK_GROUP_RAID0: case BTRFS_BLOCK_GROUP_RAID10: case BTRFS_BLOCK_GROUP_RAID5: From patchwork Mon May 16 14:31:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 12850924 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 8F2A1C433FE for ; Mon, 16 May 2022 14:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244540AbiEPOcE (ORCPT ); Mon, 16 May 2022 10:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244468AbiEPOby (ORCPT ); Mon, 16 May 2022 10:31:54 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3417826127 for ; Mon, 16 May 2022 07:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1652711512; x=1684247512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Su3JHLpizdjoIf6xF+rz+MdEM4xqxCp+FWNsJQq4uIk=; b=ovKry8EgXlPBwlLGLSw6WvL3JLQB+K3jc7LoEGrYwSF7UoB+/SRtMcjs WzX/3pTM+mkBe0DsGwgvsqcnmrqLPg5/FuYWKA5Dddkj72vDC2YoNBMOG TN3TuYbc4hgKTRskkxmvDWyMO6FfnxqnqAfFWgJV15VQ7/9jATI2UNGI/ tO7LHXLkYAzMFklA1Ys1hHDZ8BlgXjgL3VA6P4S3dfoZLwcVf50SUrETI 8fSuARJfTOjTzt5X9sp6gYoUu7AQSUhldFc/q86DEBIGN4uTcXcuPpyxM MtdHiezrUd9lj1gT0b+KV8GkuimPOOh4FaGwEZxiwX/B05XyNlfmp1TjF Q==; X-IronPort-AV: E=Sophos;i="5.91,230,1647273600"; d="scan'208";a="205309219" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 16 May 2022 22:31:52 +0800 IronPort-SDR: g9QjzzNG7TeNyeOBPDXYSWdfHHUxKX5grvJvOTTKh83QCZaulInKWCPmXDjdDb8o3z/JTfeS/T dX5wGHaJW21wPadolc4/IQgk98BnTycGZkO1c9KEa22pPeca3Nhgk6SJqRRvZl+OShoE4Csm6S bd0UQ9+8QHjnacLBkNC0aHXLB3Ev/sakf1Z3ejNrEu32IDDgim4OUX4oJjeacsF25Lz4n/bLAb J8AjOZxZuB5Vh8MOOslEPWIKfmnOKy/b1861laaMV1UwdXpUnWPiu2jm0NgpSSoWPGfEvzizb5 ft8M9FU0Wky94xpvvtkeTFAt Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 16 May 2022 06:57:34 -0700 IronPort-SDR: dg1EJxnVWBwvbGAFbzD4mhuBiiCjz8kGZQFuhLiBAMjC+08lZOEWLva6HtycT/2sqhrqF1Evk1 TYUQJnlKEy3r1Mpata52NiTMtXdpTZmCriGx13HbsoAool0Tp9j3VeaojlUcP07nkyqAXZ+uGD 5uSBLmRmjCalWEHx/VxabJKo2xwfO+kSe4wvTAcWXeaMo4vvug1VflufTqXpe5YNSOQULavxYf lfsrbEwJj2aO1DZXDR+50SE3KECqUz2MlQcEWscPBVOSJc7rXVwNzau2n+8bsP8efKjFG65yx4 m78= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.72]) by uls-op-cesaip02.wdc.com with ESMTP; 16 May 2022 07:31:52 -0700 From: Johannes Thumshirn To: linux-btrfs@vger.kernel.org Cc: Johannes Thumshirn Subject: [RFC ONLY 8/8] btrfs: add raid stripe tree pretty printer Date: Mon, 16 May 2022 07:31:43 -0700 Message-Id: <40c1d1679ee4a847dfcd95eab797222a320da905.1652711187.git.johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Decode raid-stripe-tree entries on btrfs_print_tree(). Signed-off-by: Johannes Thumshirn --- fs/btrfs/print-tree.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index dd8777872143..1ee06b511951 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c @@ -6,6 +6,7 @@ #include "ctree.h" #include "disk-io.h" #include "print-tree.h" +#include "raid-stripe-tree.h" struct root_name_map { u64 id; @@ -25,6 +26,7 @@ static const struct root_name_map root_map[] = { { BTRFS_FREE_SPACE_TREE_OBJECTID, "FREE_SPACE_TREE" }, { BTRFS_BLOCK_GROUP_TREE_OBJECTID, "BLOCK_GROUP_TREE" }, { BTRFS_DATA_RELOC_TREE_OBJECTID, "DATA_RELOC_TREE" }, + { BTRFS_RAID_STRIPE_TREE_OBJECTID, "RAID_STRIPE_TREE" }, }; const char *btrfs_root_name(const struct btrfs_key *key, char *buf) @@ -184,6 +186,20 @@ static void print_uuid_item(struct extent_buffer *l, unsigned long offset, } } +static void print_raid_stripe_key(struct extent_buffer *eb, u32 item_size, + struct btrfs_dp_stripe *stripe) +{ + int num_stripes; + int i; + + num_stripes = btrfs_num_raid_stripes(item_size); + + for (i = 0; i < num_stripes; i++) + pr_info("\t\t\tstripe %d devid %llu offset %llu\n", i, + btrfs_stripe_extent_devid_nr(eb, stripe, i), + btrfs_stripe_extent_offset_nr(eb, stripe, i)); +} + /* * Helper to output refs and locking status of extent buffer. Useful to debug * race condition related problems. @@ -348,6 +364,11 @@ void btrfs_print_leaf(struct extent_buffer *l) print_uuid_item(l, btrfs_item_ptr_offset(l, i), btrfs_item_size(l, i)); break; + case BTRFS_RAID_STRIPE_KEY: + print_raid_stripe_key(l, btrfs_item_size(l, i), + btrfs_item_ptr(l, i, + struct btrfs_dp_stripe)); + break; } } }