Create a per-module mutex on MOD_LOAD, and destroy it on MOD_UNLOAD.
(This fixes witness_destroy() panic after module unload.) OK'ed by: rwatson, julian
This commit is contained in:
parent
6ab93aca6d
commit
30aabc9afd
@ -63,6 +63,7 @@
|
||||
#define ERROUT(x) do { error = (x); goto done; } while (0)
|
||||
|
||||
/* Netgraph methods */
|
||||
static int ng_device_mod_event(module_t, int, void *);
|
||||
static ng_constructor_t ng_device_constructor;
|
||||
static ng_rcvmsg_t ng_device_rcvmsg;
|
||||
static ng_shutdown_t ng_device_shutdown;
|
||||
@ -74,6 +75,7 @@ static ng_disconnect_t ng_device_disconnect;
|
||||
static struct ng_type ngd_typestruct = {
|
||||
.version = NG_ABI_VERSION,
|
||||
.name = NG_DEVICE_NODE_TYPE,
|
||||
.mod_event = ng_device_mod_event,
|
||||
.constructor = ng_device_constructor,
|
||||
.rcvmsg = ng_device_rcvmsg,
|
||||
.shutdown = ng_device_shutdown,
|
||||
@ -101,7 +103,6 @@ typedef struct ngd_private *priv_p;
|
||||
/* List of all active nodes and mutex to protect it */
|
||||
static SLIST_HEAD(, ngd_private) ngd_nodes = SLIST_HEAD_INITIALIZER(ngd_nodes);
|
||||
static struct mtx ng_device_mtx;
|
||||
MTX_SYSINIT(ng_device, &ng_device_mtx, "ng_device", MTX_DEF);
|
||||
|
||||
/* Maximum number of NGD devices */
|
||||
#define MAX_NGD 25 /* should be more than enough for now */
|
||||
@ -535,3 +536,25 @@ get_free_unit()
|
||||
|
||||
return (unit);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle loading and unloading for this node type.
|
||||
*/
|
||||
static int
|
||||
ng_device_mod_event(module_t mod, int event, void *data)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
mtx_init(&ng_device_mtx, "ng_device", NULL, MTX_DEF);
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
mtx_destroy(&ng_device_mtx);
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ static void ng_eiface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
||||
#endif
|
||||
|
||||
/* Netgraph methods */
|
||||
static int ng_eiface_mod_event(module_t, int, void *);
|
||||
static ng_constructor_t ng_eiface_constructor;
|
||||
static ng_rcvmsg_t ng_eiface_rcvmsg;
|
||||
static ng_shutdown_t ng_eiface_rmnode;
|
||||
@ -104,6 +105,7 @@ static ng_disconnect_t ng_eiface_disconnect;
|
||||
static struct ng_type typestruct = {
|
||||
.version = NG_ABI_VERSION,
|
||||
.name = NG_EIFACE_NODE_TYPE,
|
||||
.mod_event = ng_eiface_mod_event,
|
||||
.constructor = ng_eiface_constructor,
|
||||
.rcvmsg = ng_eiface_rcvmsg,
|
||||
.shutdown = ng_eiface_rmnode,
|
||||
@ -124,7 +126,6 @@ static int ng_units_in_use = 0;
|
||||
#define UNITS_BITSPERWORD (sizeof(*ng_eiface_units) * NBBY)
|
||||
|
||||
static struct mtx ng_eiface_mtx;
|
||||
MTX_SYSINIT(ng_eiface, &ng_eiface_mtx, "ng_eiface", MTX_DEF);
|
||||
|
||||
/************************************************************************
|
||||
HELPER STUFF
|
||||
@ -665,3 +666,25 @@ ng_eiface_disconnect(hook_p hook)
|
||||
priv->ether = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle loading and unloading for this node type.
|
||||
*/
|
||||
static int
|
||||
ng_eiface_mod_event(module_t mod, int event, void *data)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
mtx_init(&ng_eiface_mtx, "ng_eiface", NULL, MTX_DEF);
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
mtx_destroy(&ng_eiface_mtx);
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
@ -204,6 +204,7 @@ static void ng_fec_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
||||
#endif
|
||||
|
||||
/* Netgraph methods */
|
||||
static int ng_fec_mod_event(module_t, int, void *);
|
||||
static ng_constructor_t ng_fec_constructor;
|
||||
static ng_rcvmsg_t ng_fec_rcvmsg;
|
||||
static ng_shutdown_t ng_fec_shutdown;
|
||||
@ -245,6 +246,7 @@ static const struct ng_cmdlist ng_fec_cmds[] = {
|
||||
static struct ng_type typestruct = {
|
||||
.version = NG_ABI_VERSION,
|
||||
.name = NG_FEC_NODE_TYPE,
|
||||
.mod_event = ng_fec_mod_event,
|
||||
.constructor = ng_fec_constructor,
|
||||
.rcvmsg = ng_fec_rcvmsg,
|
||||
.shutdown = ng_fec_shutdown,
|
||||
@ -261,7 +263,6 @@ static int ng_units_in_use = 0;
|
||||
#define UNITS_BITSPERWORD (sizeof(*ng_fec_units) * NBBY)
|
||||
|
||||
static struct mtx ng_fec_mtx;
|
||||
MTX_SYSINIT(ng_fec, &ng_fec_mtx, "ng_fec", MTX_DEF);
|
||||
|
||||
/*
|
||||
* Find the first free unit number for a new interface.
|
||||
@ -1243,3 +1244,25 @@ ng_fec_shutdown(node_p node)
|
||||
NG_NODE_UNREF(node);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle loading and unloading for this node type.
|
||||
*/
|
||||
static int
|
||||
ng_fec_mod_event(module_t mod, int event, void *data)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
mtx_init(&ng_fec_mtx, "ng_fec", NULL, MTX_DEF);
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
mtx_destroy(&ng_fec_mtx);
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ static void ng_iface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
||||
#endif
|
||||
|
||||
/* Netgraph methods */
|
||||
static int ng_iface_mod_event(module_t, int, void *);
|
||||
static ng_constructor_t ng_iface_constructor;
|
||||
static ng_rcvmsg_t ng_iface_rcvmsg;
|
||||
static ng_shutdown_t ng_iface_shutdown;
|
||||
@ -195,6 +196,7 @@ static const struct ng_cmdlist ng_iface_cmds[] = {
|
||||
static struct ng_type typestruct = {
|
||||
.version = NG_ABI_VERSION,
|
||||
.name = NG_IFACE_NODE_TYPE,
|
||||
.mod_event = ng_iface_mod_event,
|
||||
.constructor = ng_iface_constructor,
|
||||
.rcvmsg = ng_iface_rcvmsg,
|
||||
.shutdown = ng_iface_shutdown,
|
||||
@ -214,7 +216,6 @@ static int ng_units_in_use = 0;
|
||||
#define UNITS_BITSPERWORD (sizeof(*ng_iface_units) * NBBY)
|
||||
|
||||
static struct mtx ng_iface_mtx;
|
||||
MTX_SYSINIT(ng_iface, &ng_iface_mtx, "ng_iface", MTX_DEF);
|
||||
|
||||
/************************************************************************
|
||||
HELPER STUFF
|
||||
@ -836,3 +837,24 @@ ng_iface_disconnect(hook_p hook)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle loading and unloading for this node type.
|
||||
*/
|
||||
static int
|
||||
ng_iface_mod_event(module_t mod, int event, void *data)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
mtx_init(&ng_iface_mtx, "ng_iface", NULL, MTX_DEF);
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
mtx_destroy(&ng_iface_mtx);
|
||||
break;
|
||||
default:
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
@ -159,7 +159,6 @@ SYSCTL_INT(_net_graph, OID_AUTO, recvspace, CTLFLAG_RW,
|
||||
static LIST_HEAD(, ngpcb) ngsocklist;
|
||||
|
||||
static struct mtx ngsocketlist_mtx;
|
||||
MTX_SYSINIT(ngsocketlist, &ngsocketlist_mtx, "ng_socketlist", MTX_DEF);
|
||||
|
||||
#define sotongpcb(so) ((struct ngpcb *)(so)->so_pcb)
|
||||
|
||||
@ -1094,6 +1093,7 @@ ngs_mod_event(module_t mod, int event, void *data)
|
||||
|
||||
switch (event) {
|
||||
case MOD_LOAD:
|
||||
mtx_init(&ngsocketlist_mtx, "ng_socketlist", NULL, MTX_DEF);
|
||||
/* Register protocol domain */
|
||||
net_add_domain(&ngdomain);
|
||||
break;
|
||||
@ -1109,6 +1109,7 @@ ngs_mod_event(module_t mod, int event, void *data)
|
||||
/* Unregister protocol domain XXX can't do this yet.. */
|
||||
if ((error = net_rm_domain(&ngdomain)) != 0)
|
||||
break;
|
||||
mtx_destroy(&ngsocketlist_mtx);
|
||||
} else
|
||||
#endif
|
||||
error = EBUSY;
|
||||
|
Loading…
x
Reference in New Issue
Block a user