Skip to content

Conversation

@nrwahl2
Copy link
Contributor

@nrwahl2 nrwahl2 commented Nov 3, 2025

My short-term goal (not done yet) is to get rid of ha_msg_input_t and move its two members directly into fsa_data_t. This will require some more fiddling with register_fsa_error{,_adv}, register_fsa_input{,_adv}, and related functions/macros. That's the main reason that I started working on best practices for the do_X() functions at the end of this PR. I want to make it easier to reason about all this msg_data nonsense.

(For context, some of the controller's macros require a variable named msg_data to exist, even if it's a NULL dummy variable.)

@nrwahl2 nrwahl2 requested a review from clumens November 3, 2025 20:13
@nrwahl2 nrwahl2 force-pushed the nrwahl2-controller branch from b644bc3 to e2701e0 Compare November 3, 2025 20:45
@nrwahl2
Copy link
Contributor Author

nrwahl2 commented Nov 4, 2025

At this point, having added more commits, we'll want to do a cts-lab run. We can break the PR into pieces, however.

@clumens
Copy link
Contributor

clumens commented Nov 4, 2025

At this point, having added more commits, we'll want to do a cts-lab run. We can break the PR into pieces, however.

Why don't you break all the "Drop..." commits out into their own PR first.

@nrwahl2 nrwahl2 force-pushed the nrwahl2-controller branch from 08958c2 to 5dd0678 Compare November 6, 2025 23:25
@nrwahl2
Copy link
Contributor Author

nrwahl2 commented Nov 6, 2025

Updated to tackle all the do_X() handlers, now that #3981 is merged.

* Make function static.
* Use uint8_t for log_type.
* Assert pointer is non-NULL before dereferencing.
* Use pcmk__is_set().

Signed-off-by: Reid Wahl <[email protected]>
No code changes aside from moving functions around.

Signed-off-by: Reid Wahl <[email protected]>
...and scheduler IPC handlers.

Signed-off-by: Reid Wahl <[email protected]>
This one is slightly more complex than other recent ones.
* Use pcmk__is_set() instead of bitwise-and.
* Drop some elses after early returns.
* Drop a redundant "action & A_TE_START" check before checking
  cur_state. We would have returned already if that flag were not set.
* Wait to register the TE UUID until after checking error conditions;
  register it only if our TE start is a success.
* Drop the init_ok variable and use early returns instead.

Signed-off-by: Reid Wahl <[email protected]>
And add a FIXME comment about some confusing, likely incorrect behavior.

Signed-off-by: Reid Wahl <[email protected]>
The user_name argument was already ignored.

Signed-off-by: Reid Wahl <[email protected]>
* Give update_dc_expected() a name that is clearer, albeit longer.
* Declare static variable first_join first, within the narrowest scope
  possible.
* Use bool/true/false instead of gboolean/TRUE/FALSE.
* Drop was_nack variable.
* Rename tmp1 variable to more meaningful "state".
* Handle NULL variables with pcmk__s().
* Create join_confirm immediately before setting its join id attribute.
* Declare start_state variable within the narrowest scope possible.
* Compare pointers explicitly against NULL.
* !AM_I_DC instead of AM_I_DC == FALSE.
* Use register_fsa_input_before().

Signed-off-by: Reid Wahl <[email protected]>
Note that the "or wanting to shut down" comment was made obsolete by
commit 0e4db7b in 2006.

Signed-off-by: Reid Wahl <[email protected]>
Surprisingly, this seems to have never been set, even though it's been
checked and cleared since at least 2004. Even as of 12c39ec, which
added a new check for R_STARTING, nothing was setting it.

This allows a couple of functions to be simplified.

Signed-off-by: Reid Wahl <[email protected]>
I think this is all we can do before functionizing pieces of
do_dc_join_filter_offer(). This adds some parentheses, uses bool instaed
of gboolean, avoids comparing against FALSE, moves some assignments to
just before the variable is used, reorders declarations in accordance
with the order of use, renames ack_nack_bool to accept, etc.

Signed-off-by: Reid Wahl <[email protected]>
Also touch do_cl_join_announce() since nothing needs to change within
the body.

Signed-off-by: Reid Wahl <[email protected]>
And remove some nesting.

Signed-off-by: Reid Wahl <[email protected]>
Previously, we relied on a msg_data variable being declared. I found
this very non-intuitive. We often created such a variable just as a
dummy so that the macro would work.

Signed-off-by: Reid Wahl <[email protected]>
@nrwahl2 nrwahl2 force-pushed the nrwahl2-controller branch from 5dd0678 to 73678b7 Compare November 6, 2025 23:27
} else if (pcmk__is_set(controld_globals.fsa_input_register,
R_TE_CONNECTED)) {
}
if (pcmk__is_set(controld_globals.fsa_input_register, R_TE_CONNECTED)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picky, but I'd like to see spaces between all these if blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally do too. This is kind of my one exception: related if {... early return; } if {... early return; } blocks. I feel like the braces add enough space for good readability as long as there aren't comments.

Either way, I'm not picky about it and don't mind adding the lines.

crm_debug("Registering Signal Handlers");
mainloop_add_signal(SIGTERM, crm_shutdown);
mainloop_add_signal(SIGPIPE, sigpipe_ignore);
mainloop_add_signal(SIGPIPE, NULL); // Ignore SIGPIPE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also modify the doxygen on mainloop_add_signal to reference that the dispatch param can be NULL.


if (!pcmk__str_eq(op, CRM_OP_JOIN_ACKNAK, pcmk__str_casei)) {
crm_trace("Ignoring op=%s message", op);
if (!pcmk__str_eq(op, CRM_OP_JOIN_ACKNAK, pcmk__str_none)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love how consistent we are with this:

clumens@spire ~/src/pacemaker main|…❯ k CRM_OP_ | grep pcmk__str_eq | grep -c pcmk__str_casei
11
clumens@spire ~/src/pacemaker main|…❯ k CRM_OP_ | grep pcmk__str_eq | grep -c pcmk__str_none 
14

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when we moved from safe_str_eq(), we used pcmk__str_casei for safety (since there were so ungodly many changes, and we haven't updated them all yet.

return;
}

if (!AM_I_DC && controld_is_local_node(welcome_from)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to see the spaces preserved on these blocks too.

register_fsa_error(I_ERROR);
return;
}
if (controld_globals.dc_name == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise with blank lines here too.

{
crm_debug("Ensuring DC, quorum and node attributes are up-to-date");
crm_update_quorum(pcmk__cluster_has_quorum(), TRUE);
crm_debug("Ensuring DC, quorum, and node attributes are up to date");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long live the oxford comma.

return 1;
}

return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the commit message - "instaed" instead of "instead". Heh.


} else { // Should always be PCMK__XE_GENERATION_TUPLE
CRM_LOG_ASSERT(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be inverted:

if (!pcmk__xe_is(generation, PCMK__XE_GENERATION_TUPLE)) {
    CRM_LOG_ASSERT(false);
}

for (int i = ...) {
}

pcmk__plural_s(count_welcomed));
crmd_join_phase_log(LOG_DEBUG);
/* crmd_fsa_stall(FALSE); Needed? */
// crmd_fsa_stall(false); Needed?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been commented out since its introduction in 0b84e7e. Again, it apparently hasn't caused any problems that we know of, so I don't think we need to keep it around.

crm_notice("Not invoking the TE because we are not the DC");
return;
}
if (pcmk__is_set(action, A_TE_INVOKE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise with blank lines in this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants