static gboolean sbd_get_two_node(void) { uint8_t two_node_u8 = 0; int cmap_fd; if (!track_handle) { if (cmap_initialize(&cmap_handle) != CS_OK) { cl_log(LOG_WARNING, "Cannot initialize CMAP service\n"); goto out; } if (cmap_track_add(cmap_handle, "quorum.two_node", CMAP_TRACK_DELETE|CMAP_TRACK_MODIFY|CMAP_TRACK_ADD, sbd_cmap_notify_fn, NULL, &track_handle) != CS_OK) { cl_log(LOG_WARNING, "Failed adding CMAP tracker for 2Node-mode\n"); goto out; } /* add the tracker to mainloop */ if (cmap_fd_get(cmap_handle, &cmap_fd) != CS_OK) { cl_log(LOG_WARNING, "Failed to get a file handle for cmap\n"); goto out; } if (!(cmap_source = g_unix_fd_source_new (cmap_fd, G_IO_IN))) { cl_log(LOG_WARNING, "Couldn't create source for cmap\n"); goto out; } g_source_set_callback(cmap_source, cmap_dispatch_callback, NULL, NULL); g_source_attach(cmap_source, NULL); } if (cmap_get_uint8(cmap_handle, "quorum.two_node", &two_node_u8) == CS_OK) { cl_log(two_node_u8? LOG_NOTICE : LOG_INFO, "Corosync is%s in 2Node-mode", two_node_u8?"":" not"); two_node = two_node_u8; } else { cl_log(LOG_INFO, "quorum.two_node not present in cmap\n"); } return TRUE; out: cmap_destroy(); return FALSE; }
static void _cs_cmap_rrp_faulty_key_changed ( cmap_handle_t cmap_handle_c, cmap_track_handle_t cmap_track_handle, int32_t event, const char *key_name, struct cmap_notify_value new_value, struct cmap_notify_value old_value, void *user_data) { uint32_t iface_no; char tmp_key[CMAP_KEYNAME_MAXLEN]; int res; int no_retries; uint8_t faulty; cs_error_t err; res = sscanf(key_name, "runtime.totem.pg.mrp.rrp.%u.%s", &iface_no, tmp_key); if (res != 2) { return ; } if (strcmp(tmp_key, "faulty") != 0) { return ; } no_retries = 0; while ((err = cmap_get_uint8(cmap_handle, key_name, &faulty)) == CS_ERR_TRY_AGAIN && no_retries++ < CMAP_MAX_RETRIES) { sleep(1); } if (err != CS_OK) { return ; } if (faulty) { _cs_rrp_faulty_event(iface_no, "faulty"); } else { _cs_rrp_faulty_event(iface_no, "operational"); } }
static void _cs_cmap_link_faulty_key_changed ( cmap_handle_t cmap_handle_c, cmap_track_handle_t cmap_track_handle, int32_t event, const char *key_name, struct cmap_notify_value new_value, struct cmap_notify_value old_value, void *user_data) { uint32_t iface_no; uint32_t nodeid; int res; int no_retries; uint8_t connected; cs_error_t err; res = sscanf(key_name, "stats.knet.node%u.link%u.connected", &nodeid, &iface_no); if (res != 2) { return ; } no_retries = 0; while ((err = cmap_get_uint8(stats_handle, key_name, &connected)) == CS_ERR_TRY_AGAIN && no_retries++ < CMAP_MAX_RETRIES) { sleep(1); } if (err != CS_OK) { return ; } if (connected) { _cs_link_faulty_event(nodeid, iface_no, "operational"); } else { _cs_link_faulty_event(nodeid, iface_no, "disconnected"); } }
static void print_key(cmap_handle_t handle, const char *key_name, size_t value_len, const void *value, cmap_value_types_t type) { char *str; char *bin_value = NULL; cs_error_t err; int8_t i8; uint8_t u8; int16_t i16; uint16_t u16; int32_t i32; uint32_t u32; int64_t i64; uint64_t u64; float flt; double dbl; int end_loop; int no_retries; size_t bin_value_len; end_loop = 0; no_retries = 0; err = CS_OK; while (!end_loop) { switch (type) { case CMAP_VALUETYPE_INT8: if (value == NULL) { err = cmap_get_int8(handle, key_name, &i8); } else { i8 = *((int8_t *)value); } break; case CMAP_VALUETYPE_INT16: if (value == NULL) { err = cmap_get_int16(handle, key_name, &i16); } else { i16 = *((int16_t *)value); } break; case CMAP_VALUETYPE_INT32: if (value == NULL) { err = cmap_get_int32(handle, key_name, &i32); } else { i32 = *((int32_t *)value); } break; case CMAP_VALUETYPE_INT64: if (value == NULL) { err = cmap_get_int64(handle, key_name, &i64); } else { i64 = *((int64_t *)value); } break; case CMAP_VALUETYPE_UINT8: if (value == NULL) { err = cmap_get_uint8(handle, key_name, &u8); } else { u8 = *((uint8_t *)value); } break; case CMAP_VALUETYPE_UINT16: if (value == NULL) { err = cmap_get_uint16(handle, key_name, &u16); } else { u16 = *((uint16_t *)value); } break; case CMAP_VALUETYPE_UINT32: if (value == NULL) { err = cmap_get_uint32(handle, key_name, &u32); } else { u32 = *((uint32_t *)value); } break; case CMAP_VALUETYPE_UINT64: if (value == NULL) { err = cmap_get_uint64(handle, key_name, &u64); } else { u64 = *((uint64_t *)value); } break; case CMAP_VALUETYPE_FLOAT: if (value == NULL) { err = cmap_get_float(handle, key_name, &flt); } else { flt = *((float *)value); } break; case CMAP_VALUETYPE_DOUBLE: if (value == NULL) { err = cmap_get_double(handle, key_name, &dbl); } else { dbl = *((double *)value); } break; case CMAP_VALUETYPE_STRING: if (value == NULL) { err = cmap_get_string(handle, key_name, &str); } else { str = (char *)value; } break; case CMAP_VALUETYPE_BINARY: if (show_binary) { if (value == NULL) { bin_value = malloc(value_len); if (bin_value == NULL) { fprintf(stderr, "Can't alloc memory\n"); exit(EXIT_FAILURE); } bin_value_len = value_len; err = cmap_get(handle, key_name, bin_value, &bin_value_len, NULL); } else { bin_value = (char *)value; } } break; } if (err == CS_OK) end_loop = 1; if (err == CS_ERR_TRY_AGAIN) { sleep(1); no_retries++; } if (no_retries > MAX_TRY_AGAIN) { end_loop = 1; } }; if (err != CS_OK) { fprintf(stderr, "Can't get value of %s. Error %s\n", key_name, cs_strerror(err)); return ; } printf("%s (", key_name); switch (type) { case CMAP_VALUETYPE_INT8: printf("%s) = %"PRId8, "i8", i8); break; case CMAP_VALUETYPE_UINT8: printf("%s) = %"PRIu8, "u8", u8); break; case CMAP_VALUETYPE_INT16: printf("%s) = %"PRId16, "i16", i16); break; case CMAP_VALUETYPE_UINT16: printf("%s) = %"PRIu16, "u16", u16); break; case CMAP_VALUETYPE_INT32: printf("%s) = %"PRId32, "i32", i32); break; case CMAP_VALUETYPE_UINT32: printf("%s) = %"PRIu32, "u32", u32); break; case CMAP_VALUETYPE_INT64: printf("%s) = %"PRId64, "i64", i64); break; case CMAP_VALUETYPE_UINT64: printf("%s) = %"PRIu64, "u64", u64); break; case CMAP_VALUETYPE_FLOAT: printf("%s) = %f", "flt", flt); break; case CMAP_VALUETYPE_DOUBLE: printf("%s) = %lf", "dbl", dbl); break; case CMAP_VALUETYPE_STRING: printf("%s) = %s", "str", str); if (value == NULL) { free(str); } break; case CMAP_VALUETYPE_BINARY: printf("%s)", "bin"); if (show_binary) { printf(" = "); if (bin_value) { print_binary_key(bin_value, value_len); if (value == NULL) { free(bin_value); } } else { printf("*empty*"); } } break; } printf("\n"); }
static void qdevice_cmap_reload_cb(cmap_handle_t cmap_handle, cmap_track_handle_t cmap_track_handle, int32_t event, const char *key_name, struct cmap_notify_value new_value, struct cmap_notify_value old_value, void *user_data) { cs_error_t cs_res; uint8_t reload; struct qdevice_instance *instance; const char *node_list_prefix_str; const char *logging_prefix_str; const char *heuristics_prefix_str; struct qdevice_cmap_change_events events; memset(&events, 0, sizeof(events)); node_list_prefix_str = "nodelist."; logging_prefix_str = "logging."; heuristics_prefix_str = "quorum.device.heuristics."; if (cmap_context_get(cmap_handle, (const void **)&instance) != CS_OK) { qdevice_log(LOG_ERR, "Fatal error. Can't get cmap context"); exit(1); } /* * Wait for full reload */ if (strcmp(key_name, "config.totemconfig_reload_in_progress") == 0 && new_value.type == CMAP_VALUETYPE_UINT8 && new_value.len == sizeof(reload)) { reload = 1; if (memcmp(new_value.data, &reload, sizeof(reload)) == 0) { /* * Ignore nodelist changes */ instance->cmap_reload_in_progress = 1; return ; } else { instance->cmap_reload_in_progress = 0; events.node_list = 1; events.logging = 1; events.heuristics = 1; } } if (instance->cmap_reload_in_progress) { return ; } if (((cs_res = cmap_get_uint8(cmap_handle, "config.totemconfig_reload_in_progress", &reload)) == CS_OK) && reload == 1) { return ; } if (strncmp(key_name, node_list_prefix_str, strlen(node_list_prefix_str)) == 0) { events.node_list = 1; } if (strncmp(key_name, logging_prefix_str, strlen(logging_prefix_str)) == 0) { events.logging = 1; } if (strncmp(key_name, heuristics_prefix_str, strlen(heuristics_prefix_str)) == 0) { events.heuristics = 1; } if (events.logging) { qdevice_cmap_logging_event(instance); } if (events.node_list) { qdevice_cmap_node_list_event(instance); } if (events.heuristics) { qdevice_cmap_heuristics_event(instance); } /* * Inform model about change */ if (qdevice_model_cmap_changed(instance, &events) != 0) { qdevice_log(LOG_DEBUG, "qdevice_model_cmap_changed returned error -> exit"); exit(2); } }