linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bean Huo <huobean@gmail.com>
To: jejb@linux.ibm.com, martin.petersen@oracle.com, bvanassche@acm.org
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bean Huo <beanhuo@micron.com>
Subject: [PATCH] scsi: sd: Use UNMAP in case the device doesn't support WRITE_SAME
Date: Wed,  7 Oct 2020 12:42:20 +0200	[thread overview]
Message-ID: <20201007104220.8772-1-huobean@gmail.com> (raw)

From: Bean Huo <beanhuo@micron.com>

There exists a storage device that supports READ_CAPACITY, but doesn't
support WRITE_SAME. The problem is that WRITE SAME heuristics doesn't work
for this kind of storage device since its block limits VPD page doesn't
contain the LBP information. Currently we set its provisioning_mode
"writesame_16" and didn't check "no_write_same". If we didn't manually change
this default provisioning_mode to "unmap" through sysfs, provisioning_mode
will be set to "disabled" after the first WRITE_SAME command with the following
error occurs:

sd 0:0:0:3: [sdd] tag#4 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte=0x08 cmd_age=0s
sd 0:0:0:3: [sdd] tag#4 Sense Key : 0x5 [current]
sd 0:0:0:3: [sdd] tag#4 ASC=0x20 ASCQ=0x0
sd 0:0:0:3: [sdd] tag#4 CDB: opcode=0x93 93 08 00 00 00 00 00 00 05 4b 00 00 00 1f 00 00
blk_update_request: critical target error, dev sdd, sector 10840 op 0x3:(DISCARD) flags 0x800 phys_seg 1 prio class 0

Comparing to manually change provisioning_mode in sysfs, it is better to set
provisioning_mode to "unmap" in case WRITE_SAME is not supported.

Signed-off-by: Bean Huo <beanhuo@micron.com>
---
 drivers/scsi/sd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 95018e650f2d..93fb41741b21 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2372,7 +2372,10 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
 		if (buffer[14] & 0x40) /* LBPRZ */
 			sdkp->lbprz = 1;
 
-		sd_config_discard(sdkp, SD_LBP_WS16);
+		if (sdp->no_write_same)
+			sd_config_discard(sdkp, SD_LBP_UNMAP);
+		else
+			sd_config_discard(sdkp, SD_LBP_WS16);
 	}
 
 	sdkp->capacity = lba + 1;
-- 
2.17.1


             reply	other threads:[~2020-10-07 10:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 10:42 Bean Huo [this message]
2020-10-08  3:47 ` [PATCH] scsi: sd: Use UNMAP in case the device doesn't support WRITE_SAME Martin K. Petersen
2020-10-08 14:24   ` Bean Huo

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=20201007104220.8772-1-huobean@gmail.com \
    --to=huobean@gmail.com \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).