jingfei195887 opened a new pull request, #22006:
URL: https://github.com/apache/nuttx/pull/22006
## Summary
- **fs: Do not sync in the reboot notifier from interrupt context.**
`reboot_notifier_call_chain()` runs an atomic notifier chain, so it can
be raised from any context. The filesystem notifier calls `sync()`, which
takes sleeping locks (for example `fs_lock` in `hostfs_sync()`). An
interrupt handler cannot wait for such a lock. Skip `sync()` when
`up_interrupt_context()` is true.
- **fs: move the reboot notifier into fs_reboot.c.**
Move the notifier out of `fs_initialize.c` into a new `fs/fs_reboot.c`,
which exports `fs_reboot_initialize()` for `fs_initialize()`. No
functional change.
## Impact
- New feature / API change: NO.
- Behavior: when `SYS_POWER_OFF` or `SYS_RESTART` is raised from interrupt
context, the filesystem notifier no longer calls `sync()`. Task context
is unchanged.
- Build: new `fs/fs_reboot.c` and `fs/fs_reboot.h`, added to both Make and
CMake.
- 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` (hostfs enabled) with a small test app. It opens a file on a
hostfs mount, writes to it and calls
`reboot_notifier_call_chain(SYS_RESTART, NULL)`, once from task context
(`reboottask`) and once from a watchdog callback, which runs in interrupt
context (`rebootisr`):
```
mount -t hostfs -o fs=/tmp/fsup_rbisr /h
fsuptest reboottask /h/reboottask.txt
fsuptest rebootisr /h/rebootisr.txt
```
The simulator ran under `strace -f -e trace=openat,close,fsync,fdatasync`
to count host `fsync()` calls on each file.
Testing logs before change (master 75cecc8b4a):
```
reboottask: notifier returned, in interrupt=0
rebootisr: notifier returned, in interrupt=1
host fsync: reboottask.txt=1 rebootisr.txt=1
```
Testing logs after change:
```
reboottask: notifier returned, in interrupt=0
rebootisr: notifier returned, in interrupt=1
host fsync: reboottask.txt=1 rebootisr.txt=0
```
On sim the hostfs lock was free, so `sync()` from the watchdog on master
completed instead of blocking. The test shows that the call is now
skipped in interrupt context and still made in task context.
The branch was then rebased onto master 59e9cbbebc (no conflicts, patches
unchanged) and the build checks below were rerun there.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` 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]