From 268d02c30fa75ae235a6bd19e4d2a3116965708f Mon Sep 17 00:00:00 2001 From: Ken Gaillot Date: Feb 05 2021 06:23:35 +0000 Subject: Refactor: scheduler: new convenience function for changing resource's next role ... for logging consistency --- diff --git a/include/crm/pengine/complex.h b/include/crm/pengine/complex.h index 1d010f4..d5e1a39 100644 --- a/include/crm/pengine/complex.h +++ b/include/crm/pengine/complex.h @@ -1,5 +1,5 @@ /* - * Copyright 2004-2020 the Pacemaker project contributors + * Copyright 2004-2021 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -35,6 +35,9 @@ void pe_get_versioned_attributes(xmlNode *meta_hash, pe_resource_t *rsc, gboolean is_parent(pe_resource_t *child, pe_resource_t *rsc); pe_resource_t *uber_parent(pe_resource_t *rsc); +void pe__set_next_role(pe_resource_t *rsc, enum rsc_role_e role, + const char *why); + #ifdef __cplusplus } #endif diff --git a/lib/pengine/complex.c b/lib/pengine/complex.c index 3e63510..4d069da 100644 --- a/lib/pengine/complex.c +++ b/lib/pengine/complex.c @@ -1062,3 +1062,22 @@ pe__count_common(pe_resource_t *rsc) } } } + +/*! + * \internal + * \brief Update a resource's next role + * + * \param[in,out] rsc Resource to be updated + * \param[in] role Resource's new next role + * \param[in] why Human-friendly reason why role is changing (for logs) + */ +void +pe__set_next_role(pe_resource_t *rsc, enum rsc_role_e role, const char *why) +{ + CRM_ASSERT((rsc != NULL) && (why != NULL)); + if (rsc->next_role != role) { + pe_rsc_trace(rsc, "Resetting next role for %s from %s to %s (%s)", + rsc->id, role2text(rsc->next_role), role2text(role), why); + rsc->next_role = role; + } +}