From: Bart Van Assche <bart.vanassche@sandisk.com>
To: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: <target-devel@vger.kernel.org>,
Bart Van Assche <bart.vanassche@sandisk.com>,
Max Lohrmann <post@wickenrode.com>, <stable@vger.kernel.org>
Subject: [PATCH 1/6] target: Fix VERIFY and WRITE VERIFY command parsing
Date: Thu, 30 Mar 2017 10:12:39 -0700 [thread overview]
Message-ID: <20170330171244.8346-2-bart.vanassche@sandisk.com> (raw)
In-Reply-To: <20170330171244.8346-1-bart.vanassche@sandisk.com>
Use the value of the BYTCHK field to determine the size of the
Data-Out buffer. For VERIFY, honor the VRPROTECT, DPO and FUA
fields. This patch avoids that LIO complains about a mismatch
between the expected transfer length and the SCSI CDB length
if the value of the BYTCHK field is 0.
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Max Lohrmann <post@wickenrode.com>
Cc: <stable@vger.kernel.org>
---
drivers/target/target_core_sbc.c | 71 +++++++++++++++++++++++++++++++++++-----
1 file changed, 62 insertions(+), 9 deletions(-)
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index c194063f169b..ee35c90e3b8d 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -828,6 +828,59 @@ sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)
return 0;
}
+/**
+ * sbc_parse_verify - parse VERIFY, VERIFY_16 and WRITE VERIFY commands
+ * @cmd: (in) structure that describes the SCSI command to be parsed.
+ * @sectors: (out) Number of logical blocks on the storage medium that will be
+ * affected by the SCSI command.
+ * @bufflen: (out) Expected length of the SCSI Data-Out buffer.
+ */
+static sense_reason_t sbc_parse_verify(struct se_cmd *cmd, int *sectors,
+ u32 *bufflen)
+{
+ struct se_device *dev = cmd->se_dev;
+ u8 *cdb = cmd->t_task_cdb;
+ u8 bytchk = (cdb[1] >> 1) & 3;
+ sense_reason_t ret;
+
+ switch (cdb[0]) {
+ case VERIFY:
+ case WRITE_VERIFY:
+ *sectors = transport_get_sectors_10(cdb);
+ cmd->t_task_lba = transport_lba_32(cdb);
+ break;
+ case VERIFY_16:
+ *sectors = transport_get_sectors_16(cdb);
+ cmd->t_task_lba = transport_lba_64(cdb);
+ break;
+ default:
+ WARN_ON_ONCE(true);
+ return TCM_UNSUPPORTED_SCSI_OPCODE;
+ }
+
+ if (sbc_check_dpofua(dev, cmd, cdb))
+ return TCM_INVALID_CDB_FIELD;
+
+ ret = sbc_check_prot(dev, cmd, cdb, *sectors, true);
+ if (ret)
+ return ret;
+
+ switch (bytchk) {
+ case 0:
+ *bufflen = 0;
+ break;
+ case 1:
+ *bufflen = sbc_get_size(cmd, *sectors);
+ cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
+ break;
+ default:
+ pr_err("Unsupported BYTCHK value %d for SCSI opcode %#x\n",
+ bytchk, cdb[0]);
+ return TCM_INVALID_CDB_FIELD;
+ }
+ return TCM_NO_SENSE;
+}
+
sense_reason_t
sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
{
@@ -895,7 +948,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
cmd->execute_cmd = sbc_execute_rw;
break;
case WRITE_10:
- case WRITE_VERIFY:
sectors = transport_get_sectors_10(cdb);
cmd->t_task_lba = transport_lba_32(cdb);
@@ -909,6 +961,12 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
cmd->execute_cmd = sbc_execute_rw;
break;
+ case WRITE_VERIFY:
+ ret = sbc_parse_verify(cmd, §ors, &size);
+ if (ret)
+ return ret;
+ cmd->execute_cmd = sbc_execute_rw;
+ goto check_lba;
case WRITE_12:
sectors = transport_get_sectors_12(cdb);
cmd->t_task_lba = transport_lba_32(cdb);
@@ -1106,14 +1164,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
break;
case VERIFY:
case VERIFY_16:
- size = 0;
- if (cdb[0] == VERIFY) {
- sectors = transport_get_sectors_10(cdb);
- cmd->t_task_lba = transport_lba_32(cdb);
- } else {
- sectors = transport_get_sectors_16(cdb);
- cmd->t_task_lba = transport_lba_64(cdb);
- }
+ ret = sbc_parse_verify(cmd, §ors, &size);
+ if (ret)
+ return ret;
cmd->execute_cmd = sbc_emulate_noop;
goto check_lba;
case REZERO_UNIT:
--
2.12.0
next parent reply other threads:[~2017-03-30 17:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20170330171244.8346-1-bart.vanassche@sandisk.com>
2017-03-30 17:12 ` Bart Van Assche [this message]
2017-04-02 22:43 ` [PATCH 1/6] target: Fix VERIFY and WRITE VERIFY command parsing Nicholas A. Bellinger
2017-03-30 17:12 ` [PATCH 2/6] target/iscsi: Call .iscsit_release_cmd() once Bart Van Assche
2017-04-02 22:59 ` Nicholas A. Bellinger
2017-04-04 5:06 ` Varun Prakash
2017-04-13 7:44 ` Varun Prakash
2017-05-02 4:33 ` Nicholas A. Bellinger
2017-05-07 12:52 ` Varun Prakash
2017-05-09 7:49 ` Nicholas A. Bellinger
2017-05-10 16:03 ` Varun Prakash
2017-11-01 0:07 ` Bart Van Assche
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=20170330171244.8346-2-bart.vanassche@sandisk.com \
--to=bart.vanassche@sandisk.com \
--cc=nab@linux-iscsi.org \
--cc=post@wickenrode.com \
--cc=stable@vger.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).