Skip to content

Commit

Permalink
Fix: Fencing: Cache metadata lookups to avoid repeated blocking durin…
Browse files Browse the repository at this point in the history
…g device registration
  • Loading branch information
beekhof committed Jun 4, 2014
1 parent e647fec commit d924912
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions fencing/commands.c
Expand Up @@ -506,22 +506,33 @@ parse_host_list(const char *hosts)
return output;
}

GHashTable *metadata_cache = NULL;

static xmlNode *
get_agent_metadata(const char *agent)
{
stonith_t *st = stonith_api_new();
xmlNode *xml = NULL;
char *buffer = NULL;
int rc = 0;

rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, 10);
if (rc || !buffer) {
crm_err("Could not retrieve metadata for fencing agent %s", agent);
return NULL;
if(metadata_cache == NULL) {
metadata_cache = g_hash_table_new_full(
crm_str_hash, g_str_equal, g_hash_destroy_str, g_hash_destroy_str);
}

buffer = g_hash_table_lookup(metadata_cache, agent);
if(buffer == NULL) {
stonith_t *st = stonith_api_new();
int rc = st->cmds->metadata(st, st_opt_sync_call, agent, NULL, &buffer, 10);

stonith_api_delete(st);
if (rc || !buffer) {
crm_err("Could not retrieve metadata for fencing agent %s", agent);
return NULL;
}
g_hash_table_replace(metadata_cache, strdup(agent), buffer);
}

xml = string2xml(buffer);
free(buffer);
stonith_api_delete(st);

return xml;
}
Expand Down

0 comments on commit d924912

Please sign in to comment.