From 52e2b86b331f195b187e8649052b263ffeca09ce Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 15 Oct 2019 09:38:26 +0900 Subject: [PATCH] lib/iscsi: Move spdk_iscsi_execute() from iscsi_conn_handle_incoming_pdus() to spdk_iscsi_read_pdu() Move spdk_iscsi_execute() from iscsi_conn_handle_incoming_pdus() to spdk_iscsi_read_pdu() and then strip the prefix spdk_ from spdk_iscsi_execute() and make it private. This is to introduce state machine into receive incoming PDU processing. Signed-off-by: Shuhei Matsumoto Change-Id: I5d5b3e55ece0994532e924d3c75d898cb373875c Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470287 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/iscsi/conn.c | 12 +----------- lib/iscsi/iscsi.c | 16 ++++++++++++---- lib/iscsi/iscsi.h | 3 +-- test/unit/lib/iscsi/conn.c/conn_ut.c | 6 +----- test/unit/lib/iscsi/iscsi.c/iscsi_ut.c | 4 ++-- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index eb3a7ec9c..5f0f780cf 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -1396,27 +1396,17 @@ spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *p static int iscsi_conn_handle_incoming_pdus(struct spdk_iscsi_conn *conn) { - struct spdk_iscsi_pdu *pdu; int i, rc; /* Read new PDUs from network */ for (i = 0; i < GET_PDU_LOOP_COUNT; i++) { - rc = spdk_iscsi_read_pdu(conn, &pdu); + rc = spdk_iscsi_read_pdu(conn); if (rc == 0) { break; } else if (rc < 0) { return rc; } - rc = spdk_iscsi_execute(conn, pdu); - if (rc == 0) { - spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0); - } - spdk_put_pdu(pdu); - if (rc < 0) { - return SPDK_ISCSI_CONNECTION_FATAL; - } - if (conn->is_stopped) { break; } diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index e9a9a9fba..7787b7bbf 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -4446,8 +4446,8 @@ remove_acked_pdu(struct spdk_iscsi_conn *conn, uint32_t ExpStatSN) } } -int -spdk_iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) +static int +iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) { int opcode; int rc; @@ -4587,7 +4587,7 @@ spdk_iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) } int -spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) +spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn) { struct spdk_iscsi_pdu *pdu; struct spdk_mempool *pool; @@ -4738,7 +4738,15 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) return SPDK_ISCSI_CONNECTION_FATAL; } - *_pdu = pdu; + rc = iscsi_execute(conn, pdu); + if (rc == 0) { + spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0); + } + spdk_put_pdu(pdu); + if (rc < 0) { + return SPDK_ISCSI_CONNECTION_FATAL; + } + return 1; error: diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index 3d26be9fb..62203e61f 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -410,10 +410,9 @@ void spdk_iscsi_auth_groups_info_json(struct spdk_json_write_ctx *w); void spdk_iscsi_send_nopin(struct spdk_iscsi_conn *conn); void spdk_iscsi_task_response(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *task); -int spdk_iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu); int spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs, int iovcnt, struct spdk_iscsi_pdu *pdu, uint32_t *mapped_length); -int spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu); +int spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn); bool spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, struct spdk_dif_ctx *dif_ctx); void spdk_iscsi_task_mgmt_response(struct spdk_iscsi_conn *conn, diff --git a/test/unit/lib/iscsi/conn.c/conn_ut.c b/test/unit/lib/iscsi/conn.c/conn_ut.c index 4f66a8524..31fca067a 100644 --- a/test/unit/lib/iscsi/conn.c/conn_ut.c +++ b/test/unit/lib/iscsi/conn.c/conn_ut.c @@ -142,17 +142,13 @@ DEFINE_STUB_V(spdk_iscsi_task_mgmt_response, DEFINE_STUB_V(spdk_iscsi_send_nopin, (struct spdk_iscsi_conn *conn)); -DEFINE_STUB(spdk_iscsi_execute, int, - (struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu), 0); - DEFINE_STUB_V(spdk_del_transfer_task, (struct spdk_iscsi_conn *conn, uint32_t task_tag)); DEFINE_STUB(spdk_iscsi_conn_handle_queued_datain_tasks, int, (struct spdk_iscsi_conn *conn), 0); -DEFINE_STUB(spdk_iscsi_read_pdu, int, - (struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu), 0); +DEFINE_STUB(spdk_iscsi_read_pdu, int, (struct spdk_iscsi_conn *conn), 0); DEFINE_STUB_V(spdk_free_sess, (struct spdk_iscsi_sess *sess)); diff --git a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c index 9ebeed1f0..bb7ec6107 100644 --- a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c +++ b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c @@ -295,7 +295,7 @@ maxburstlength_test(void) req->write_bit = 1; req->final_bit = 1; - rc = spdk_iscsi_execute(&conn, req_pdu); + rc = iscsi_execute(&conn, req_pdu); CU_ASSERT(rc == 0); response_pdu = TAILQ_FIRST(&g_write_pdu_list); @@ -320,7 +320,7 @@ maxburstlength_test(void) data_out->ttt = r2t->ttt; DSET24(data_out->data_segment_len, 1028); - rc = spdk_iscsi_execute(&conn, data_out_pdu); + rc = iscsi_execute(&conn, data_out_pdu); CU_ASSERT(rc == SPDK_ISCSI_CONNECTION_FATAL); SPDK_CU_ASSERT_FATAL(response_pdu->task != NULL);