jingfei195887 opened a new pull request, #22113:
URL: https://github.com/apache/nuttx/pull/22113
## Summary
Two commits that let a remote file system server wait for an advisory lock
without blocking its request thread, and use it in rpmsgfs.
- **fs/vfs: add file_setlk_async for non-blocking advisory locks.**
`file_setlk_async()` parks a caller-owned waiter on the lock bucket when
the request conflicts; its callback runs, outside the internal lock, once
a later release grants the lock. `file_setlk_cancel()` removes a pending
waiter. Waiters dropped by `close()` complete with `-EBADF`.
`file_setlk()` is built on top of it: a blocking call parks a stack waiter
whose callback posts a local semaphore, which replaces the per-bucket
semaphore and waiter count. The API is private to `fs/` (`fs/vfs/vfs.h`).
Current master semantics are kept: a signal still ends `F_SETLKW` with
`EINTR` (the pending request is cancelled, e4d34248379), and a conflict
still compares the owning file as well as the thread (726dd10bcd0).
- **fs/rpmsgfs: block FIOC_SETLKW instead of polling.**
The client turned `FIOC_SETLKW` into `FIOC_SETLK` and retried every
20 ms. It now forwards `FIOC_SETLKW`; the server parks a request that
cannot be taken with `file_setlk_async()` and sends the reply when the
lock is granted, so only the calling thread waits and the server's rx
thread is not blocked. Pending requests are cancelled when the endpoint
is released.
## Impact
- New feature / API change: new fs-internal `file_setlk_async()` /
`file_setlk_cancel()`; no public API change.
- Behavior: local `fcntl()` locking is unchanged. Over rpmsgfs, a blocked
`F_SETLKW` sends one request instead of one every 20 ms, and returns when
the server grants the lock.
- Unchanged by this PR: the rpmsgfs client wait (`rpmsg_wait()`) is not
interruptible, so a signal does not end an `F_SETLKW` over rpmsgfs (the
polling loop on master did not end on a signal either).
- Only built with `CONFIG_FS_LOCK_BUCKET_SIZE > 0`; `sim:rpserver` and
`sim:rpproxy` defaults (bucket size 0) still build.
- Build, hardware, documentation, security, compatibility: NO.
## Testing
Host: Ubuntu 22.04 x86_64, gcc 13.1.0. Base: master 20a363b9404.
**Local locks** (`sim:nsh`, `CONFIG_FS_TMPFS`,
`CONFIG_FS_LOCK_BUCKET_SIZE=16`): a thread holds a write lock on a tmpfs
file for 100 ms while the main thread waits with `F_SETLKW` (3 rounds),
then a 500 ms hold is interrupted by `SIGUSR1` after 200 ms. Same result on
master, on this PR, and with the first commit alone:
```
setlkw: round 0 ret=0 blocked wake=0ms
setlkw: round 1 ret=0 blocked wake=0ms
setlkw: round 2 ret=0 blocked wake=0ms
setlkw: signal ret=-1 errno=4 before-release
```
**Over rpmsgfs** (`sim:rpserver` + `sim:rpproxy`, both with
`CONFIG_FS_LOCK_BUCKET_SIZE=16`): the server locks `/tlk/lk` on a tmpfs for
10 s; the proxy mounts the server's `/tlk` with rpmsgfs and waits for the
same lock with `F_SETLKW`. The number of lock requests reaching the server
was counted with a temporary log line in `rpmsgfs_ioctl_handler()` (not part
of this PR).
| | proxy `F_SETLKW` | requests seen by the server |
|---|---|---|
| master | `ret=0 blocked=5971ms` | 151 x `FIOC_SETLK` (150 polls + unlock) |
| this PR | `ret=0 blocked=5960ms` | 1 x `FIOC_SETLKW` + 1 x `FIOC_SETLK`
(unlock) |
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_FS_TMPFS`, `CONFIG_FS_LOCK_BUCKET_SIZE=16`,
`CONFIG_RPTUN`, `CONFIG_FS_RPMSGFS`, `CONFIG_FS_RPMSGFS_SERVER`: Make and
CMake builds pass with no warnings in the changed files; `ostest` exits
with status 0. Each commit builds on its own.
- 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]