From e4e6c256b9b7d6368b258417d2f2b3d45a160154 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 8 Oct 2019 09:49:51 +0900 Subject: [PATCH] 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: Shuhei Matsumoto Change-Id: I9e1029ffa555e5e43aade53f61e942e98343006d Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469801 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/iscsi/conn.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index eb0fece5b..fb6df92f4 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -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,32 +1317,19 @@ iscsi_conn_flush_pdus(void *_conn) struct spdk_iscsi_conn *conn = _conn; int rc; - if (conn->state <= ISCSI_CONN_STATE_RUNNING) { - rc = iscsi_conn_flush_pdus_internal(conn); - if (rc == 0 && conn->flush_poller != NULL) { - spdk_poller_unregister(&conn->flush_poller); - } else if (rc == 1 && conn->flush_poller == NULL) { - 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 (spdk_unlikely(conn->state > ISCSI_CONN_STATE_RUNNING)) { + return 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. - */ + rc = iscsi_conn_flush_pdus_internal(conn); + if (rc == 0 && conn->flush_poller != NULL) { + spdk_poller_unregister(&conn->flush_poller); + } else if (rc == 1 && conn->flush_poller == NULL) { + conn->flush_poller = spdk_poller_register(iscsi_conn_flush_pdus, + conn, 50); + } + + 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); } }