From d34076322bb97acba0f73a060b1bf4a04b2f4a90 Mon Sep 17 00:00:00 2001 From: mpi Date: Mon, 26 Jul 2021 05:51:13 +0000 Subject: [PATCH] Pass a socket pointer to various socket buffer routines in preparation for per-socket locking. No functional change. --- sys/kern/uipc_socket.c | 20 ++++++++++---------- sys/kern/uipc_socket2.c | 33 +++++++++++++++++---------------- sys/sys/socketvar.h | 17 +++++++++-------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index dce20208828..6f3f2ce4b30 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.263 2021/05/28 16:24:53 visa Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.264 2021/07/26 05:51:13 mpi Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -860,7 +860,7 @@ dontblock: *paddr = m_copym(m, 0, m->m_len, M_NOWAIT); m = m->m_next; } else { - sbfree(&so->so_rcv, m); + sbfree(so, &so->so_rcv, m); if (paddr) { *paddr = m; so->so_rcv.sb_mb = m->m_next; @@ -884,7 +884,7 @@ dontblock: *controlp = m_copym(m, 0, m->m_len, M_NOWAIT); m = m->m_next; } else { - sbfree(&so->so_rcv, m); + sbfree(so, &so->so_rcv, m); so->so_rcv.sb_mb = m->m_next; m->m_nextpkt = m->m_next = NULL; cm = m; @@ -984,7 +984,7 @@ dontblock: orig_resid = 0; } else { nextrecord = m->m_nextpkt; - sbfree(&so->so_rcv, m); + sbfree(so, &so->so_rcv, m); if (mp) { *mp = m; mp = &m->m_next; @@ -1065,7 +1065,7 @@ dontblock: if (m && pr->pr_flags & PR_ATOMIC) { flags |= MSG_TRUNC; if ((flags & MSG_PEEK) == 0) - (void) sbdroprecord(&so->so_rcv); + (void) sbdroprecord(so, &so->so_rcv); } if ((flags & MSG_PEEK) == 0) { if (m == NULL) { @@ -1452,7 +1452,7 @@ somove(struct socket *so, int wait) while (m && m->m_type == MT_CONTROL) m = m->m_next; if (m == NULL) { - sbdroprecord(&so->so_rcv); + sbdroprecord(so, &so->so_rcv); if (so->so_proto->pr_flags & PR_WANTRCVD && so->so_pcb) (so->so_proto->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL, NULL); @@ -1492,7 +1492,7 @@ somove(struct socket *so, int wait) * that the whole first record can be processed. */ m = so->so_rcv.sb_mb; - sbfree(&so->so_rcv, m); + sbfree(so, &so->so_rcv, m); so->so_rcv.sb_mb = m_free(m); sbsync(&so->so_rcv, nextrecord); } @@ -1502,7 +1502,7 @@ somove(struct socket *so, int wait) */ m = so->so_rcv.sb_mb; while (m && m->m_type == MT_CONTROL) { - sbfree(&so->so_rcv, m); + sbfree(so, &so->so_rcv, m); so->so_rcv.sb_mb = m_free(m); m = so->so_rcv.sb_mb; sbsync(&so->so_rcv, nextrecord); @@ -1541,7 +1541,7 @@ somove(struct socket *so, int wait) so->so_rcv.sb_datacc -= size; } else { *mp = so->so_rcv.sb_mb; - sbfree(&so->so_rcv, *mp); + sbfree(so, &so->so_rcv, *mp); so->so_rcv.sb_mb = (*mp)->m_next; sbsync(&so->so_rcv, nextrecord); } @@ -1550,7 +1550,7 @@ somove(struct socket *so, int wait) SBLASTRECORDCHK(&so->so_rcv, "somove 3"); SBLASTMBUFCHK(&so->so_rcv, "somove 3"); - SBCHECK(&so->so_rcv); + SBCHECK(so, &so->so_rcv); if (m == NULL) goto release; m->m_nextpkt = NULL; diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 03306ca908c..e387e4705f7 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.112 2021/07/25 14:13:47 mpi Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.113 2021/07/26 05:51:13 mpi Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -654,7 +654,7 @@ sbappend(struct socket *so, struct sockbuf *sb, struct mbuf *m) */ sb->sb_lastrecord = m; } - sbcompress(sb, m, n); + sbcompress(so, sb, m, n); SBLASTRECORDCHK(sb, "sbappend 2"); } @@ -673,7 +673,7 @@ sbappendstream(struct socket *so, struct sockbuf *sb, struct mbuf *m) SBLASTMBUFCHK(sb, __func__); - sbcompress(sb, m, sb->sb_mbtail); + sbcompress(so, sb, m, sb->sb_mbtail); sb->sb_lastrecord = sb->sb_mb; SBLASTRECORDCHK(sb, __func__); @@ -681,7 +681,7 @@ sbappendstream(struct socket *so, struct sockbuf *sb, struct mbuf *m) #ifdef SOCKBUF_DEBUG void -sbcheck(struct sockbuf *sb) +sbcheck(struct socket *so, struct sockbuf *sb) { struct mbuf *m, *n; u_long len = 0, mbcnt = 0; @@ -723,7 +723,7 @@ sbappendrecord(struct socket *so, struct sockbuf *sb, struct mbuf *m0) * Put the first mbuf on the queue. * Note this permits zero length records. */ - sballoc(sb, m0); + sballoc(so, sb, m0); SBLASTRECORDCHK(sb, "sbappendrecord 1"); SBLINKRECORD(sb, m0); m = m0->m_next; @@ -732,7 +732,7 @@ sbappendrecord(struct socket *so, struct sockbuf *sb, struct mbuf *m0) m0->m_flags &= ~M_EOR; m->m_flags |= M_EOR; } - sbcompress(sb, m, m0); + sbcompress(so, sb, m, m0); SBLASTRECORDCHK(sb, "sbappendrecord 2"); } @@ -778,8 +778,8 @@ sbappendaddr(struct socket *so, struct sockbuf *sb, const struct sockaddr *asa, SBLASTRECORDCHK(sb, "sbappendaddr 1"); for (n = m; n->m_next != NULL; n = n->m_next) - sballoc(sb, n); - sballoc(sb, n); + sballoc(so, sb, n); + sballoc(so, sb, n); nlast = n; SBLINKRECORD(sb, m); @@ -815,8 +815,8 @@ sbappendcontrol(struct socket *so, struct sockbuf *sb, struct mbuf *m0, SBLASTRECORDCHK(sb, "sbappendcontrol 1"); for (m = control; m->m_next != NULL; m = m->m_next) - sballoc(sb, m); - sballoc(sb, m); + sballoc(so, sb, m); + sballoc(so, sb, m); mlast = m; SBLINKRECORD(sb, control); @@ -834,7 +834,8 @@ sbappendcontrol(struct socket *so, struct sockbuf *sb, struct mbuf *m0, * is null, the buffer is presumed empty. */ void -sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n) +sbcompress(struct socket *so, struct sockbuf *sb, struct mbuf *m, + struct mbuf *n) { int eor = 0; struct mbuf *o; @@ -870,7 +871,7 @@ sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n) else sb->sb_mb = m; sb->sb_mbtail = m; - sballoc(sb, m); + sballoc(so, sb, m); n = m; m->m_flags &= ~M_EOR; m = m->m_next; @@ -935,12 +936,12 @@ sbdrop(struct socket *so, struct sockbuf *sb, int len) break; } len -= m->m_len; - sbfree(sb, m); + sbfree(so, sb, m); mn = m_free(m); m = mn; } while (m && m->m_len == 0) { - sbfree(sb, m); + sbfree(so, sb, m); mn = m_free(m); m = mn; } @@ -967,7 +968,7 @@ sbdrop(struct socket *so, struct sockbuf *sb, int len) * and move the next record to the front. */ void -sbdroprecord(struct sockbuf *sb) +sbdroprecord(struct socket *so, struct sockbuf *sb) { struct mbuf *m, *mn; @@ -975,7 +976,7 @@ sbdroprecord(struct sockbuf *sb) if (m) { sb->sb_mb = m->m_nextpkt; do { - sbfree(sb, m); + sbfree(so, sb, m); mn = m_free(m); } while ((m = mn) != NULL); } diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index f859830d405..6c338ac5211 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.99 2021/07/25 14:13:47 mpi Exp $ */ +/* $OpenBSD: socketvar.h,v 1.100 2021/07/26 05:51:13 mpi Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -223,7 +223,7 @@ soreadable(struct socket *so) ((so)->so_state & SS_CANTSENDMORE) || (so)->so_error) /* adjust counters in sb reflecting allocation of m */ -#define sballoc(sb, m) do { \ +#define sballoc(so, sb, m) do { \ (sb)->sb_cc += (m)->m_len; \ if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ (sb)->sb_datacc += (m)->m_len; \ @@ -233,7 +233,7 @@ soreadable(struct socket *so) } while (/* CONSTCOND */ 0) /* adjust counters in sb reflecting freeing of m */ -#define sbfree(sb, m) do { \ +#define sbfree(so, sb, m) do { \ (sb)->sb_cc -= (m)->m_len; \ if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \ (sb)->sb_datacc -= (m)->m_len; \ @@ -287,11 +287,12 @@ int sbappendaddr(struct socket *, struct sockbuf *, int sbappendcontrol(struct socket *, struct sockbuf *, struct mbuf *, struct mbuf *); void sbappendrecord(struct socket *, struct sockbuf *, struct mbuf *); -void sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *); +void sbcompress(struct socket *, struct sockbuf *, struct mbuf *, + struct mbuf *); struct mbuf * sbcreatecontrol(const void *, size_t, int, int); void sbdrop(struct socket *, struct sockbuf *, int); -void sbdroprecord(struct sockbuf *); +void sbdroprecord(struct socket *, struct sockbuf *); void sbflush(struct socket *, struct sockbuf *); void sbrelease(struct socket *, struct sockbuf *); int sbcheckreserve(u_long, u_long); @@ -348,12 +349,12 @@ void sblastrecordchk(struct sockbuf *, const char *); void sblastmbufchk(struct sockbuf *, const char *); #define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where)) -void sbcheck(struct sockbuf *); -#define SBCHECK(sb) sbcheck(sb) +void sbcheck(struct socket *, struct sockbuf *); +#define SBCHECK(so, sb) sbcheck((so), (sb)) #else #define SBLASTRECORDCHK(sb, where) /* nothing */ #define SBLASTMBUFCHK(sb, where) /* nothing */ -#define SBCHECK(sb) /* nothing */ +#define SBCHECK(so, sb) /* nothing */ #endif /* SOCKBUF_DEBUG */ #endif /* _KERNEL */ -- 2.20.1