iscsi: Refactor spdk_iscsi_conn_free

Current implementation is a little complicated and a little
refactoring will improve maintainability.

Change-Id: I23bdbe6a0e14739631c4b4f211bedefc9742f410
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/436447
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-12-07 16:22:25 +09:00 committed by Jim Harris
parent dbad9e1e60
commit 72caa1d06b

View File

@ -454,16 +454,17 @@ spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
{
struct spdk_iscsi_sess *sess;
int idx;
uint32_t i, j;
uint32_t i;
pthread_mutex_lock(&g_conns_mutex);
if (conn->sess == NULL) {
goto end;
}
idx = -1;
sess = conn->sess;
conn->sess = NULL;
if (sess == NULL) {
goto end;
}
for (i = 0; i < sess->connections; i++) {
if (sess->conns[i] == conn) {
@ -472,31 +473,26 @@ spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
}
}
if (sess->connections < 1) {
SPDK_ERRLOG("zero connection\n");
sess->connections = 0;
if (idx < 0) {
SPDK_ERRLOG("remove conn not found\n");
} else {
if (idx < 0) {
SPDK_ERRLOG("remove conn not found\n");
} else {
for (j = idx; j < sess->connections - 1; j++) {
sess->conns[j] = sess->conns[j + 1];
}
sess->conns[sess->connections - 1] = NULL;
for (i = idx; i < sess->connections - 1; i++) {
sess->conns[i] = sess->conns[i + 1];
}
sess->conns[sess->connections - 1] = NULL;
sess->connections--;
if (sess->connections == 0) {
/* cleanup last connection */
SPDK_DEBUGLOG(SPDK_LOG_ISCSI,
"cleanup last conn free sess\n");
spdk_free_sess(sess);
}
}
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Terminating connections(tsih %d): %d\n",
sess->tsih, sess->connections);
if (sess->connections == 0) {
/* cleanup last connection */
SPDK_DEBUGLOG(SPDK_LOG_ISCSI,
"cleanup last conn free sess\n");
spdk_free_sess(sess);
}
end:
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "cleanup free conn\n");
_spdk_iscsi_conn_free(conn);