From patchwork Wed Dec 13 14:43:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824580dys; Wed, 13 Dec 2023 06:43:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFXIYIEYwMD+tEdiGIGHJs9D0PBpwzmxVqb2bNaTUnZ8my5ZdTEZlkowA6Kl46IkyfcjNyp X-Received: by 2002:a05:6a20:734f:b0:190:a95:ec72 with SMTP id v15-20020a056a20734f00b001900a95ec72mr9796607pzc.40.1702478625828; Wed, 13 Dec 2023 06:43:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478625; cv=none; d=google.com; s=arc-20160816; b=m5opAUGIAUf5UzhQ+6bdpFdJWXB8dPR0Oogqh7H/OFvfFjV9QWSW3H0vWVonb87+nW fPjY0xuClPHbAGXPlAnZE1NsQCVZcsqSeCSG3l5Ou1iSlT3KW6IAQ8N0ihaaomxPGLOz bMV+naBFdkzSugRFGIr6IC+tDD2YlmPnU59IAEW/VkFW9r69cxvWxhd5+RGRcCi97cBA 66bo6grRujlhQUEshu6JatgMYFH3UXlVE5PPqJ1WGJ8xqQlS4qJLlPG+9gqn5DWUJLDo Q82g5l7dWWaGYIWMlx9lwVyvYkLNzYDqN5gFhi6IRmKRjul1vYvuqT/zqI4/OOnebks0 xYOg== 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=Bm4r/lR6LaOEQU8zWvtqcw8sJ6IysvuDwMH22qrSb4s=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=HwRpjnpKckr8rMAHuxBUZXBRaaZ69aRkzT4ifjoWtIK9IHJn1q2zlJ1nVPbheW42/3 Y33OxiALW1s2HkdWfGiLuDBDkzd7aHEYoe7lDMY74sRcaMpJarSXkBmo5+LRIq07mKQ4 kZWD2UXR3fEx9L0gS3ldb0PpiazstgxAblb0rC7OEDAkBmKN0cgeQ+5kvCr147WUBdyK Wt9MzlkBYeopbi3dXGKIWcws3yyriWk2P6q+09FKwS5LQWQYFzCiz8gc92Ko2b8OwjZk TsfKuq3L6ksfOiZjusSNxlfCjTIbtbvWa+j1Rmjk1oTjnD3hZ99nA0+TphVjYHSQHDlW ujdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=i6yZLI7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j7-20020a654287000000b005c1b2e37aeasi9683369pgp.384.2023.12.13.06.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=i6yZLI7W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 56E7680C6EBD; Wed, 13 Dec 2023 06:43:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379323AbjLMOnZ (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379272AbjLMOnI (ORCPT ); Wed, 13 Dec 2023 09:43:08 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3AEE107; Wed, 13 Dec 2023 06:43:14 -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=1702478594; x=1734014594; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=k/eSjTGoN725k3LZy+WZVmCNR9DvRAZuWjLXRQb2ZVo=; b=i6yZLI7WoRfc6IANfbDlojCNQ/f/XOTQb40S2dpTUn3c9TvFWp78feQq HfiMDal8qp/9nIoDuOCl+HkchLDxYxLkxeh1HhzaknGXDVnHoCF1mRuv0 9/p2y0axZIRDfA8l/41Y5dtSvRwllsk/yCT/WAd/tAMNzXcy7x4fTVOda ea0JaFM5T1UMITQaR6E8dggg18962EkQ3PpI9FKS207Ovo5pE0Lp19yIf XiTVB820IK4JzvX/EXUz+g8zoh/KFlCUPeXH8ZiyqZiaB8oM2Qs4HjNcI XyqJKHVhnX2VLR5PoFPxMlLmAO1eUTDAQAMu+fpknst04GUPQhyyCkRex Q==; X-CSE-ConnectionGUID: Vhjy7St+RmqxN4ifySrVjQ== X-CSE-MsgGUID: 429hW5lOTuib3QA+JrmxTw== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802965" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:14 +0800 IronPort-SDR: NUVmos8vm9cR2oQ4Djni4qHbuIkxqcyumoZpCZC5PsUbne0f8HIrCLuk/2ehSQd+jPSC+jJNL8 T5jyxTmaiy2Q== 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; 13 Dec 2023 05:48:26 -0800 IronPort-SDR: c/s0/YKZMafYfky/XtrydRIzOSGnTzsxNh3F/dDJvjUDtMUqdUa0v9pxypBd9+Wk2oogwsW7Tk Mmfp2cs1adPA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 13 Dec 2023 06:43:13 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:01 -0800 Subject: [PATCH v2 06/13] btrfs: factor out block mapping for RAID10 MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-6-cf5cfb9e2400@wdc.com> References: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@wdc.com> In-Reply-To: <20231213-btrfs_map_block-cleanup-v2-0-cf5cfb9e2400@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=1702478586; l=2601; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=k/eSjTGoN725k3LZy+WZVmCNR9DvRAZuWjLXRQb2ZVo=; b=eGKcEIqKJEY7oDZiWFy+6o9xNILU5E60gvfBeHaPRV+52HMOLFF4IzrNtknxLTtgz1N/yakLW xIDvxy671pBBC4jAqdH8oNLTRB4FGQuNVSZUWHqH3psw4mEc4///jgn 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 groat.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 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:41 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178227550855746 X-GMAIL-MSGID: 1785178227550855746 Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID10, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fe2807bb0935..4c9c130cdfd0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6408,6 +6408,35 @@ static void map_blocks_dup(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_raid10(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + bool dev_replace_is_ongoing) +{ + u32 factor = map->num_stripes / map->sub_stripes; + int old_stripe_index; + + io_geom->stripe_index = + (io_geom->stripe_nr % factor) * map->sub_stripes; + io_geom->stripe_nr /= factor; + + if (io_geom->op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->sub_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index += io_geom->mirror_num - 1; + return; + } + + old_stripe_index = io_geom->stripe_index; + io_geom->stripe_index = find_live_mirror(fs_info, map, + io_geom->stripe_index, + dev_replace_is_ongoing); + io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6502,23 +6531,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { map_blocks_dup(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { - u32 factor = map->num_stripes / map->sub_stripes; - - io_geom.stripe_index = (io_geom.stripe_nr % factor) * map->sub_stripes; - io_geom.stripe_nr /= factor; - - if (op != BTRFS_MAP_READ) - io_geom.num_stripes = map->sub_stripes; - else if (io_geom.mirror_num) - io_geom.stripe_index += io_geom.mirror_num - 1; - else { - int old_stripe_index = io_geom.stripe_index; - io_geom.stripe_index = find_live_mirror(fs_info, map, - io_geom.stripe_index, - dev_replace_is_ongoing); - io_geom.mirror_num = io_geom.stripe_index - old_stripe_index + 1; - } - + map_blocks_raid10(fs_info, map, &io_geom, + dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { /*