From ba3adc4367df75113883bc6e653afe01bed86adc Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 6 Jun 2019 17:35:47 +0800 Subject: [PATCH] iscsi: return the correct error code in spdk_iscsi_read_pdu We shoud not always return SPDK_ISCSI_CONNECTION_FATAL in spdk_iscsi_read_pdu function. Reason: In iscsi_conn_handle_incoming_pdus, the loop directly return only rc==SPDK_ISCSI_CONNECTION_FATAL. But it masks all the necessary information. So we would like to keep some information of the return value for spdk_iscsi_read_pdu, and we can use error log to track those information. Then we can return SPDK_ISCSI_CONNECTION_FATAL as the error return value for iscsi_conn_handle_incoming_pdus function. Signed-off-by: Ziye Yang Change-Id: I4c40fcb27052b55cb92e06273701a881def18e12 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457078 Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Tested-by: SPDK CI Jenkins --- lib/iscsi/conn.c | 9 +++++---- lib/iscsi/iscsi.c | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 904b08a49..ea2cffe4a 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -1353,8 +1353,9 @@ iscsi_conn_handle_incoming_pdus(struct spdk_iscsi_conn *conn) rc = spdk_iscsi_read_pdu(conn, &pdu); if (rc == 0) { break; - } else if (rc == SPDK_ISCSI_CONNECTION_FATAL) { - return rc; + } else if (rc < 0) { + SPDK_ERRLOG("Failed to read pdu, error=%d\n", rc); + return SPDK_ISCSI_CONNECTION_FATAL; } if (conn->state == ISCSI_CONN_STATE_LOGGED_OUT) { @@ -1365,11 +1366,11 @@ iscsi_conn_handle_incoming_pdus(struct spdk_iscsi_conn *conn) rc = spdk_iscsi_execute(conn, pdu); spdk_put_pdu(pdu); - if (rc != 0) { + if (rc < 0) { SPDK_ERRLOG("spdk_iscsi_execute() fatal error on %s(%s)\n", conn->target_port != NULL ? spdk_scsi_port_get_name(conn->target_port) : "NULL", conn->initiator_port != NULL ? spdk_scsi_port_get_name(conn->initiator_port) : "NULL"); - return rc; + return SPDK_ISCSI_CONNECTION_FATAL; } spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0); diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 5a0e8a174..a3e8aa1f1 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -485,6 +485,7 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) } else { SPDK_ERRLOG("Data(%d) > MaxSegment(%d)\n", data_len, SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH); + rc = SPDK_ISCSI_CONNECTION_FATAL; goto error; } pdu->mobj = spdk_mempool_get(pool); @@ -560,6 +561,7 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) rc = MATCH_DIGEST_WORD(pdu->header_digest, crc32c); if (rc == 0) { SPDK_ERRLOG("header digest error (%s)\n", conn->initiator_name); + rc = SPDK_ISCSI_CONNECTION_FATAL; goto error; } } @@ -567,6 +569,7 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) crc32c = spdk_iscsi_pdu_calc_data_digest(pdu); rc = MATCH_DIGEST_WORD(pdu->data_digest, crc32c); if (rc == 0) { + rc = SPDK_ISCSI_CONNECTION_FATAL; SPDK_ERRLOG("data digest error (%s)\n", conn->initiator_name); goto error; } @@ -578,7 +581,7 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) error: spdk_put_pdu(pdu); conn->pdu_in_progress = NULL; - return SPDK_ISCSI_CONNECTION_FATAL; + return rc; } struct _iscsi_sgl {