aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSagi Grimberg <sagig@mellanox.com>2014-06-11 05:09:58 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2014-06-11 16:06:45 -0400
commitd77e65350f2d82dfa0557707d505711f5a43c8fd (patch)
tree04adddbd63d60ebdaae4ee5a7c320dd6b9412d76
parent8846bab180fa2bcfe02d4ba5288fbaba12c8f4f3 (diff)
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: Sagi Grimberg <sagig@mellanox.com> Reviewed-by: Mike Christie <michaelc@cs.wisc.edu> Acked-by: Mike Christie <michaelc@cs.wisc.edu> Cc: stable@vger.kernel.org # 3.15+ Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c34
-rw-r--r--drivers/scsi/libiscsi.c18
2 files changed, 19 insertions, 33 deletions
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index 2e2d903db838..8d44a4060634 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -41,11 +41,11 @@
41#include "iscsi_iser.h" 41#include "iscsi_iser.h"
42 42
43/* Register user buffer memory and initialize passive rdma 43/* Register user buffer memory and initialize passive rdma
44 * dto descriptor. Total data size is stored in 44 * dto descriptor. Data size is stored in
45 * iser_task->data[ISER_DIR_IN].data_len 45 * task->data[ISER_DIR_IN].data_len, Protection size
46 * os stored in task->prot[ISER_DIR_IN].data_len
46 */ 47 */
47static int iser_prepare_read_cmd(struct iscsi_task *task, 48static int iser_prepare_read_cmd(struct iscsi_task *task)
48 unsigned int edtl)
49 49
50{ 50{
51 struct iscsi_iser_task *iser_task = task->dd_data; 51 struct iscsi_iser_task *iser_task = task->dd_data;
@@ -73,14 +73,6 @@ static int iser_prepare_read_cmd(struct iscsi_task *task,
73 return err; 73 return err;
74 } 74 }
75 75
76 if (edtl > iser_task->data[ISER_DIR_IN].data_len) {
77 iser_err("Total data length: %ld, less than EDTL: "
78 "%d, in READ cmd BHS itt: %d, conn: 0x%p\n",
79 iser_task->data[ISER_DIR_IN].data_len, edtl,
80 task->itt, iser_task->ib_conn);
81 return -EINVAL;
82 }
83
84 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_IN); 76 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_IN);
85 if (err) { 77 if (err) {
86 iser_err("Failed to set up Data-IN RDMA\n"); 78 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} 92}
101 93
102/* Register user buffer memory and initialize passive rdma 94/* Register user buffer memory and initialize passive rdma
103 * dto descriptor. Total data size is stored in 95 * dto descriptor. Data size is stored in
104 * task->data[ISER_DIR_OUT].data_len 96 * task->data[ISER_DIR_OUT].data_len, Protection size
97 * is stored at task->prot[ISER_DIR_OUT].data_len
105 */ 98 */
106static int 99static int
107iser_prepare_write_cmd(struct iscsi_task *task, 100iser_prepare_write_cmd(struct iscsi_task *task,
@@ -135,14 +128,6 @@ iser_prepare_write_cmd(struct iscsi_task *task,
135 return err; 128 return err;
136 } 129 }
137 130
138 if (edtl > iser_task->data[ISER_DIR_OUT].data_len) {
139 iser_err("Total data length: %ld, less than EDTL: %d, "
140 "in WRITE cmd BHS itt: %d, conn: 0x%p\n",
141 iser_task->data[ISER_DIR_OUT].data_len,
142 edtl, task->itt, task->conn);
143 return -EINVAL;
144 }
145
146 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_OUT); 131 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_OUT);
147 if (err != 0) { 132 if (err != 0) {
148 iser_err("Failed to register write cmd RDMA mem\n"); 133 iser_err("Failed to register write cmd RDMA mem\n");
@@ -417,11 +402,12 @@ int iser_send_command(struct iscsi_conn *conn,
417 if (scsi_prot_sg_count(sc)) { 402 if (scsi_prot_sg_count(sc)) {
418 prot_buf->buf = scsi_prot_sglist(sc); 403 prot_buf->buf = scsi_prot_sglist(sc);
419 prot_buf->size = scsi_prot_sg_count(sc); 404 prot_buf->size = scsi_prot_sg_count(sc);
420 prot_buf->data_len = sc->prot_sdb->length; 405 prot_buf->data_len = data_buf->data_len >>
406 ilog2(sc->device->sector_size) * 8;
421 } 407 }
422 408
423 if (hdr->flags & ISCSI_FLAG_CMD_READ) { 409 if (hdr->flags & ISCSI_FLAG_CMD_READ) {
424 err = iser_prepare_read_cmd(task, edtl); 410 err = iser_prepare_read_cmd(task);
425 if (err) 411 if (err)
426 goto send_command_error; 412 goto send_command_error;
427 } 413 }
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 26dc005bb0f0..3f462349b16c 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -338,7 +338,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
338 struct iscsi_session *session = conn->session; 338 struct iscsi_session *session = conn->session;
339 struct scsi_cmnd *sc = task->sc; 339 struct scsi_cmnd *sc = task->sc;
340 struct iscsi_scsi_req *hdr; 340 struct iscsi_scsi_req *hdr;
341 unsigned hdrlength, cmd_len; 341 unsigned hdrlength, cmd_len, transfer_length;
342 itt_t itt; 342 itt_t itt;
343 int rc; 343 int rc;
344 344
@@ -391,11 +391,11 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
391 if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL) 391 if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL)
392 task->protected = true; 392 task->protected = true;
393 393
394 transfer_length = scsi_transfer_length(sc);
395 hdr->data_length = cpu_to_be32(transfer_length);
394 if (sc->sc_data_direction == DMA_TO_DEVICE) { 396 if (sc->sc_data_direction == DMA_TO_DEVICE) {
395 unsigned out_len = scsi_out(sc)->length;
396 struct iscsi_r2t_info *r2t = &task->unsol_r2t; 397 struct iscsi_r2t_info *r2t = &task->unsol_r2t;
397 398
398 hdr->data_length = cpu_to_be32(out_len);
399 hdr->flags |= ISCSI_FLAG_CMD_WRITE; 399 hdr->flags |= ISCSI_FLAG_CMD_WRITE;
400 /* 400 /*
401 * Write counters: 401 * Write counters:
@@ -414,18 +414,19 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
414 memset(r2t, 0, sizeof(*r2t)); 414 memset(r2t, 0, sizeof(*r2t));
415 415
416 if (session->imm_data_en) { 416 if (session->imm_data_en) {
417 if (out_len >= session->first_burst) 417 if (transfer_length >= session->first_burst)
418 task->imm_count = min(session->first_burst, 418 task->imm_count = min(session->first_burst,
419 conn->max_xmit_dlength); 419 conn->max_xmit_dlength);
420 else 420 else
421 task->imm_count = min(out_len, 421 task->imm_count = min(transfer_length,
422 conn->max_xmit_dlength); 422 conn->max_xmit_dlength);
423 hton24(hdr->dlength, task->imm_count); 423 hton24(hdr->dlength, task->imm_count);
424 } else 424 } else
425 zero_data(hdr->dlength); 425 zero_data(hdr->dlength);
426 426
427 if (!session->initial_r2t_en) { 427 if (!session->initial_r2t_en) {
428 r2t->data_length = min(session->first_burst, out_len) - 428 r2t->data_length = min(session->first_burst,
429 transfer_length) -
429 task->imm_count; 430 task->imm_count;
430 r2t->data_offset = task->imm_count; 431 r2t->data_offset = task->imm_count;
431 r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG); 432 r2t->ttt = cpu_to_be32(ISCSI_RESERVED_TAG);
@@ -438,7 +439,6 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
438 } else { 439 } else {
439 hdr->flags |= ISCSI_FLAG_CMD_FINAL; 440 hdr->flags |= ISCSI_FLAG_CMD_FINAL;
440 zero_data(hdr->dlength); 441 zero_data(hdr->dlength);
441 hdr->data_length = cpu_to_be32(scsi_in(sc)->length);
442 442
443 if (sc->sc_data_direction == DMA_FROM_DEVICE) 443 if (sc->sc_data_direction == DMA_FROM_DEVICE)
444 hdr->flags |= ISCSI_FLAG_CMD_READ; 444 hdr->flags |= ISCSI_FLAG_CMD_READ;
@@ -466,7 +466,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
466 scsi_bidi_cmnd(sc) ? "bidirectional" : 466 scsi_bidi_cmnd(sc) ? "bidirectional" :
467 sc->sc_data_direction == DMA_TO_DEVICE ? 467 sc->sc_data_direction == DMA_TO_DEVICE ?
468 "write" : "read", conn->id, sc, sc->cmnd[0], 468 "write" : "read", conn->id, sc, sc->cmnd[0],
469 task->itt, scsi_bufflen(sc), 469 task->itt, transfer_length,
470 scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0, 470 scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0,
471 session->cmdsn, 471 session->cmdsn,
472 session->max_cmdsn - session->exp_cmdsn + 1); 472 session->max_cmdsn - session->exp_cmdsn + 1);