Skip to content

Commit

Permalink
sd: Avoid sending medium write commands if device is write protected
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sujit Reddy Thumma authored and Christoph Hellwig committed Sep 15, 2014
1 parent 74cf298 commit 2eefd57
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cache_type_store(struct device *dev, struct device_attribute *attr,
if (ct < 0)
return -EINVAL;
rcd = ct & 0x01 ? 1 : 0;
wce = ct & 0x02 ? 1 : 0;
wce = (ct & 0x02) && !sdkp->write_prot ? 1 : 0;

if (sdkp->cache_override) {
sdkp->WCE = wce;
Expand Down Expand Up @@ -2490,6 +2490,10 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
sdkp->DPOFUA = 0;
}

/* No cache flush allowed for write protected devices */
if (sdkp->WCE && sdkp->write_prot)
sdkp->WCE = 0;

if (sdkp->first_scan || old_wce != sdkp->WCE ||
old_rcd != sdkp->RCD || old_dpofua != sdkp->DPOFUA)
sd_printk(KERN_NOTICE, sdkp,
Expand Down

0 comments on commit 2eefd57

Please sign in to comment.