From 43f695d93961192ef2dda814f4a2248459117b23 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Thu, 17 Oct 2019 08:03:07 +0900 Subject: [PATCH] lib/iscsi: Move PDU header handling before data buffer allocation To use zero copy bdev I/O APIs for write I/O, we have to allocate iSCSI task before allocating data buffer because allocating data buffer will be changed to spdk_bdev_zcopy_start() call and the allocated iSCSI task will be passed to the call. One critical change is that we have to read all data for the current PDU even if handling the PDU is rejected. For that purpose, use is_rejected flag and do not call iscsi_pdu_payload_handle() is is_rejected is true. If iscsi_pdu_hdr_handle() returns negative, close the connection, so return the state machine immediately. Signed-off-by: Shuhei Matsumoto Change-Id: Ice77b7266af8ac392d9094478523e6e6fe6d131a Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470413 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Community-CI: Broadcom SPDK FC-NVMe CI --- lib/iscsi/iscsi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 690619956..f189a5492 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -4870,6 +4870,13 @@ iscsi_read_pdu(struct spdk_iscsi_conn *conn) } } + rc = iscsi_pdu_hdr_handle(conn, pdu); + if (rc < 0) { + SPDK_ERRLOG("Critical error is detected. Close the connection\n"); + conn->pdu_recv_state = ISCSI_PDU_RECV_STATE_ERROR; + break; + } + conn->pdu_recv_state = ISCSI_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD; break; case ISCSI_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD: @@ -4953,9 +4960,10 @@ iscsi_read_pdu(struct spdk_iscsi_conn *conn) break; } - rc = iscsi_pdu_hdr_handle(conn, pdu); - if (rc == 0 && !pdu->is_rejected) { + if (!pdu->is_rejected) { rc = iscsi_pdu_payload_handle(conn, pdu); + } else { + rc = 0; } if (rc == 0) { spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0);