jingfei195887 opened a new pull request, #22013:
URL: https://github.com/apache/nuttx/pull/22013
## Summary
- **fs: add umount_all() to force-unmount all mountpoints.**
Add an fs-internal `umount_all()` in `fs/mount/fs_umount2.c` for the
reboot/poweroff path. It force-unmounts every mountpoint so that each
filesystem's `unbind()` runs, which a plain `sync()` does not reach.
`umount_all()` drives `foreach_mountpoint()` with the inode write lock
held for the whole traversal. `foreach_inode()` and
`foreach_mountpoint()` get a `readonly` argument that selects the read
lock (as before) or the write lock. `nx_umount2()` takes the write lock
again 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 calls
the filesystem's `syncfs` before `unbind()`.
- **fs/mount: drop statfs from mountpoint traversal.**
`mountpoint_filter()` called `statfs` on every mountpoint while the
traversal lock was held. With the write lock taken by `umount_all()`, a
filesystem whose `statfs` blocks on a remote peer can deadlock with that
peer. `foreach_mountpoint_t` now passes only the path; the procfs
`fs/mount`, `fs/blocks` and `fs/usage` handlers call `statfs()`
themselves. Mountpoints without a `statfs` method are no longer skipped
by the traversal.
`umount_all()` has no caller in the tree yet; it is intended for the
filesystem reboot notifier.
Note: this changes the signature of the fs-internal `foreach_inode()`.
#21999 adds a new `foreach_inode(mountpt_syncfs, NULL)` call in
`fs/vfs/fs_sync.c`. Whichever of the two PRs lands second has to be
rebased and pass `true` (read lock) there.
## Impact
- New feature / API change: new fs-internal `umount_all()`; fs-internal
`foreach_inode()`, `foreach_mountpoint()` and `foreach_mountpoint_t`
signatures change. No public API change.
- Behavior: `umount2()` now calls `syncfs` before `unbind()`. The mount
listings in procfs are unchanged.
- Build, hardware, documentation, security, compatibility: NO.
## Testing
Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0.
`sim:nsh` with tmpfs, hostfs and procfs, and a small test app whose
`umountall` command calls `umount_all()` (flat build):
```
mount -t tmpfs /t1
mount -t hostfs -o fs=/tmp/fsup_umount /h
echo hello > /t1/a.txt
cat /proc/fs/mount
fsuptest umountall
ls /h
ls /t1
ls /proc
```
Testing logs before change (master fc8d354f9a, `umount_all()` absent):
```
nsh> fsuptest umountall
umountall: not available
nsh> ls /t1
/t1:
a.txt
```
Testing logs after change:
```
nsh> cat /proc/fs/mount
/bin type binfs
/data type hostfs
/etc type romfs
/h type hostfs
/proc type procfs
/t1 type tmpfs
/tmp type tmpfs
nsh> fsuptest umountall
umountall: done
nsh> ls /h
nsh: ls: stat failed: 2
nsh> ls /t1
nsh: ls: stat failed: 2
nsh> ls /proc
nsh: ls: stat failed: 2
```
The `cat /proc/fs/mount` output is identical before and after the change.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_FS_PROCFS` and `CONFIG_FS_TMPFS`: Make and CMake
builds pass with no new warnings in the changed files; `ostest` exits
with status 0.
- Verified on sim only.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]