Lines Matching defs:inst

105 method_record_start(restarter_inst_t *inst)
107 int index = inst->ri_start_index++ % RINST_START_TIMES;
109 inst->ri_start_time[index] = gethrtime();
125 method_rate_critical(restarter_inst_t *inst)
129 uint_t n = inst->ri_start_index;
139 if (instance_is_wait_style(inst))
147 if (scf_read_propvec(inst->ri_i.i_fmri, "startd",
156 if (inst->ri_start_index < critical_failure_count)
160 (inst->ri_start_time[(n - 1) % critical_failure_count] -
161 inst->ri_start_time[n % critical_failure_count]) /
173 method_is_transient(restarter_inst_t *inst, int type)
175 if (instance_is_transient_style(inst) || type != METHOD_START)
187 method_store_contract(restarter_inst_t *inst, int type, ctid_t *cid)
193 uu_die("%s: Couldn't get new contract's id", inst->ri_i.i_fmri);
195 primary = !method_is_transient(inst, type);
198 if (inst->ri_i.i_transient_ctid != 0) {
201 "was set to %ld\n", inst->ri_i.i_fmri,
202 inst->ri_i.i_transient_ctid);
205 inst->ri_i.i_transient_ctid = *cid;
207 if (inst->ri_i.i_primary_ctid != 0) {
212 method_remove_contract(inst, B_TRUE, B_FALSE);
215 if (inst->ri_i.i_primary_ctid != 0) {
218 "was set to %ld\n", inst->ri_i.i_fmri,
219 inst->ri_i.i_primary_ctid);
222 inst->ri_i.i_primary_ctid = *cid;
223 inst->ri_i.i_primary_ctid_stopped = 0;
226 "%s.\n", *cid, inst->ri_i.i_fmri);
228 contract_hash_store(*cid, inst->ri_id);
232 if (inst->ri_mi_deleted)
235 r = restarter_store_contract(inst->ri_m_inst, *cid, primary ?
242 inst->ri_mi_deleted = B_TRUE;
246 libscf_handle_rebind(scf_instance_handle(inst->ri_m_inst));
250 libscf_reget_instance(inst);
258 inst->ri_i.i_fmri, *cid);
273 * ECANCELED - inst was deleted from the repository
278 method_remove_contract(restarter_inst_t *inst, boolean_t primary,
281 ctid_t * const ctidp = primary ? &inst->ri_i.i_primary_ctid :
282 &inst->ri_i.i_transient_ctid;
289 primary ? "primary" : "transient", *ctidp, inst->ri_i.i_fmri);
295 if (inst->ri_mi_deleted) {
300 r = restarter_remove_contract(inst->ri_m_inst, *ctidp, primary ?
307 inst->ri_mi_deleted = B_TRUE;
311 libscf_handle_rebind(scf_instance_handle(inst->ri_m_inst));
315 libscf_reget_instance(inst);
323 "%s.\n", inst->ri_i.i_fmri, *ctidp, strerror(r));
343 * Activate a contract template for the type method of inst. type,
347 * ECANCELED - inst has been deleted from the repository
350 method_ready_contract(restarter_inst_t *inst, int type,
364 iswait = instance_is_wait_style(inst);
365 istrans = method_is_transient(inst, type);
404 if (type == METHOD_START && inst->ri_i.i_primary_ctid != 0) {
405 ret = ct_pr_tmpl_set_transfer(tmpl, inst->ri_i.i_primary_ctid);
412 method_remove_contract(inst, B_TRUE, B_TRUE);
413 if (inst->ri_mi_deleted) {
427 err = ct_pr_tmpl_set_svc_fmri(tmpl, inst->ri_i.i_fmri);
445 exec_method(const restarter_inst_t *inst, int type, const char *method,
455 if (inst->ri_utmpx_prefix[0] != '\0' && inst->ri_utmpx_prefix != NULL)
456 (void) utmpx_mark_init(getpid(), inst->ri_utmpx_prefix);
458 setlog(inst->ri_logstem);
459 log_instance(inst, B_FALSE, "Executing %s method (\"%s\").",
468 log_instance(inst, B_FALSE,
473 log_instance(inst, B_FALSE,
476 log_instance(inst, B_FALSE, "%s: a resource "
479 log_instance(inst, B_FALSE, "%s: a system "
497 log_instance(inst, B_FALSE, "%s: the pool "
502 log_instance(inst, B_FALSE, "%s: the "
507 log_instance(inst, B_FALSE, "%s: pool name "
534 log_instance(inst, B_FALSE, "%s: %s (\"%s\")",
572 log_instance(inst, B_FALSE, "Out of memory.");
577 log_instance(inst, B_FALSE, "Missing passwd entry for "
592 nenv = set_smf_env(mcp->env, mcp->env_sz, NULL, inst,
603 write_status(restarter_inst_t *inst, const char *mname, int stat)
608 if (inst->ri_mi_deleted)
611 r = libscf_write_method_status(inst->ri_m_inst, mname, stat);
617 libscf_reget_instance(inst);
621 inst->ri_mi_deleted = 1;
629 inst->ri_i.i_fmri, strerror(r));
643 * repository connection is broken, it is rebound, but inst may not be
651 * ECANCELED - inst was deleted from the repository before method was run
676 restarter_inst_t *inst = *instp;
677 int id = inst->ri_id;
680 assert(MUTEX_HELD(&inst->ri_lock));
681 assert(instance_in_transition(inst));
683 if (inst->ri_mi_deleted)
692 inst->ri_pre_online_hook();
694 h = scf_instance_handle(inst->ri_m_inst);
698 scf_instance_get_snapshot(inst->ri_m_inst, "running", snap) != 0) {
702 inst->ri_i.i_fmri, mname);
712 r = libscf_note_method_log(inst->ri_m_inst, st->st_log_prefix,
713 inst->ri_logstem);
717 inst->ri_i.i_fmri, strerror(r));
720 if ((method = libscf_get_method(h, type, inst, snap, &restart_on,
725 inst->ri_i.i_fmri, mname);
727 log_instance(inst, B_TRUE, "No '%s' method "
730 log_instance(inst, B_TRUE, "Method property "
737 inst->ri_i.i_fmri, mname);
738 log_instance(inst, B_TRUE, "Method property '%s/exec "
745 inst->ri_i.i_fmri);
752 if (type == METHOD_STOP && (!instance_is_transient_style(inst))) {
753 if (inst->ri_i.i_primary_ctid == 0) {
757 inst->ri_i.i_fmri);
761 if ((ctfd = contract_open(inst->ri_i.i_primary_ctid, "process",
764 log_instance(inst, B_TRUE, "Could not open service "
766 inst->ri_i.i_primary_ctid);
773 inst->ri_i.i_fmri);
775 log_instance(inst, B_TRUE, "Executing %s method (null).",
779 write_status(inst, mname, 0);
786 if (inst->ri_i.i_primary_ctid == 0) {
788 inst->ri_i.i_fmri);
789 log_instance(inst, B_TRUE, "Invalid use of \":kill\" "
797 inst->ri_i.i_fmri, sig);
799 log_instance(inst, B_TRUE, "Executing %s method (:kill).",
802 if (contract_kill(inst->ri_i.i_primary_ctid, sig,
803 inst->ri_i.i_fmri) != 0) {
811 inst->ri_i.i_fmri, method);
814 inst->ri_m_inst, snap, mname, method, &mcp);
817 log_instance(inst, B_TRUE, "%s", m_error->msg);
823 r = method_ready_contract(inst, type, restart_on, cte_mask);
826 assert(inst->ri_mi_deleted);
837 "to root-accessible libraries\n", inst->ri_i.i_fmri);
843 if (instance_is_wait_style(inst) && type == METHOD_START) {
856 log_instance(inst, B_TRUE, "Missing start method (%s), "
871 method_record_start(inst);
872 if (method_rate_critical(inst) &&
873 !instance_is_wait_style(inst)) {
874 log_instance(inst, B_TRUE, "Restarting too quickly, "
885 exec_method(inst, type, method, mcp, need_session);
896 inst->ri_i.i_fmri, method, strerror(forkerr));
905 * stash it in inst & the repository.
907 method_store_contract(inst, type, &ctid);
915 if (type == METHOD_START && !inst->ri_mi_deleted)
916 (void) libscf_write_start_pid(inst->ri_m_inst, pid);
918 if (instance_is_wait_style(inst) && type == METHOD_START) {
920 if (wait_register(pid, inst->ri_i.i_fmri, 1, 0)) {
923 inst->ri_i.i_fmri, pid);
927 write_status(inst, mname, 0);
942 if (timeout != METHOD_TIMEOUT_INFINITE && !is_timeout_ovr(inst))
943 timeout_insert(inst, ctid, timeout);
948 MUTEX_UNLOCK(&inst->ri_lock);
957 inst = inst_lookup_by_id(id);
960 * inst can't be removed, as the removal thread waits
963 assert(inst != NULL);
964 *instp = inst;
966 if (inst->ri_timeout != NULL && inst->ri_timeout->te_fired)
969 timeout_remove(inst, ctid);
973 inst->ri_i.i_fmri, WEXITSTATUS(ret_status));
978 mname, inst->ri_i.i_fmri, strerror(err));
984 write_status(inst, mname, ret_status);
1004 inst->ri_i.i_fmri, method, buf);
1005 log_instance(inst, B_TRUE, "Method \"%s\" "
1010 inst->ri_i.i_fmri, method,
1012 log_instance(inst, B_TRUE, "Method \"%s\" "
1024 inst->ri_i.i_fmri, method, WEXITSTATUS(ret_status));
1027 log_instance(inst, B_TRUE, "Method \"%s\" exited with status "
1045 if (type == METHOD_STOP && (!instance_is_transient_style(inst)) &&
1046 !(contract_is_empty(inst->ri_i.i_primary_ctid))) {
1050 timeout_insert(inst, inst->ri_i.i_primary_ctid,
1064 if (contract_is_empty(inst->ri_i.i_primary_ctid))
1069 if (inst->ri_timeout->te_fired)
1072 timeout_remove(inst, inst->ri_i.i_primary_ctid);
1077 transient = method_is_transient(inst, type);
1080 method_remove_contract(inst, !transient, B_TRUE);
1111 restarter_inst_t *inst;
1121 inst = inst_lookup_by_id(info->sf_id);
1123 assert(inst->ri_method_thread != 0);
1124 assert(instance_in_transition(inst) == 1);
1127 * We cannot leave this function with inst in transition, because
1128 * protocol.c withholds messages for inst otherwise.
1132 method_names[info->sf_method_type], inst->ri_i.i_fmri);
1138 switch (r = libscf_fmri_get_instance(local_handle, inst->ri_i.i_fmri,
1152 (void) restarter_instance_update_states(local_handle, inst,
1153 inst->ri_i.i_state, RESTARTER_STATE_NONE, RERR_NONE,
1163 inst->ri_m_inst = s_inst;
1164 inst->ri_mi_deleted = B_FALSE;
1168 log_transition(inst, START_REQUESTED);
1170 r = method_run(&inst, info->sf_method_type, &exit_code);
1174 assert(inst->ri_i.i_next_state != RESTARTER_STATE_NONE);
1184 inst->ri_i.i_primary_ctid != 0) {
1185 if (inst->ri_i.i_next_state == RESTARTER_STATE_OFFLINE)
1186 inst->ri_i.i_primary_ctid_stopped = 1;
1188 method_remove_contract(inst, B_TRUE, B_TRUE);
1194 (void) restarter_instance_update_states(local_handle, inst,
1195 inst->ri_i.i_next_state, RESTARTER_STATE_NONE,
1198 (void) update_fault_count(inst, FAULT_COUNT_RESET);
1221 if (retryable && update_fault_count(inst, FAULT_COUNT_INCR) != 1)
1226 log_transition(inst, START_FAILED_REPEATEDLY);
1228 log_transition(inst, START_FAILED_TIMEOUT_FATAL);
1230 log_transition(inst, START_FAILED_CONFIGURATION);
1232 log_transition(inst, START_FAILED_FATAL);
1234 log_transition(inst, START_FAILED_OTHER);
1244 (void) restarter_instance_update_states(local_handle, inst,
1248 if (!method_is_transient(inst, info->sf_method_type) &&
1249 inst->ri_i.i_primary_ctid != 0)
1250 method_remove_contract(inst, B_TRUE, B_TRUE);
1253 inst->ri_method_thread = 0;
1257 * with restarter_delete_inst() when the 'inst' structure is freed.
1259 (void) pthread_cond_broadcast(&inst->ri_method_cv);
1260 MUTEX_UNLOCK(&inst->ri_lock);