From patchwork Wed Oct 10 01:52:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10633795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01A0F13AD for ; Wed, 10 Oct 2018 01:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E71B2298B6 for ; Wed, 10 Oct 2018 01:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB3D1298CA; Wed, 10 Oct 2018 01:52:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83E2A298DB for ; Wed, 10 Oct 2018 01:52:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbeJJJMf (ORCPT ); Wed, 10 Oct 2018 05:12:35 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:39878 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbeJJJMf (ORCPT ); Wed, 10 Oct 2018 05:12:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539136367; x=1570672367; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=mNMcePsDiYFu1nBuR4Pj+B/FH01mKmMAV/NO8ULxzUs=; b=lbQsbNPr/jKYMF7kQh4byfbZQfqY1HD7CO3T/8VNb1UGKly0KOQfzSif mFBDXzGDmTyQigwC5CtGUnc0hoAtqVSkTlkgwhxCYpotM2GoWR+6ZoWnp WezadlC3+E9yUr+lGwe3DTYTlackgxMYxEHMfa5ElrDKDFpcuCL3X6V1s zf9wkJItvRzbvrWuTvks3Wx22wPRXo9I2GJbTulO9GD2LOiUVQTw5pjyX 50cDU70NgAXZd6URvkvBUYioZbH7x7IM0Eyfpx2XcBqRASd7yQ/6BuKci gurpW5K4nlhJEPW/nkwQqmE/abFpQjUHHNppHrUdUNvK1fqaLacfuFEeB g==; X-IronPort-AV: E=Sophos;i="5.54,362,1534780800"; d="scan'208";a="92692968" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2018 09:52:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Oct 2018 18:38:13 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Oct 2018 18:52:46 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Christoph Hellwig , Matias Bjorling Subject: [PATCH 04/11] block: Introduce blkdev_nr_zones() helper Date: Wed, 10 Oct 2018 10:52:32 +0900 Message-Id: <20181010015239.24930-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010015239.24930-1-damien.lemoal@wdc.com> References: <20181010015239.24930-1-damien.lemoal@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce the blkdev_nr_zones() helper function to get the total number of zones of a zoned block device. This number is always 0 for a regular block device (q->limits.zoned == BLK_ZONED_NONE case). Replace hard-coded number of zones calculation in dmz_get_zoned_device() with a call to this helper. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig --- block/blk-zoned.c | 27 +++++++++++++++++++++++++++ drivers/md/dm-zoned-target.c | 3 +-- include/linux/blkdev.h | 5 +++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index c461cf63f1f4..32e377f755d8 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -63,6 +63,33 @@ void __blk_req_zone_write_unlock(struct request *rq) } EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); +static inline unsigned int __blkdev_nr_zones(struct request_queue *q, + sector_t nr_sectors) +{ + unsigned long zone_sectors = blk_queue_zone_sectors(q); + + return (nr_sectors + zone_sectors - 1) >> ilog2(zone_sectors); +} + +/** + * blkdev_nr_zones - Get number of zones + * @bdev: Target block device + * + * Description: + * Return the total number of zones of a zoned block device. + * For a regular block device, the number of zones is always 0. + */ +unsigned int blkdev_nr_zones(struct block_device *bdev) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (!blk_queue_is_zoned(q)) + return 0; + + return __blkdev_nr_zones(q, bdev->bd_part->nr_sects); +} +EXPORT_SYMBOL_GPL(blkdev_nr_zones); + /* * Check that a zone report belongs to the partition. * If yes, fix its start sector and write pointer, copy it in the diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index a44183ff4be0..12d96a263623 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -702,8 +702,7 @@ static int dmz_get_zoned_device(struct dm_target *ti, char *path) dev->zone_nr_blocks = dmz_sect2blk(dev->zone_nr_sectors); dev->zone_nr_blocks_shift = ilog2(dev->zone_nr_blocks); - dev->nr_zones = (dev->capacity + dev->zone_nr_sectors - 1) - >> dev->zone_nr_sectors_shift; + dev->nr_zones = blkdev_nr_zones(dev->bdev); dmz->dev = dev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6980014357d4..c24969b1741b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -401,6 +401,7 @@ struct blk_zone_report_hdr { u8 padding[60]; }; +extern unsigned int blkdev_nr_zones(struct block_device *bdev); extern int blkdev_report_zones(struct block_device *bdev, sector_t sector, struct blk_zone *zones, unsigned int *nr_zones, gfp_t gfp_mask); @@ -414,6 +415,10 @@ extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, #else /* CONFIG_BLK_DEV_ZONED */ +static inline unsigned int blkdev_nr_zones(struct block_device *bdev) +{ + return 0; +} static inline int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)