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

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

scsi_io_init() may fail, leaving a zone of a zoned block device locked.
Fix this by properly unlocking the write same request target zone if
scsi_io_init() fails.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Cc: stable@vger.kernel.org
---
 drivers/scsi/sd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f9d1432..e60a309 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -948,6 +948,10 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
 	rq->__data_len = sdp->sector_size;
 	ret = scsi_init_io(cmd);
 	rq->__data_len = nr_bytes;
+
+	if (sd_is_zoned(sdkp) && ret != BLKPREP_OK)
+		sd_zbc_write_unlock_zone(cmd);
+
 	return ret;
 }
 
-- 
2.9.3

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

* [PATCH] sd: Write lock zone for REQ_OP_WRITE_ZEROES
  2017-05-08  5:59 [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd() damien.lemoal
@ 2017-05-08  5:59 ` damien.lemoal
  2017-05-12  3:12 ` [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd() Martin K. Petersen
  1 sibling, 0 replies; 3+ messages in thread
From: damien.lemoal @ 2017-05-08  5:59 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, ignoring the
unmap == true case (as in this case, the write same command will necessarily
be aligned on the entire zone and be equivalent to a discard which does not
write lock zones).

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/sd.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e60a309..b0a525d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -827,6 +827,7 @@ 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) {
@@ -839,9 +840,22 @@ static int sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
 
 	if (sdp->no_write_same)
 		return BLKPREP_INVALID;
+
+	if (sd_is_zoned(sdkp)) {
+		ret = sd_zbc_write_lock_zone(cmd);
+		if (ret != BLKPREP_OK)
+			return ret;
+	}
+
 	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);
+
+	if (sd_is_zoned(sdkp) && ret != BLKPREP_OK)
+		sd_zbc_write_unlock_zone(cmd);
+
+	return ret;
 }
 
 static void sd_config_write_same(struct scsi_disk *sdkp)
-- 
2.9.3

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

* Re: [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd()
  2017-05-08  5:59 [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd() damien.lemoal
  2017-05-08  5:59 ` [PATCH] sd: Write lock zone for REQ_OP_WRITE_ZEROES damien.lemoal
@ 2017-05-12  3:12 ` Martin K. Petersen
  1 sibling, 0 replies; 3+ 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, stable


Damien,

> scsi_io_init() may fail, leaving a zone of a zoned block device locked.
> Fix this by properly unlocking the write same request target zone if
> scsi_io_init() fails.

Applied to 4.12/scsi-fixes.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-08  5:59 [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd() damien.lemoal
2017-05-08  5:59 ` [PATCH] sd: Write lock zone for REQ_OP_WRITE_ZEROES damien.lemoal
2017-05-12  3:12 ` [PATCH] sd: Unlock zone in case of error in sd_setup_write_same_cmnd() 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