static void corosync_fplay_control_init (void) { icmap_track_t track = NULL; icmap_set_string("runtime.blackbox.dump_flight_data", "no"); icmap_set_string("runtime.blackbox.dump_state", "no"); icmap_track_add("runtime.blackbox.dump_flight_data", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY, fplay_key_change_notify_fn, NULL, &track); icmap_track_add("runtime.blackbox.dump_state", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY, fplay_key_change_notify_fn, NULL, &track); }
static void add_totem_config_notification(struct totem_config *totem_config) { icmap_track_t icmap_track; icmap_track_add("totem.", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX, totem_change_notify, totem_config, &icmap_track); }
static void corosync_totem_dynamic_init (void) { icmap_track_t icmap_track = NULL; icmap_track_add("nodelist.node.", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX, totem_dynamic_notify, NULL, &icmap_track); }
static void totemknet_add_config_notifications(struct totemknet_instance *instance) { icmap_track_t icmap_track_totem = NULL; icmap_track_t icmap_track_reload = NULL; ENTER(); icmap_track_add("totem.", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX, totemknet_refresh_config, instance, &icmap_track_totem); icmap_track_add("config.totemconfig_reload_in_progress", ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY, totemknet_refresh_config, instance, &icmap_track_reload); LEAVE(); }
static void wd_scan_resources (void) { int res_count = 0; icmap_track_t icmap_track = NULL; icmap_iter_t iter; const char *key_name; int res; char res_name[ICMAP_KEYNAME_MAXLEN]; char res_type[ICMAP_KEYNAME_MAXLEN]; char tmp_key[ICMAP_KEYNAME_MAXLEN]; ENTER(); iter = icmap_iter_init("resources."); while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) { res = sscanf(key_name, "resources.%[^.].%[^.].%[^.]", res_type, res_name, tmp_key); if (res != 3) { continue ; } if (strcmp(tmp_key, "state") != 0) { continue ; } snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "resources.%s.%s.", res_type, res_name); if (wd_resource_create (tmp_key, res_name) == 0) { res_count++; } } icmap_iter_finalize(iter); icmap_track_add("resources.process.", ICMAP_TRACK_ADD | ICMAP_TRACK_PREFIX, wd_resource_created_cb, NULL, &icmap_track); icmap_track_add("resources.system.", ICMAP_TRACK_ADD | ICMAP_TRACK_PREFIX, wd_resource_created_cb, NULL, &icmap_track); if (res_count == 0) { log_printf (LOGSYS_LEVEL_INFO, "no resources configured."); } }
static int corosync_main_config_read_logging ( const char **error_string) { const char *error_reason; #ifdef LOGCONFIG_USE_ICMAP icmap_iter_t iter; const char *key_name; #else cmap_iter_handle_t iter; char key_name[CMAP_KEYNAME_MAXLEN]; #endif char key_subsys[MAP_KEYNAME_MAXLEN]; char key_item[MAP_KEYNAME_MAXLEN]; int res; /* format set is supported only for toplevel */ if (corosync_main_config_format_set(&error_reason) < 0) { goto parse_error; } if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) { goto parse_error; } /* * we will need 2 of these to compensate for new logging * config format */ #ifdef LOGCONFIG_USE_ICMAP iter = icmap_iter_init("logging.logger_subsys."); while ((key_name = icmap_iter_next(iter, NULL, NULL)) != NULL) { #else cmap_iter_init(cmap_handle, "logging.logger_subsys.", &iter); while ((cmap_iter_next(cmap_handle, iter, key_name, NULL, NULL)) == CS_OK) { #endif res = sscanf(key_name, "logging.logger_subsys.%[^.].%s", key_subsys, key_item); if (res != 2) { continue ; } if (strcmp(key_item, "subsys") != 0) { continue ; } snprintf(key_item, MAP_KEYNAME_MAXLEN, "logging.logger_subsys.%s", key_subsys); if (corosync_main_config_set(key_item, key_subsys, &error_reason) < 0) { goto parse_error; } } #ifdef LOGCONFIG_USE_ICMAP icmap_iter_finalize(iter); #else cmap_iter_finalize(cmap_handle, iter); #endif logsys_config_apply(); return 0; parse_error: *error_string = error_reason; return (-1); } #ifdef LOGCONFIG_USE_ICMAP static void main_logging_notify( int32_t event, const char *key_name, struct icmap_notify_value new_val, struct icmap_notify_value old_val, void *user_data) #else static void main_logging_notify( cmap_handle_t cmap_handle_unused, cmap_handle_t cmap_track_handle_unused, int32_t event, const char *key_name, struct cmap_notify_value new_val, struct cmap_notify_value old_val, void *user_data) #endif { const char *error_string; static int reload_in_progress = 0; /* If a full reload happens then suspend updates for individual keys until * it's all completed */ if (strcmp(key_name, "config.reload_in_progress") == 0) { if (*(uint8_t *)new_val.data == 1) { reload_in_progress = 1; } else { reload_in_progress = 0; } } if (reload_in_progress) { log_printf(LOGSYS_LEVEL_DEBUG, "Ignoring key change, reload in progress. %s\n", key_name); return; } /* * Reload the logsys configuration */ if (logsys_format_set(NULL) == -1) { fprintf (stderr, "Unable to setup logging format.\n"); } corosync_main_config_read_logging(&error_string); } #ifdef LOGCONFIG_USE_ICMAP static void add_logsys_config_notification(void) { icmap_track_t icmap_track = NULL; icmap_track_add("logging.", ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX, main_logging_notify, NULL, &icmap_track); icmap_track_add("config.reload_in_progress", ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY, main_logging_notify, NULL, &icmap_track); }
/* * return 0 - fully configured * return -1 - partially configured */ static int32_t wd_resource_create (char *res_path, char *res_name) { char *state; uint64_t tmp_value; struct resource *ref = calloc (1, sizeof (struct resource)); char key_name[ICMAP_KEYNAME_MAXLEN]; strcpy(ref->res_path, res_path); ref->check_timeout = WD_DEFAULT_TIMEOUT_MS; ref->check_timer = 0; strcpy(ref->name, res_name); ref->fsm.name = ref->name; ref->fsm.table = wd_fsm_table; ref->fsm.entries = sizeof(wd_fsm_table) / sizeof(struct cs_fsm_entry); ref->fsm.curr_entry = 0; ref->fsm.curr_state = WD_S_STOPPED; ref->fsm.state_to_str = wd_res_state_to_str; ref->fsm.event_to_str = wd_res_event_to_str; snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "poll_period"); if (icmap_get_uint64(key_name, &tmp_value) != CS_OK) { icmap_set_uint64(key_name, ref->check_timeout); } else { if (tmp_value >= WD_MIN_TIMEOUT_MS && tmp_value <= WD_MAX_TIMEOUT_MS) { ref->check_timeout = tmp_value; } else { log_printf (LOGSYS_LEVEL_WARNING, "Could NOT use poll_period:%"PRIu64" ms for resource %s", tmp_value, ref->name); } } icmap_track_add(res_path, ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY | ICMAP_TRACK_DELETE | ICMAP_TRACK_PREFIX, wd_key_changed, ref, &ref->icmap_track); snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "recovery"); if (icmap_get_string(key_name, &ref->recovery) != CS_OK) { /* key does not exist. */ log_printf (LOGSYS_LEVEL_WARNING, "resource %s missing a recovery key.", ref->name); return -1; } snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "state"); if (icmap_get_string(key_name, &state) != CS_OK) { /* key does not exist. */ log_printf (LOGSYS_LEVEL_WARNING, "resource %s missing a state key.", ref->name); return -1; } snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "last_updated"); if (icmap_get_uint64(key_name, &tmp_value) != CS_OK) { /* key does not exist. */ ref->last_updated = 0; } else { ref->last_updated = tmp_value; } /* * delay the first check to give the monitor time to start working. */ tmp_value = CS_MAX(ref->check_timeout * 2, WD_DEFAULT_TIMEOUT_MS); api->timer_add_duration(tmp_value * MILLI_2_NANO_SECONDS, ref, wd_resource_check_fn, &ref->check_timer); cs_fsm_state_set(&ref->fsm, WD_S_RUNNING, ref); return 0; }