Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4606894rdb; Tue, 12 Dec 2023 04:39:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNdxCqv6n2+5uvCKoXLSc9GiGi2DbtTyBsYg9a6iqdC0JY2/KR6PxouTQ+cEe8ZhsKEvk7 X-Received: by 2002:a17:902:bc8c:b0:1d0:6ffd:9e2b with SMTP id bb12-20020a170902bc8c00b001d06ffd9e2bmr5203800plb.125.1702384756577; Tue, 12 Dec 2023 04:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702384756; cv=none; d=google.com; s=arc-20160816; b=l686o6ko967MWue3Edh0ZA6liMNQQpEfR2pesluL2rc9UNuBLLqh7CJpAli5HPrNou eRxjSFX1dYNb8A4EBKy7FmAZXdJJEeJqFK/534mzOEJnmXoRyljONGDV4I8inyaoAbuP Db59A51s/45JxcNZ54+4Ue8A6NfDye8ed2W/aY7xhfikfhX0lqPmC1uoHRQ1OTCv+E+H yxU5n7kE/0H7+fS6l+1OlxMQi2GDsC7EmYTimE/dJ/qYSkx5mj8TdXakgFUBz42s0oes kRnOUS9YEG3aHA9zgJiLGLmErVq/HuKkZcYevf5ofzvAZl66fZ9xSijSia2s4UfdZXCe yJ8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :wdcironportexception:ironport-sdr:ironport-sdr:dkim-signature; bh=Z0Ubgf4/rbeUlp2cdmZlS9wZsMfcIC1jUg3wTx7zLio=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=KWBXwcoYagQC3Wg/u96r2+hF7qPpI3iqnPzDptRYrPJIjPtTHJH3jQ7ykRCs2A/mwk kVXwgTXd7mWCPwS7EQg7oCmrN8Q5G7G2IXjvq/j0Pu0PxQ0ouGoxEjCu9v+ElKk5WT1w M+yZ0V20GHTaKoYPhIcBnaVb377v5L56Fsn3DMKnc6y/S9SogwmaJLulbdaBN7AIfMIo ia2uMjtGo/dI3mpdcy982XsNHWCvLEjKBlbK95dAJlIP2XL1yJLxfUIUMm1KAUvNFYec r0rC7QZdZ2WtIBEZjwhvu+BqPzgQwdR2M3hh2M54uxSfaEjq5mtBL9Var0D6PZLdSTCZ nO7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=E0mtm3OD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id m10-20020a170902db0a00b001cf8e9e8813si7804876plx.315.2023.12.12.04.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:39:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=E0mtm3OD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wdc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id EC8FF804C51E; Tue, 12 Dec 2023 04:39:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346703AbjLLMiw (ORCPT + 99 others); Tue, 12 Dec 2023 07:38:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346542AbjLLMig (ORCPT ); Tue, 12 Dec 2023 07:38:36 -0500 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD2518A; Tue, 12 Dec 2023 04:38:30 -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=1702384710; x=1733920710; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=13sSKOdPGCtJkfDz7HQPJxztkCHKHtWtxlS4sYRz4H4=; b=E0mtm3ODGYYYMV8YUegryncaZoWzS4o6t4v9LxRadScZkpdqSjm9x6cg vA1Ek6wO6BCYWJaMRdj3zw2zUeOAo5yUNoSM9ViHXZxrZp0TV0MgG6SrU S3vH4NUVqs0MGgnjC72v3suCpa333uqDt10FpYD1eaSODZl69OliJ7Ca3 b6wyN1a3zkDfb8jXsPpdWZ1U4OKoL/da69PV8E/4GOlpcSK7DlezAsORT 7/RCgbAAShhVdYLT6xVKCMeZt0jfh+bUEM3ry7xUrQFNoPrpzL1Tz6S9Z sBVKZB24NFoEH2y94qaxTXl+t2Ehbn3LIStRgE2SNSxU+xmqT0HLZVLgj g==; X-CSE-ConnectionGUID: va5vw7GKTH2FBlFviEvl2g== X-CSE-MsgGUID: 7MRTnW96QaS6F8qfMtdagA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629800" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:24 +0800 IronPort-SDR: j0J/dG2cgKpx4DcpuqCRoR9U3+qv9Iyxt69e4py1qaKKfCOEgTOOhEErPFzooqtcZVCEgU/gs9 xt3mSFH/xcyQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 12 Dec 2023 03:43:37 -0800 IronPort-SDR: 5scbsRwiXUxhNm5LGPAxCPN18+mYWq7ksdwM55JYQOAmA9fXPdGQOgKwRqgDip5/vxloYNCMhF ETdj34Q+m/kw== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:23 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:06 -0800 Subject: [PATCH 08/13] btrfs: factor out block mapping for RAID5/6 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231212-btrfs_map_block-cleanup-v1-8-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702384691; l=4237; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=13sSKOdPGCtJkfDz7HQPJxztkCHKHtWtxlS4sYRz4H4=; b=TDOS5Lt38tJFregGC9nNL23Jv/PCsz8I1IJK3qjSuXJmjp4sHbxkXD8Qf6U/zluSNhuTSShXE g170bvYfm06B9G05ZhEWK0oilO0BXLCZROYDmNQO0fnNI4awFm6dmCK X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 04:39:13 -0800 (PST) Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID5 and RAID6, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 91 +++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index bc0988d8bd56..fd213bb7d619 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6437,6 +6437,54 @@ static void map_blocks_for_raid10(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; } +static void map_blocks_for_raid56(struct btrfs_chunk_map *map, + enum btrfs_map_op op, + struct btrfs_io_geometry *io_geom, + u64 logical, u64 *length) +{ + int data_stripes = nr_data_stripes(map); + + if (op != BTRFS_MAP_READ || io_geom->mirror_num > 1) { + /* + * Needs full stripe mapping. + * + * Push stripe_nr back to the start of the full stripe + * For those cases needing a full stripe, @stripe_nr + * is the full stripe number. + * + * Originally we go raid56_full_stripe_start / full_stripe_len, + * but that can be expensive. Here we just divide + * @stripe_nr with @data_stripes. + */ + io_geom->stripe_nr /= data_stripes; + + /* RAID[56] write or recovery. Return all stripes */ + io_geom->num_stripes = map->num_stripes; + io_geom->max_errors = btrfs_chunk_max_errors(map); + + /* Return the length to the full stripe end */ + *length = min(logical + *length, + io_geom->raid56_full_stripe_start + map->start + + btrfs_stripe_nr_to_offset(data_stripes)) - + logical; + io_geom->stripe_index = 0; + io_geom->stripe_offset = 0; + return; + } + + ASSERT(io_geom->mirror_num <= 1); + /* Just grab the data stripe directly. */ + io_geom->stripe_index = io_geom->stripe_nr % data_stripes; + io_geom->stripe_nr /= data_stripes; + + /* We distribute the parity blocks across stripes */ + io_geom->stripe_index = + (io_geom->stripe_nr + io_geom->stripe_index) % map->num_stripes; + + if (op == BTRFS_MAP_READ && io_geom->mirror_num < 1) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6529,48 +6577,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_for_raid10(fs_info, map, op, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { - int data_stripes = nr_data_stripes(map); - - if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { - /* - * Needs full stripe mapping. - * - * Push stripe_nr back to the start of the full stripe - * For those cases needing a full stripe, @stripe_nr - * is the full stripe number. - * - * Originally we go raid56_full_stripe_start / full_stripe_len, - * but that can be expensive. Here we just divide - * @stripe_nr with @data_stripes. - */ - io_geom.stripe_nr /= data_stripes; - - /* RAID[56] write or recovery. Return all stripes */ - io_geom.num_stripes = map->num_stripes; - io_geom.max_errors = btrfs_chunk_max_errors(map); - - /* Return the length to the full stripe end */ - *length = min(logical + *length, - io_geom.raid56_full_stripe_start + - map->start + - btrfs_stripe_nr_to_offset( - data_stripes)) - - logical; - io_geom.stripe_index = 0; - io_geom.stripe_offset = 0; - } else { - ASSERT(io_geom.mirror_num <= 1); - /* Just grab the data stripe directly. */ - io_geom.stripe_index = io_geom.stripe_nr % data_stripes; - io_geom.stripe_nr /= data_stripes; - - /* We distribute the parity blocks across stripes */ - io_geom.stripe_index = - (io_geom.stripe_nr + io_geom.stripe_index) % - map->num_stripes; - if (op == BTRFS_MAP_READ && io_geom.mirror_num < 1) - io_geom.mirror_num = 1; - } + map_blocks_for_raid56(map, op, &io_geom, logical, length); } else { /* * After this, stripe_nr is the number of stripes on this -- 2.43.0