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