From patchwork Thu Jan 28 04:47:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79FF9C433DB for ; Thu, 28 Jan 2021 04:49:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B3BE64DD9 for ; Thu, 28 Jan 2021 04:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbhA1EtY (ORCPT ); Wed, 27 Jan 2021 23:49:24 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21969 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbhA1EtW (ORCPT ); Wed, 27 Jan 2021 23:49:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809361; x=1643345361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nlVDSYPsDiNDIn4MgX4E8oTX+gmER/SxjozWNm4/+I0=; b=AC2wC8ob7S7spqukE39AM5m+6snPfo+ftl1PgZQB2+E5TZmxGaT8HB8D i2UC4P9CaaLFmahBiWRFN4/qVOj9Ueg5qKzpqXdqCDpoFOEElfoHNSd81 RYFjKS63rPkSjJTXXsCdby1ZhbhUEzKWMRtGxaPAYpa9qN0xJvRDG8Pcu Rm0LsY0LdH4XUdW1ihUqC5RGdhgn813ULLLawd7MZ7eT0mKuZUG57aOqF v+4nt6BmPl2+hooTJA7u4ObItaEkiCcSnNRXSBTh6+jZ16eBPZ/ZNAjIm mzR2Yiz4CoWBY86a/JSlBIUehkhEy8IUnWlER0QPoBBT67rJjxdReWeV7 w==; IronPort-SDR: dvMYoRePYBMgIp4/nNXX1K4pgNepYOHgMYaVVkjMl045+LxL+AEYc7nCpf8JMolBUrEfp2VIKY xHF1/hLY5obhwJW5XWqBZ/WM6mTFrLl7PmDBKpRw58p7tcYxORAFhd2sdp6dio0QdiKYE3F+dM sEMlWjoHO5ALBaGNbdjTsKoSnM5xsEaHSKv/Fyx6Dg9FpDOxUz1M6GiKbXNDJG0flMEhttIoRJ x8uJcyr/xNumQLyVBXtJ7bS9PHqBF+8HJdEkGkomeaSRMEoyS+6V78Y1nBQaUrdYnqAFsYL6VT uZ0= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509126" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:37 +0800 IronPort-SDR: jk7I/2Q10HaA7mQHUWqRZsgowiItqCMimrhCIyluGOzKQdhJkMvjzsTa1RTdrys0KiiNvD4Dvp GE25Soy67RnBe3TBmEs2WskukWZdtloTORChy9Bd2Lz9bldLslCgx3HMz4O68phbORjOzBtOQE WWYQeDAc3t1zVccs1t9AuL686gOVYyTOHjzFjC6TWSF3YlAxbj6uVGVKQx3tQ0rWUxkYyOdRrL OWtD/BBdvF5p0VPSYJzELEohX+PTlwEbDDf5rt8IOdBu/dnmJt/MqvAVxWvkf29jFECP3PjrRK sQkUDw2T3E5oaX8MhZXv5AVh Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:29:56 -0800 IronPort-SDR: Rw4bUzOvN4mJwZLFxFUm6LpJsGwe5YcjBXIX2Ymv9mt+5XHcopn8O27sy142fveBFZy18GIqep dvyoGjJpSCtn0JKO6dGlnahV4dhyjT/iii6yhL5o/XGgczi5bC4+HJYI97zt156LnEvC9UlYVk OWD50plCdjYBxhJSEehpZDV18NEpG1mFbF301ZIQVHxOfwa450BEWZvJlo/Sadvlt4IBLUHmdk /zz5jCgU8+44Juwu2kXXwWCyftM6fkjACRZQfke/V/+xM0bxwwgoMgC2ZAsHUtKWQYOGvuSUoL usU= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:36 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 1/8] block: document zone_append_max_bytes attribute Date: Thu, 28 Jan 2021 13:47:26 +0900 Message-Id: <20210128044733.503606-2-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The description of the zone_append_max_bytes sysfs queue attribute is missing from Documentation/block/queue-sysfs.rst. Add it. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Chaitanya Kulkarni Reviewed-by: Martin K. Petersen Reviewed-by: Johannes Thumshirn --- Documentation/block/queue-sysfs.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/block/queue-sysfs.rst b/Documentation/block/queue-sysfs.rst index 2638d3446b79..edc6e6960b96 100644 --- a/Documentation/block/queue-sysfs.rst +++ b/Documentation/block/queue-sysfs.rst @@ -261,6 +261,12 @@ For block drivers that support REQ_OP_WRITE_ZEROES, the maximum number of bytes that can be zeroed at once. The value 0 means that REQ_OP_WRITE_ZEROES is not supported. +zone_append_max_bytes (RO) +-------------------------- +This is the maximum number of bytes that can be written to a sequential +zone of a zoned block device using a zone append write operation +(REQ_OP_ZONE_APPEND). This value is always 0 for regular block devices. + zoned (RO) ---------- This indicates if the device is a zoned block device and the zone model of the From patchwork Thu Jan 28 04:47:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74915C433DB for ; Thu, 28 Jan 2021 04:49:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3702364DDA for ; Thu, 28 Jan 2021 04:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbhA1Etu (ORCPT ); Wed, 27 Jan 2021 23:49:50 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:22074 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbhA1Etr (ORCPT ); Wed, 27 Jan 2021 23:49:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809386; x=1643345386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SWCTJmRNv2T9JpmyPX37nbAkKPtO6xgSUCxz+iuTR/w=; b=cpFV+sXoR/xZsMmRj0y57S4v1eNDAODe+Ws4TiRBPW+/moBLYmPSF7e4 iZh67hdaNLXToZqxUlhU+VXD36devnkSjQtwC7bIyrPUwoXuhyrI5a5KP 9VepGgvG6Qet+EgFoWT+jP8XKgh7ty+be2VXW4W0sWkUxBqsPuYv/i+s2 zXLD18QCUzEi+I8Rrp9eWSc0p3sUEOBjn+64DZ4yqybFpdlsfB+cfzC/F dEYATSdu6Ct2SVznVx+5X/Lq96XNIt2nSm0fzhyIV/FQli8n404ILLSe8 Ku4NDt7u/ncJSDAjP8gxk4M0Ci1En2Muy3SXNuN1v21yX+48O+4YwUvTO g==; IronPort-SDR: PC3YyB4lebHhlOWeDomrMqGD+e9IerrVSReJE8AlRwSpPOHYcnBXMEXaDIl5P0EKzautL78XSC oKHYb9Z+bLliaw7EMWr9qvDv9uGjSV7dobj0/S6dK8QrP5i8AQTJFe5OgEhj2l3AY5ZtIFEs55 s7qOw9bdgMqW3y+qZWvNN93Mfrhsp/wA+UBZqAyQC31Eoo1Ay1434eeFQHyoqeWeJvzCEXlsK7 I1txpglZWRpdCjvHro+Ok32McvLsHpBiCnlrmtC7P97+MYOr+N6eJb5eBcl1x0CQ6se94P3zLD 65E= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509129" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:39 +0800 IronPort-SDR: o7ob7SaI97tiVu2bvpAZSixXYeeTBv7HLDTN5w1p2hBMJhV1NC6tD/l4dzS7lwyxkM1VHNnX5p h2kVp229QUHG7RhRibc99ez5hvSO1gUzTJWS1ifh+ZgZ4bNn+32srKCANu15spiicxE2B9ES0S iZa8Iaal7gMTfjbOid05ZZa35//gFhKoaHYnFsoZULXre+Y+Zp68R198+0iiKxEat9RQljhW4n /zHjNQPit5kddN0wxR5SQquOgmp/TY7nsU0mjq++ZOHnp3PlvN19LR5yA8RsRS1a1INK+THRxO ASmrrWiYzqxvI/3IQJv8/8wH Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:29:57 -0800 IronPort-SDR: jBNmDaXDVx8v8RZcXtnMGGqEm3shQx0PxDNLaX1rzbyNbnPEVu1t9X34NLlWClP6rF9ErVcQ0I RtgqajKMuXA2X2Pvk5cZESe2jSoGcHmD/P53lB4UCwpXkvhmkjIgH3V+EBlA8foqgNHTY1c7E7 FjTIk5Nr0HKNOH4jBBO/nGekm86UgUAA1YfHnSarLNb9pZNvOBa+HDVR/zbOCxY6NY1ZP9K4yt pUJPoH4sN6bH+F2icZDg6pkQQGirtTTIvKgI0min0s/BwDOfZJ+pk3H8XxlirLkj8jsnmft2Ni 3UE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:37 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 2/8] nvme: cleanup zone information initialization Date: Thu, 28 Jan 2021 13:47:27 +0900 Message-Id: <20210128044733.503606-3-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org For a zoned namespace, in nvme_update_ns_info(), call nvme_update_zone_info() after executing nvme_update_disk_info() so that the namespace queue logical and physical block size limits are set. This allows setting the namespace queue max_zone_append_sectors limit in nvme_update_zone_info() instead of nvme_revalidate_zones(), simplifying this function. Also use blk_queue_set_zoned() to set the namespace zoned model. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- drivers/nvme/host/core.c | 11 ++++++----- drivers/nvme/host/zns.c | 11 +++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1a3cdc6b1036..81a1c7f6223f 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -2176,17 +2176,18 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_id_ns *id) ns->lba_shift = id->lbaf[lbaf].ds; nvme_set_queue_limits(ns->ctrl, ns->queue); + ret = nvme_configure_metadata(ns, id); + if (ret) + goto out_unfreeze; + nvme_set_chunk_sectors(ns, id); + nvme_update_disk_info(ns->disk, ns, id); + if (ns->head->ids.csi == NVME_CSI_ZNS) { ret = nvme_update_zone_info(ns, lbaf); if (ret) goto out_unfreeze; } - ret = nvme_configure_metadata(ns, id); - if (ret) - goto out_unfreeze; - nvme_set_chunk_sectors(ns, id); - nvme_update_disk_info(ns->disk, ns, id); blk_mq_unfreeze_queue(ns->disk->queue); if (blk_queue_is_zoned(ns->queue)) { diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 1dfe9a3500e3..c7e3ec561ba0 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -9,13 +9,7 @@ int nvme_revalidate_zones(struct nvme_ns *ns) { - struct request_queue *q = ns->queue; - int ret; - - ret = blk_revalidate_disk_zones(ns->disk, NULL); - if (!ret) - blk_queue_max_zone_append_sectors(q, ns->ctrl->max_zone_append); - return ret; + return blk_revalidate_disk_zones(ns->disk, NULL); } static int nvme_set_max_append(struct nvme_ctrl *ctrl) @@ -109,10 +103,11 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf) goto free_data; } - q->limits.zoned = BLK_ZONED_HM; + blk_queue_set_zoned(ns->disk, BLK_ZONED_HM); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); blk_queue_max_open_zones(q, le32_to_cpu(id->mor) + 1); blk_queue_max_active_zones(q, le32_to_cpu(id->mar) + 1); + blk_queue_max_zone_append_sectors(q, ns->ctrl->max_zone_append); free_data: kfree(id); return status; From patchwork Thu Jan 28 04:47:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF1E3C433E0 for ; Thu, 28 Jan 2021 04:50:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78FE764DDA for ; Thu, 28 Jan 2021 04:50:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbhA1EuH (ORCPT ); Wed, 27 Jan 2021 23:50:07 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21969 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbhA1EuD (ORCPT ); Wed, 27 Jan 2021 23:50:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809403; x=1643345403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YobZghyNsgskNB+fC+I1GvLwxiefgtnuuC0Tcp7ryyI=; b=NNTAQ9tVBPqmkVeHutbFLdWmYEhd+TpmV8QKOmLbeBaE4F2mwp2rCXwn oGNhv+bcKkxPO5oZisyWkMN0GEBYJknDySg3ohiyn7Ym7fXsdfEX4rlvw SW1VwUyPlSxjMJ01R2M2aGmbHqknzvaa8rZnvYVVMxlFyF+NalLhXhO1E kKiQlirxkmfr+8l85gGNPtbqGyetFbyL57m1NhrMAkDwkgtrtiHJKuGaO 8lpmmhUydylkbyRYKNsMo/eIDtgDjQupmwphwacSJmhTwEejXBHAgWu4C XU3s764F7TKEW0zNmz1c6TEhdeg6UHFDoim1Mj6C9nqpRhatFq+s8dA3R Q==; IronPort-SDR: SaF8XR6C8U22TQ9035EkOg5imG2DYaliY5mYa3nnIFVHxz0+Q7T2ELNvVK66DRHdldlof3lRpK RU0ic4/kUlcoph7aRc1E8kJOJxCcZ0ffBWV/Knlt5g397+t2BQMojRqvi0qs18ojuT1MqXXlOt kqg3teILg7k28hpYMrRBVN/K+ZzsA1Qcis0v5UxMss8QQNlQHq9Cf8Jo6dKc399M3l89DlAD9R UIlU5qVT76Pna9eV3anYYZ6uUi3kE/KesLBta2KNm7qMjPUv/Rga8Bv1t9+u16+X/WQT6o4Mow 2JM= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509132" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:40 +0800 IronPort-SDR: SiSp3TYuXQEqH998FV4e83lTSZORVJYnRuTe/2nVj5VA8quS5iiLLy6K1HL5cQqk3QG6rg7Ip1 /YbmPepJRGezJO9Ccxgxbpnsqq+TpNrG2Q1ECotU2Od0hhZakOWXflK96P5Elimnqw3mSxjj73 rqpUdk0a9o9xtKPBTq1XHi2MLEa+QrcpiTTtkZIn1Z7o+yKGHIQ1TbbpRQfg8AIGWwtgYPFL3H JdTvNZP6HvFUlVPopHRFAjIkgn/MLwIU4tctqloqc1WtFgXffLxQio7816IviHA6fFQq+ID2sW xDH7JOh0pdq5gqfXpLjMKm0m Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:29:59 -0800 IronPort-SDR: 9RcohAp9AMgU5B7rQIxsmbG4uch5GxDip1QD1xSnMBIuPmFlTmbHioiPbNRL2EDa/fBYDWBb08 f9Q4NGR3usz6Ez9dTU6cRvCiM/DaUVDZz55/Dq2niCiGulwBXt9Q5eJjpwoF9ZRmGKkECu7Fly wUG9p3+HrZa0On4ZF0ntny/L7BWLJKixVz/R5j4b1xwAe4delg5B2v9/Yv4AbKTaM+FnN9KZMi 9C1jqkMK2sq/P8NliAxdm6KzkwU9IMtTQK5eYWvsLALI9vUiWJuk6i8f5306kiBEX3ElOf2Wlk 3iQ= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:39 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 3/8] nullb: use blk_queue_set_zoned() to setup zoned devices Date: Thu, 28 Jan 2021 13:47:28 +0900 Message-Id: <20210128044733.503606-4-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Use blk_queue_set_zoned() to set a nullb device zone model instead of directly assigning the device queue zoned limit. This initialization of the devicve zoned model as well as the setup of the queue flag QUEUE_FLAG_ZONE_RESETALL and of the device queue elevator feature are moved from null_init_zoned_dev() to null_register_zoned_dev() so that the initialization of the queue limits is done when the gendisk of the nullb device is available. Signed-off-by: Damien Le Moal Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- drivers/block/null_blk/zoned.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 148b871f263b..78cae8703dcf 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -146,10 +146,6 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) sector += dev->zone_size_sects; } - q->limits.zoned = BLK_ZONED_HM; - blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); - blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE); - return 0; } @@ -158,6 +154,10 @@ int null_register_zoned_dev(struct nullb *nullb) struct nullb_device *dev = nullb->dev; struct request_queue *q = nullb->q; + blk_queue_set_zoned(nullb->disk, BLK_ZONED_HM); + blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); + blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE); + if (queue_is_mq(q)) { int ret = blk_revalidate_disk_zones(nullb->disk, NULL); From patchwork Thu Jan 28 04:47:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B4A5C433E0 for ; Thu, 28 Jan 2021 04:50:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CC7964DD6 for ; Thu, 28 Jan 2021 04:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231251AbhA1Eub (ORCPT ); Wed, 27 Jan 2021 23:50:31 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:22074 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231231AbhA1Eu2 (ORCPT ); Wed, 27 Jan 2021 23:50:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809428; x=1643345428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O5qP2BvielJYmUlUhNylv6LuJjfmaS7aLBnXfbQBd5s=; b=AJZGERhWZQrtfnzMrEHIV124U0+E2e1dr7pon6fE2hzDZn9HLzhe1VOT P2R2X9iSe7kbI0nHE1ytCE9VKfIyuPxqSehfy6SRnruLV2O3OtAEAJgJ1 pbjFSA4JVBY9SVwBbifFE1vrZRoN8vNyOnolFqT+1W5AxBThGxoNDEBNw kR0fYb3Be/giPg9jtXI6Trpjtfwyo5gGfRqAaGggY9FVFb0X3iOHhpIE8 ZY0SIdjvzoXIWiOwMAwqg5zccYaeNtVTu/O1NyiQzfYMfKlWcgJp2WuRN jjgOOwIp1H4i0BqLQ4h4EUfNr1kDqNMzBwqvZuOrfKym6JVXHbr7AQp7q A==; IronPort-SDR: tlR7IPQdtoxNp302SYZSb7X7iAGxzMCv0RVZGufgmonBI2vCqurzYG34FnqOuan5OXUk9r3jTN CYRh2eBrRdBE0GmF6wCbHakYT4TzhtYgXvuDncTWq66WF9NWUfgyXnMjwunuPweaUlNFB6drLm bfkR6Xo9em4HQWUeYqTOcm8+QqFvjkq2TIPxcejVL20722fHT/xyjSC9KexFgLvMbK/2wz716m B+I4MxzBuX1a2hIOv+7A6TTlOQbmc++am4NfuQvIHRIRPSuYk+YAbXFZmyZj/zKpcAaZBXuZRp yeM= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509134" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:42 +0800 IronPort-SDR: tQPjUYi9cdtYvuBMY+UzQCJvhZa66m4iytRGVJJs2F47ew5CyLF1Ek5LjT0RrVSaIuX8MZnusG sCjtSvcmBsesa/yuu4NCuUAWUHBIqdki4VJlDBgBNsN4Ta9OSGl+kwrcI4VfNgNxloDvW+L/vM s74l608MWMr8AnLHm+JdIwE7++8rx3b+7H/SAPWReMH+mVovt5FOqWTwP9wsOnSp0KPzIoNTq+ SaHQk2otjZ6t76ZcYxdyXympbJSPUiMgfPx6uoaM5i9IBEB607D82Nb0t4IlHfdcPuS6ssXAu4 6DETLUdbh43U0lYbPD5gGM4D Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:30:00 -0800 IronPort-SDR: 8FBSkmLkyjz/GhHTUchlUwVPFmI+pC7A7EzrMqfa3aKCq8hn1uhE8WCrOLREjJOTmvCt3/CE0A PFi6FIaeYm42gCoDFulkqJRp74RBKkiObqip/8YLU5qrv8PTMAeTu2Y9odXlKxxFlbZvu5ejsU DGiolIEupzXSPUdqBMUlhiyub/QZ2ynvdm9KWsJN5/8O/dopTirjNGr2qnZcoR/3ZX46Jkviex Gz0JFZ39uG0fQ+i29cUV7N2vlNDYZQSEONJZF6Z8/4lc7Vm5g5Hsn3WR+vBMeqsEL0dpBkHiBi /QE= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:40 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 4/8] block: use blk_queue_set_zoned in add_partition() Date: Thu, 28 Jan 2021 13:47:29 +0900 Message-Id: <20210128044733.503606-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When changing the zoned model of host-aware zoned block devices, use blk_queue_set_zoned() instead of directly assigning the gendisk queue zoned limit. Signed-off-by: Damien Le Moal Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/partitions/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index b1cdf88f96e2..d6094203116a 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -334,7 +334,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, case BLK_ZONED_HA: pr_info("%s: disabling host aware zoned block device support due to partitions\n", disk->disk_name); - disk->queue->limits.zoned = BLK_ZONED_NONE; + blk_queue_set_zoned(disk, BLK_ZONED_NONE); break; case BLK_ZONED_NONE: break; From patchwork Thu Jan 28 04:47:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B52E3C433E9 for ; Thu, 28 Jan 2021 04:50:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 848E264DD9 for ; Thu, 28 Jan 2021 04:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231259AbhA1Euf (ORCPT ); Wed, 27 Jan 2021 23:50:35 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:22123 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231243AbhA1Eu3 (ORCPT ); Wed, 27 Jan 2021 23:50:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809428; x=1643345428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FYa88HT0yWBywxqBZGFR8tCz7AMVDuJCnFOsRnimI0M=; b=S/Ngb5UmdID3Fi1rnflqq/b9DGEyEOo04pEvOJ8GypaXCAkW36izPOhT Kt8ZZm6aDt5G51VjEMteg1fhgB7AQnbXa6TxucHBHQRW2mEjXsypTUNBn HSydGWN9Uo2F0kvG5wUYya0gNuXFaNgcLa2O1cpyN+He8m6SqhduHkSA1 +ccMWZb0pJgYg159BQR+LUOkex/+0/jjuqhBHXQ23CoBmMk6RUj3KNZcJ BCxUj4vFsB416hPpjV1SXNeCTfXCgiuRIpGSe3xKRcjlixec0L2HBGo0W 05ovWBOVfnEGDU7e2BMBNfVovS4IGHQ7mTyigBCLPouOp4nPiazfW2EX/ A==; IronPort-SDR: 9VwR49JZBk2581ynwlWv69cD6DcOeLkDVFmY5+I+UOGVguXt6KX2LUlWYt7ULLl/E588/7f2rO Vzyzc+gg9JgC/zpNKodfFx9ygpxq66pkoVlL/3n0uKm94Dg5HsnE/gW7899ye8u6TqQBncnizg y+gCfS581rhXiqPaWSbgrlFrhtTMvjctP4Bl+fR3FVFQZGaNcbwjISX5+HME0RMDqsq2iPa1uQ XMXwSF+GdEXADR3h1vuQd0VI8dzzfe05Rof+2k8vHRe8udXVfvinrOMRifEUjyAI84xMRAnIFH XzA= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509136" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:43 +0800 IronPort-SDR: bU9IvMTj4o/RjNgHIh2Vwgczaft8crkbQxAUijzz5ZdIUMJHB1JEwcb2ih6wmB5AwIgG7pzmIN 6rTOyfX/OAxsJwRr/5bFKYTdO9VjXU1gW3EczG9RLr3oPLT3NgtfSfZx7Rgr6vbRui+vkBpVb/ jUYRB+AvWNRwStmAydVu072G1tPK/6NArJfNNJQMUj/yP+52NdWJPqn/18WhWvWQEAHeYTozrL GkBM67oVnHG6z2+z9F8Ow3k7RbRdGAJ2XZBQFQsnXIHnOWg25BiH8XcApuBFFBPYQv0RhAY74G bSUDtq+f6fPqouR7kROD1woK Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:30:02 -0800 IronPort-SDR: c2uU3xUrafHzTvInYusEBlkZFhykLUHkikWL1bY/D0HixajYtB+H/8+7/8J3BxAl+/sQkwwgen kOsXKwa7T6GdbPJvyDJbNSLIA0qKhAR6x6CiCVViEFKAmuOVTNS/Y1Igqw6pDguJhYlzk2igIp mMWnW1DuNbonLU5OmyHug7NfP9fWF/hL/EvbEdtuSz84juITF14ZEKTGzQAWf2acYNUpflkMA2 Gck7JNM3OmoZEBBSlJxBNcf0U+gITl/bP/K78FpfJYVv5nrGesXq8uSRjiFmrhvrwNClCSqZYQ 3no= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:42 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 5/8] block: introduce zone_write_granularity limit Date: Thu, 28 Jan 2021 13:47:30 +0900 Message-Id: <20210128044733.503606-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Per ZBC and ZAC specifications, host-managed SMR hard-disks mandate that all writes into sequential write required zones be aligned to the device physical block size. However, NVMe ZNS does not have this constraint and allows write operations into sequential zones to be aligned to the device logical block size. This inconsistency does not help with software portability across device types. To solve this, introduce the zone_write_granularity queue limit to indicate the alignment constraint, in bytes, of write operations into zones of a zoned block device. This new limit is exported as a read-only sysfs queue attribute and the helper blk_queue_zone_write_granularity() introduced for drivers to set this limit. The function blk_queue_set_zoned() is modified to set this new limit to the device logical block size by default. NVMe ZNS devices as well as zoned nullb devices use this default value as is. The scsi disk driver is modified to execute the blk_queue_zone_write_granularity() helper to set the zone write granularity of host-managed SMR disks to the disk physical block size. The accessor functions queue_zone_write_granularity() and bdev_zone_write_granularity() are also introduced. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- Documentation/block/queue-sysfs.rst | 7 ++++++ block/blk-settings.c | 37 ++++++++++++++++++++++++++++- block/blk-sysfs.c | 8 +++++++ drivers/scsi/sd_zbc.c | 8 +++++++ include/linux/blkdev.h | 15 ++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Documentation/block/queue-sysfs.rst b/Documentation/block/queue-sysfs.rst index edc6e6960b96..4dc7f0d499a8 100644 --- a/Documentation/block/queue-sysfs.rst +++ b/Documentation/block/queue-sysfs.rst @@ -279,4 +279,11 @@ devices are described in the ZBC (Zoned Block Commands) and ZAC do not support zone commands, they will be treated as regular block devices and zoned will report "none". +zone_write_granularity (RO) +--------------------------- +This indicates the alignment constraint, in bytes, for write operations in +sequential zones of zoned block devices (devices with a zoned attributed +that reports "host-managed" or "host-aware"). This value is always 0 for +regular block devices. + Jens Axboe , February 2009 diff --git a/block/blk-settings.c b/block/blk-settings.c index 4c974340f1a9..a1e66165adcf 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -60,6 +60,7 @@ void blk_set_default_limits(struct queue_limits *lim) lim->io_opt = 0; lim->misaligned = 0; lim->zoned = BLK_ZONED_NONE; + lim->zone_write_granularity = 0; } EXPORT_SYMBOL(blk_set_default_limits); @@ -366,6 +367,28 @@ void blk_queue_physical_block_size(struct request_queue *q, unsigned int size) } EXPORT_SYMBOL(blk_queue_physical_block_size); +/** + * blk_queue_zone_write_granularity - set zone write granularity for the queue + * @q: the request queue for the zoned device + * @size: the zone write granularity size, in bytes + * + * Description: + * This should be set to the lowest possible size allowing to write in + * sequential zones of a zoned block device. + */ +void blk_queue_zone_write_granularity(struct request_queue *q, + unsigned int size) +{ + if (WARN_ON_ONCE(!blk_queue_is_zoned(q))) + return; + + q->limits.zone_write_granularity = size; + + if (q->limits.zone_write_granularity < q->limits.logical_block_size) + q->limits.zone_write_granularity = q->limits.logical_block_size; +} +EXPORT_SYMBOL_GPL(blk_queue_zone_write_granularity); + /** * blk_queue_alignment_offset - set physical block alignment offset * @q: the request queue for the device @@ -631,6 +654,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->discard_granularity; } + t->zone_write_granularity = max(t->zone_write_granularity, + b->zone_write_granularity); t->zoned = max(t->zoned, b->zoned); return ret; } @@ -847,6 +872,8 @@ EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging); */ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model) { + struct request_queue *q = disk->queue; + switch (model) { case BLK_ZONED_HM: /* @@ -875,7 +902,15 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model) break; } - disk->queue->limits.zoned = model; + q->limits.zoned = model; + if (model != BLK_ZONED_NONE) { + /* + * Set the zone write granularity to the device logical block + * size by default. The driver can change this value if needed. + */ + blk_queue_zone_write_granularity(q, + queue_logical_block_size(q)); + } } EXPORT_SYMBOL_GPL(blk_queue_set_zoned); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index b513f1683af0..ae39c7f3d83d 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -219,6 +219,12 @@ static ssize_t queue_write_zeroes_max_show(struct request_queue *q, char *page) (unsigned long long)q->limits.max_write_zeroes_sectors << 9); } +static ssize_t queue_zone_write_granularity_show(struct request_queue *q, + char *page) +{ + return queue_var_show(queue_zone_write_granularity(q), page); +} + static ssize_t queue_zone_append_max_show(struct request_queue *q, char *page) { unsigned long long max_sectors = q->limits.max_zone_append_sectors; @@ -585,6 +591,7 @@ QUEUE_RO_ENTRY(queue_discard_zeroes_data, "discard_zeroes_data"); QUEUE_RO_ENTRY(queue_write_same_max, "write_same_max_bytes"); QUEUE_RO_ENTRY(queue_write_zeroes_max, "write_zeroes_max_bytes"); QUEUE_RO_ENTRY(queue_zone_append_max, "zone_append_max_bytes"); +QUEUE_RO_ENTRY(queue_zone_write_granularity, "zone_write_granularity"); QUEUE_RO_ENTRY(queue_zoned, "zoned"); QUEUE_RO_ENTRY(queue_nr_zones, "nr_zones"); @@ -639,6 +646,7 @@ static struct attribute *queue_attrs[] = { &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_zone_append_max_entry.attr, + &queue_zone_write_granularity_entry.attr, &queue_nonrot_entry.attr, &queue_zoned_entry.attr, &queue_nr_zones_entry.attr, diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index cf07b7f93579..8293b29584b3 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -789,6 +789,14 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) blk_queue_max_active_zones(q, 0); nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks); + /* + * Per ZBC and ZAC specifications, writes in sequential write required + * zones of host-managed devices must be aligned to the device physical + * block size. + */ + if (blk_queue_zoned_model(q) == BLK_ZONED_HM) + blk_queue_zone_write_granularity(q, sdkp->physical_block_size); + /* READ16/WRITE16 is mandatory for ZBC disks */ sdkp->device->use_16_for_rw = 1; sdkp->device->use_10_for_rw = 0; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0dea268bd61b..9149f4a5adb3 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -337,6 +337,7 @@ struct queue_limits { unsigned int max_zone_append_sectors; unsigned int discard_granularity; unsigned int discard_alignment; + unsigned int zone_write_granularity; unsigned short max_segments; unsigned short max_integrity_segments; @@ -1160,6 +1161,8 @@ extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_max_zone_append_sectors(struct request_queue *q, unsigned int max_zone_append_sectors); extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); +void blk_queue_zone_write_granularity(struct request_queue *q, + unsigned int size); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); void blk_queue_update_readahead(struct request_queue *q); @@ -1473,6 +1476,18 @@ static inline int bdev_io_opt(struct block_device *bdev) return queue_io_opt(bdev_get_queue(bdev)); } +static inline unsigned int +queue_zone_write_granularity(const struct request_queue *q) +{ + return q->limits.zone_write_granularity; +} + +static inline unsigned int +bdev_zone_write_granularity(struct block_device *bdev) +{ + return queue_zone_write_granularity(bdev_get_queue(bdev)); +} + static inline int queue_alignment_offset(const struct request_queue *q) { if (q->limits.misaligned) From patchwork Thu Jan 28 04:47:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B6CC433E6 for ; Thu, 28 Jan 2021 04:51:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64ABC60235 for ; Thu, 28 Jan 2021 04:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231133AbhA1Euz (ORCPT ); Wed, 27 Jan 2021 23:50:55 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:21969 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbhA1Eus (ORCPT ); Wed, 27 Jan 2021 23:50:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809448; x=1643345448; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AS28SYb5q1dU4ktJHvnVMu02oMpGHGEKFN6I8l7eXCY=; b=ZEb189+44cXfqrzJPfs74wYDlphEkleFnxxkICu0zkdYvWnYPkEXH4J0 5N/CHHuXncSrbDt0Ixp6tY01e2vlVbslUnOk2732nqi02NYYVUFJZdMIk 7SWzF8nfoYhfIM3zh0sX044qrDEIiNCaF7qO78SsjLfChZ0HvpPPvX47n R1kSJJmdJJ4GwdJdSvQN6ey4FUpODccZ4Itm1eXd8Jwls8zFygQFOoIMj Z8vJCMGu7ZG7CUNPr0/ZtRfrkDfpx7iZ0VWr+wb107Mxg23VpeK13fzKW rVqG/gYUAmR9sseuR/gQ9wPynRxMho7JbFkZ3xyhO3CFRdJ5L2URqzd+I A==; IronPort-SDR: v6uV6cOLpUvbVzNWjf4tCDoGM6cTbDjr6oaqbbR5JIA2z0Wg0owo1KzGWgYr/KSTwN6LcSVWRH XyZ0uCBQSMY3PyNW4LZSqEU4pUe6o70hMKoxBpgWi8ZWDD/Jfv8d6mpdwN9izuUE+a8uDQHb2Q GEJObIedxq1NxUA242NSvzO9ykfIrPOem9XKwNa3suWnh2K/q9vP80uVSTiBtPqO5rUyhWbatd N4dW4iBf0wZJmw15EJa5tPoABpe16ooRuTqxgpIWhQUVmQCD+UlN0nkyoC+8DuyonDfAkMKzLA NqI= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509141" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:45 +0800 IronPort-SDR: uqaKiiVCg8znjzm8bGqDB1xyXEhDT/pXTZq9jkekh4aTDRmJSquqvgCefBrpvORZr1JMr+TqPY KwyWglknbB8Dc5C2KqnjYsGQZp11JcZ8Iv1crlacauRNONc2CnBJ69WCS06mRh9azh2L3pb0dN jT0yxTeSmB46S6F6DiHufiBG+pfr65JhX9QWQTRy2d8+E2KtBnWYp5Es8IOH8qnIlIV+EUbN4u S3VAFOQrPfe3nU3v8c+mUd6cAp/5cY9slG+Ht9K9r97wJ/q1hYRyC2CUHlKclOnG4fvXf5vT7g iUxt8QCaQsoJD9m6xrHUWflh Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:30:03 -0800 IronPort-SDR: Ih/EIXJQ+gm7gzO0vYm/RUmL/N2knyTj+4YQH3D2SEHcGrwcmtNZQxBVXi3nTLGXND293dX5dv 3osTAZVlmO9JfrAPv/Bi40zkDPS7XHJmLbju+yPgWStmacadE7vXXBeqMt1lbcBZbPsHZBOCPL 64LZrURWEW/UJWwRiU8cDrOw9VAqjAVlcSRnYCpzIJ/xcYXUHx4BYVRG2jEobNX+4tyWDmibgG e5XXPyMCMYMmFDTW1lJajFjyLc8xgiP8wDEbhRw5HIRYhra0VLM/LlE0fSOWYrKFp9pPsFoH5R hec= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:44 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 6/8] zonefs: use zone write granularity as block size Date: Thu, 28 Jan 2021 13:47:31 +0900 Message-Id: <20210128044733.503606-7-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Zoned block devices have different granularity constraints for write operations into sequential zones. E.g. ZBC and ZAC devices require that writes be aligned to the device physical block size while NVMe ZNS devices allow logical block size aligned write operations. To correctly handle such difference, use the device zone write granularity limit to set the block size of a zonefs volume, thus allowing the smallest possible write unit for all zoned device types. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Chaitanya Kulkarni Reviewed-by: Johannes Thumshirn --- fs/zonefs/super.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index ab68e27bb322..b9fb55b250ae 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -1581,12 +1581,11 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent) sb->s_time_gran = 1; /* - * The block size is set to the device physical sector size to ensure - * that write operations on 512e devices (512B logical block and 4KB - * physical block) are always aligned to the device physical blocks, - * as mandated by the ZBC/ZAC specifications. + * The block size is set to the device zone write granularity to ensure + * that write operations are always aligned according to the device + * interface constraints. */ - sb_set_blocksize(sb, bdev_physical_block_size(sb->s_bdev)); + sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev)); sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev)); sbi->s_uid = GLOBAL_ROOT_UID; sbi->s_gid = GLOBAL_ROOT_GID; From patchwork Thu Jan 28 04:47:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27654C433E6 for ; Thu, 28 Jan 2021 04:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C699964DD6 for ; Thu, 28 Jan 2021 04:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231269AbhA1EvL (ORCPT ); Wed, 27 Jan 2021 23:51:11 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:22074 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231174AbhA1EvK (ORCPT ); Wed, 27 Jan 2021 23:51:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809470; x=1643345470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=To8ibe4IoXLbKNtSVr85Y+rPsQgn0MZHdGIA9grMAlY=; b=V6Ghz+9Axl9/yxaIYG7lGwYPUcczyjlkCd12ZDmFkD36LLfHCWWFUl8H IHq4ZAfggWMquiwyqVtPu7tdkb8dHEYjY6za36o8NM1Z1XKc+Y0Xw3ZSh AeRdeB4+xd1wgnCX6jP6RW/UagwkgNBZYiEl3nih0m2jaOTDPERL4j8i4 FsqIv6RS+KYIyK1rg+wiQtAT0AksM2QNh0cggUaPB2D0wBZ0g/GTYvp+4 I2wJnY74OpSa2MQjCGohy8PnL/TaZe3A38ypQoh4hf4t4XS3YS5I4WWxd iRTjnIOTsbpoEvJSpb3wysrufZrGJqxrKiF6OnsnDo0rKt4ruo7rwOJNe w==; IronPort-SDR: ZzXf/Kormxb38aYW+flfF650NDqrl6HT4+FXHdT3upBqeQFI15Y7+7ojlsHEk73B9845KJ7t2I 9jAgoqMAN3TOpI04bcIe94r/1nrNJkMdcqf/qVqqxqXZJv6s+kZLuH4rJVRkfYT9pE4S3TpBvK RvVNAlqG1zT4mxVEV7gA+L+jZnhqrWS7NaHIG1+oGVpXbK4YzEYPKE7h1QG/b54bI7ybnfJi1A i2vuBgxu6cLXpNR1Mx7cTsK8Vc5wtKLEJrWVxwXE6TtxN/y/Zli6tarQHRHxq6pVGUWcwuETu+ bgY= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509145" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:47 +0800 IronPort-SDR: wh8YZcCoSyyWdWR0VSoWJ15PVnbFMMJBF8ne4V7ZDqHNXlH2n7XITa4uC9ogPBFksc1FgWWzzy etep7vdPiGTaUzrTLdz3QnM4idi2ERDtuLzgpUoUAcrFi9c9Oyawg0UiEorC0UjMmOR6oxKSX9 ETcAFEOX47PvHxOfIGwMM1i/3MBaCilLB6BilCrtgV3liAwNMQEkerKjO2yeibGOLlcYn8oDXu w/nzmekLtD/QVO+wn4c8Yz1a5om0uugSJyd01U0d9gsIB0mK7HR5JmvP16iE61XoDsP52+qe6y 5mXFPiaN4DGRlpGgDTCjFOFU Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:30:05 -0800 IronPort-SDR: kgqL13pGkC8QABIy4e6bYHJfwv9FlTi5e0mJkrgoRIiurS/qlobH/8gLRvVFaW2WqnXxqAx0Zk X1xIeQcLXveAeTMlasw9QF9po0Xl1/JmRVWjPqXx/LMqeXisQUsKKLWvTzwXJoeHpQ/4EL6KW0 FwVwB5RH6c8vow0S5BXbHszwhzUvco0p2cKlowbRu58yxbUvzTwJIFzkJwTI1MwQdqmntJeFZY 7/OH+3s/0PkTZM79M+d9+Oc3Oz586aak3QVemcPXkEKBJlwuBrhpp6S9b2bPVlR7/Cjl79oxwc bMg= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:45 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 7/8] block: introduce blk_queue_clear_zone_settings() Date: Thu, 28 Jan 2021 13:47:32 +0900 Message-Id: <20210128044733.503606-8-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Introduce the internal function blk_queue_clear_zone_settings() to cleanup all limits and resources related to zoned block devices. This new function is called from blk_queue_set_zoned() when a disk zoned model is set to BLK_ZONED_NONE. This particular case can happens when a partition is created on a host-aware scsi disk. Signed-off-by: Damien Le Moal Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- block/blk-settings.c | 2 ++ block/blk-zoned.c | 17 +++++++++++++++++ block/blk.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/block/blk-settings.c b/block/blk-settings.c index a1e66165adcf..7dd8be314ac6 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -910,6 +910,8 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model) */ blk_queue_zone_write_granularity(q, queue_logical_block_size(q)); + } else { + blk_queue_clear_zone_settings(q); } } EXPORT_SYMBOL_GPL(blk_queue_set_zoned); diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 7a68b6e4300c..833978c02e60 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -549,3 +549,20 @@ int blk_revalidate_disk_zones(struct gendisk *disk, return ret; } EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones); + +void blk_queue_clear_zone_settings(struct request_queue *q) +{ + blk_mq_freeze_queue(q); + + blk_queue_free_zone_bitmaps(q); + blk_queue_flag_clear(QUEUE_FLAG_ZONE_RESETALL, q); + q->required_elevator_features &= ~ELEVATOR_F_ZBD_SEQ_WRITE; + q->nr_zones = 0; + q->max_open_zones = 0; + q->max_active_zones = 0; + q->limits.chunk_sectors = 0; + q->limits.zone_write_granularity = 0; + q->limits.max_zone_append_sectors = 0; + + blk_mq_unfreeze_queue(q); +} diff --git a/block/blk.h b/block/blk.h index 0198335c5838..977d79a0d99a 100644 --- a/block/blk.h +++ b/block/blk.h @@ -333,8 +333,10 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); #ifdef CONFIG_BLK_DEV_ZONED void blk_queue_free_zone_bitmaps(struct request_queue *q); +void blk_queue_clear_zone_settings(struct request_queue *q); #else static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {} +static inline void blk_queue_clear_zone_settings(struct request_queue *q) {} #endif int blk_alloc_devt(struct block_device *part, dev_t *devt); From patchwork Thu Jan 28 04:47:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 12051781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7465FC433E9 for ; Thu, 28 Jan 2021 04:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBF7A64DBD for ; Thu, 28 Jan 2021 04:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbhA1EvN (ORCPT ); Wed, 27 Jan 2021 23:51:13 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:22123 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbhA1EvM (ORCPT ); Wed, 27 Jan 2021 23:51:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611809472; x=1643345472; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EKhsyGUiAPT9iVQna/YmfrtwycQGpAjmcTYD4lMXNEs=; b=F8CO0xB+JrFMmUADhb671gvZ7/rsY9mBFbEdvyPq1uQfurdHbDiQQZDZ vGKVqnsXqmkaytrKt5R0T3oB1rJtYmMh+7XowbEQ3SCrHZUAglxQ8F+3p 7j1GXF3Eg2mpAVk5w6kVwlgc8ARExPAkgP01uBDSMfKeCuGFFaL/UggoC GqppXWS0C7ehkTh9BsGkPJywZrC0tztL2+EAm/LSbyN3HCyt/rQKpO6FB wMgCV58TqUShSh+uMW7PuYODj+f7o+zzCYysalV7rcUzrPJRPFtUZagvU QCC+9Xuiwu2oA4jJo/GivQ7j1krjk8T9uRibI5pei1BLDkawpYu0fqg+U w==; IronPort-SDR: V4rqozJW9Sq7D8lXq1FNDM9lyU/ZO8RK2gE7stvk007UnQf0ciPTIyxlfQP+zm9sgtJhb+WEO4 SKQPJBrCGJJS5vDKcvJmRPBicHIABANtxBc5mDwWUpvzEkMRTDImc7TjJJYEuJMK1Ic5AA2hZ4 7t5vlJokDrPYaDFeieqqJvV5TaVbTMRSlwVM6VSwxSI9YeGfbjrbE5o9inXkjGf/Hqk/UtkkNY F+36/8tQuzmMMRVNIKLf5PQpLok7nYKlBSrY18yvHBPK/kY0zmE3VnOBCwClnJZ7CIa0vJ3Flw n0M= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="158509147" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 12:47:48 +0800 IronPort-SDR: n2Y0JBCq46eC4M76Hm9c539F+BGALk68FyhJ2p81TOl1QUUb4IN5X9S8keqL4DVrUyESNr3hUG jfVrJkiNddKWPPE0V7ezbUej9VYb+3wDKihtek/1/ITWAMaRCgLLnGvDaYKI5cVKmsjxL9yrP4 RATQXemYntgKLVhtLGv3hejWhFKzbxMmV1J1DrCMMRbOXZE86dOnOm+mSWFEjbWu6yZ5v/rozh vlehcQEvzt6w1vvBFGlvw06vsglE7SjeGzYyMGhcsh+vEStM3rZBPPSbLtKZuSiJeYKK5Mh9ev tkkwkzCdni28Vfu9M/oZlnfK Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 20:30:07 -0800 IronPort-SDR: knyvuuTglsAK3pbOeeqHjtips90rfYXAkh0tF9qiqV8q622wCBoNmRVWyT4smvYPHCxcmQW8Nv 5n/7SR1uTfIc1B7bD3bC3dHb/4kWkp4ClLXSY+Ols9XKvR92VtUEyUEDwgyPw9Ptq3Sri5d0Eb mMBGu1ItA6JFERgoKHOrFitedPGVM89nDfpFO/smM+lfQcRTNrq+w0sS5bEsdovt5rr6arFNBX OPfmdQMrczo2Wnp8wPeuFBfoYFjYLXKj1DbOOBxX+EzO1WuCANQcdrTSCliTIrl3luDlpFezyn LKI= WDCIronportException: Internal Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 20:47:47 -0800 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , linux-nvme@lists.infradead.org, Christoph Hellwig , Keith Busch , Chaitanya Kulkarni Subject: [PATCH v4 8/8] sd_zbc: clear zone resources for non-zoned case Date: Thu, 28 Jan 2021 13:47:33 +0900 Message-Id: <20210128044733.503606-9-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com> References: <20210128044733.503606-1-damien.lemoal@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org For host-aware ZBC disk, setting the device zoned model to BLK_ZONED_HA using blk_queue_set_zoned() in sd_read_block_characteristics() may result in the block device effective zoned model to be "none" (BLK_ZONED_NONE) if partitions are present on the device. In this case, sd_zbc_read_zones() should not setup the zone related queue limits for the disk so that the device limits and configuration is consistent with a regular disk and resources not uselessly allocated (e.g. the zone write pointer tracking array for zone append emulation). Furthermore, if the disk zoned model changes at run time due to the creation of a partition by the user, the zone related resources can be released. Fix both problems by introducing the function sd_zbc_clear_zone_info() to reset the scsi disk zone information and free resources and by returning early in sd_zbc_read_zones() for a block device that has a zoned model equal to BLK_ZONED_NONE. Signed-off-by: Damien Le Moal Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Martin K. Petersen --- drivers/scsi/sd_zbc.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index 8293b29584b3..03adb39293c2 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -665,12 +665,28 @@ static int sd_zbc_init_disk(struct scsi_disk *sdkp) return 0; } -void sd_zbc_release_disk(struct scsi_disk *sdkp) +static void sd_zbc_clear_zone_info(struct scsi_disk *sdkp) { + /* Serialize against revalidate zones */ + mutex_lock(&sdkp->rev_mutex); + kvfree(sdkp->zones_wp_offset); sdkp->zones_wp_offset = NULL; kfree(sdkp->zone_wp_update_buf); sdkp->zone_wp_update_buf = NULL; + + sdkp->nr_zones = 0; + sdkp->rev_nr_zones = 0; + sdkp->zone_blocks = 0; + sdkp->rev_zone_blocks = 0; + + mutex_unlock(&sdkp->rev_mutex); +} + +void sd_zbc_release_disk(struct scsi_disk *sdkp) +{ + if (sd_is_zoned(sdkp)) + sd_zbc_clear_zone_info(sdkp); } static void sd_zbc_revalidate_zones_cb(struct gendisk *disk) @@ -769,6 +785,21 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) */ return 0; + /* READ16/WRITE16 is mandatory for ZBC disks */ + sdkp->device->use_16_for_rw = 1; + sdkp->device->use_10_for_rw = 0; + + if (!blk_queue_is_zoned(q)) { + /* + * This can happen for a host aware disk with partitions. + * The block device zone information was already cleared + * by blk_queue_set_zoned(). Only clear the scsi disk zone + * information and exit early. + */ + sd_zbc_clear_zone_info(sdkp); + return 0; + } + /* Check zoned block device characteristics (unconstrained reads) */ ret = sd_zbc_check_zoned_characteristics(sdkp, buf); if (ret) @@ -797,10 +828,6 @@ int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf) if (blk_queue_zoned_model(q) == BLK_ZONED_HM) blk_queue_zone_write_granularity(q, sdkp->physical_block_size); - /* READ16/WRITE16 is mandatory for ZBC disks */ - sdkp->device->use_16_for_rw = 1; - sdkp->device->use_10_for_rw = 0; - sdkp->rev_nr_zones = nr_zones; sdkp->rev_zone_blocks = zone_blocks;