Lines Matching defs:scp
94 static void shadcons_stop_all(shadow_conspiracy_t *scp);
102 shadcons_dprintf(shadow_conspiracy_t *scp, const char *fmt, ...)
106 if ((scp)->sc_debugfd < 0)
109 _shadow_dprintf(scp->sc_debugfd, __FILE__, fmt, ap);
114 shadcons_warn(shadow_conspiracy_t *scp, const char *fmt, ...)
118 if ((scp)->sc_warnfd < 0)
121 _shadow_dprintf(scp->sc_warnfd, __FILE__, fmt, ap);
133 shadcons_panic(shadow_conspiracy_t *scp)
139 shadcons_entry_remove(shadow_conspiracy_t *scp, shadow_conspiracy_entry_t *nsp)
141 shadow_hash_remove(scp->sc_hash, nsp);
175 shadow_conspiracy_t *scp = data;
185 shadcons_dprintf(scp, "[%d] starting\n", tid);
192 shadcons_mutex_enter(&scp->sc_lock);
194 if (scp->sc_shutdown) {
195 shadcons_dprintf(scp, "[%d] exiting\n", tid);
196 if (--scp->sc_nworkers == 0)
197 (void) pthread_cond_broadcast(&scp->sc_cv);
198 shadcons_mutex_exit(&scp->sc_lock);
200 } else if (scp->sc_suspend) {
201 shadcons_dprintf(scp, "[%d] suspending\n", tid);
202 while (scp->sc_suspend)
203 (void) pthread_cond_wait(&scp->sc_cv,
204 &scp->sc_lock);
207 size = shadow_hash_count(scp->sc_hash);
214 (nsp = shadow_hash_lookup(scp->sc_hash, dataset)) == NULL ||
215 (nsp = shadow_hash_next(scp->sc_hash, nsp)) == NULL)
216 nsp = shadow_hash_first(scp->sc_hash);
224 shadcons_dprintf(scp,
227 (void) pthread_cond_wait(&scp->sc_cv, &scp->sc_lock);
249 nsp = shadow_hash_next(scp->sc_hash, nsp);
251 nsp = shadow_hash_first(scp->sc_hash);
272 shadcons_dprintf(scp,
276 (void) pthread_cond_timedwait(&scp->sc_cv,
277 &scp->sc_lock, &ts);
288 nsp->swe_next = gethrtime() + scp->sc_throttle;
296 shadcons_mutex_exit(&scp->sc_lock);
312 shadcons_mutex_enter(&scp->sc_lock);
319 gen = ++scp->sc_gen;
321 (void) pthread_cond_broadcast(&scp->sc_cv);
332 if (gen == scp->sc_gen && ++count == size) {
333 shadcons_dprintf(scp,
335 (void) pthread_cond_wait(&scp->sc_cv,
336 &scp->sc_lock);
338 } else if (gen != scp->sc_gen) {
339 shadcons_dprintf(scp,
342 gen = scp->sc_gen;
345 shadcons_dprintf(scp,
354 shadcons_dprintf(scp,
357 if ((nsp = shadow_hash_lookup(scp->sc_hash,
370 shadcons_dprintf(scp,
373 shadcons_entry_remove(scp, nsp);
374 gen = ++scp->sc_gen;
376 if (shadcons_stop_other_workers(scp)) {
382 shadcons_dprintf(scp,
386 shadcons_dprintf(scp,
400 shadcons_start_workers(shadow_conspiracy_t *scp)
406 shadcons_mutex_enter(&scp->sc_lock);
412 while (scp->sc_shutdown)
413 (void) pthread_cond_wait(&scp->sc_cv, &scp->sc_lock);
415 scp->sc_gen++;
417 if (scp->sc_active || scp->sc_workers != NULL || scp->sc_inrefresh ||
418 shadow_hash_first(scp->sc_hash) == NULL) {
419 (void) pthread_cond_broadcast(&scp->sc_cv);
420 shadcons_mutex_exit(&scp->sc_lock);
424 shadcons_dprintf(scp, "spawning %d worker threads\n", scp->sc_nthread);
425 ASSERT(scp->sc_nthread > 0);
427 if ((scp->sc_workers = shadow_zalloc(
428 scp->sc_nthread * sizeof (pthread_t))) == NULL) {
429 shadcons_mutex_exit(&scp->sc_lock);
438 for (i = 0; i < scp->sc_nthread; i++) {
439 if (pthread_create(&scp->sc_workers[i], NULL,
440 shadow_worker, scp) != 0)
442 scp->sc_nworkers++;
446 scp->sc_active = B_TRUE;
447 (void) pthread_cond_broadcast(&scp->sc_cv);
448 shadcons_mutex_exit(&scp->sc_lock);
454 workers = scp->sc_workers;
455 nthread = scp->sc_nthread;
456 scp->sc_workers = NULL;
458 shadcons_mutex_exit(&scp->sc_lock);
471 shadcons_stop_common(shadow_conspiracy_t *scp, boolean_t full_stop)
476 workers = scp->sc_workers;
477 nthread = scp->sc_nthread;
478 scp->sc_workers = NULL;
480 scp->sc_shutdown = B_TRUE;
482 scp->sc_suspend = B_TRUE;
491 shadcons_mutex_exit(&scp->sc_lock);
494 shadcons_mutex_enter(&scp->sc_lock);
495 (void) pthread_cond_broadcast(&scp->sc_cv);
496 shadcons_mutex_exit(&scp->sc_lock);
510 shadcons_panic(scp);
515 shadcons_mutex_enter(&scp->sc_lock);
516 while (scp->sc_nworkers > 0)
517 (void) pthread_cond_wait(&scp->sc_cv, &scp->sc_lock);
518 scp->sc_shutdown = B_FALSE;
519 (void) pthread_cond_broadcast(&scp->sc_cv);
520 shadcons_mutex_exit(&scp->sc_lock);
528 shadcons_stop_all(shadow_conspiracy_t *scp)
530 shadcons_mutex_enter(&scp->sc_lock);
532 if (scp->sc_workers == NULL) {
533 scp->sc_active = B_FALSE;
534 shadcons_mutex_exit(&scp->sc_lock);
538 shadcons_dprintf(scp, "stopping worker threads\n");
539 scp->sc_active = B_FALSE;
541 shadcons_stop_common(scp, B_TRUE);
550 shadcons_stop_other_workers(shadow_conspiracy_t *scp)
552 if (shadow_hash_first(scp->sc_hash) != NULL)
561 if (scp->sc_workers == NULL)
564 shadcons_dprintf(scp,
566 scp->sc_active = B_FALSE;
568 scp->sc_nworkers--;
569 shadcons_stop_common(scp, B_TRUE);
590 shadcons_suspend(shadow_conspiracy_t *scp, shadow_conspiracy_entry_t *nsp)
592 shadcons_dprintf(scp, "suspending workers\n");
594 shadcons_stop_common(scp, B_FALSE);
606 shadcons_resume(shadow_conspiracy_t *scp, shadow_conspiracy_entry_t *nsp)
610 shadcons_mutex_enter(&scp->sc_lock);
611 ASSERT(scp->sc_suspend);
613 shadcons_dprintf(scp, "resuming workers\n");
617 scp->sc_suspend = B_FALSE;
618 nthread = scp->sc_nthread;
619 shadcons_mutex_exit(&scp->sc_lock);
622 shadcons_mutex_enter(&scp->sc_lock);
623 (void) pthread_cond_broadcast(&scp->sc_cv);
624 shadcons_mutex_exit(&scp->sc_lock);
637 shadcons_scf_get_int(shadow_conspiracy_t *scp,
645 if ((pg = scf_pg_create(scp->sc_scf_hdl)) == NULL)
648 if (scf_instance_get_pg_composed(scp->sc_inst,
654 if ((prop = scf_property_create(scp->sc_scf_hdl)) == NULL ||
655 (value = scf_value_create(scp->sc_scf_hdl)) == NULL ||
668 shadcons_scf_get_string(shadow_conspiracy_t *scp,
676 if ((pg = scf_pg_create(scp->sc_scf_hdl)) == NULL)
680 if (scf_instance_get_pg_composed(scp->sc_inst,
686 if ((prop = scf_property_create(scp->sc_scf_hdl)) == NULL ||
687 (value = scf_value_create(scp->sc_scf_hdl)) == NULL ||
700 shadcons_enable_output(shadow_conspiracy_t *scp, const char *path,
704 scp->sc_debugfd = open(path, O_CREAT | O_RDWR | O_APPEND,
706 if (scp->sc_debugfd < 0)
709 scp->sc_warnfd = open(path, O_RDWR | O_APPEND, 0640);
710 if (scp->sc_warnfd < 0)
717 shadcons_disable_output(shadow_conspiracy_t *scp, boolean_t fordebug)
720 if (scp->sc_debugfd >= 0) {
721 (void) close(scp->sc_debugfd);
722 scp->sc_debugfd = -1;
725 if (scp->sc_warnfd >= 0) {
726 (void) close(scp->sc_warnfd);
727 scp->sc_warnfd = -1;
733 shadcons_set_config(shadow_conspiracy_t *scp)
739 shadcons_mutex_enter(&scp->sc_lock);
742 err = shadcons_enable_output(scp, "/dev/stderr", B_FALSE);
749 if (shadcons_scf_get_string(scp, CONFIG_PARAMS, DEBUG_FILE,
751 err = shadcons_enable_output(scp, debugfn, B_TRUE);
753 shadcons_warn(scp,
757 shadcons_warn(scp,
761 if (shadcons_scf_get_int(scp, CONFIG_PARAMS, WORKER_THREADS,
763 shadcons_warn(scp, "Could not retrieve %s/%s from SMF\n",
766 } else if (shadcons_scf_get_int(scp, CONFIG_PARAMS, FAIL_THROTTLE,
768 shadcons_warn(scp, "Could not retrieve %s/%s from SMF\n",
772 scp->sc_nthread = (uint32_t)threads;
773 scp->sc_throttle = throttle;
774 shadcons_mutex_exit(&scp->sc_lock);
779 shadcons_scf_fini(shadow_conspiracy_t *scp)
781 scf_instance_destroy(scp->sc_inst);
782 (void) scf_handle_unbind(scp->sc_scf_hdl);
783 scf_handle_destroy(scp->sc_scf_hdl);
787 shadcons_scf_init(shadow_conspiracy_t *scp)
789 if ((scp->sc_scf_hdl = scf_handle_create(SCF_VERSION)) == NULL ||
790 scf_handle_bind(scp->sc_scf_hdl) == -1 ||
791 (scp->sc_inst = scf_instance_create(scp->sc_scf_hdl)) == NULL ||
792 scf_handle_decode_fmri(scp->sc_scf_hdl, scp->sc_fmri, NULL, NULL,
793 scp->sc_inst, NULL, NULL, SCF_DECODE_FMRI_EXACT) == -1) {
794 shadcons_scf_fini(scp);
801 shadcons_cancel_common(shadow_conspiracy_t *scp, const char *dataset,
806 shadcons_mutex_enter(&scp->sc_lock);
808 if ((nsp = shadow_hash_lookup(scp->sc_hash, dataset)) == NULL) {
809 shadcons_mutex_exit(&scp->sc_lock);
813 shadcons_suspend(scp, nsp);
815 shadcons_mutex_enter(&scp->sc_lock);
817 shadcons_mutex_exit(&scp->sc_lock);
818 shadcons_resume(scp, nsp);
822 shadcons_dprintf(scp,
826 shadcons_entry_remove(scp, nsp);
828 shadcons_mutex_exit(&scp->sc_lock);
830 shadcons_resume(scp, NULL);
836 shadcons_cancel(shadow_conspiracy_t *scp, const char *dataset)
838 return (shadcons_cancel_common(scp, dataset, B_TRUE));
842 shadcons_stop(shadow_conspiracy_t *scp, const char *dataset)
844 (void) shadcons_cancel_common(scp, dataset, B_FALSE);
848 shadcons_start(shadow_conspiracy_t *scp, const char *dataset,
853 shadcons_mutex_enter(&scp->sc_lock);
854 if (shadow_hash_lookup(scp->sc_hash, dataset) != NULL) {
855 shadcons_dprintf(scp,
859 shadcons_mutex_exit(&scp->sc_lock);
865 shadcons_mutex_exit(&scp->sc_lock);
871 shadcons_mutex_exit(&scp->sc_lock);
878 shadcons_mutex_exit(&scp->sc_lock);
886 shadcons_mutex_exit(&scp->sc_lock);
890 shadcons_dprintf(scp,
892 shadow_hash_insert(scp->sc_hash, scep);
893 shadcons_mutex_exit(&scp->sc_lock);
898 return (shadcons_start_workers(scp));
902 shadcons_svc_refresh(shadow_conspiracy_t *scp)
904 shadcons_dprintf(scp, "refreshing shadow service\n");
906 shadcons_mutex_enter(&scp->sc_lock);
909 shadcons_scf_fini(scp);
910 if (shadcons_scf_init(scp) != 0) {
911 free(scp->sc_fmri);
912 scp->sc_fmri = NULL;
913 shadcons_mutex_exit(&scp->sc_lock);
922 scp->sc_inrefresh = B_TRUE;
923 shadcons_mutex_exit(&scp->sc_lock);
925 shadcons_stop_all(scp);
926 shadcons_set_config(scp);
928 shadcons_mutex_enter(&scp->sc_lock);
929 scp->sc_inrefresh = B_FALSE;
930 shadcons_mutex_exit(&scp->sc_lock);
932 return (shadcons_start_workers(scp));
937 shadcons_svc_start(shadow_conspiracy_t *scp)
939 shadcons_dprintf(scp, "starting shadow service\n");
940 return (shadcons_start_workers(scp));
945 shadcons_svc_stop(shadow_conspiracy_t *scp)
947 shadcons_dprintf(scp, "stopping shadow service\n");
948 shadcons_stop_all(scp);
953 shadcons_status(shadow_conspiracy_t *scp, const char *dataset,
960 shadcons_mutex_enter(&scp->sc_lock);
961 if ((nsp = shadow_hash_lookup(scp->sc_hash, dataset)) == NULL) {
962 shadcons_mutex_exit(&scp->sc_lock);
968 shadcons_mutex_exit(&scp->sc_lock);
995 shadcons_status_all(shadow_conspiracy_t *scp,
1006 shadcons_mutex_enter(&scp->sc_lock);
1008 nelems = shadow_hash_count(scp->sc_hash);
1011 shadcons_mutex_exit(&scp->sc_lock);
1018 shadcons_mutex_exit(&scp->sc_lock);
1023 nsp = shadow_hash_first(scp->sc_hash);
1029 shadow_strdup(scp->sc_hash->sh_convert(nsp));
1035 shadcons_mutex_exit(&scp->sc_lock);
1051 nsp = shadow_hash_next(scp->sc_hash, nsp);
1054 shadcons_mutex_exit(&scp->sc_lock);
1062 shadcons_hash_count(shadow_conspiracy_t *scp)
1064 return (shadow_hash_count(scp->sc_hash));
1068 shadcons_hash_first(shadow_conspiracy_t *scp)
1070 return (shadow_hash_first(scp->sc_hash));
1074 shadcons_hash_next(shadow_conspiracy_t *scp, void *elem)
1076 return (shadow_hash_next(scp->sc_hash, elem));
1080 shadcons_hash_remove(shadow_conspiracy_t *scp, void *elem)
1082 shadow_hash_remove(scp->sc_hash, elem);
1086 shadcons_hashentry_dataset(shadow_conspiracy_t *scp, void *entry)
1088 return (scp->sc_hash->sh_convert(entry));
1092 shadcons_lock(shadow_conspiracy_t *scp)
1094 shadcons_mutex_enter(&scp->sc_lock);
1098 shadcons_unlock(shadow_conspiracy_t *scp)
1100 shadcons_mutex_exit(&scp->sc_lock);
1105 shadcons_fini(shadow_conspiracy_t *scp)
1109 if (scp == NULL)
1112 shadcons_disable_output(scp, B_TRUE);
1113 shadcons_disable_output(scp, B_FALSE);
1114 shadcons_scf_fini(scp);
1116 shadcons_mutex_enter(&scp->sc_lock);
1117 while ((nsp = shadow_hash_first(scp->sc_hash)) != NULL) {
1118 shadcons_entry_remove(scp, nsp);
1120 shadow_hash_destroy(scp->sc_hash);
1121 shadcons_mutex_exit(&scp->sc_lock);
1123 (void) pthread_cond_destroy(&scp->sc_cv);
1124 (void) pthread_mutex_destroy(&scp->sc_lock);
1125 free(scp->sc_fmri);
1126 free(scp);
1133 shadow_conspiracy_t *scp;
1135 if ((scp = shadow_zalloc(sizeof (shadow_conspiracy_t))) == NULL)
1140 if (pthread_mutex_init(&scp->sc_lock, &mtype) != 0) {
1141 free(scp);
1144 if (pthread_cond_init(&scp->sc_cv, NULL) != 0) {
1145 (void) pthread_mutex_destroy(&scp->sc_lock);
1146 free(scp);
1150 scp->sc_debugfd = scp->sc_warnfd = -1;
1152 if ((scp->sc_fmri = shadow_strdup(fmri)) == NULL) {
1153 (void) pthread_cond_destroy(&scp->sc_cv);
1154 (void) pthread_mutex_destroy(&scp->sc_lock);
1155 free(scp);
1159 if (shadcons_scf_init(scp) != 0) {
1160 (void) pthread_cond_destroy(&scp->sc_cv);
1161 (void) pthread_mutex_destroy(&scp->sc_lock);
1162 free(scp->sc_fmri);
1163 free(scp);
1167 shadcons_set_config(scp);
1169 if ((scp->sc_hash = shadow_hash_create(
1173 (void) pthread_cond_destroy(&scp->sc_cv);
1174 (void) pthread_mutex_destroy(&scp->sc_lock);
1175 free(scp->sc_fmri);
1176 free(scp);
1180 return (scp);