Lines Matching refs:mp

100 	fmd_module_t *mp = arg;  in fmd_module_start()  local
104 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_start()
106 if (mp->mod_ops->mop_init(mp) != 0 || mp->mod_error != 0) { in fmd_module_start()
107 if (mp->mod_error == 0) in fmd_module_start()
108 mp->mod_error = errno ? errno : EFMD_MOD_INIT; in fmd_module_start()
113 fmd_eventq_insert_at_head(mp->mod_queue, fmd.d_mod_event); in fmd_module_start()
115 ASSERT(MUTEX_HELD(&mp->mod_lock)); in fmd_module_start()
116 mp->mod_flags |= FMD_MOD_INIT; in fmd_module_start()
118 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_start()
119 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_start()
125 for (xp = fmd_list_next(&mp->mod_transports); in fmd_module_start()
134 while ((ep = fmd_eventq_delete(mp->mod_queue)) != NULL) { in fmd_module_start()
139 if (mp->mod_error != 0) { in fmd_module_start()
140 fmd_eventq_done(mp->mod_queue); in fmd_module_start()
145 mp->mod_ops->mop_dispatch(mp, ep); in fmd_module_start()
146 fmd_eventq_done(mp->mod_queue); in fmd_module_start()
153 fmd_module_lock(mp); in fmd_module_start()
158 fmd_ckpt_save(mp); in fmd_module_start()
159 fmd_module_unlock(mp); in fmd_module_start()
163 if (mp->mod_ops->mop_fini(mp) != 0 && mp->mod_error == 0) in fmd_module_start()
164 mp->mod_error = errno ? errno : EFMD_MOD_FINI; in fmd_module_start()
166 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_start()
167 mp->mod_flags |= FMD_MOD_FINI; in fmd_module_start()
170 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_start()
171 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_start()
177 fmd_module_t *mp = fmd_zalloc(sizeof (fmd_module_t), FMD_SLEEP); in fmd_module_create() local
188 (void) pthread_mutex_init(&mp->mod_lock, NULL); in fmd_module_create()
189 (void) pthread_cond_init(&mp->mod_cv, NULL); in fmd_module_create()
190 (void) pthread_mutex_init(&mp->mod_stats_lock, NULL); in fmd_module_create()
192 mp->mod_name = fmd_strdup(buf, FMD_SLEEP); in fmd_module_create()
193 mp->mod_path = fmd_strdup(path, FMD_SLEEP); in fmd_module_create()
194 mp->mod_ops = ops; in fmd_module_create()
195 mp->mod_ustat = fmd_ustat_create(); in fmd_module_create()
199 "%s/%s/%s", fmd.d_rootdir, dir, mp->mod_name); in fmd_module_create()
201 mp->mod_ckpt = fmd_strdup(buf, FMD_SLEEP); in fmd_module_create()
204 mp->mod_timerids = fmd_idspace_create(mp->mod_name, 1, limit + 1); in fmd_module_create()
205 mp->mod_threads = fmd_idspace_create(mp->mod_name, 0, INT_MAX); in fmd_module_create()
207 fmd_buf_hash_create(&mp->mod_bufs); in fmd_module_create()
208 fmd_serd_hash_create(&mp->mod_serds); in fmd_module_create()
210 mp->mod_topo_current = fmd_topo_hold(); in fmd_module_create()
213 fmd_list_append(&fmd.d_mod_list, mp); in fmd_module_create()
220 if ((mp->mod_stats = (fmd_modstat_t *)fmd_ustat_insert(mp->mod_ustat, in fmd_module_create()
224 fmd_module_destroy(mp); in fmd_module_create()
228 if (nv_alloc_init(&mp->mod_nva_sleep, in fmd_module_create()
229 &fmd_module_nva_ops_sleep, mp) != 0 || in fmd_module_create()
230 nv_alloc_init(&mp->mod_nva_nosleep, in fmd_module_create()
231 &fmd_module_nva_ops_nosleep, mp) != 0) { in fmd_module_create()
234 fmd_module_destroy(mp); in fmd_module_create()
240 mp->mod_queue = fmd_eventq_create(mp, in fmd_module_create()
241 &mp->mod_stats->ms_evqstat, &mp->mod_stats_lock, limit); in fmd_module_create()
244 &mp->mod_stats->ms_memlimit.fmds_value.ui64); in fmd_module_create()
247 &mp->mod_stats->ms_buflimit.fmds_value.ui64); in fmd_module_create()
250 &mp->mod_stats->ms_thrlimit.fmds_value.ui32); in fmd_module_create()
253 &mp->mod_stats->ms_doorthrlimit.fmds_value.ui32); in fmd_module_create()
256 &mp->mod_stats->ms_xprtlimit.fmds_value.ui32); in fmd_module_create()
259 &mp->mod_stats->ms_xprtqlimit.fmds_value.ui32); in fmd_module_create()
262 &mp->mod_stats->ms_ckpt_save.fmds_value.bool); in fmd_module_create()
265 &mp->mod_stats->ms_ckpt_restore.fmds_value.bool); in fmd_module_create()
268 &mp->mod_stats->ms_ckpt_zeroed.fmds_value.bool); in fmd_module_create()
270 if (mp->mod_stats->ms_ckpt_zeroed.fmds_value.bool) in fmd_module_create()
271 fmd_ckpt_delete(mp); /* blow away any pre-existing checkpoint */ in fmd_module_create()
279 fmd_module_hold(mp); in fmd_module_create()
280 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_create()
281 mp->mod_stats->ms_loadtime.fmds_value.ui64 = gethrtime(); in fmd_module_create()
282 mp->mod_thread = fmd_thread_create(mp, fmd_module_start, mp); in fmd_module_create()
284 if (mp->mod_thread == NULL) { in fmd_module_create()
286 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_create()
287 fmd_module_rele(mp); in fmd_module_create()
297 while (!(mp->mod_flags & FMD_MOD_INIT) && mp->mod_error == 0) in fmd_module_create()
298 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_module_create()
304 if (!(mp->mod_flags & FMD_MOD_INIT)) { in fmd_module_create()
305 err = mp->mod_error; in fmd_module_create()
306 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_create()
309 fmd_ckpt_rename(mp); /* move aside bad checkpoint */ in fmd_module_create()
323 fmd_module_unload(mp); in fmd_module_create()
324 fmd_module_rele(mp); in fmd_module_create()
330 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_create()
331 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_create()
333 fmd_dprintf(FMD_DBG_MOD, "loaded module %s\n", mp->mod_name); in fmd_module_create()
334 return (mp); in fmd_module_create()
338 fmd_module_untimeout(fmd_idspace_t *ids, id_t id, fmd_module_t *mp) in fmd_module_untimeout() argument
347 if (arg != NULL && mp != fmd.d_rmod) in fmd_module_untimeout()
352 fmd_module_unload(fmd_module_t *mp) in fmd_module_unload() argument
356 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_unload()
358 if (mp->mod_flags & FMD_MOD_QUIT) { in fmd_module_unload()
359 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_unload()
363 ASSERT(mp->mod_thread != NULL); in fmd_module_unload()
364 mp->mod_flags |= FMD_MOD_QUIT; in fmd_module_unload()
366 if (mp->mod_queue != NULL) in fmd_module_unload()
367 fmd_eventq_abort(mp->mod_queue); in fmd_module_unload()
374 while ((mp->mod_flags & (FMD_MOD_INIT | FMD_MOD_FINI)) == FMD_MOD_INIT) in fmd_module_unload()
375 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_module_unload()
377 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_unload()
378 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_unload()
380 fmd_thread_destroy(mp->mod_thread, FMD_THREAD_JOIN); in fmd_module_unload()
381 mp->mod_thread = NULL; in fmd_module_unload()
387 fmd_module_lock(mp); in fmd_module_unload()
389 if (mp->mod_timerids != NULL) { in fmd_module_unload()
390 fmd_idspace_apply(mp->mod_timerids, in fmd_module_unload()
391 (void (*)())fmd_module_untimeout, mp); in fmd_module_unload()
393 fmd_idspace_destroy(mp->mod_timerids); in fmd_module_unload()
394 mp->mod_timerids = NULL; in fmd_module_unload()
397 if (mp->mod_threads != NULL) { in fmd_module_unload()
398 fmd_idspace_destroy(mp->mod_threads); in fmd_module_unload()
399 mp->mod_threads = NULL; in fmd_module_unload()
402 (void) fmd_buf_hash_destroy(&mp->mod_bufs); in fmd_module_unload()
403 fmd_serd_hash_destroy(&mp->mod_serds); in fmd_module_unload()
405 while ((mtp = fmd_list_next(&mp->mod_topolist)) != NULL) { in fmd_module_unload()
406 fmd_list_delete(&mp->mod_topolist, mtp); in fmd_module_unload()
411 fmd_module_unlock(mp); in fmd_module_unload()
412 fmd_dprintf(FMD_DBG_MOD, "unloaded module %s\n", mp->mod_name); in fmd_module_unload()
416 fmd_module_destroy(fmd_module_t *mp) in fmd_module_destroy() argument
418 fmd_conf_formal_t *cfp = mp->mod_argv; in fmd_module_destroy()
421 ASSERT(MUTEX_HELD(&mp->mod_lock)); in fmd_module_destroy()
423 if (mp->mod_thread != NULL) { in fmd_module_destroy()
424 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_destroy()
425 fmd_module_unload(mp); in fmd_module_destroy()
426 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_destroy()
429 ASSERT(mp->mod_thread == NULL); in fmd_module_destroy()
430 ASSERT(mp->mod_refs == 0); in fmd_module_destroy()
438 fmd_list_delete(&fmd.d_mod_list, mp); in fmd_module_destroy()
441 if (mp->mod_topo_current != NULL) in fmd_module_destroy()
442 fmd_topo_rele(mp->mod_topo_current); in fmd_module_destroy()
444 if (mp->mod_nva_sleep.nva_ops != NULL) in fmd_module_destroy()
445 nv_alloc_fini(&mp->mod_nva_sleep); in fmd_module_destroy()
446 if (mp->mod_nva_nosleep.nva_ops != NULL) in fmd_module_destroy()
447 nv_alloc_fini(&mp->mod_nva_nosleep); in fmd_module_destroy()
453 if (mp->mod_queue != NULL) { in fmd_module_destroy()
454 fmd_eventq_destroy(mp->mod_queue); in fmd_module_destroy()
455 mp->mod_queue = NULL; in fmd_module_destroy()
458 if (mp->mod_ustat != NULL) { in fmd_module_destroy()
459 (void) pthread_mutex_lock(&mp->mod_stats_lock); in fmd_module_destroy()
460 fmd_ustat_destroy(mp->mod_ustat); in fmd_module_destroy()
461 mp->mod_ustat = NULL; in fmd_module_destroy()
462 mp->mod_stats = NULL; in fmd_module_destroy()
463 (void) pthread_mutex_unlock(&mp->mod_stats_lock); in fmd_module_destroy()
466 for (i = 0; i < mp->mod_dictc; i++) in fmd_module_destroy()
467 fm_dc_closedict(mp->mod_dictv[i]); in fmd_module_destroy()
469 fmd_free(mp->mod_dictv, sizeof (struct fm_dc_handle *) * mp->mod_dictc); in fmd_module_destroy()
471 if (mp->mod_conf != NULL) in fmd_module_destroy()
472 fmd_conf_close(mp->mod_conf); in fmd_module_destroy()
474 for (i = 0; i < mp->mod_argc; i++, cfp++) { in fmd_module_destroy()
479 fmd_free(mp->mod_argv, sizeof (fmd_conf_formal_t) * mp->mod_argc); in fmd_module_destroy()
481 fmd_strfree(mp->mod_name); in fmd_module_destroy()
482 fmd_strfree(mp->mod_path); in fmd_module_destroy()
483 fmd_strfree(mp->mod_ckpt); in fmd_module_destroy()
484 nvlist_free(mp->mod_fmri); in fmd_module_destroy()
485 fmd_strfree(mp->mod_vers); in fmd_module_destroy()
487 fmd_free(mp, sizeof (fmd_module_t)); in fmd_module_destroy()
497 fmd_module_error(fmd_module_t *mp, int err) in fmd_module_error() argument
503 ASSERT(MUTEX_HELD(&mp->mod_lock)); in fmd_module_error()
508 if (mp->mod_error == 0) in fmd_module_error()
509 mp->mod_error = err; in fmd_module_error()
511 if (mp == fmd.d_self) in fmd_module_error()
521 nvl = fmd_protocol_moderror(mp, EFMD_MOD_FAIL, fmd_strerror(err)); in fmd_module_error()
528 fmd_module_dispatch(fmd_module_t *mp, fmd_event_t *e) in fmd_module_dispatch() argument
530 const fmd_hdl_ops_t *ops = mp->mod_info->fmdi_ops; in fmd_module_dispatch()
532 fmd_hdl_t *hdl = (fmd_hdl_t *)mp; in fmd_module_dispatch()
541 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_dispatch()
543 ASSERT(!(mp->mod_flags & FMD_MOD_BUSY)); in fmd_module_dispatch()
544 mp->mod_flags |= FMD_MOD_BUSY; in fmd_module_dispatch()
546 if ((err = setjmp(mp->mod_jmpbuf)) != 0) { in fmd_module_dispatch()
547 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_dispatch()
548 fmd_module_error(mp, err); in fmd_module_dispatch()
551 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_dispatch()
552 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_dispatch()
567 ASSERT(t->mt_mod == mp); in fmd_module_dispatch()
575 fmd_modstat_publish(mp); in fmd_module_dispatch()
594 old_topo = mp->mod_topo_current; in fmd_module_dispatch()
595 fmd_module_lock(mp); in fmd_module_dispatch()
596 mp->mod_topo_current = (fmd_topo_t *)ep->ev_data; in fmd_module_dispatch()
597 fmd_topo_addref(mp->mod_topo_current); in fmd_module_dispatch()
598 fmd_module_unlock(mp); in fmd_module_dispatch()
600 ops->fmdo_topo(hdl, mp->mod_topo_current->ft_hdl); in fmd_module_dispatch()
605 fmd_module_exit(mp); in fmd_module_dispatch()
609 fmd_module_transport(fmd_module_t *mp, fmd_xprt_t *xp, fmd_event_t *e) in fmd_module_transport() argument
612 fmd_hdl_t *hdl = (fmd_hdl_t *)mp; in fmd_module_transport()
615 return (mp->mod_info->fmdi_ops->fmdo_send(hdl, xp, e, ep->ev_nvl)); in fmd_module_transport()
633 fmd_module_gc(fmd_module_t *mp) in fmd_module_gc() argument
638 if (mp->mod_error != 0) in fmd_module_gc()
641 fmd_module_lock(mp); in fmd_module_gc()
643 if ((info = mp->mod_info) != NULL) { in fmd_module_gc()
644 fmd_serd_hash_apply(&mp->mod_serds, fmd_serd_eng_gc, NULL); in fmd_module_gc()
647 fmd_module_unlock(mp); in fmd_module_gc()
651 fmd_eventq_insert_at_head(mp->mod_queue, e); in fmd_module_gc()
656 fmd_module_trygc(fmd_module_t *mp) in fmd_module_trygc() argument
658 if (fmd_module_trylock(mp)) { in fmd_module_trygc()
659 fmd_serd_hash_apply(&mp->mod_serds, fmd_serd_eng_gc, NULL); in fmd_module_trygc()
660 fmd_module_unlock(mp); in fmd_module_trygc()
665 fmd_module_contains(fmd_module_t *mp, fmd_event_t *ep) in fmd_module_contains() argument
670 fmd_module_lock(mp); in fmd_module_contains()
672 for (cp = fmd_list_next(&mp->mod_cases); in fmd_module_contains()
679 rv = fmd_serd_hash_contains(&mp->mod_serds, ep); in fmd_module_contains()
681 fmd_module_unlock(mp); in fmd_module_contains()
686 fmd_module_setdirty(fmd_module_t *mp) in fmd_module_setdirty() argument
688 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_setdirty()
689 mp->mod_flags |= FMD_MOD_MDIRTY; in fmd_module_setdirty()
690 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_setdirty()
694 fmd_module_setcdirty(fmd_module_t *mp) in fmd_module_setcdirty() argument
696 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_setcdirty()
697 mp->mod_flags |= FMD_MOD_CDIRTY; in fmd_module_setcdirty()
698 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_setcdirty()
702 fmd_module_clrdirty(fmd_module_t *mp) in fmd_module_clrdirty() argument
706 fmd_module_lock(mp); in fmd_module_clrdirty()
708 if (mp->mod_flags & FMD_MOD_CDIRTY) { in fmd_module_clrdirty()
709 for (cp = fmd_list_next(&mp->mod_cases); in fmd_module_clrdirty()
714 if (mp->mod_flags & FMD_MOD_MDIRTY) { in fmd_module_clrdirty()
715 fmd_serd_hash_apply(&mp->mod_serds, in fmd_module_clrdirty()
717 fmd_buf_hash_commit(&mp->mod_bufs); in fmd_module_clrdirty()
720 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_clrdirty()
721 mp->mod_flags &= ~(FMD_MOD_MDIRTY | FMD_MOD_CDIRTY); in fmd_module_clrdirty()
722 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_clrdirty()
724 fmd_module_unlock(mp); in fmd_module_clrdirty()
728 fmd_module_commit(fmd_module_t *mp) in fmd_module_commit() argument
732 ASSERT(fmd_module_locked(mp)); in fmd_module_commit()
734 if (mp->mod_flags & FMD_MOD_CDIRTY) { in fmd_module_commit()
735 for (cp = fmd_list_next(&mp->mod_cases); in fmd_module_commit()
740 if (mp->mod_flags & FMD_MOD_MDIRTY) { in fmd_module_commit()
741 fmd_serd_hash_apply(&mp->mod_serds, fmd_serd_eng_commit, NULL); in fmd_module_commit()
742 fmd_buf_hash_commit(&mp->mod_bufs); in fmd_module_commit()
745 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_commit()
746 mp->mod_flags &= ~(FMD_MOD_MDIRTY | FMD_MOD_CDIRTY); in fmd_module_commit()
747 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_commit()
749 mp->mod_gen++; in fmd_module_commit()
753 fmd_module_lock(fmd_module_t *mp) in fmd_module_lock() argument
757 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_lock()
759 while (mp->mod_flags & FMD_MOD_LOCK) { in fmd_module_lock()
760 if (mp->mod_owner != self) in fmd_module_lock()
761 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_module_lock()
763 fmd_panic("recursive module lock of %p\n", (void *)mp); in fmd_module_lock()
766 mp->mod_owner = self; in fmd_module_lock()
767 mp->mod_flags |= FMD_MOD_LOCK; in fmd_module_lock()
769 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_lock()
770 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_lock()
774 fmd_module_unlock(fmd_module_t *mp) in fmd_module_unlock() argument
776 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_unlock()
778 ASSERT(mp->mod_owner == pthread_self()); in fmd_module_unlock()
779 ASSERT(mp->mod_flags & FMD_MOD_LOCK); in fmd_module_unlock()
781 mp->mod_owner = 0; in fmd_module_unlock()
782 mp->mod_flags &= ~FMD_MOD_LOCK; in fmd_module_unlock()
784 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_unlock()
785 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_unlock()
789 fmd_module_trylock(fmd_module_t *mp) in fmd_module_trylock() argument
791 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_trylock()
793 if (mp->mod_flags & FMD_MOD_LOCK) { in fmd_module_trylock()
794 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_trylock()
798 mp->mod_owner = pthread_self(); in fmd_module_trylock()
799 mp->mod_flags |= FMD_MOD_LOCK; in fmd_module_trylock()
801 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_trylock()
802 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_trylock()
808 fmd_module_locked(fmd_module_t *mp) in fmd_module_locked() argument
810 return ((mp->mod_flags & FMD_MOD_LOCK) && in fmd_module_locked()
811 mp->mod_owner == pthread_self()); in fmd_module_locked()
815 fmd_module_enter(fmd_module_t *mp, void (*func)(fmd_hdl_t *)) in fmd_module_enter() argument
819 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_enter()
821 ASSERT(!(mp->mod_flags & FMD_MOD_BUSY)); in fmd_module_enter()
822 mp->mod_flags |= FMD_MOD_BUSY; in fmd_module_enter()
824 if ((err = setjmp(mp->mod_jmpbuf)) != 0) { in fmd_module_enter()
825 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_enter()
826 fmd_module_error(mp, err); in fmd_module_enter()
829 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_enter()
830 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_enter()
839 (*func)((fmd_hdl_t *)mp); in fmd_module_enter()
845 fmd_module_exit(fmd_module_t *mp) in fmd_module_exit() argument
847 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_exit()
849 ASSERT(mp->mod_flags & FMD_MOD_BUSY); in fmd_module_exit()
850 mp->mod_flags &= ~FMD_MOD_BUSY; in fmd_module_exit()
852 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_module_exit()
853 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_exit()
865 fmd_module_abort(fmd_module_t *mp, int err) in fmd_module_abort() argument
874 fmd_errclass(err), mp->mod_name, (void *)mp); in fmd_module_abort()
878 fmd_errclass(err), mp->mod_name, (void *)mp); in fmd_module_abort()
897 if (tid != mp->mod_thread->thr_tid) { in fmd_module_abort()
898 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_abort()
900 if (mp->mod_error == 0) in fmd_module_abort()
901 mp->mod_error = err; in fmd_module_abort()
903 mp->mod_flags |= FMD_MOD_FAIL; in fmd_module_abort()
904 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_abort()
910 ASSERT(mp->mod_flags & FMD_MOD_BUSY); in fmd_module_abort()
911 longjmp(mp->mod_jmpbuf, err); in fmd_module_abort()
915 fmd_module_hold(fmd_module_t *mp) in fmd_module_hold() argument
917 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_hold()
920 (void *)mp, mp->mod_name, mp->mod_refs)); in fmd_module_hold()
922 mp->mod_refs++; in fmd_module_hold()
923 ASSERT(mp->mod_refs != 0); in fmd_module_hold()
925 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_hold()
929 fmd_module_rele(fmd_module_t *mp) in fmd_module_rele() argument
931 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_module_rele()
934 (void *)mp, mp->mod_name, mp->mod_refs)); in fmd_module_rele()
936 ASSERT(mp->mod_refs != 0); in fmd_module_rele()
938 if (--mp->mod_refs == 0) in fmd_module_rele()
939 fmd_module_destroy(mp); in fmd_module_rele()
941 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_module_rele()
950 fmd_module_dc_opendict(fmd_module_t *mp, const char *dict) in fmd_module_dc_opendict() argument
956 ASSERT(fmd_module_locked(mp)); in fmd_module_dc_opendict()
983 mp->mod_name, dict, dictdir, dictnam); in fmd_module_dc_opendict()
988 dcv = fmd_alloc(sizeof (dcp) * (mp->mod_dictc + 1), FMD_SLEEP); in fmd_module_dc_opendict()
989 bcopy(mp->mod_dictv, dcv, sizeof (dcp) * mp->mod_dictc); in fmd_module_dc_opendict()
990 fmd_free(mp->mod_dictv, sizeof (dcp) * mp->mod_dictc); in fmd_module_dc_opendict()
991 mp->mod_dictv = dcv; in fmd_module_dc_opendict()
992 mp->mod_dictv[mp->mod_dictc++] = dcp; in fmd_module_dc_opendict()
995 mp->mod_codelen = MAX(mp->mod_codelen, len); in fmd_module_dc_opendict()
1005 fmd_module_dc_key2code(fmd_module_t *mp, in fmd_module_dc_key2code() argument
1010 for (i = 0; i < mp->mod_dictc; i++) { in fmd_module_dc_key2code()
1011 if ((err = fm_dc_key2code(mp->mod_dictv[i], (const char **)keys, in fmd_module_dc_key2code()
1035 fmd_module_t *mp, *nmp; in fmd_modhash_destroy() local
1039 for (mp = mhp->mh_hash[i]; mp != NULL; mp = nmp) { in fmd_modhash_destroy()
1040 nmp = mp->mod_next; in fmd_modhash_destroy()
1041 mp->mod_next = NULL; in fmd_modhash_destroy()
1042 fmd_module_rele(mp); in fmd_modhash_destroy()
1095 fmd_module_t *mp, *np; in fmd_modhash_apply() local
1101 for (mp = mhp->mh_hash[i]; mp != NULL; mp = np) { in fmd_modhash_apply()
1102 np = mp->mod_next; in fmd_modhash_apply()
1103 func(mp); in fmd_modhash_apply()
1113 fmd_module_t *mp, *np; in fmd_modhash_tryapply() local
1120 for (mp = mhp->mh_hash[i]; mp != NULL; mp = np) { in fmd_modhash_tryapply()
1121 np = mp->mod_next; in fmd_modhash_tryapply()
1122 func(mp); in fmd_modhash_tryapply()
1132 fmd_module_t *mp; in fmd_modhash_dispatch() local
1139 for (mp = mhp->mh_hash[i]; mp != NULL; mp = mp->mod_next) { in fmd_modhash_dispatch()
1145 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modhash_dispatch()
1147 if ((mp->mod_flags & (FMD_MOD_INIT | FMD_MOD_FINI | in fmd_modhash_dispatch()
1148 FMD_MOD_QUIT)) == FMD_MOD_INIT && !mp->mod_error) { in fmd_modhash_dispatch()
1157 fmd_eventq_drop_topo(mp->mod_queue); in fmd_modhash_dispatch()
1159 fmd_eventq_insert_at_time(mp->mod_queue, ep); in fmd_modhash_dispatch()
1162 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modhash_dispatch()
1173 fmd_module_t *mp; in fmd_modhash_lookup() local
1179 for (mp = mhp->mh_hash[h]; mp != NULL; mp = mp->mod_next) { in fmd_modhash_lookup()
1180 if (strcmp(name, mp->mod_name) == 0) in fmd_modhash_lookup()
1184 if (mp != NULL) in fmd_modhash_lookup()
1185 fmd_module_hold(mp); in fmd_modhash_lookup()
1190 return (mp); in fmd_modhash_lookup()
1197 fmd_module_t *mp; in fmd_modhash_load() local
1212 for (mp = mhp->mh_hash[h]; mp != NULL; mp = mp->mod_next) { in fmd_modhash_load()
1213 if (strcmp(name, mp->mod_name) == 0) in fmd_modhash_load()
1217 if (mp != NULL) { in fmd_modhash_load()
1227 while ((mp = fmd_module_create(path, ops)) == NULL) { in fmd_modhash_load()
1234 mp->mod_hash = mhp; in fmd_modhash_load()
1235 mp->mod_next = mhp->mh_hash[h]; in fmd_modhash_load()
1237 mhp->mh_hash[h] = mp; in fmd_modhash_load()
1241 return (mp); in fmd_modhash_load()
1247 fmd_module_t *mp, **pp; in fmd_modhash_unload() local
1254 for (mp = *pp; mp != NULL; mp = mp->mod_next) { in fmd_modhash_unload()
1255 if (strcmp(name, mp->mod_name) == 0) in fmd_modhash_unload()
1258 pp = &mp->mod_next; in fmd_modhash_unload()
1261 if (mp == NULL) { in fmd_modhash_unload()
1266 *pp = mp->mod_next; in fmd_modhash_unload()
1267 mp->mod_next = NULL; in fmd_modhash_unload()
1274 fmd_module_unload(mp); in fmd_modhash_unload()
1275 fmd_module_rele(mp); in fmd_modhash_unload()
1281 fmd_modstat_publish(fmd_module_t *mp) in fmd_modstat_publish() argument
1283 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modstat_publish()
1285 ASSERT(mp->mod_flags & FMD_MOD_STSUB); in fmd_modstat_publish()
1286 mp->mod_flags |= FMD_MOD_STPUB; in fmd_modstat_publish()
1287 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_modstat_publish()
1289 while (mp->mod_flags & FMD_MOD_STPUB) in fmd_modstat_publish()
1290 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_modstat_publish()
1292 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_publish()
1296 fmd_modstat_snapshot(fmd_module_t *mp, fmd_ustat_snap_t *uss) in fmd_modstat_snapshot() argument
1305 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modstat_snapshot()
1307 while (mp->mod_error == 0 && (mp->mod_flags & FMD_MOD_STSUB)) in fmd_modstat_snapshot()
1308 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_modstat_snapshot()
1310 if (mp->mod_error != 0) { in fmd_modstat_snapshot()
1311 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1315 mp->mod_flags |= FMD_MOD_STSUB; in fmd_modstat_snapshot()
1316 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_modstat_snapshot()
1317 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1324 fmd_eventq_insert_at_head(mp->mod_queue, e); in fmd_modstat_snapshot()
1330 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modstat_snapshot()
1332 while (mp->mod_error == 0 && !(mp->mod_flags & FMD_MOD_STPUB)) { in fmd_modstat_snapshot()
1335 (void) pthread_cond_wait(&mp->mod_cv, &mp->mod_lock); in fmd_modstat_snapshot()
1336 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1340 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modstat_snapshot()
1343 if (mp->mod_error != 0) { in fmd_modstat_snapshot()
1344 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1348 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_modstat_snapshot()
1349 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1355 (void) pthread_mutex_lock(&mp->mod_stats_lock); in fmd_modstat_snapshot()
1357 if (mp->mod_stats != NULL) { in fmd_modstat_snapshot()
1358 mp->mod_stats->ms_snaptime.fmds_value.ui64 = gethrtime(); in fmd_modstat_snapshot()
1359 err = fmd_ustat_snapshot(mp->mod_ustat, uss); in fmd_modstat_snapshot()
1363 (void) pthread_mutex_unlock(&mp->mod_stats_lock); in fmd_modstat_snapshot()
1369 (void) pthread_mutex_lock(&mp->mod_lock); in fmd_modstat_snapshot()
1371 ASSERT(mp->mod_flags & FMD_MOD_STSUB); in fmd_modstat_snapshot()
1372 ASSERT(mp->mod_flags & FMD_MOD_STPUB); in fmd_modstat_snapshot()
1373 mp->mod_flags &= ~(FMD_MOD_STSUB | FMD_MOD_STPUB); in fmd_modstat_snapshot()
1375 (void) pthread_cond_broadcast(&mp->mod_cv); in fmd_modstat_snapshot()
1376 (void) pthread_mutex_unlock(&mp->mod_lock); in fmd_modstat_snapshot()
1382 fmd_module_topo_hold(fmd_module_t *mp) in fmd_module_topo_hold() argument
1386 ASSERT(fmd_module_locked(mp)); in fmd_module_topo_hold()
1389 mtp->mt_topo = mp->mod_topo_current; in fmd_module_topo_hold()
1391 fmd_list_prepend(&mp->mod_topolist, mtp); in fmd_module_topo_hold()
1397 fmd_module_topo_rele(fmd_module_t *mp, struct topo_hdl *hdl) in fmd_module_topo_rele() argument
1401 ASSERT(fmd_module_locked(mp)); in fmd_module_topo_rele()
1403 for (mtp = fmd_list_next(&mp->mod_topolist); mtp != NULL; in fmd_module_topo_rele()
1412 fmd_list_delete(&mp->mod_topolist, mtp); in fmd_module_topo_rele()