From owner-p4-projects@FreeBSD.ORG Sun Aug 1 13:21:39 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BEF711065674; Sun, 1 Aug 2010 13:21:39 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B074106566C for ; Sun, 1 Aug 2010 13:21:39 +0000 (UTC) (envelope-from anchie@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 57E038FC0C for ; Sun, 1 Aug 2010 13:21:39 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id o71DLdYs094431 for ; Sun, 1 Aug 2010 13:21:39 GMT (envelope-from anchie@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id o71DLd3V094429 for perforce@freebsd.org; Sun, 1 Aug 2010 13:21:39 GMT (envelope-from anchie@FreeBSD.org) Date: Sun, 1 Aug 2010 13:21:39 GMT Message-Id: <201008011321.o71DLd3V094429@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to anchie@FreeBSD.org using -f From: Ana Kukec To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181681 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Aug 2010 13:21:40 -0000 http://p4web.freebsd.org/@@181681?ac=10 Change 181681 by anchie@anchie_malimis on 2010/08/01 13:20:58 Added initial version of locking, SEND locks and VNET_LIST locks. Affected files ... .. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#49 edit Differences ... ==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#49 (text+ko) ==== @@ -63,24 +63,41 @@ u_long send_sendspace = 8 * (1024 + sizeof(struct sockaddr_send)); u_long send_recvspace = 9216; +struct mtx send_mtx; +#define SEND_LOCK_INIT() mtx_init(&send_mtx, "send_mtx", NULL, MTX_DEF) +#define SEND_LOCK() mtx_lock(&send_mtx) +#define SEND_UNLOCK() mtx_unlock(&send_mtx) +#define SEND_LOCK_DESTROY() mtx_destroy(&send_mtx) + static int send_attach(struct socket *so, int proto, struct thread *td) { int error; - if (V_send_so != NULL) + SEND_LOCK(); + if (V_send_so != NULL) { + SEND_UNLOCK(); return (EEXIST); + } error = priv_check(td, PRIV_NETINET_RAW); - if (error) - return (error); - if (proto != IPPROTO_SEND) + if (error) { + SEND_UNLOCK(); + return(error); + } + + if (proto != IPPROTO_SEND) { + SEND_UNLOCK(); return (EPROTONOSUPPORT); + } error = soreserve(so, send_sendspace, send_recvspace); - if (error) - return (error); + if (error) { + SEND_UNLOCK(); + return(error); + } V_send_so = so; + SEND_UNLOCK(); return (0); } @@ -217,8 +234,10 @@ send_close(struct socket *so) { + SEND_LOCK(); if (V_send_so) V_send_so = NULL; + SEND_UNLOCK(); } /* @@ -232,8 +251,11 @@ struct ip6_hdr *ip6; struct sockaddr_send sendsrc; - if (V_send_so == NULL) + SEND_LOCK(); + if (V_send_so == NULL) { + SEND_UNLOCK(); return (-1); + } /* * Make sure to clear any possible internally embedded scope before @@ -264,6 +286,7 @@ sorwakeup_locked(V_send_so); } + SEND_UNLOCK(); return (0); } @@ -289,10 +312,13 @@ switch (type) { case MOD_LOAD: + SEND_LOCK_INIT(); + error = pf_proto_register(PF_INET6, &send_protosw); if (error != 0) { printf("%s:%d: MOD_LOAD pf_proto_register(): %d\n", __func__, __LINE__, error); + SEND_LOCK_DESTROY(); break; } send_sendso_input_hook = send_input; @@ -301,18 +327,26 @@ /* Do not allow unloading w/o locking. */ return (EBUSY); #ifdef __notyet__ + VNET_LIST_RLOCK_NOSLEEP(); + SEND_LOCK(); VNET_FOREACH(vnet_iter) { CURVNET_SET(vnet_iter); if (V_send_so != NULL) { CURVNET_RESTORE(); + SEND_UNLOCK(); + VNET_LIST_RUNLOCK_NOSLEEP(); return (EBUSY); } CURVNET_RESTORE(); } -#endif + SEND_UNLOCK(); + VNET_LIST_RUNLOCK_NOSLEEP(); error = pf_proto_unregister(PF_INET6, IPPROTO_SEND, SOCK_RAW); + if (error == 0) + SEND_LOCK_DESTROY(); send_sendso_input_hook = NULL; break; +#endif default: error = 0; break;