From patchwork Wed Dec 13 14:43:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824625dys; Wed, 13 Dec 2023 06:43:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrjoTJ1dgLqUaa0SiwI8XRutl937XfUXT9CeQEzJYUZhVQUGZMXem0G4l+Z7+44Ab22i2T X-Received: by 2002:a17:902:f546:b0:1d3:6238:a528 with SMTP id h6-20020a170902f54600b001d36238a528mr96751plf.23.1702478630740; Wed, 13 Dec 2023 06:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478630; cv=none; d=google.com; s=arc-20160816; b=W6cZSX8oivcLVtNPQZofid2e9/Z95hZsKHZXC8TcNJtXoezkNvxyyd1sHonk2QnYHp 7+aucf59mE3EzgJXwNNh+UGLwZ0NUDPmC1x92tNWLQEhT/u7PS90doQAbwrY29RNBl0N dipl0wFn1H8um2mkFc/Jr3XjRvyPExe5bqovWHb3PMUbavNeD2LXYK65Ojx17+ZDhLVH vEJ67nWpPBOhwo1NqvX2/8NaggX5fL7DUC8sUCe8Yifme1JbCYhWxJTcYg4DBDUuRyKT mcmPOREl4sxLHwSPB5kzEW9yY8OEj9lZdEchEuXD8Cj/31GyT20sCU3peWlRNNLlyRXI qliA== 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=5X/YXOPnsh3MUkHJu+m9TVkOt4yOKa0FHQYFxRSX268=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=zMQvA9n5u/mhauZ6jPurnacBzJXfSGy5o0j9BEPF/q89rK8sRlvZ4p5Ai4uYCDr+N+ gOrX6mVXkRu68VcKZPXctN2lgzgQCQGP1dxKXT0CBXOA1hH+bONWH0MxKBMi5Fmvh06Y CFdvsctCYAPqbAmw3oKmblR7OWZHVnG0ZCZd4CV+jsk8rKrPzTZgv0MTGcqGtkM/PgkT u1jMquk/zU6LRYQRs7YF1BQZOw326S9DisrwcXRhCnq2TcTGRXJwz6ejIwGO6FRkNNw9 /PqxHr1fx26UV1aBF6fOhogax2k+8/Yw0WEYYnSFWJm/EfZoCV9i1ZaXjgNJMvu9jhg7 BcOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=rsq3ow2e; 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 o15-20020a170902d4cf00b001d082f25836si9698711plg.333.2023.12.13.06.43.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:50 -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=rsq3ow2e; 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 01422826E333; Wed, 13 Dec 2023 06:43:47 -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 S1441973AbjLMOng (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378944AbjLMOnN (ORCPT ); Wed, 13 Dec 2023 09:43:13 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D95DD; Wed, 13 Dec 2023 06:43:19 -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=1702478599; x=1734014599; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=qN9uFU57GBna2r1afgLudejpCt6oeNpZ8RYEEAbqQXg=; b=rsq3ow2eWmjEgFeyR0jpq8WGVr3aVBbipVvjQfs8g+QM/jxxDkmNYsun dchscET/rroFcnDmjXZ3CnM4PpCkoGtbe/zc327lsmXszDShDt0F+NY87 rUMQWE75TNobHNp5N3R+O9jnCvOkBk7EiMM2/zDOesmFFhtr57vqPnvbY Saz6MPtaL5uEAsMAsH3Sap6UTrsBjpOBAP1PMPzCewoVsNXPDIur8u4jU aN+2JEmbXxoy2fQRU5iaIQx4+PhacXxIIK74rqZf4oGzmvgB/EiYvdFYS wH9hLOQulVExhrQuKs53KDKuYaofX7ADa2iZBFXYrbbyBNgNo4sN9aBbD w==; X-CSE-ConnectionGUID: FSnTn6JcTaaJEa7Na8rxyg== X-CSE-MsgGUID: LInRM9QtT9iKNuNtPYzxhQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580759" 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:18 +0800 IronPort-SDR: lyt6xR+vykByqf1jWQA8GMQ/ft12tNXRgi7Z25mb2GJxiDgjA8doJhOOYCg+DgKQaPcQEHb3Ub TmQl6n7JXF2w== 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:30 -0800 IronPort-SDR: J2ayBnMfsZEDf/vIc07aK+WYzQeCZ/WpAJqHvaNHjQ2NotY1+NOxfWGl/LoOA44EUhCMHF8yW/ EwbcbU+id01g== 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:17 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:04 -0800 Subject: [PATCH v2 09/13] btrfs: factor out block mapping for single profiles MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-9-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=1479; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=qN9uFU57GBna2r1afgLudejpCt6oeNpZ8RYEEAbqQXg=; b=GNdQPNmiHfgl1oXaJa/IVRS0l3ajkT51NLCGozaz/MHqjMXwZZ1CW6t4MH4Jx3fi4CkpD97Ym g4JV3WNQke0Ce8JBP4/pBhcFu5cxQp3j3hu7Trc+B1uQk/QkogCGigQ 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:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178232602351080 X-GMAIL-MSGID: 1785178232602351080 Now that we have a container for the I/O geometry that has all the needed information for the block mappings of SINGLE profiles, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 55614a9eb8a5..e23c7d2842a6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6487,6 +6487,14 @@ static void map_blocks_raid56_read(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_single(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + io_geom->stripe_index = io_geom->stripe_nr % map->num_stripes; + io_geom->stripe_nr /= map->num_stripes; + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6591,9 +6599,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ - io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; - io_geom.stripe_nr /= map->num_stripes; - io_geom.mirror_num = io_geom.stripe_index + 1; + map_blocks_single(map, &io_geom); } if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info,