Skip to content

Commit 5f63c39

Browse files
Ken Gaillotnrwahl2
authored andcommitted
Refactor: controller: drop node state section enum
It now boils down to a bool for whether we want only unlocked resources
1 parent c55a910 commit 5f63c39

File tree

6 files changed

+33
-53
lines changed

6 files changed

+33
-53
lines changed

daemons/controld/controld_cib.c

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,15 @@ cib_delete_callback(xmlNode *msg, int call_id, int rc, xmlNode *output,
279279

280280
/*!
281281
* \internal
282-
* \brief Get the XPath and description of a node state section to be deleted
282+
* \brief Get the XPath and description of resource history to be deleted
283283
*
284-
* \param[in] uname Desired node
285-
* \param[in] section Subsection of \c PCMK__XE_NODE_STATE to be deleted
286-
* \param[out] xpath Where to store XPath of \p section
287-
* \param[out] desc If not \c NULL, where to store description of \p section
284+
* \param[in] uname Name of node to delete resource history for
285+
* \param[in] unlocked_only If true, delete history of only unlocked resources
286+
* \param[out] xpath Where to store XPath for history deletion
287+
* \param[out] desc If not NULL, where to store loggable description
288288
*/
289289
void
290-
controld_node_state_deletion_strings(const char *uname,
291-
enum controld_section_e section,
290+
controld_node_state_deletion_strings(const char *uname, bool unlocked_only,
292291
char **xpath, char **desc)
293292
{
294293
const char *desc_pre = NULL;
@@ -297,20 +296,13 @@ controld_node_state_deletion_strings(const char *uname,
297296
long long expire = (long long) time(NULL)
298297
- controld_globals.shutdown_lock_limit;
299298

300-
switch (section) {
301-
case controld_section_lrm:
302-
*xpath = pcmk__assert_asprintf(XPATH_NODE_LRM, uname);
303-
desc_pre = "resource history";
304-
break;
305-
case controld_section_lrm_unlocked:
306-
*xpath = pcmk__assert_asprintf(XPATH_NODE_LRM_UNLOCKED, uname,
307-
uname, expire);
308-
desc_pre = "resource history (other than shutdown locks)";
309-
break;
310-
default:
311-
// We called this function incorrectly
312-
pcmk__assert(false);
313-
break;
299+
if (unlocked_only) {
300+
*xpath = pcmk__assert_asprintf(XPATH_NODE_LRM_UNLOCKED,
301+
uname, uname, expire);
302+
desc_pre = "resource history (other than shutdown locks)";
303+
} else {
304+
*xpath = pcmk__assert_asprintf(XPATH_NODE_LRM, uname);
305+
desc_pre = "resource history";
314306
}
315307

316308
if (desc != NULL) {
@@ -320,15 +312,14 @@ controld_node_state_deletion_strings(const char *uname,
320312

321313
/*!
322314
* \internal
323-
* \brief Delete subsection of a node's CIB \c PCMK__XE_NODE_STATE
315+
* \brief Delete a node's resource history from the CIB
324316
*
325-
* \param[in] uname Desired node
326-
* \param[in] section Subsection of \c PCMK__XE_NODE_STATE to delete
327-
* \param[in] options CIB call options to use
317+
* \param[in] uname Name of node to delete resource history for
318+
* \param[in] unlocked_only If true, delete history of only unlocked resources
319+
* \param[in] options CIB call options to use
328320
*/
329321
void
330-
controld_delete_node_state(const char *uname, enum controld_section_e section,
331-
int options)
322+
controld_delete_node_state(const char *uname, bool unlocked_only, int options)
332323
{
333324
cib_t *cib = controld_globals.cib_conn;
334325
char *xpath = NULL;
@@ -337,8 +328,7 @@ controld_delete_node_state(const char *uname, enum controld_section_e section,
337328

338329
pcmk__assert((uname != NULL) && (cib != NULL));
339330

340-
controld_node_state_deletion_strings(uname, section, &xpath, &desc);
341-
331+
controld_node_state_deletion_strings(uname, unlocked_only, &xpath, &desc);
342332
cib__set_call_options(options, "node state deletion",
343333
cib_xpath|cib_multiple);
344334
cib_rc = cib->cmds->remove(cib, xpath, NULL, options);

daemons/controld/controld_cib.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,10 @@ int controld_update_cib(const char *section, xmlNode *data, int options,
4646
void *));
4747
unsigned int cib_op_timeout(void);
4848

49-
// Subsections of PCMK__XE_NODE_STATE
50-
enum controld_section_e {
51-
controld_section_lrm,
52-
controld_section_lrm_unlocked,
53-
};
54-
55-
void controld_node_state_deletion_strings(const char *uname,
56-
enum controld_section_e section,
49+
void controld_node_state_deletion_strings(const char *uname, bool unlocked_only,
5750
char **xpath, char **desc);
58-
void controld_delete_node_state(const char *uname,
59-
enum controld_section_e section, int options);
51+
void controld_delete_node_state(const char *uname, bool unlocked_only,
52+
int options);
6053
int controld_delete_resource_history(const char *rsc_id, const char *node,
6154
const char *user_name, int call_options);
6255

daemons/controld/controld_execd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,7 @@ force_reprobe(lrm_state_t *lrm_state, const char *from_sys,
10711071
}
10721072

10731073
/* Now delete the copy in the CIB */
1074-
controld_delete_node_state(lrm_state->node_name, controld_section_lrm,
1075-
cib_none);
1074+
controld_delete_node_state(lrm_state->node_name, false, cib_none);
10761075
}
10771076

10781077
/*!

daemons/controld/controld_fencing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ update_node_state_after_fencing(const char *target, const char *target_xml_id)
248248
fsa_register_cib_callback(rc, pcmk__str_copy(target), cib_fencing_updated);
249249

250250
// Delete node's resource history from CIB
251-
controld_delete_node_state(peer->name, controld_section_lrm, cib_none);
251+
controld_delete_node_state(peer->name, false, cib_none);
252252

253253
// Ask attribute manager to delete node's transient attributes
254254
// @TODO: This is the only call to controld_purge_node_attrs that doesn't

daemons/controld/controld_join_dc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ do_dc_join_ack(long long action, enum crmd_fsa_cause cause,
758758

759759
cib_t *cib = controld_globals.cib_conn;
760760
int rc = pcmk_ok;
761-
enum controld_section_e section = controld_section_lrm;
761+
762+
const bool unlocked_only = pcmk__is_set(controld_globals.flags,
763+
controld_shutdown_lock_enabled);
762764
char *xpath = NULL;
763765
xmlNode *state = NULL;
764766

@@ -822,10 +824,8 @@ do_dc_join_ack(long long action, enum crmd_fsa_cause cause,
822824
}
823825

824826
// Delete relevant parts of node's current executor state from CIB
825-
if (pcmk__is_set(controld_globals.flags, controld_shutdown_lock_enabled)) {
826-
section = controld_section_lrm_unlocked;
827-
}
828-
controld_node_state_deletion_strings(join_from, section, &xpath, NULL);
827+
controld_node_state_deletion_strings(join_from, unlocked_only, &xpath,
828+
NULL);
829829

830830
rc = cib->cmds->remove(cib, xpath, NULL,
831831
cib_xpath|cib_multiple|cib_transaction);

daemons/controld/controld_remote_ra.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,15 @@ should_purge_attributes(pcmk__node_status_t *node)
205205
static void
206206
purge_remote_node_attrs(int call_opt, pcmk__node_status_t *node)
207207
{
208-
enum controld_section_e section = controld_section_lrm;
208+
const bool unlocked_only = pcmk__is_set(controld_globals.flags,
209+
controld_shutdown_lock_enabled);
209210

210211
// Purge node's transient attributes (from attribute manager and CIB)
211212
if (should_purge_attributes(node)) {
212213
controld_purge_node_attrs(node->name, true);
213214
}
214215

215-
if (pcmk__is_set(controld_globals.flags, controld_shutdown_lock_enabled)) {
216-
section = controld_section_lrm_unlocked;
217-
}
218-
controld_delete_node_state(node->name, section, call_opt);
216+
controld_delete_node_state(node->name, unlocked_only, call_opt);
219217
}
220218

221219
/*!
@@ -324,7 +322,7 @@ remote_node_down(const char *node_name, const enum down_opts opts)
324322
* think resources are still running on the node.
325323
*/
326324
if (opts == DOWN_ERASE_LRM) {
327-
controld_delete_node_state(node_name, controld_section_lrm, call_opt);
325+
controld_delete_node_state(node_name, false, call_opt);
328326
}
329327

330328
/* Ensure node is in the remote peer cache with lost state */

0 commit comments

Comments
 (0)