Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4720347ioa; Wed, 27 Apr 2022 09:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiwdv0vbQKNNSfJZ4hzhqQ4QxzUNEhojY5nhSSiWQtiQonUNsuFR3jHAZULDR3TTxKifT1 X-Received: by 2002:a63:2486:0:b0:3ab:84c3:864a with SMTP id k128-20020a632486000000b003ab84c3864amr8950629pgk.358.1651077439583; Wed, 27 Apr 2022 09:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651077439; cv=none; d=google.com; s=arc-20160816; b=IAvYgPQPn1z1vY80p9oztXsDofZ2i6fihN/NaYdj6z1tXZuD1gAYvAeaQyromAyp9O POA/xz5M8ps/lT4Zafvn4HTrMK7YDBtOuflY1AendsJ1Ed2KiLflK0amAz3fHStxOc/x 2er03kVDvaAAIy4dSXPIDLSAxiiSCkJ+UCL7UNfP7xtNoe+1ygwnnj0GG0sTi7jJRbKI 6CQseM5Z3mlbBH9OLcgWIDzMMx4vtup5R/G4bpv2cE7zUC+0jum/k1Z7MnkGOMx481IZ 8L9t2Ns5G/SNCsUaya21CtYNEWWMlzvjscGE6/BPte7K82/+/YLYlin3896zW1gMcjNV SnUg== 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=ffM16ryPWJ6fYXTfy7LXC81hPnUdkDXlmIiQv6XuFeE=; b=xgy/+XWc97uD7RiZVvw8VfEP+ETbDOzGaHZDw/MZbqQ6m9MUbPbuLeMxBgO+25dZUu +eiTR4t+ObL/VJTlm4emCDN/0gXjTo/WaNf/mlwEg+fj7is3rs1+5wfu82gAVJxl5fjh LaLcZ7PEfTedqw9yfO/9x0/hx2kaN2/efw2wXdtH+S4bz8uyW7Idof+Bf4+yUm7BGkfJ jwtbrbobj9EjmYu3UESS5Q7dm2MjOFXdjKYDugtwtuAU5HkFoW4Yj5lntiivDCzrqVeW loEvjRhlgOUdiGsKbXUIX4y2hRui0nsyS2nB5PJ9F3JpJrFxtTdWI5F8ZyLTuAE3MwpD 7MSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=czoz1DZU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id m12-20020a170902db0c00b00156b0dd99b6si2151170plx.221.2022.04.27.09.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:37:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=czoz1DZU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1D5D33886; Wed, 27 Apr 2022 09:06:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241610AbiD0QIM (ORCPT + 99 others); Wed, 27 Apr 2022 12:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241578AbiD0QG4 (ORCPT ); Wed, 27 Apr 2022 12:06:56 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC7353D1BF9 for ; Wed, 27 Apr 2022 09:03:14 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220427160308euoutp02b0a58ed022b9483d48a36fa3d01c47c1~pzFFZp7J01060710607euoutp02Z for ; Wed, 27 Apr 2022 16:03:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220427160308euoutp02b0a58ed022b9483d48a36fa3d01c47c1~pzFFZp7J01060710607euoutp02Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651075388; bh=ffM16ryPWJ6fYXTfy7LXC81hPnUdkDXlmIiQv6XuFeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=czoz1DZUIJLQgdra6izfn4a61lOGG0j0S0wfOzB8x8exfU2X28fKGL4qHJ39d5VY+ WUWf6Ztcs04m1E8JqK34dwgeFD3FR5hg2Gn9H9P3VqQgSn+f+UY+tgMYC/+lovSBtC XAT+CPidHuIqFVx2zfla6R15Zl23cUuwQEDlt4o8= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220427160306eucas1p2e570e1b4e34a5067bb507ed05d2d73a6~pzFDvZ7kA0627806278eucas1p29; Wed, 27 Apr 2022 16:03:06 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 5A.0A.10260.A3969626; Wed, 27 Apr 2022 17:03:06 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220427160305eucas1p26831c19df0b2097e42209edcf73526b7~pzFDM2UI22337723377eucas1p2c; Wed, 27 Apr 2022 16:03:05 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220427160305eusmtrp1235314abc78e18282c5dc2e5777199f2~pzFDL4Ere2077420774eusmtrp1T; Wed, 27 Apr 2022 16:03:05 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-92-6269693aae9b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 13.A7.09404.93969626; Wed, 27 Apr 2022 17:03:05 +0100 (BST) Received: from localhost (unknown [106.210.248.162]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220427160305eusmtip22f05675131d051368efed5b5a469ebf6~pzFC4wzQ40262002620eusmtip2Q; Wed, 27 Apr 2022 16:03:05 +0000 (GMT) From: Pankaj Raghav To: jaegeuk@kernel.org, axboe@kernel.dk, snitzer@kernel.org, hch@lst.de, mcgrof@kernel.org, naohiro.aota@wdc.com, sagi@grimberg.me, damien.lemoal@opensource.wdc.com, dsterba@suse.com, johannes.thumshirn@wdc.com Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, clm@fb.com, gost.dev@samsung.com, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, josef@toxicpanda.com, jonathan.derrick@linux.dev, agk@redhat.com, kbusch@kernel.org, kch@nvidia.com, linux-nvme@lists.infradead.org, dm-devel@redhat.com, bvanassche@acm.org, jiangbo.365@bytedance.com, linux-fsdevel@vger.kernel.org, matias.bjorling@wdc.com, linux-block@vger.kernel.org, Pankaj Raghav Subject: [PATCH 09/16] btrfs: zoned: Make sb_zone_number function non power of 2 compatible Date: Wed, 27 Apr 2022 18:02:48 +0200 Message-Id: <20220427160255.300418-10-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220427160255.300418-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Se0x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ZK4nzehZ0JAoJpCeWpGanphakFsH0MXFwSjUwSeoz9Aau c5v8yPPef/mGLUcSK5P+ZIqqOZWK3bvHsspW/llBw4I/NU99v5rwSnCbvDs9UV4ibv1S1RY+ 0QuzAmcu+rxcbfJKpbAjr1dFPnF0/e/3KGt67q6Lh6ed1o7PbfBsu6UcGCr/57r8tDk9ftfU 05LtZqixcLE8ZeAx5p3ztszaP27ijf3Ce701NbNVH+WcnCBwumHJvebD5cd7Za+rRe94yyZ5 Jef8T+F0+2rR3Kkq/y6fPnlZe5OMUd6yB3t5up4mFNhO6l9Zp2K3iFmj+qXcFRVdZom5qrf0 FWX3MEgtv/4j1/cEv/n5Q6mMd8w7T7CyH+XpuzUpTcxTtWwlx8xUEZ6pk6r3rZyhxFKckWio xVxUnAgAjuFRN7IDAAA= X-CMS-MailID: 20220427160305eucas1p26831c19df0b2097e42209edcf73526b7 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220427160305eucas1p26831c19df0b2097e42209edcf73526b7 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220427160305eucas1p26831c19df0b2097e42209edcf73526b7 References: <20220427160255.300418-1-p.raghav@samsung.com> X-Spam-Status: No, score=-2.5 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 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 6f76942d0ea5..8f574a474420 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); @@ -515,7 +520,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; @@ -840,7 +845,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; @@ -964,7 +969,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