From patchwork Wed Dec 13 14:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824366dys; Wed, 13 Dec 2023 06:43:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyvCSA/Wp+k7kQ/6xxBLoieC4FldWxA03ze0ciDlZOkyyo02fcjDHKSsmy+OA5cMTMwvOP X-Received: by 2002:a17:902:7e83:b0:1d3:5cef:a03c with SMTP id z3-20020a1709027e8300b001d35cefa03cmr179182pla.129.1702478601578; Wed, 13 Dec 2023 06:43:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478601; cv=none; d=google.com; s=arc-20160816; b=eUg/Lr8isgdT5EnG5mfvZo8RoZzsNqe9rcV2xvBNelM12S3ZbD6mInKYxgR1DjxIqs nWb+Dk04ZoQQ+tA2//vOddOJNV7s+KFjbzYAe7AI/SG0cJoAzfiH/uND66aAqqTdvQyh Z92Nu/iO0tnPgzW7nAFb10IKzKjNEHLE9jaC47mJzQ+xqm3L/1fUL3gmmAE8ZNSLtrbj v/1bI1v+JfNRAemSjaw8ngx1PWW5IX/vIDlnDD3KePhMBSRjEo7T0N36hDGN4jEBxTlU jsIK1EIx4Ra0xBI4ElS1H3zCaFK5iUyJ4zDBSjdTjWr14ajNrrV+9zO4RugXYFDKNl+e ir2w== 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=G0uQ8Njd0ZGQY7DYWRQ1yCsw7xDMczezmCcla3/Q96M=; fh=WpTkEVtBXkq0RoDrgO3Js2s/6swFB/ddJMCfC4s0b8Q=; b=Rqxi9AfAnbAzbOeQ0j8k3osKsZEdqrtFyLuwieeDmdYMjbsSvP3lOP50hLg7BiXOzl +OtdZAHP4HUOtWb0a+l85lYi4uFrPFrI4iMmwFVPdGWYQ1DqvnsgDJrytIiYH2TPXOkV 1/jdlVlj273mOstVr7qI250o0++/SrXppT4R3NQ04+zFv5M566AJXNPEo65YD6Ua65Y2 VwLV5R3ZP9CZ9u7lt5OWA0kl5JlBML5zrz9c465PhCMQl3q28sd1D9QQdj+3aE/0SX60 Y0X8lm4TFeiGlFnJj0AA3ORHD35Jji9oQQ+pximv4w5Gxi8b8isJZ6LrUSW7ngW+D0m5 1wyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TnkfyvSy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u9-20020a170902e80900b001d33c6ce935si2652813plg.436.2023.12.13.06.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TnkfyvSy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 77A398031B23; Wed, 13 Dec 2023 06:43:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235386AbjLMOnL (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235299AbjLMOnD (ORCPT ); Wed, 13 Dec 2023 09:43:03 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B21E124; Wed, 13 Dec 2023 06:43:09 -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=1702478588; x=1734014588; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=fLhd1MyDh4ypvFhcwsIuuCtALl4S244wNQFfdcICrTg=; b=TnkfyvSyeA1/q3KeQOfhhAwE+wgaP92OoIltyfDnTByssZ5gjIy3h25L uvO6K+ktOEbb3awyY68/KlkNhXmsimTN5ijTgecgX+S2ncu1ycUSg3HKy Qq+jF6j5gXTVqjqG/ypIBtDpfUUKMx9tXeDJ8b2UDHKFyz9Qfq7bOKn9x Vnjq2RQNyjoevUO75flU2F5anIYVM7ujnevM4EBK6lwwOPi1rAbQZ5lkD 4vIM9lJz9JEc8h3Fe8ZO7wwOYwLM27GDXjLRhnm17ovddDwh5JW5VUMwh QwmZQUTDaEPh+tjpIiRJOY/tsc0GeDjinCiPtgAoQ8brl76QJlN+D3nbM Q==; X-CSE-ConnectionGUID: Q0HLwt5WQyaDShLA6+Wusg== X-CSE-MsgGUID: SQicrwMvT6yJ0tCm29G4Xw== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802938" 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:08 +0800 IronPort-SDR: /iXhflbgZ4L5W8cafBotModBWZbxixjgFWkRGvbVaMeO1VBbGOUfqIef2Vy46+y+27iF45zu91 N4fOknyfYU+Q== 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:20 -0800 IronPort-SDR: 3Aep+t61H4Om/uEMNGTfvo6ZNadHR51oXjbTWa4NG5rOF/mybzIYBSH4pOsgRX86BbnwI0WktF OS6Wue9ppxxA== 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:07 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:56 -0800 Subject: [PATCH v2 01/13] btrfs: factor out helper for single device IO check MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-1-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, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=1998; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=fLhd1MyDh4ypvFhcwsIuuCtALl4S244wNQFfdcICrTg=; b=saGTUjHP3jWIxzIxSkKyDz3xz/OmV+KoocqSCfxxEIOuDJWVhwoNUXikb/s7rBbglCCsPfSnl yNM+B483/ppDSAVU0oIH9twkbNc07lWH9SFM1Bw+l/AldagqxAb3d52 X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178202013614078 X-GMAIL-MSGID: 1785178202013614078 The check in btrfs_map_block() deciding if a particular I/O is targeting a single device is getting more and more convoluted. Factor out the check conditions into a helper function, with no functional change otherwise. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1cc6b5d5eb61..1011178a244c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6330,6 +6330,28 @@ static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, return 0; } +static bool is_single_device_io(struct btrfs_fs_info *fs_info, + struct btrfs_io_stripe *smap, + struct btrfs_chunk_map *map, + int num_alloc_stripes, + enum btrfs_map_op op, int mirror_num) +{ + if (!smap) + return false; + + if (num_alloc_stripes != 1) + return false; + + if (btrfs_need_stripe_tree_update(fs_info, map->type) && + op != BTRFS_MAP_READ) + return false; + + if ((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1) + return false; + + return true; +} + /* * Map one logical range to one or more physical ranges. * @@ -6532,10 +6554,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * physical block information on the stack instead of allocating an * I/O context structure. */ - if (smap && num_alloc_stripes == 1 && - !(btrfs_need_stripe_tree_update(fs_info, map->type) && - op != BTRFS_MAP_READ) && - !((map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) && mirror_num > 1)) { + if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, + mirror_num)) { ret = set_io_stripe(fs_info, op, logical, length, smap, map, stripe_index, stripe_offset, stripe_nr); if (mirror_num_ret) From patchwork Wed Dec 13 14:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824660dys; Wed, 13 Dec 2023 06:43:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQ2ScoCcj5WghHoOzFO9v43Khvz+hDQHB5lUsvRSu0o7+zTeg2adsNho+35NhWr1L+abkV X-Received: by 2002:a17:90b:4ac7:b0:286:6cc1:5fd1 with SMTP id mh7-20020a17090b4ac700b002866cc15fd1mr4057100pjb.84.1702478635078; 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=HRIpLr0TsshxTz8SFXXzWSLhYyVqRBo8EiqKwAEuQeY3Cz3MhiwwaBz8LiOY8twABk 71Beo95A7l8xrxgjLfVeK31E+xZjfezmRjt9wA5eSPw8myMndOvQv0BVxAHkj56JABZw yrEM/ZYaSJAolnneQTnLjguYJBLDzXiTU2wcOaVti9Z5UmWpDNXNEugjCsWrtzZ66/uo 2rezeacqbAsECO8m/7JdDuVTvd8Vk1hZ4A/NUtDBmHoT+iw+xxEF3623HQvCjtZWUkDV hkssD9kfJ7AcBMo5r2YMdXKd0IUe+NwrD7yuyg90C+rJZsxRhD+13nzJ7OIDLAx4MNaf bCzA== 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=PLU8rxU8VhFOUVWn+kgWCvAColV8fy8Watd/rhWcSTk=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=OHgB+g/6lzqib8HOnBaRXbGvnx8Xy2JO6pz3wuUjYIjQMuzKA8RwuF6ea0MKu09o0k wkAZW0WSg0YR6kKoysYuzflEPzmWUx2LQO028sn0Yi1ZUfgnvPQiZp2GDOehMxDw5LI+ 4eRY150Ajx4p17ruFve5qT4DUKMa/P6QpBLpaVRKz4X21AKt2fdO3DVHxNncWKG5SU6p TXz/BSmNRr2HT2GewR6T1pQcIL17jaOoEIXcQlT0Io97jqvhcqN8kXbPslBA1xKtaUzD OolIck5rpnjGADAI2Uh98QeX8v9+bVOi6/2koPHm65xg06OHJ/H0QhGWh4paJ7cgCK5l carQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=N41Le6Kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id jx3-20020a17090b46c300b00286eeac293fsi10862847pjb.155.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.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=N41Le6Kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id E1BDE803C690; Wed, 13 Dec 2023 06:43:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379296AbjLMOnQ (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233684AbjLMOnF (ORCPT ); Wed, 13 Dec 2023 09:43:05 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B99DD; Wed, 13 Dec 2023 06:43:10 -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=1702478590; x=1734014590; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=kCWRP4ScRPyTqiJ4MDp9iTyJnJWsDUgaRphcdVMeqP4=; b=N41Le6KxFn1+00e4QkNJYWknHyiC5pUZlCIMXZl1JleqpUahAZlo1Q3S c06LK5bQA2/g0ot0tLej1i9/cERf0NOpphmxCAJ7eZqS/jpcZ6OZzATWm c7E370XqTda7YgF/nfcR2nF3PKSXxG6g7j2wcIHgeCxmQgk9ePOufLgJw 0C1sLz7qkhzLYe8u3njnFwQKBSMxB9G3HR2C5fSiyvfhnA9Laof+hywgR 5/9l2s83g4w4NSJ8UreIib1HM5BTwQwUEWnQllmKZrPL6XjKiaM3efWX9 DZxvnnT/tpX402YvnsPfaCB9F+i4Z6W0iNWcCXGttr/NbknHmPPTJyFZs g==; X-CSE-ConnectionGUID: rxeWZ6TySI6feA77rUiLtA== X-CSE-MsgGUID: oJw4pwKgRxye/OJealKLtA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802945" 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:09 +0800 IronPort-SDR: FWVbcpiYP1oJc9svd3OUOlP063r4p9weCnI58aYtoI/Jwtl6e2tD2wzFH2vhFQrBNIqXgMSmf9 YjZkfrBVP/KA== 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:21 -0800 IronPort-SDR: Sdqk3/eBzRzzkp2HGk8fT6lwuLwp1XheEUB6rD5taGVGQtS9g2aGj/uFym8ECulRPJu571htm7 Mz5ocnGzDYDw== 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:09 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:57 -0800 Subject: [PATCH v2 02/13] btrfs: re-introduce struct btrfs_io_geometry MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-2-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=11440; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=kCWRP4ScRPyTqiJ4MDp9iTyJnJWsDUgaRphcdVMeqP4=; b=OFP/4/oB9kN+9QYp7QGL72N2aaB/7kQePUB5cM8B57xxcsjfqxEKzWkE0ZgWdL3QvXQU4ufHk wFQ2RN9N/S+Am1+6rQ+f7CW/Uplka857APsWBc8ByWin+H4jp6VfSbR 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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178237561250498 X-GMAIL-MSGID: 1785178237561250498 Re-introduce struct btrfs_io_geometry, holding the necessary bits and pieces needed in btrfs_map_block() to decide the I/O geometry of a specific block mapping. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 159 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1011178a244c..ea830ff0c0e3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -41,6 +41,17 @@ BTRFS_BLOCK_GROUP_RAID10 | \ BTRFS_BLOCK_GROUP_RAID56_MASK) +struct btrfs_io_geometry { + u32 stripe_index; + u32 stripe_nr; + int mirror_num; + int num_stripes; + u64 stripe_offset; + u64 raid56_full_stripe_start; + int max_errors; + enum btrfs_map_op op; +}; + const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { [BTRFS_RAID_RAID10] = { .sub_stripes = 2, @@ -6393,28 +6404,27 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, struct btrfs_io_stripe *smap, int *mirror_num_ret) { struct btrfs_chunk_map *map; + struct btrfs_io_geometry io_geom = { }; u64 map_offset; - u64 stripe_offset; - u32 stripe_nr; - u32 stripe_index; int data_stripes; int i; int ret = 0; - int mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); - int num_stripes; int num_copies; - int max_errors = 0; struct btrfs_io_context *bioc = NULL; struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace; int dev_replace_is_ongoing = 0; u16 num_alloc_stripes; - u64 raid56_full_stripe_start = (u64)-1; u64 max_len; ASSERT(bioc_ret); + io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); + io_geom.num_stripes = 1; + io_geom.stripe_index = 0; + io_geom.op = op; + num_copies = btrfs_num_copies(fs_info, logical, fs_info->sectorsize); - if (mirror_num > num_copies) + if (io_geom.mirror_num > num_copies) return -EINVAL; map = btrfs_get_chunk_map(fs_info, logical, *length); @@ -6424,8 +6434,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, data_stripes = nr_data_stripes(map); map_offset = logical - map->start; - max_len = btrfs_max_io_len(map, op, map_offset, &stripe_nr, - &stripe_offset, &raid56_full_stripe_start); + io_geom.raid56_full_stripe_start = (u64)-1; + max_len = btrfs_max_io_len(map, io_geom.op, map_offset, &io_geom.stripe_nr, + &io_geom.stripe_offset, + &io_geom.raid56_full_stripe_start); *length = min_t(u64, map->chunk_len - map_offset, max_len); down_read(&dev_replace->rwsem); @@ -6437,53 +6449,51 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (!dev_replace_is_ongoing) up_read(&dev_replace->rwsem); - num_stripes = 1; - stripe_index = 0; if (map->type & BTRFS_BLOCK_GROUP_RAID0) { - stripe_index = stripe_nr % map->num_stripes; - stripe_nr /= map->num_stripes; + io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; + io_geom.stripe_nr /= map->num_stripes; if (op == BTRFS_MAP_READ) - mirror_num = 1; + io_geom.mirror_num = 1; } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { if (op != BTRFS_MAP_READ) { - num_stripes = map->num_stripes; - } else if (mirror_num) { - stripe_index = mirror_num - 1; + io_geom.num_stripes = map->num_stripes; + } else if (io_geom.mirror_num) { + io_geom.stripe_index = io_geom.mirror_num - 1; } else { - stripe_index = find_live_mirror(fs_info, map, 0, + io_geom.stripe_index = find_live_mirror(fs_info, map, 0, dev_replace_is_ongoing); - mirror_num = stripe_index + 1; + io_geom.mirror_num = io_geom.stripe_index + 1; } } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { if (op != BTRFS_MAP_READ) { - num_stripes = map->num_stripes; - } else if (mirror_num) { - stripe_index = mirror_num - 1; + io_geom.num_stripes = map->num_stripes; + } else if (io_geom.mirror_num) { + io_geom.stripe_index = io_geom.mirror_num - 1; } else { - mirror_num = 1; + io_geom.mirror_num = 1; } } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { u32 factor = map->num_stripes / map->sub_stripes; - stripe_index = (stripe_nr % factor) * map->sub_stripes; - stripe_nr /= factor; + io_geom.stripe_index = (io_geom.stripe_nr % factor) * map->sub_stripes; + io_geom.stripe_nr /= factor; if (op != BTRFS_MAP_READ) - num_stripes = map->sub_stripes; - else if (mirror_num) - stripe_index += mirror_num - 1; + 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 = stripe_index; - stripe_index = find_live_mirror(fs_info, map, - stripe_index, + 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); - mirror_num = stripe_index - old_stripe_index + 1; + io_geom.mirror_num = io_geom.stripe_index - old_stripe_index + 1; } } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { - if (op != BTRFS_MAP_READ || mirror_num > 1) { + if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) { /* * Needs full stripe mapping. * @@ -6495,29 +6505,33 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * but that can be expensive. Here we just divide * @stripe_nr with @data_stripes. */ - stripe_nr /= data_stripes; + io_geom.stripe_nr /= data_stripes; /* RAID[56] write or recovery. Return all stripes */ - num_stripes = map->num_stripes; - max_errors = btrfs_chunk_max_errors(map); + 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, - raid56_full_stripe_start + map->start + - btrfs_stripe_nr_to_offset(data_stripes)) - + io_geom.raid56_full_stripe_start + + map->start + + btrfs_stripe_nr_to_offset( + data_stripes)) - logical; - stripe_index = 0; - stripe_offset = 0; + io_geom.stripe_index = 0; + io_geom.stripe_offset = 0; } else { - ASSERT(mirror_num <= 1); + ASSERT(io_geom.mirror_num <= 1); /* Just grab the data stripe directly. */ - stripe_index = stripe_nr % data_stripes; - stripe_nr /= data_stripes; + io_geom.stripe_index = io_geom.stripe_nr % data_stripes; + io_geom.stripe_nr /= data_stripes; /* We distribute the parity blocks across stripes */ - stripe_index = (stripe_nr + stripe_index) % map->num_stripes; - if (op == BTRFS_MAP_READ && mirror_num < 1) - mirror_num = 1; + 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; } } else { /* @@ -6525,19 +6539,19 @@ 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 */ - stripe_index = stripe_nr % map->num_stripes; - stripe_nr /= map->num_stripes; - mirror_num = stripe_index + 1; + 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; } - if (stripe_index >= map->num_stripes) { + if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, "stripe index math went horribly wrong, got stripe_index=%u, num_stripes=%u", - stripe_index, map->num_stripes); + io_geom.stripe_index, map->num_stripes); ret = -EINVAL; goto out; } - num_alloc_stripes = num_stripes; + num_alloc_stripes = io_geom.num_stripes; if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL && op != BTRFS_MAP_READ) /* @@ -6555,11 +6569,12 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * I/O context structure. */ if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, - mirror_num)) { + io_geom.mirror_num)) { ret = set_io_stripe(fs_info, op, logical, length, smap, map, - stripe_index, stripe_offset, stripe_nr); + io_geom.stripe_index, io_geom.stripe_offset, + io_geom.stripe_nr); if (mirror_num_ret) - *mirror_num_ret = mirror_num; + *mirror_num_ret = io_geom.mirror_num; *bioc_ret = NULL; goto out; } @@ -6579,7 +6594,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * It's still mostly the same as other profiles, just with extra rotation. */ if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK && - (op != BTRFS_MAP_READ || mirror_num > 1)) { + (op != BTRFS_MAP_READ || io_geom.mirror_num > 1)) { /* * For RAID56 @stripe_nr is already the number of full stripes * before us, which is also the rotation value (needs to modulo @@ -6589,12 +6604,13 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * modulo, to reduce one modulo call. */ bioc->full_stripe_logical = map->start + - btrfs_stripe_nr_to_offset(stripe_nr * data_stripes); - for (int i = 0; i < num_stripes; i++) { + btrfs_stripe_nr_to_offset(io_geom.stripe_nr * data_stripes); + for (int i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, &bioc->stripes[i], map, - (i + stripe_nr) % num_stripes, - stripe_offset, stripe_nr); + (i + io_geom.stripe_nr) % io_geom.num_stripes, + io_geom.stripe_offset, + io_geom.stripe_nr); if (ret < 0) break; } @@ -6603,13 +6619,15 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * For all other non-RAID56 profiles, just copy the target * stripe into the bioc. */ - for (i = 0; i < num_stripes; i++) { + for (i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, stripe_index, - stripe_offset, stripe_nr); + &bioc->stripes[i], map, + io_geom.stripe_index, + io_geom.stripe_offset, + io_geom.stripe_nr); if (ret < 0) break; - stripe_index++; + io_geom.stripe_index++; } } @@ -6620,18 +6638,19 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, } if (op != BTRFS_MAP_READ) - max_errors = btrfs_chunk_max_errors(map); + io_geom.max_errors = btrfs_chunk_max_errors(map); if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL && op != BTRFS_MAP_READ) { handle_ops_on_dev_replace(op, bioc, dev_replace, logical, - &num_stripes, &max_errors); + &io_geom.num_stripes, + &io_geom.max_errors); } *bioc_ret = bioc; - bioc->num_stripes = num_stripes; - bioc->max_errors = max_errors; - bioc->mirror_num = mirror_num; + bioc->num_stripes = io_geom.num_stripes; + bioc->max_errors = io_geom.max_errors; + bioc->mirror_num = io_geom.mirror_num; out: if (dev_replace_is_ongoing) { From patchwork Wed Dec 13 14:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824418dys; Wed, 13 Dec 2023 06:43:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbiolQMT6/KHxMMkz5ox39xvRa7+fW54A0jlAPtRmKtGSeojPZczfzSr4YrmXKR0E6XnXU X-Received: by 2002:a05:6870:468c:b0:203:1462:67e6 with SMTP id a12-20020a056870468c00b00203146267e6mr2417639oap.67.1702478606409; Wed, 13 Dec 2023 06:43:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478606; cv=none; d=google.com; s=arc-20160816; b=GjFyCxXzBtntWm3dXKfSeySZaIkYEe0smH/7moZgwTtInfmWKvIx6NQ1nCv3M5NPwn 8ExGjgjJOEjY48DakBF2hF8c8jETDQBGfCgS9RxBEeyaKg6D5mIuM0pz22ldlbWLUZWX P2vlJp8chdh7z8te5Nxj107VIdgW47iEZYk1YJ7kp/vW0MOHvny5KPglfy3n1pKQXF1R KiTMuAzXHff25lCgsFZKuJGcR4zRSJgl/snenldkA8lLYQrzrGYat2qzvPary3He1L02 piRzS2ul6SnzHa0nZsQ/qs/8W//qftLwh4DhSMX4ReiroSHSHxLFPuKV3Fw4CNNCvc5q IrIQ== 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=L9btdijvHzfaMuZ6aNCdVtZJwid4lIEG1ZIfAJe2zjc=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=fnh/kn0bvJBRQw6D4V9hC6f3ECvni+jRMBpfArx7sMUzzQTAmV6a4SP0tg1GRLhQXn tfyymxBbVb799tqi+tK20nN2ojYwREbfMMPj3IxWax3/Krp1fB9+zpV6av3b8wdQ0W3/ 5Wgag3E0bMiS1J0Z7MqEwa+pPCeORP2u86XaOXZpkRfItO4rpHzeVeMcvucdxBdzN8s/ AQfYCrhZmA/LmlvLDKEdJAoq1RgN+V6eGHoktVJhqohoYI3eLyp1aB/ymzOr30YT1Las uwcmGq7Rpz8aBGa4n7Xpn/3ODjgNIRMc+sS7GJWLT/CpwgV7K2bACyjFKzWoom2b9+uO 2WFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=ckNXms9r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l190-20020a6325c7000000b005c219415020si9407334pgl.262.2023.12.13.06.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=ckNXms9r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 65FB18031B2C; Wed, 13 Dec 2023 06:43:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379235AbjLMOnN (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235211AbjLMOnG (ORCPT ); Wed, 13 Dec 2023 09:43:06 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63690E8; Wed, 13 Dec 2023 06:43:11 -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=1702478591; x=1734014591; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=DqGz1rYplJkgJR0SxwKCAVGZlaVGnSqeh82zQn3mpYM=; b=ckNXms9rfHbHwDnRz6oXwqykHduw6xaxeKdEDbv+gix1sMhv0n5HGPHn 4Y0dYVHBgK+FEWtaK2GZtf2Xi7blsPGO7tqVz0BPonqQGwa2XivYkmAFG 7N2Tvm4yYjd9o9TLE+9Jt/2m0gtJgjWCgQmJkP0RzGNyB2lA1S1eh1Rwn 7YIpd+SzlLTQ+A+VYUda1Ial5CPZidsyxXsFVVAHcs/+AKAyfuvo/iEMi bZaE7I9400Btkx+Se9unzpzf3LAjVuD0JGfC5K88Sgb/5gAVQZOxD5do8 j+5t+gkAuCpS3rNmCCEpbAwI91X+TqiyDj4DPDMMRU9D89u8DpeG7LLLU A==; X-CSE-ConnectionGUID: G3elwU++R5S2CLMLHtBxgQ== X-CSE-MsgGUID: 9aZGGctJTzKQeoUe90wQvg== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802950" 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:10 +0800 IronPort-SDR: 0ZLJys326bWtX5l6B2E3V467+WDcPbPFazSB5KndUOnuS2UDE0Vh2GHjNzAPvlfu1N9j2TerD0 ZBgW9JkMlGXw== 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:23 -0800 IronPort-SDR: mH4/02Fv0lKDus5ePvVTMvCY4GcsQCIgXfl0a07nDa7OLM8yWYJN+BahVF5sUpqok9FeqqBFgI HZ7YOqg1H1NQ== 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:10 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:58 -0800 Subject: [PATCH v2 03/13] btrfs: factor out block-mapping for RAID0 MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-3-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=1489; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=DqGz1rYplJkgJR0SxwKCAVGZlaVGnSqeh82zQn3mpYM=; b=xlbEMd1j1Wu9P6eCyo6iBXspLF9f3x7tz0e67tYGzF/xVt1F9OourzYw6O4kTvg138QGFZQWZ ObmXHrFmD1vCbvc33JVGokDB9k2YSuo0Of+JU6nWruJWmgT2YaYcG7X X-Developer-Key: i=johannes.thumshirn@wdc.com; a=ed25519; pk=TGmHKs78FdPi+QhrViEvjKIGwReUGCfa+3LEnGoR2KM= X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178207179967009 X-GMAIL-MSGID: 1785178207179967009 Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID0, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ea830ff0c0e3..1d2e6fb7b9bf 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6363,6 +6363,15 @@ static bool is_single_device_io(struct btrfs_fs_info *fs_info, return true; } +static void map_blocks_raid0(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; + if (io_geom->op == BTRFS_MAP_READ) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6450,10 +6459,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, up_read(&dev_replace->rwsem); if (map->type & BTRFS_BLOCK_GROUP_RAID0) { - io_geom.stripe_index = io_geom.stripe_nr % map->num_stripes; - io_geom.stripe_nr /= map->num_stripes; - if (op == BTRFS_MAP_READ) - io_geom.mirror_num = 1; + map_blocks_raid0(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { if (op != BTRFS_MAP_READ) { io_geom.num_stripes = map->num_stripes; From patchwork Wed Dec 13 14:42:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824554dys; Wed, 13 Dec 2023 06:43:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdeROry1InvlRZd8i4UcEHdZvfDLyN2hhN6NpN3w3sv0meGcWsQHoXSRGQv3qTIIWyeTRm X-Received: by 2002:a05:6a20:66a5:b0:190:a941:798e with SMTP id o37-20020a056a2066a500b00190a941798emr2652371pzh.48.1702478622903; Wed, 13 Dec 2023 06:43:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478622; cv=none; d=google.com; s=arc-20160816; b=aJEeEa7NyITtVSHfzs4hbHmUdRPs/FEr7Vgu8GX6bjkJeWKoVsLATGSHA+ZUAGdXg7 jqu3B5TEY7gVc50Aw8A6nFCaWWV5xCKJkLJUbKTcjYUaef8XT0XwZGT4YYikQUeUl9+J eZf0tmuhfqljrHtqgv+PgUAvh+c8NO+EnIxYoU8IC9qN6RsofSGVVaRK2pPGz7RP9W9V hm3fnmJKCpa0FgGnPygiA0gngTTsA8KgGxBmavAxncxxZPpP9Wjoj34jE/6zUUd85m6Z hhdnv9vW3amQtVr5m4efqKIyDLrGOgK0QCHt1rIraQ2xIaq2mu16urXUxf5HjPXuyM9r pZmA== 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=ktFPvMZEwYarDw1pFTPhyR81JlkFG0Q8+4piYUoYJqY=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=R2vF/EeWXUgw0NWLFL0XYvSYmzL6ZMGl7bEdLqxtd/69gyymrpIvSYQfqk7j0HBX0I S3OkXtzcpTwkNYJQQENDLniJKuVYuY9bHKGBgcP7fGtX761hMvl4phIlX301njZdC/ob uNcHg7+GzObbwf85SB/aUoHmxnM4DGeVpzsEl0mVcIR+xRFjC6ijVzrLMk/FROdUAy9W 6l1t8mpKRb19nN2RkB/Rm88a6PKM7SALpCoKBUMXEZIqW+r/M/paJ3gn2BqvMKCqxq5v e5KRkQD0QWwqkSeEibmtT9liq7gfymjSOyT4uc/sFG54oxJjTUeHhsPfNvK8/WTXmbwo YdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=JyF3WpfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c9-20020a63d509000000b0057d7cff25besi9399522pgg.829.2023.12.13.06.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:43:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=JyF3WpfZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 7C26380B817C; Wed, 13 Dec 2023 06:43:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441920AbjLMOnT (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235222AbjLMOnG (ORCPT ); Wed, 13 Dec 2023 09:43:06 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DE3F3; Wed, 13 Dec 2023 06:43:12 -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=1702478592; x=1734014592; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=DVkLebp/jq2o9nPLKBH36Ylzg4UHswQI1Rt/5sJXbtI=; b=JyF3WpfZFnrGLd2wOOttzdXcI02AKRQR8U+/EnWOg1cmDT4rPVgTh6rL X143AyI587MLYxD9bOdvycJb+V5cqFM2WSO4+kFxxKFu0ykMbw+ucVMkH wwMku8VfyYiY32aX/48l58AsoFUQeMmtecI36uMd2fmAqf7QhGyZUKX7u L4o4lKU8sEE0IsQmTVqht9/v6w61/EC1edntnSA/4GIpgh+tpDglg6S8p r7R6Aj1wrmuCTREv8frceRdf0GpbGOJLLxtYxlpC+tDZ7oxoupgow1xsH Qx9GkJGH8I0ccwtyxMOU7mIvaIUW4wUte9fGyDrRmGOWC5P+QNBvIEZFS g==; X-CSE-ConnectionGUID: OrrUzAxyQDCplnkLgDsnEw== X-CSE-MsgGUID: nKJB3GZCQK6JDRStopihqQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802956" 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:12 +0800 IronPort-SDR: sxwvuniB2EqbXaM9zqPJ0F2Rf9hj9/HuzkLgPrTYHXeONtGeh9ed7LHEZPzY9M4Hfp0huihwwO iw6PoBuTshlA== 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:24 -0800 IronPort-SDR: mBAKFcxwrFzfAj2Vom8gDZqGSIAYT3F+pNQ4WUosCO/psNqVrevXsPYu5WI2NFJ7LO1tX4YCKh JU3dwU9wAMVQ== 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:11 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:42:59 -0800 Subject: [PATCH v2 04/13] btrfs: factor out RAID1 block mapping MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-4-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=2037; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=DVkLebp/jq2o9nPLKBH36Ylzg4UHswQI1Rt/5sJXbtI=; b=1youUuYANsh3hL/Mdb6+hv235E6Q8ipshOVB79p0pzI7PCmvrwARxCxk7rgvYcjGQZwztsVG6 //mH5cnu9pzC/MruV7UKKmV9hCGAOgDFkdz+rCb5omSvb2Gd2TaDiCT 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:35 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178224543889347 X-GMAIL-MSGID: 1785178224543889347 Now that we have a container for the I/O geometry that has all the needed information for the block mappings of RAID1, factor out a helper calculating this information. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1d2e6fb7b9bf..c11fb6db4679 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6372,6 +6372,26 @@ static void map_blocks_raid0(struct btrfs_chunk_map *map, io_geom->mirror_num = 1; } +static void map_blocks_raid1(struct btrfs_fs_info *fs_info, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + bool dev_replace_is_ongoing) +{ + 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->stripe_index = find_live_mirror(fs_info, map, 0, + dev_replace_is_ongoing); + io_geom->mirror_num = io_geom->stripe_index + 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6461,16 +6481,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (map->type & BTRFS_BLOCK_GROUP_RAID0) { map_blocks_raid0(map, &io_geom); } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { - 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.stripe_index = find_live_mirror(fs_info, map, 0, - dev_replace_is_ongoing); - io_geom.mirror_num = io_geom.stripe_index + 1; - } - + 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; 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; 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) { /* From patchwork Wed Dec 13 14:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178057 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824732dys; Wed, 13 Dec 2023 06:44:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbyjVaI2DO+FIXsIuEb867ok93PRe+yWaL+LQM6tFjCmB4OoDKwlOiup/CqimaA24IQZcM X-Received: by 2002:a17:902:ce8b:b0:1cf:fe32:632f with SMTP id f11-20020a170902ce8b00b001cffe32632fmr5288366plg.22.1702478641992; Wed, 13 Dec 2023 06:44:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478641; cv=none; d=google.com; s=arc-20160816; b=fLl4lx09EG2yr1eNTjv0G4cTNzu00PJuBXMrNeGytBeSTx44ei9eJRwd+XvJGHfFSF LJlBbhNfnKWV440uNWQwBSvnrJ8eMVStOROcYlN2UWlvMbyxuMYg95PPeJzE1UoJL0AH dFedd9eI6vBC1H5/R3FXCm5PWksdb+imaKjVQwQNXbC9qvW3hh0VWr+kyAZhJxOIWBP2 991xpUXHaaEuL+rCCUcQY9L7Azn3sYs8bqbyPCxfZy9bdHzgyt24x79h9b1kSRlRSw2o E+MEyX2yF2ZiCtHU7C4OMcEAZot/ceisPnKAsjZrggb+BRLJb4BGtum2uNmy3WEASV5K GOuQ== 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=kJZBh/wzjpPt/HNhraCV9wYL/76mD0b5QzNqkE4RARU=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=VWUvriYIAHDjln+x1wjUfI0T3kHpbetQ4xBD8lCZxjvpRly9B3LscmkH7tuCjNjAdL nz8eEWHbFZixeQhQy1luCM9vHFwkA0vxS6x+W2ayQHgyDAceJQvb2Dc4UAHvHWPWCkqy +u5w2qlUNa7Tpr4qO0DmKM0b3r8gIYhIOkn2TCZxqVGEGNwwd5cZXzyVpfW945XlVlZn 10p67Shtesr65TR+apm4L3Y2DiHgJqY689y6Fji8XmP9AeJguYRrQ8t3zGlgvuDU5+5k ZFPj9P0u1RkGRJvxTCcF4X3VbKmvlMBLJqFhMNfDG/fRbVnu/cNxXmCeN71pJ5Rr5lv4 JlDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=ZQLgZOZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id jw15-20020a170903278f00b001ca96a6eefesi9598631plb.577.2023.12.13.06.44.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:44:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=ZQLgZOZC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 8212380BB1FE; Wed, 13 Dec 2023 06:43:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441900AbjLMOn2 (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:28 -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 S235192AbjLMOnL (ORCPT ); Wed, 13 Dec 2023 09:43:11 -0500 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4594E91; Wed, 13 Dec 2023 06:43:18 -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=1702478598; x=1734014598; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=sLjwrenKmqHBOSqsM1KRhm85HG8IZyehA4bXrtvn4bM=; b=ZQLgZOZC275uLopqeMKgSMzkrMY8CtaqDrt3RU1a9H5cio0PV4VMXVrL H+D8ulphFAWtdoyQ29FON/YxeY2BD9jIKW6MkqdLUwxuts82KOiQSbFv2 KDL2Y4eFuvgXrRZCq5Hw9+f8IPZElgOvD8THCjxVOQ3WS3TpyY8cSySkE vm+UqBtLVvKI3E04m2xN0DEk9jEf9yRgr49y5GwxPmAfCAkq4adpvOpOf SKT8TZap/7uPtN4aYiDpaEtdeIFLv2ezwqbC0L1DvEYEKyFbx5jUCpVYY XL1VqxJpcSbgpLtrJjOyZ7in/Lh65Koq4l3zKmtfDEB1HBTDYkiQd/GGK g==; X-CSE-ConnectionGUID: EkFSIohuSm+ooJQ9K/Wkgw== X-CSE-MsgGUID: jPewL/rvQvi5Xyl14Xds4Q== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4802972" 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:17 +0800 IronPort-SDR: yIkfoK9NMfQ5amNWjB7XCr1Y8+sZR0QjjSpLWtWKGqqujb6rc7nsn96UO5sSk+eg/aXk0q3iTQ c9wfDbRYckTQ== 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:29 -0800 IronPort-SDR: jPwWC4S6kGyM8dieutpeuowuWyiIVgIWCh6TWacQP2GwV9yx/q44p3bdBdHoxkLOd8Fc1bUdHW jdCeE/DcoJsw== 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:15 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:02 -0800 Subject: [PATCH v2 07/13] btrfs: reduce scope of data_stripes in btrfs_map_block MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-7-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=1985; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=sLjwrenKmqHBOSqsM1KRhm85HG8IZyehA4bXrtvn4bM=; b=QCzPri8RzAPG0gQUjoB9ReI3jAolOkhuz/CxGWfC4Z32Nu4ABb2QM8e69FhqOPars7B46FJ2F 0S1GI3+M2PSD6ncphJIeR8ono5Xs/VBqXt7ixv/kwKsS2xRsAZC2ESr 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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:56 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178244436489900 X-GMAIL-MSGID: 1785178244436489900 Reduce the scope of 'data_stripes' in btrfs_map_block(). While the change allone doesn't make too much sense, it helps us factoring out a helper function for the block mapping of RAID56 I/O. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 4c9c130cdfd0..3a6a2f71d364 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6480,7 +6480,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, struct btrfs_chunk_map *map; struct btrfs_io_geometry io_geom = { }; u64 map_offset; - int data_stripes; int i; int ret = 0; int num_copies; @@ -6505,8 +6504,6 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (IS_ERR(map)) return PTR_ERR(map); - data_stripes = nr_data_stripes(map); - map_offset = logical - map->start; io_geom.raid56_full_stripe_start = (u64)-1; max_len = btrfs_max_io_len(map, io_geom.op, map_offset, &io_geom.stripe_nr, @@ -6534,6 +6531,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid10(fs_info, map, &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. @@ -6645,7 +6644,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * modulo, to reduce one modulo call. */ bioc->full_stripe_logical = map->start + - btrfs_stripe_nr_to_offset(io_geom.stripe_nr * data_stripes); + btrfs_stripe_nr_to_offset(io_geom.stripe_nr * + nr_data_stripes(map)); for (int i = 0; i < io_geom.num_stripes; i++) { ret = set_io_stripe(fs_info, op, logical, length, &bioc->stripes[i], map, From patchwork Wed Dec 13 14:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824619dys; Wed, 13 Dec 2023 06:43:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1mzz59JYpMUpLlV5WLPEWVJ4SNME9tbCZTL7HoqVOn1rlckJLfWdnpkhtndI4EYT+SxHm X-Received: by 2002:a17:903:24c:b0:1d0:6ffd:9e1e with SMTP id j12-20020a170903024c00b001d06ffd9e1emr9218704plh.112.1702478630328; 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=jbM4RL1YE73EwcDsl5YLmdNRhhuJqY6kQyBGmpfjs584P19Vma4dToqzX3h5HkvMWc kC/s5UIIOfHD7V7iBQvz/os4BOEKV+N0LsOdhLFsMdNhK6zH/0XNWlxredcG52cMUIcC j8vskU9X2l75C3IaG9DgvCZt8DGi+jWrLEFGQR/TOE8o4DH21q9ccAt3tLCDani3vT+f PSozg4mxb4rceOP0NVGhQZnYjfpGGpu1Dj5eAHe95IEdWKQebvN/VcMXxs0NK7D/wWab i9P3S6Z9XVEKZXmpgwZl7OUIW0XjNHK6jgwhxMWvbv8zMVixGSh66DHifSPqZqfYG169 X1oA== 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=gfuuJ3yBD+NbCw+IIIHqVjdlTulPG6As9vM3RoTucBQ=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=RuWUoeDv4gWGDONNFIA++Hh/1LaZjraUgmG5L5jbh/0SL+Ffi+7CVCHfJ/PB7logyE uZ3BAzAXlsw2UdTTOiQz5JNwmlb/A/ixuKIYfGLaaEFvJHE+/Kx7xNcK4kMvs5xSaDTZ C9YyymvyqgpQltLBZzL8qIFEICMpRSzEyInp6So1f69Bg4hCPZ7IjdeXxh6PZW2hbD6r wn0G9aJh37eyGRvE+ukf9SCKz8+OYUzK0umIRkzaFvbSLUayiZRB2vtZyeYG8ALVdguA Zm3x/A5E15ijNk9fHkHCny8eUIJxE9DpmmNSnrq0C5MJ11+NjRVc33TCLPQ4NxST10xK 2XzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=NyZ3MJKX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z4-20020a170903018400b001d0c5037ef3si9814815plg.336.2023.12.13.06.43.49 (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.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=NyZ3MJKX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 1D468822F8FE; Wed, 13 Dec 2023 06:43:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379337AbjLMOnd (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbjLMOnM (ORCPT ); Wed, 13 Dec 2023 09:43:12 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49121F5; Wed, 13 Dec 2023 06:43:18 -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=1702478598; x=1734014598; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=JrLC6otdJpNPxBMTEGtJC5+A4K6Kf+scnbb6ZiQ1bcM=; b=NyZ3MJKX4ayoKXA81odEQhAGJtDl2WRtko/nXlYOYZNgnsn8a8kTSmr5 sQ/AAaiWJRxM28kUfL0FN2mhaF19XlBgE84yMivXBFuFjQ2vStrkjThI1 0ks+I4NY0+ubVb44GWPV7Q4kQ/Ymh6Wwyy6We0N0HeYM43IR26/kz80HF h1RnOJaqqnhsjwM9cI2RSrd0SVCGy8QiIxzG/ebBDEzj5EuWSmapzQ3Bx Labgvp0Av1Fx8EtPH9YlSJKTQMOnxrLJWbti4b1Dr0rKHFuRfpzJ4xO5F lLmZ+ZyqedBisPDozTlaT4ZPJmLH6YcemQfcA1zGlxxNSJcRGRwQtREKW w==; X-CSE-ConnectionGUID: ModD/G22Tb6H3dDQmnAG1A== X-CSE-MsgGUID: 5pr2wx8QRQiuTuRVW5F4HA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580758" 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: 3QbjBlfbIFqCPWx5EZ1PD3MXbVfd8VGMdibjiHnnmFEpE+HXFuPo4wkxtmQEHK1MwezGsrDhpJ twHPojFYFMAg== 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:29 -0800 IronPort-SDR: 0e2xv/lp+/Uo5Obqqegq+kFah03nY2x0azHvdUub5ucRxjXix6DpwUxJqgW8ttRGFvy6zzpw1Q VfZ7S57gFRcg== 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:16 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:03 -0800 Subject: [PATCH v2 08/13] btrfs: factor out block mapping for RAID5/6 MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-8-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=4380; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=JrLC6otdJpNPxBMTEGtJC5+A4K6Kf+scnbb6ZiQ1bcM=; b=hNSvkQw//aHD+11hnf5wXBYQNAWrLOptg4mI7qL3TM5DCyXRbJDcMiW8sfTJ6Pb36YbGPDOpM NIxB4YdUYWIA1u+Cs+KodZNRjcsa+n+uk6ukNdWS0mTiDlIHqfdFAC9 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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:43:44 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178232127987762 X-GMAIL-MSGID: 1785178232127987762 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 | 96 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3a6a2f71d364..55614a9eb8a5 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6437,6 +6437,56 @@ static void map_blocks_raid10(struct btrfs_fs_info *fs_info, io_geom->mirror_num = io_geom->stripe_index - old_stripe_index + 1; } +static void map_blocks_raid56_write(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom, + u64 logical, u64 *length) +{ + int data_stripes = nr_data_stripes(map); + + /* + * 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; +} + +static void map_blocks_raid56_read(struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) +{ + int data_stripes = nr_data_stripes(map); + + 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 (io_geom->op == BTRFS_MAP_READ && io_geom->mirror_num < 1) + io_geom->mirror_num = 1; +} + /* * Map one logical range to one or more physical ranges. * @@ -6531,48 +6581,10 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_blocks_raid10(fs_info, map, &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; - } + if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) + map_blocks_raid56_write(map, &io_geom, logical, length); + else + map_blocks_raid56_read(map, &io_geom); } else { /* * After this, stripe_nr is the number of stripes on this 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, From patchwork Wed Dec 13 14:43:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178058 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824802dys; Wed, 13 Dec 2023 06:44:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHebklfK0up5f4jEqhdV1lubMgVNOewTyoDFqBojA35B/E9CmDMu9mUw8h4WBqVMybIstR1 X-Received: by 2002:a05:6a20:6596:b0:18f:97c:6174 with SMTP id p22-20020a056a20659600b0018f097c6174mr7368765pzh.113.1702478650366; Wed, 13 Dec 2023 06:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478650; cv=none; d=google.com; s=arc-20160816; b=q3nxEyt1uwiRaGa/oycHPDTFew7p3zTcabVLmYbbWaHuKOBvUYUer5S4WWfIvqsE0w /mH9pNELMeZYiHWw4iFuoUz0HFsYIIvP6s9Lwv46FdsfBcvmAco4ay1K8cH6wGnMN5fj gaW2o2bwZKTe4FSzk1CiR6w95sBlO+FfgHA5RpuL7T9eWJaBARKXdG2lQQSy5SaDuELx cy+PWzW/GHw1G2Yga1EyncjUQSSVNT9qn7aGJ8VX+jrS6F2kNSWZYvsLV1rXzxqyUb/S dlyUSKxvnjWBR861nC/VsbsP0po1zAuPid0RxA8fLKRR6zPxi+85uQfvOXyi7omR0m8I JjOg== 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=67ZyFkS+jDxi+HKwW8L8hjlg9K51QntYqXEda14211w=; fh=WpTkEVtBXkq0RoDrgO3Js2s/6swFB/ddJMCfC4s0b8Q=; b=rupEr9Axc/YS8KhC+qZOiNroynjomkG/skKeO3+Z40uUBRq3cIeHsWQyYViSXjXc0I WS3rfnZXtEV5IcCX7wpwyeKoDhhKZG7rYAFHCrS1w8Y0Zii7QxLUxad0xmidTQZl8hEX m2gjs4J1MZ3CIT2jm1I5HQY7efpzFmOr90cChWoJVA8KHSQu/uLGc+Xr2HmhzTk/y3wJ 5IdWSsVwlHxucNZst9YrGSH9HPUHtbR80UUOhxXGrNqytx0vUr4zrCABDI+8cnrQswn4 q/ovxHL7CrzA8naxQdzvu3f8whyGyKHpZwKyOg7dsI9EsqXe52r152JLqSfED1E9D6XS yTJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YEFxn6+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id bq5-20020a056a02044500b005b938759695si10128684pgb.886.2023.12.13.06.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:44:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YEFxn6+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id D288D819D9F5; Wed, 13 Dec 2023 06:44:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441824AbjLMOno (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:44 -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 S1441822AbjLMOnR (ORCPT ); Wed, 13 Dec 2023 09:43:17 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C26111; Wed, 13 Dec 2023 06:43:22 -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=1702478603; x=1734014603; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=e/guiXA3HBcKLNpRnItMMeCwjZTheHhEwP/jrp5atmY=; b=YEFxn6+6IlKeT0YQC4cpeK0ELg1lr/xsOgW5A3XgKFt09X+KbQfDre3h xVWfQTm+rFqSJ2aVK82dExss7co5KFERtMAECGzPm5K25+HTzIpWeQ/pp 0g2pi890oR/fcoNYUoTHktKX3eoN/iBqMRvapkoiV3sPcKZO7Tu6AztTP B+J2DbjRLSR8OJh7imXZ78Pr4sX8DKRNpckvjFcty0N5vi6wafhP3ZqkE VqvQRPG7gI1nCNxA90Jfn434o/vNV652rADDF/nuXAJG/LpdOmo2NNcWI 0akP7X7C+YR1BWxIeg8WQNSkJWqURufHbCnIhiPOSoU+ApwL3vv8ovO2x w==; X-CSE-ConnectionGUID: 3Rfrop7cQL+I8pt+OZDsgg== X-CSE-MsgGUID: NtmwwGUHSf+D2X5YTBQt0w== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580767" 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:22 +0800 IronPort-SDR: E3ko+KObtmN9TWOk2pjWdNbkx8lZGuD4z2YPFejS1loJAazcKfeP+3OJ0AtdU1lPoeKRM6ci/G VKdnn5BS/XuQ== 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:31 -0800 IronPort-SDR: GdIZ5OuzcBMxPNwuIsC7fpMODao02c7yFLhY+nG/WPXU5q3TmOAJNaJaxsiCANvkOcy6gqcF+c nfFvpZLHs1LA== 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:19 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:05 -0800 Subject: [PATCH v2 10/13] btrfs: btrfs: untagle if else maze in btrfs_map_block MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-10-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, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=2122; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=e/guiXA3HBcKLNpRnItMMeCwjZTheHhEwP/jrp5atmY=; b=4lWlvPgsM4isrIKCCNY0se1/2neTvCtcmnMZFfFbAQn0bacYYcdj2A4V6CHCxVwmCbEM8RHZG jvkhaRP43FxA3v5CAJstrbh3wAgHkxCOhW6ID2+ovZJHFPnZg22Pr1D 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:44:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178252889668079 X-GMAIL-MSGID: 1785178252889668079 Untangle the if-else maze in btrfs_map_block into a switch statement, checking the different block-group profile types and call out into the per-profile block mapping helpers. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e23c7d2842a6..efb31c3005b7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6578,28 +6578,38 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, if (!dev_replace_is_ongoing) up_read(&dev_replace->rwsem); - if (map->type & BTRFS_BLOCK_GROUP_RAID0) { + switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case BTRFS_BLOCK_GROUP_RAID0: map_blocks_raid0(map, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) { + break; + case BTRFS_BLOCK_GROUP_RAID1: + case BTRFS_BLOCK_GROUP_RAID1C3: + case BTRFS_BLOCK_GROUP_RAID1C4: map_blocks_raid1(fs_info, map, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { + break; + case BTRFS_BLOCK_GROUP_DUP: map_blocks_dup(map, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { + break; + case BTRFS_BLOCK_GROUP_RAID10: map_blocks_raid10(fs_info, map, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { + break; + case BTRFS_BLOCK_GROUP_RAID5: + case BTRFS_BLOCK_GROUP_RAID6: if (op != BTRFS_MAP_READ || io_geom.mirror_num > 1) map_blocks_raid56_write(map, &io_geom, logical, length); else map_blocks_raid56_read(map, &io_geom); - } else { + break; + default: /* * After this, stripe_nr is the number of stripes on this * device we have to walk to find the data, and stripe_index is * the number of our device in the stripe array */ map_blocks_single(map, &io_geom); + break; } if (io_geom.stripe_index >= map->num_stripes) { btrfs_crit(fs_info, From patchwork Wed Dec 13 14:43:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178061 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824993dys; Wed, 13 Dec 2023 06:44:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwz+v+KCbh93gAo27Kv1xXDH9bVOmh76GPxmkTGk9do4pG2rrPhs2WE4vzpYWItBjLEvzR X-Received: by 2002:a05:6a20:7488:b0:18f:97c:4f47 with SMTP id p8-20020a056a20748800b0018f097c4f47mr4653930pzd.83.1702478668165; Wed, 13 Dec 2023 06:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478668; cv=none; d=google.com; s=arc-20160816; b=uHpyOu/xriNGL7RBRaqO2cZjiipU1Ddudmhw3MJyGo76j35lfoWmFjnHZpyvVSwUtY 3xazVU4uGl9sWbvEbquHqOTb5zNo654mJjq7Pa0m9FZxqhBtr+vEXY5TkKpJpIwBAHEa 8Z8lsKwIVJk2dKbvj0hmtUfuQcjKPR65LZUEnCsdTPzC+tXGFkGkKPlCMyOfKlXBHOeY bgKdmE+YMNtckWqLIhk110L9oBv9yhl4Rpqa0evcEyETUZ6OW5CrZO4K14MpMyR0AViv cQq+fvtzRd8hI2OTBB8wrdzreTMLFl15ya2JwDiMesPycBgW0kCf0+nf9guoI6o9tq6f FB+Q== 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=XTlD0NZtsv1bet7wV429heQp+3zASiUkz7Q9hg3rWX8=; fh=WpTkEVtBXkq0RoDrgO3Js2s/6swFB/ddJMCfC4s0b8Q=; b=lhO7M6efqdhYJBmv1scKfvkeRF7Po7smE3zU0T/itQcaEtIPrY0BQAvbKg4XQNIXPg EC6bjpWxU0r/ylHFntwPinujNcigDGxTezVN9d2J9JygEfn4Ft6JaiLgrAp+NjILHuin eZfexlMEMWOItJmuO5boa4+ScRtnOWcR2qR7DsbFLbD+7Brerm0gM2ba2Bv5FsUa588M ACH7QUDzpzaPrqaNqOOIztTwRwipocdw35uP2E/zj28NqqQyIL4bBx1r6pBV4plK/eit C69fNkKMbiMNTSy75ER+GtLftr1VKKr1czjj6/FqJkeqbFEw2zsjYthZhVicLgaUsyO8 hxEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hxjbiCxM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y31-20020a056a00181f00b006cd8db77f84si9520340pfa.274.2023.12.13.06.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:44:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=hxjbiCxM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 5A44380403B2; Wed, 13 Dec 2023 06:44:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441992AbjLMOnj (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235414AbjLMOnP (ORCPT ); Wed, 13 Dec 2023 09:43:15 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C7EBE8; Wed, 13 Dec 2023 06:43:21 -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=1702478601; x=1734014601; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=Ah3Vw4nWYJIAnXcNelLMdrcDtyNCiNo5U8kP1u49x0w=; b=hxjbiCxMrofXuH7CTxI7TfIP5cxi9L0pOTEAnPrZAsJGllASRlhk/L0m JaDRB7aZrXlDxSdoZPCPNsJFAqZu7suUXZufRYa/0irtJYKwcH1r0J9yq nhu5Sd2RN3h+TOdZeoboBE4E+Sj0EyRfx5h1BUxkbKyHzB9nJCeNChDR6 kTSvj+wEUiv1KKMHR817bCgfkGQKp/nfhVkHi7TcPuqtW/kFZPjZX3RZw byrak2dIkTnoyA728mbHfq5w5lm9nH8V27tlEtqz0ld4Eh+hYyiU6b4HS RF4JWh9HKf8C3VHfL+1Gr9D+O9r1MGGBb//DzVYFLdtfjps3f/WG65nM+ w==; X-CSE-ConnectionGUID: 6RG5a2QoQbSVfa9bIkD+2Q== X-CSE-MsgGUID: Lp4CYsTAQHC565vYKhi2JA== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580766" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 13 Dec 2023 22:43:21 +0800 IronPort-SDR: hTgQ5HwwCuP+Wz6gDtS3ZsRJvMDAwZbkgHhw2LA2R59wHV9Czqb8OkS5fek++3435UM57mr5t5 KpitkyOWO2FA== 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; 13 Dec 2023 05:54:13 -0800 IronPort-SDR: VvVdq1CnJZr2JfFT6DnT7dtllm1H9tFvlOJzi52jo7n6yXsIW8fPcKV7HRkmW4vRrZOOuGCU4s KFJTrQHrfg4Q== 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:20 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:06 -0800 Subject: [PATCH v2 11/13] btrfs: open code set_io_stripe for RAID56 MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-11-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, Christoph Hellwig , Johannes Thumshirn X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1702478586; l=1394; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=Ah3Vw4nWYJIAnXcNelLMdrcDtyNCiNo5U8kP1u49x0w=; b=JdXIZ2jgKTDsilTL8y0X1wiwgQYzp3eVnaq/e99QhWGLgO4/80TcF+4a8jehziRY38V4XiH9L WWBcyX0g4I1A/YdBXoqzPYZRosQJR4mU5mYMDBe2orIFftkhZkbM4VZ 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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:44:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178271556928114 X-GMAIL-MSGID: 1785178271556928114 Open code set_io_stripe() for RAID56, as it a) uses a different method to calculate the stripe_index and b) doesn't need to go through raid-stripe-tree mapping code. Reviewed-by: Christoph Hellwig Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index efb31c3005b7..5e4885a01796 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6675,13 +6675,16 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, btrfs_stripe_nr_to_offset(io_geom.stripe_nr * nr_data_stripes(map)); for (int i = 0; i < io_geom.num_stripes; i++) { - ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, - (i + io_geom.stripe_nr) % io_geom.num_stripes, - io_geom.stripe_offset, - io_geom.stripe_nr); - if (ret < 0) - break; + struct btrfs_io_stripe *dst = &bioc->stripes[i]; + u32 stripe_index; + + stripe_index = + (i + io_geom.stripe_nr) % io_geom.num_stripes; + dst->dev = map->stripes[stripe_index].dev; + dst->physical = + map->stripes[stripe_index].physical + + io_geom.stripe_offset + + btrfs_stripe_nr_to_offset(io_geom.stripe_nr); } } else { /* From patchwork Wed Dec 13 14:43:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178060 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824896dys; Wed, 13 Dec 2023 06:44:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFu8/MJKRXgwb7TS/4Q9sGoMX+BjOEcT/ZR5cDncHwIEqUmdnOXipUHSHF5JK5U48UceEyO X-Received: by 2002:a17:902:e789:b0:1d0:6ffe:9fb with SMTP id cp9-20020a170902e78900b001d06ffe09fbmr9387195plb.89.1702478659086; Wed, 13 Dec 2023 06:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478659; cv=none; d=google.com; s=arc-20160816; b=Aod4xPoFn7cmL0MW2gRnmpZ42grG8E6+jpesV74b0G5Kq4UXBK2LLNWOn6qwKLlkWU F78GYm/z8q8Ypztc4cTZ37CTcZTF/L+BWVVgWf5z2NKpl1VADnqIOf8SMoEnUFT5OR8Q 6I2PuyBqJSM4YAJo6mZENHyotqcgvd4p5gizLlbSz0j+V5Dj7NOPbSiox0Q9Vb6RZrN6 PLKF5SrpeUlJfN3TNG3TBfautUmVPjvgeybxx86E2afd/M4ngJudmmg43td/OWqBOST/ 1XhaCmpAsQLRubLhFd3SPfSsnokBB55TiU0WdtLir+nnnxOyVTQoMOdGRaGOJLhg9rLd sE0g== 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=V4L8NrS0SJO1ylZM+saVEG4nS9k1qR0uYFS3zpJuyws=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=kE/y0oc3HUX23U/ZHXpINshj0UE41KlwoYgy8WlE29KWn8HQdldMY/nzMIUtwc38AT PvEbeRyJO2AkhK24yZxHhxtH5pduqHZxM4rzHdS6YHrSHqfAj3i3o/coy2r7UdDGENBt m0YeMx0IEpXxZhm9dal2BgEOuUxvz898jbQPLoRneESsukAiFMshMaLvpUgwPTZmWWH/ VU+9wifcbfACTN/WP3v/Zaj3gvDHYR5VX0n4j06kDTSYRS4Ivr4QdVJJnXj5AL1zWJQm 4ArunY2al+GppJfZbyx8hUvfrXmnXxYiuyy8Ax524Uc03PlaxOO4zx/TFlN6WTGFcoCK rimg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kmYLvyMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x3-20020a1709027c0300b001cfd0495291si9587153pll.524.2023.12.13.06.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:44:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kmYLvyMj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 8C6DB8037A34; Wed, 13 Dec 2023 06:44:16 -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 S1442022AbjLMOns (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441823AbjLMOnR (ORCPT ); Wed, 13 Dec 2023 09:43:17 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9365113; Wed, 13 Dec 2023 06:43:22 -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=1702478603; x=1734014603; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=eZt1O9QucdaQ99WccyAeIMWXNVcbEm/Y3+q0saMB1e4=; b=kmYLvyMjHizh3TsdZFSbhXlm77dPnp7ST3LJS+X5GkGe2otFHSVWRYL+ 7eqU/aI7osADAFMyeWZqhliRcddSjsO6ygZ0fxSkJlmH8GO7rxc9Gb/RO FjMp9o8RZROgNn96Al8nFe1QtKl0feUsDIxZiraf2L769r8PbYGmNwaSO 0DWhNKdiatwsCCAOp+WzrA5dKS6wDEmAT5ITjeZmaDm+IU3N/0ADBXfoF qV0sfUJdb3k/TgkPN6xUSgnmAYmeY1XlLzwdVVnw8Z9sPV7oggYUG1J38 LCuDfWozEoBYw35YAxhCUrAit1ffdFVdDcrMkfSVimFR1al8t2uJhZmzn w==; X-CSE-ConnectionGUID: UiNuIYSbTj+0pO70I3pRrw== X-CSE-MsgGUID: s9FO/aUeQkyvOyC0yD1ThQ== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580769" 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:22 +0800 IronPort-SDR: ctGPnXkYGwXbRolnSzBm89i7vg3m3zdNMdvCeF26KmMh2AR9p9+LPa4rDdMT5wdv/UUSlrssbX yx9zFGXMjpAw== 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:34 -0800 IronPort-SDR: n1d5fkQCkaI8Fdxj7iL1ktPusJ8p+V4vkMrytCZTeuAigmV32ihbqQhQ8BM1D9HqUyagPCYDGp NCmBpl3MpoCQ== 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:21 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:07 -0800 Subject: [PATCH v2 12/13] btrfs: pass struct btrfs_io_geometry to set_io_stripe MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-12-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=2892; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=eZt1O9QucdaQ99WccyAeIMWXNVcbEm/Y3+q0saMB1e4=; b=g41Ospujk+QFP0sv8LXM/Gi1HPxraC4KaS5+vr9p2XRrIj+7JcgZIcoTnZd1cpUmQmL0imz3A vWBspq5WS/UC5cvDkzyu03wXNWGML/vtQXAofqiYT/5bC46CRLtmDkj 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]); Wed, 13 Dec 2023 06:44:16 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178262061018721 X-GMAIL-MSGID: 1785178262061018721 Instead of passing three members of 'struct btrfs_io_geometry' into set_io_stripe() pass a pointer to the whole structure and then get the needed members out of btrfs_io_geometry. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5e4885a01796..440ac0c1c907 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6325,19 +6325,22 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, return U64_MAX; } -static int set_io_stripe(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, - u64 logical, u64 *length, struct btrfs_io_stripe *dst, - struct btrfs_chunk_map *map, u32 stripe_index, - u64 stripe_offset, u64 stripe_nr) +static int set_io_stripe(struct btrfs_fs_info *fs_info, u64 logical, + u64 *length, struct btrfs_io_stripe *dst, + struct btrfs_chunk_map *map, + struct btrfs_io_geometry *io_geom) { - dst->dev = map->stripes[stripe_index].dev; + dst->dev = map->stripes[io_geom->stripe_index].dev; - if (op == BTRFS_MAP_READ && btrfs_need_stripe_tree_update(fs_info, map->type)) + if (io_geom->op == BTRFS_MAP_READ && + btrfs_need_stripe_tree_update(fs_info, map->type)) return btrfs_get_raid_extent_offset(fs_info, logical, length, - map->type, stripe_index, dst); + map->type, + io_geom->stripe_index, dst); - dst->physical = map->stripes[stripe_index].physical + - stripe_offset + btrfs_stripe_nr_to_offset(stripe_nr); + dst->physical = map->stripes[io_geom->stripe_index].physical + + io_geom->stripe_offset + + btrfs_stripe_nr_to_offset(io_geom->stripe_nr); return 0; } @@ -6638,9 +6641,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, */ if (is_single_device_io(fs_info, smap, map, num_alloc_stripes, op, io_geom.mirror_num)) { - ret = set_io_stripe(fs_info, op, logical, length, smap, map, - io_geom.stripe_index, io_geom.stripe_offset, - io_geom.stripe_nr); + ret = set_io_stripe(fs_info, logical, length, smap, map, + &io_geom); if (mirror_num_ret) *mirror_num_ret = io_geom.mirror_num; *bioc_ret = NULL; @@ -6692,11 +6694,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, * stripe into the bioc. */ for (i = 0; i < io_geom.num_stripes; i++) { - ret = set_io_stripe(fs_info, op, logical, length, - &bioc->stripes[i], map, - io_geom.stripe_index, - io_geom.stripe_offset, - io_geom.stripe_nr); + ret = set_io_stripe(fs_info, logical, length, + &bioc->stripes[i], map, &io_geom); if (ret < 0) break; io_geom.stripe_index++; From patchwork Wed Dec 13 14:43:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 178059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7824890dys; Wed, 13 Dec 2023 06:44:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWG9XenxjaKCUTBi+7Pfhe29x5+JJ+5gQ8PZO0grFi/kcxECajq8e24RFkP5oAEFxeCe6N X-Received: by 2002:a17:902:cf41:b0:1d0:3fb3:9202 with SMTP id e1-20020a170902cf4100b001d03fb39202mr5690421plg.22.1702478658913; Wed, 13 Dec 2023 06:44:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702478658; cv=none; d=google.com; s=arc-20160816; b=MNPisnnbLZDGoPifbMMoMBsVIspIdfYgZUSTZKjYI7Se9v2uqZ6zPT5ZQx6ABk/fo0 ulWw5SHY23e+wiIc7W1TiJUQeCtN1ZC+mXm5OcTSaGPxW4GtvHYUvSTj3SWoqLNiFWAk GcDZim90zx6AGDHM9k2WY4tagOwHfKc0a1rb1drZJJbLwaItSEMRR0M9aB8n3G4yELh1 xs+xayBNytdAyM11446KjKGKNLmaTedJuDC+Y8eM9l5k6CfpnMT1Q//lN+CtQaqwF3Bb QJ+mYnwyrsedg4YBJC7vKJEWj65TEiwaVijoHekRvqSwDXvWW/0Vs5HUTVoMk+Z5jNK4 NBnA== 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=4jlIbR7HBGDk8RlccyOzXZua2NC5Z+fJ4UX8ZLYizGo=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=J59rWemwLR7L/bGP3lFRB7wM7Q0HqM6fM97oA+HQviA7OjQgmZuXQQK6Lj/L6mSrVZ PzTUqrDUs7k5tVybNPVVl24dOxGYzSAvITMAPqE7ClEauyP+IrbfPQjFLbzd6dGcV7W0 CXIn/MIbcR6OOMUsP7yG+bQXmU6VMiRysbjnvAJuxseUzbiCS7jptyt3STYsEqcYYaFM tqMc4yLcgSdoyh5TYl1bJcczQawXqKtVH2t4vOMNR6OLxkD+zGI9ieouS7Hj4FcYGKaZ 8Fqk0Q15rGPFe2VdYkbEOdGm3dP88MfjtWhfJLKFyncqGIhH72VMfaDwCDlvUkCY20vV Nkmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=p17WjYou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z3-20020a1709028f8300b001d0b2230dbfsi9460963plo.266.2023.12.13.06.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 06:44:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=p17WjYou; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 14CC7819D9FE; Wed, 13 Dec 2023 06:44:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442076AbjLMOnw (ORCPT + 99 others); Wed, 13 Dec 2023 09:43:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441894AbjLMOnR (ORCPT ); Wed, 13 Dec 2023 09:43:17 -0500 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216E4DD; Wed, 13 Dec 2023 06:43:24 -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=1702478604; x=1734014604; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=+TftUUx2tLHphusHbKwAkIsPHhEjw8xGZXfDg5e4VA4=; b=p17WjYouU1pa/eNVZPgTrWjTBzHnz05WyWMmLwwi9giSrIxig+Tn9fiZ wKdAUfJDuauP8S+L6UHW5yxM0L6yaEH8bvKJeDh70McHs5Eee9dOdbH3P /dLnyE7W7Vj9IRSSPBPo6x+enq4mkk6l5iCS2DT/7rUItzq6dvsNczseD Vaa9bvFGZjBYprUORmvc8rndYlBuXUJTnkVElaYFpSsf07tytCELBCsIM FN3cNh5xRDG5/Saaos6hl8SvY0Yo46jic+HCCUz8om6CiisApFLnN3kGr K+ygMXWSHpQpz2Ehv2I7iS0uHF62TgrXO3HenB8NgtyVWddSlqu1e/vBU Q==; X-CSE-ConnectionGUID: nf+DZJhFT1OtkMLl9oEkSA== X-CSE-MsgGUID: Z1/XJVbrRsy7gnBZRYfW/Q== X-IronPort-AV: E=Sophos;i="6.04,272,1695657600"; d="scan'208";a="4580771" 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:23 +0800 IronPort-SDR: zUSHzdLmWTnWUHuSxoV6+WxTQKZgy33EHNmSsTK70enuTJmDB0F7QOy4UcGzEI9K1sstDffQ5c FnRT3Ss7FF+A== 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:35 -0800 IronPort-SDR: 2i3JYJmaowjXk8a9dnNE++rmRUZIdVWsy/NP6EHrCjfPlhv3hf3ObCzWhCPWIdLAgtfL6N8nhW m4+7t5h9m5Zw== 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:22 -0800 From: Johannes Thumshirn Date: Wed, 13 Dec 2023 06:43:08 -0800 Subject: [PATCH v2 13/13] btrfs: pass btrfs_io_geometry into btrfs_max_io_len MIME-Version: 1.0 Message-Id: <20231213-btrfs_map_block-cleanup-v2-13-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=3294; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=+TftUUx2tLHphusHbKwAkIsPHhEjw8xGZXfDg5e4VA4=; b=8Y2fUAr7KwnhLCRKmviEJLcDpFAOVutymltmuVbA1agTg8HC3E24PFd8X0JTUWyVO9qGYEPa7 IfrGUGc+C1eAQ8pSyQn4yfpMQNTqq3ipnA6+6TvCoRKiiNBwVroRyJv 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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 13 Dec 2023 06:44:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785178262227075368 X-GMAIL-MSGID: 1785178262227075368 Instead of passing three individual members of 'struct btrfs_io_geometry' into btrfs_max_io_len(), pass a pointer to btrfs_io_geometry. Signed-off-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 440ac0c1c907..af803b162d0b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6277,17 +6277,16 @@ static void handle_ops_on_dev_replace(enum btrfs_map_op op, bioc->replace_nr_stripes = nr_extra_stripes; } -static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, - u64 offset, u32 *stripe_nr, u64 *stripe_offset, - u64 *full_stripe_start) +static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, u64 offset, + struct btrfs_io_geometry *io_geom) { /* * Stripe_nr is the stripe where this block falls. stripe_offset is * the offset of this block in its stripe. */ - *stripe_offset = offset & BTRFS_STRIPE_LEN_MASK; - *stripe_nr = offset >> BTRFS_STRIPE_LEN_SHIFT; - ASSERT(*stripe_offset < U32_MAX); + io_geom->stripe_offset = offset & BTRFS_STRIPE_LEN_MASK; + io_geom->stripe_nr = offset >> BTRFS_STRIPE_LEN_SHIFT; + ASSERT(io_geom->stripe_offset < U32_MAX); if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) { unsigned long full_stripe_len = @@ -6302,18 +6301,19 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, * to go rounddown(), not round_down(), as nr_data_stripes is * not ensured to be power of 2. */ - *full_stripe_start = - btrfs_stripe_nr_to_offset( - rounddown(*stripe_nr, nr_data_stripes(map))); + io_geom->raid56_full_stripe_start = btrfs_stripe_nr_to_offset( + rounddown(io_geom->stripe_nr, nr_data_stripes(map))); - ASSERT(*full_stripe_start + full_stripe_len > offset); - ASSERT(*full_stripe_start <= offset); + ASSERT(io_geom->raid56_full_stripe_start + full_stripe_len > + offset); + ASSERT(io_geom->raid56_full_stripe_start <= offset); /* * For writes to RAID56, allow to write a full stripe set, but * no straddling of stripe sets. */ - if (op == BTRFS_MAP_WRITE) - return full_stripe_len - (offset - *full_stripe_start); + if (io_geom->op == BTRFS_MAP_WRITE) + return full_stripe_len - + (offset - io_geom->raid56_full_stripe_start); } /* @@ -6321,7 +6321,7 @@ static u64 btrfs_max_io_len(struct btrfs_chunk_map *map, enum btrfs_map_op op, * a single disk). */ if (map->type & BTRFS_BLOCK_GROUP_STRIPE_MASK) - return BTRFS_STRIPE_LEN - *stripe_offset; + return BTRFS_STRIPE_LEN - io_geom->stripe_offset; return U64_MAX; } @@ -6567,9 +6567,7 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, map_offset = logical - map->start; io_geom.raid56_full_stripe_start = (u64)-1; - max_len = btrfs_max_io_len(map, io_geom.op, map_offset, &io_geom.stripe_nr, - &io_geom.stripe_offset, - &io_geom.raid56_full_stripe_start); + max_len = btrfs_max_io_len(map, map_offset, &io_geom); *length = min_t(u64, map->chunk_len - map_offset, max_len); down_read(&dev_replace->rwsem);