diff options
| author | Sujit Reddy Thumma <sthumma@codeaurora.org> | 2014-08-11 08:40:37 -0400 |
|---|---|---|
| committer | Christoph Hellwig <hch@lst.de> | 2014-09-15 19:01:57 -0400 |
| commit | 2eefd57b97609949ae40952da2dea338e7d9a125 (patch) | |
| tree | 9010e184d6af69458b34cf6239ba2e4ba6ef8c9c | |
| parent | 74cf298fedfcb732335cae5d157e95295e87cf2a (diff) | |
sd: Avoid sending medium write commands if device is write protected
The SYNCHRONIZE_CACHE command is a medium write command and hence can
fail when the device is write protected. Avoid sending such commands by
making sure that write-cache-enable is disabled even though the device
claim to support it.
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Venkatesh Srinivas <venkateshs@google.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
| -rw-r--r-- | drivers/scsi/sd.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 2c2041ca4b70..aa43496b7b93 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
| @@ -185,7 +185,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr, | |||
| 185 | if (ct < 0) | 185 | if (ct < 0) |
| 186 | return -EINVAL; | 186 | return -EINVAL; |
| 187 | rcd = ct & 0x01 ? 1 : 0; | 187 | rcd = ct & 0x01 ? 1 : 0; |
| 188 | wce = ct & 0x02 ? 1 : 0; | 188 | wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0; |
| 189 | 189 | ||
| 190 | if (sdkp->cache_override) { | 190 | if (sdkp->cache_override) { |
| 191 | sdkp->WCE = wce; | 191 | sdkp->WCE = wce; |
| @@ -2490,6 +2490,10 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer) | |||
| 2490 | sdkp->DPOFUA = 0; | 2490 | sdkp->DPOFUA = 0; |
| 2491 | } | 2491 | } |
| 2492 | 2492 | ||
| 2493 | /* No cache flush allowed for write protected devices */ | ||
| 2494 | if (sdkp->WCE && sdkp->write_prot) | ||
| 2495 | sdkp->WCE = 0; | ||
| 2496 | |||
| 2493 | if (sdkp->first_scan || old_wce != sdkp->WCE || | 2497 | if (sdkp->first_scan || old_wce != sdkp->WCE || |
| 2494 | old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA) | 2498 | old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA) |
| 2495 | sd_printk(KERN_NOTICE, sdkp, | 2499 | sd_printk(KERN_NOTICE, sdkp, |
