From 1ba87aba31a8fa3958e69de5a41c171b57758adb Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Thu, 9 Aug 2018 09:36:20 +0800 Subject: [PATCH] iSCSI: set a connection to EXISTING STATE in condition If the connection is already in exiting or exited status, we should not set it again. And this could prevent the coredump. Change-Id: Ia506d13b12c3a6cb5619d65e4b3353b149a85947 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/421668 Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/iscsi/conn.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 57964c285..f0392f631 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -690,7 +690,13 @@ void spdk_shutdown_iscsi_conns(void) if (conn == NULL) { continue; } - conn->state = ISCSI_CONN_STATE_EXITING; + + /* Do not set conn->state if the connection has already started exiting. + * This ensures we do not move a connection from EXITED state back to EXITING. + */ + if (conn->state < ISCSI_CONN_STATE_EXITING) { + conn->state = ISCSI_CONN_STATE_EXITING; + } } pthread_mutex_unlock(&g_conns_mutex); @@ -749,7 +755,13 @@ spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn, const char *conn_match, } SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "CID=%u\n", xconn->cid); - xconn->state = ISCSI_CONN_STATE_EXITING; + + /* Do not set xconn->state if the connection has already started exiting. + * This ensures we do not move a connection from EXITED state back to EXITING. + */ + if (xconn->state < ISCSI_CONN_STATE_EXITING) { + xconn->state = ISCSI_CONN_STATE_EXITING; + } num++; } }