From 95d0d388ac9c14373708101bce1a8922f43d6386 Mon Sep 17 00:00:00 2001 From: rwatson Date: Sun, 25 Mar 2007 21:44:24 +0000 Subject: [PATCH] Replace GIANT_REQUIRED's present for socket locking with NET_LOCK_GIANT(). If/when someone does the necessary MPSAFEty locking for the NFSv4 client, the socket code is generally MPSAFE now. Spotted by: kris --- sys/rpc/rpcclnt.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/sys/rpc/rpcclnt.c b/sys/rpc/rpcclnt.c index 04e1bce0cf5a..d666e1b4f3a8 100644 --- a/sys/rpc/rpcclnt.c +++ b/sys/rpc/rpcclnt.c @@ -360,15 +360,15 @@ rpcclnt_connect(rpc, td) RPC_RETURN(EFAULT); } - GIANT_REQUIRED; /* XXX until socket locking done */ - /* create the socket */ rpc->rc_so = NULL; saddr = rpc->rc_name; + NET_LOCK_GIANT(); error = socreate(saddr->sa_family, &rpc->rc_so, rpc->rc_sotype, rpc->rc_soproto, td->td_ucred, td); + NET_UNLOCK_GIANT(); if (error) { RPCDEBUG("error %d in socreate()", error); @@ -624,13 +624,13 @@ rpcclnt_disconnect(rpc) { struct socket *so; - GIANT_REQUIRED; /* XXX until socket locking done */ - if (rpc->rc_so) { so = rpc->rc_so; rpc->rc_so = NULL; + NET_LOCK_GIANT(); soshutdown(so, 2); soclose(so); + NET_UNLOCK_GIANT(); } } @@ -678,8 +678,6 @@ rpcclnt_send(so, nam, top, rep) #endif int error, soflags, flags; - GIANT_REQUIRED; /* XXX until socket locking done */ - if (rep) { if (rep->r_flags & R_SOFTTERM) { m_freem(top); @@ -705,7 +703,14 @@ rpcclnt_send(so, nam, top, rep) else flags = 0; + /* + * XXXRW: If/when this code becomes MPSAFE itself, Giant might have + * to be conditionally acquired earlier for the stack so has to avoid + * lock order reversals with any locks held over rpcclnt_send(). + */ + NET_LOCK_GIANT(); error = sosend(so, sendnam, NULL, top, NULL, flags, td); + NET_UNLOCK_GIANT(); if (error) { if (rep) { @@ -763,8 +768,6 @@ rpcclnt_receive(rep, aname, mp, td) #endif int error, sotype, rcvflg; - GIANT_REQUIRED; /* XXX until socket locking done */ - /* * Set up arguments for soreceive() */ @@ -835,7 +838,9 @@ rpcclnt_receive(rep, aname, mp, td) #endif do { rcvflg = MSG_WAITALL; + NET_LOCK_GIANT(); error = soreceive(so, NULL, &auio, NULL, NULL, &rcvflg); + NET_UNLOCK_GIANT(); if (error == EWOULDBLOCK && rep) { if (rep->r_flags & R_SOFTTERM) RPC_RETURN(EINTR); @@ -868,7 +873,9 @@ rpcclnt_receive(rep, aname, mp, td) auio.uio_resid = len; do { rcvflg = MSG_WAITALL; + NET_LOCK_GIANT(); error = soreceive(so, NULL, &auio, mp, NULL, &rcvflg); + NET_UNLOCK_GIANT(); } while (error == EWOULDBLOCK || error == EINTR || error == ERESTART); if (!error && auio.uio_resid > 0) { @@ -894,7 +901,9 @@ rpcclnt_receive(rep, aname, mp, td) #endif do { rcvflg = 0; + NET_LOCK_GIANT(); error = soreceive(so, NULL, &auio, mp, &control, &rcvflg); + NET_UNLOCK_GIANT(); if (control) m_freem(control); if (error == EWOULDBLOCK && rep) { @@ -940,8 +949,10 @@ rpcclnt_receive(rep, aname, mp, td) do { rcvflg = 0; + NET_LOCK_GIANT(); error = soreceive(so, getnam, &auio, mp, NULL, &rcvflg); - RPCDEBUG("soreceivce returns %d", error); + NET_UNLOCK_GIANT(); + RPCDEBUG("soreceive returns %d", error); if (error == EWOULDBLOCK && (rep->r_flags & R_SOFTTERM)) { RPCDEBUG("wouldblock && softerm -> EINTR"); RPC_RETURN(EINTR);