Commit e4e6c256 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Changpeng Liu
Browse files

lib/iscsi: Flush PDUs only when connection state is RUNNING or less



In iscsi_conn_flush_pdus(), call iscsi_conn_flush_pdus_internal()
only when the connection state is RUNNING or INVALID.

Besides, we can remove the iscsi_conn_flush_pdus() call from
iscsi_conn_sock_cb() because the connection state is already EXITING.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I9e1029ffa555e5e43aade53f61e942e98343006d
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469801


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent fe5611b7
Loading
Loading
Loading
Loading
+14 −30
Original line number Diff line number Diff line
@@ -1306,12 +1306,10 @@ iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn)
 * underlying TCP socket buffer - for example, in the case where the
 * socket buffer is already full.
 *
 * During normal RUNNING connection state, if not all PDUs are flushed,
 * then subsequent calls to this routine will eventually flush
 * remaining PDUs.
 * If not all PDUs are flushed, then subsequent calls to this routine
 * will eventually flush remaining PDUs.
 *
 * During other connection states (EXITING), this
 * function will spin until all PDUs have successfully been flushed.
 * PDUs are flushed only during normal RUNNING connection state.
 */
static int
iscsi_conn_flush_pdus(void *_conn)
@@ -1319,7 +1317,10 @@ iscsi_conn_flush_pdus(void *_conn)
	struct spdk_iscsi_conn *conn = _conn;
	int rc;

	if (conn->state <= ISCSI_CONN_STATE_RUNNING) {
	if (spdk_unlikely(conn->state > ISCSI_CONN_STATE_RUNNING)) {
		return 1;
	}

	rc = iscsi_conn_flush_pdus_internal(conn);
	if (rc == 0 && conn->flush_poller != NULL) {
		spdk_poller_unregister(&conn->flush_poller);
@@ -1327,24 +1328,8 @@ iscsi_conn_flush_pdus(void *_conn)
		conn->flush_poller = spdk_poller_register(iscsi_conn_flush_pdus,
				     conn, 50);
	}
	} else {
		/*
		 * If the connection state is not RUNNING, then
		 * keep trying to flush PDUs until our list is
		 * empty - to make sure all data is sent before
		 * closing the connection.
		 */
		do {
			rc = iscsi_conn_flush_pdus_internal(conn);
		} while (rc == 1);
	}

	if (rc < 0 && conn->state < ISCSI_CONN_STATE_EXITING) {
		/*
		 * If the poller has already started destruction of the connection,
		 *  i.e. the socket read failed, then the connection state may already
		 *  be EXITED.  We don't want to set it back to EXITING in that case.
		 */
	if (rc < 0) {
		conn->state = ISCSI_CONN_STATE_EXITING;
	}

@@ -1465,7 +1450,6 @@ iscsi_conn_sock_cb(void *arg, struct spdk_sock_group *group, struct spdk_sock *s
	rc = iscsi_conn_handle_incoming_pdus(conn);
	if (rc < 0) {
		conn->state = ISCSI_CONN_STATE_EXITING;
		iscsi_conn_flush_pdus(conn);
	}
}