Index: if_vtnet.c =================================================================== --- if_vtnet.c (revision 299234) +++ if_vtnet.c (working copy) @@ -308,27 +308,36 @@ MODULE_DEPEND(vtnet, netmap, 1, 1, 1); #endif /* DEV_NETMAP */ +static struct sx mlu; +SX_SYSINIT(vtnet_mlu, &mlu, "vtnet mod load/unload"); + static int vtnet_modevent(module_t mod, int type, void *unused) { - int error; + int error = 0; + static int loaded = 0; - error = 0; - switch (type) { case MOD_LOAD: - vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr", - sizeof(struct vtnet_tx_header), - NULL, NULL, NULL, NULL, 0, 0); + sx_xlock(&mlu); + if (loaded++ == 0) + vtnet_tx_header_zone = uma_zcreate("vtnet_tx_hdr", + sizeof(struct vtnet_tx_header), + NULL, NULL, NULL, NULL, 0, 0); + sx_xunlock(&mlu); break; case MOD_QUIESCE: case MOD_UNLOAD: - if (uma_zone_get_cur(vtnet_tx_header_zone) > 0) - error = EBUSY; - else if (type == MOD_UNLOAD) { - uma_zdestroy(vtnet_tx_header_zone); - vtnet_tx_header_zone = NULL; + sx_xlock(&mlu); + if (--loaded == 0) { + if (uma_zone_get_cur(vtnet_tx_header_zone) > 0) + error = EBUSY; + else if (type == MOD_UNLOAD) { + uma_zdestroy(vtnet_tx_header_zone); + vtnet_tx_header_zone = NULL; + } } + sx_xunlock(&mlu); break; case MOD_SHUTDOWN: break;