From 16d5a6155a88839a29fc309d1ed7fa14101e28c1 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Sat, 18 Jan 2020 00:57:40 +0800 Subject: [PATCH] lib/iscsi: Using async writev for ISCSI_OP_LOGIN_RSP PDU Change-Id: Ia69c996c731dfd89702bbb28468d8798c391034d Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/481922 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Community-CI: SPDK CI Jenkins Tested-by: SPDK CI Jenkins --- lib/iscsi/conn.c | 3 +- lib/iscsi/iscsi.c | 73 ++++++++++++++------------ test/unit/lib/iscsi/iscsi.c/iscsi_ut.c | 6 +-- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 0b4993999..5d2f5577c 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -1502,8 +1502,7 @@ spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *p spdk_trace_record(TRACE_ISCSI_FLUSH_WRITEBUF_START, conn->id, pdu->mapped_length, (uintptr_t)pdu, pdu->sock_req.iovcnt); - if (spdk_unlikely((pdu->bhs.opcode == ISCSI_OP_LOGIN_RSP) || - (pdu->bhs.opcode == ISCSI_OP_LOGOUT_RSP))) { + if (spdk_unlikely(pdu->bhs.opcode == ISCSI_OP_LOGOUT_RSP)) { rc = spdk_sock_writev(conn->sock, pdu->iov, pdu->sock_req.iovcnt); if (rc == pdu->mapped_length) { _iscsi_conn_pdu_write_done(pdu, 0); diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index eddb38aa5..d7e202ca0 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -1123,15 +1123,39 @@ iscsi_conn_params_update(struct spdk_iscsi_conn *conn) return rc; } +static void +iscsi_conn_login_pdu_err_complete(void *arg) +{ + struct spdk_iscsi_conn *conn = arg; + + if (conn->full_feature) { + iscsi_conn_params_update(conn); + } +} + +static void +iscsi_conn_login_pdu_success_complete(void *arg) +{ + struct spdk_iscsi_conn *conn = arg; + + if (conn->full_feature) { + if (iscsi_conn_params_update(conn) != 0) { + return; + } + } + conn->state = ISCSI_CONN_STATE_RUNNING; + if (conn->full_feature != 0) { + spdk_iscsi_conn_schedule(conn); + } +} + /* * The response function of spdk_iscsi_op_login - * return: - * 0:success; - * -1:error; */ -static int +static void iscsi_op_login_response(struct spdk_iscsi_conn *conn, - struct spdk_iscsi_pdu *rsp_pdu, struct iscsi_param *params) + struct spdk_iscsi_pdu *rsp_pdu, struct iscsi_param *params, + iscsi_conn_xfer_complete_cb cb_fn) { struct iscsi_bhs_login_rsp *rsph; @@ -1160,16 +1184,8 @@ iscsi_op_login_response(struct spdk_iscsi_conn *conn, rsph->flags &= ~ISCSI_LOGIN_CURRENT_STAGE_MASK; rsph->flags &= ~ISCSI_LOGIN_NEXT_STAGE_MASK; } - spdk_iscsi_param_free(params); - spdk_iscsi_conn_write_pdu(conn, rsp_pdu, spdk_iscsi_conn_pdu_generic_complete, NULL); - - /* after send PDU digest on/off */ - if (conn->full_feature) { - return iscsi_conn_params_update(conn); - } - - return 0; + spdk_iscsi_conn_write_pdu(conn, rsp_pdu, cb_fn, conn); } /* @@ -2173,8 +2189,8 @@ iscsi_pdu_hdr_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) } rc = iscsi_op_login_rsp_init(conn, pdu, rsp_pdu); if (rc < 0) { - iscsi_op_login_response(conn, rsp_pdu, NULL); - return rc; + iscsi_op_login_response(conn, rsp_pdu, NULL, iscsi_conn_login_pdu_err_complete); + return 0; } conn->login_rsp_pdu = rsp_pdu; @@ -2201,35 +2217,26 @@ iscsi_pdu_payload_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu * rc = iscsi_op_login_store_incoming_params(conn, pdu, rsp_pdu, ¶ms); if (rc < 0) { - iscsi_op_login_response(conn, rsp_pdu, NULL); - return rc; + iscsi_op_login_response(conn, rsp_pdu, NULL, iscsi_conn_login_pdu_err_complete); + return 0; } if (conn->state == ISCSI_CONN_STATE_INVALID) { rc = iscsi_op_login_phase_none(conn, rsp_pdu, params, cid); if (rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE || rc == SPDK_ISCSI_LOGIN_ERROR_PARAMETER) { - iscsi_op_login_response(conn, rsp_pdu, params); - return rc; + iscsi_op_login_response(conn, rsp_pdu, params, iscsi_conn_login_pdu_err_complete); + return 0; } } rc = iscsi_op_login_rsp_handle(conn, rsp_pdu, ¶ms); if (rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE) { - iscsi_op_login_response(conn, rsp_pdu, params); - return rc; + iscsi_op_login_response(conn, rsp_pdu, params, iscsi_conn_login_pdu_err_complete); + return 0; } - rc = iscsi_op_login_response(conn, rsp_pdu, params); - if (rc == 0) { - conn->state = ISCSI_CONN_STATE_RUNNING; - if (conn->full_feature != 0) { - spdk_iscsi_conn_schedule(conn); - } - } else { - SPDK_ERRLOG("login error - connection will be destroyed\n"); - } - - return rc; + iscsi_op_login_response(conn, rsp_pdu, params, iscsi_conn_login_pdu_success_complete); + return 0; } static int diff --git a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c index 32372585c..c62b43207 100644 --- a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c +++ b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c @@ -1350,7 +1350,7 @@ pdu_hdr_op_login_test(void) login_reqh->flags |= ISCSI_LOGIN_CONTINUE; rc = iscsi_pdu_hdr_op_login(&conn, &pdu); - CU_ASSERT(rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE); + CU_ASSERT(rc == 0); check_login_response(ISCSI_CLASS_INITIATOR_ERROR, ISCSI_LOGIN_INITIATOR_ERROR); /* Case 5 - Both version-min and version-max must be set to 0x00. */ @@ -1358,7 +1358,7 @@ pdu_hdr_op_login_test(void) login_reqh->version_min = ISCSI_VERSION + 1; rc = iscsi_pdu_hdr_op_login(&conn, &pdu); - CU_ASSERT(rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE); + CU_ASSERT(rc == 0); check_login_response(ISCSI_CLASS_INITIATOR_ERROR, ISCSI_LOGIN_UNSUPPORTED_VERSION); /* Case 6 - T bit is set to 1 correctly but invalid stage code is set to NSG. */ @@ -1367,7 +1367,7 @@ pdu_hdr_op_login_test(void) login_reqh->flags |= ISCSI_NSG_RESERVED_CODE; rc = iscsi_pdu_hdr_op_login(&conn, &pdu); - CU_ASSERT(rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE); + CU_ASSERT(rc == 0); check_login_response(ISCSI_CLASS_INITIATOR_ERROR, ISCSI_LOGIN_INITIATOR_ERROR); /* Case 7 - Login request is correct. Login response is initialized and set to