Skip to content

mountinfo: fix ParentsFilter and PrefixFilter edge cases - #271

Merged
thaJeztah merged 3 commits into
moby:mainfrom
kolyshkin:mountinfo-parents-filter
Oct 26, 2026
Merged

thaJeztah merged 3 commits into
moby:mainfrom
kolyshkin:mountinfo-parents-filter

Conversation

@kolyshkin

Copy link
Copy Markdown
Collaborator
  1. ParentsFilter did a plain string prefix match, so a mount point of /a
    was considered to be a parent of /aa. Fix it to match on path components,
    similar to what commit f11a7ca did for PrefixFilter. Add a table-driven
    unit test for ParentsFilter (first commit), and test cases for the fix.

  2. PrefixFilter("/") only returned the root mount itself, as the root prefix
    becomes // after appending a slash. Fix it to return all mounts.

    Note this changes the behavior of mount.RecursiveUnmount("/") slow path:
    it used to try unmounting / only, and now it tries to unmount all mounts
    (deepest first), as documented.

ParentsFilter is only tested against the fedoraMountinfo fixture.
Add a table-driven unit test for it, similar to TestPrefixFilter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
ParentsFilter does a plain string prefix match, so, for example,
a mount point of "/a" is considered to be a parent of "/aa".

Fix it to match on path components instead, similar to what
commit f11a7ca did for PrefixFilter. The root mount point
has to be special-cased, as it already ends with a slash.

Document the requirements for the path argument, same as for
PrefixFilter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
PrefixFilter appends a slash to both the prefix and the mount point
before comparing them. For the root prefix, this results in "//",
which only matches the root mount itself, so PrefixFilter("/")
returns a single entry rather than all of them.

Since every mount point is under "/", special-case it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin force-pushed the mountinfo-parents-filter branch from 790381d to 44e556e Compare October 26, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fixes match the documented behavior and include regression coverage for the affected edge cases, with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes two mount-filter edge cases so parent matching respects path boundaries and the root prefix includes all mounts.

Changes:

  • Prevents ParentsFilter from treating /a as a parent of /aa and documents input requirements.
  • Makes PrefixFilter("/") include all mounts, aligning recursive unmount behavior with its documentation.
  • Adds regression tests for root prefixes and parent-path matching.
File Description
mountinfo/​mountinfo_filters.go Corrects both filters and clarifies parent-filter requirements.
mountinfo/​mountinfo_filters_test.go Adds root-prefix cases and table-driven parent-filter coverage.

Review effort: Balanced

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thx!

@thaJeztah
thaJeztah merged commit b3eba80 into moby:main Oct 26, 2026
25 checks passed
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.

4 participants