lib/iscsi: Separate PDU header and payload handling
Extract PDU header handling from PDU payload handling for all PDU types, and then group them into a new function iscsi_pdu_hdr_handle(). Then the original iscsi_execute() is renamed to iscsi_pdu_payload_handle(). Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I1fb1937cfaf502797f2c4edb3aeeb97d4697c7d4 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471015 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
50bd0364d6
commit
8f9b34dd74
@ -2201,9 +2201,8 @@ iscsi_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
struct iscsi_param *params = NULL;
|
struct iscsi_param *params = NULL;
|
||||||
int cid;
|
int cid;
|
||||||
|
|
||||||
rc = iscsi_pdu_hdr_op_login(conn, pdu);
|
if (conn->login_rsp_pdu == NULL) {
|
||||||
if (rc != 0 || pdu->is_rejected || conn->login_rsp_pdu == NULL) {
|
return 0;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp_pdu = conn->login_rsp_pdu;
|
rsp_pdu = conn->login_rsp_pdu;
|
||||||
@ -2322,11 +2321,6 @@ iscsi_op_text(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
struct iscsi_bhs_text_req *reqh;
|
struct iscsi_bhs_text_req *reqh;
|
||||||
struct iscsi_bhs_text_resp *rsph;
|
struct iscsi_bhs_text_resp *rsph;
|
||||||
|
|
||||||
rc = iscsi_pdu_hdr_op_text(conn, pdu);
|
|
||||||
if (rc != 0 || pdu->is_rejected) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
data_len = 0;
|
data_len = 0;
|
||||||
alloc_len = conn->MaxRecvDataSegmentLength;
|
alloc_len = conn->MaxRecvDataSegmentLength;
|
||||||
|
|
||||||
@ -3491,11 +3485,9 @@ static int
|
|||||||
iscsi_op_scsi(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
iscsi_op_scsi(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
||||||
{
|
{
|
||||||
struct spdk_iscsi_task *task;
|
struct spdk_iscsi_task *task;
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = iscsi_pdu_hdr_op_scsi(conn, pdu);
|
if (pdu->task == NULL) {
|
||||||
if (rc != 0 || pdu->is_rejected || pdu->task == NULL) {
|
return 0;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task = pdu->task;
|
task = pdu->task;
|
||||||
@ -3983,12 +3975,6 @@ iscsi_op_nopout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
uint32_t task_tag;
|
uint32_t task_tag;
|
||||||
int I_bit;
|
int I_bit;
|
||||||
int data_len;
|
int data_len;
|
||||||
int rc;
|
|
||||||
|
|
||||||
rc = iscsi_pdu_hdr_op_nopout(conn, pdu);
|
|
||||||
if (rc != 0 || pdu->is_rejected) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
reqh = (struct iscsi_bhs_nop_out *)&pdu->bhs;
|
reqh = (struct iscsi_bhs_nop_out *)&pdu->bhs;
|
||||||
I_bit = reqh->immediate;
|
I_bit = reqh->immediate;
|
||||||
@ -4502,9 +4488,8 @@ iscsi_op_data(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
int F_bit;
|
int F_bit;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = iscsi_pdu_hdr_op_data(conn, pdu);
|
if (pdu->task == NULL) {
|
||||||
if (rc != 0 || pdu->is_rejected || pdu->task == NULL) {
|
return 0;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subtask = pdu->task;
|
subtask = pdu->task;
|
||||||
@ -4667,7 +4652,7 @@ iscsi_update_cmdsn(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
iscsi_pdu_hdr_handle(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
||||||
{
|
{
|
||||||
int opcode;
|
int opcode;
|
||||||
int rc;
|
int rc;
|
||||||
@ -4682,11 +4667,7 @@ iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "opcode %x\n", opcode);
|
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "opcode %x\n", opcode);
|
||||||
|
|
||||||
if (opcode == ISCSI_OP_LOGIN) {
|
if (opcode == ISCSI_OP_LOGIN) {
|
||||||
rc = iscsi_op_login(conn, pdu);
|
return iscsi_pdu_hdr_op_login(conn, pdu);
|
||||||
if (rc < 0) {
|
|
||||||
SPDK_ERRLOG("iscsi_op_login() failed\n");
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connection in login phase but receive non-login opcode
|
/* connection in login phase but receive non-login opcode
|
||||||
@ -4714,18 +4695,18 @@ iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case ISCSI_OP_NOPOUT:
|
case ISCSI_OP_NOPOUT:
|
||||||
rc = iscsi_op_nopout(conn, pdu);
|
rc = iscsi_pdu_hdr_op_nopout(conn, pdu);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ISCSI_OP_SCSI:
|
case ISCSI_OP_SCSI:
|
||||||
rc = iscsi_op_scsi(conn, pdu);
|
rc = iscsi_pdu_hdr_op_scsi(conn, pdu);
|
||||||
break;
|
break;
|
||||||
case ISCSI_OP_TASK:
|
case ISCSI_OP_TASK:
|
||||||
rc = iscsi_pdu_hdr_op_task(conn, pdu);
|
rc = iscsi_pdu_hdr_op_task(conn, pdu);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ISCSI_OP_TEXT:
|
case ISCSI_OP_TEXT:
|
||||||
rc = iscsi_op_text(conn, pdu);
|
rc = iscsi_pdu_hdr_op_text(conn, pdu);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ISCSI_OP_LOGOUT:
|
case ISCSI_OP_LOGOUT:
|
||||||
@ -4733,7 +4714,7 @@ iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ISCSI_OP_SCSI_DATAOUT:
|
case ISCSI_OP_SCSI_DATAOUT:
|
||||||
rc = iscsi_op_data(conn, pdu);
|
rc = iscsi_pdu_hdr_op_data(conn, pdu);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ISCSI_OP_SNACK:
|
case ISCSI_OP_SNACK:
|
||||||
@ -4746,7 +4727,54 @@ iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
SPDK_ERRLOG("processing PDU (opcode=%x) failed on %s(%s)\n",
|
SPDK_ERRLOG("processing PDU header (opcode=%x) failed on %s(%s)\n",
|
||||||
|
opcode,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
iscsi_pdu_payload_handle(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
||||||
|
{
|
||||||
|
int opcode;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
opcode = pdu->bhs.opcode;
|
||||||
|
|
||||||
|
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "opcode %x\n", opcode);
|
||||||
|
|
||||||
|
switch (opcode) {
|
||||||
|
case ISCSI_OP_LOGIN:
|
||||||
|
rc = iscsi_op_login(conn, pdu);
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_NOPOUT:
|
||||||
|
rc = iscsi_op_nopout(conn, pdu);
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_SCSI:
|
||||||
|
rc = iscsi_op_scsi(conn, pdu);
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_TASK:
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_TEXT:
|
||||||
|
rc = iscsi_op_text(conn, pdu);
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_LOGOUT:
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_SCSI_DATAOUT:
|
||||||
|
rc = iscsi_op_data(conn, pdu);
|
||||||
|
break;
|
||||||
|
case ISCSI_OP_SNACK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SPDK_ERRLOG("unsupported opcode %x\n", opcode);
|
||||||
|
return iscsi_reject(conn, pdu, ISCSI_REASON_PROTOCOL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc < 0) {
|
||||||
|
SPDK_ERRLOG("processing PDU payload (opcode=%x) failed on %s(%s)\n",
|
||||||
opcode,
|
opcode,
|
||||||
conn->target_port != NULL ? spdk_scsi_port_get_name(conn->target_port) : "NULL",
|
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");
|
conn->initiator_port != NULL ? spdk_scsi_port_get_name(conn->initiator_port) : "NULL");
|
||||||
@ -4925,7 +4953,10 @@ iscsi_read_pdu(struct spdk_iscsi_conn *conn)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = iscsi_execute(conn, pdu);
|
rc = iscsi_pdu_hdr_handle(conn, pdu);
|
||||||
|
if (rc == 0 && !pdu->is_rejected) {
|
||||||
|
rc = iscsi_pdu_payload_handle(conn, pdu);
|
||||||
|
}
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0);
|
spdk_trace_record(TRACE_ISCSI_TASK_EXECUTED, 0, 0, (uintptr_t)pdu, 0);
|
||||||
spdk_put_pdu(pdu);
|
spdk_put_pdu(pdu);
|
||||||
|
@ -295,7 +295,10 @@ maxburstlength_test(void)
|
|||||||
req->write_bit = 1;
|
req->write_bit = 1;
|
||||||
req->final_bit = 1;
|
req->final_bit = 1;
|
||||||
|
|
||||||
rc = iscsi_execute(&conn, req_pdu);
|
rc = iscsi_pdu_hdr_handle(&conn, req_pdu);
|
||||||
|
if (rc == 0 && !req_pdu->is_rejected) {
|
||||||
|
rc = iscsi_pdu_payload_handle(&conn, req_pdu);
|
||||||
|
}
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
|
|
||||||
response_pdu = TAILQ_FIRST(&g_write_pdu_list);
|
response_pdu = TAILQ_FIRST(&g_write_pdu_list);
|
||||||
@ -320,7 +323,10 @@ maxburstlength_test(void)
|
|||||||
data_out->ttt = r2t->ttt;
|
data_out->ttt = r2t->ttt;
|
||||||
DSET24(data_out->data_segment_len, 1028);
|
DSET24(data_out->data_segment_len, 1028);
|
||||||
|
|
||||||
rc = iscsi_execute(&conn, data_out_pdu);
|
rc = iscsi_pdu_hdr_handle(&conn, data_out_pdu);
|
||||||
|
if (rc == 0 && !data_out_pdu->is_rejected) {
|
||||||
|
rc = iscsi_pdu_payload_handle(&conn, data_out_pdu);
|
||||||
|
}
|
||||||
CU_ASSERT(rc == SPDK_ISCSI_CONNECTION_FATAL);
|
CU_ASSERT(rc == SPDK_ISCSI_CONNECTION_FATAL);
|
||||||
|
|
||||||
SPDK_CU_ASSERT_FATAL(response_pdu->task != NULL);
|
SPDK_CU_ASSERT_FATAL(response_pdu->task != NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user