From patchwork Fri Oct 12 10:08:48 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: 10638349 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 8C33B17E3 for ; Fri, 12 Oct 2018 10:09:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D0692B841 for ; Fri, 12 Oct 2018 10:09:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 716E72B849; Fri, 12 Oct 2018 10:09:18 +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 199832B845 for ; Fri, 12 Oct 2018 10:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728440AbeJLRk4 (ORCPT ); Fri, 12 Oct 2018 13:40:56 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:63750 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbeJLRkz (ORCPT ); Fri, 12 Oct 2018 13:40:55 -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=1539338956; x=1570874956; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ChI648UUuXSFML9oyGHxBP4Vd/R699w90ih4jszByFw=; b=IEnqXfshE5IHVKTgOOpfAilu/eD8nUGMjq5fy8xTrYweXp361OLdwDw6 iJnf/jEX/KFZnSeygtegAQIHSzqPkL6gW0lC5uohX5NlTYrCLoTqtnQbV HnE7M8ssxm3clr9neZNMMVuTLOGI++migdTqsN87xsUIZCfIBKBEILeBW phRb9UVa/KNWQ52FFqPWjSFtRImCV65cxp8jytcg1fmX9rVAkRMjNwmvG CoZA4WNjsz2/8I79h6OXf4scG203WeQI9fAvRDtVNmnLaDEIkcRQhG1Zs qF6BFoYwQXiLzzx7K37UVi/hf2htXZD1ghQZvZbibE8X0yV5caX4zTtqL Q==; X-IronPort-AV: E=Sophos;i="5.54,371,1534780800"; d="scan'208";a="96419707" 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:09:05 +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:24 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 12 Oct 2018 03:09:05 -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 09/11] block: Expose queue nr_zones in sysfs Date: Fri, 12 Oct 2018 19:08:48 +0900 Message-Id: <20181012100850.23316-10-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 Expose through sysfs the nr_zones field of struct request_queue. Exposing this value helps in debugging disk issues as well as facilitating scripts based use of the disk (e.g. blktests). For zoned block devices, the nr_zones field indicates the total number of zones of the device calculated using the known disk capacity and zone size. This number of zones is always 0 for regular block devices. Since nr_zones is defined conditionally with CONFIG_BLK_DEV_ZONED, introduce the blk_queue_nr_zones() function to return the correct value for any device, regardless if CONFIG_BLK_DEV_ZONED is set. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke --- block/blk-sysfs.c | 11 +++++++++++ include/linux/blkdev.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 3772671cf2bc..92be8092ca4f 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -300,6 +300,11 @@ static ssize_t queue_zoned_show(struct request_queue *q, char *page) } } +static ssize_t queue_nr_zones_show(struct request_queue *q, char *page) +{ + return queue_var_show(blk_queue_nr_zones(q), page); +} + static ssize_t queue_nomerges_show(struct request_queue *q, char *page) { return queue_var_show((blk_queue_nomerges(q) << 1) | @@ -637,6 +642,11 @@ static struct queue_sysfs_entry queue_zoned_entry = { .show = queue_zoned_show, }; +static struct queue_sysfs_entry queue_nr_zones_entry = { + .attr = {.name = "nr_zones", .mode = 0444 }, + .show = queue_nr_zones_show, +}; + static struct queue_sysfs_entry queue_nomerges_entry = { .attr = {.name = "nomerges", .mode = 0644 }, .show = queue_nomerges_show, @@ -727,6 +737,7 @@ static struct attribute *default_attrs[] = { &queue_write_zeroes_max_entry.attr, &queue_nonrot_entry.attr, &queue_zoned_entry.attr, + &queue_nr_zones_entry.attr, &queue_nomerges_entry.attr, &queue_rq_affinity_entry.attr, &queue_iostats_entry.attr, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c24969b1741b..879753b10263 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -804,6 +804,11 @@ static inline unsigned int blk_queue_zone_sectors(struct request_queue *q) } #ifdef CONFIG_BLK_DEV_ZONED +static inline unsigned int blk_queue_nr_zones(struct request_queue *q) +{ + return blk_queue_is_zoned(q) ? q->nr_zones : 0; +} + static inline unsigned int blk_queue_zone_no(struct request_queue *q, sector_t sector) { @@ -819,6 +824,11 @@ static inline bool blk_queue_zone_is_seq(struct request_queue *q, return false; return test_bit(blk_queue_zone_no(q, sector), q->seq_zones_bitmap); } +#else /* CONFIG_BLK_DEV_ZONED */ +static inline unsigned int blk_queue_nr_zones(struct request_queue *q) +{ + return 0; +} #endif /* CONFIG_BLK_DEV_ZONED */ static inline bool rq_is_sync(struct request *rq)