nvme/tcp: simplify state change function
state change function do not need to use swtich to do some work. Do memset in state machine. Signed-off-by: MengjinWu <mengjin.wu@intel.com> Change-Id: Ie66454d8f31860f403171f20858a6b4a24e3c76f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14502 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Xiaodong Liu <xiaodong.liu@intel.com>
This commit is contained in:
parent
7a7f21b6fe
commit
31fc5f196f
@ -801,7 +801,7 @@ nvme_tcp_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
nvme_tcp_qpair_set_recv_state(struct nvme_tcp_qpair *tqpair,
|
||||
enum nvme_tcp_pdu_recv_state state)
|
||||
{
|
||||
@ -810,19 +810,7 @@ nvme_tcp_qpair_set_recv_state(struct nvme_tcp_qpair *tqpair,
|
||||
tqpair, state);
|
||||
return;
|
||||
}
|
||||
|
||||
tqpair->recv_state = state;
|
||||
switch (state) {
|
||||
case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY:
|
||||
case NVME_TCP_PDU_RECV_STATE_ERROR:
|
||||
memset(tqpair->recv_pdu, 0, sizeof(struct nvme_tcp_pdu));
|
||||
break;
|
||||
case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH:
|
||||
case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH:
|
||||
case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1623,6 +1611,7 @@ nvme_tcp_read_pdu(struct nvme_tcp_qpair *tqpair, uint32_t *reaped)
|
||||
switch (tqpair->recv_state) {
|
||||
/* If in a new state */
|
||||
case NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY:
|
||||
memset(tqpair->recv_pdu, 0, sizeof(struct nvme_tcp_pdu));
|
||||
nvme_tcp_qpair_set_recv_state(tqpair, NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH);
|
||||
break;
|
||||
/* common header */
|
||||
@ -1698,6 +1687,7 @@ nvme_tcp_read_pdu(struct nvme_tcp_qpair *tqpair, uint32_t *reaped)
|
||||
nvme_tcp_pdu_payload_handle(tqpair, reaped);
|
||||
break;
|
||||
case NVME_TCP_PDU_RECV_STATE_ERROR:
|
||||
memset(tqpair->recv_pdu, 0, sizeof(struct nvme_tcp_pdu));
|
||||
rc = NVME_TCP_PDU_FATAL;
|
||||
break;
|
||||
default:
|
||||
|
@ -787,46 +787,15 @@ static void
|
||||
test_nvme_tcp_qpair_set_recv_state(void)
|
||||
{
|
||||
struct nvme_tcp_qpair tqpair = {};
|
||||
enum nvme_tcp_pdu_recv_state state;
|
||||
struct nvme_tcp_pdu recv_pdu = {};
|
||||
|
||||
tqpair.recv_pdu = &recv_pdu;
|
||||
|
||||
/* case1: The recv state of tqpair is same with the state to be set */
|
||||
tqpair.recv_state = NVME_TCP_PDU_RECV_STATE_ERROR;
|
||||
state = NVME_TCP_PDU_RECV_STATE_ERROR;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
CU_ASSERT(tqpair.recv_state == state);
|
||||
|
||||
/* case2: The recv state of tqpair is different with the state to be set */
|
||||
/* state is NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY or NVME_TCP_PDU_RECV_STATE_ERROR, tqpair->recv_pdu will be cleared */
|
||||
tqpair.recv_pdu->cb_arg = (void *)0xDEADBEEF;
|
||||
state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
CU_ASSERT(tqpair.recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY);
|
||||
CU_ASSERT(tqpair.recv_pdu->cb_arg == (void *)0x0);
|
||||
|
||||
tqpair.recv_pdu->cb_arg = (void *)0xDEADBEEF;
|
||||
state = NVME_TCP_PDU_RECV_STATE_ERROR;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, NVME_TCP_PDU_RECV_STATE_ERROR);
|
||||
CU_ASSERT(tqpair.recv_state == NVME_TCP_PDU_RECV_STATE_ERROR);
|
||||
CU_ASSERT(tqpair.recv_pdu->cb_arg == (void *)0x0);
|
||||
|
||||
/* state is NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH or NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH or NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD or default */
|
||||
state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
CU_ASSERT(tqpair.recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH);
|
||||
|
||||
state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
CU_ASSERT(tqpair.recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PSH);
|
||||
|
||||
state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
CU_ASSERT(tqpair.recv_state == NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_PAYLOAD);
|
||||
|
||||
state = 0xff;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, state);
|
||||
/* Different state will be set accordingly */
|
||||
tqpair.recv_state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY;
|
||||
nvme_tcp_qpair_set_recv_state(&tqpair, 0xff);
|
||||
CU_ASSERT(tqpair.recv_state == 0xff);
|
||||
}
|
||||
|
||||
@ -1424,6 +1393,10 @@ test_nvme_tcp_ctrlr_connect_qpair(void)
|
||||
rc = nvme_tcp_ctrlr_connect_qpair(&ctrlr, qpair);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* skip NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_READY state */
|
||||
/* assume already received the icresp */
|
||||
tqpair->recv_state = NVME_TCP_PDU_RECV_STATE_AWAIT_PDU_CH;
|
||||
|
||||
while (nvme_qpair_get_state(qpair) == NVME_QPAIR_CONNECTING) {
|
||||
rc = nvme_tcp_qpair_process_completions(qpair, 0);
|
||||
CU_ASSERT(rc >= 0);
|
||||
|
Loading…
Reference in New Issue
Block a user