From b18724aef1e73cf3360947e821118cbaeaeb41e7 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Feb 24 2021 16:08:58 +0000 Subject: Refactor: libpacemaker: Move reduce_stonith_history into the library. And also rename it to pcmk__reduce_fence_history. I don't see anywhere else that could use this function at the moment, but it seems too generic to keep in crm_mon. --- diff --git a/include/pcmki/pcmki_fence.h b/include/pcmki/pcmki_fence.h index 241d030..d4cef68 100644 --- a/include/pcmki/pcmki_fence.h +++ b/include/pcmki/pcmki_fence.h @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the Pacemaker project contributors + * Copyright 2019-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -219,4 +219,18 @@ int pcmk__fence_validate(pcmk__output_t *out, stonith_t *st, const char *agent, const char *id, stonith_key_value_t *params, unsigned int timeout); +/** + * \brief Reduce the STONITH history + * + * STONITH history is reduced as follows: + * - The last successful action of every action-type and target is kept + * - For failed actions, who failed is kept + * - All actions in progress are kept + * + * \param[in] history List of STONITH actions + * + * \return The reduced history + */ +stonith_history_t * +pcmk__reduce_fence_history(stonith_history_t *history); #endif diff --git a/lib/pacemaker/pcmk_fence.c b/lib/pacemaker/pcmk_fence.c index d591379..34540cc 100644 --- a/lib/pacemaker/pcmk_fence.c +++ b/lib/pacemaker/pcmk_fence.c @@ -1,5 +1,5 @@ /* - * Copyright 2009-2020 the Pacemaker project contributors + * Copyright 2009-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -520,3 +520,46 @@ pcmk_fence_validate(xmlNodePtr *xml, stonith_t *st, const char *agent, return rc; } #endif + +stonith_history_t * +pcmk__reduce_fence_history(stonith_history_t *history) +{ + stonith_history_t *new, *hp, *np; + + if (!history) { + return history; + } + + new = history; + hp = new->next; + new->next = NULL; + + while (hp) { + stonith_history_t *hp_next = hp->next; + + hp->next = NULL; + + for (np = new; ; np = np->next) { + if ((hp->state == st_done) || (hp->state == st_failed)) { + /* action not in progress */ + if (pcmk__str_eq(hp->target, np->target, pcmk__str_casei) && + pcmk__str_eq(hp->action, np->action, pcmk__str_casei) && + (hp->state == np->state) && + ((hp->state == st_done) || + pcmk__str_eq(hp->delegate, np->delegate, pcmk__str_casei))) { + /* purge older hp */ + stonith_history_free(hp); + break; + } + } + + if (!np->next) { + np->next = hp; + break; + } + } + hp = hp_next; + } + + return new; +} diff --git a/tools/crm_mon.c b/tools/crm_mon.c index ff1b86b..2179f53 100644 --- a/tools/crm_mon.c +++ b/tools/crm_mon.c @@ -1520,56 +1520,6 @@ print_simple_status(pcmk__output_t *out, pe_working_set_t * data_set, /* coverity[leaked_storage] False positive */ } -/*! - * \internal - * \brief Reduce the stonith-history - * for successful actions we keep the last of every action-type & target - * for failed actions we record as well who had failed - * for actions in progress we keep full track - * - * \param[in] history List of stonith actions - * - */ -static stonith_history_t * -reduce_stonith_history(stonith_history_t *history) -{ - stonith_history_t *new = history, *hp, *np; - - if (new) { - hp = new->next; - new->next = NULL; - - while (hp) { - stonith_history_t *hp_next = hp->next; - - hp->next = NULL; - - for (np = new; ; np = np->next) { - if ((hp->state == st_done) || (hp->state == st_failed)) { - /* action not in progress */ - if (pcmk__str_eq(hp->target, np->target, pcmk__str_casei) && - pcmk__str_eq(hp->action, np->action, pcmk__str_casei) && - (hp->state == np->state) && - ((hp->state == st_done) || - pcmk__str_eq(hp->delegate, np->delegate, pcmk__str_casei))) { - /* purge older hp */ - stonith_history_free(hp); - break; - } - } - - if (!np->next) { - np->next = hp; - break; - } - } - hp = hp_next; - } - } - - return new; -} - static int send_custom_trap(const char *node, const char *rsc, const char *task, int target_rc, int rc, int status, const char *desc) @@ -1935,7 +1885,7 @@ mon_refresh_display(gpointer user_data) if (!pcmk_is_set(options.mon_ops, mon_op_fence_full_history) && (output_format != mon_output_xml)) { - stonith_history = reduce_stonith_history(stonith_history); + stonith_history = pcmk__reduce_fence_history(stonith_history); } break; /* all other cases are errors */ }