pacemaker/0029-Fix-crm_resource-Allow-the-resource-configuration-to.patch
Jan Pokorný dff8d9929d
1.1.13-3: Update to Pacemaker-1.1.13 post-release + patches
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2015-10-14 01:54:55 +02:00

128 lines
5.1 KiB
Diff

From: Andrew Beekhof <andrew@beekhof.net>
Date: Thu, 17 Sep 2015 09:46:38 +1000
Subject: [PATCH] Fix: crm_resource: Allow the resource configuration to be
modified for --force-{check,start,..} calls
(cherry picked from commit 1206f735a8ddb33c77152c736828e823e7755c34)
---
tools/crm_resource.c | 36 +++++++++++++++++++++++++++++++-----
tools/crm_resource.h | 2 +-
tools/crm_resource_runtime.c | 14 +++++++++++++-
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index 156bbea..2a94362 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -247,6 +247,7 @@ main(int argc, char **argv)
const char *prop_set = NULL;
const char *rsc_long_cmd = NULL;
const char *longname = NULL;
+ GHashTable *override_params = NULL;
char *xml_file = NULL;
crm_ipc_t *crmd_channel = NULL;
@@ -503,11 +504,35 @@ main(int argc, char **argv)
}
}
- if (optind < argc && argv[optind] != NULL) {
+ if (optind < argc
+ && argv[optind] != NULL
+ && rsc_cmd == 0
+ && rsc_long_cmd) {
+
+ override_params = g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str);
+ while (optind < argc && argv[optind] != NULL) {
+ char *name = calloc(1, strlen(argv[optind]));
+ char *value = calloc(1, strlen(argv[optind]));
+ int rc = sscanf(argv[optind], "%[^=]=%s", name, value);
+
+ if(rc == 2) {
+ g_hash_table_replace(override_params, name, value);
+
+ } else {
+ CMD_ERR("Error parsing '%s' as a name=value pair for --%s", argv[optind], rsc_long_cmd);
+ free(value);
+ free(name);
+ argerr++;
+ }
+ optind++;
+ }
+
+ } else if (optind < argc && argv[optind] != NULL && rsc_cmd == 0) {
CMD_ERR("non-option ARGV-elements: ");
while (optind < argc && argv[optind] != NULL) {
- CMD_ERR("%s ", argv[optind++]);
- ++argerr;
+ CMD_ERR("[%d of %d] %s ", optind, argc, argv[optind]);
+ optind++;
+ argerr++;
}
}
@@ -516,7 +541,8 @@ main(int argc, char **argv)
}
if (argerr) {
- crm_help('?', EX_USAGE);
+ CMD_ERR("Invalid option(s) supplied, use --help for valid usage");
+ return crm_exit(EX_USAGE);
}
our_pid = calloc(1, 11);
@@ -631,7 +657,7 @@ main(int argc, char **argv)
rc = wait_till_stable(timeout_ms, cib_conn);
} else if (rsc_cmd == 0 && rsc_long_cmd) { /* force-(stop|start|check) */
- rc = cli_resource_execute(rsc_id, rsc_long_cmd, cib_conn, &data_set);
+ rc = cli_resource_execute(rsc_id, rsc_long_cmd, override_params, cib_conn, &data_set);
} else if (rsc_cmd == 'A' || rsc_cmd == 'a') {
GListPtr lpc = NULL;
diff --git a/tools/crm_resource.h b/tools/crm_resource.h
index 5a206e0..d4c3b05 100644
--- a/tools/crm_resource.h
+++ b/tools/crm_resource.h
@@ -74,7 +74,7 @@ int cli_resource_search(const char *rsc, pe_working_set_t * data_set);
int cli_resource_delete(cib_t *cib_conn, crm_ipc_t * crmd_channel, const char *host_uname, resource_t * rsc, pe_working_set_t * data_set);
int cli_resource_restart(resource_t * rsc, const char *host, int timeout_ms, cib_t * cib);
int cli_resource_move(const char *rsc_id, const char *host_name, cib_t * cib, pe_working_set_t *data_set);
-int cli_resource_execute(const char *rsc_id, const char *rsc_action, cib_t * cib, pe_working_set_t *data_set);
+int cli_resource_execute(const char *rsc_id, const char *rsc_action, GHashTable *override_hash, cib_t * cib, pe_working_set_t *data_set);
int cli_resource_update_attribute(const char *rsc_id, const char *attr_set, const char *attr_id,
const char *attr_name, const char *attr_value, bool recursive,
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
index b9427bc..ce9db01 100644
--- a/tools/crm_resource_runtime.c
+++ b/tools/crm_resource_runtime.c
@@ -1297,7 +1297,7 @@ wait_till_stable(int timeout_ms, cib_t * cib)
}
int
-cli_resource_execute(const char *rsc_id, const char *rsc_action, cib_t * cib, pe_working_set_t *data_set)
+cli_resource_execute(const char *rsc_id, const char *rsc_action, GHashTable *override_hash, cib_t * cib, pe_working_set_t *data_set)
{
int rc = pcmk_ok;
svc_action_t *op = NULL;
@@ -1360,6 +1360,18 @@ cli_resource_execute(const char *rsc_id, const char *rsc_action, cib_t * cib, pe
setenv("OCF_TRACE_RA", "1", 1);
}
+ if(op && override_hash) {
+ GHashTableIter iter;
+ char *name = NULL;
+ char *value = NULL;
+
+ g_hash_table_iter_init(&iter, override_hash);
+ while (g_hash_table_iter_next(&iter, (gpointer *) & name, (gpointer *) & value)) {
+ printf("Overriding the cluser configuration for '%s' with '%s' = '%s'\n", rsc->id, name, value);
+ g_hash_table_replace(op->params, strdup(name), strdup(value));
+ }
+ }
+
if(op == NULL) {
/* Re-run but with stderr enabled so we can display a sane error message */
crm_enable_stderr(TRUE);