Skip to content

Use anonymous struct/enum in typedefs where possible #4049

Open
nrwahl2 wants to merge 20 commits intoClusterLabs:mainfrom
nrwahl2:nrwahl2-struct
Open

Use anonymous struct/enum in typedefs where possible #4049
nrwahl2 wants to merge 20 commits intoClusterLabs:mainfrom
nrwahl2:nrwahl2-struct

Conversation

@nrwahl2
Copy link
Contributor

@nrwahl2 nrwahl2 commented Feb 5, 2026

Very low priority, but should be a quick review

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
There's no reason to name the structs or enums in these cases, since we
always refer to the type using its typedef name.

This commit skips changing public headers, since that would be an API
change.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use cib_api_operations_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2 nrwahl2 requested a review from clumens February 5, 2026 02:37
Copy link
Contributor

@clumens clumens left a comment

Choose a reason for hiding this comment

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

It would also be worth adding something to doc/sphinx/Pacemaker_Development/c.rst explaining this. I'm hoping one day we'll have someone new on the team and we can point them at that instead of having to re-explain all this stuff.


typedef void (*lrmd_event_callback) (lrmd_event_data_t * event);

//! \deprecated Use \c lrmd_list_t instead of <tt>struct lrmd_list_s</tt>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would love to deprecate this all the way out of the code. It's so obnoxious to have a reimplementation of a linked list as public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. That would be quite a bit more involved to do right now though. We have not only lrmd_list_freeall() using it but also three methods in lrmd_api_operations_t, which is not deprecated. Those method signatures can't be changed, so we'd have to get to a point where we can deprecate them altogether.

@@ -184,6 +184,7 @@ typedef struct stonith_history_s {
} stonith_history_t;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we can't also deprecate stonith_history_s and stonith_key_value_s? (Speaking of things I'd love to see go away)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! The reason is they're already deprecated.

/*!
 * \brief Key-value pair list node
 * \deprecated Do not use
 */
typedef struct stonith_key_value_s {
    char *key;
    char *value;
    struct stonith_key_value_s *next;
} stonith_key_value_t;

// @TODO Keep this definition but make it internal
/*!
 * \brief Fencing history entry
 * \deprecated Do not use
 */
typedef struct stonith_history_s {
    char *target;
    char *action;
    char *origin;
    char *delegate;
    char *client;
    int state;
    time_t completed;
    struct stonith_history_s *next;
    long completed_nsec;
    char *exit_reason;
} stonith_history_t;

The enum itself is not deprecated. However, we want to treat the enum in
the typedef as anonymous and use crm_exit_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use crm_time_period_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use pcmk_nvpair_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use pcmk_rule_input_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use svc_action_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_event_data_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_key_value_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_rsc_info_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_op_info_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_list_t instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to treat the
struct in the typedef as anonymous and use lrmd_api_operations_t
instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Use appropriate libpacemaker functions instead. All public functions
that use stonith_t are already deprecated.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to use cib_t to
refer to it instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to use
crm_time_t to refer to it instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The structure itself is not deprecated. However, we want to use lrmd_t
to refer to it instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2
Copy link
Contributor Author

nrwahl2 commented Feb 5, 2026

It would also be worth adding something to doc/sphinx/Pacemaker_Development/c.rst explaining this. I'm hoping one day we'll have someone new on the team and we can point them at that instead of having to re-explain all this stuff.

The development guide already says enums shouldn't have a typedef at all, and that they don't require any special naming convention. So really we should have enum crm_exit or enum crm_exit_code rather than enum crm_exit_e or crm_exit_t. Though I didn't feel like going that far, since we use crm_exit_t in tons of places internally and in function signatures.

I'll add a note for structs.

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