PERFORCE change 181681 for review
Ana Kukec
anchie at FreeBSD.org
Sun Aug 1 13:21:40 UTC 2010
http://p4web.freebsd.org/@@181681?ac=10
Change 181681 by anchie at 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;
More information about the p4-projects
mailing list