From 3e9215f785af0a9d841c80efcd8ea7ece14c458b Mon Sep 17 00:00:00 2001 From: ad Date: Fri, 13 Oct 2023 18:50:39 +0000 Subject: [PATCH] Use cv_fdrestart() to implement fo_restart. --- sys/kern/uipc_socket.c | 33 ++++++++------------------------- sys/kern/uipc_syscalls.c | 10 ++-------- sys/sys/socketvar.h | 5 ++--- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index e5b5d8f37091..3e4c33fa5ee2 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.305 2023/10/04 22:17:09 ad Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.306 2023/10/13 18:50:39 ad Exp $ */ /* * Copyright (c) 2002, 2007, 2008, 2009, 2023 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.305 2023/10/04 22:17:09 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.306 2023/10/13 18:50:39 ad Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -895,7 +895,6 @@ sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf **mp, *m; long space, len, resid, clen, mlen; int error, s, dontroute, atomic; - short wakeup_state = 0; clen = 0; @@ -968,17 +967,11 @@ sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, goto release; } sbunlock(&so->so_snd); - if (wakeup_state & SS_RESTARTSYS) { - error = ERESTART; - goto out; - } error = sbwait(&so->so_snd); if (error) goto out; - wakeup_state = so->so_state; goto restart; } - wakeup_state = 0; mp = ⊤ space -= clen; do { @@ -1160,7 +1153,6 @@ soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, struct mbuf *nextrecord; int mbuf_removed = 0; const struct domain *dom; - short wakeup_state = 0; pr = so->so_proto; atomic = pr->pr_flags & PR_ATOMIC; @@ -1271,16 +1263,12 @@ restart: SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 1"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 1"); sbunlock(&so->so_rcv); - if (wakeup_state & SS_RESTARTSYS) - error = ERESTART; - else - error = sbwait(&so->so_rcv); + error = sbwait(&so->so_rcv); if (error != 0) { sounlock(so); splx(s); return error; } - wakeup_state = so->so_state; goto restart; } @@ -1457,7 +1445,6 @@ dontblock: #endif so->so_state &= ~SS_RCVATMARK; - wakeup_state = 0; len = uio->uio_resid; if (so->so_oobmark && len > so->so_oobmark - offset) len = so->so_oobmark - offset; @@ -1600,10 +1587,7 @@ dontblock: (*pr->pr_usrreqs->pr_rcvd)(so, flags, l); SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); - if (wakeup_state & SS_RESTARTSYS) - error = ERESTART; - else - error = sbwait(&so->so_rcv); + error = sbwait(&so->so_rcv); if (error != 0) { sbunlock(&so->so_rcv); sounlock(so); @@ -1612,7 +1596,6 @@ dontblock: } if ((m = so->so_rcv.sb_mb) != NULL) nextrecord = m->m_nextpkt; - wakeup_state = so->so_state; } } @@ -1680,6 +1663,7 @@ soshutdown(struct socket *so, int how) void sorestart(struct socket *so) { + /* * An application has called close() on an fd on which another * of its threads has called a socket system call. @@ -1689,10 +1673,9 @@ sorestart(struct socket *so) * Any other fd will block again on the 2nd syscall. */ solock(so); - so->so_state |= SS_RESTARTSYS; - cv_broadcast(&so->so_cv); - cv_broadcast(&so->so_snd.sb_cv); - cv_broadcast(&so->so_rcv.sb_cv); + cv_fdrestart(&so->so_cv); + cv_fdrestart(&so->so_snd.sb_cv); + cv_fdrestart(&so->so_rcv.sb_cv); sounlock(so); } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 0880445d9707..ae38b0bd5ff9 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.208 2023/10/04 22:17:09 ad Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.209 2023/10/13 18:50:39 ad Exp $ */ /*- * Copyright (c) 2008, 2009, 2023 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.208 2023/10/04 22:17:09 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.209 2023/10/13 18:50:39 ad Exp $"); #ifdef _KERNEL_OPT #include "opt_pipe.h" @@ -175,7 +175,6 @@ do_sys_accept(struct lwp *l, int sock, struct sockaddr *name, file_t *fp, *fp2; int error, fd; struct socket *so, *so2; - short wakeup_state = 0; if ((fp = fd_getfile(sock)) == NULL) return EBADF; @@ -211,15 +210,10 @@ do_sys_accept(struct lwp *l, int sock, struct sockaddr *name, so->so_error = ECONNABORTED; break; } - if (wakeup_state & SS_RESTARTSYS) { - error = ERESTART; - goto bad; - } error = sowait(so, true, 0); if (error) { goto bad; } - wakeup_state = so->so_state; } if (so->so_error) { error = so->so_error; diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index db4e26d55ce5..4e2ba8e7708d 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,7 +1,7 @@ -/* $NetBSD: socketvar.h,v 1.165 2022/04/09 23:52:23 riastradh Exp $ */ +/* $NetBSD: socketvar.h,v 1.166 2023/10/13 18:50:39 ad Exp $ */ /*- - * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. + * Copyright (c) 2008, 2009, 2023 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -197,7 +197,6 @@ struct socket { #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */ #define SS_RCVATMARK 0x040 /* at mark on input */ #define SS_ISABORTING 0x080 /* aborting fd references - close() */ -#define SS_RESTARTSYS 0x100 /* restart blocked system calls */ #define SS_POLLRDBAND 0x200 /* poll should return POLLRDBAND */ #define SS_MORETOCOME 0x400 /* * hint from sosend to lower layer;