Skip to content

Commit c683ed2

Browse files
Ken Gaillotclumens
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 cb7e35b commit c683ed2

File tree

6 files changed

+32
-53
lines changed

6 files changed

+32
-53
lines changed

daemons/controld/controld_cib.c

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

282282
/*!
283283
* \internal
284-
* \brief Get the XPath and description of a node state section to be deleted
284+
* \brief Get the XPath and description of resource history to be deleted
285285
*
286-
* \param[in] uname Desired node
287-
* \param[in] section Subsection of \c PCMK__XE_NODE_STATE to be deleted
288-
* \param[out] xpath Where to store XPath of \p section
289-
* \param[out] desc If not \c NULL, where to store description of \p section
286+
* \param[in] uname Name of node to delete resource history for
287+
* \param[in] unlocked_only If true, delete history of only unlocked resources
288+
* \param[out] xpath Where to store XPath for history deletion
289+
* \param[out] desc If not NULL, where to store loggable description
290290
*/
291291
void
292-
controld_node_state_deletion_strings(const char *uname,
293-
enum controld_section_e section,
292+
controld_node_state_deletion_strings(const char *uname, bool unlocked_only,
294293
char **xpath, char **desc)
295294
{
296295
const char *desc_pre = NULL;
@@ -299,20 +298,13 @@ controld_node_state_deletion_strings(const char *uname,
299298
long long expire = (long long) time(NULL)
300299
- controld_globals.shutdown_lock_limit;
301300

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

318310
if (desc != NULL) {
@@ -322,15 +314,14 @@ controld_node_state_deletion_strings(const char *uname,
322314

323315
/*!
324316
* \internal
325-
* \brief Delete subsection of a node's CIB \c PCMK__XE_NODE_STATE
317+
* \brief Delete a node's resource history from the CIB
326318
*
327-
* \param[in] uname Desired node
328-
* \param[in] section Subsection of \c PCMK__XE_NODE_STATE to delete
329-
* \param[in] options CIB call options to use
319+
* \param[in] uname Name of node to delete resource history for
320+
* \param[in] unlocked_only If true, delete history of only unlocked resources
321+
* \param[in] options CIB call options to use
330322
*/
331323
void
332-
controld_delete_node_state(const char *uname, enum controld_section_e section,
333-
int options)
324+
controld_delete_node_state(const char *uname, bool unlocked_only, int options)
334325
{
335326
cib_t *cib = controld_globals.cib_conn;
336327
char *xpath = NULL;
@@ -339,8 +330,7 @@ controld_delete_node_state(const char *uname, enum controld_section_e section,
339330

340331
pcmk__assert((uname != NULL) && (cib != NULL));
341332

342-
controld_node_state_deletion_strings(uname, section, &xpath, &desc);
343-
333+
controld_node_state_deletion_strings(uname, unlocked_only, &xpath, &desc);
344334
cib__set_call_options(options, "node state deletion",
345335
cib_xpath|cib_multiple);
346336
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
@@ -1074,8 +1074,7 @@ force_reprobe(lrm_state_t *lrm_state, const char *from_sys,
10741074
}
10751075

10761076
/* Now delete the copy in the CIB */
1077-
controld_delete_node_state(lrm_state->node_name, controld_section_lrm,
1078-
cib_none);
1077+
controld_delete_node_state(lrm_state->node_name, false, cib_none);
10791078
}
10801079

10811080
/*!

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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ do_dc_join_ack(long long action,
772772
pcmk__node_status_t *peer = NULL;
773773
enum controld_join_phase phase = controld_join_none;
774774

775-
enum controld_section_e section = controld_section_lrm;
775+
const bool unlocked_only = pcmk__is_set(controld_globals.flags,
776+
controld_shutdown_lock_enabled);
776777
char *xpath = NULL;
777778
xmlNode *state = NULL;
778779
xmlNode *execd_state = NULL;
@@ -841,10 +842,8 @@ do_dc_join_ack(long long action,
841842
}
842843

843844
// Delete relevant parts of node's current executor state from CIB
844-
if (pcmk__is_set(controld_globals.flags, controld_shutdown_lock_enabled)) {
845-
section = controld_section_lrm_unlocked;
846-
}
847-
controld_node_state_deletion_strings(join_from, section, &xpath, NULL);
845+
controld_node_state_deletion_strings(join_from, unlocked_only, &xpath,
846+
NULL);
848847

849848
rc = cib->cmds->remove(cib, xpath, NULL,
850849
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)