Commit d77e6535 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Nicholas Bellinger

libiscsi, iser: Adjust data_length to include protection information

In case protection information exists over the wire
iscsi header data length is required to include it.
Use protection information aware scsi helpers to set
the correct transfer length.

In order to avoid breakage, remove iser transfer length
checks for each task as they are not always true and
somewhat redundant anyway.
Signed-off-by: default avatarSagi Grimberg <sagig@mellanox.com>
Reviewed-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Acked-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Cc: stable@vger.kernel.org # 3.15+
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 8846bab1
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
#include "iscsi_iser.h" #include "iscsi_iser.h"
/* Register user buffer memory and initialize passive rdma /* Register user buffer memory and initialize passive rdma
* dto descriptor. Total data size is stored in * dto descriptor. Data size is stored in
* iser_task->data[ISER_DIR_IN].data_len * task->data[ISER_DIR_IN].data_len, Protection size
* os stored in task->prot[ISER_DIR_IN].data_len
*/ */
static int iser_prepare_read_cmd(struct iscsi_task *task, static int iser_prepare_read_cmd(struct iscsi_task *task)
unsigned int edtl)
{ {
struct iscsi_iser_task *iser_task = task->dd_data; struct iscsi_iser_task *iser_task = task->dd_data;
...@@ -73,14 +73,6 @@ static int iser_prepare_read_cmd(struct iscsi_task *task, ...@@ -73,14 +73,6 @@ static int iser_prepare_read_cmd(struct iscsi_task *task,
return err; return err;
} }
if (edtl > iser_task->data[ISER_DIR_IN].data_len) {
iser_err("Total data length: %ld, less than EDTL: "
"%d, in READ cmd BHS itt: %d, conn: 0x%p\n",
iser_task->data[ISER_DIR_IN].data_len, edtl,
task->itt, iser_task->ib_conn);
return -EINVAL;
}
err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_IN); err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_IN);
if (err) { if (err) {
iser_err("Failed to set up Data-IN RDMA\n"); iser_err("Failed to set up Data-IN RDMA\n");
...@@ -100,8 +92,9 @@ static int iser_prepare_read_cmd(struct iscsi_task *task, ...@@ -100,8 +92,9 @@ static int iser_prepare_read_cmd(struct iscsi_task *task,
} }
/* Register user buffer memory and initialize passive rdma /* Register user buffer memory and initialize passive rdma
* dto descriptor. Total data size is stored in * dto descriptor. Data size is stored in
* task->data[ISER_DIR_OUT].data_len * task->data[ISER_DIR_OUT].data_len, Protection size
* is stored at task->prot[ISER_DIR_OUT].data_len
*/ */
static int static int
iser_prepare_write_cmd(struct iscsi_task *task, iser_prepare_write_cmd(struct iscsi_task *task,
...@@ -135,14 +128,6 @@ iser_prepare_write_cmd(struct iscsi_task *task, ...@@ -135,14 +128,6 @@ iser_prepare_write_cmd(struct iscsi_task *task,
return err; return err;
} }
if (edtl > iser_task->data[ISER_DIR_OUT].data_len) {
iser_err("Total data length: %ld, less than EDTL: %d, "
"in WRITE cmd BHS itt: %d, conn: 0x%p\n",
iser_task->data[ISER_DIR_OUT].data_len,
edtl, task->itt, task->conn);
return -EINVAL;
}
err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_OUT); err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_OUT);
if (err != 0) { if (err != 0) {
iser_err("Failed to register write cmd RDMA mem\n"); iser_err("Failed to register write cmd RDMA mem\n");
...@@ -417,11 +402,12 @@ int iser_send_command(struct iscsi_conn *conn, ...@@ -417,11 +402,12 @@ int iser_send_command(struct iscsi_conn *conn,
if (scsi_prot_sg_count(sc)) { if (scsi_prot_sg_count(sc)) {
prot_buf->buf = scsi_prot_sglist(sc); prot_buf->buf = scsi_prot_sglist(sc);
prot_buf->size = scsi_prot_sg_count(sc); prot_buf->size = scsi_prot_sg_count(sc);
prot_buf->data_len = sc->prot_sdb->length; prot_buf->data_len = data_buf->data_len >>
ilog2(sc->device->sector_size) * 8;
} }
if (hdr->flags & ISCSI_FLAG_CMD_READ) { if (hdr->flags & ISCSI_FLAG_CMD_READ) {
err = iser_prepare_read_cmd(task, edtl); err = iser_prepare_read_cmd(task);
if (err) if (err)
goto send_command_error; goto send_command_error;
} }
......
...@@ -338,7 +338,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) ...@@ -338,7 +338,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
struct iscsi_session *session = conn->session; struct iscsi_session *session = conn->session;
struct scsi_cmnd *sc = task->sc; struct scsi_cmnd *sc = task->sc;
struct iscsi_scsi_req *hdr; struct iscsi_scsi_req *hdr;
unsigned hdrlength, cmd_len; unsigned hdrlength, cmd_len, transfer_length;
itt_t itt; itt_t itt;
int rc; int rc;
...@@ -391,11 +391,11 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) ...@@ -391,11 +391,11 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL) if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL)
task->protected = true; task->protected = true;
transfer_length = scsi_transfer_length(sc);
hdr->data_length = cpu_to_be32(transfer_length);
if (sc->sc_data_direction == DMA_TO_DEVICE) { if (sc->sc_data_direction == DMA_TO_DEVICE) {
unsigned out_len = scsi_out(sc)->length;
struct iscsi_r2t_info *r2t = &task->unsol_r2t; struct iscsi_r2t_info *r2t = &task->unsol_r2t;
hdr->data_length = cpu_to_be32(out_len);
hdr->flags |= ISCSI_FLAG_CMD_WRITE; hdr->flags |= ISCSI_FLAG_CMD_WRITE;
/* /*
* Write counters: * Write counters:
...@@ -414,18 +414,19 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) ...@@ -414,18 +414,19 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
memset(r2t, 0, sizeof(*r2t)); memset(r2t, 0, sizeof(*r2t));
if (session->imm_data_en) { if (session->imm_data_en) {
if (out_len >= session->first_burst) if (transfer_length >= session->first_burst)
task->imm_count = min(session->first_burst, task->imm_count = min(session->first_burst,
conn->max_xmit_dlength); conn->max_xmit_dlength);
else else
task->imm_count = min(out_len, task->imm_count = min(transfer_length,
conn->max_xmit_dlength); conn->max_xmit_dlength);
hton24(hdr->dlength, task->imm_count); hton24(hdr->dlength, task->imm_count);
} else } else
zero_data(hdr->dlength); zero_data(hdr->dlength);
if (!session->initial_r2t_en) { if (!session->initial_r2t_en) {
r2t->data_length = min(session->first_burst, out_len) - r2t->data_length = min(session->first_burst,
transfer_length) -
task->imm_count; task->imm_count;
r2t->data_offset = task->imm_count; r2t->data_offset = task->imm_count;
r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG); r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
...@@ -438,7 +439,6 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) ...@@ -438,7 +439,6 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
} else { } else {
hdr->flags |= ISCSI_FLAG_CMD_FINAL; hdr->flags |= ISCSI_FLAG_CMD_FINAL;
zero_data(hdr->dlength); zero_data(hdr->dlength);
hdr->data_length = cpu_to_be32(scsi_in(sc)->length);
if (sc->sc_data_direction == DMA_FROM_DEVICE) if (sc->sc_data_direction == DMA_FROM_DEVICE)
hdr->flags |= ISCSI_FLAG_CMD_READ; hdr->flags |= ISCSI_FLAG_CMD_READ;
...@@ -466,7 +466,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) ...@@ -466,7 +466,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
scsi_bidi_cmnd(sc) ? "bidirectional" : scsi_bidi_cmnd(sc) ? "bidirectional" :
sc->sc_data_direction == DMA_TO_DEVICE ? sc->sc_data_direction == DMA_TO_DEVICE ?
"write" : "read", conn->id, sc, sc->cmnd[0], "write" : "read", conn->id, sc, sc->cmnd[0],
task->itt, scsi_bufflen(sc), task->itt, transfer_length,
scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0, scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0,
session->cmdsn, session->cmdsn,
session->max_cmdsn - session->exp_cmdsn + 1); session->max_cmdsn - session->exp_cmdsn + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment