Repository navigation
src/mon/MgrStatMonitor: fix invalid iterator increment in calc_pool_availability() - #63398
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an invalid iterator increment in calc_pool_availability() by using std::erase_if for atomic removals and refactors loops to structured bindings for clarity.
- Replace manual erase-in-loop with
std::erase_ifto avoid invalidated iterators. - Refactor pool-add and stats-update loops to use structured bindings.
Comments suppressed due to low confidence (2)
src/mon/MgrStatMonitor.cc:74
- [nitpick] Using
_as a placeholder can be unclear or conflict with other code; consider naming itunusedor annotating with[[maybe_unused]].
for (auto [poolid, _] : digest.pool_pg_unavailable_map) {
src/mon/MgrStatMonitor.cc:82
- Consider adding unit tests for
calc_pool_availability()to cover pool addition, removal, and status transitions to prevent regressions.
std::erase_if(pool_availability, [&](auto& kv) {
a44b1ef to
b09e266
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR addresses invalid iterator usage in calc_pool_availability() by switching to atomic erasure and cleaning up loop logic.
- Use
std::erase_ifto remove stale pools safely - Refactor addition and stats‐update loops with structured bindings and clear iterator increments
Comments suppressed due to low confidence (1)
src/mon/MgrStatMonitor.cc:82
- The new removal logic using
std::erase_ifand the subsequent availability updates lack unit tests to verify pool addition, removal, and status transitions; consider adding coverage for these cases.
std::erase_if(pool_availability, [&](auto& kv) {
There was a problem hiding this comment.
Using operator[] on digest.pool_pg_unavailable_map for a lookup can inadvertently insert default entries; consider using find or at to avoid side-effects on the map.
| const bool currently_avail = digest.pool_pg_unavailable_map[poolid].empty(); | |
| auto it = digest.pool_pg_unavailable_map.find(poolid); | |
| const bool currently_avail = (it != digest.pool_pg_unavailable_map.end()) && it->second.empty(); |
There was a problem hiding this comment.
@NitzanMordhai - copilot may have a point here. If you are sure you are not inserting - maybe add a comment explaining?
There was a problem hiding this comment.
@ronen-fr, it sounds reasonable. will change it
There was a problem hiding this comment.
as we are still C++-20: don't you get 'unused' warnings for the '_'?
If so - maybe mark it as [[maybe_unused]]] ?
There was a problem hiding this comment.
can it be
(const auto& kv)
?
There was a problem hiding this comment.
I'd suggest using fmt::format() for the whole modified code.
|
LGTM, but note Copilot's comment (and some nits). |
b09e266 to
6e4b99c
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an invalid iterator usage in calc_pool_availability() by replacing the unsafe removal loop with std::erase_if and refactoring the stats-update loop for clarity.
- Replace manual iterator increment and erasure with an atomic removal using std::erase_if
- Refactor loops to use structured bindings and clearer logging
Comments suppressed due to low confidence (1)
src/mon/MgrStatMonitor.cc:105
- Accessing it->second when it equals digest.pool_pg_unavailable_map.end() leads to undefined behavior. Consider splitting the condition to first check if the iterator is not equal to end before accessing its second element.
const bool currently_avail = (it == digest.pool_pg_unavailable_map.end()) && it->second.empty();
6e4b99c to
db90c27
Compare
|
fixing the currently_avail . |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an invalid iterator increment in calc_pool_availability() by refactoring the pool availability update loop and using std::erase_if to safely remove pools during iteration. Key changes include:
- Replacing the manual iterator erase pattern with std::erase_if.
- Refactoring loops to leverage structured bindings and clearer logging.
- Updating logging to use fmt::format for consistency.
There was a problem hiding this comment.
[nitpick] Ensure that the use of fmt::format for logging is consistent with the remainder of the codebase so that logging remains uniform across modules.
| dout(20) << fmt::format("{}", __func__) << dendl; | |
| dout(20) << __func__ << dendl; |
c05d19f to
d6dc687
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an invalid iterator increment issue in calc_pool_availability() by using std::erase_if to atomically remove invalid pool entries and refactors the stats-update loop for better clarity and maintainability.
- Replace manual iterator handling with std::erase_if for safe removal.
- Use structured bindings and clearer iterator increments.
- Improve logging messages via fmt::format for enhanced readability.
|
@shraddhaag please take a look |
|
Ping @shraddhaag. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
|
Just need to rebase. |
d6dc687 to
98be774
Compare
…vailability() Erasing entries from `pool_availability` inside a range-for loop invalidated the hidden iterator, triggering an “Invalid read” under Valgrind. - Use `std::erase_if(pool_availability, predicate)` for atomic removal. - Refactor the stats-update loop to use structured bindings and a clear `++it` for readability. Fixes: https://tracker.ceph.com/issues/71271 Signed-off-by: Nitzan Mordechai <[email protected]>
98be774 to
7369a4d
Compare
|
jenkins test make check |
|
jenkins test api |
|
jenkins test make check arm64 |
Erasing entries from
pool_availabilityinside a range-forloop invalidated the hidden iterator, triggering an
“Invalid read” under Valgrind.
std::erase_if(pool_availability, predicate)foratomic removal.
and a clear
++itfor readability.Fixes: https://tracker.ceph.com/issues/71271
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition