From fdf55886e9206599712494aa354a19932b913bff Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Jan 22 2021 12:12:42 +0000 Subject: Refactor: tools: use new resource parameter function in crm_resource patch_name: 021-rhbz1872376.patch present_in_specfile: true location_in_specfile: 21 squash_commits: true --- diff --git a/tools/crm_resource.c b/tools/crm_resource.c index b028c40..9663e68 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -1902,6 +1902,7 @@ main(int argc, char **argv) unsigned int count = 0; GHashTable *params = NULL; pe_node_t *current = pe__find_active_on(rsc, &count, NULL); + bool free_params = true; if (count > 1) { out->err(out, "%s is active on more than one node," @@ -1909,23 +1910,26 @@ main(int argc, char **argv) current = NULL; } - params = crm_str_table_new(); + crm_debug("Looking up %s in %s", options.prop_name, rsc->id); if (pcmk__str_eq(options.attr_set_type, XML_TAG_ATTR_SETS, pcmk__str_casei)) { - get_rsc_attributes(params, rsc, current, data_set); + params = pe_rsc_params(rsc, current, data_set); + free_params = false; } else if (pcmk__str_eq(options.attr_set_type, XML_TAG_META_SETS, pcmk__str_casei)) { - /* No need to redirect to the parent */ + params = crm_str_table_new(); get_meta_attributes(params, rsc, current, data_set); } else { + params = crm_str_table_new(); pe__unpack_dataset_nvpairs(rsc->xml, XML_TAG_UTILIZATION, NULL, params, NULL, FALSE, data_set); } - crm_debug("Looking up %s in %s", options.prop_name, rsc->id); rc = out->message(out, "attribute-list", rsc, options.prop_name, params); - g_hash_table_destroy(params); + if (free_params) { + g_hash_table_destroy(params); + } break; } diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c index 89d6172..398fef0 100644 --- a/tools/crm_resource_print.c +++ b/tools/crm_resource_print.c @@ -134,8 +134,11 @@ attribute_list_default(pcmk__output_t *out, va_list args) { char *attr = va_arg(args, char *); GHashTable *params = va_arg(args, GHashTable *); - const char *value = g_hash_table_lookup(params, attr); + const char *value = NULL; + if (params != NULL) { + value = g_hash_table_lookup(params, attr); + } if (value != NULL) { out->begin_list(out, NULL, NULL, "Attributes"); out->list_item(out, attr, "%s", value); @@ -154,8 +157,11 @@ attribute_list_text(pcmk__output_t *out, va_list args) { char *attr = va_arg(args, char *); GHashTable *params = va_arg(args, GHashTable *); - const char *value = g_hash_table_lookup(params, attr); + const char *value = NULL; + if (params != NULL) { + value = g_hash_table_lookup(params, attr); + } if (value != NULL) { out->info(out, "%s", value); } else { diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c index e0804fc..9ff9e96 100644 --- a/tools/crm_resource_runtime.c +++ b/tools/crm_resource_runtime.c @@ -916,40 +916,29 @@ cli_resource_fail(pcmk__output_t *out, pcmk_ipc_api_t *controld_api, } static GHashTable * -generate_resource_params(pe_resource_t * rsc, pe_working_set_t * data_set) +generate_resource_params(pe_resource_t *rsc, pe_node_t *node, + pe_working_set_t *data_set) { GHashTable *params = NULL; GHashTable *meta = NULL; GHashTable *combined = NULL; GHashTableIter iter; + char *key = NULL; + char *value = NULL; - if (!rsc) { - crm_err("Resource does not exist in config"); - return NULL; - } - - params = crm_str_table_new(); - meta = crm_str_table_new(); combined = crm_str_table_new(); - get_rsc_attributes(params, rsc, NULL /* TODO: Pass in local node */ , data_set); - get_meta_attributes(meta, rsc, NULL /* TODO: Pass in local node */ , data_set); - - if (params) { - char *key = NULL; - char *value = NULL; - + params = pe_rsc_params(rsc, node, data_set); + if (params != NULL) { g_hash_table_iter_init(&iter, params); while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value)) { g_hash_table_insert(combined, strdup(key), strdup(value)); } - g_hash_table_destroy(params); } - if (meta) { - char *key = NULL; - char *value = NULL; - + meta = crm_str_table_new(); + get_meta_attributes(meta, rsc, node, data_set); + if (meta != NULL) { g_hash_table_iter_init(&iter, meta); while (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value)) { char *crm_name = crm_meta_name(key); @@ -1827,7 +1816,8 @@ cli_resource_execute(pcmk__output_t *out, pe_resource_t *rsc, rprov = crm_element_value(rsc->xml, XML_AGENT_ATTR_PROVIDER); rtype = crm_element_value(rsc->xml, XML_ATTR_TYPE); - params = generate_resource_params(rsc, data_set); + params = generate_resource_params(rsc, NULL /* @TODO use local node */, + data_set); if (timeout_ms == 0) { timeout_ms = pe_get_configured_timeout(rsc, action, data_set);