Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4784412iob; Mon, 9 May 2022 01:18:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDMtn9Ynpok7CNrzN9BMkTkPb+Un1o5NzguHcu10qisEQAzZWtuRSsH6jPeu5Cx/5EnP60 X-Received: by 2002:a17:902:e851:b0:15e:d129:fb20 with SMTP id t17-20020a170902e85100b0015ed129fb20mr14861839plg.140.1652084296356; Mon, 09 May 2022 01:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652084296; cv=none; d=google.com; s=arc-20160816; b=eFWDXeWhfS6zIUFfbWZEqoY5nVy+v6eO9Gd5nToz3+PTEqFRPYgoCIjCOqOxQYC8a5 tc7GPzoNLvP0tP5gPB9aRfR8AjDQImecg1atkCzodG/9jOVOxmyyunsmXBgiDv+JSzjr zqwVVOksUg862waTchV0cFaAkZqZ4bqgCezrXbrJOLijwk3lW3jJ4p4iCeeX+10zq9ZZ eG7K2QnQei37KjeuUXgo/gI3tN5XhpJAMa0wr90qck3GC//x1uREMmvXHcNuXLC0gli1 jSKgrMWdzlMVx4WJgjxlaTEco3TbEzD1mv9BRC3tYy8/msPSAQ24OXxb+hnWRjyDiB69 rttA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=LMzILViEYGl7DXa37dpeTA+tqVrqwK5EcVpc6Ix2yY8=; b=vL6ZgwOuDKq9BVWFUn52O1Nyzn9C0f8CGRk+HM547qH4QWcg2z0nQlJTUKF66C+SZ2 lNh30U4wjHBOa0dOmYeFZIgwlWpVUePWZPMetlD4rPRbgaDZ/QgfOkkl6UKSU2DTzW7+ 6qDVAGz18z8m6A/hiETEnsZqRkbALnK9ii9ErqMrPotnEQDBACdVl1mRPpSnP3/ORt7K h7AtO3qkRlfQiyC0M2PfRXNpnE+2YtzzRc/Kwqc9rV1Hm4dUyc9EAN0/QjVH/9cq2XTV HbUTMeCj4s0Dete7LQzN9L98/RpYC15FJqf3XDt1ooFJxtrghDeIVWOuRaJDLUbL/1CA ESlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=obP4nF7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s13-20020a17090302cd00b0015870834b16si10694005plk.549.2022.05.09.01.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 01:18:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=obP4nF7c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BECEBFD347; Mon, 9 May 2022 01:06:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389978AbiEFIQU (ORCPT + 99 others); Fri, 6 May 2022 04:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389870AbiEFIPH (ORCPT ); Fri, 6 May 2022 04:15:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EF0B67D3E for ; Fri, 6 May 2022 01:11:19 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220506081115euoutp01016705f980bb24d791d90c1cbde8f587~sdcpLfnUJ2306323063euoutp01L for ; Fri, 6 May 2022 08:11:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220506081115euoutp01016705f980bb24d791d90c1cbde8f587~sdcpLfnUJ2306323063euoutp01L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651824675; bh=LMzILViEYGl7DXa37dpeTA+tqVrqwK5EcVpc6Ix2yY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obP4nF7chR4bizNpPP4tT3YwhWmITRtJcuxwOUr1oUk/UX96RZoauA4G8l4G0zeIg mC049hre2KQPq/WQ4sKYBy3KQLdG6UMHBMbsAvfwBFJfyfAozDaHXrKVPhFp/nnKGK mtmkm7jfAOQY1orlMwE7h4KflOFV9GruFyN1sjTs= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220506081113eucas1p2f26a6d8f18f7cbb7ff59652198904281~sdcneF8rQ1186311863eucas1p2N; Fri, 6 May 2022 08:11:13 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id C3.17.10009.128D4726; Fri, 6 May 2022 09:11:13 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505~sdcm-zlTq0616806168eucas1p2r; Fri, 6 May 2022 08:11:12 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220506081112eusmtrp1cb2b5b25d973a47abc875150c38a6a35~sdcm_v8_A3089330893eusmtrp1R; Fri, 6 May 2022 08:11:12 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-96-6274d8216386 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id F4.F9.09404.028D4726; Fri, 6 May 2022 09:11:12 +0100 (BST) Received: from localhost (unknown [106.210.248.174]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220506081112eusmtip29939a1aabce6a042ae1abb239d666502~sdcmlVHIw2136621366eusmtip2V; Fri, 6 May 2022 08:11:12 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, hare@suse.de, dsterba@suse.com, axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, snitzer@kernel.org Cc: Chris Mason , Josef Bacik , bvanassche@acm.org, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, Jens Axboe , gost.dev@samsung.com, jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, Naohiro Aota , linux-kernel@vger.kernel.org, Johannes Thumshirn , Sagi Grimberg , Alasdair Kergon , linux-block@vger.kernel.org, Chaitanya Kulkarni , Keith Busch , linux-btrfs@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v3 06/11] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Date: Fri, 6 May 2022 10:11:00 +0200 Message-Id: <20220506081105.29134-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506081105.29134-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0xTZxjG9/Wcnh6aQQ4twjdhMTbIImQgbMm+ObeBmuwElylLlmW6TSuc IVlB08u8sMReWGlBoJSAU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8am+T+b/nthqoLU87bHUqT1OtSxc wufWGRsUy33KY4g/UZZeqNU1wS7I0rx99mHnz9KyF1r2VG/o+uJ/JNvn1rkyj+TEQ3uYns7O e3TwjEJKdsVMz9RnIZOt5vWWBzVfWi50Sq0mOvRtndrlmTziddzvw31l/n4LuVMR/PvaLfFr AV0vnB9NK2Oa6r908aLU8/H7Eq8meIuwXbt+s8nG7GrTm5LrPAH3f3WXHGZWm5XZdmrKhOlF k5aa5O+YFCNZIPzSYrsUw+ovj9y5HXRWuZ7j3X1la5bOjbf3fjfG9Sf67unRFTx9obReiaU4 I9FQi7moOBEAETYNDLMDAAA= X-CMS-MailID: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220506081112eucas1p2f6116cb713749c259a6da533df9c2505 References: <20220506081105.29134-1-p.raghav@samsung.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make the calculation in sb_zone_number function to be generic and work for both power-of-2 and non power-of-2 zone sizes. The function signature has been modified to take block device and mirror as input as this function is only invoked from callers that have access to the block device. This enables to use the generic bdev_zone_no function provided by the block layer to calculate the zone number. Even though division is used to calculate the zone index for non power-of-2 zone sizes, this function will not be used in the fast path as the sb_zone_location cache is used for the superblock zone location. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index e8c7cebb2..5be2ef7bb 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -34,9 +34,6 @@ #define BTRFS_SB_LOG_FIRST_OFFSET (512ULL * SZ_1G) #define BTRFS_SB_LOG_SECOND_OFFSET (4096ULL * SZ_1G) -#define BTRFS_SB_LOG_FIRST_SHIFT const_ilog2(BTRFS_SB_LOG_FIRST_OFFSET) -#define BTRFS_SB_LOG_SECOND_SHIFT const_ilog2(BTRFS_SB_LOG_SECOND_OFFSET) - /* Number of superblock log zones */ #define BTRFS_NR_SB_LOG_ZONES 2 @@ -153,15 +150,23 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones, /* * Get the first zone number of the superblock mirror */ -static inline u32 sb_zone_number(int shift, int mirror) +static inline u32 sb_zone_number(struct block_device *bdev, int mirror) { u64 zone; ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); switch (mirror) { - case 0: zone = 0; break; - case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; - case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + case 0: + zone = 0; + break; + case 1: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_FIRST_OFFSET >> SECTOR_SHIFT); + break; + case 2: + zone = bdev_zone_no(bdev, + BTRFS_SB_LOG_SECOND_OFFSET >> SECTOR_SHIFT); + break; } ASSERT(zone <= U32_MAX); @@ -514,7 +519,7 @@ int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache) /* Cache the sb zone number */ for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; ++i) { zone_info->sb_zone_location[i] = - sb_zone_number(zone_info->zone_size_shift, i); + sb_zone_number(bdev, i); } /* Validate superblock log */ nr_zones = BTRFS_NR_SB_LOG_ZONES; @@ -839,7 +844,7 @@ int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw, nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; @@ -963,7 +968,7 @@ int btrfs_reset_sb_log_zones(struct block_device *bdev, int mirror) nr_sectors = bdev_nr_sectors(bdev); nr_zones = nr_sectors >> zone_sectors_shift; - sb_zone = sb_zone_number(zone_sectors_shift + SECTOR_SHIFT, mirror); + sb_zone = sb_zone_number(bdev, mirror); if (sb_zone + 1 >= nr_zones) return -ENOENT; -- 2.25.1