Skip to content

Commit d924912

Browse files
committed
Fix: Fencing: Cache metadata lookups to avoid repeated blocking during device registration
1 parent e647fec commit d924912

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

fencing/commands.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,22 +506,33 @@ parse_host_list(const char *hosts)
506506
return output;
507507
}
508508

509+
GHashTable *metadata_cache = NULL;
510+
509511
static xmlNode *
510512
get_agent_metadata(const char *agent)
511513
{
512-
stonith_t *st = stonith_api_new();
513514
xmlNode *xml = NULL;
514515
char *buffer = NULL;
515-
int rc = 0;
516516

517-
rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, 10);
518-
if (rc || !buffer) {
519-
crm_err("Could not retrieve metadata for fencing agent %s", agent);
520-
return NULL;
517+
if(metadata_cache == NULL) {
518+
metadata_cache = g_hash_table_new_full(
519+
crm_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str);
520+
}
521+
522+
buffer = g_hash_table_lookup(metadata_cache, agent);
523+
if(buffer == NULL) {
524+
stonith_t *st = stonith_api_new();
525+
int rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, 10);
526+
527+
stonith_api_delete(st);
528+
if (rc || !buffer) {
529+
crm_err("Could not retrieve metadata for fencing agent %s", agent);
530+
return NULL;
531+
}
532+
g_hash_table_replace(metadata_cache, strdup(agent), buffer);
521533
}
534+
522535
xml = string2xml(buffer);
523-
free(buffer);
524-
stonith_api_delete(st);
525536

526537
return xml;
527538
}

0 commit comments

Comments
 (0)