Skip to content

Commit 5d0fddd

Browse files
shlomopongratzJames Bottomley
authored andcommitted
[SCSI] libiscsi: Restructure iscsi_tcp r2t response logic
Restructure the iscsi_tcp_r2t_rsp routine in order to avoid allocating r2t from r2tpool.queue and returning it back in case the parameters rhdr->data_length and or rhdr->data_offset prohibit the requing. Since the values of these parameters are known prior to the allocation, we can pre-check and thus avoid futile allocations. [jejb: checkpatch fixes] Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent ac0245f commit 5d0fddd

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/scsi/libiscsi_tcp.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
529529
struct iscsi_r2t_rsp *rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;
530530
struct iscsi_r2t_info *r2t;
531531
int r2tsn = be32_to_cpu(rhdr->r2tsn);
532+
u32 data_length;
533+
u32 data_offset;
532534
int rc;
533535

534536
if (tcp_conn->in.datalen) {
@@ -554,40 +556,39 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_task *task)
554556
return 0;
555557
}
556558

557-
rc = kfifo_out(&tcp_task->r2tpool.queue, (void*)&r2t, sizeof(void*));
558-
if (!rc) {
559-
iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
560-
"Target has sent more R2Ts than it "
561-
"negotiated for or driver has leaked.\n");
562-
return ISCSI_ERR_PROTO;
563-
}
564-
565-
r2t->exp_statsn = rhdr->statsn;
566-
r2t->data_length = be32_to_cpu(rhdr->data_length);
567-
if (r2t->data_length == 0) {
559+
data_length = be32_to_cpu(rhdr->data_length);
560+
if (data_length == 0) {
568561
iscsi_conn_printk(KERN_ERR, conn,
569562
"invalid R2T with zero data len\n");
570-
kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
571-
sizeof(void*));
572563
return ISCSI_ERR_DATALEN;
573564
}
574565

575-
if (r2t->data_length > session->max_burst)
566+
if (data_length > session->max_burst)
576567
ISCSI_DBG_TCP(conn, "invalid R2T with data len %u and max "
577568
"burst %u. Attempting to execute request.\n",
578-
r2t->data_length, session->max_burst);
569+
data_length, session->max_burst);
579570

580-
r2t->data_offset = be32_to_cpu(rhdr->data_offset);
581-
if (r2t->data_offset + r2t->data_length > scsi_out(task->sc)->length) {
571+
data_offset = be32_to_cpu(rhdr->data_offset);
572+
if (data_offset + data_length > scsi_out(task->sc)->length) {
582573
iscsi_conn_printk(KERN_ERR, conn,
583574
"invalid R2T with data len %u at offset %u "
584-
"and total length %d\n", r2t->data_length,
585-
r2t->data_offset, scsi_out(task->sc)->length);
586-
kfifo_in(&tcp_task->r2tpool.queue, (void*)&r2t,
587-
sizeof(void*));
575+
"and total length %d\n", data_length,
576+
data_offset, scsi_out(task->sc)->length);
588577
return ISCSI_ERR_DATALEN;
589578
}
590579

580+
rc = kfifo_out(&tcp_task->r2tpool.queue, (void *)&r2t, sizeof(void *));
581+
if (!rc) {
582+
iscsi_conn_printk(KERN_ERR, conn, "Could not allocate R2T. "
583+
"Target has sent more R2Ts than it "
584+
"negotiated for or driver has leaked.\n");
585+
return ISCSI_ERR_PROTO;
586+
}
587+
588+
r2t->exp_statsn = rhdr->statsn;
589+
r2t->data_length = data_length;
590+
r2t->data_offset = data_offset;
591+
591592
r2t->ttt = rhdr->ttt; /* no flip */
592593
r2t->datasn = 0;
593594
r2t->sent = 0;

0 commit comments

Comments
 (0)