From dbad9e1e6031139a912f1e34166c9183de07b059 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 7 Dec 2018 16:07:17 +0900 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/436230 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/iscsi/conn.c | 64 +++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index d4e593637..48fb38ea3 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -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); } }