Repository navigation
fs: add umount_all() to force-unmount all mountpoints - #22013
Merged
Merged
Conversation
jingfei195887
requested review from
Donny9,
GUIDINGLI,
anchao,
jerpelea,
pkarashchenko and
xiaoxiang781216
as code owners
November 18, 2026 15:22
|
Add umount_all() in fs/mount/fs_umount2.c for the reboot/poweroff path, where every mountpoint must be force-unmounted so that each filesystem's unbind() runs (e.g. metadata a filesystem only writes at unmount), which a bare sync() does not reach. umount_all() drives the existing foreach_mountpoint() enumerator and takes the inode write lock once for the whole drain. nx_umount2() takes the write lock again inside the callback, but the NuttX rwsem is recursive for the current writer (holder == tid), so the nested acquisition does not deadlock. The traversal now visits children before their parent and saves the sibling link before each callback, so the callback may unmount and free the inode it is handed. A mountpoint that cannot be unmounted (e.g. a read-only or proxy filesystem whose unbind returns an error) is left in the tree and stepped over, so a single traversal always terminates. nx_umount2() also calls syncfs() before unbind(). No dynamic allocation is used on this path. Signed-off-by: jingfei <[email protected]>
umount_all() drives foreach_mountpoint() with the inode write lock held for the whole traversal. mountpoint_filter() issued a statfs() on every mountpoint inside that lock. For a proxy filesystem whose statfs is a blocking cross-core RPC, the reboot thread then waits (no timeout) for a reply while holding the write lock, and the peer core cannot make progress because the handler that serves its requests is itself blocked on the same lock as a reader -- a ring wait that hangs the system. statfs is not needed by the traversal itself. Make foreach_mountpoint_t hand only the mountpoint path; the only consumer that needs statfs (procfs fs/mount, fs/blocks, fs/usage) now calls statfs() itself, under its own read-lock traversal where recursive read is safe. This also unmounts mountpoints whose fs has no statfs method, which the old statfs-gated filter silently skipped. Signed-off-by: jingfei <[email protected]>
jingfei195887
force-pushed
the
fs/umount-all
branch
from
November 18, 2026 17:30
7800d6d to
ce60493
Compare
xiaoxiang781216
approved these changes
Nov 19, 2026
jerpelea
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fs: add umount_all() to force-unmount all mountpoints.
Add an fs-internal
umount_all()infs/mount/fs_umount2.cfor thereboot/poweroff path. It force-unmounts every mountpoint so that each
filesystem's
unbind()runs, which a plainsync()does not reach.umount_all()drivesforeach_mountpoint()with the inode write lockheld for the whole traversal.
foreach_inode()andforeach_mountpoint()get areadonlyargument that selects the readlock (as before) or the write lock.
nx_umount2()takes the write lockagain inside the callback, which is safe because the rwsem is recursive
for the current writer. The traversal now visits children before their
parent and saves the sibling link before each callback, so a callback may
unmount and free the inode it is handed. A mountpoint that cannot be
unmounted is left in the tree and stepped over.
nx_umount2()also callsthe filesystem's
syncfsbeforeunbind().fs/mount: drop statfs from mountpoint traversal.
mountpoint_filter()calledstatfson every mountpoint while thetraversal lock was held. With the write lock taken by
umount_all(), afilesystem whose
statfsblocks on a remote peer can deadlock with thatpeer.
foreach_mountpoint_tnow passes only the path; the procfsfs/mount,fs/blocksandfs/usagehandlers callstatfs()themselves. Mountpoints without a
statfsmethod are no longer skippedby the traversal.
umount_all()has no caller in the tree yet; it is intended for thefilesystem reboot notifier.
Note: this changes the signature of the fs-internal
foreach_inode().#21999 adds a new
foreach_inode(mountpt_syncfs, NULL)call infs/vfs/fs_sync.c. Whichever of the two PRs lands second has to berebased and pass
true(read lock) there.Impact
umount_all(); fs-internalforeach_inode(),foreach_mountpoint()andforeach_mountpoint_tsignatures change. No public API change.
umount2()now callssyncfsbeforeunbind(). The mountlistings in procfs are unchanged.
Testing
Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0.
sim:nshwith tmpfs, hostfs and procfs, and a small test app whoseumountallcommand callsumount_all()(flat build):Testing logs before change (master fc8d354,
umount_all()absent):Testing logs after change:
The
cat /proc/fs/mountoutput is identical before and after the change../tools/checkpatch.sh -g master..HEAD: all checks pass.sim:nshwithCONFIG_FS_PROCFSandCONFIG_FS_TMPFS: Make and CMakebuilds pass with no new warnings in the changed files;
ostestexitswith status 0.
PR verification Self-Check