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)