Commit 72caa1d0 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/436447


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent dbad9e1e
Loading
Loading
Loading
Loading
+17 −21
Original line number Diff line number Diff line
@@ -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,23 +473,14 @@ spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
		}
	}

	if (sess->connections < 1) {
		SPDK_ERRLOG("zero connection\n");
		sess->connections = 0;
	} 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];
		for (i = idx; i < sess->connections - 1; i++) {
			sess->conns[i] = sess->conns[i + 1];
		}
		sess->conns[sess->connections - 1] = NULL;
		}
		sess->connections--;
	}

	SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "Terminating connections(tsih %d): %d\n",
		      sess->tsih, sess->connections);

		if (sess->connections == 0) {
			/* cleanup last connection */
@@ -496,6 +488,10 @@ spdk_iscsi_conn_free(struct spdk_iscsi_conn *conn)
				      "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);

end:
	SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "cleanup free conn\n");