iscsi: Refine name and nesting structure of connection removal

Following change will make iSCSI connection management easier to read.

Before:
- _spdk_iscsi_conn_free(conn) is called by _spdk_iscsi_conn_check_shutdown(conn)
  or _spdk_iscsi_conn_destruct(conn).
- spdk_iscsi_conn_remove_conn(conn) is called by _spdk_iscsi_conn_free(conn).
- spdk_iscsi_conn_free(conn) is called by spdk_iscsi_remove_conn(conn).

After
- spdk_iscsi_conn_free(conn) is called by _spdk_iscsi_conn_check_shutdown(conn)
  or _spdk_iscsi_conn_destruct(conn).
- _spdk_iscsi_conn_free(conn) is called by spdk_iscsi_conn_free(conn).

This refinement is done by the following:
- Call _func() by func(). func() is parent of _func().
- Inline spdk_iscsi_conn_remove_conn(conn) into _spdk_iscsi_conn_free(conn).

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

View File

@ -411,7 +411,8 @@ static int spdk_iscsi_conn_free_tasks(struct spdk_iscsi_conn *conn)
return 0;
}
static void spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
static void
_spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
{
if (conn == NULL) {
return;
@ -428,18 +429,40 @@ static void spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
free_conn(conn);
}
static void spdk_iscsi_remove_conn(struct spdk_iscsi_conn *conn)
static void
spdk_iscsi_conn_cleanup_backend(struct spdk_iscsi_conn *conn)
{
int rc;
struct spdk_iscsi_tgt_node *target;
if (conn->sess->connections > 1) {
/* connection specific cleanup */
} else if (!g_spdk_iscsi.AllowDuplicateIsid) {
/* clean up all tasks to all LUNs for session */
target = conn->sess->target;
if (target != NULL) {
rc = spdk_iscsi_tgt_node_cleanup_luns(conn, target);
if (rc < 0) {
SPDK_ERRLOG("target abort failed\n");
}
}
}
}
static void
spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
{
struct spdk_iscsi_sess *sess;
int idx;
uint32_t i, j;
pthread_mutex_lock(&g_conns_mutex);
idx = -1;
sess = conn->sess;
conn->sess = NULL;
if (sess == NULL) {
spdk_iscsi_conn_free(conn);
return;
goto end;
}
for (i = 0; i < sess->connections; i++) {
@ -474,35 +497,10 @@ static void spdk_iscsi_remove_conn(struct spdk_iscsi_conn *conn)
spdk_free_sess(sess);
}
end:
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "cleanup free conn\n");
spdk_iscsi_conn_free(conn);
}
_spdk_iscsi_conn_free(conn);
static void
spdk_iscsi_conn_cleanup_backend(struct spdk_iscsi_conn *conn)
{
int rc;
struct spdk_iscsi_tgt_node *target;
if (conn->sess->connections > 1) {
/* connection specific cleanup */
} else if (!g_spdk_iscsi.AllowDuplicateIsid) {
/* clean up all tasks to all LUNs for session */
target = conn->sess->target;
if (target != NULL) {
rc = spdk_iscsi_tgt_node_cleanup_luns(conn, target);
if (rc < 0) {
SPDK_ERRLOG("target abort failed\n");
}
}
}
}
static void
_spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
{
pthread_mutex_lock(&g_conns_mutex);
spdk_iscsi_remove_conn(conn);
pthread_mutex_unlock(&g_conns_mutex);
}
@ -520,7 +518,7 @@ _spdk_iscsi_conn_check_shutdown(void *arg)
spdk_poller_unregister(&conn->shutdown_timer);
spdk_iscsi_conn_stop(conn);
_spdk_iscsi_conn_free(conn);
spdk_iscsi_conn_free(conn);
return 1;
}
@ -542,7 +540,7 @@ _spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn)
conn->shutdown_timer = spdk_poller_register(_spdk_iscsi_conn_check_shutdown, conn, 1000);
} else {
spdk_iscsi_conn_stop(conn);
_spdk_iscsi_conn_free(conn);
spdk_iscsi_conn_free(conn);
}
}