Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML refactors/deprecations: crm_foreach_xpath_result() to pcmk__xml_tracking_changes() #3851

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

nrwahl2
Copy link
Contributor

@nrwahl2 nrwahl2 commented Mar 21, 2025

@clumens Here's the next batch of 20 commits. Enjoy.

nrwahl2 added 20 commits March 21, 2025 13:39
PCMK_XA_FILE was misused in two places to refer to an XML element.

Signed-off-by: Reid Wahl <[email protected]>
To replace crm_foreach_xpath_result().

We can add a reverse argument later if needed.

Note that all internal callers are passing XPath expressions that can
only match elements. So we don't have to worry about the "return an
element for an attribute, etc." logic that we were using in the past via
crm_foreach_xpath_result() -> pcmk__xpath_match_element() (or
getXpathResult() farther in the past).

Signed-off-by: Reid Wahl <[email protected]>
Now all internal callers call get_xpath_object() with XPath expressions
that can only match elements. This avoids the need to rely on the
strange pcmk__xpath_match_element() logic when we replace
get_xpath_object() with an internal function.

Signed-off-by: Reid Wahl <[email protected]>
To replace get_xpath_object().

get_xpath_object() dereferences its xmlNode argument without
NULL-checking it. So the fact that we now dereference it in all of the
callers to get its doc member, shouldn't cause any NEW problems. Later,
in per-function best practices commits, we should NULL-check the
arguments where appropriate.

Signed-off-by: Reid Wahl <[email protected]>
I think the only unused headers we want to include are the ones that
xml.h is a wrapper for: xml_*.h, minus internal headers.

Update other files that break as a result, that were depending on the
transitive includes.

Signed-off-by: Reid Wahl <[email protected]>
It saves a little bit of space, but it obfuscates what we're doing.

Signed-off-by: Reid Wahl <[email protected]>
IMO this makes it clearer that we're setting flags for a particular
document. It has nothing to do with any particular node within the
document; we were using the node argument only to access its doc member.

Also add doxygen, rename to pcmk__xml_doc_set_flags(), and take a
uint32_t argument instead of an enum (since it may be a group of
multiple flags).

Signed-off-by: Reid Wahl <[email protected]>
Most of these changes are straightforward because all but one caller
passed false as the lazy argument. This is equivalent to checking the
the pcmk__xf_tracking flag on the node's doc.

One caller passes true, which also checks the pcmk__xf_lazy flag.

It's probably worth renaming pcmk__xf_lazy to something with clearer
meaning later.

Signed-off-by: Reid Wahl <[email protected]>
This makes no practical difference, but it classifies these two defects
as "false positives" rather than as "intentional" (the default).

I'm leaving the other coverity code-line annotations alone, because most
or all of them are being addressed by other concurrent pull requests.

https://documentation.blackduck.com/bundle/coverity-docs/page/customizing_coverity/topics/annotations/c_annotations_c_cpp_code-line.html#annotations_c_cpp_code-line_annotations

Signed-off-by: Reid Wahl <[email protected]>
For clarity of purpose. Also improve doc comments for several private
XML struct types.

Signed-off-by: Reid Wahl <[email protected]>
This isn't necessary, but it's convenient. The force argument passes
through to pcmk__xa_remove(), which pcmk__xe_remove_matching_attrs()
calls.

The motivation is xml_accept_changes(). Previously, we checked the
document's pcmk__xf_dirty flag, cleared all the document's flags, and
then accepted attr deletions throughout the tree. There was a hidden
ordering dependency there. If we did not clear the document's flags
before accepting the tree's attr deletions, then the document's
pcmk__xf_tracking flag would still be enabled. In that case,
pcmk__xa_remove() wouldn't actually remove the deleted attributes. It
would just set their pcmk__xf_deleted flag... which was already set.

Now, we check the doc's flag, accept attr deletions throughout the tree
if set, and then clear everything in the doc that needs to be cleared.

On the flip side, adding another argument is mildly inconvenient for
other callers. Oh well.

Signed-off-by: Reid Wahl <[email protected]>
@nrwahl2 nrwahl2 requested a review from clumens March 21, 2025 20:51
@@ -349,7 +349,7 @@ create_async_command(xmlNode *msg)
return NULL;
}

op = get_xpath_object("//@" PCMK__XA_ST_DEVICE_ACTION, msg, LOG_ERR);
op = get_xpath_object("//*[@" PCMK__XA_ST_DEVICE_ACTION "]", msg, LOG_ERR);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look carefully through this commit please, and anything else that modifies actual XPath expressions. We're not going to get a compile time error for bad XPath syntax, or for good syntax that no longer matches what we want to.

* \internal
* \brief Information about an XML node that is marked as deleted
*
* When change tracking is enabled and we delete an XML node, we simply mark
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, this is wrong. We actually do delete it in free_xml_with_position().

} pcmk__deleted_xml_t;

/*!
* \internal
* \brief Private data for an XML document
Copy link
Contributor Author

Choose a reason for hiding this comment

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

s/document/node/

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.

1 participant