Skip to content

Conversation

@clumens
Copy link
Contributor

@clumens clumens commented Nov 26, 2025

No description provided.

Instead of including any of the pcmki/pcmki_* headers, you should
include the top-level pacemaker-internal.h instead.  And then fix the
one place that wasn't following this rule.

Ref T777
...and remove a couple that are no longer needed.
This is the first part of a project to reduce crm/common/internal.h to a
file that basically just includes all the other internal files.  After
that, we can then use the #error technique to make sure the subheaders
are not included anywhere.  But first, we need to move everything out of
this header to avoid circular imports.

Ref T777
This provides a place for internal mainloop related functions from
crm/common/internal.h to be moved to.

Ref T777
This provides a place for internal flag-related functions from
crm/common/internal.h to be moved to.

Ref T777
This provides a place for internal memory elated functions from
crm/common/internal.h to be moved to.  I've also moved pcmk__mem_assert
from results_internal.h to this file since it feels memory related, but
I've left pcmk__assert and pcmk__abort_as.  Those don't really belong in
that file, but I can't think of anywhere else to put them at the moment.

Ref T777
This provides a place for internal procfs-related functions from
crm/common/internal.h to be moved to.

Ref T777
...and into scores_internal.h where they belong.

Ref T777
...and into lists_internal.h where they belong.

Ref T777
This provides a place for internal miscellaneous functions from
crm/common/internal.h to be moved to.  I kind of hate ever having a file
named utils, but this lines up with the C file in lib/common/.

Ref T777
This provides a place for internal process-related functions from
crm/common/internal.h to be moved to.

Ref T777
...and into failcounts_internal.h where they belong.  Additionally,
logging.h needs to include results.h because CRM_CHECK uses crm_abort.
It would be worth going through all these header files and make sure
they include everything they need, but that's a project for a different
day.

Ref T777
This provides a place for internal cibsecrets-related functions from
crm/common/internal.h to be moved to.

Ref T777
It's defined in logging.c in libcrmcommon, so this is a natural place
for the extern line to go.

Ref T777
…aders.

A couple of the subheaders need to be fixed to avoid the circular
includes, but it's much better now than it was before all those previous
patches to split things out of internal.h.

I'm leaving PCMK__NELEM in here because I can't think of a better place
for it (maybe utils_internal.h?) and it's not really doing any harm
here.

I've intentionally left out a couple headers:

* unittest_internal.h - This is specific to unit testing and doesn't
  really have anything to do with public vs. private API.  The
  _internal.h part of its name is mostly meant to make sure it's not
  included in the source distribution by Makefile.am

* various XML headers - xml_internal.h is meant to wrap including all of
  those, so they don't need to be separately listed.

Ref T777
Now that crm/common/internal.h includes all the private header files,
crm_internal.h can include just that one.

Ref T777
...headers directly.

Instead of including any of the crm/common/*_internal.h headers, you
should include the top-level crm/common/internal.h instead.  And then
fix the many, many places that were including these headers.

Note that the #ifdef/#error/#endif blocks need to go above any of the
multiple inclusion guards.  This is because every file includes
crm_internal.h first, which includes crm/common/internal.h, which
includes all the internal headers, which causes the multilple inclusion
guards to be set.  Then when those internal headers are included
directly later on, the guards will prevent the file from being included
and also prevent the #error from happening.

Ref T777
This needs to be defined or else testing internal headers will fail due
to the #error preprocessor directives.
@clumens clumens changed the title Prevent directly including top-level internal headers Prevent directly including lower-level internal headers Nov 26, 2025
@nrwahl2 nrwahl2 self-requested a review November 26, 2025 22:08
@clumens
Copy link
Contributor Author

clumens commented Nov 26, 2025

This is an experiment to see if we can easily have a library-level main internal header file that includes all the subheaders, and then prevent anyone from directly including those subheaders. It's not foolproof, of course, but it just needs to be good enough to prevent us from making mistakes during development.

I only converted two of the private library-level header files over, and only did a little bit of reorganization of #include blocks. There's an almost endless amount of cleanups that could be done on those blocks, and I don't think it's worth doing one giant PR that fixes it all. We can deal with that stuff as we go along.

I think especially with <crm/common/internal.h>, we could have some discussion about whether or not we want one giant main header that everything includes, or if we maybe want xml_internal.h to be includeable too. We could potentially also have an IPC related includeable header file, and maybe or or two more.

@clumens clumens changed the title Prevent directly including lower-level internal headers Prevent directly including some internal subheader files Nov 26, 2025
@nrwahl2 nrwahl2 added the review: in progress PRs that are currently being reviewed label Dec 18, 2025
#include <crm/common/io_internal.h>
#include <crm/common/iso8601_internal.h>
#include <crm/common/mainloop_internal.h>
#include <crm/common/memory_internal.h>
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 commit message: "memory elated"

pcmk__assert and pcmk__abort_as could go in a utils_internal.h I guess. I think they live in results because they're abnormal-exit functions, and crm_exit lives in results.

Edit: I see you did create such a file.

Copy link
Contributor

Choose a reason for hiding this comment

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

utils_internal.h also seems like a very reasonable place for PCMK__NELEM()

#ifndef PCMK__PACEMAKER_INTERNAL__H
#define PCMK__PACEMAKER_INTERNAL__H

#define PCMK__DIRECT_INCLUDE
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should do these per-header. Like PCMK__DIRECT_INCLUDE_PCMKI or PCMK__IN_PACEMAKER_INTERNAL_H or something. (PCMK__DIRECT_INCLUDE_PACEMAKER_INTERNAL__H feels too long but it's even clearer.)

We already have PCMK__PACEMAKER_INTERNAL__H, etc., but those remain defined at the end of the header. We need one that we #undef at the end, as we're doing here with PCMK__DIRECT_INCLUDE.

My thinking is that we don't want any OTHER header that defines PCMK__DIRECT_INCLUDE to be able to include these sub-header files.

@@ -0,0 +1,31 @@
/*
* Copyright 2025 the Pacemaker project contributors
Copy link
Contributor

Choose a reason for hiding this comment

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

Thus far (meaning when Ken was here), we've been conservatively keeping the old copyright date from the file that we split contents out from -- so 2004-2025 in this case. The idea has been that the code is old even though the file is new. Copyright is "current year only" when all the contents of the file are new.

I don't have strong feelings about it, and I don't know to what extent the copyright notices matter.

This comment applies to other new files in this PR as well -- take it or leave it :)

*/
GList *pcmk__subtract_lists(GList *from, const GList *items,
GCompareFunc cmp);
GList *pcmk__subtract_lists(GList *from, const GList *items,GCompareFunc cmp);
Copy link
Contributor

Choose a reason for hiding this comment

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

space between comma and GCompareFunc

#ifndef PCMK__CRM_COMMON_INTERNAL__H
#define PCMK__CRM_COMMON_INTERNAL__H

#include <stdbool.h> // bool
Copy link
Contributor

Choose a reason for hiding this comment

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

extern bool pcmk__is_daemon is still present

Copy link
Contributor

Choose a reason for hiding this comment

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

goes away in a later commit

#include <crm/cib.h>
#include <crm/common/xml.h>
#include <crm/cluster.h>
#include <crm/common/ipc_internal.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this one be replaced by crm/common/internal.h?

*/

#ifndef PCMK__DIRECT_INCLUDE
#error "Include <crm/common/internal.h> instead of <acl_internal.h> directly"
Copy link
Contributor

Choose a reason for hiding this comment

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

These messages all say "...instead of <basename.h> directly". In the pcmki commit, the messages say "...instead of <pcmki/basename.h> directly". We don't have to be consistent, but I do want to point it out.


#include <crm/common/scheduler.h>
#include <crm/common/output_internal.h>
#include <crm/common/internal.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

above scheduler.h if we want alphabetical order

#include <crm/services.h>
#include <crm/common/xml.h>
#include <crm/common/mainloop.h>
#include <crm/common/output_internal.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

We've been mostly replacing these with crm/common/internal.h in header files. It's up to you -- we can leave it out and rely on the <crm_internal.h> include at the top.

#include <crm/pengine/status.h>
#include <pacemaker-internal.h>

#include "crm/common/util.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we dropping the includes of util.h and xml.h here?

@nrwahl2 nrwahl2 removed the review: in progress PRs that are currently being reviewed label Dec 18, 2025
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