Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pmdas/hacluster/GNUmakefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
132 changes: 127 additions & 5 deletions src/pmdas/hacluster/corosync.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +21,7 @@
#include "libpcp.h"
#include "pmda.h"

#include "pmdahacluster.h"
#include "corosync.h"

static char *quorumtool_command;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions src/pmdas/hacluster/corosync.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -58,23 +58,25 @@ struct corosync_global {
uint32_t ring_errors;
};

struct rings {
struct corosync_ring {
uint8_t status;
char address[40];
uint64_t node_id;
uint32_t number;
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);

Expand Down
10 changes: 5 additions & 5 deletions src/pmdas/hacluster/drbd.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/pmdas/hacluster/drbd.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -54,7 +54,7 @@ enum {
NUM_DRBD_PEER_DEVICE_STATS
};

struct resource {
struct drbd_resource {
char resource[128];
char role[10];
char volume[128];
Expand All @@ -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];
Expand All @@ -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);

Expand Down
Loading
Loading