Date: Tue, 1 Apr 2014 21:40:46 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264022 - in head/sys: cam/ctl dev/iscsi Message-ID: <201404012140.s31LekKi098309@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Tue Apr 1 21:40:46 2014 New Revision: 264022 URL: http://svnweb.freebsd.org/changeset/base/264022 Log: 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 Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c head/sys/dev/iscsi/icl.c head/sys/dev/iscsi/icl.h head/sys/dev/iscsi/iscsi.c Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c ============================================================================== --- head/sys/cam/ctl/ctl_frontend_iscsi.c Tue Apr 1 21:30:54 2014 (r264021) +++ head/sys/cam/ctl/ctl_frontend_iscsi.c Tue Apr 1 21:40:46 2014 (r264022) @@ -1215,7 +1215,7 @@ cfiscsi_session_new(struct cfiscsi_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; Modified: head/sys/dev/iscsi/icl.c ============================================================================== --- head/sys/dev/iscsi/icl.c Tue Apr 1 21:30:54 2014 (r264021) +++ head/sys/dev/iscsi/icl.c Tue Apr 1 21:40:46 2014 (r264022) @@ -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, in 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, in 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 *i { int error; + ICL_CONN_LOCK_ASSERT_NOT(ic); + if (so->so_type != SOCK_STREAM) return (EINVAL); Modified: head/sys/dev/iscsi/icl.h ============================================================================== --- head/sys/dev/iscsi/icl.h Tue Apr 1 21:30:54 2014 (r264021) +++ head/sys/dev/iscsi/icl.h Tue Apr 1 21:40:46 2014 (r264022) @@ -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); Modified: head/sys/dev/iscsi/iscsi.c ============================================================================== --- head/sys/dev/iscsi/iscsi.c Tue Apr 1 21:30:54 2014 (r264021) +++ head/sys/dev/iscsi/iscsi.c Tue Apr 1 21:40:46 2014 (r264022) @@ -1641,7 +1641,7 @@ iscsi_ioctl_session_add(struct iscsi_sof 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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404012140.s31LekKi098309>