Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4720346ioa; Wed, 27 Apr 2022 09:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjxx0JaqAxJ/+rCwH2GCnNS7K0taXwRbem0l5inBbwwZEHVnX5DLZZQcu0LdA1yyet7E9V X-Received: by 2002:a63:610a:0:b0:3c1:570f:122a with SMTP id v10-20020a63610a000000b003c1570f122amr2026436pgb.609.1651077439543; 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=JVW1c0hXIJMHvcnTUsF7SuOVCwZ/HnDwXfHW7ypHCnWig6Is8DQLFATacWJf8vwfOX odRUYPt9uZ17KX2vOH5sIBWYwh7AYb6CC3dGNlrmqEUNZpGkSnDOqqHizFpn1t1qixyQ Lu6riO+KCvwbvpM0fzaqKBjEkisxYi3UuvJ9JBOhNV0146xsAQY8B7oG5DYFNClieybK tqI7+Im0mKeUdwQWAwH8g6XBo8Ss9xbJ7wdx8+twkPEocaBB7SmW+/6ZcfoCHcdB+M+y EmvgJOSzLJCJqSU5MlIvo4kJZWf5+jZM+329b4AvBOCNTuWpMpQYsfZcfdVRReOCs0nf ZwOg== 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=6yQzfClVhDZ6n4jKfgnEonLdHdedN/dO+ui2CUTxKaw=; b=dATAKTIHQVbQFtQUXjKIzSnbEBlrh0ByIuXmDGD6hNS8V5AwLDckjgvucHcDihkViB R42v/G+IUBEJsGXyLLBN+RQ6AYSPu+aAteoQ4OTi5t7fUTa/FFpcZDGR4WN2t+dT32Bx E3J2hVP15EaTuqgWSdbakhNZ2k6XkaePFAKNdKhNOulZ9h7NH4g4FIhEXkVrgK8wA8cf 9WpuFxmmBexqqowuyuqW2G6DckgP6T9FBKHQiarSbHbIN8NsP9xCosNdhxd4Y44I5pps sIU4onvw3EypaKmr/t1ETg2RECnENDjJnXhKqKqE6Cb6MO1viOf8/RbLuWt9kotLIiTn rpJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="cKE+vL/O"; 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 b16-20020a170903229000b0015ce3e35354si2242867plh.90.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: 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="cKE+vL/O"; 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99FFD48B8AC; Wed, 27 Apr 2022 09:07:02 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241825AbiD0QII (ORCPT + 99 others); Wed, 27 Apr 2022 12:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241610AbiD0QHE (ORCPT ); Wed, 27 Apr 2022 12:07:04 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1236B3D2807 for ; Wed, 27 Apr 2022 09:03:14 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220427160306euoutp021b0ccc26e7bb4c41f7111c8f05912546~pzFEN0p3R1616716167euoutp02F for ; Wed, 27 Apr 2022 16:03:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220427160306euoutp021b0ccc26e7bb4c41f7111c8f05912546~pzFEN0p3R1616716167euoutp02F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651075386; bh=6yQzfClVhDZ6n4jKfgnEonLdHdedN/dO+ui2CUTxKaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cKE+vL/OPgHNA5HyEuoppvKdFOS+gwWs/XPu9wKdHeQVDpM9bVGUGuGH4Cz1Ot2nV mwZW75NlBDHpbmp3EMaq6ci6eCl8znZzFGLCjeqC8bf+AzrosLVKEJGzyhJO56tHro xWC6wXNFsIlB0LEPDkuJgM7n+T08AdvuEPooYFV8= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220427160305eucas1p23f1ca6b3cc5d07b7197b62455d839133~pzFCtQUuI1589415894eucas1p2K; Wed, 27 Apr 2022 16:03:05 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 7B.D7.10009.93969626; Wed, 27 Apr 2022 17:03:05 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220427160304eucas1p1a0080df82f76c39882c4298c3c3d99fd~pzFCRIwGd2685626856eucas1p1p; Wed, 27 Apr 2022 16:03:04 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220427160304eusmtrp21dbea116401f4753609014b6527a5210~pzFCQGpO42598325983eusmtrp2o; Wed, 27 Apr 2022 16:03:04 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-7f-626969390a70 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C6.81.09522.83969626; Wed, 27 Apr 2022 17:03:04 +0100 (BST) Received: from localhost (unknown [106.210.248.162]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220427160304eusmtip21ef5128fdd0e92e860a902eb43177b8d~pzFB5d6OL3126231262eusmtip26; Wed, 27 Apr 2022 16:03:04 +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 08/16] btrfs: zoned: add generic btrfs helpers for zoned devices Date: Wed, 27 Apr 2022 18:02:47 +0200 Message-Id: <20220427160255.300418-9-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: H4sIAAAAAAAAA01Se0xbZRzNd+/t7aWx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eWpGanphakFsH0MXFwSjUwbXh0sFYx ffez0B6x6u98avHVshcbxYx9PuuKqC2oyAzgu+CwtoUpebr1lrPqWgqLljxszKicc6BGQ13I 6evUJ+ebNSwcVrf4uN4X2H9p0b79p9z1jxvH3u/mepvZFyL1epHRTbW0Za4/4t5/vhSaYfbe Nv/OIaHcQy/5yxZ8X/bHpEG2/YBd47UCT6FTu35+ccguYrMy7AvSi0xYfvGwTtrMxss3rzr+ fb/IzDvo9PeqkBVWQo8tRKNua6l/rP7w3DF31qFTMVd5171Zv+Y374rm8BKVtJ2Xjq9u9Yj8 yrfkL4+Dq8uUw98/2STONzv8qsZ57wfTRxHFkjMF416p3f6VVTG7S19jdfC2JWpySizFGYmG WsxFxYkABPmx3bEDAAA= X-CMS-MailID: 20220427160304eucas1p1a0080df82f76c39882c4298c3c3d99fd X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220427160304eucas1p1a0080df82f76c39882c4298c3c3d99fd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220427160304eucas1p1a0080df82f76c39882c4298c3c3d99fd 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 Add helpers to calculate alignment, round up and round down for zoned devices. These helpers encapsulates the necessary handling for power_of_2 and non-power_of_2 zone sizes. Optimized calculations are performed for zone sizes that are power_of_2 with log and shifts. btrfs_zoned_is_aligned() is added instead of reusing bdev_zone_aligned() helper is due to some use cases in btrfs where zone alignment is checked before having access to the underlying block device such as in this function: btrfs_load_block_group_zone_info(). Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/btrfs/zoned.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 49317524e9a6..b9c435961361 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -9,6 +9,7 @@ #include "disk-io.h" #include "block-group.h" #include "btrfs_inode.h" +#include "misc.h" /* * Block groups with more than this value (percents) of unusable space will be @@ -34,6 +35,33 @@ struct btrfs_zoned_device_info { u32 sb_zone_location[BTRFS_SUPER_MIRROR_MAX]; }; +static inline bool btrfs_zoned_is_aligned(u64 pos, u64 zone_size) +{ + u64 remainder = 0; + + if (is_power_of_two_u64(zone_size)) + return IS_ALIGNED(pos, zone_size); + + div64_u64_rem(pos, zone_size, &remainder); + return remainder == 0; +} + +static inline u64 btrfs_zoned_roundup(u64 pos, u64 zone_size) +{ + if (is_power_of_two_u64(zone_size)) + return ALIGN(pos, zone_size); + + return roundup(pos, zone_size); +} + +static inline u64 btrfs_zoned_rounddown(u64 pos, u64 zone_size) +{ + if (is_power_of_two_u64(zone_size)) + return round_down(pos, zone_size); + + return rounddown(pos, zone_size); +} + #ifdef CONFIG_BLK_DEV_ZONED int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone); -- 2.25.1