enum ocf_exitcode pe_resource_ocf_exitcode_get(struct pe_operation *op, int lsb_exitcode) { qb_enter(); if (strcmp(op->rclass, "lsb") == 0 && strcmp("monitor", op->method) == 0) { switch(lsb_exitcode) { case LSB_STATUS_OK: return OCF_OK; case LSB_STATUS_VAR_PID: return OCF_NOT_RUNNING; case LSB_STATUS_VAR_LOCK: return OCF_NOT_RUNNING; case LSB_STATUS_NOT_RUNNING: return OCF_NOT_RUNNING; case LSB_STATUS_NOT_INSTALLED: return OCF_UNKNOWN_ERROR; default: return OCF_UNKNOWN_ERROR; } } else if (lsb_exitcode > LSB_NOT_RUNNING) { qb_leave(); return OCF_UNKNOWN_ERROR; } /* For non-status operations, the LSB and OCF share error code meaning * for rc <= 7 */ qb_leave(); return (enum ocf_exitcode)lsb_exitcode; }
static void configure_resource_create(xmlNode *rsc_node, xmlNode *params_node, struct assembly *assembly) { struct resource *resource; char *name; /* 6 = rsc__ and terminator */ char resource_name[ASSEMBLY_NAME_MAX + RESOURCE_NAME_MAX + 6]; qb_enter(); resource = calloc(1, sizeof (struct resource)); name = (char*)xmlGetProp(rsc_node, BAD_CAST "name"); snprintf(resource_name, ASSEMBLY_NAME_MAX + RESOURCE_NAME_MAX + 6, "cfg_%s_%s", assembly->name, name); resource->name = strdup(resource_name); resource->type = strdup("script_runner"); resource->rclass = strdup("ocf"); resource->rprovider = strdup("pacemaker-cloud"); recover_init(&resource->recover, "-1", "-1", resource_recover_restart, resource_recover_escalate, resource_state_change_event); resource->recover.instance = resource; resource->assembly = assembly; qb_map_put(assembly->resource_map, resource->name, resource); resource_add_ref_params(params_node, resource); qb_leave(); }
void pe_resource_unref(struct pe_operation *op) { qb_enter(); op->refcount--; qb_log(LOG_TRACE, "unref %s_%s_%d refcount:%d", op->rname, op->method, op->interval, op->refcount); if (op->refcount == 0) { crm_free(op->hostname); crm_free(op->rprovider); crm_free(op->rtype); crm_free(op->rclass); crm_free(op->node_uuid); crm_free(op->op_digest); free(op->method); free(op->rname); qb_map_foreach(op->params, qb_map_transverse_rm, op->params); qb_map_destroy(op->params); qb_util_stopwatch_free(op->time_execed); free(op); } qb_leave(); }
static void node_op_history_clear(struct assembly *assembly) { qb_map_iter_t *iter; struct operation_history *oh; const char *key; struct resource *r; qb_enter(); iter = qb_map_iter_create(op_history_map); while ((key = qb_map_iter_next(iter, (void **)&oh)) != NULL) { r = oh->resource; if (r->assembly == assembly) { /* stop the recurring monitor. */ if (qb_loop_timer_is_running(NULL, r->monitor_timer) && r->monitor_op) { recurring_monitor_stop(r->monitor_op); } qb_map_rm(op_history_map, key); free(oh->rsc_id); free(oh->operation); free(oh->op_digest); free(oh); } } qb_map_iter_free(iter); qb_leave(); }
void pe_resource_ref(struct pe_operation *op) { qb_enter(); op->refcount++; qb_leave(); }
static void schedule_processing(void) { qb_enter(); qb_loop_job_add(NULL, QB_LOOP_LOW, NULL, process_job); qb_leave(); }
static void dup_attr(gpointer key, gpointer value, gpointer user_data) { qb_enter(); qb_map_put(user_data, strdup(key), strdup(value)); qb_leave(); }
void cape_load_from_buffer(const char *buffer) { qb_enter(); _config = xmlParseMemory(buffer, strlen(buffer)); parse_and_load(); qb_leave(); }
static void node_recover_escalate(void * inst) { // struct assembly *a = (struct assembly *)inst; qb_enter(); qb_leave(); }
static void test6_signal (int sig) { cs_error_t error; qb_enter(); test6_sig_delivered++; if ((error = sam_data_store (&test6_sig_delivered, sizeof (test6_sig_delivered))) != CS_OK) { qb_log (LOG_ERR, "Can't store data! Error : %d", error); } }
static void resource_recover_restart(void * inst) { struct resource *resource = (struct resource *)inst; qb_enter(); qb_loop_timer_del(NULL, resource->monitor_timer); qb_leave(); }
static void func_two(void) { qb_enter(); qb_logt(LOG_DEBUG, 0, "arf arf?"); qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!"); qb_log(LOG_ERR, "oops, I did it again"); qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ..."); qb_leave(); }
int pe_resource_is_hard_error(enum ocf_exitcode ec) { qb_enter(); qb_leave(); return (ec == OCF_INVALID_PARAM || ec == OCF_UNIMPLEMENT_FEATURE || ec == OCF_INSUFFICIENT_PRIV || ec == OCF_NOT_INSTALLED || ec == OCF_NOT_CONFIGURED); }
static void xml_new_time_prop(xmlNode *n, const char *name, time_t val) { char int_str[36]; qb_enter(); snprintf(int_str, 36, "%d", (int)val); xmlNewProp(n, BAD_CAST name, BAD_CAST int_str); qb_leave(); }
void qb_rb_force_close(struct qb_ringbuffer_s * rb) { if (rb == NULL) { return; } qb_enter(); qb_atomic_int_set(&rb->shared_hdr->ref_count, -1); (void)qb_rb_close_helper(rb, QB_TRUE, QB_TRUE); }
int instance_destroy(struct assembly *a) { qb_enter(); instance_destroy_by_instance_id(a->instance_id, instance_destroy_completion, a); qb_leave(); return 0; }
void qb_rb_close(struct qb_ringbuffer_s * rb) { if (rb == NULL) { return; } qb_enter(); (void)qb_atomic_int_dec_and_test(&rb->shared_hdr->ref_count); (void)qb_rb_close_helper(rb, rb->flags & QB_RB_FLAG_CREATE, QB_FALSE); }
static void process_job(void *data) { qb_enter(); if (pe_is_busy_processing()) { schedule_processing(); } else { process(); } qb_leave(); }
int32_t pe_process_state(xmlDocPtr doc, pe_resource_execute_t exec_fn, pe_transition_completed_t done_fn, void *user_data, int debug) { crm_graph_t *transition = NULL; xmlNode *xml_input = xmlDocGetRootElement(doc); qb_enter(); if (working_set) { qb_log(LOG_ERR, "Transition already in progress"); qb_leave(); return -EEXIST; } transition_count++; if (debug) { char filename[PATH_MAX]; assert(validate_xml(xml_input, "pacemaker-1.2", FALSE) == TRUE); snprintf(filename, PATH_MAX, "/tmp/pe-%d-%d.xml", getpid(), transition_count); xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1); qb_log(LOG_INFO, "Executing deployable transition [%s]", filename); } else { qb_log(LOG_INFO, "Executing deployable transition [%d]", transition_count); } working_set = calloc(1, sizeof(pe_working_set_t)); run_fn = exec_fn; completed_fn = done_fn; run_user_data = user_data; set_graph_functions(&graph_exec_fns); set_working_set_defaults(working_set); /* calculate output */ do_calculations(working_set, xml_input, NULL); transition = unpack_graph(working_set->graph, __func__); //print_graph(LOG_INFO, transition); graph_updated = TRUE; qb_loop_job_add(NULL, QB_LOOP_HIGH, transition, process_next_job); qb_leave(); return 0; }
static gboolean exec_crmd_action(crm_graph_t *graph, crm_action_t *action) { qb_enter(); action->confirmed = TRUE; update_graph(graph, action); graph_updated = TRUE; qb_leave(); return TRUE; }
/* * External API */ int32_t instance_create(struct assembly *assembly) { qb_enter(); qb_util_stopwatch_start(assembly->sw_instance_create); image_id_get(assembly->name, image_id_get_completion, assembly); instance_create_from_image_id(assembly->image_id, instance_create_completion, assembly); qb_loop_job_add(NULL, QB_LOOP_LOW, assembly, my_instance_state_get); qb_leave(); return 0; }
static void resources_create(xmlNode *cur_node, struct assembly *assembly) { qb_enter(); for (; cur_node; cur_node = cur_node->next) { if (cur_node->type != XML_ELEMENT_NODE) { continue; } resource_create(cur_node, assembly); } qb_leave(); }
int32_t pe_is_busy_processing(void) { qb_enter(); if (working_set != NULL) { qb_leave(); return TRUE; } qb_leave(); return FALSE; }
/* * This tests recovery policy quit and callback. */ static int test2 (void) { cs_error_t error; unsigned int instance_id; qb_enter(); error = sam_initialize (2000, SAM_RECOVERY_POLICY_QUIT); if (error != CS_OK) { qb_log (LOG_ERR, "Can't initialize SAM API. Error %d", error); return 1; } qb_log (LOG_INFO, "register"); error = sam_register (&instance_id); if (error != CS_OK) { qb_log (LOG_ERR, "Can't register. Error %d", error); return 1; } if (instance_id == 1) { signal (SIGTERM, test2_signal); qb_log (LOG_INFO, "iid %d: start", instance_id); error = sam_start (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't start hc. Error %d", error); return 1; } qb_log (LOG_INFO, "iid %d: sleep 1", instance_id); sleep (1); qb_log (LOG_INFO, "iid %d: hc send", instance_id); error = sam_hc_send (); if (error != CS_OK) { qb_log (LOG_ERR, "Can't send hc. Error %d", error); return 1; } qb_log (LOG_INFO, "iid %d: wait for delivery of signal", instance_id); while (!test2_sig_delivered) { sleep (1); } qb_log (LOG_INFO, "iid %d: wait for real kill", instance_id); sleep (3); } return 1; }
static void log_it_please(void) { qb_enter(); qb_log(LOG_TRACE, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_DEBUG, "A:%d B:%d C:%d", 1, 2, 3); errno = EEXIST; qb_perror(LOG_WARNING, "bogus error"); errno = 0; qb_log(LOG_INFO, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_NOTICE, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_WARNING, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_ERR, "A:%d B:%d C:%d", 1, 2, 3); qb_leave(); }
static void resource_execute_cb(struct pe_operation *op) { struct resource *resource; struct assembly *assembly; qb_enter(); assembly = qb_map_get(assembly_map, op->hostname); resource = qb_map_get(assembly->resource_map, op->rname); if (assembly->recover.state != RECOVER_STATE_RUNNING) { qb_log(LOG_DEBUG, "can't execute resource in offline state"); resource_action_completed(op, OCF_UNKNOWN_ERROR); return; } qb_log(LOG_TRACE, "%s_%s_%d [%s] on %s target_rc:%d", op->rname, op->method, op->interval, op->rclass, op->hostname, op->target_outcome); qb_util_stopwatch_start(op->time_execed); op->resource = resource; if (strcmp(op->method, "monitor") == 0) { if (strstr(op->rname, op->hostname) != NULL) { assert(op->resource); if (op->interval > 0) { recurring_monitor_start(op); } else { resource_monitor_execute(op); } } else { qb_util_stopwatch_stop(op->time_execed); pe_resource_completed(op, OCF_NOT_RUNNING); pe_resource_unref(op); } } else if (strcmp (op->method, "start") == 0) { transport_resource_action(assembly, resource, op); } else if (strcmp(op->method, "stop") == 0) { if (resource->monitor_op) { recurring_monitor_stop(resource->monitor_op); } transport_resource_action(assembly, resource, op); } else if (strcmp(op->method, "delete") == 0) { op_history_delete(op); } else { assert(0); } qb_leave(); }
void resource_action_completed(struct pe_operation *op, enum ocf_exitcode pe_exitcode) { uint64_t el; struct assembly *a = qb_map_get(assembly_map, op->hostname);; struct resource *r = qb_map_get(a->resource_map, op->rname); qb_enter(); op->times_executed++; qb_util_stopwatch_stop(op->time_execed); el = qb_util_stopwatch_us_elapsed_get(op->time_execed); qb_log(LOG_INFO, "%s_%s_%d [%s] on %s rc:[%d/%d] time:[%"PRIu64"/%ums]", op->rname, op->method, op->interval, op->rclass, op->hostname, pe_exitcode, op->target_outcome, el / QB_TIME_US_IN_MSEC, op->timeout); if (strstr(op->rname, op->hostname) != NULL) { op_history_save(r, op, pe_exitcode); } if (op->times_executed <= 1) { pe_resource_completed(op, pe_exitcode); } resource_state_set(r, op, pe_exitcode); if (pe_exitcode != op->target_outcome) { schedule_processing(); } if (op->interval > 0) { if (pe_exitcode != op->target_outcome) { /* unreference as not used by the timer anymore. */ pe_resource_unref(op); } else { qb_loop_timer_add(NULL, QB_LOOP_LOW, op->interval * QB_TIME_NS_IN_MSEC, op, resource_monitor_execute, &r->monitor_timer); } } else { pe_resource_unref(op); } qb_leave(); }
static void resource_recover_escalate(void * inst) { struct resource *r = (struct resource *)inst; qb_enter(); qb_log(LOG_NOTICE, "Escalating failure of service %s to node %s:%s", r->name, r->assembly->uuid, r->assembly->name); qb_loop_timer_del(NULL, r->monitor_timer); instance_destroy(r->assembly); qb_leave(); }
void cape_exit(void) { struct assembly *assembly; qb_map_iter_t *iter; qb_enter(); iter = qb_map_iter_create(assembly_map); while ((qb_map_iter_next(iter, (void **)&assembly)) != NULL) { transport_disconnect(assembly); } qb_map_iter_free(iter); qb_leave(); }
static void node_recover_restart(void * inst) { struct assembly *a = (struct assembly *)inst; qb_enter(); transport_disconnect(a); node_op_history_clear(a); instance_create(a); qb_leave(); }