Hi Andrew, I added utilization support for crm_attribute and crm_resource. Attached the patch. Please let me know if you have any comments or suggestions on that.
BTW, LF#2351 has been fixed. Attached the patch there: http://developerbugs.linux-foundation.org/show_bug.cgi?id=2351 Thanks, Yan -- Yan Gao <y...@novell.com> Software Engineer China Server Team, OPS Engineering, Novell, Inc.
# HG changeset patch # User Yan Gao <y...@novell.com> # Date 1267696081 -28800 # Node ID 692f8d2fa65b1e956f450ccb0664fc50f6f8b7bb # Parent a6b66ac53fa969658860964b186548bc514c9455 Dev: Tools: Add utilization support for crm_attribute and crm_resource diff -r a6b66ac53fa9 -r 692f8d2fa65b crmd/control.c --- a/crmd/control.c Thu Mar 04 08:40:17 2010 +0100 +++ b/crmd/control.c Thu Mar 04 17:48:01 2010 +0800 @@ -86,7 +86,7 @@ } else { int rc = update_attr( fsa_cib_conn, cib_quorum_override|cib_scope_local|cib_inhibit_notify, - XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, XML_ATTR_EXPECTED_VOTES, votes, FALSE); + XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL, XML_ATTR_EXPECTED_VOTES, votes, FALSE); crm_info("Setting expected votes to %s", votes); if(cib_ok > rc) { diff -r a6b66ac53fa9 -r 692f8d2fa65b crmd/election.c --- a/crmd/election.c Thu Mar 04 08:40:17 2010 +0100 +++ b/crmd/election.c Thu Mar 04 17:48:01 2010 +0800 @@ -444,10 +444,10 @@ add_cib_op_callback(fsa_cib_conn, rc, FALSE, NULL, feature_update_callback); update_attr(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG, - NULL, NULL, NULL, "dc-version", VERSION"-"BUILD_VERSION, FALSE); + NULL, NULL, NULL, NULL, "dc-version", VERSION"-"BUILD_VERSION, FALSE); update_attr(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG, - NULL, NULL, NULL, "cluster-infrastructure", cluster_type, FALSE); + NULL, NULL, NULL, NULL, "cluster-infrastructure", cluster_type, FALSE); mainloop_set_trigger(config_read); free_xml(cib); diff -r a6b66ac53fa9 -r 692f8d2fa65b crmd/lrm.c --- a/crmd/lrm.c Thu Mar 04 08:40:17 2010 +0100 +++ b/crmd/lrm.c Thu Mar 04 17:48:01 2010 +0800 @@ -1156,7 +1156,7 @@ from_sys, rsc->id); update_attr(fsa_cib_conn, cib_none, XML_CIB_TAG_CRMCONFIG, - NULL, NULL, NULL, "last-lrm-refresh", now_s, FALSE); + NULL, NULL, NULL, NULL, "last-lrm-refresh", now_s, FALSE); crm_free(now_s); } diff -r a6b66ac53fa9 -r 692f8d2fa65b include/crm/cib_util.h --- a/include/crm/cib_util.h Thu Mar 04 08:40:17 2010 +0100 +++ b/include/crm/cib_util.h Thu Mar 04 17:48:01 2010 +0800 @@ -50,21 +50,21 @@ extern enum cib_errors update_attr( cib_t *the_cib, int call_options, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console); extern enum cib_errors find_nvpair_attr( - cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *set_name, - const char *attr_id, const char *attr_name, gboolean to_console, char **value); + cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *set_type, + const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value); extern enum cib_errors read_attr( cib_t *the_cib, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, char **attr_value, gboolean to_console); extern enum cib_errors delete_attr( cib_t *the_cib, int options, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console); extern enum cib_errors query_node_uuid( diff -r a6b66ac53fa9 -r 692f8d2fa65b lib/cib/cib_attrs.c --- a/lib/cib/cib_attrs.c Thu Mar 04 08:40:17 2010 +0100 +++ b/lib/cib/cib_attrs.c Thu Mar 04 17:48:01 2010 +0800 @@ -47,8 +47,8 @@ extern enum cib_errors find_nvpair_attr( - cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *set_name, - const char *attr_id, const char *attr_name, gboolean to_console, char **value) + cib_t *the_cib, const char *attr, const char *section, const char *node_uuid, const char *attr_set_type, + const char *set_name, const char *attr_id, const char *attr_name, gboolean to_console, char **value) { int offset = 0; static int xpath_max = 1024; @@ -56,7 +56,13 @@ char *xpath_string = NULL; xmlNode *xml_search = NULL; - const char *set_type = XML_TAG_ATTR_SETS; + const char *set_type = NULL; + + if (attr_set_type) { + set_type = attr_set_type; + } else { + set_type = XML_TAG_ATTR_SETS; + } CRM_ASSERT(value != NULL); *value = NULL; @@ -88,7 +94,9 @@ if(set_name) { offset += snprintf(xpath_string + offset, xpath_max - offset, "//%...@id='%s']", set_type, set_name); - } + } else { + offset += snprintf(xpath_string + offset, xpath_max - offset, "//%s", set_type); + } offset += snprintf(xpath_string + offset, xpath_max - offset, "//nvpair["); if(attr_id) { @@ -139,7 +147,7 @@ enum cib_errors update_attr(cib_t *the_cib, int call_options, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console) { const char *tag = NULL; @@ -155,7 +163,7 @@ CRM_CHECK(attr_value != NULL, return cib_missing); CRM_CHECK(attr_name != NULL || attr_id != NULL, return cib_missing); - rc = find_nvpair_attr(the_cib, XML_ATTR_ID, section, node_uuid, set_name, attr_id, attr_name, FALSE, &local_attr_id); + rc = find_nvpair_attr(the_cib, XML_ATTR_ID, section, node_uuid, set_type, set_name, attr_id, attr_name, FALSE, &local_attr_id); if(rc == cib_ok) { attr_id = local_attr_id; goto do_modify; @@ -214,6 +222,11 @@ } else if(node_uuid) { local_set_name = crm_concat(section, node_uuid, '-'); + if(set_type) { + char *tmp_set_name = local_set_name; + local_set_name = crm_concat(tmp_set_name, set_type, '-'); + crm_free(tmp_set_name); + } } else { local_set_name = crm_concat(section, "options", '-'); } @@ -243,6 +256,9 @@ } else { xml_obj = create_xml_node(xml_obj, XML_TAG_META_SETS); } + + } else if(set_type) { + xml_obj = create_xml_node(xml_obj, set_type); } else { xml_obj = create_xml_node(xml_obj, XML_TAG_ATTR_SETS); @@ -288,7 +304,7 @@ enum cib_errors read_attr(cib_t *the_cib, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, char **attr_value, gboolean to_console) { enum cib_errors rc = cib_ok; @@ -299,7 +315,7 @@ *attr_value = NULL; - rc = find_nvpair_attr(the_cib, XML_NVPAIR_ATTR_VALUE, section, node_uuid, set_name, attr_id, attr_name, to_console, attr_value); + rc = find_nvpair_attr(the_cib, XML_NVPAIR_ATTR_VALUE, section, node_uuid, set_type, set_name, attr_id, attr_name, to_console, attr_value); if(rc != cib_ok) { do_crm_log(LOG_DEBUG_2, "Query failed for attribute %s (section=%s, node=%s, set=%s): %s", attr_name, section, crm_str(set_name), crm_str(node_uuid), @@ -311,7 +327,7 @@ enum cib_errors delete_attr(cib_t *the_cib, int options, - const char *section, const char *node_uuid, const char *set_name, + const char *section, const char *node_uuid, const char *set_type, const char *set_name, const char *attr_id, const char *attr_name, const char *attr_value, gboolean to_console) { enum cib_errors rc = cib_ok; @@ -322,7 +338,7 @@ CRM_CHECK(attr_name != NULL || attr_id != NULL, return cib_missing); if(attr_id == NULL) { - rc = find_nvpair_attr(the_cib, XML_ATTR_ID, section, node_uuid, set_name, attr_id, attr_name, to_console, &local_attr_id); + rc = find_nvpair_attr(the_cib, XML_ATTR_ID, section, node_uuid, set_type, set_name, attr_id, attr_name, to_console, &local_attr_id); if(rc != cib_ok) { return rc; } @@ -467,7 +483,7 @@ sprintf(attr_id, "%s-%s", attr_name, uuid); } - rc = update_attr(the_cib, cib_sync_call, scope, uuid, set_name, + rc = update_attr(the_cib, cib_sync_call, scope, uuid, NULL, set_name, attr_id, attr_name, standby_value, TRUE); crm_free(attr_id); diff -r a6b66ac53fa9 -r 692f8d2fa65b tools/attrd.c --- a/tools/attrd.c Thu Mar 04 08:40:17 2010 +0100 +++ b/tools/attrd.c Thu Mar 04 17:48:01 2010 +0800 @@ -686,7 +686,7 @@ } else if(hash_entry->value == NULL) { /* delete the attr */ - rc = delete_attr(cib_conn, cib_none, hash_entry->section, attrd_uuid, + rc = delete_attr(cib_conn, cib_none, hash_entry->section, attrd_uuid, NULL, hash_entry->set, hash_entry->uuid, hash_entry->id, NULL, FALSE); if(hash_entry->stored_value) { @@ -708,7 +708,7 @@ } else { /* send update */ rc = update_attr(cib_conn, cib_none, hash_entry->section, - attrd_uuid, hash_entry->set, hash_entry->uuid, + attrd_uuid, NULL, hash_entry->set, hash_entry->uuid, hash_entry->id, hash_entry->value, FALSE); if(safe_str_neq(hash_entry->value, hash_entry->stored_value) || rc < 0) { crm_info("Sent update %d: %s=%s", rc, hash_entry->id, hash_entry->value); diff -r a6b66ac53fa9 -r 692f8d2fa65b tools/crm_attribute.c --- a/tools/crm_attribute.c Thu Mar 04 08:40:17 2010 +0100 +++ b/tools/crm_attribute.c Thu Mar 04 17:48:01 2010 +0800 @@ -52,6 +52,7 @@ const char *rsc_id = NULL; const char *attr_value = NULL; const char *attr_default = NULL; +const char *set_type = NULL; static struct crm_option long_options[] = { /* Top-level Options */ @@ -73,6 +74,7 @@ {"-spacer-", 0, 0, '-', "\t\t\tValid values: crm_config, rsc_defaults, op_defaults"}, {"lifetime", 1, 0, 'l', "Lifetime of the node attribute."}, {"-spacer-", 0, 0, '-', "\t\t\tValid values: reboot, forever"}, + {"utilization", 0, 0, 'z', "Set an utilization attribute for the node."}, {"set-name", 1, 0, 's', "(Advanced) The attribute set in which to place the value"}, {"id", 1, 0, 'i', "\t(Advanced) The ID used to identify the attribute"}, {"default", 1, 0, 'd', "(Advanced) The default value to display if none is found in the configuration"}, @@ -119,7 +121,7 @@ int option_index = 0; crm_system_name = basename(argv[0]); - crm_set_options("V?$GDQqN:U:u:s:n:v:l:t:i:!r:d:", "command -n attribute [options]", long_options, + crm_set_options("V?$GDQqN:U:u:s:n:v:l:t:zi:!r:d:", "command -n attribute [options]", long_options, "Manage node's attributes and cluster options." "\n\nAllows node attributes and cluster options to be queried, modified and deleted.\n"); @@ -165,6 +167,10 @@ case 't': type = optarg; break; + case 'z': + type = XML_CIB_TAG_NODES; + set_type = XML_TAG_UTILIZATION; + break; case 'n': attr_name = crm_strdup(optarg); break; @@ -241,7 +247,7 @@ crm_info("Update %s=%s sent via attrd", attr_name, command=='D'?"<none>":attr_value); } else if(command=='D') { - rc = delete_attr(the_cib, cib_opts, type, dest_node, set_name, + rc = delete_attr(the_cib, cib_opts, type, dest_node, set_type, set_name, attr_id, attr_name, attr_value, TRUE); if(rc == cib_NOTEXISTS) { @@ -256,7 +262,7 @@ time_t now = time(NULL); now_s = crm_itoa(now); update_attr(the_cib, cib_sync_call, - XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, + XML_CIB_TAG_CRMCONFIG, NULL, NULL, NULL, NULL, "last-lrm-refresh", now_s, TRUE); crm_free(now_s); } @@ -266,12 +272,12 @@ CRM_DEV_ASSERT(attr_name != NULL); CRM_DEV_ASSERT(attr_value != NULL); - rc = update_attr(the_cib, cib_opts, type, dest_node, set_name, + rc = update_attr(the_cib, cib_opts, type, dest_node, set_type, set_name, attr_id, attr_name, attr_value, TRUE); } else /* query */ { char *read_value = NULL; - rc = read_attr(the_cib, type, dest_node, set_name, + rc = read_attr(the_cib, type, dest_node, set_type, set_name, attr_id, attr_name, &read_value, TRUE); if(rc == cib_NOTEXISTS && attr_default) { diff -r a6b66ac53fa9 -r 692f8d2fa65b tools/crm_resource.c --- a/tools/crm_resource.c Thu Mar 04 08:40:17 2010 +0100 +++ b/tools/crm_resource.c Thu Mar 04 17:48:01 2010 +0800 @@ -269,8 +269,11 @@ if(safe_str_eq(attr_set_type, XML_TAG_ATTR_SETS)) { get_rsc_attributes(params, the_rsc, current, data_set); + } else if(safe_str_eq(attr_set_type, XML_TAG_META_SETS)) { + get_meta_attributes(params, the_rsc, current, data_set); } else { - get_meta_attributes(params, the_rsc, current, data_set); + unpack_instance_attributes(data_set->input, the_rsc->xml, XML_TAG_UTILIZATION, NULL, + params, NULL, FALSE, data_set->now); } crm_debug("Looking up %s in %s", attr, the_rsc->id); @@ -1015,6 +1018,7 @@ {"parameter-value", 1, 0, 'v', "Value to use with -p, -g or -d"}, {"lifetime", 1, 0, 'u', "\tLifespan of migration constraints\n"}, {"meta", 0, 0, 'm', "\t\tModify a resource's configuration option rather than one which is passed to the resource agent script. For use with -p, -g, -d"}, + {"utilization", 0, 0, 'z', "\tModify a resource's utilization attribute. For use with -p, -g, -d"}, {"set-name", 1, 0, 's', "\t(Advanced) ID of the instance_attributes object to change"}, {"nvpair", 1, 0, 'i', "\t(Advanced) ID of the nvpair object to change/delete"}, {"force", 0, 0, 'f', "\n" /* Is this actually true anymore? @@ -1071,7 +1075,7 @@ int flag; crm_log_init(basename(argv[0]), LOG_ERR, FALSE, FALSE, argc, argv); - crm_set_options("V?$LRQxDCPp:WMUr:H:h:v:t:p:g:d:i:s:G:S:fx:lmu:FOocqN:aA", "(query|command) [options]", long_options, + crm_set_options("V?$LRQxDCPp:WMUr:H:h:v:t:p:g:d:i:s:G:S:fx:lmzu:FOocqN:aA", "(query|command) [options]", long_options, "Perform tasks related to cluster resources.\n Allows resources to be queried (definition and location), modified, and moved around the cluster.\n"); if(argc < 2) { @@ -1101,6 +1105,9 @@ case 'm': attr_set_type = XML_TAG_META_SETS; break; + case 'z': + attr_set_type = XML_TAG_UTILIZATION; + break; case 'u': move_lifetime = crm_strdup(optarg); break;
_______________________________________________ Pacemaker mailing list Pacemaker@oss.clusterlabs.org http://oss.clusterlabs.org/mailman/listinfo/pacemaker