From patchwork Tue Dec 12 12:38: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: 177328 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7692652vqy; Tue, 12 Dec 2023 04:39:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFH7xR2rEwHFDrWQomm5JAPVTeoHwJkeDTLgwLm+xgnLgAzxXb0GqwyIdgWG5Tegr7UH64B X-Received: by 2002:a17:903:2307:b0:1d0:6ffd:610d with SMTP id d7-20020a170903230700b001d06ffd610dmr7422897plh.47.1702384777956; Tue, 12 Dec 2023 04:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702384777; cv=none; d=google.com; s=arc-20160816; b=NuxBrdFoA5Q79SqZKM4RfFkNKGaWFeWfTJ0HC1pdDOYAQAVmbjik/ZJDZNpyMNz8ex +pjqCL2tZzC4b9Dzvi62JhqiIZ0oqdUwUm7WqxOvHX3EwjwVg1LNU/+NFENUbRr8fQ// AaNmoxVh4f14ATLQNvpU+8UoXzRUGzYff8BQWaXoDbJpJDmrk10AISiHaYXc9BB5rOg9 Cvg2dvsI+PX2oQuYRVMgySyZ8cw00ooH8sZeYwLv8LRpLjDWvISCZ4CefJ/8vpDTnUYw 3ToCXQhEp7DAQUZlCzDzac90k2SzMzEXRTxXH3nTldknG4PxACnwtr51qrAMeQ1Dca8y STcg== 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=vn6TiKbPMkLigIc+EBWHQjyfFVwtyPhlweVeE09Mq50=; fh=RkzPy8j9Bgyvxc5aNhoOEUjthII6WQwvTfVAiEIVvUg=; b=qg8HBSImVhh5Jsh9/7p6Qhkztmx6+W52/RBOMcLMHYPLjUib0vSnt13nYCc8SSMxOu 9XgydYCxVh2w43Y+E1UjSXrPQj4HW7CKlxYsaP9vTRAFJQiOMijehNvtocydO4qqGr35 8gBh8b8ExPXEHFPFfHyL5cKwfjLxeJki4Bo2JxaM3gw2jl1KjTQXZh1yevrICerLzCkt yo6wpjQv6wg6FcUU8wRmaXDk6Dzj/K2pdwpGbmVBnG0XAqG+idI/uudSj/ov7xXky1JE OE6X23qPLRHPXsPY1UzowzHBKDBs6a45Wq5t5m1z1lwU7mZdRhv33GP/FgljwBrts6eT /mOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kzVTsrVV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id ja12-20020a170902efcc00b001cff3cae848si7722391plb.37.2023.12.12.04.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kzVTsrVV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 BBD518027B7D; Tue, 12 Dec 2023 04:39:32 -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 S1346775AbjLLMi7 (ORCPT + 99 others); Tue, 12 Dec 2023 07:38:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346710AbjLLMih (ORCPT ); Tue, 12 Dec 2023 07:38:37 -0500 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB3B1AA; Tue, 12 Dec 2023 04:38:36 -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=1702384716; x=1733920716; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=5N+ew4xV5T7Bg5xRXq4tOKGJ+cFKuS/hdyWQo9PfRK4=; b=kzVTsrVVVOLBT6ujfGKRWLb04CHbFyjyrAhuXjr6D4VQywpuIZUJmXMu OuzAKPEbCGB32iKy/sXP3ec3hm+LwQLrEt6P3Akc7Xu3DfSVZs4pJBzAE 1UHdZ/gFdEkhcyKBmWK0K9ebz9ESr4bTpCpuI9DVW9Z2WjgwWTsOWKYaT AmV7jDtbsXJN8vuuk5ig3j/V63bjKOMKyyvIb5ylt7GoNaAekbA8xYnBl 8bIORoYdzPS76tNvBYA9JF9n1k0JPct7yK9YEnKZtDHRpD9YPsE/JS2iP iL10A+KowFJmP6fzWouBH8XvK1q9RnFfVeGTcfGR/Vd8c3ruOpGsqUuO+ Q==; X-CSE-ConnectionGUID: uVLj9uwRRq2AUSArnRqE7Q== X-CSE-MsgGUID: Kw0t9OlYQUaISAH1jqUHgA== X-IronPort-AV: E=Sophos;i="6.04,270,1695657600"; d="scan'208";a="4629803" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Dec 2023 20:38:26 +0800 IronPort-SDR: vKkvRlQYyDxiFmPXH4dqCmG/4MPVnkwrK5fSUR/1TpDtDXTRpOuF3C1F4muK2CCgzDTmMBzm7u A8lZs6UINL3Q== 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; 12 Dec 2023 03:43:40 -0800 IronPort-SDR: 437019ZkLS5lVX+ILTYrOyq/+MvQ1iB1fXqdv7sacM5yvroTKC9tetv5GjVreidiR/1ZJNVY8B TeusU574/icA== WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Dec 2023 04:38:26 -0800 From: Johannes Thumshirn Date: Tue, 12 Dec 2023 04:38:08 -0800 Subject: [PATCH 10/13] btrfs: untagle if else maze in btrfs_map_block MIME-Version: 1.0 Message-Id: <20231212-btrfs_map_block-cleanup-v1-10-b2d954d9a55b@wdc.com> References: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@wdc.com> In-Reply-To: <20231212-btrfs_map_block-cleanup-v1-0-b2d954d9a55b@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=1702384691; l=1978; i=johannes.thumshirn@wdc.com; s=20230613; h=from:subject:message-id; bh=5N+ew4xV5T7Bg5xRXq4tOKGJ+cFKuS/hdyWQo9PfRK4=; b=2kMp398nU9E3QkdK1U8I9QCQXm14Ml+zCql16ykYKhLoWPS+u2gLznbChrXeRk1aLFZxP4NCc aCqY/yRLCYRDOrga34Pjc3zOZYRBhwtjHvtfF4KMjTjUbu2yf3xA+EY 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]); Tue, 12 Dec 2023 04:39:33 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785079821176020277 X-GMAIL-MSGID: 1785079821176020277 Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- fs/btrfs/volumes.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e7bd3a25c516..946333c8c331 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6574,26 +6574,38 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, io_geom.num_stripes = 1; io_geom.stripe_index = 0; io_geom.mirror_num = (mirror_num_ret ? *mirror_num_ret : 0); - if (map->type & BTRFS_BLOCK_GROUP_RAID0) { + + switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + case BTRFS_BLOCK_GROUP_RAID0: map_blocks_for_raid0(map, op, &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_for_raid1(fs_info, map, op, &io_geom, dev_replace_is_ongoing); - } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { + break; + case BTRFS_BLOCK_GROUP_DUP: map_blocks_for_dup(map, op, &io_geom); - } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { + break; + case BTRFS_BLOCK_GROUP_RAID10: map_blocks_for_raid10(fs_info, map, op, &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: map_blocks_for_raid56(map, op, &io_geom, logical, length); - } 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_for_single(map, &io_geom); + break; } + 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",