linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: target-devel@vger.kernel.org, nab@linux-iscsi.org, hch@lst.de,
	roland@kernel.org
Subject: [PATCH 05/11] target: support zero allocation length in REQUEST SENSE
Date: Fri,  7 Sep 2012 17:30:36 +0200	[thread overview]
Message-ID: <1347031842-2531-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1347031842-2531-1-git-send-email-pbonzini@redhat.com>

Similar to INQUIRY and MODE SENSE, construct the sense data in a
buffer and later copy it to the scatterlist.  Do not do anything,
but still clear a pending unit attention condition, if the allocation
length is zero.

However, SPC tells us that "If a REQUEST SENSE command is terminated with
CHECK CONDITION status [and] the REQUEST SENSE command was received on
an I_T nexus with a pending unit attention condition (i.e., before the
device server reports CHECK CONDITION status), then the device server
shall not clear the pending unit attention condition."  Do the
transport_kmap_data_sg early to detect this case.

It also tells us "Device servers shall not adjust the additional sense
length to reflect truncation if the allocation length is less than the
sense data available", so do not do that!  Note that the err variable
is write-only.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 drivers/target/target_core_spc.c  |   35 ++++++++++++++++++-----------------
 include/target/target_core_base.h |    1 +
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 4c861de..b905fb2 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -877,9 +877,11 @@ static int spc_emulate_modesense(struct se_cmd *cmd)
 static int spc_emulate_request_sense(struct se_cmd *cmd)
 {
 	unsigned char *cdb = cmd->t_task_cdb;
-	unsigned char *buf;
+	unsigned char *rbuf;
 	u8 ua_asc = 0, ua_ascq = 0;
-	int err = 0;
+	unsigned char buf[SE_SENSE_BUF];
+
+	memset(buf, 0, SE_SENSE_BUF);
 
 	if (cdb[1] & 0x01) {
 		pr_err("REQUEST_SENSE description emulation not"
@@ -888,20 +890,21 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
 		return -ENOSYS;
 	}
 
-	buf = transport_kmap_data_sg(cmd);
-
-	if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
+	rbuf = transport_kmap_data_sg(cmd);
+	if (cmd->scsi_sense_reason != 0) {
+		/*
+		 * Out of memory.  We will fail with CHECK CONDITION, so
+		 * we must not clear the unit attention condition.
+		 */
+		target_complete_cmd(cmd, CHECK_CONDITION);
+		return 0;
+	} else if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
 		/*
 		 * CURRENT ERROR, UNIT ATTENTION
 		 */
 		buf[0] = 0x70;
 		buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION;
 
-		if (cmd->data_length < 18) {
-			buf[7] = 0x00;
-			err = -EINVAL;
-			goto end;
-		}
 		/*
 		 * The Additional Sense Code (ASC) from the UNIT ATTENTION
 		 */
@@ -915,11 +916,6 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
 		buf[0] = 0x70;
 		buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE;
 
-		if (cmd->data_length < 18) {
-			buf[7] = 0x00;
-			err = -EINVAL;
-			goto end;
-		}
 		/*
 		 * NO ADDITIONAL SENSE INFORMATION
 		 */
@@ -927,8 +923,11 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
 		buf[7] = 0x0A;
 	}
 
-end:
-	transport_kunmap_data_sg(cmd);
+	if (rbuf) {
+		memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
+		transport_kunmap_data_sg(cmd);
+	}
+
 	target_complete_cmd(cmd, GOOD);
 	return 0;
 }
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 015cea0..5be8937 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -121,6 +121,7 @@
 
 #define SE_INQUIRY_BUF				512
 #define SE_MODE_PAGE_BUF			512
+#define SE_SENSE_BUF				96
 
 /* struct se_hba->hba_flags */
 enum hba_flags_table {
-- 
1.7.1



  parent reply	other threads:[~2012-09-07 15:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 15:30 [PATCH 00/11] lots of fixes for zero allocation length Paolo Bonzini
2012-09-07 15:30 ` [PATCH 01/11] target: go through normal processing for zero-length PSCSI commands Paolo Bonzini
2012-09-07 18:06   ` Nicholas A. Bellinger
2012-09-07 15:30 ` [PATCH 02/11] target: report too-small parameter lists everywhere Paolo Bonzini
2012-09-07 18:09   ` Nicholas A. Bellinger
2012-09-07 15:30 ` [PATCH 03/11] target: fail REPORT LUNS with less than 16 bytes of payload Paolo Bonzini
2012-09-07 18:09   ` Nicholas A. Bellinger
2012-09-07 15:30 ` [PATCH 04/11] target: support zero-size allocation lengths in transport_kmap_data_sg Paolo Bonzini
2012-09-07 18:12   ` Nicholas A. Bellinger
2012-09-07 15:30 ` Paolo Bonzini [this message]
2012-09-07 18:17   ` [PATCH 05/11] target: support zero allocation length in REQUEST SENSE Nicholas A. Bellinger
2012-09-07 15:30 ` [PATCH 06/11] target: go through normal processing for zero-length REQUEST_SENSE Paolo Bonzini
2012-09-07 18:23   ` Nicholas A. Bellinger
2012-09-07 18:33     ` Nicholas A. Bellinger
2012-09-07 20:34       ` Paolo Bonzini
2012-09-07 15:30 ` [PATCH 07/11] target: support zero allocation length in INQUIRY Paolo Bonzini
2012-09-07 15:30 ` [PATCH 08/11] target: fix truncation of mode data, support zero allocation length Paolo Bonzini
2012-09-07 15:30 ` [PATCH 09/11] target: support zero allocation length in SBC commands Paolo Bonzini
2012-09-07 15:30 ` [PATCH 10/11] target: do not submit a zero-bio I/O request Paolo Bonzini
2012-09-07 15:30 ` [PATCH 11/11] target: go through normal processing for all zero-length commands Paolo Bonzini
2012-09-07 19:01 ` [PATCH 00/11] lots of fixes for zero allocation length Nicholas A. Bellinger
2012-09-10  7:28 ` Christoph Hellwig
2012-09-10  7:48   ` Paolo Bonzini

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=1347031842-2531-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=roland@kernel.org \
    --cc=target-devel@vger.kernel.org \
    /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).