All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@wdc.com>
To: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-nvme@lists.infradead.org, Christoph Hellwig <hch@lst.de>,
	Keith Busch <keith.busch@wdc.com>,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Subject: [PATCH v4 8/8] sd_zbc: clear zone resources for non-zoned case
Date: Thu, 28 Jan 2021 13:47:33 +0900	[thread overview]
Message-ID: <20210128044733.503606-9-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com>

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 <damien.lemoal@wdc.com>
---
 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;
 
-- 
2.29.2


WARNING: multiple messages have this Message-ID (diff)
From: Damien Le Moal <damien.lemoal@wdc.com>
To: linux-block@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: Keith Busch <keith.busch@wdc.com>,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>,
	linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>
Subject: [PATCH v4 8/8] sd_zbc: clear zone resources for non-zoned case
Date: Thu, 28 Jan 2021 13:47:33 +0900	[thread overview]
Message-ID: <20210128044733.503606-9-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20210128044733.503606-1-damien.lemoal@wdc.com>

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 <damien.lemoal@wdc.com>
---
 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;
 
-- 
2.29.2


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2021-01-28  4:51 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28  4:47 [PATCH v4 0/8] block: add zone write granularity limit Damien Le Moal
2021-01-28  4:47 ` Damien Le Moal
2021-01-28  4:47 ` [PATCH v4 1/8] block: document zone_append_max_bytes attribute Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28 10:20   ` Johannes Thumshirn
2021-01-28 10:20     ` Johannes Thumshirn
2021-01-28  4:47 ` [PATCH v4 2/8] nvme: cleanup zone information initialization Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  9:17   ` Christoph Hellwig
2021-01-28  9:17     ` Christoph Hellwig
2021-01-28  9:27     ` Damien Le Moal
2021-01-28  9:27       ` Damien Le Moal
2021-01-28  9:32       ` Christoph Hellwig
2021-01-28  9:32         ` Christoph Hellwig
2021-01-28  4:47 ` [PATCH v4 3/8] nullb: use blk_queue_set_zoned() to setup zoned devices Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  5:12   ` Chaitanya Kulkarni
2021-01-28  5:12     ` Chaitanya Kulkarni
2021-01-28  9:17   ` Christoph Hellwig
2021-01-28  9:17     ` Christoph Hellwig
2021-01-28 11:17   ` Johannes Thumshirn
2021-01-28 11:17     ` Johannes Thumshirn
2021-01-28  4:47 ` [PATCH v4 4/8] block: use blk_queue_set_zoned in add_partition() Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  5:16   ` Chaitanya Kulkarni
2021-01-28  5:16     ` Chaitanya Kulkarni
2021-01-28  9:17   ` Christoph Hellwig
2021-01-28  9:17     ` Christoph Hellwig
2021-01-28 11:28   ` Johannes Thumshirn
2021-01-28 11:28     ` Johannes Thumshirn
2021-01-28  4:47 ` [PATCH v4 5/8] block: introduce zone_write_granularity limit Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  9:19   ` Christoph Hellwig
2021-01-28  9:19     ` Christoph Hellwig
2021-01-28 11:32   ` Johannes Thumshirn
2021-01-28 11:32     ` Johannes Thumshirn
2021-02-05  2:54   ` Martin K. Petersen
2021-02-05  2:54     ` Martin K. Petersen
2021-01-28  4:47 ` [PATCH v4 6/8] zonefs: use zone write granularity as block size Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  5:17   ` Chaitanya Kulkarni
2021-01-28  5:17     ` Chaitanya Kulkarni
2021-01-28 11:33   ` Johannes Thumshirn
2021-01-28 11:33     ` Johannes Thumshirn
2021-01-28  4:47 ` [PATCH v4 7/8] block: introduce blk_queue_clear_zone_settings() Damien Le Moal
2021-01-28  4:47   ` Damien Le Moal
2021-01-28  5:26   ` Chaitanya Kulkarni
2021-01-28  5:26     ` Chaitanya Kulkarni
2021-01-28  9:21   ` Christoph Hellwig
2021-01-28  9:21     ` Christoph Hellwig
2021-01-28  9:32     ` Damien Le Moal
2021-01-28  9:32       ` Damien Le Moal
2021-01-28  9:33       ` Christoph Hellwig
2021-01-28  9:33         ` Christoph Hellwig
2021-01-28 11:43   ` Johannes Thumshirn
2021-01-28 11:43     ` Johannes Thumshirn
2021-01-28  4:47 ` Damien Le Moal [this message]
2021-01-28  4:47   ` [PATCH v4 8/8] sd_zbc: clear zone resources for non-zoned case Damien Le Moal
2021-01-28  5:38   ` Chaitanya Kulkarni
2021-01-28  5:38     ` Chaitanya Kulkarni
2021-01-28  5:40     ` Damien Le Moal
2021-01-28  5:40       ` Damien Le Moal
2021-01-28  9:24   ` Christoph Hellwig
2021-01-28  9:24     ` Christoph Hellwig
2021-01-28  9:36     ` Damien Le Moal
2021-01-28  9:36       ` Damien Le Moal
2021-01-28 11:48   ` Johannes Thumshirn
2021-01-28 11:48     ` Johannes Thumshirn
2021-02-05  2:56   ` Martin K. Petersen
2021-02-05  2:56     ` Martin K. Petersen
2021-02-04  8:47 ` [PATCH v4 0/8] block: add zone write granularity limit Damien Le Moal
2021-02-04  8:47   ` Damien Le Moal
2021-02-08 17:17   ` Christoph Hellwig
2021-02-08 17:17     ` Christoph Hellwig
2021-02-10 14:45 ` Jens Axboe
2021-02-10 14:45   ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210128044733.503606-9-damien.lemoal@wdc.com \
    --to=damien.lemoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=keith.busch@wdc.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.