[Stgt-devel] [Patch 5/6] Update spc_request_sense() to return some sense data.

Mark Harvey markh794
Wed Jun 20 10:07:42 CEST 2007


>From ff2ab514b13173c6e6fc515c2b3a7bf10b100feb Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Wed, 20 Jun 2007 17:49:33 +1000
Subject: update spc_request_sense() to return some sort of sense data.

Updated spc_request_sense() so it returns some data.
- spc_request_sense() needs more investigation as:
   sg_requests /dev/sgX => returns old (SCSI-1) sense.
   At least it no longer returns an error.

Signed-off-by: Mark Harvey <markh794 at gmail.com>
---
 usr/spc.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/usr/spc.c b/usr/spc.c
index 6dbe013..6530e73 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -233,9 +233,36 @@ int spc_test_unit(int host_no, struct scsi_cmd *cmd)
 
 int spc_request_sense(int host_no, struct scsi_cmd *cmd)
 {
-	cmd->len = 0;
-	sense_data_build(cmd, NO_SENSE, NO_ADDITIONAL_SENSE);
+	uint8_t *data;
+	uint8_t key = NO_SENSE;
+	uint16_t asc = NO_ADDITIONAL_SENSE;
+
+	data = valloc(pagesize);
+	if (!data) {
+		key = HARDWARE_ERROR;
+		asc = E_INTERNAL_TGT_FAILURE;
+		goto sense;
+	}
+	memset(data, 0, pagesize);
+
+	/* SPC4: 6.28 - Check if we support the DESC bit */
+	if (cmd->scb[1] && 1) {
+		if (!cmd->dev->attrs.sense_format) {
+			key = ILLEGAL_REQUEST;
+			asc = E_INVALID_FIELD_IN_CDB;
+			goto sense;
+		}
+	}
+
+	sense_data_build(cmd, key, asc);
+	cmd->len = cmd->sense_len;
+	memcpy(data, cmd->sense_buffer, cmd->sense_len);
 	return SAM_STAT_GOOD;
+
+sense:
+	cmd->len = 0;
+	sense_data_build(cmd, key, asc);
+	return SAM_STAT_CHECK_CONDITION;
 }
 
 void dump_cdb(struct scsi_cmd *cmd)
-- 
1.5.2.1








More information about the stgt mailing list