diff options
author | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
---|---|---|
committer | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
commit | 92d8381dd544a8237b3fd68c4e7fce9bd0903fb2 (patch) | |
tree | 2465ddbcecac65f96c5c6d5cef1a4fe3f1ac03f8 /sys/netsmb | |
parent | 969293170b27461145f69a538d5abd15fea34ba1 (diff) | |
download | FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.zip FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.tar.gz |
Lock down a socket, milestone 1.
o Add a mutex (sb_mtx) to struct sockbuf. This protects the data in a
socket buffer. The mutex in the receive buffer also protects the data
in struct socket.
o Determine the lock strategy for each members in struct socket.
o Lock down the following members:
- so_count
- so_options
- so_linger
- so_state
o Remove *_locked() socket APIs. Make the following socket APIs
touching the members above now require a locked socket:
- sodisconnect()
- soisconnected()
- soisconnecting()
- soisdisconnected()
- soisdisconnecting()
- sofree()
- soref()
- sorele()
- sorwakeup()
- sotryfree()
- sowakeup()
- sowwakeup()
Reviewed by: alfred
Diffstat (limited to 'sys/netsmb')
-rw-r--r-- | sys/netsmb/smb_trantcp.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/netsmb/smb_trantcp.c b/sys/netsmb/smb_trantcp.c index bb017bf..53c918b 100644 --- a/sys/netsmb/smb_trantcp.c +++ b/sys/netsmb/smb_trantcp.c @@ -250,15 +250,18 @@ nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct thread *td) if (error) goto bad; s = splnet(); + SOCK_LOCK(so); while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { - tsleep(&so->so_timeo, PSOCK, "nbcon", 2 * hz); + msleep(&so->so_timeo, SOCK_MTX(so), PSOCK, "nbcon", 2 * hz); if ((so->so_state & SS_ISCONNECTING) && so->so_error == 0 && (error = nb_intr(nbp, td->td_proc)) != 0) { so->so_state &= ~SS_ISCONNECTING; + SOCK_UNLOCK(so); splx(s); goto bad; } } + SOCK_UNLOCK(so); if (so->so_error) { error = so->so_error; so->so_error = 0; @@ -408,12 +411,15 @@ nbssn_recv(struct nbpcb *nbp, struct mbuf **mpp, int *lenp, for(;;) { m = NULL; error = nbssn_recvhdr(nbp, &len, &rpcode, MSG_DONTWAIT, td); + SOCK_LOCK(so); if (so->so_state & (SS_ISDISCONNECTING | SS_ISDISCONNECTED | SS_CANTRCVMORE)) { + SOCK_UNLOCK(so); nbp->nbp_state = NBST_CLOSED; NBDEBUG("session closed by peer\n"); return ECONNRESET; } + SOCK_UNLOCK(so); if (error) return error; if (len == 0 && nbp->nbp_state != NBST_SESSION) @@ -639,8 +645,10 @@ smb_nbst_intr(struct smb_vc *vcp) if (nbp == NULL || nbp->nbp_tso == NULL) return; + SOCK_LOCK(nbp->nbp_tso); sorwakeup(nbp->nbp_tso); sowwakeup(nbp->nbp_tso); + SOCK_UNLOCK(nbp->nbp_tso); } static int |