public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sd: Write lock zone for REQ_OP_WRITE_ZEROES
@ 2017-05-08  6:48 damien.lemoal
  2017-05-12  3:12 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: damien.lemoal @ 2017-05-08  6:48 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen
  Cc: Hannes Reinecke, Christoph Hellwig, Bart Van Assche,
	Damien Le Moal

From: Damien Le Moal <damien.lemoal@wdc.com>

For a zoned block device, sd_zbc_complete() handles zone write unlock
on completion of a REQ_OP_WRITE_ZEROES command but the zone write
locking is missing from sd_setup_write_zeroes_cmnd(). This patch fixes
this problem by locking the target zone of a REQ_OP_WRITE_ZEROES
request.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---

Changes from v1:
* Lock zone in all cases so that no warning is triggered in sd_zbc_complete()
  with unlocked zones for the unmap case.

 drivers/scsi/sd.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e60a309..de9e2f2 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -827,21 +827,32 @@ static int sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
 	struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
 	u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9);
 	u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9);
+	int ret;
 
 	if (!(rq->cmd_flags & REQ_NOUNMAP)) {
 		switch (sdkp->zeroing_mode) {
 		case SD_ZERO_WS16_UNMAP:
-			return sd_setup_write_same16_cmnd(cmd, true);
+			ret = sd_setup_write_same16_cmnd(cmd, true);
+			goto out;
 		case SD_ZERO_WS10_UNMAP:
-			return sd_setup_write_same10_cmnd(cmd, true);
+			ret = sd_setup_write_same10_cmnd(cmd, true);
+			goto out;
 		}
 	}
 
 	if (sdp->no_write_same)
 		return BLKPREP_INVALID;
+
 	if (sdkp->ws16 || sector > 0xffffffff || nr_sectors > 0xffff)
-		return sd_setup_write_same16_cmnd(cmd, false);
-	return sd_setup_write_same10_cmnd(cmd, false);
+		ret = sd_setup_write_same16_cmnd(cmd, false);
+	else
+		ret = sd_setup_write_same10_cmnd(cmd, false);
+
+out:
+	if (sd_is_zoned(sdkp) && ret == BLKPREP_OK)
+		return sd_zbc_write_lock_zone(cmd);
+
+	return ret;
 }
 
 static void sd_config_write_same(struct scsi_disk *sdkp)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] sd: Write lock zone for REQ_OP_WRITE_ZEROES
  2017-05-08  6:48 [PATCH v2] sd: Write lock zone for REQ_OP_WRITE_ZEROES damien.lemoal
@ 2017-05-12  3:12 ` Martin K. Petersen
  0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2017-05-12  3:12 UTC (permalink / raw)
  To: damien.lemoal
  Cc: linux-scsi, Martin K . Petersen, Hannes Reinecke,
	Christoph Hellwig, Bart Van Assche


Damien,

> For a zoned block device, sd_zbc_complete() handles zone write unlock
> on completion of a REQ_OP_WRITE_ZEROES command but the zone write
> locking is missing from sd_setup_write_zeroes_cmnd(). This patch fixes
> this problem by locking the target zone of a REQ_OP_WRITE_ZEROES
> request.

Applied to 4.12/scsi-fixes. Thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-12  3:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-08  6:48 [PATCH v2] sd: Write lock zone for REQ_OP_WRITE_ZEROES damien.lemoal
2017-05-12  3:12 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox