[PATCH 1/2] SSC: honour the readonly attribute

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



TGTD devices can be set to "readonly" attributes.
Add support to honour this attribute for SSC devices too.

MODE SENSE (SSC 8.3.1 MODE PARAMETERS OVERVIEW)
  When used with the MODE SENSE command, a write protection (WP) bit of zero
  specifies the medium is write enabled. A WP bit of one specifies the medium
  is currently in the write protected state. When used with the MODE
  SELECT command, this field is ignored.

  NOTE 56 The write protected state may be due to logical unit internal
  restrictions, software write protection, or physical write protection.

In this case "software write protect" applies since the TGTD readonly
attribute for the LUN is set to 1.

SSC 4.2.13 WRITE PROTECTION  TABLE 5 -- ERROR CONDITIONS AND SENSE KEYS
  Attempt to perform an erase, format, partition, set capacity,
  or write-type operation on write protected medium.

  DATA PROTECT

Fail erase/space/write6/writefilemark with DATA_PROTECT/ASC_WRITE_PROTECT
for SSC LUNs that have the readonly attribute set to 1

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 usr/ssc.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/usr/ssc.c b/usr/ssc.c
index e6bb6f1..8177483 100644
--- a/usr/ssc.c
+++ b/usr/ssc.c
@@ -57,10 +57,20 @@ static int ssc_mode_sense(int host_no, struct scsi_cmd *cmd)
 	uint8_t *data, mode6;
 
 	ret = spc_mode_sense(host_no, cmd);
+	if (ret != SAM_STAT_GOOD)
+		return ret;
 
 	mode6 = (cmd->scb[0] == 0x1a);
 	data = scsi_get_in_buffer(cmd);
 
+	/* set write protect bit to 1 for readonly devices */
+	if (cmd->dev->attrs.readonly) {
+		if (mode6)
+			data[2] |= 0x80;
+		else
+			data[3] |= 0x80;
+	}
+
 	/* set the device to report BUFFERED MODE for writes */
 	if (mode6)
 		data[2] |= 0x10;
@@ -86,6 +96,19 @@ static int ssc_rw(int host_no, struct scsi_cmd *cmd)
 	if (ret)
 		return SAM_STAT_RESERVATION_CONFLICT;
 
+	if (cmd->dev->attrs.readonly) {
+		switch (cmd->scb[0]) {
+		case ERASE:
+		case SPACE:
+		case WRITE_6:
+		case WRITE_FILEMARKS:
+			key = DATA_PROTECT;
+			asc = ASC_WRITE_PROTECT;
+			goto sense;
+			break;
+		}
+	}
+
 	ret = cmd->dev->bst->bs_cmd_submit(cmd);
 	if (ret) {
 		key = HARDWARE_ERROR;
@@ -93,6 +116,7 @@ static int ssc_rw(int host_no, struct scsi_cmd *cmd)
 	} else
 		return SAM_STAT_GOOD;
 
+sense:
 	cmd->offset = 0;
 	scsi_set_in_resid_by_actual(cmd, 0);
 	scsi_set_out_resid_by_actual(cmd, 0);
-- 
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux