aboutsummaryrefslogtreecommitdiff
path: root/sys/netsmb
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2009-06-01 21:17:03 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2009-06-01 21:17:03 +0000
commit74fb0ba732c0470e4cae21d0a7af01715bd77bc3 (patch)
tree13628b6be10af95db7dc7d8ef88b3291d48583ab /sys/netsmb
parentb2bc85365907ed05547af9b400576928866915b9 (diff)
downloadsrc-74fb0ba732c0470e4cae21d0a7af01715bd77bc3.tar.gz
src-74fb0ba732c0470e4cae21d0a7af01715bd77bc3.zip
Rework socket upcalls to close some races with setup/teardown of upcalls.
- Each socket upcall is now invoked with the appropriate socket buffer locked. It is not permissible to call soisconnected() with this lock held; however, so socket upcalls now return an integer value. The two possible values are SU_OK and SU_ISCONNECTED. If an upcall returns SU_ISCONNECTED, then the soisconnected() will be invoked on the socket after the socket buffer lock is dropped. - A new API is provided for setting and clearing socket upcalls. The API consists of soupcall_set() and soupcall_clear(). - To simplify locking, each socket buffer now has a separate upcall. - When a socket upcall returns SU_ISCONNECTED, the upcall is cleared from the receive socket buffer automatically. Note that a SO_SND upcall should never return SU_ISCONNECTED. - All this means that accept filters should now return SU_ISCONNECTED instead of calling soisconnected() directly. They also no longer need to explicitly clear the upcall on the new socket. - The HTTP accept filter still uses soupcall_set() to manage its internal state machine, but other accept filters no longer have any explicit knowlege of socket upcall internals aside from their return value. - The various RPC client upcalls currently drop the socket buffer lock while invoking soreceive() as a temporary band-aid. The plan for the future is to add a new flag to allow soreceive() to be called with the socket buffer locked. - The AIO callback for socket I/O is now also invoked with the socket buffer locked. Previously sowakeup() would drop the socket buffer lock only to call aio_swake() which immediately re-acquired the socket buffer lock for the duration of the function call. Discussed with: rwatson, rmacklem
Notes
Notes: svn path=/head/; revision=193272
Diffstat (limited to 'sys/netsmb')
-rw-r--r--sys/netsmb/smb_trantcp.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/sys/netsmb/smb_trantcp.c b/sys/netsmb/smb_trantcp.c
index 167b74be0191..1a74e728b6ff 100644
--- a/sys/netsmb/smb_trantcp.c
+++ b/sys/netsmb/smb_trantcp.c
@@ -100,14 +100,15 @@ nb_intr(struct nbpcb *nbp, struct proc *p)
return 0;
}
-static void
+static int
nb_upcall(struct socket *so, void *arg, int waitflag)
{
struct nbpcb *nbp = arg;
if (arg == NULL || nbp->nbp_selectid == NULL)
- return;
+ return (SU_OK);
wakeup(nbp->nbp_selectid);
+ return (SU_OK);
}
static int
@@ -152,10 +153,8 @@ nb_connect_in(struct nbpcb *nbp, struct sockaddr_in *to, struct thread *td)
if (error)
return error;
nbp->nbp_tso = so;
- so->so_upcallarg = (caddr_t)nbp;
- so->so_upcall = nb_upcall;
SOCKBUF_LOCK(&so->so_rcv);
- so->so_rcv.sb_flags |= SB_UPCALL;
+ soupcall_set(so, SO_RCV, nb_upcall, nbp);
SOCKBUF_UNLOCK(&so->so_rcv);
so->so_rcv.sb_timeo = (5 * hz);
so->so_snd.sb_timeo = (5 * hz);