From 1a907f11fd19ca75d63dd327df0e09cb4a03bea1 Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Wed, 28 Feb 2018 13:55:38 +0800 Subject: [PATCH] lib/iscsi: Add nop_poller for iscsi polling group. Change-Id: I7f0f64845a5b980632991e7b6d130e4be60ffa20 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/401749 Tested-by: SPDK Automated Test System Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- lib/iscsi/conn.c | 24 ++++++++++++------------ lib/iscsi/conn.h | 1 + lib/iscsi/iscsi.h | 1 + lib/iscsi/iscsi_subsystem.c | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index ec50be06e..b19b6ed46 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -888,25 +888,33 @@ spdk_iscsi_get_pdu_length(struct spdk_iscsi_pdu *pdu, int header_digest, return total; } -static int +void spdk_iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn) { uint64_t tsc; + /** + * This function will be executed by nop_poller of iSCSI polling group, so + * we need to check the connection state first, then do the nop interval + * expiration check work. + */ + if ((conn->state == ISCSI_CONN_STATE_EXITED) || + (conn->state == ISCSI_CONN_STATE_EXITING)) { + return; + } + /* Check for nop interval expiration */ tsc = spdk_get_ticks(); if (conn->nop_outstanding) { if ((tsc - conn->last_nopin) > (conn->timeout * spdk_get_ticks_hz())) { SPDK_ERRLOG("Timed out waiting for NOP-Out response from initiator\n"); SPDK_ERRLOG(" tsc=0x%lx, last_nopin=0x%lx\n", tsc, conn->last_nopin); - return -1; + conn->state = ISCSI_CONN_STATE_EXITING; } } else if (tsc - conn->last_nopin > conn->nopininterval) { conn->last_nopin = tsc; spdk_iscsi_send_nopin(conn); } - - return 0; } /** @@ -1153,8 +1161,6 @@ spdk_iscsi_conn_sock_cb(void *arg, struct spdk_sock_group *group, struct spdk_so static int spdk_iscsi_conn_execute(struct spdk_iscsi_conn *conn) { - int rc = 0; - if (conn->state == ISCSI_CONN_STATE_EXITED) { return -1; } @@ -1162,12 +1168,6 @@ spdk_iscsi_conn_execute(struct spdk_iscsi_conn *conn) if (conn->state == ISCSI_CONN_STATE_EXITING) { goto conn_exit; } - /* Check for nop interval expiration */ - rc = spdk_iscsi_conn_handle_nop(conn); - if (rc < 0) { - conn->state = ISCSI_CONN_STATE_EXITING; - goto conn_exit; - } spdk_iscsi_conn_handle_queued_datain_tasks(conn); diff --git a/lib/iscsi/conn.h b/lib/iscsi/conn.h index 2168ee7f1..59fdcd452 100644 --- a/lib/iscsi/conn.h +++ b/lib/iscsi/conn.h @@ -174,6 +174,7 @@ void spdk_shutdown_iscsi_conns(void); int spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, struct spdk_sock *sock); void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn); +void spdk_iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn); void spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn); int spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn, const char *conn_match, int drop_all); diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index c3d8c1e91..275b6dd05 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -259,6 +259,7 @@ struct spdk_iscsi_sess { struct spdk_iscsi_poll_group { uint32_t core; struct spdk_poller *poller; + struct spdk_poller *nop_poller; STAILQ_HEAD(connections, spdk_iscsi_conn) connections; struct spdk_sock_group *sock_group; }; diff --git a/lib/iscsi/iscsi_subsystem.c b/lib/iscsi/iscsi_subsystem.c index 7dd980e59..dabbb7e73 100644 --- a/lib/iscsi/iscsi_subsystem.c +++ b/lib/iscsi/iscsi_subsystem.c @@ -850,6 +850,17 @@ spdk_iscsi_poll_group_poll(void *ctx) } } +static void +spdk_iscsi_poll_group_handle_nop(void *ctx) +{ + struct spdk_iscsi_poll_group *group = ctx; + struct spdk_iscsi_conn *conn, *tmp; + + STAILQ_FOREACH_SAFE(conn, &group->connections, link, tmp) { + spdk_iscsi_conn_handle_nop(conn); + } +} + static void iscsi_create_poll_group_done(void *ctx) { @@ -870,6 +881,8 @@ iscsi_create_poll_group(void *ctx) assert(pg->sock_group != NULL); pg->poller = spdk_poller_register(spdk_iscsi_poll_group_poll, pg, 0); + /* set the period to 1 sec */ + pg->nop_poller = spdk_poller_register(spdk_iscsi_poll_group_handle_nop, pg, 1000000); } static void @@ -884,6 +897,7 @@ iscsi_unregister_poll_group(void *ctx) spdk_sock_group_close(&pg->sock_group); spdk_poller_unregister(&pg->poller); + spdk_poller_unregister(&pg->nop_poller); } static void