From 92d8381dd544a8237b3fd68c4e7fce9bd0903fb2 Mon Sep 17 00:00:00 2001 From: tanimura Date: Mon, 20 May 2002 05:41:09 +0000 Subject: 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 --- sys/fs/portalfs/portal_vnops.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'sys/fs/portalfs') diff --git a/sys/fs/portalfs/portal_vnops.c b/sys/fs/portalfs/portal_vnops.c index b345c57..23b471f 100644 --- a/sys/fs/portalfs/portal_vnops.c +++ b/sys/fs/portalfs/portal_vnops.c @@ -43,24 +43,26 @@ */ #include -#include -#include -#include -#include -#include -#include -#include #include #include -#include -#include +#include +#include +#include #include -#include #include +#include +#include +#include +#include #include #include +#include +#include +#include +#include #include #include +#include #include static int portal_fileid = PORTAL_ROOTFILEID+1; @@ -182,8 +184,12 @@ portal_connect(so, so2) if (so->so_type != so2->so_type) return (EPROTOTYPE); - if ((so2->so_options & SO_ACCEPTCONN) == 0) + SOCK_LOCK(so2); + if ((so2->so_options & SO_ACCEPTCONN) == 0) { + SOCK_UNLOCK(so2); return (ECONNREFUSED); + } + SOCK_UNLOCK(so2); if ((so3 = sonewconn(so2, 0)) == 0) return (ECONNREFUSED); @@ -280,14 +286,17 @@ portal_open(ap) * and keep polling the reference count. XXX. */ s = splnet(); + SOCK_LOCK(so); while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { if (fmp->pm_server->f_count == 1) { + SOCK_UNLOCK(so); error = ECONNREFUSED; splx(s); goto bad; } - (void) tsleep((caddr_t) &so->so_timeo, PSOCK, "portalcon", 5 * hz); + (void) msleep((caddr_t) &so->so_timeo, SOCK_MTX(so), PSOCK, "portalcon", 5 * hz); } + SOCK_UNLOCK(so); splx(s); if (so->so_error) { -- cgit v1.1