diff --git a/src/pmdas/hacluster/GNUmakefile b/src/pmdas/hacluster/GNUmakefile index b9caf514a33..b3950f731ff 100644 --- a/src/pmdas/hacluster/GNUmakefile +++ b/src/pmdas/hacluster/GNUmakefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 - 2021 Red Hat. +# Copyright (c) 2020 - 2026 Red Hat. # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the @@ -68,7 +68,7 @@ $(VERSION_SCRIPT): domain.h: ../../pmns/stdpmid $(DOMAIN_MAKERULE) -pmda.o: pmdahacluster.h +pmda.o pacemaker.o corosync.o: pmdahacluster.h pmda.o pacemaker.o: pacemaker.h pmda.o corosync.o: corosync.h pmda.o sbd.o: sbd.h diff --git a/src/pmdas/hacluster/corosync.c b/src/pmdas/hacluster/corosync.c index 5549e59b9c3..7952e305677 100644 --- a/src/pmdas/hacluster/corosync.c +++ b/src/pmdas/hacluster/corosync.c @@ -1,7 +1,7 @@ /* * HA Cluster Corosync statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -21,6 +21,7 @@ #include "libpcp.h" #include "pmda.h" +#include "pmdahacluster.h" #include "corosync.h" static char *quorumtool_command; @@ -29,7 +30,7 @@ static char *cfgtool_command; static struct corosync_global global_stats; int -hacluster_corosync_node_fetch(int item, struct member_votes *node, pmAtomValue *atom) +hacluster_corosync_node_fetch(int item, struct corosync_node *node, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_COROSYNC_MEMBER_STATS) @@ -97,7 +98,7 @@ hacluster_corosync_global_fetch(int item, pmAtomValue *atom) } int -hacluster_corosync_ring_fetch(int item, struct rings *rings, pmAtomValue *atom) +hacluster_corosync_ring_fetch(int item, struct corosync_ring *rings, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_COROSYNC_RINGS_STATS) @@ -140,7 +141,128 @@ hacluster_corosync_ring_all_fetch(int item, pmAtomValue *atom) } int -hacluster_refresh_corosync_node(const char *node_name, struct member_votes *node) +hacluster_corosync_node_instance_refresh(void) +{ + int sts, node_id; + char buffer[4096], node_name[128]; + char *buffer_ptr; + FILE *pf; + pmInDom indom = hacluster_indom(COROSYNC_NODE_INDOM); + + /* + * Update indom cache based off number of nodes listed in the + * membership information section of corosync-quorumtool output + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + + pmsprintf(buffer, sizeof(buffer), "%s 2>&1", quorumtool_command); + + if ((pf = popen(buffer, "r")) == NULL) + return oserror(); + + while (fgets(buffer, sizeof(buffer)-1, pf) != NULL) { + /* Clear whitespace at start of each line */ + buffer_ptr = buffer; + while(isspace((unsigned char)*buffer_ptr)) buffer_ptr++; + + if(isdigit(buffer_ptr[0])) { + /* + * corosync-quorumtool membership information layout: + * Nodeid Votes Qdevice Name + */ + sscanf(buffer_ptr, "%d %*d %*s %s", &node_id, node_name); + + if (node_id == 0) { + memset(node_name, '\0', sizeof(node_name)); + memcpy(node_name, "Qdevice", strlen("Qdevice")); + } + + /* + * At this point node_name contains our device name this will be used to + * map stats to node instances + */ + struct corosync_node *node; + + sts = pmdaCacheLookupName(indom, node_name, NULL, (void **)&node); + if (sts == PM_ERR_INST || (sts >=0 && node == NULL)) { + node = calloc(1, sizeof(struct corosync_node)); + if (node == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + pmdaCacheStore(indom, PMDA_CACHE_ADD, node_name, (void *)node); + } + } + pclose(pf); + return(0); +} + +int +hacluster_corosync_ring_instance_refresh(void) +{ + int sts; + char buffer[4096], ring_name[128]; + FILE *pf; + pmInDom indom = hacluster_indom(COROSYNC_RING_INDOM); + pmInDom indom_all = hacluster_indom(COROSYNC_RING_ALL_INDOM); + + /* + * Update indom cache based off number of nodes listed in the + * membership information section of corosync-quorumtool output + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); + + pmsprintf(buffer, sizeof(buffer), "%s 2>&1", cfgtool_command); + + if ((pf = popen(buffer, "r")) == NULL) + return oserror(); + + while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { + + /* + * The aim is to find the id and status lines for our corresponding + * ring indom based on the ring id (ring_name) + * + * Check for the exact match that we are in the RING (corosync < v2.99) + * or LINK (corosync v2.99.0+) details section for our given ring by + * its ring id (ring_name) + */ + if (strstr(buffer, "RING ID") || strstr(buffer, "LINK ID")) { + /* Collect the ring number while are matching to our ring_name */ + sscanf(buffer, "%*s %*s %s", ring_name); + + /* + * At this point node_name contains our device name this will be used to + * map stats to node instances + */ + struct corosync_ring *ring; + + sts = pmdaCacheLookupName(indom, ring_name, NULL, (void **)&ring); + if (sts == PM_ERR_INST || (sts >=0 && ring == NULL)) { + ring = calloc(1, sizeof(struct corosync_ring)); + if (ring == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + pmdaCacheStore(indom, PMDA_CACHE_ADD, ring_name, (void *)ring); + pmdaCacheStore(indom_all, PMDA_CACHE_ADD, ring_name, NULL); + } + } + pclose(pf); + return(0); +} + +int +hacluster_refresh_corosync_node(const char *node_name, struct corosync_node *node) { char buffer[4096], local[8]; char *buffer_ptr; @@ -240,7 +362,7 @@ hacluster_refresh_corosync_global() } int -hacluster_refresh_corosync_ring(const char *ring_name, struct rings *rings) +hacluster_refresh_corosync_ring(const char *ring_name, struct corosync_ring *rings) { char buffer[4096]; char *buffer_ptr; diff --git a/src/pmdas/hacluster/corosync.h b/src/pmdas/hacluster/corosync.h index 11c3b3b4577..a2385b18010 100644 --- a/src/pmdas/hacluster/corosync.h +++ b/src/pmdas/hacluster/corosync.h @@ -1,7 +1,7 @@ /* * HA Cluster Corosync statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -43,7 +43,7 @@ enum { NUM_COROSYNC_RINGS_STATS }; -struct member_votes { +struct corosync_node { uint32_t votes; uint8_t local; uint64_t node_id; @@ -58,7 +58,7 @@ struct corosync_global { uint32_t ring_errors; }; -struct rings { +struct corosync_ring { uint8_t status; char address[40]; uint64_t node_id; @@ -66,15 +66,17 @@ struct rings { char ring_id[44]; }; -extern int hacluster_corosync_node_fetch(int, struct member_votes *, pmAtomValue *); -extern int hacluster_refresh_corosync_node(const char *, struct member_votes *); +extern int hacluster_corosync_node_fetch(int, struct corosync_node *, pmAtomValue *); +extern int hacluster_refresh_corosync_node(const char *, struct corosync_node *); +extern int hacluster_corosync_node_instance_refresh(void); extern int hacluster_corosync_global_fetch(int, pmAtomValue *); extern int hacluster_refresh_corosync_global(); -extern int hacluster_corosync_ring_fetch(int, struct rings *, pmAtomValue *); +extern int hacluster_corosync_ring_fetch(int, struct corosync_ring *, pmAtomValue *); extern int hacluster_corosync_ring_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_corosync_ring(const char *, struct rings *); +extern int hacluster_refresh_corosync_ring(const char *, struct corosync_ring *); +extern int hacluster_corosync_ring_instance_refresh(void); extern void corosync_stats_setup(void); diff --git a/src/pmdas/hacluster/drbd.c b/src/pmdas/hacluster/drbd.c index 6f1e2cffbb6..fed4590eac8 100644 --- a/src/pmdas/hacluster/drbd.c +++ b/src/pmdas/hacluster/drbd.c @@ -1,7 +1,7 @@ /* * HA Cluster DRDB statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -27,7 +27,7 @@ static char *drbdsetup_command; static char *split_brain_path; int -hacluster_drbd_resource_fetch(int item, struct resource *resource, pmAtomValue *atom) +hacluster_drbd_resource_fetch(int item, struct drbd_resource *resource, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_DRBD_RESOURCE_STATS) @@ -98,7 +98,7 @@ hacluster_drbd_resource_all_fetch(int item, pmAtomValue *atom) } int -hacluster_drbd_peer_device_fetch(int item, struct peer_device *peer_device, pmAtomValue *atom) +hacluster_drbd_peer_device_fetch(int item, struct drbd_peer_device *peer_device, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_DRBD_PEER_DEVICE_STATS) @@ -161,7 +161,7 @@ hacluster_drbd_peer_device_all_fetch(int item, pmAtomValue *atom) } int -hacluster_refresh_drbd_resource(const char *resource_name, struct resource *resource) +hacluster_refresh_drbd_resource(const char *resource_name, struct drbd_resource *resource) { char buffer[4096]; char *node, *volume; @@ -277,7 +277,7 @@ hacluster_refresh_drbd_resource(const char *resource_name, struct resource *reso } int -hacluster_refresh_drbd_peer_device(const char *peer_name, struct peer_device *peer_device) +hacluster_refresh_drbd_peer_device(const char *peer_name, struct drbd_peer_device *peer_device) { char buffer[4096]; char *node, *peer_node_id; diff --git a/src/pmdas/hacluster/drbd.h b/src/pmdas/hacluster/drbd.h index aa7e7b222cd..6a666a46b38 100644 --- a/src/pmdas/hacluster/drbd.h +++ b/src/pmdas/hacluster/drbd.h @@ -1,7 +1,7 @@ /* * HA Cluster DRDB statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -54,7 +54,7 @@ enum { NUM_DRBD_PEER_DEVICE_STATS }; -struct resource { +struct drbd_resource { char resource[128]; char role[10]; char volume[128]; @@ -69,7 +69,7 @@ struct resource { uint8_t split_brain; }; -struct peer_device { +struct drbd_peer_device { char resource[128]; char peer_node_id[128]; char peer_role[10]; @@ -82,13 +82,13 @@ struct peer_device { uint32_t connections_unacked; }; -extern int hacluster_drbd_resource_fetch(int, struct resource *, pmAtomValue *); +extern int hacluster_drbd_resource_fetch(int, struct drbd_resource *, pmAtomValue *); extern int hacluster_drbd_resource_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_drbd_resource(const char *, struct resource *); +extern int hacluster_refresh_drbd_resource(const char *, struct drbd_resource *); -extern int hacluster_drbd_peer_device_fetch(int, struct peer_device *, pmAtomValue *); +extern int hacluster_drbd_peer_device_fetch(int, struct drbd_peer_device *, pmAtomValue *); extern int hacluster_drbd_peer_device_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_drbd_peer_device(const char *, struct peer_device *); +extern int hacluster_refresh_drbd_peer_device(const char *, struct drbd_peer_device *); extern void drbd_stats_setup(void); diff --git a/src/pmdas/hacluster/pacemaker.c b/src/pmdas/hacluster/pacemaker.c index 6c4deefc652..6952936e5cf 100644 --- a/src/pmdas/hacluster/pacemaker.c +++ b/src/pmdas/hacluster/pacemaker.c @@ -1,7 +1,7 @@ /* * HA Cluster Pacemaker statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -18,6 +18,7 @@ #include "libpcp.h" #include "pmda.h" +#include "pmdahacluster.h" #include "pacemaker.h" #include @@ -166,7 +167,7 @@ hacluster_pacemaker_global_fetch(int item, pmAtomValue *atom) } int -hacluster_pacemaker_fail_fetch(int item, struct fail_count *fail_count, pmAtomValue *atom) +hacluster_pacemaker_fail_fetch(int item, struct pacemaker_fail *fail_count, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_PACEMAKER_FAIL_STATS) @@ -190,7 +191,7 @@ hacluster_pacemaker_fail_fetch(int item, struct fail_count *fail_count, pmAtomVa } int -hacluster_pacemaker_constraints_fetch(int item, struct location_constraints *locations_constraints, pmAtomValue *atom) +hacluster_pacemaker_constraints_fetch(int item, struct pacemaker_constraints *locations_constraints, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_PACEMAKER_CONSTRAINTS_STATS) @@ -229,7 +230,7 @@ hacluster_pacemaker_constraints_all_fetch(int item, pmAtomValue *atom) } int -hacluster_pacemaker_nodes_fetch(int item, struct nodes *nodes, pmAtomValue *atom) +hacluster_pacemaker_nodes_fetch(int item, struct pacemaker_nodes *nodes, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_PACEMAKER_NODES_STATS) @@ -293,7 +294,7 @@ hacluster_pacemaker_nodes_fetch(int item, struct nodes *nodes, pmAtomValue *atom } int -hacluster_pacemaker_node_attribs_fetch(int item, struct attributes *attributes, pmAtomValue *atom) +hacluster_pacemaker_node_attribs_fetch(int item, struct pacemaker_node_attrib *attributes, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_PACEMAKER_NODE_ATTRIB_STATS) @@ -320,7 +321,7 @@ hacluster_pacemaker_node_attribs_all_fetch(int item, pmAtomValue *atom) } int -hacluster_pacemaker_resources_fetch(int item, struct resources *resources, pmAtomValue *atom) +hacluster_pacemaker_resources_fetch(int item, struct pacemaker_resources *resources, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_PACEMAKER_RESOURCES_STATS) @@ -424,28 +425,26 @@ hacluster_refresh_pacemaker_global() } int -hacluster_refresh_pacemaker_fail(const char *instance_name, struct fail_count *fail_count) +hacluster_pacemaker_fail_instance_refresh(void) { - char buffer[4096]; - char *node, *resource_id, *tofree, *str; - int found_node_history = 0, found_node_name = 0; - FILE *pf; + int sts; + char buffer[4096], instance_name[256], node_name[128], resource_name[127]; + int found_node_history = 0, found_node_name = 0; + FILE *pf; + pmInDom indom = hacluster_indom(PACEMAKER_FAIL_INDOM); + + /* + * Update indom cache based off the reading of crm_mon listed in + * the output from crm_mon + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); if ((pf = popen(buffer, "r")) == NULL) - return -oserror(); - - /* - * We need to split our combined NODE:RESOURCE_ID instance names into their - * separated NODE and RESOURCE_ID fields for matching in the output - */ - tofree = str = strdup(instance_name); - node = strsep(&str, ":"); - resource_id = strsep(&str, ":"); + return oserror(); while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ if (strstr(buffer, "")) { found_node_history = 1; @@ -453,7 +452,8 @@ hacluster_refresh_pacemaker_fail(const char *instance_name, struct fail_count *f } /* Find the node name for our resource */ - if (strstr(buffer, "node name=") && strstr(buffer, node) && found_node_history ) { + if (strstr(buffer, "node name=") && found_node_history ) { + sscanf(buffer, "\t", node_name); found_node_name = 1; continue; } @@ -465,32 +465,67 @@ hacluster_refresh_pacemaker_fail(const char *instance_name, struct fail_count *f } /* Record our instance as node:resource-id and assign */ - if (strstr(buffer, "resource_history id=") && strstr(buffer, resource_id) && found_node_name) { - sscanf(buffer, "%*s %*s %*s migration-threshold=\"%"SCNu64"\" fail-count=\"%"SCNu64"\"", - &fail_count->migration_threshold, - &fail_count->fail_count - ); + if (found_node_history && found_node_name) { + + if (strstr(buffer, "resource_history id=")) { + sscanf(buffer, "\t=0 && fail == NULL)) { + fail = calloc(1, sizeof(struct pacemaker_fail)); + if (fail == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + sscanf(buffer, "%*s %*s %*s migration-threshold=\"%"SCNu64"\" fail-count=\"%"SCNu64"\"", + &fail->migration_threshold, + &fail->fail_count + ); + + pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)fail); + } } } - pclose(pf); - free(tofree); + pclose(pf); return 0; } int -hacluster_refresh_pacemaker_constraints(const char *constraints_name, struct location_constraints *location_constraints) +hacluster_pacemaker_constraints_instance_refresh(void) { - char buffer[4096]; - int found_constraints = 0; - FILE *pf; + int sts; + char buffer[4096], constraint_name[256]; + int found_constraints = 0; + FILE *pf; + pmInDom indom = hacluster_indom(PACEMAKER_CONSTRAINTS_INDOM); + pmInDom indom_all = hacluster_indom(PACEMAKER_CONSTRAINTS_ALL_INDOM); + + /* + * Update indom cache based off the reading of cibadmin listed in + * the output from cibadmin + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); pmsprintf(buffer, sizeof(buffer), "%s 2>&1", cibadmin_command); + buffer[sizeof(buffer)-1] = '\0'; if ((pf = popen(buffer, "r")) == NULL) - return -oserror(); + return oserror(); while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ if (strstr(buffer, "")) { found_constraints = 1; @@ -498,36 +533,61 @@ hacluster_refresh_pacemaker_constraints(const char *constraints_name, struct loc } /* Find the node name for our resource */ - if (strstr(buffer, "rsc_location id=") && strstr(buffer, constraints_name) && found_constraints) { + if (strstr(buffer, "rsc_location id=") && found_constraints) { + sscanf(buffer, "\t=0 && constraints == NULL)) { + constraints = calloc(1, sizeof(struct pacemaker_constraints)); + if (constraints == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + sscanf(buffer, "%*s %*s rsc=\"%[^\"]\" role=\"%[^\"]\" node=\"%[^\"]\" score=\"%[^\"]\"", - location_constraints->resource, - location_constraints->role, - location_constraints->node, - location_constraints->score + constraints->resource, + constraints->role, + constraints->node, + constraints->score ); - } + + pmdaCacheStore(indom, PMDA_CACHE_ADD, constraint_name, (void *)constraints); + pmdaCacheStore(indom_all, PMDA_CACHE_ADD, constraint_name, NULL); + } } pclose(pf); return 0; } int -hacluster_refresh_pacemaker_nodes(const char *node_name, struct nodes *nodes) +hacluster_pacemaker_nodes_instance_refresh(void) { - char buffer[4096]; - int found_nodes = 0; - FILE *pf; + int sts; + char buffer[4096], node_name[256]; + int found_nodes = 0; + FILE *pf; + pmInDom indom = hacluster_indom(PACEMAKER_NODES_INDOM); char online[10], standby[10], standby_on_fail[10], maintenance[10], pending[10]; char unclean[10], shutdown[10], expected_up[10], dc[10]; + /* + * Update indom cache based off the reading of crm_mon listed in + * the output from crm_mon + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); if ((pf = popen(buffer, "r")) == NULL) - return -oserror(); + return oserror(); while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ if (strstr(buffer, "")) { found_nodes = 1; @@ -541,46 +601,65 @@ hacluster_refresh_pacemaker_nodes(const char *node_name, struct nodes *nodes) } /* Collect our node names */ - if (found_nodes && strstr(buffer, node_name)) { - if(strstr(buffer, "feature_set")) { - sscanf(buffer, "%*s %*s %*s online=\"%9[^\"]\" standby=\"%9[^\"]\" standby_onfail=\"%9[^\"]\" maintenance=\"%9[^\"]\" pending=\"%9[^\"]\" unclean=\"%9[^\"]\" health=\"%9[^\"]\" feature_set =\"%9[^\"]\" shutdown=\"%9[^\"]\" expected_up=\"%9[^\"]\" is_dc =\"%9[^\"]\" %*s type=\"%6[^\"]\"", - online, - standby, - standby_on_fail, - maintenance, - pending, - unclean, - nodes->health, - nodes->feature_set, - shutdown, - expected_up, - dc, - nodes->type - ); - } else { - sscanf(buffer, "%*s %*s %*s online=\"%9[^\"]\" standby=\"%9[^\"]\" standby_onfail=\"%9[^\"]\" maintenance=\"%9[^\"]\" pending=\"%9[^\"]\" unclean=\"%9[^\"]\" shutdown=\"%9[^\"]\" expected_up=\"%9[^\"]\" is_dc =\"%9[^\"]\" %*s type=\"%6[^\"]\"", - online, - standby, - standby_on_fail, - maintenance, - pending, - unclean, - shutdown, - expected_up, - dc, - nodes->type - ); - } + if (found_nodes) { + if (strstr(buffer, "node name=")) { + sscanf(buffer, "\t=0 && pace_nodes == NULL)) { + pace_nodes = calloc(1, sizeof(struct pacemaker_nodes)); + if (pace_nodes == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + if(strstr(buffer, "feature_set")) { + sscanf(buffer, "%*s %*s %*s online=\"%9[^\"]\" standby=\"%9[^\"]\" standby_onfail=\"%9[^\"]\" maintenance=\"%9[^\"]\" pending=\"%9[^\"]\" unclean=\"%9[^\"]\" health=\"%9[^\"]\" feature_set =\"%9[^\"]\" shutdown=\"%9[^\"]\" expected_up=\"%9[^\"]\" is_dc =\"%9[^\"]\" %*s type=\"%6[^\"]\"", + online, + standby, + standby_on_fail, + maintenance, + pending, + unclean, + pace_nodes->health, + pace_nodes->feature_set, + shutdown, + expected_up, + dc, + pace_nodes->type + ); + } else { + sscanf(buffer, "%*s %*s %*s online=\"%9[^\"]\" standby=\"%9[^\"]\" standby_onfail=\"%9[^\"]\" maintenance=\"%9[^\"]\" pending=\"%9[^\"]\" unclean=\"%9[^\"]\" shutdown=\"%9[^\"]\" expected_up=\"%9[^\"]\" is_dc =\"%9[^\"]\" %*s type=\"%6[^\"]\"", + online, + standby, + standby_on_fail, + maintenance, + pending, + unclean, + shutdown, + expected_up, + dc, + pace_nodes->type + ); + } - nodes->online = bool_convert(online); - nodes->standby = bool_convert(standby); - nodes->standby_on_fail = bool_convert(standby_on_fail); - nodes->maintenance = bool_convert(maintenance); - nodes->pending = bool_convert(pending); - nodes->unclean = bool_convert(unclean); - nodes->shutdown = bool_convert(shutdown); - nodes->expected_up = bool_convert(expected_up); - nodes->dc = bool_convert(dc); + pace_nodes->online = bool_convert(online); + pace_nodes->standby = bool_convert(standby); + pace_nodes->standby_on_fail = bool_convert(standby_on_fail); + pace_nodes->maintenance = bool_convert(maintenance); + pace_nodes->pending = bool_convert(pending); + pace_nodes->unclean = bool_convert(unclean); + pace_nodes->shutdown = bool_convert(shutdown); + pace_nodes->expected_up = bool_convert(expected_up); + pace_nodes->dc = bool_convert(dc); + + pmdaCacheStore(indom, PMDA_CACHE_ADD, node_name, (void *)pace_nodes); + } } } pclose(pf); @@ -588,28 +667,28 @@ hacluster_refresh_pacemaker_nodes(const char *node_name, struct nodes *nodes) } int -hacluster_refresh_pacemaker_node_attribs(const char *attrib_name, struct attributes *attributes) +hacluster_pacemaker_node_attrib_instance_refresh(void) { - char buffer[4096]; - char *node_name, *attribute_name, *tofree, *str; - int found_node_attributes = 0, found_node_name = 0; - FILE *pf; + int sts; + char buffer[4096], node_name[128], attribute_name[127], instance_name[256]; + int found_node_attributes = 0, found_node_name = 0; + FILE *pf; + pmInDom indom = hacluster_indom(PACEMAKER_NODE_ATTRIB_INDOM); + pmInDom indom_all = hacluster_indom(PACEMAKER_NODE_ATTRIB_ALL_INDOM); + + /* + * Update indom cache based off the reading of crm_mon listed in + * the output from crm_mon + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); if ((pf = popen(buffer, "r")) == NULL) - return -oserror(); - - /* - * We need to split our combined NODE:ATTRIBUTE_NAME instance names into their - * separated NODE and ATTRIBUTE_NAME fields for matching in the output - */ - tofree = str = strdup(attrib_name); - node_name = strsep(&str, ":"); - attribute_name = strsep(&str, ":"); + return oserror(); while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ if (strstr(buffer, "")) { found_node_attributes = 1; @@ -623,7 +702,8 @@ hacluster_refresh_pacemaker_node_attribs(const char *attrib_name, struct attribu } /* Find the node name for our node */ - if (strstr(buffer, "node name=") && strstr(buffer, node_name) && found_node_attributes ) { + if (strstr(buffer, "node name=") && found_node_attributes ) { + sscanf(buffer, "\tvalue); + if (found_node_attributes && found_node_name) { + + if (strstr(buffer, "attribute name=")) { + sscanf(buffer, "\t=0 && node_attrib == NULL)) { + node_attrib = calloc(1, sizeof(struct pacemaker_node_attrib)); + if (node_attrib == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + sscanf(buffer, "%*s %*s value=\"%[^\"]\"", node_attrib->value); + + pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)node_attrib); + pmdaCacheStore(indom_all, PMDA_CACHE_ADD, instance_name, NULL); + } + } + } + pclose(pf); + return 0; +} + +int +hacluster_pacemaker_resources_instance_refresh(void) +{ + int sts; + char buffer[4096], resource_id[128] = {'\0'}, node_name[127] = {'\0'}, instance_name[256]; + int found_resources = 0; + FILE *pf; + pmInDom indom= hacluster_indom(PACEMAKER_RESOURCES_INDOM); + pmInDom indom_all = hacluster_indom(PACEMAKER_RESOURCES_ALL_INDOM); + + /* + * Update indom cache based off the reading of crm_mon listed in + * the output from crm_mon + */ + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); + + pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); + + if ((pf = popen(buffer, "r")) == NULL) + return oserror(); + + while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { + /* First we need to check whether we are in section*/ + if (strstr(buffer, "")) { + found_resources = 1; + continue; + } + + /* Check to see if we pass in clones */ + if (strstr(buffer, "")) { + found_resources = 0; + continue; + } + + /* Record our instance as node:resource-id and assign */ + if (found_resources) { + + if (strstr(buffer, "resource id=")) { + sscanf(buffer, "\t")) { + /* + * Assign indom based upon our resource_name:node_id by joining our node_name + * with our volume number but only if we have both a resource name and a node_id + */ + if (node_name[0] == '\0') { + snprintf(instance_name, sizeof(instance_name), "%s", resource_id); + } else { + snprintf(instance_name, sizeof(instance_name), "%s:%s", resource_id, node_name); + } + + struct pacemaker_resources *pace_resources; + + sts = pmdaCacheLookupName(indom, instance_name, NULL, (void **)&pace_resources); + if (sts == PM_ERR_INST || (sts >=0 && pace_resources == NULL)) { + pace_resources = calloc(1, sizeof(struct pacemaker_resources)); + if (pace_resources == NULL) { + pclose(pf); + return PM_ERR_AGAIN; + } + } + else if (sts < 0) + continue; + + pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)pace_resources); + pmdaCacheStore(indom_all, PMDA_CACHE_ADD, instance_name, NULL); + + /* Clear node name in the event that a resource has not got a node attachment */ + memset(node_name, '\0', sizeof(node_name)); + } } } pclose(pf); - free(tofree); return 0; } int -hacluster_refresh_pacemaker_resources(const char *instance_name, struct resources *resources) +hacluster_refresh_pacemaker_resources(const char *instance_name, struct pacemaker_resources *resources) { char buffer[4096]; char *node, *resource_id, *tofree, *str; diff --git a/src/pmdas/hacluster/pacemaker.h b/src/pmdas/hacluster/pacemaker.h index 9f741b80098..5120cb7aa2f 100644 --- a/src/pmdas/hacluster/pacemaker.h +++ b/src/pmdas/hacluster/pacemaker.h @@ -1,7 +1,7 @@ /* * HA Cluster Pacemaker statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -78,19 +78,19 @@ struct pacemaker_global { uint8_t stonith_enabled; }; -struct fail_count { +struct pacemaker_fail { uint64_t fail_count; uint64_t migration_threshold; }; -struct location_constraints { +struct pacemaker_constraints { char node[128]; char resource[128]; char role[18]; char score[10]; }; -struct nodes { +struct pacemaker_nodes { uint8_t online; uint8_t standby; uint8_t standby_on_fail; @@ -105,11 +105,11 @@ struct nodes { char feature_set[64]; }; -struct attributes { +struct pacemaker_node_attrib { char value[256]; }; -struct resources { +struct pacemaker_resources { char agent[128]; char clone[128]; char group[128]; @@ -125,23 +125,24 @@ struct resources { extern int hacluster_pacemaker_global_fetch(int, pmAtomValue *); extern int hacluster_refresh_pacemaker_global(); -extern int hacluster_pacemaker_fail_fetch(int, struct fail_count *, pmAtomValue *); -extern int hacluster_refresh_pacemaker_fail(const char *, struct fail_count *); +extern int hacluster_pacemaker_fail_fetch(int, struct pacemaker_fail *, pmAtomValue *); +extern int hacluster_pacemaker_fail_instance_refresh(void); -extern int hacluster_pacemaker_constraints_fetch(int, struct location_constraints *, pmAtomValue *); +extern int hacluster_pacemaker_constraints_fetch(int, struct pacemaker_constraints *, pmAtomValue *); extern int hacluster_pacemaker_constraints_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_pacemaker_constraints(const char *, struct location_constraints *); +extern int hacluster_pacemaker_constraints_instance_refresh(void); -extern int hacluster_pacemaker_nodes_fetch(int, struct nodes *, pmAtomValue *); -extern int hacluster_refresh_pacemaker_nodes(const char *, struct nodes *); +extern int hacluster_pacemaker_nodes_fetch(int, struct pacemaker_nodes *, pmAtomValue *); +extern int hacluster_pacemaker_nodes_instance_refresh(void); -extern int hacluster_pacemaker_node_attribs_fetch(int, struct attributes *, pmAtomValue *); +extern int hacluster_pacemaker_node_attribs_fetch(int, struct pacemaker_node_attrib *, pmAtomValue *); extern int hacluster_pacemaker_node_attribs_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_pacemaker_node_attribs(const char *, struct attributes *); +extern int hacluster_pacemaker_node_attrib_instance_refresh(void); -extern int hacluster_pacemaker_resources_fetch(int, struct resources *, pmAtomValue *); +extern int hacluster_pacemaker_resources_fetch(int, struct pacemaker_resources *, pmAtomValue *); extern int hacluster_pacemaker_resources_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_pacemaker_resources(const char *, struct resources *); +extern int hacluster_pacemaker_resources_instance_refresh(void); +extern int hacluster_refresh_pacemaker_resources(const char *, struct pacemaker_resources *); extern void pacemaker_stats_setup(void); diff --git a/src/pmdas/hacluster/pmda.c b/src/pmdas/hacluster/pmda.c index 179068dfb7e..09cfc321d96 100644 --- a/src/pmdas/hacluster/pmda.c +++ b/src/pmdas/hacluster/pmda.c @@ -1,7 +1,7 @@ /* * High Available (HA) Cluster PMDA * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -51,7 +51,11 @@ pmdaIndom indomtable[] = { { .it_indom = DRBD_PEER_DEVICE_ALL_INDOM}, }; -#define INDOM(x) (indomtable[x].it_indom) +pmInDom +hacluster_indom(int serial) +{ + return indomtable[serial].it_indom; +} /* * All metrics supported by this PMDA - one table entry for each metric @@ -393,478 +397,6 @@ metrictable_size(void) return sizeof(metrictable)/sizeof(metrictable[0]); } -int -hacluster_pacemaker_fail_instance_refresh(void) -{ - int sts; - char buffer[4096], instance_name[256], node_name[128], resource_name[127]; - int found_node_history = 0, found_node_name = 0; - FILE *pf; - pmInDom indom = INDOM(PACEMAKER_FAIL_INDOM); - - /* - * Update indom cache based off the reading of crm_mon listed in - * the output from crm_mon - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ - if (strstr(buffer, "")) { - found_node_history = 1; - continue; - } - - /* Find the node name for our resource */ - if (strstr(buffer, "node name=") && found_node_history ) { - sscanf(buffer, "\t", node_name); - found_node_name = 1; - continue; - } - - /* Check for when we overrun to another node */ - if (strstr(buffer, "")) { - found_node_name = 0; - continue; - } - - /* Record our instance as node:resource-id and assign */ - if (found_node_history && found_node_name) { - - if (strstr(buffer, "resource_history id=")) { - sscanf(buffer, "\t=0 && fail == NULL)) { - fail = calloc(1, sizeof(struct pacemaker_fail)); - if (fail == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)fail); - } - } - } - pclose(pf); - return 0; -} - -int -hacluster_pacemaker_constraints_instance_refresh(void) -{ - int sts; - char buffer[4096], constraint_name[256]; - int found_constraints = 0; - FILE *pf; - pmInDom indom = INDOM(PACEMAKER_CONSTRAINTS_INDOM); - pmInDom indom_all = INDOM(PACEMAKER_CONSTRAINTS_ALL_INDOM); - - /* - * Update indom cache based off the reading of cibadmin listed in - * the output from cibadmin - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", cibadmin_command); - buffer[sizeof(buffer)-1] = '\0'; - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ - if (strstr(buffer, "")) { - found_constraints = 1; - continue; - } - - /* Find the node name for our resource */ - if (strstr(buffer, "rsc_location id=") && found_constraints) { - sscanf(buffer, "\t=0 && constraints == NULL)) { - constraints = calloc(1, sizeof(struct pacemaker_constraints)); - if (constraints == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, constraint_name, (void *)constraints); - pmdaCacheStore(indom_all, PMDA_CACHE_ADD, constraint_name, NULL); - } - } - pclose(pf); - return 0; -} - -int -hacluster_pacemaker_nodes_instance_refresh(void) -{ - int sts; - char buffer[4096], node_name[256]; - int found_nodes = 0; - FILE *pf; - pmInDom indom = INDOM(PACEMAKER_NODES_INDOM); - - /* - * Update indom cache based off the reading of crm_mon listed in - * the output from crm_mon - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ - if (strstr(buffer, "")) { - found_nodes = 1; - continue; - } - - /* Check to see if we overun section */ - if (strstr(buffer, "")) { - found_nodes = 0; - continue; - } - - /* Collect our node names */ - if (found_nodes) { - if (strstr(buffer, "node name=")) { - sscanf(buffer, "\t=0 && pace_nodes == NULL)) { - pace_nodes = calloc(1, sizeof(struct pacemaker_nodes)); - if (pace_nodes == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, node_name, (void *)pace_nodes); - } - } - } - pclose(pf); - return 0; -} - -int -hacluster_pacemaker_node_attrib_instance_refresh(void) -{ - int sts; - char buffer[4096], node_name[128], attribute_name[127], instance_name[256]; - int found_node_attributes = 0, found_node_name = 0; - FILE *pf; - pmInDom indom = INDOM(PACEMAKER_NODE_ATTRIB_INDOM); - pmInDom indom_all = INDOM(PACEMAKER_NODE_ATTRIB_ALL_INDOM); - - /* - * Update indom cache based off the reading of crm_mon listed in - * the output from crm_mon - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ - if (strstr(buffer, "")) { - found_node_attributes = 1; - continue; - } - - /* Check to see if we pass */ - if (strstr(buffer, "")) { - found_node_attributes = 0; - continue; - } - - /* Find the node name for our node */ - if (strstr(buffer, "node name=") && found_node_attributes ) { - sscanf(buffer, "\t")) { - found_node_name = 0; - continue; - } - - /* Record our instance as node:resource-id and assign */ - if (found_node_attributes && found_node_name) { - - if (strstr(buffer, "attribute name=")) { - sscanf(buffer, "\t=0 && node_attrib == NULL)) { - node_attrib = calloc(1, sizeof(struct pacemaker_node_attrib)); - if (node_attrib == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)node_attrib); - pmdaCacheStore(indom_all, PMDA_CACHE_ADD, instance_name, NULL); - } - } - } - pclose(pf); - return 0; -} - -int -hacluster_pacemaker_resources_instance_refresh(void) -{ - int sts; - char buffer[4096], resource_id[128] = {'\0'}, node_name[127] = {'\0'}, instance_name[256]; - int found_resources = 0; - FILE *pf; - pmInDom indom= INDOM(PACEMAKER_RESOURCES_INDOM); - pmInDom indom_all = INDOM(PACEMAKER_RESOURCES_ALL_INDOM); - - /* - * Update indom cache based off the reading of crm_mon listed in - * the output from crm_mon - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", crm_mon_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* First we need to check whether we are in section*/ - if (strstr(buffer, "")) { - found_resources = 1; - continue; - } - - /* Check to see if we pass in clones */ - if (strstr(buffer, "")) { - found_resources = 0; - continue; - } - - /* Record our instance as node:resource-id and assign */ - if (found_resources) { - - if (strstr(buffer, "resource id=")) { - sscanf(buffer, "\t")) { - /* - * Assign indom based upon our resource_name:node_id by joining our node_name - * with our volume number but only if we have both a resource name and a node_id - */ - if (node_name[0] == '\0') { - snprintf(instance_name, sizeof(instance_name), "%s", resource_id); - } else { - snprintf(instance_name, sizeof(instance_name), "%s:%s", resource_id, node_name); - } - - struct pacemaker_resources *pace_resources; - - sts = pmdaCacheLookupName(indom, instance_name, NULL, (void **)&pace_resources); - if (sts == PM_ERR_INST || (sts >=0 && pace_resources == NULL)) { - pace_resources = calloc(1, sizeof(struct pacemaker_resources)); - if (pace_resources == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, instance_name, (void *)pace_resources); - pmdaCacheStore(indom_all, PMDA_CACHE_ADD, instance_name, NULL); - - /* Clear node name in the event that a resource has not got a node attachment */ - memset(node_name, '\0', sizeof(node_name)); - } - } - } - pclose(pf); - return 0; -} - -int -hacluster_corosync_node_instance_refresh(void) -{ - int sts, node_id; - char buffer[4096], node_name[128]; - char *buffer_ptr; - FILE *pf; - pmInDom indom = INDOM(COROSYNC_NODE_INDOM); - - /* - * Update indom cache based off number of nodes listed in the - * membership information section of corosync-quorumtool output - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", quorumtool_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while (fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - /* Clear whitespace at start of each line */ - buffer_ptr = buffer; - while(isspace((unsigned char)*buffer_ptr)) buffer_ptr++; - - if(isdigit(buffer_ptr[0])) { - /* - * corosync-quorumtool membership information layout: - * Nodeid Votes Qdevice Name - */ - sscanf(buffer_ptr, "%d %*d %*s %s", &node_id, node_name); - - if (node_id == 0) { - memset(node_name, '\0', sizeof(node_name)); - memcpy(node_name, "Qdevice", strlen("Qdevice")); - } - - /* - * At this point node_name contains our device name this will be used to - * map stats to node instances - */ - struct corosync_node *node; - - sts = pmdaCacheLookupName(indom, node_name, NULL, (void **)&node); - if (sts == PM_ERR_INST || (sts >=0 && node == NULL)) { - node = calloc(1, sizeof(struct corosync_node)); - if (node == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, node_name, (void *)node); - } - } - pclose(pf); - return(0); -} - -static int -hacluster_corosync_ring_instance_refresh(void) -{ - int sts; - char buffer[4096], ring_name[128]; - FILE *pf; - pmInDom indom = INDOM(COROSYNC_RING_INDOM); - pmInDom indom_all = INDOM(COROSYNC_RING_ALL_INDOM); - - /* - * Update indom cache based off number of nodes listed in the - * membership information section of corosync-quorumtool output - */ - pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); - pmdaCacheOp(indom_all, PMDA_CACHE_INACTIVE); - - pmsprintf(buffer, sizeof(buffer), "%s 2>&1", cfgtool_command); - - if ((pf = popen(buffer, "r")) == NULL) - return oserror(); - - while(fgets(buffer, sizeof(buffer)-1, pf) != NULL) { - - /* - * The aim is to find the id and status lines for our corresponding - * ring indom based on the ring id (ring_name) - * - * Check for the exact match that we are in the RING (corosync < v2.99) - * or LINK (corosync v2.99.0+) details section for our given ring by - * its ring id (ring_name) - */ - if (strstr(buffer, "RING ID") || strstr(buffer, "LINK ID")) { - /* Collect the ring number while are matching to our ring_name */ - sscanf(buffer, "%*s %*s %s", ring_name); - - /* - * At this point node_name contains our device name this will be used to - * map stats to node instances - */ - struct corosync_ring *ring; - - sts = pmdaCacheLookupName(indom, ring_name, NULL, (void **)&ring); - if (sts == PM_ERR_INST || (sts >=0 && ring == NULL)) { - ring = calloc(1, sizeof(struct corosync_ring)); - if (ring == NULL) { - pclose(pf); - return PM_ERR_AGAIN; - } - } - else if (sts < 0) - continue; - - pmdaCacheStore(indom, PMDA_CACHE_ADD, ring_name, (void *)ring); - pmdaCacheStore(indom_all, PMDA_CACHE_ADD, ring_name, NULL); - } - } - pclose(pf); - return(0); -} - static int hacluster_sbd_device_instance_refresh(void) { @@ -873,8 +405,8 @@ hacluster_sbd_device_instance_refresh(void) char *token; char *buffer_ptr; FILE *fp; - pmInDom indom = INDOM(SBD_DEVICE_INDOM); - pmInDom indom_all = INDOM(SBD_DEVICE_ALL_INDOM); + pmInDom indom = hacluster_indom(SBD_DEVICE_INDOM); + pmInDom indom_all = hacluster_indom(SBD_DEVICE_ALL_INDOM); /* * Update indom cache based off number of nodes listed in the @@ -947,8 +479,8 @@ hacluster_drbd_resource_instance_refresh(void) int volume; char *buffer_ptr; FILE *pf; - pmInDom indom = INDOM(DRBD_RESOURCE_INDOM); - pmInDom indom_all = INDOM(DRBD_RESOURCE_ALL_INDOM); + pmInDom indom = hacluster_indom(DRBD_RESOURCE_INDOM); + pmInDom indom_all = hacluster_indom(DRBD_RESOURCE_ALL_INDOM); int found_node = 0, found_volume = 0, nesting = 0; @@ -1028,8 +560,8 @@ hacluster_drbd_peer_device_instance_refresh(void) int peer_node_id; char *buffer_ptr; FILE *pf; - pmInDom indom = INDOM(DRBD_PEER_DEVICE_INDOM); - pmInDom indom_all = INDOM(DRBD_PEER_DEVICE_ALL_INDOM); + pmInDom indom = hacluster_indom(DRBD_PEER_DEVICE_INDOM); + pmInDom indom_all = hacluster_indom(DRBD_PEER_DEVICE_ALL_INDOM); int found_node = 0, found_peer_node = 0, nesting = 0; @@ -1120,167 +652,151 @@ hacluster_instance(pmInDom indom, int inst, char *name, pmInResult **result, pmd static int hacluster_fetch_refresh(pmdaExt *pmda, int *need_refresh) { - struct pacemaker_fail *fail; - struct pacemaker_constraints *constraints; - struct pacemaker_nodes *pace_nodes; - struct pacemaker_node_attrib *node_attribs; - struct pacemaker_resources *pace_resources; - struct corosync_node *node; - struct corosync_ring *ring; - struct sbd_device *sbd; - struct drbd_resource *resource; - struct drbd_peer_device *peer; - char *node_name, *ring_name, *sbd_dev, *resource_name, *peer_device; - char *instance_name, *constraint_name, *pace_node_name, *attrib_name; - char *pace_resource_name; - int i, sts; - - if ((sts = hacluster_pacemaker_fail_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_pacemaker_constraints_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_pacemaker_nodes_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_pacemaker_node_attrib_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_pacemaker_resources_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_corosync_node_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_corosync_ring_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_sbd_device_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_drbd_resource_instance_refresh()) < 0) - return sts; - - if ((sts = hacluster_drbd_peer_device_instance_refresh()) < 0) - return sts; + int i, sts; if (need_refresh[CLUSTER_PACEMAKER_GLOBAL]) hacluster_refresh_pacemaker_global(); - - for (pmdaCacheOp(INDOM(PACEMAKER_FAIL_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(PACEMAKER_FAIL_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(PACEMAKER_FAIL_INDOM), i, &instance_name, (void **)&fail) || !fail) - continue; - if (need_refresh[CLUSTER_PACEMAKER_FAIL]) - hacluster_refresh_pacemaker_fail(instance_name, &fail->fail_count); + if (need_refresh[CLUSTER_PACEMAKER_FAIL]) { + if ((sts = hacluster_pacemaker_fail_instance_refresh()) < 0) + return sts; } - - for (pmdaCacheOp(INDOM(PACEMAKER_CONSTRAINTS_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(PACEMAKER_CONSTRAINTS_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(PACEMAKER_CONSTRAINTS_INDOM), i, &constraint_name, (void **)&constraints) || !constraints) - continue; - if (need_refresh[CLUSTER_PACEMAKER_CONSTRAINTS] || - need_refresh[CLUSTER_PACEMAKER_CONSTRAINTS_ALL]) - hacluster_refresh_pacemaker_constraints(constraint_name, &constraints->location_constraints); + if (need_refresh[CLUSTER_PACEMAKER_CONSTRAINTS] || need_refresh[CLUSTER_PACEMAKER_CONSTRAINTS_ALL]) { + if ((sts = hacluster_pacemaker_constraints_instance_refresh()) <0) + return sts; } - - for (pmdaCacheOp(INDOM(PACEMAKER_NODES_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(PACEMAKER_NODES_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(PACEMAKER_NODES_INDOM), i, &pace_node_name, (void **)&pace_nodes) || !pace_nodes) - continue; - if (need_refresh[CLUSTER_PACEMAKER_NODES]) - hacluster_refresh_pacemaker_nodes(pace_node_name, &pace_nodes->nodes); + if (need_refresh[CLUSTER_PACEMAKER_NODES]) { + if ((sts = hacluster_pacemaker_nodes_instance_refresh()) <0) + return sts; } - - for (pmdaCacheOp(INDOM(PACEMAKER_NODE_ATTRIB_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(PACEMAKER_NODE_ATTRIB_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(PACEMAKER_NODE_ATTRIB_INDOM), i, &attrib_name, (void **)&node_attribs) || !node_attribs) - continue; - if (need_refresh[CLUSTER_PACEMAKER_NODE_ATTRIB] || - need_refresh[CLUSTER_PACEMAKER_NODE_ATTRIB_ALL]) - hacluster_refresh_pacemaker_node_attribs(attrib_name, &node_attribs->attributes); + if ((need_refresh[CLUSTER_PACEMAKER_NODE_ATTRIB] || need_refresh[CLUSTER_PACEMAKER_NODE_ATTRIB_ALL])) { + if ((sts = hacluster_pacemaker_node_attrib_instance_refresh()) <0) + return sts; } - - for (pmdaCacheOp(INDOM(PACEMAKER_RESOURCES_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(PACEMAKER_RESOURCES_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(PACEMAKER_RESOURCES_INDOM), i, &pace_resource_name, (void **)&pace_resources) || !pace_resources) - continue; - if (need_refresh[CLUSTER_PACEMAKER_RESOURCES] || - need_refresh[CLUSTER_PACEMAKER_RESOURCES_ALL]) - hacluster_refresh_pacemaker_resources(pace_resource_name, &pace_resources->resources); + if ((need_refresh[CLUSTER_PACEMAKER_RESOURCES] || need_refresh[CLUSTER_PACEMAKER_RESOURCES_ALL])) { + struct pacemaker_resources *pace_resources; + char *pace_resource_name; + + if ((sts = hacluster_pacemaker_resources_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(PACEMAKER_RESOURCES_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(PACEMAKER_RESOURCES_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(PACEMAKER_RESOURCES_INDOM), i, &pace_resource_name, (void **)&pace_resources) || !pace_resources) + continue; + + if (need_refresh[CLUSTER_PACEMAKER_RESOURCES] || + need_refresh[CLUSTER_PACEMAKER_RESOURCES_ALL]) + hacluster_refresh_pacemaker_resources(pace_resource_name, pace_resources); + } } - for (pmdaCacheOp(INDOM(COROSYNC_NODE_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(COROSYNC_NODE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(COROSYNC_NODE_INDOM), i, &node_name, (void **)&node) || !node) - continue; + if (need_refresh[CLUSTER_COROSYNC_NODE]) { + struct corosync_node *node; + char *node_name; - if (need_refresh[CLUSTER_COROSYNC_NODE]) - hacluster_refresh_corosync_node(node_name, &node->member_votes); + if ((sts = hacluster_corosync_node_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(COROSYNC_NODE_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(COROSYNC_NODE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(COROSYNC_NODE_INDOM), i, &node_name, (void **)&node) || !node) + continue; + + if (need_refresh[CLUSTER_COROSYNC_NODE]) + hacluster_refresh_corosync_node(node_name, node); + } } - + if (need_refresh[CLUSTER_COROSYNC_GLOBAL]) hacluster_refresh_corosync_global(); - - for (pmdaCacheOp(INDOM(COROSYNC_RING_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(COROSYNC_RING_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(COROSYNC_RING_INDOM), i, &ring_name, (void **)&ring) || !ring) - continue; - if (need_refresh[CLUSTER_COROSYNC_RING] || - need_refresh[CLUSTER_COROSYNC_RING_ALL]) - hacluster_refresh_corosync_ring(ring_name, &ring->rings); + if ((need_refresh[CLUSTER_COROSYNC_RING] || need_refresh[CLUSTER_COROSYNC_RING_ALL])) { + struct corosync_ring *ring; + char *ring_name; + + if ((sts = hacluster_corosync_ring_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(COROSYNC_RING_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(COROSYNC_RING_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(COROSYNC_RING_INDOM), i, &ring_name, (void **)&ring) || !ring) + continue; + + if (need_refresh[CLUSTER_COROSYNC_RING] || + need_refresh[CLUSTER_COROSYNC_RING_ALL]) + hacluster_refresh_corosync_ring(ring_name, ring); + } } - - for (pmdaCacheOp(INDOM(SBD_DEVICE_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(SBD_DEVICE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(SBD_DEVICE_INDOM), i, &sbd_dev, (void **)&sbd) || !sbd) - continue; - if (need_refresh[CLUSTER_SBD_DEVICE] || - need_refresh[CLUSTER_SBD_DEVICE_ALL]) - hacluster_refresh_sbd_device(sbd_dev, &sbd->sbd); + if ((need_refresh[CLUSTER_SBD_DEVICE] || need_refresh[CLUSTER_SBD_DEVICE_ALL])) { + struct sbd_device *sbd; + char *sbd_dev; + + if ((sts = hacluster_sbd_device_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(SBD_DEVICE_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(SBD_DEVICE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(SBD_DEVICE_INDOM), i, &sbd_dev, (void **)&sbd) || !sbd) + continue; + + if (need_refresh[CLUSTER_SBD_DEVICE] || + need_refresh[CLUSTER_SBD_DEVICE_ALL]) + hacluster_refresh_sbd_device(sbd_dev, sbd); + } } - - for (pmdaCacheOp(INDOM(DRBD_RESOURCE_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(DRBD_RESOURCE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(DRBD_RESOURCE_INDOM), i, &resource_name, (void **)&resource) || !resource) - continue; - if (need_refresh[CLUSTER_DRBD_RESOURCE] || - need_refresh[CLUSTER_DRBD_RESOURCE_ALL]) - hacluster_refresh_drbd_resource(resource_name, &resource->resource); + if ((need_refresh[CLUSTER_DRBD_RESOURCE] || need_refresh[CLUSTER_DRBD_RESOURCE_ALL])) { + struct drbd_resource *resource; + char *resource_name; + + if ((sts = hacluster_drbd_resource_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(DRBD_RESOURCE_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(DRBD_RESOURCE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(DRBD_RESOURCE_INDOM), i, &resource_name, (void **)&resource) || !resource) + continue; + + if (need_refresh[CLUSTER_DRBD_RESOURCE] || + need_refresh[CLUSTER_DRBD_RESOURCE_ALL]) + hacluster_refresh_drbd_resource(resource_name, resource); + } } - - for (pmdaCacheOp(INDOM(DRBD_PEER_DEVICE_INDOM), PMDA_CACHE_WALK_REWIND);;) { - if ((i= pmdaCacheOp(INDOM(DRBD_PEER_DEVICE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) - break; - if (!pmdaCacheLookup(INDOM(DRBD_PEER_DEVICE_INDOM), i, &peer_device, (void **)&peer) || !peer) - continue; - if (need_refresh[CLUSTER_DRBD_PEER_DEVICE] || - need_refresh[CLUSTER_DRBD_PEER_DEVICE_ALL]) - hacluster_refresh_drbd_peer_device(peer_device, &peer->peer_device); + if ((need_refresh[CLUSTER_DRBD_PEER_DEVICE] || need_refresh[CLUSTER_DRBD_PEER_DEVICE_ALL])) { + struct drbd_peer_device *peer; + char *peer_device; + + if ((sts = hacluster_drbd_peer_device_instance_refresh()) < 0) + return sts; + + for (pmdaCacheOp(hacluster_indom(DRBD_PEER_DEVICE_INDOM), PMDA_CACHE_WALK_REWIND);;) { + if ((i= pmdaCacheOp(hacluster_indom(DRBD_PEER_DEVICE_INDOM), PMDA_CACHE_WALK_NEXT)) < 0) + break; + if (!pmdaCacheLookup(hacluster_indom(DRBD_PEER_DEVICE_INDOM), i, &peer_device, (void **)&peer) || !peer) + continue; + + if (need_refresh[CLUSTER_DRBD_PEER_DEVICE] || + need_refresh[CLUSTER_DRBD_PEER_DEVICE_ALL]) + hacluster_refresh_drbd_peer_device(peer_device, peer); + } } return sts; } + static int hacluster_fetch(int numpmid, pmID pmidlist[], pmdaResult **resp, pmdaExt *pmda) { @@ -1320,85 +836,85 @@ hacluster_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) return hacluster_pacemaker_global_fetch(item, atom); case CLUSTER_PACEMAKER_FAIL: - sts = pmdaCacheLookup(INDOM(PACEMAKER_FAIL_INDOM), inst, NULL, (void **)&fail); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_FAIL_INDOM), inst, NULL, (void **)&fail); if (sts < 0) return sts; - return hacluster_pacemaker_fail_fetch(item, &fail->fail_count, atom); + return hacluster_pacemaker_fail_fetch(item, fail, atom); case CLUSTER_PACEMAKER_CONSTRAINTS: - sts = pmdaCacheLookup(INDOM(PACEMAKER_CONSTRAINTS_INDOM), inst, NULL, (void **)&constraints); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_CONSTRAINTS_INDOM), inst, NULL, (void **)&constraints); if (sts < 0) return sts; - return hacluster_pacemaker_constraints_fetch(item, &constraints->location_constraints, atom); + return hacluster_pacemaker_constraints_fetch(item, constraints, atom); case CLUSTER_PACEMAKER_CONSTRAINTS_ALL: return hacluster_pacemaker_constraints_all_fetch(item, atom); case CLUSTER_PACEMAKER_NODES: - sts = pmdaCacheLookup(INDOM(PACEMAKER_NODES_INDOM), inst, NULL, (void **)&pace_nodes); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_NODES_INDOM), inst, NULL, (void **)&pace_nodes); if (sts < 0) return sts; - return hacluster_pacemaker_nodes_fetch(item, &pace_nodes->nodes, atom); + return hacluster_pacemaker_nodes_fetch(item, pace_nodes, atom); case CLUSTER_PACEMAKER_NODE_ATTRIB: - sts = pmdaCacheLookup(INDOM(PACEMAKER_NODE_ATTRIB_INDOM), inst, NULL, (void **)&pace_attribs); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_NODE_ATTRIB_INDOM), inst, NULL, (void **)&pace_attribs); if (sts < 0) return sts; - return hacluster_pacemaker_node_attribs_fetch(item, &pace_attribs->attributes, atom); + return hacluster_pacemaker_node_attribs_fetch(item, pace_attribs, atom); case CLUSTER_PACEMAKER_NODE_ATTRIB_ALL: return hacluster_pacemaker_node_attribs_all_fetch(item, atom); case CLUSTER_PACEMAKER_RESOURCES: - sts = pmdaCacheLookup(INDOM(PACEMAKER_RESOURCES_INDOM), inst, NULL, (void **)&pace_resources); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_RESOURCES_INDOM), inst, NULL, (void **)&pace_resources); if (sts < 0) return sts; - return hacluster_pacemaker_resources_fetch(item, &pace_resources->resources, atom); + return hacluster_pacemaker_resources_fetch(item, pace_resources, atom); case CLUSTER_PACEMAKER_RESOURCES_ALL: return hacluster_pacemaker_resources_all_fetch(item, atom); case CLUSTER_COROSYNC_NODE: - sts = pmdaCacheLookup(INDOM(COROSYNC_NODE_INDOM), inst, NULL, (void **)&node); + sts = pmdaCacheLookup(hacluster_indom(COROSYNC_NODE_INDOM), inst, NULL, (void **)&node); if (sts < 0) return sts; - return hacluster_corosync_node_fetch(item, &node->member_votes, atom); + return hacluster_corosync_node_fetch(item, node, atom); case CLUSTER_COROSYNC_GLOBAL: return hacluster_corosync_global_fetch(item, atom); case CLUSTER_COROSYNC_RING: - sts = pmdaCacheLookup(INDOM(COROSYNC_RING_INDOM), inst, NULL, (void **)&ring); + sts = pmdaCacheLookup(hacluster_indom(COROSYNC_RING_INDOM), inst, NULL, (void **)&ring); if (sts < 0) return sts; - return hacluster_corosync_ring_fetch(item, &ring->rings, atom); + return hacluster_corosync_ring_fetch(item, ring, atom); case CLUSTER_COROSYNC_RING_ALL: return hacluster_corosync_ring_all_fetch(item, atom); case CLUSTER_SBD_DEVICE: - sts = pmdaCacheLookup(INDOM(SBD_DEVICE_INDOM), inst, NULL, (void **)&sbd); + sts = pmdaCacheLookup(hacluster_indom(SBD_DEVICE_INDOM), inst, NULL, (void **)&sbd); if (sts < 0) return sts; - return hacluster_sbd_device_fetch(item, &sbd->sbd, atom); + return hacluster_sbd_device_fetch(item, sbd, atom); case CLUSTER_SBD_DEVICE_ALL: return hacluster_sbd_device_all_fetch(item, atom); case CLUSTER_DRBD_RESOURCE: - sts = pmdaCacheLookup(INDOM(DRBD_RESOURCE_INDOM), inst, NULL, (void **)&resource); + sts = pmdaCacheLookup(hacluster_indom(DRBD_RESOURCE_INDOM), inst, NULL, (void **)&resource); if (sts < 0) return sts; - return hacluster_drbd_resource_fetch(item, &resource->resource, atom); + return hacluster_drbd_resource_fetch(item, resource, atom); case CLUSTER_DRBD_RESOURCE_ALL: return hacluster_drbd_resource_all_fetch(item, atom); case CLUSTER_DRBD_PEER_DEVICE: - sts = pmdaCacheLookup(INDOM(DRBD_PEER_DEVICE_INDOM), inst, NULL, (void **)&peer); + sts = pmdaCacheLookup(hacluster_indom(DRBD_PEER_DEVICE_INDOM), inst, NULL, (void **)&peer); if (sts < 0) return sts; - return hacluster_drbd_peer_device_fetch(item, &peer->peer_device, atom); + return hacluster_drbd_peer_device_fetch(item, peer, atom); case CLUSTER_DRBD_PEER_DEVICE_ALL: return hacluster_drbd_peer_device_all_fetch(item, atom); @@ -1493,13 +1009,13 @@ hacluster_label(int ident, int type, pmLabelSet **lpp, pmdaExt *pmda) static int hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) { - struct location_constraints *constraints; - struct attributes *attributes; - struct resources *resources; - struct rings *ring; - struct sbd *sbd; - struct resource *resource; - struct peer_device *peer_device; + struct pacemaker_constraints *constraints; + struct pacemaker_node_attrib *attributes; + struct pacemaker_resources *resources; + struct corosync_ring *ring; + struct sbd_device *sbd; + struct drbd_resource *resource; + struct drbd_peer_device *peer_device; int sts; int no_node_attachment = 0; @@ -1511,7 +1027,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) switch (pmInDom_serial(indom)) { case PACEMAKER_CONSTRAINTS_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(PACEMAKER_CONSTRAINTS_INDOM), inst, &name, (void **)&constraints); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_CONSTRAINTS_INDOM), inst, &name, (void **)&constraints); if (sts < 0 || sts == PMDA_CACHE_INACTIVE) return 0; return pmdaAddLabels(lp, "{\"constraint\":\"%s\", \"node\":\"%s\", \"resource\":\"%s\", \"role\":\"%s\", \"score\":\"%s\"}", @@ -1523,7 +1039,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) ); case PACEMAKER_NODE_ATTRIB_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(PACEMAKER_NODE_ATTRIB_INDOM), inst, &name, (void **)&attributes); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_NODE_ATTRIB_INDOM), inst, &name, (void **)&attributes); if (sts < 0 || sts == PMDA_CACHE_INACTIVE) return 0; /* @@ -1543,7 +1059,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) return sts; case PACEMAKER_RESOURCES_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(PACEMAKER_RESOURCES_INDOM), inst, &name, (void **)&resources); + sts = pmdaCacheLookup(hacluster_indom(PACEMAKER_RESOURCES_INDOM), inst, &name, (void **)&resources); if (sts < 0 || sts == PMDA_CACHE_INACTIVE) return 0; @@ -1572,7 +1088,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) return sts; case COROSYNC_RING_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(COROSYNC_RING_INDOM), inst, &name, (void **)&ring); + sts = pmdaCacheLookup(hacluster_indom(COROSYNC_RING_INDOM), inst, &name, (void **)&ring); if (sts <0 || sts == PMDA_CACHE_INACTIVE) return 0; @@ -1584,7 +1100,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) ); case SBD_DEVICE_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(SBD_DEVICE_INDOM), inst, &name, (void**)&sbd); + sts = pmdaCacheLookup(hacluster_indom(SBD_DEVICE_INDOM), inst, &name, (void**)&sbd); if (sts <0 || sts == PMDA_CACHE_INACTIVE) return 0; @@ -1594,7 +1110,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) ); case DRBD_RESOURCE_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(DRBD_RESOURCE_INDOM), inst, &name, (void**)&resource); + sts = pmdaCacheLookup(hacluster_indom(DRBD_RESOURCE_INDOM), inst, &name, (void**)&resource); if (sts <0 || sts == PMDA_CACHE_INACTIVE) return 0; @@ -1606,7 +1122,7 @@ hacluster_labelCallBack(pmInDom indom, unsigned int inst, pmLabelSet **lp) ); case DRBD_PEER_DEVICE_ALL_INDOM: - sts = pmdaCacheLookup(INDOM(DRBD_PEER_DEVICE_INDOM), inst, &name, (void**)&peer_device); + sts = pmdaCacheLookup(hacluster_indom(DRBD_PEER_DEVICE_INDOM), inst, &name, (void**)&peer_device); if (sts <0 || sts == PMDA_CACHE_INACTIVE) return 0; diff --git a/src/pmdas/hacluster/pmdahacluster.h b/src/pmdas/hacluster/pmdahacluster.h index a813ccb02d6..19b83daf5ec 100644 --- a/src/pmdas/hacluster/pmdahacluster.h +++ b/src/pmdas/hacluster/pmdahacluster.h @@ -1,7 +1,7 @@ /* * High Availability (HA) Cluster PMDA * - * Copyright (c) 2020 -2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -66,45 +66,7 @@ enum { NUM_INDOMS }; -struct pacemaker_fail { - struct fail_count fail_count; -}; - -struct pacemaker_constraints { - struct location_constraints location_constraints; -}; - -struct pacemaker_nodes { - struct nodes nodes; -}; - -struct pacemaker_node_attrib { - struct attributes attributes; -}; - -struct pacemaker_resources { - struct resources resources; -}; - -struct corosync_node { - struct member_votes member_votes; -}; - -struct corosync_ring { - struct rings rings; -}; - -struct sbd_device { - struct sbd sbd; -}; - -struct drbd_resource { - struct resource resource; -}; - -struct drbd_peer_device { - struct peer_device peer_device; -}; +extern pmInDom hacluster_indom(int); extern pmdaMetric metrictable[]; extern int metrictable_size(); diff --git a/src/pmdas/hacluster/sbd.c b/src/pmdas/hacluster/sbd.c index cf49112cb34..5db20a75641 100644 --- a/src/pmdas/hacluster/sbd.c +++ b/src/pmdas/hacluster/sbd.c @@ -29,7 +29,7 @@ static char *sbd_status_healthy = "Healthy"; static char *sbd_status_unhealthy = "Unhealthy"; int -hacluster_sbd_device_fetch(int item, struct sbd *sbd, pmAtomValue *atom) +hacluster_sbd_device_fetch(int item, struct sbd_device *sbd, pmAtomValue *atom) { /* check for bounds */ if (item < 0 || item >= NUM_SBD_DEVICE_STATS) @@ -76,7 +76,7 @@ hacluster_sbd_device_all_fetch(int item, pmAtomValue *atom) } int -hacluster_refresh_sbd_device(const char *sbd_dev, struct sbd *sbd) +hacluster_refresh_sbd_device(const char *sbd_dev, struct sbd_device *sbd) { char buffer[4096]; FILE *pf; diff --git a/src/pmdas/hacluster/sbd.h b/src/pmdas/hacluster/sbd.h index 0a6971d0ea4..0d1c6204a65 100644 --- a/src/pmdas/hacluster/sbd.h +++ b/src/pmdas/hacluster/sbd.h @@ -1,7 +1,7 @@ /* * HA Cluster SBD statistics. * - * Copyright (c) 2020 - 2021 Red Hat. + * Copyright (c) 2020 - 2026 Red Hat. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -27,7 +27,7 @@ enum { NUM_SBD_DEVICE_STATS }; -struct sbd { +struct sbd_device { char path[256]; char status[11]; uint32_t msgwait; @@ -36,9 +36,9 @@ struct sbd { uint32_t watchdog; }; -extern int hacluster_sbd_device_fetch(int, struct sbd *, pmAtomValue *); +extern int hacluster_sbd_device_fetch(int, struct sbd_device *, pmAtomValue *); extern int hacluster_sbd_device_all_fetch(int, pmAtomValue *); -extern int hacluster_refresh_sbd_device(const char *, struct sbd *); +extern int hacluster_refresh_sbd_device(const char *, struct sbd_device *); extern void sbd_stats_setup(void);