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/nfsclient/nfs_socket.c | |
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/nfsclient/nfs_socket.c')
-rw-r--r-- | sys/nfsclient/nfs_socket.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sys/nfsclient/nfs_socket.c b/sys/nfsclient/nfs_socket.c index 0a4f849..eda43db 100644 --- a/sys/nfsclient/nfs_socket.c +++ b/sys/nfsclient/nfs_socket.c @@ -230,6 +230,7 @@ nfs_connect(struct nfsmount *nmp, struct nfsreq *rep) * that interruptible mounts don't hang here for a long time. */ s = splnet(); + SOCK_LOCK(so); while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { (void) tsleep((caddr_t)&so->so_timeo, PSOCK, "nfscon", 2 * hz); @@ -238,10 +239,12 @@ nfs_connect(struct nfsmount *nmp, struct nfsreq *rep) (error = nfs_sigintr(nmp, rep, (rep->r_td ? rep->r_td->td_proc : NULL))) != 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; @@ -414,10 +417,14 @@ nfs_send(struct socket *so, struct sockaddr *nam, struct mbuf *top, rep->r_flags &= ~R_MUSTRESEND; soflags = rep->r_nmp->nm_soflags; - if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED)) + SOCK_LOCK(so); + if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED)) { + SOCK_UNLOCK(so); sendnam = (struct sockaddr *)0; - else + } else { + SOCK_UNLOCK(so); sendnam = nam; + } if (so->so_type == SOCK_SEQPACKET) flags = MSG_EOR; else @@ -646,10 +653,14 @@ errout: } else { if ((so = rep->r_nmp->nm_so) == NULL) return (EACCES); - if (so->so_state & SS_ISCONNECTED) + SOCK_LOCK(so); + if (so->so_state & SS_ISCONNECTED) { + SOCK_UNLOCK(so); getnam = (struct sockaddr **)0; - else + } else { + SOCK_UNLOCK(so); getnam = aname; + } auio.uio_resid = len = 1000000; auio.uio_td = td; do { |