MCPcopy Create free account
hub / github.com/corosync/corosync / wd_resource_create

Function wd_resource_create

exec/wd.c:421–495  ·  view source on GitHub ↗

* return 0 - fully configured * return -1 - partially configured */

Source from the content-addressed store, hash-verified

419 * return -1 - partially configured
420 */
421static int32_t wd_resource_create (char *res_path, char *res_name)
422{
423 char *state;
424 uint64_t tmp_value;
425 struct resource *ref = calloc (1, sizeof (struct resource));
426 char key_name[ICMAP_KEYNAME_MAXLEN];
427
428 strcpy(ref->res_path, res_path);
429 ref->check_timeout = WD_DEFAULT_TIMEOUT_MS;
430 ref->check_timer = 0;
431
432 strcpy(ref->name, res_name);
433 ref->fsm.name = ref->name;
434 ref->fsm.table = wd_fsm_table;
435 ref->fsm.entries = sizeof(wd_fsm_table) / sizeof(struct cs_fsm_entry);
436 ref->fsm.curr_entry = 0;
437 ref->fsm.curr_state = WD_S_STOPPED;
438 ref->fsm.state_to_str = wd_res_state_to_str;
439 ref->fsm.event_to_str = wd_res_event_to_str;
440
441 snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "poll_period");
442 if (icmap_get_uint64(key_name, &tmp_value) != CS_OK) {
443 icmap_set_uint64(key_name, ref->check_timeout);
444 } else {
445 if (tmp_value >= WD_MIN_TIMEOUT_MS && tmp_value <= WD_MAX_TIMEOUT_MS) {
446 ref->check_timeout = tmp_value;
447 } else {
448 log_printf (LOGSYS_LEVEL_WARNING,
449 "Could NOT use poll_period:%"PRIu64" ms for resource %s",
450 tmp_value, ref->name);
451 }
452 }
453
454 icmap_track_add(res_path,
455 ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY | ICMAP_TRACK_DELETE | ICMAP_TRACK_PREFIX,
456 wd_key_changed,
457 ref, &ref->icmap_track);
458
459 snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "recovery");
460 if (icmap_get_string(key_name, &ref->recovery) != CS_OK) {
461 /* key does not exist.
462 */
463 log_printf (LOGSYS_LEVEL_WARNING,
464 "resource %s missing a recovery key.", ref->name);
465 return -1;
466 }
467 snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "state");
468 if (icmap_get_string(key_name, &state) != CS_OK) {
469 /* key does not exist.
470 */
471 log_printf (LOGSYS_LEVEL_WARNING,
472 "resource %s missing a state key.", ref->name);
473 return -1;
474 }
475
476 snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "%s%s", res_path, "last_updated");
477 if (icmap_get_uint64(key_name, &tmp_value) != CS_OK) {
478 /* key does not exist.

Callers 2

wd_resource_created_cbFunction · 0.85
wd_scan_resourcesFunction · 0.85

Calls 5

icmap_get_uint64Function · 0.85
icmap_set_uint64Function · 0.85
icmap_track_addFunction · 0.85
icmap_get_stringFunction · 0.85
cs_fsm_state_setFunction · 0.85

Tested by

no test coverage detected