git: 0d3789584915 - main - ctl: use socket buffer mutexes in struct socket directly

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Thu, 23 May 2024 19:12:21 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=0d37895849150e1646485068d12c3a8ff26809f9

commit 0d37895849150e1646485068d12c3a8ff26809f9
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-05-23 19:11:54 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-05-23 19:11:54 +0000

    ctl: use socket buffer mutexes in struct socket directly
    
    A mechanical change performed with sed(1) script:
    
    s/SOCKBUF_LOCK\(&so->so_rcv\)/SOCK_RECVBUF_LOCK(so)/
    s/SOCKBUF_UNLOCK\(&so->so_rcv\)/SOCK_RECVBUF_UNLOCK(so)/
    s/SOCKBUF_MTX\(&so->so_rcv\)/SOCK_RECVBUF_MTX(so)/
    s/SOCKBUF_LOCK\(&so->so_snd\)/SOCK_SENDBUF_LOCK(so)/
    s/SOCKBUF_UNLOCK\(&so->so_snd\)/SOCK_SENDBUF_UNLOCK(so)/
    s/SOCKBUF_MTX\(&so->so_snd\)/SOCK_SENDBUF_MTX(so)/
    
    Reviewed by:            mav
    Differential Revision:  https://reviews.freebsd.org/D45190
---
 sys/cam/ctl/ctl_ha.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sys/cam/ctl/ctl_ha.c b/sys/cam/ctl/ctl_ha.c
index 695006ed99e1..e94708028ee4 100644
--- a/sys/cam/ctl/ctl_ha.c
+++ b/sys/cam/ctl/ctl_ha.c
@@ -164,17 +164,17 @@ ctl_ha_close(struct ha_softc *softc)
 		report = 1;
 	}
 	if (so) {
-		SOCKBUF_LOCK(&so->so_rcv);
+		SOCK_RECVBUF_LOCK(so);
 		soupcall_clear(so, SO_RCV);
 		while (softc->ha_receiving) {
 			wakeup(&softc->ha_receiving);
-			msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv),
+			msleep(&softc->ha_receiving, SOCK_RECVBUF_MTX(so),
 			    0, "ha_rx exit", 0);
 		}
-		SOCKBUF_UNLOCK(&so->so_rcv);
-		SOCKBUF_LOCK(&so->so_snd);
+		SOCK_RECVBUF_UNLOCK(so);
+		SOCK_SENDBUF_LOCK(so);
 		soupcall_clear(so, SO_SND);
-		SOCKBUF_UNLOCK(&so->so_snd);
+		SOCK_SENDBUF_UNLOCK(so);
 		softc->ha_so = NULL;
 		if (softc->ha_connect)
 			pause("reconnect", hz / 2);
@@ -218,7 +218,7 @@ ctl_ha_rx_thread(void *arg)
 			next = wire_hdr.length;
 		else
 			next = sizeof(wire_hdr);
-		SOCKBUF_LOCK(&so->so_rcv);
+		SOCK_RECVBUF_LOCK(so);
 		while (sbavail(&so->so_rcv) < next || softc->ha_disconnect) {
 			if (softc->ha_connected == 0 || softc->ha_disconnect ||
 			    so->so_error ||
@@ -226,10 +226,10 @@ ctl_ha_rx_thread(void *arg)
 				goto errout;
 			}
 			so->so_rcv.sb_lowat = next;
-			msleep(&softc->ha_receiving, SOCKBUF_MTX(&so->so_rcv),
+			msleep(&softc->ha_receiving, SOCK_RECVBUF_MTX(so),
 			    0, "-", 0);
 		}
-		SOCKBUF_UNLOCK(&so->so_rcv);
+		SOCK_RECVBUF_UNLOCK(so);
 
 		if (wire_hdr.length == 0) {
 			iov.iov_base = &wire_hdr;
@@ -246,7 +246,7 @@ ctl_ha_rx_thread(void *arg)
 			if (error != 0) {
 				printf("%s: header receive error %d\n",
 				    __func__, error);
-				SOCKBUF_LOCK(&so->so_rcv);
+				SOCK_RECVBUF_LOCK(so);
 				goto errout;
 			}
 		} else {
@@ -259,7 +259,7 @@ ctl_ha_rx_thread(void *arg)
 errout:
 	softc->ha_receiving = 0;
 	wakeup(&softc->ha_receiving);
-	SOCKBUF_UNLOCK(&so->so_rcv);
+	SOCK_RECVBUF_UNLOCK(so);
 	ctl_ha_conn_wake(softc);
 	kthread_exit();
 }
@@ -280,13 +280,13 @@ ctl_ha_send(struct ha_softc *softc)
 				break;
 			}
 		}
-		SOCKBUF_LOCK(&so->so_snd);
+		SOCK_SENDBUF_LOCK(so);
 		if (sbspace(&so->so_snd) < softc->ha_sending->m_pkthdr.len) {
 			so->so_snd.sb_lowat = softc->ha_sending->m_pkthdr.len;
-			SOCKBUF_UNLOCK(&so->so_snd);
+			SOCK_SENDBUF_UNLOCK(so);
 			break;
 		}
-		SOCKBUF_UNLOCK(&so->so_snd);
+		SOCK_SENDBUF_UNLOCK(so);
 		error = sosend(softc->ha_so, NULL, NULL, softc->ha_sending,
 		    NULL, MSG_DONTWAIT, curthread);
 		softc->ha_sending = NULL;
@@ -309,14 +309,14 @@ ctl_ha_sock_setup(struct ha_softc *softc)
 	if (error)
 		printf("%s: soreserve failed %d\n", __func__, error);
 
-	SOCKBUF_LOCK(&so->so_rcv);
+	SOCK_RECVBUF_LOCK(so);
 	so->so_rcv.sb_lowat = sizeof(struct ha_msg_wire);
 	soupcall_set(so, SO_RCV, ctl_ha_rupcall, softc);
-	SOCKBUF_UNLOCK(&so->so_rcv);
-	SOCKBUF_LOCK(&so->so_snd);
+	SOCK_RECVBUF_UNLOCK(so);
+	SOCK_SENDBUF_LOCK(so);
 	so->so_snd.sb_lowat = sizeof(struct ha_msg_wire);
 	soupcall_set(so, SO_SND, ctl_ha_supcall, softc);
-	SOCKBUF_UNLOCK(&so->so_snd);
+	SOCK_SENDBUF_UNLOCK(so);
 
 	bzero(&opt, sizeof(struct sockopt));
 	opt.sopt_dir = SOPT_SET;