Message ID | 20230106083317.93938-3-p.raghav@samsung.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp713757wrt; Fri, 6 Jan 2023 00:37:26 -0800 (PST) X-Google-Smtp-Source: AMrXdXtJFz3lbEaQCZLyQUsTkpAwcMhgMlNgKUkONSwfNIBJWQq7PoAx6cy5eYMvFT6+0NOAv3cY X-Received: by 2002:a17:906:d939:b0:84d:17af:2fee with SMTP id rn25-20020a170906d93900b0084d17af2feemr1980301ejb.50.1672994246553; Fri, 06 Jan 2023 00:37:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672994246; cv=none; d=google.com; s=arc-20160816; b=kElcUg5kICgRHMv3twYzFvT6FF0fB20v2sv8AkO/YdAe7JOIK5p/jHpoLn5TFi1Ui7 WWWwTSSObuIjT2Lxb6tFMHLYFzRBkK5dV9bABrY0B73XHVzJ6cH2UXAbVwxYgL0krIHB Ls1COjb68DS6h3JPEEkCHoB3fb178lrWX2bLpSI8f5kC5rSk9F4gpPt/TvlawVP51FuD c51pvjn47Qat7gVngj/1IzFWFWldmlQ4xG32eDRffmSCi2ejWL5xT1Lwx9jtGHnE/Igr 52KPQFoesqVJjjVueRCxvK8nanUVJ9GlhpI6wQW4+DxUsViFoLrFxriDm+4n//FFLI5r jg5g== 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=mYUOjDUgV5uRZr8FSI2sN9uglijkdaYClIStHAMPSkA=; b=mZ7t6GICKXZpE4iVQ2Sl02Zbr+vpodOAIHX+vZL7lcQ+cgjxAPYKMPAWbAz5AJ4BDo oMiuWX/2XNV5QBmTFlfUWKGZZSb+WvQAtY24a2DAQ2t1ezfBOJorPk6smIZ07ICJ3Bsv TEJrtOWjo+8fOMk1H+u7AozWSNOhDhbdetUlt4AnkfS5UX3Dq2JTpq95ns0wStkC9Yuw 9NOHjllcQEKA5dztI1atFnYVIZg1fmhjavJMYxHTn4cCNX9i4Uz7FK2+XLl1+jq12wYf hXZrHJ3QBSIN/6NQRtnPdRdUOmLj8l6wllCxl2MTUp6tyYRyjVljwUw/pPwk50OA0gBg 2w4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=VmeTtBF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a17090699c400b007c16e4d5e9esi782309ejn.412.2023.01.06.00.37.02; Fri, 06 Jan 2023 00:37:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=VmeTtBF5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232656AbjAFId4 (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Fri, 6 Jan 2023 03:33:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbjAFId0 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 6 Jan 2023 03:33:26 -0500 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F53E676CE for <linux-kernel@vger.kernel.org>; Fri, 6 Jan 2023 00:33:23 -0800 (PST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20230106083321euoutp018ad9827a9eb4363a0857256a26e941c1~3qy5BRGPb1990819908euoutp01A for <linux-kernel@vger.kernel.org>; Fri, 6 Jan 2023 08:33:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20230106083321euoutp018ad9827a9eb4363a0857256a26e941c1~3qy5BRGPb1990819908euoutp01A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1672994001; bh=mYUOjDUgV5uRZr8FSI2sN9uglijkdaYClIStHAMPSkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VmeTtBF5gK5bztpCTGGZApS6CQVXo9uIwcf3KtFV9+4tNaM0IfiDRBHi8xxwu8SKG IeVjhxHeDcvSWZSGlFkTk70SzePsOGpxp4y5eqRVSjh7jKqoyJQLa5aGP1URdpjuWQ TltkqGJuqrZml32qlhsDnXSEpmn5p3T65m6Jqfp0= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20230106083320eucas1p2d90ff0852e090e65aca5fa311795922e~3qy3_jx7W0127301273eucas1p2-; Fri, 6 Jan 2023 08:33:20 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 46.43.43884.0DCD7B36; Fri, 6 Jan 2023 08:33:20 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20230106083320eucas1p1f8de0c6ecf351738e8f0ee5f3390d94f~3qy3k3X6I2244622446eucas1p12; Fri, 6 Jan 2023 08:33:20 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230106083320eusmtrp1ca7857a1c230a82c8c50a2ca90d049a8~3qy3kPC_x2166121661eusmtrp1h; Fri, 6 Jan 2023 08:33:20 +0000 (GMT) X-AuditID: cbfec7f5-271ff7000000ab6c-44-63b7dcd0381b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id E7.C6.23420.0DCD7B36; Fri, 6 Jan 2023 08:33:20 +0000 (GMT) Received: from localhost (unknown [106.210.248.66]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230106083319eusmtip2fc156a9b99243a61ab87bd75fb6194fb~3qy3WgiZY2797827978eusmtip2g; Fri, 6 Jan 2023 08:33:19 +0000 (GMT) From: Pankaj Raghav <p.raghav@samsung.com> To: axboe@kernel.dk Cc: kernel@pankajraghav.com, linux-kernel@vger.kernel.org, hare@suse.de, bvanassche@acm.org, snitzer@kernel.org, dm-devel@redhat.com, damien.lemoal@opensource.wdc.com, linux-nvme@lists.infradead.org, hch@lst.de, linux-block@vger.kernel.org, gost.dev@samsung.com, Pankaj Raghav <p.raghav@samsung.com> Subject: [PATCH 2/7] block: add a new helper bdev_{is_zone_start, offset_from_zone_start} Date: Fri, 6 Jan 2023 09:33:12 +0100 Message-Id: <20230106083317.93938-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230106083317.93938-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKKsWRmVeSWpSXmKPExsWy7djP87oX7mxPNti9T8li9d1+NotpH34y W/w+e57ZYu+72awWNw/sZLLYs2gSk8XK1UeZLM68/MxisfeWtsXlXXPYLOYve8pu8XlpC7vF iVvSDrwel694e1w+W+qxaVUnm8fmJfUeu282sHnsbL3P6nF2paPH+31X2Tz6tqxi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: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20230106083320eucas1p1f8de0c6ecf351738e8f0ee5f3390d94f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20230106083320eucas1p1f8de0c6ecf351738e8f0ee5f3390d94f References: <20230106083317.93938-1-p.raghav@samsung.com> <CGME20230106083320eucas1p1f8de0c6ecf351738e8f0ee5f3390d94f@eucas1p1.samsung.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754261615098874600?= X-GMAIL-MSGID: =?utf-8?q?1754261615098874600?= |
Series |
block zoned cleanups
|
|
Commit Message
Pankaj Raghav
Jan. 6, 2023, 8:33 a.m. UTC
Instead of open coding to check for zone start, add a helper to improve
readability and store the logic in one place.
bdev_offset_from_zone_start() will be used later in the series.
Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
block/blk-core.c | 2 +-
block/blk-zoned.c | 4 ++--
include/linux/blkdev.h | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 3 deletions(-)
Comments
On 1/6/23 17:33, Pankaj Raghav wrote: > Instead of open coding to check for zone start, add a helper to improve > readability and store the logic in one place. > > bdev_offset_from_zone_start() will be used later in the series. > > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> > --- > block/blk-core.c | 2 +- > block/blk-zoned.c | 4 ++-- > include/linux/blkdev.h | 18 ++++++++++++++++++ > 3 files changed, 21 insertions(+), 3 deletions(-) > > diff --git a/block/blk-core.c b/block/blk-core.c > index 9321767470dc..0405b3144e7a 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -573,7 +573,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, > return BLK_STS_NOTSUPP; > > /* The bio sector must point to the start of a sequential zone */ > - if (bio->bi_iter.bi_sector & (bdev_zone_sectors(bio->bi_bdev) - 1) || > + if (!bdev_is_zone_start(bio->bi_bdev, bio->bi_iter.bi_sector) || > !bio_zone_is_seq(bio)) > return BLK_STS_IOERR; > > diff --git a/block/blk-zoned.c b/block/blk-zoned.c > index db829401d8d0..614b575be899 100644 > --- a/block/blk-zoned.c > +++ b/block/blk-zoned.c > @@ -277,10 +277,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op, > return -EINVAL; > > /* Check alignment (handle eventual smaller last zone) */ > - if (sector & (zone_sectors - 1)) > + if (!bdev_is_zone_start(bdev, sector)) > return -EINVAL; > > - if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity) > + if (!bdev_is_zone_start(bdev, nr_sectors) && end_sector != capacity) > return -EINVAL; > > /* > diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h > index 0e40b014c40b..04b7cbfd7a2a 100644 > --- a/include/linux/blkdev.h > +++ b/include/linux/blkdev.h > @@ -715,6 +715,7 @@ static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) > { > return 0; > } > + whiteline change > static inline unsigned int bdev_max_open_zones(struct block_device *bdev) > { > return 0; > @@ -1304,6 +1305,23 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) > return q->limits.chunk_sectors; > } > > +static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev, > + sector_t sec) > +{ > + if (!bdev_is_zoned(bdev)) this helper should never be called outside of code supporting zones. So why this check ? > + return 0; > + > + return sec & (bdev_zone_sectors(bdev) - 1); > +} > + > +static inline bool bdev_is_zone_start(struct block_device *bdev, sector_t sec) > +{ > + if (!bdev_is_zoned(bdev)) > + return false; Same here. > + > + return bdev_offset_from_zone_start(bdev, sec) == 0; > +} > + > static inline int queue_dma_alignment(const struct request_queue *q) > { > return q ? q->limits.dma_alignment : 511;
On 1/6/23 00:33, Pankaj Raghav wrote: > +static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev, > + sector_t sec) > +{ > + if (!bdev_is_zoned(bdev)) > + return 0; > + > + return sec & (bdev_zone_sectors(bdev) - 1); > +} > + > +static inline bool bdev_is_zone_start(struct block_device *bdev, sector_t sec) > +{ > + if (!bdev_is_zoned(bdev)) > + return false; > + > + return bdev_offset_from_zone_start(bdev, sec) == 0; > +} A nit: 'sector_t sector' is much more common in the block layer than 'sector_t sec'. Please consider changing 'sec' into 'sector'. Thanks, Bart.
On 1/6/23 00:33, Pankaj Raghav wrote: > Instead of open coding to check for zone start, add a helper to improve > readability and store the logic in one place. > > bdev_offset_from_zone_start() will be used later in the series. > > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> Looks good. Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> -ck
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
diff --git a/block/blk-core.c b/block/blk-core.c index 9321767470dc..0405b3144e7a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -573,7 +573,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_NOTSUPP; /* The bio sector must point to the start of a sequential zone */ - if (bio->bi_iter.bi_sector & (bdev_zone_sectors(bio->bi_bdev) - 1) || + if (!bdev_is_zone_start(bio->bi_bdev, bio->bi_iter.bi_sector) || !bio_zone_is_seq(bio)) return BLK_STS_IOERR; diff --git a/block/blk-zoned.c b/block/blk-zoned.c index db829401d8d0..614b575be899 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -277,10 +277,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_op op, return -EINVAL; /* Check alignment (handle eventual smaller last zone) */ - if (sector & (zone_sectors - 1)) + if (!bdev_is_zone_start(bdev, sector)) return -EINVAL; - if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity) + if (!bdev_is_zone_start(bdev, nr_sectors) && end_sector != capacity) return -EINVAL; /* diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0e40b014c40b..04b7cbfd7a2a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -715,6 +715,7 @@ static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) { return 0; } + static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { return 0; @@ -1304,6 +1305,23 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return q->limits.chunk_sectors; } +static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev, + sector_t sec) +{ + if (!bdev_is_zoned(bdev)) + return 0; + + return sec & (bdev_zone_sectors(bdev) - 1); +} + +static inline bool bdev_is_zone_start(struct block_device *bdev, sector_t sec) +{ + if (!bdev_is_zoned(bdev)) + return false; + + return bdev_offset_from_zone_start(bdev, sec) == 0; +} + static inline int queue_dma_alignment(const struct request_queue *q) { return q ? q->limits.dma_alignment : 511;