From patchwork Fri Oct 12 10:08:43 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: 10638319 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 3A39E17E3 for ; Fri, 12 Oct 2018 10:09:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB4B2B841 for ; Fri, 12 Oct 2018 10:09:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EFC92B845; Fri, 12 Oct 2018 10:09:00 +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 B79DB2B846 for ; Fri, 12 Oct 2018 10:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728387AbeJLRkh (ORCPT ); Fri, 12 Oct 2018 13:40:37 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63720 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728346AbeJLRkh (ORCPT ); Fri, 12 Oct 2018 13:40:37 -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=1539338938; x=1570874938; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=zVQuPDzq9aj5bwQT1OSJlAZ4eW8iyHRoJBfNAprdM0o=; b=e24CIXSCY1D0n/SUNK5hiqHpqVnz5XngHvx8lpgWM/9r4hX7400N4jtW 95K3kqvYR6GdL8RlCeQzHR+ZALCgQU4LmhKOjK6bE41D64LuMUOPZe5p4 2CenQ133fGUqKsdtn4NIJK6ikeZxHOua3QG/NqFzub30g+LKnUNNdx1NK VVN6Lp2tRMolu2qcfNp0JRr9mXn0aHBDqBqcXYCYeK4ucPpszumx+kzp4 OI10n/6cWrdHCPyLtuvF3OhmOiZNA8cH+4egyBqqhWVZLbok1RfH0i9XS rLIpvYvXioWugAOp4QbmNhing9vVOe9Fgex6jsmpcTztYvIpRXg4l38U7 Q==; X-IronPort-AV: E=Sophos;i="5.54,371,1534780800"; d="scan'208";a="96419684" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 18:08:58 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 12 Oct 2018 02:54:17 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Oct 2018 03:08:57 -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 v4 04/11] block: Introduce blkdev_nr_zones() helper Date: Fri, 12 Oct 2018 19:08:43 +0900 Message-Id: <20181012100850.23316-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012100850.23316-1-damien.lemoal@wdc.com> References: <20181012100850.23316-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 Reviewed-by: Hannes Reinecke --- 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)