From 6bb1f3c7fe2aa95c8f204120e91fafd5526c7432 Mon Sep 17 00:00:00 2001 From: trasz Date: Tue, 1 Apr 2014 21:40:46 +0000 Subject: [PATCH] Get rid of ICL lock; use upper-layer (initiator or target) lock instead. This avoids extra locking in icl_pdu_queue(); the upper layer needs to call it while holding its own lock anyway, to avoid sending PDUs out of order. Sponsored by: The FreeBSD Foundation --- sys/cam/ctl/ctl_frontend_iscsi.c | 2 +- sys/dev/iscsi/icl.c | 27 +++++++++++++++++---------- sys/dev/iscsi/icl.h | 4 ++-- sys/dev/iscsi/iscsi.c | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c index 295ac8dc588..6985b4edf2a 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.c +++ b/sys/cam/ctl/ctl_frontend_iscsi.c @@ -1215,7 +1215,7 @@ cfiscsi_session_new(struct cfiscsi_softc *softc) cv_init(&cs->cs_login_cv, "cfiscsi_login"); #endif - cs->cs_conn = icl_conn_new(); + cs->cs_conn = icl_conn_new(&cs->cs_lock); cs->cs_conn->ic_receive = cfiscsi_receive_callback; cs->cs_conn->ic_error = cfiscsi_error_callback; cs->cs_conn->ic_prv0 = cs; diff --git a/sys/dev/iscsi/icl.c b/sys/dev/iscsi/icl.c index 44a049f7fbd..637e029473c 100644 --- a/sys/dev/iscsi/icl.c +++ b/sys/dev/iscsi/icl.c @@ -88,9 +88,10 @@ static volatile u_int icl_ncons; } \ } while (0) -#define ICL_CONN_LOCK(X) mtx_lock(&X->ic_lock) -#define ICL_CONN_UNLOCK(X) mtx_unlock(&X->ic_lock) -#define ICL_CONN_LOCK_ASSERT(X) mtx_assert(&X->ic_lock, MA_OWNED) +#define ICL_CONN_LOCK(X) mtx_lock(X->ic_lock) +#define ICL_CONN_UNLOCK(X) mtx_unlock(X->ic_lock) +#define ICL_CONN_LOCK_ASSERT(X) mtx_assert(X->ic_lock, MA_OWNED) +#define ICL_CONN_LOCK_ASSERT_NOT(X) mtx_assert(X->ic_lock, MA_NOTOWNED) static void icl_conn_fail(struct icl_conn *ic) @@ -896,7 +897,7 @@ icl_send_thread(void *arg) break; } icl_conn_send_pdus(ic); - cv_wait(&ic->ic_send_cv, &ic->ic_lock); + cv_wait(&ic->ic_send_cv, ic->ic_lock); } ic->ic_send_running = false; @@ -961,20 +962,19 @@ icl_pdu_queue(struct icl_pdu *ip) ic = ip->ip_conn; - ICL_CONN_LOCK(ic); + ICL_CONN_LOCK_ASSERT(ic); + if (ic->ic_disconnecting || ic->ic_socket == NULL) { ICL_DEBUG("icl_pdu_queue on closed connection"); - ICL_CONN_UNLOCK(ic); icl_pdu_free(ip); return; } TAILQ_INSERT_TAIL(&ic->ic_to_send, ip, ip_next); - ICL_CONN_UNLOCK(ic); cv_signal(&ic->ic_send_cv); } struct icl_conn * -icl_conn_new(void) +icl_conn_new(struct mtx *lock) { struct icl_conn *ic; @@ -983,7 +983,7 @@ icl_conn_new(void) ic = uma_zalloc(icl_conn_zone, M_WAITOK | M_ZERO); TAILQ_INIT(&ic->ic_to_send); - mtx_init(&ic->ic_lock, "icl_lock", NULL, MTX_DEF); + ic->ic_lock = lock; cv_init(&ic->ic_send_cv, "icl_tx"); cv_init(&ic->ic_receive_cv, "icl_rx"); #ifdef DIAGNOSTIC @@ -998,7 +998,6 @@ void icl_conn_free(struct icl_conn *ic) { - mtx_destroy(&ic->ic_lock); cv_destroy(&ic->ic_send_cv); cv_destroy(&ic->ic_receive_cv); uma_zfree(icl_conn_zone, ic); @@ -1102,6 +1101,8 @@ icl_conn_handoff(struct icl_conn *ic, int fd) cap_rights_t rights; int error; + ICL_CONN_LOCK_ASSERT_NOT(ic); + /* * Steal the socket from userland. */ @@ -1141,6 +1142,7 @@ icl_conn_handoff(struct icl_conn *ic, int fd) void icl_conn_shutdown(struct icl_conn *ic) { + ICL_CONN_LOCK_ASSERT_NOT(ic); ICL_CONN_LOCK(ic); if (ic->ic_socket == NULL) { @@ -1157,6 +1159,8 @@ icl_conn_close(struct icl_conn *ic) { struct icl_pdu *pdu; + ICL_CONN_LOCK_ASSERT_NOT(ic); + ICL_CONN_LOCK(ic); if (ic->ic_socket == NULL) { ICL_CONN_UNLOCK(ic); @@ -1214,6 +1218,7 @@ icl_conn_close(struct icl_conn *ic) bool icl_conn_connected(struct icl_conn *ic) { + ICL_CONN_LOCK_ASSERT_NOT(ic); ICL_CONN_LOCK(ic); if (ic->ic_socket == NULL) { @@ -1234,6 +1239,8 @@ icl_conn_handoff_sock(struct icl_conn *ic, struct socket *so) { int error; + ICL_CONN_LOCK_ASSERT_NOT(ic); + if (so->so_type != SOCK_STREAM) return (EINVAL); diff --git a/sys/dev/iscsi/icl.h b/sys/dev/iscsi/icl.h index ab61cd8faa6..2bfc5dc6e75 100644 --- a/sys/dev/iscsi/icl.h +++ b/sys/dev/iscsi/icl.h @@ -74,7 +74,7 @@ void icl_pdu_free(struct icl_pdu *ip); #define ICL_MAX_DATA_SEGMENT_LENGTH (128 * 1024) struct icl_conn { - struct mtx ic_lock; + struct mtx *ic_lock; struct socket *ic_socket; #ifdef DIAGNOSTIC volatile u_int ic_outstanding_pdus; @@ -102,7 +102,7 @@ struct icl_conn { void *ic_prv0; }; -struct icl_conn *icl_conn_new(void); +struct icl_conn *icl_conn_new(struct mtx *lock); void icl_conn_free(struct icl_conn *ic); int icl_conn_handoff(struct icl_conn *ic, int fd); void icl_conn_shutdown(struct icl_conn *ic); diff --git a/sys/dev/iscsi/iscsi.c b/sys/dev/iscsi/iscsi.c index 8bf2f2590c3..88d4954a8d1 100644 --- a/sys/dev/iscsi/iscsi.c +++ b/sys/dev/iscsi/iscsi.c @@ -1641,7 +1641,7 @@ iscsi_ioctl_session_add(struct iscsi_softc *sc, struct iscsi_session_add *isa) return (EBUSY); } - is->is_conn = icl_conn_new(); + is->is_conn = icl_conn_new(&is->is_lock); is->is_conn->ic_receive = iscsi_receive_callback; is->is_conn->ic_error = iscsi_error_callback; is->is_conn->ic_prv0 = is; -- 2.45.0