From patchwork Wed Dec 13 14:43:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824663dys; Wed, 13 Dec 2023 06:43:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWs4CQATlCc/QWe1QN1lI/qNl2qvTpfgDjYWQ+uKVVIeQN4lu4ExufFUPW/hMbiwq5Vrkm X-Received: by 2002:a05:6358:7f0f:b0:170:f3ba:e42a with SMTP id p15-20020a0563587f0f00b00170f3bae42amr1899167rwn.15.1702478635296; Wed, 13 Dec 2023 06:43:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478635; cv=none; d=google.com; s=arc-20160816; b=bbafjJmcZbhG3GHRn2weUkd7P7qBmrCutMDOq4BQn9cog3+T3qzSluAXPIlN/nWGKM 7RBBWkXa+Sl55UV8BDjgtUmHQ96zVHfpQidXogNjTO1WPjbFjrvE3I695lc31nVqFqgo p0Kakcxl/XkxP2kHXiwr5FN3lOePuPYURpunaJsKVtm5i60iK2OpVnb/lJzZpNuAzXvE R6qrMVQuOU8bXEj9NqDJG1ybXtneagKajNtz0D2aJjBvvBS7eBpip9acqg7w1bay4QIs Il+jr58cRY3l+JysUVcE11H0DNF0zIbdL5pC8lC3378XRAqhCpeXJE5Os56OgHEZ00g2 Q2Ng== 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=Q5L9nOJ1wLfjSaHEdgH2Hf+K155lOeyCKcMzcTVYVaM=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=uY7A8e/hI/1/wHxUnCyittkab3KtVb0DKTbH/WZA3kQQsY2Rce31h4oKBdnQ9pof0r txqNQE2cp+b+7RQOiYF+vGa9+0XCdsoDZkp1n2r+QCavwIzgM0AaFEqkKthphar0ypuE p7ORn7Atn/AA7kbAptJ7qEeW0o+9tZWZQqoIFgbKY0pZgXIf97v3wARtUZqN0+kJkzOr G4swA6mM8RN46VEv/Zy8zAVCCZkwvapdgdBkpfiYN4tjBxWA/qH2DraexSwuy9IVnJpd 60sPokUhxaE9r2digsoAxnGHjSPiU2sK3Ew4evsTQfZsF7pfQBcmk93fiI5FddSZXlGs mwBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=bi1hDzPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q5-20020a632a05000000b005c6fc5d7a58si8330493pgq.356.2023.12.13.06.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=bi1hDzPp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 98B7B826E352; Wed, 13 Dec 2023 06:43:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441927AbjLMOnX (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379214AbjLMOnH (ORCPT ); Wed, 13 Dec 2023 09:43:07 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF29710D; Wed, 13 Dec 2023 06:43:13 -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=1702478593; x=1734014593; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=OGBopphelKNfH3fDb7Sryq8+Z3p2RDE/ywfM09UR7p4=; b=bi1hDzPpuKz0//o8Oxmm8HLJnQ4g4W7TxEOywbRKxhyjgisp64xgXCzS jJxSduvcv4Dksf+F+5eQ14HX8sPSnQlchYJUD3OCJHH6UueAo6m2BIV++ 9WPCIPFj1qoZFjNV4PqIsTuhVyimqY9/cdol0eAgV97YZs22S7K3a/B+a f/G8yp+z8XJ4pYoSr+tlvy7GEgUUWq5S8wDCxAF3bFiE2FwR1iLOJqsAR 08UmLScHaJj2fxbfN5CYhyDSdsUvjVmKvodgcVl1Ncq6iwBoNlXjcCbEn eUfhoPvmP61UAYqhVA7pb8Upz41M8edVAubjDhJasIfSxPwVgTq9fQY8P Q==; X-CSE-ConnectionGUID: 1f+F10bjSYigoi42PdxRig== X-CSE-MsgGUID: FEuCJKl3SemXdBePbuYRSA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802960" 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:13 +0800 IronPort-SDR: FLJAOc0lbqerwDZ4MToxlU4c9G7Ttz9yqNEZuHaraCPJrIOnuibTmOeMu9t9Q9cB+cWd8Al1ij Znz4+PAH1mEQ== 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:25 -0800 IronPort-SDR: rnTZSX//iZgybjgnnAkzZqoPezDuWIFemcqbCoxFEr5w+jxQ2TeSNvkH0WraZ1ksD8KfbGE2Xf NxEebyD4s/Bg== 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:12 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:00 -0800 Subject: [PATCH v2 05/13] btrfs: factor out block mapping for DUP profiles MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-5-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=1656; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=OGBopphelKNfH3fDb7Sryq8+Z3p2RDE/ywfM09UR7p4=; b=RoUSRB0NVfcBYTvIOqxOOxqc+hkutI1em/Twwdx6l0bDKETDThATmODhCll6UwYpaFA8rq/uH 0Tzc8n5u/9FA6kNzuXkI3dhPx+QfoO14JiDspxKP41PCdWZTtwvmoDQ 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 morse.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 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:50 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178237541622978 X-GMAIL-MSGID: 1785178237541622978 Now that we have a container for the I/O geometry that has all the needed information for the block mappings of DUP, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c11fb6db4679..fe2807bb0935 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6392,6 +6392,22 @@ static void map_blocks_raid1(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index + 1; } +static void map_blocks_dup(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + if (io_geom->op != BTRFS_MAP_READ) { + io_geom->num_stripes = map->num_stripes; + return; + } + + if (io_geom->mirror_num) { + io_geom->stripe_index = io_geom->mirror_num - 1; + return; + } + + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6484,14 +6500,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing); } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { - if (op != BTRFS_MAP_READ) { - io_geom.num_stripes = map->num_stripes; - } else if (io_geom.mirror_num) { - io_geom.stripe_index = io_geom.mirror_num - 1; - } else { - io_geom.mirror_num = 1; - } - + map_blocks_dup(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { u32 factor = map->num_stripes / map->sub_stripes;