* Handle loading and unloading for this code. * The only thing we need to link into is the NETISR strucure. */
| 3190 | * The only thing we need to link into is the NETISR strucure. |
| 3191 | */ |
| 3192 | static int |
| 3193 | ngb_mod_event(module_t mod, int event, void *data) |
| 3194 | { |
| 3195 | struct proc *p; |
| 3196 | struct thread *td; |
| 3197 | int i, error = 0; |
| 3198 | |
| 3199 | switch (event) { |
| 3200 | case MOD_LOAD: |
| 3201 | /* Initialize everything. */ |
| 3202 | NG_WORKLIST_LOCK_INIT(); |
| 3203 | rw_init(&ng_typelist_lock, "netgraph types"); |
| 3204 | rw_init(&ng_idhash_lock, "netgraph idhash"); |
| 3205 | rw_init(&ng_namehash_lock, "netgraph namehash"); |
| 3206 | rw_init(&ng_topo_lock, "netgraph topology mutex"); |
| 3207 | #ifdef NETGRAPH_DEBUG |
| 3208 | mtx_init(&ng_nodelist_mtx, "netgraph nodelist mutex", NULL, |
| 3209 | MTX_DEF); |
| 3210 | mtx_init(&ngq_mtx, "netgraph item list mutex", NULL, |
| 3211 | MTX_DEF); |
| 3212 | #endif |
| 3213 | ng_qzone = uma_zcreate("NetGraph items", sizeof(struct ng_item), |
| 3214 | NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0); |
| 3215 | uma_zone_set_max(ng_qzone, maxalloc); |
| 3216 | ng_qdzone = uma_zcreate("NetGraph data items", |
| 3217 | sizeof(struct ng_item), NULL, NULL, NULL, NULL, |
| 3218 | UMA_ALIGN_CACHE, 0); |
| 3219 | uma_zone_set_max(ng_qdzone, maxdata); |
| 3220 | /* Autoconfigure number of threads. */ |
| 3221 | if (numthreads <= 0) |
| 3222 | numthreads = mp_ncpus; |
| 3223 | /* Create threads. */ |
| 3224 | p = NULL; /* start with no process */ |
| 3225 | for (i = 0; i < numthreads; i++) { |
| 3226 | if (kproc_kthread_add(ngthread, NULL, &p, &td, |
| 3227 | RFHIGHPID, 0, "ng_queue", "ng_queue%d", i)) { |
| 3228 | numthreads = i; |
| 3229 | break; |
| 3230 | } |
| 3231 | } |
| 3232 | break; |
| 3233 | case MOD_UNLOAD: |
| 3234 | /* You can't unload it because an interface may be using it. */ |
| 3235 | error = EBUSY; |
| 3236 | break; |
| 3237 | default: |
| 3238 | error = EOPNOTSUPP; |
| 3239 | break; |
| 3240 | } |
| 3241 | return (error); |
| 3242 | } |
| 3243 | |
| 3244 | static moduledata_t netgraph_mod = { |
| 3245 | "netgraph", |
nothing calls this directly
no test coverage detected