xiaoxiang781216 opened a new pull request, #20107:
URL: https://github.com/apache/nuttx/pull/20107
## Summary
- Rework `lio_listio()` to link all requests of a batch into a list before
submitting any I/O; `aio_signal()` then removes each completed node under
`aio_lock()` and notifies the caller only when the list becomes empty. This
fixes the thread-unsafe "submit first, set up notification state later"
ordering of the old implementation.
- Fix a family of crashes around the new `lio_link` machinery:
uninitialized/overwritten list nodes (use `list_clear_node()` for non-batch
operations, call the new `aio_read_internal()`/`aio_write_internal()` from
`lio_listio()` to preserve list membership), a NULL-aiocbp dereference when no
I/O could be queued, and an invalid `list_delete()` for failed submissions in
`LIO_WAIT` mode.
- Fix `aioc` use-after-free: the I/O workers decanted (freed) the container
before signaling completion; `aioc_decant()` now runs after `aio_signal()`.
- Fix `aio_cancel()`: endless loop when cancelling already-running I/O, and
missing `EBADF` validation of the file descriptor (`file_get()`/`file_put()`).
- Align `aio_read()`/`aio_write()`/`aio_error()` return values with POSIX:
`-1` + `errno = EINVAL` for rejected requests (also retrievable via
`aio_error()`), but `0` with the error reported through `aio_error()` for a bad
file descriptor.
- `aio_suspend()` now re-checks the completion list after every wakeup so a
SIGPOLL from unrelated AIO no longer causes a spurious return, and the timeout
is honored across wakeups.
- Reject a NULL `aiocbp` in `aio_fsync()` (POSIX Issue 6 removed the NULL
special case).
- Make the `lio_listio()` prototype match POSIX (`restrict` qualifiers,
unnamed parameters).
- Add a configurable `CONFIG_FS_AIO_LISTIO_MAX` (default 10), validate
`nent` against `{AIO_LISTIO_MAX}` in `lio_listio()`, and report it via
`sysconf(_SC_AIO_LISTIO_MAX)`.
- Move `lio_listio.c` from `libs/libc/aio` to `fs/aio` so the whole AIO
implementation lives in one directory.
## Impact
- All changes are confined to `fs/aio/`, `libs/libc/aio/`, `include/aio.h`,
`include/limits.h`, `libs/libc/libc.csv` and `libs/libc/unistd/lib_sysconf.c`;
no new dependencies.
- `struct aiocb` layout changes (the unused `aio_priv` field is replaced by
`lio_link`/`lio_sigevent`/`lio_sigwork`) — ABI-affecting for out-of-tree users
of `include/aio.h`, which is why this is submitted as one series.
- `lio_listio()` prototype gains `restrict` qualifiers per POSIX; existing
callers compile unchanged.
## Testing
- `sim:nsh` with `CONFIG_FS_AIO=y`, `CONFIG_TESTING_OSTEST=y`,
`CONFIG_TESTING_OSTEST_AIO=y`: build is warning-free; the full `ostest` run
exits with status 0 and the AIO test reports all 7 cases (poll, LIO_WAIT,
aio_suspend, individual signals, list completion signal, cancel by aiocb,
cancel by fd) successful:
```
user_main: AIO test
AIO test case 1: Poll for transfer complete
...
AIO test case 7:Cancel I/O by file descriptor
aio_cancel return 1
...
aio_test: Test completed successfully
ostest_main: Exiting with status 0
```
- `tools/checkpatch.sh -c -u -m -g` passes for the whole series.
--
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]