iscsi: Simplify duplicated target pointers in iscsi_op_login_phase_none
conn->target is initialized to NULL in iscsi_op_login_phase_none and then configured in iscsi_op_login_session_normal. Hence subsequent references to target node can be done by conn->target and related local variables can be removed. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I68b94cb8e136522ef1e0ed74c0035ec2b666bb9e Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/463700 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
8f71ab3a2b
commit
1738ec7a9e
@ -1459,9 +1459,9 @@ iscsi_op_login_session_normal(struct spdk_iscsi_conn *conn,
|
||||
struct spdk_iscsi_pdu *rsp_pdu,
|
||||
char *initiator_port_name,
|
||||
struct iscsi_param *params,
|
||||
struct spdk_iscsi_tgt_node **target,
|
||||
int cid)
|
||||
{
|
||||
struct spdk_iscsi_tgt_node *target = NULL;
|
||||
const char *target_name;
|
||||
const char *target_short_name;
|
||||
struct iscsi_bhs_login_rsp *rsph;
|
||||
@ -1495,16 +1495,16 @@ iscsi_op_login_session_normal(struct spdk_iscsi_conn *conn,
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_spdk_iscsi.mutex);
|
||||
rc = iscsi_op_login_check_target(conn, rsp_pdu, target_name, target);
|
||||
rc = iscsi_op_login_check_target(conn, rsp_pdu, target_name, &target);
|
||||
pthread_mutex_unlock(&g_spdk_iscsi.mutex);
|
||||
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
conn->target = *target;
|
||||
conn->dev = (*target)->dev;
|
||||
conn->target_port = spdk_scsi_dev_find_port_by_id((*target)->dev,
|
||||
conn->target = target;
|
||||
conn->dev = target->dev;
|
||||
conn->target_port = spdk_scsi_dev_find_port_by_id(target->dev,
|
||||
conn->portal->group->tag);
|
||||
|
||||
rc = iscsi_op_login_check_session(conn, rsp_pdu,
|
||||
@ -1514,12 +1514,12 @@ iscsi_op_login_session_normal(struct spdk_iscsi_conn *conn,
|
||||
}
|
||||
|
||||
/* force target flags */
|
||||
pthread_mutex_lock(&((*target)->mutex));
|
||||
rc = iscsi_op_login_negotiate_chap_param(conn, *target);
|
||||
pthread_mutex_unlock(&((*target)->mutex));
|
||||
pthread_mutex_lock(&target->mutex);
|
||||
rc = iscsi_op_login_negotiate_chap_param(conn, target);
|
||||
pthread_mutex_unlock(&target->mutex);
|
||||
|
||||
if (rc == 0) {
|
||||
rc = iscsi_op_login_negotiate_digest_param(conn, *target);
|
||||
rc = iscsi_op_login_negotiate_digest_param(conn, target);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
@ -1623,13 +1623,15 @@ static int
|
||||
iscsi_op_login_set_conn_info(struct spdk_iscsi_conn *conn,
|
||||
struct spdk_iscsi_pdu *rsp_pdu,
|
||||
char *initiator_port_name,
|
||||
enum session_type session_type,
|
||||
struct spdk_iscsi_tgt_node *target, int cid)
|
||||
enum session_type session_type, int cid)
|
||||
{
|
||||
int rc = 0;
|
||||
struct spdk_iscsi_tgt_node *target;
|
||||
struct iscsi_bhs_login_rsp *rsph;
|
||||
struct spdk_scsi_port *initiator_port;
|
||||
|
||||
target = conn->target;
|
||||
|
||||
rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs;
|
||||
conn->authenticated = false;
|
||||
conn->auth.chap_phase = ISCSI_CHAP_PHASE_WAIT_A;
|
||||
@ -1693,12 +1695,12 @@ static int
|
||||
iscsi_op_login_set_target_info(struct spdk_iscsi_conn *conn,
|
||||
struct spdk_iscsi_pdu *rsp_pdu,
|
||||
enum session_type session_type,
|
||||
int alloc_len,
|
||||
struct spdk_iscsi_tgt_node *target)
|
||||
int alloc_len)
|
||||
{
|
||||
char buf[MAX_TMPBUF];
|
||||
const char *val;
|
||||
int rc = 0;
|
||||
struct spdk_iscsi_tgt_node *target = conn->target;
|
||||
struct spdk_iscsi_portal *portal = conn->portal;
|
||||
|
||||
/* declarative parameters */
|
||||
@ -1774,7 +1776,6 @@ iscsi_op_login_phase_none(struct spdk_iscsi_conn *conn,
|
||||
enum session_type session_type;
|
||||
char initiator_port_name[MAX_INITIATOR_PORT_NAME];
|
||||
struct iscsi_bhs_login_rsp *rsph;
|
||||
struct spdk_iscsi_tgt_node *target = NULL;
|
||||
int rc = 0;
|
||||
rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs;
|
||||
|
||||
@ -1796,13 +1797,12 @@ iscsi_op_login_phase_none(struct spdk_iscsi_conn *conn,
|
||||
if (session_type == SESSION_TYPE_NORMAL) {
|
||||
rc = iscsi_op_login_session_normal(conn, rsp_pdu,
|
||||
initiator_port_name,
|
||||
params, &target, cid);
|
||||
params, cid);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
} else if (session_type == SESSION_TYPE_DISCOVERY) {
|
||||
target = NULL;
|
||||
rsph->tsih = 0;
|
||||
|
||||
/* force target flags */
|
||||
@ -1821,7 +1821,7 @@ iscsi_op_login_phase_none(struct spdk_iscsi_conn *conn,
|
||||
}
|
||||
|
||||
rc = iscsi_op_login_set_conn_info(conn, rsp_pdu, initiator_port_name,
|
||||
session_type, target, cid);
|
||||
session_type, cid);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
@ -1839,7 +1839,7 @@ iscsi_op_login_phase_none(struct spdk_iscsi_conn *conn,
|
||||
}
|
||||
|
||||
return iscsi_op_login_set_target_info(conn, rsp_pdu, session_type,
|
||||
alloc_len, target);
|
||||
alloc_len);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -157,14 +157,13 @@ op_login_check_target_test(void)
|
||||
static void
|
||||
op_login_session_normal_test(void)
|
||||
{
|
||||
struct spdk_iscsi_conn conn;
|
||||
struct spdk_iscsi_conn conn = {};
|
||||
struct spdk_iscsi_portal portal;
|
||||
struct spdk_iscsi_portal_grp group;
|
||||
struct spdk_iscsi_pdu rsp_pdu = {};
|
||||
struct iscsi_bhs_login_rsp *rsph;
|
||||
struct spdk_iscsi_sess sess;
|
||||
struct iscsi_param param;
|
||||
struct spdk_iscsi_tgt_node *target;
|
||||
int rc;
|
||||
|
||||
/* setup related data structures */
|
||||
@ -179,7 +178,7 @@ op_login_session_normal_test(void)
|
||||
|
||||
/* expect failure: NULL params for target name */
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
NULL, &target, 0);
|
||||
NULL, 0);
|
||||
CU_ASSERT(rc != 0);
|
||||
CU_ASSERT(rsph->status_class == ISCSI_CLASS_INITIATOR_ERROR);
|
||||
CU_ASSERT(rsph->status_detail == ISCSI_LOGIN_MISSING_PARMS);
|
||||
@ -187,7 +186,7 @@ op_login_session_normal_test(void)
|
||||
/* expect failure: incorrect key for target name */
|
||||
param.next = NULL;
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(rc != 0);
|
||||
CU_ASSERT(rsph->status_class == ISCSI_CLASS_INITIATOR_ERROR);
|
||||
CU_ASSERT(rsph->status_detail == ISCSI_LOGIN_MISSING_PARMS);
|
||||
@ -196,7 +195,7 @@ op_login_session_normal_test(void)
|
||||
param.key = "TargetName";
|
||||
param.val = NULL;
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(rc != 0);
|
||||
CU_ASSERT(rsph->status_class == ISCSI_CLASS_INITIATOR_ERROR);
|
||||
CU_ASSERT(rsph->status_detail == ISCSI_LOGIN_MISSING_PARMS);
|
||||
@ -208,7 +207,7 @@ op_login_session_normal_test(void)
|
||||
"%s", UT_INITIATOR_NAME1);
|
||||
rsph->tsih = 1; /* to append the session */
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(conn.target_port == NULL);
|
||||
CU_ASSERT(rc != 0);
|
||||
CU_ASSERT(rsph->status_class == ISCSI_CLASS_INITIATOR_ERROR);
|
||||
@ -222,7 +221,7 @@ op_login_session_normal_test(void)
|
||||
rsph->tsih = UT_ISCSI_TSIH >> 8; /* to append the session */
|
||||
sess.tag = 1;
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(conn.target_port == NULL);
|
||||
CU_ASSERT(rc != 0);
|
||||
CU_ASSERT(rsph->status_class == ISCSI_CLASS_INITIATOR_ERROR);
|
||||
@ -232,14 +231,14 @@ op_login_session_normal_test(void)
|
||||
rsph->tsih = 0; /* to create the session */
|
||||
g_spdk_iscsi.AllowDuplicateIsid = false;
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
/* expect suceess: create the session */
|
||||
rsph->tsih = 0; /* to create the session */
|
||||
g_spdk_iscsi.AllowDuplicateIsid = true;
|
||||
rc = iscsi_op_login_session_normal(&conn, &rsp_pdu, UT_INITIATOR_NAME1,
|
||||
¶m, &target, 0);
|
||||
¶m, 0);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
free(g_spdk_iscsi.session);
|
||||
|
Loading…
Reference in New Issue
Block a user