summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2007-08-06 14:26:03 +0000
committerrwatson <rwatson@FreeBSD.org>2007-08-06 14:26:03 +0000
commit23574c86734ab5cb088584d30345e698cbbeaef2 (patch)
tree63e9e0c42ec5669b83e25b5f9cbdcbee7e1be6dc /sys/kern
parent5f4b9d20fc4bf36bf86f78bb1622ee474a93dc56 (diff)
downloadFreeBSD-src-23574c86734ab5cb088584d30345e698cbbeaef2.zip
FreeBSD-src-23574c86734ab5cb088584d30345e698cbbeaef2.tar.gz
Remove the now-unused NET_{LOCK,UNLOCK,ASSERT}_GIANT() macros, which
previously conditionally acquired Giant based on debug.mpsafenet. As that has now been removed, they are no longer required. Removing them significantly simplifies error-handling in the socket layer, eliminated quite a bit of unwinding of locking in error cases. While here clean up the now unneeded opt_net.h, which previously was used for the NET_WITH_GIANT kernel option. Clean up some related gotos for consistency. Reviewed by: bz, csjp Tested by: kris Approved by: re (kensmith)
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_descrip.c3
-rw-r--r--sys/kern/kern_poll.c11
-rw-r--r--sys/kern/sys_socket.c47
-rw-r--r--sys/kern/uipc_domain.c4
-rw-r--r--sys/kern/uipc_syscalls.c67
5 files changed, 25 insertions, 107 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 29a3f9a..ef1e0e1 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2098,8 +2098,6 @@ fgetsock(struct thread *td, int fd, struct socket **spp, u_int *fflagp)
struct file *fp;
int error;
- NET_ASSERT_GIANT();
-
*spp = NULL;
if (fflagp != NULL)
*fflagp = 0;
@@ -2129,7 +2127,6 @@ void
fputsock(struct socket *so)
{
- NET_ASSERT_GIANT();
ACCEPT_LOCK();
SOCK_LOCK(so);
sorele(so);
diff --git a/sys/kern/kern_poll.c b/sys/kern/kern_poll.c
index fa5d58a..a908f00 100644
--- a/sys/kern/kern_poll.c
+++ b/sys/kern/kern_poll.c
@@ -329,7 +329,6 @@ ether_poll(int count)
{
int i;
- NET_LOCK_GIANT();
mtx_lock(&poll_mtx);
if (count > poll_each_burst)
@@ -339,7 +338,6 @@ ether_poll(int count)
pr[i].handler(pr[i].ifp, POLL_ONLY, count);
mtx_unlock(&poll_mtx);
- NET_UNLOCK_GIANT();
}
/*
@@ -366,8 +364,6 @@ netisr_pollmore()
struct timeval t;
int kern_load;
- NET_ASSERT_GIANT();
-
mtx_lock(&poll_mtx);
phase = 5;
if (residual_burst > 0) {
@@ -417,8 +413,6 @@ netisr_poll(void)
int i, cycles;
enum poll_cmd arg = POLL_ONLY;
- NET_ASSERT_GIANT();
-
mtx_lock(&poll_mtx);
phase = 3;
if (residual_burst == 0) { /* first call in this tick */
@@ -456,8 +450,6 @@ ether_poll_register(poll_handler_t *h, struct ifnet *ifp)
KASSERT(h != NULL, ("%s: handler is NULL", __func__));
KASSERT(ifp != NULL, ("%s: ifp is NULL", __func__));
- NET_ASSERT_GIANT();
-
mtx_lock(&poll_mtx);
if (poll_handlers >= POLL_LIST_LEN) {
/*
@@ -504,7 +496,6 @@ ether_poll_deregister(struct ifnet *ifp)
KASSERT(ifp != NULL, ("%s: ifp is NULL", __func__));
- NET_ASSERT_GIANT();
mtx_lock(&poll_mtx);
for (i = 0 ; i < poll_handlers ; i++)
@@ -547,7 +538,6 @@ poll_switch(SYSCTL_HANDLER_ARGS)
polling = val;
- NET_LOCK_GIANT();
IFNET_RLOCK();
TAILQ_FOREACH(ifp, &ifnet, if_link) {
if (ifp->if_capabilities & IFCAP_POLLING) {
@@ -565,7 +555,6 @@ poll_switch(SYSCTL_HANDLER_ARGS)
}
}
IFNET_RUNLOCK();
- NET_UNLOCK_GIANT();
log(LOG_ERR, "kern.polling.enable is deprecated. Use ifconfig(8)");
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index be230cb..9229658 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -73,21 +73,16 @@ soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
int flags, struct thread *td)
{
struct socket *so = fp->f_data;
+#ifdef MAC
int error;
- NET_LOCK_GIANT();
-#ifdef MAC
SOCK_LOCK(so);
error = mac_check_socket_receive(active_cred, so);
SOCK_UNLOCK(so);
- if (error) {
- NET_UNLOCK_GIANT();
+ if (error)
return (error);
- }
#endif
- error = soreceive(so, 0, uio, 0, 0, 0);
- NET_UNLOCK_GIANT();
- return (error);
+ return (soreceive(so, 0, uio, 0, 0, 0));
}
/* ARGSUSED */
@@ -98,15 +93,12 @@ soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
struct socket *so = fp->f_data;
int error;
- NET_LOCK_GIANT();
#ifdef MAC
SOCK_LOCK(so);
error = mac_check_socket_send(active_cred, so);
SOCK_UNLOCK(so);
- if (error) {
- NET_UNLOCK_GIANT();
+ if (error)
return (error);
- }
#endif
error = sosend(so, 0, uio, 0, 0, 0, uio->uio_td);
if (error == EPIPE && (so->so_options & SO_NOSIGPIPE) == 0) {
@@ -114,7 +106,6 @@ soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
psignal(uio->uio_td->td_proc, SIGPIPE);
PROC_UNLOCK(uio->uio_td->td_proc);
}
- NET_UNLOCK_GIANT();
return (error);
}
@@ -125,9 +116,7 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
struct socket *so = fp->f_data;
int error = 0;
- NET_LOCK_GIANT();
switch (cmd) {
-
case FIONBIO:
SOCK_LOCK(so);
if (*(int *)data)
@@ -207,8 +196,7 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
(so, cmd, data, 0, td));
break;
}
- NET_UNLOCK_GIANT();
- return(error);
+ return (error);
}
int
@@ -216,22 +204,16 @@ soo_poll(struct file *fp, int events, struct ucred *active_cred,
struct thread *td)
{
struct socket *so = fp->f_data;
+#ifdef MAC
int error;
- NET_LOCK_GIANT();
-#ifdef MAC
SOCK_LOCK(so);
error = mac_check_socket_poll(active_cred, so);
SOCK_UNLOCK(so);
- if (error) {
- NET_UNLOCK_GIANT();
+ if (error)
return (error);
- }
#endif
- error = sopoll(so, events, fp->f_cred, td);
- NET_UNLOCK_GIANT();
-
- return (error);
+ return (sopoll(so, events, fp->f_cred, td));
}
int
@@ -239,19 +221,18 @@ soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
struct thread *td)
{
struct socket *so = fp->f_data;
+#ifdef MAC
int error;
+#endif
bzero((caddr_t)ub, sizeof (*ub));
ub->st_mode = S_IFSOCK;
- NET_LOCK_GIANT();
#ifdef MAC
SOCK_LOCK(so);
error = mac_check_socket_stat(active_cred, so);
SOCK_UNLOCK(so);
- if (error) {
- NET_UNLOCK_GIANT();
+ if (error)
return (error);
- }
#endif
/*
* If SBS_CANTRCVMORE is set, but there's still data left in the
@@ -269,9 +250,7 @@ soo_stat(struct file *fp, struct stat *ub, struct ucred *active_cred,
ub->st_size = so->so_rcv.sb_cc - so->so_rcv.sb_ctl;
ub->st_uid = so->so_cred->cr_uid;
ub->st_gid = so->so_cred->cr_gid;
- error = (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
- NET_UNLOCK_GIANT();
- return (error);
+ return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub);
}
/*
@@ -287,13 +266,11 @@ soo_close(struct file *fp, struct thread *td)
int error = 0;
struct socket *so;
- NET_LOCK_GIANT();
so = fp->f_data;
fp->f_ops = &badfileops;
fp->f_data = NULL;
if (so)
error = soclose(so);
- NET_UNLOCK_GIANT();
return (error);
}
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index 2a199a4..4c326d3 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -453,8 +453,6 @@ pfslowtimo(void *arg)
struct domain *dp;
struct protosw *pr;
- NET_ASSERT_GIANT();
-
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_slowtimo)
@@ -468,8 +466,6 @@ pffasttimo(void *arg)
struct domain *dp;
struct protosw *pr;
- NET_ASSERT_GIANT();
-
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_fasttimo)
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c
index ca770b8..7c874ff 100644
--- a/sys/kern/uipc_syscalls.c
+++ b/sys/kern/uipc_syscalls.c
@@ -175,10 +175,8 @@ socket(td, uap)
if (error)
return (error);
/* An extra reference on `fp' has been held for us by falloc(). */
- NET_LOCK_GIANT();
error = socreate(uap->domain, &so, uap->type, uap->protocol,
td->td_ucred, td);
- NET_UNLOCK_GIANT();
if (error) {
fdclose(fdp, fp, fd, td);
} else {
@@ -225,25 +223,22 @@ kern_bind(td, fd, sa)
struct file *fp;
int error;
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, fd, &fp, NULL);
if (error)
- goto done2;
+ return (error);
so = fp->f_data;
#ifdef MAC
SOCK_LOCK(so);
error = mac_check_socket_bind(td->td_ucred, so, sa);
SOCK_UNLOCK(so);
if (error)
- goto done1;
+ goto done;
#endif
error = sobind(so, sa, td);
#ifdef MAC
-done1:
+done:
#endif
fdrop(fp, td);
-done2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -260,7 +255,6 @@ listen(td, uap)
struct file *fp;
int error;
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, uap->s, &fp, NULL);
if (error == 0) {
so = fp->f_data;
@@ -277,7 +271,6 @@ done:
#endif
fdrop(fp, td);
}
- NET_UNLOCK_GIANT();
return(error);
}
@@ -357,10 +350,9 @@ kern_accept(struct thread *td, int s, struct sockaddr **name,
}
fdp = td->td_proc->p_fd;
- NET_LOCK_GIANT();
error = getsock(fdp, s, &headfp, &fflag);
if (error)
- goto done2;
+ return (error);
head = headfp->f_data;
if ((head->so_options & SO_ACCEPTCONN) == 0) {
error = EINVAL;
@@ -491,8 +483,6 @@ done:
if (nfp != NULL)
fdrop(nfp, td);
fdrop(headfp, td);
-done2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -550,10 +540,9 @@ kern_connect(td, fd, sa)
int error;
int interrupted = 0;
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, fd, &fp, NULL);
if (error)
- goto done2;
+ return (error);
so = fp->f_data;
if (so->so_state & SS_ISCONNECTING) {
error = EALREADY;
@@ -595,8 +584,6 @@ bad:
error = EINTR;
done1:
fdrop(fp, td);
-done2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -623,11 +610,10 @@ socketpair(td, uap)
return (error);
#endif
- NET_LOCK_GIANT();
error = socreate(uap->domain, &so1, uap->type, uap->protocol,
td->td_ucred, td);
if (error)
- goto done2;
+ return (error);
error = socreate(uap->domain, &so2, uap->type, uap->protocol,
td->td_ucred, td);
if (error)
@@ -670,7 +656,7 @@ socketpair(td, uap)
goto free4;
fdrop(fp1, td);
fdrop(fp2, td);
- goto done2;
+ return (0);
free4:
fdclose(fdp, fp2, sv[1], td);
fdrop(fp2, td);
@@ -683,8 +669,6 @@ free2:
free1:
if (so1 != NULL)
(void)soclose(so1);
-done2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -770,10 +754,9 @@ kern_sendit(td, s, mp, flags, control, segflg)
struct uio *ktruio = NULL;
#endif
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
if (error)
- goto bad2;
+ return (error);
so = (struct socket *)fp->f_data;
#ifdef MAC
@@ -826,8 +809,6 @@ kern_sendit(td, s, mp, flags, control, segflg)
#endif
bad:
fdrop(fp, td);
-bad2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -968,12 +949,9 @@ kern_recvit(td, s, mp, fromseg, controlp)
if(controlp != NULL)
*controlp = 0;
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
- if (error) {
- NET_UNLOCK_GIANT();
+ if (error)
return (error);
- }
so = fp->f_data;
#ifdef MAC
@@ -982,7 +960,6 @@ kern_recvit(td, s, mp, fromseg, controlp)
SOCK_UNLOCK(so);
if (error) {
fdrop(fp, td);
- NET_UNLOCK_GIANT();
return (error);
}
#endif
@@ -998,7 +975,6 @@ kern_recvit(td, s, mp, fromseg, controlp)
for (i = 0; i < mp->msg_iovlen; i++, iov++) {
if ((auio.uio_resid += iov->iov_len) < 0) {
fdrop(fp, td);
- NET_UNLOCK_GIANT();
return (EINVAL);
}
}
@@ -1094,7 +1070,6 @@ kern_recvit(td, s, mp, fromseg, controlp)
}
out:
fdrop(fp, td);
- NET_UNLOCK_GIANT();
if (fromsa)
FREE(fromsa, M_SONAME);
@@ -1285,14 +1260,12 @@ shutdown(td, uap)
struct file *fp;
int error;
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, uap->s, &fp, NULL);
if (error == 0) {
so = fp->f_data;
error = soshutdown(so, uap->how);
fdrop(fp, td);
}
- NET_UNLOCK_GIANT();
return (error);
}
@@ -1349,14 +1322,12 @@ kern_setsockopt(td, s, level, name, val, valseg, valsize)
panic("kern_setsockopt called with bad valseg");
}
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
if (error == 0) {
so = fp->f_data;
error = sosetopt(so, &sopt);
fdrop(fp, td);
}
- NET_UNLOCK_GIANT();
return(error);
}
@@ -1429,7 +1400,6 @@ kern_getsockopt(td, s, level, name, val, valseg, valsize)
panic("kern_getsockopt called with bad valseg");
}
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
if (error == 0) {
so = fp->f_data;
@@ -1437,7 +1407,6 @@ kern_getsockopt(td, s, level, name, val, valseg, valsize)
*valsize = sopt.sopt_valsize;
fdrop(fp, td);
}
- NET_UNLOCK_GIANT();
return (error);
}
@@ -1492,10 +1461,9 @@ kern_getsockname(struct thread *td, int fd, struct sockaddr **sa,
if (*alen < 0)
return (EINVAL);
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, fd, &fp, NULL);
if (error)
- goto done;
+ return (error);
so = fp->f_data;
*sa = NULL;
error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa);
@@ -1512,8 +1480,6 @@ bad:
free(*sa, M_SONAME);
*sa = NULL;
}
-done:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -1588,14 +1554,13 @@ kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
if (*alen < 0)
return (EINVAL);
- NET_LOCK_GIANT();
error = getsock(td->td_proc->p_fd, fd, &fp, NULL);
if (error)
- goto done2;
+ return (error);
so = fp->f_data;
if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) {
error = ENOTCONN;
- goto done1;
+ goto done;
}
*sa = NULL;
error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa);
@@ -1611,10 +1576,8 @@ bad:
free(*sa, M_SONAME);
*sa = NULL;
}
-done1:
+done:
fdrop(fp, td);
-done2:
- NET_UNLOCK_GIANT();
return (error);
}
@@ -1823,8 +1786,6 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
int error, hdrlen = 0, mnw = 0;
int vfslocked;
- NET_LOCK_GIANT();
-
/*
* The file descriptor must be a regular file and have a
* backing VM object.
@@ -2242,8 +2203,6 @@ out:
if (m)
m_freem(m);
- NET_UNLOCK_GIANT();
-
if (error == ERESTART)
error = EINTR;
OpenPOWER on IntegriCloud