DawnLiu66 opened a new pull request, #21822:
URL: https://github.com/apache/nuttx/pull/21822

   ## Summary
   
   tmpfs implements only `read`/`write`, so the VFS emulates `readv`/`writev`
   in `file_readv_compat()`/`file_writev_compat()` by calling them once per
   iovec. Every call takes and drops the file lock and advances `f_pos` on its
   own, so another thread can read or write the same file between two iovecs of
   one `readv()`/`writev()`.
   
   - **fs/tmpfs: select FS_UIO.** The next commit makes tmpfs implement only
     `readv`/`writev`, which needs `uio_copyfrom()`/`uio_copyto()`.
   - **fs/tmpfs: implement readv/writev natively.** Copy between the tmpfs 
memory
     buffer and the whole iovec array with `uio_copyfrom()`/`uio_copyto()`
     under one lock. `read()`/`write()` keep working because the VFS turns them
     into a single-iovec `readv()`/`writev()` when `read`/`write` are NULL.
   
   ## Impact
   
   - New feature: NO.
   - User adaptation: NO.
   - Build: YES, `CONFIG_FS_TMPFS` now selects `CONFIG_FS_UIO`
     (`fs/vfs/fs_uio.c`). Most configurations already have it through
     `CONFIG_SERIAL`.
   - Hardware: NO.
   - Documentation: NO.
   - Security: NO.
   - Compatibility: one `readv()`/`writev()` on a tmpfs file is now one locked
     operation.
   
   ## Testing
   
   I confirm that changes are verified on local setup and works as intended:
   
   - Build Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0,
     master `562db43781`.
   - Target: `sim:nsh` with `CONFIG_FS_TMPFS`. Verified on sim only, no real
     hardware.
   - `./tools/checkpatch.sh -m -g master..HEAD`: all checks pass.
   - Make and CMake builds pass, `ostest` exits with status 0. Each commit
     builds on its own.
   
   A small test program mounts a tmpfs and:
   
   1. writes 15 bytes with a 3-iovec `writev()` and reads them back with a
      2-iovec `readv()`;
   2. starts two threads that each append 2000 records of two 64-byte iovecs
      (`'A'` or `'B'`) with `writev()`, then counts records whose bytes are
      not all the same.
   
   Testing logs before change:
   
   ```
   writev()=15 readv()=15 data=abcdefghijklmno -> ok
   concurrent writev(): 4000 records, 0 interleaved
   concurrent writev(): 4000 records, 0 interleaved
   concurrent writev(): 4000 records, 0 interleaved
   ```
   
   Testing logs after change:
   
   ```
   writev()=15 readv()=15 data=abcdefghijklmno -> ok
   concurrent writev(): 4000 records, 0 interleaved
   concurrent writev(): 4000 records, 0 interleaved
   concurrent writev(): 4000 records, 0 interleaved
   ```
   
   Data is correct before and after. The interleaving cannot be reproduced on
   `sim:nsh`: the threads do not preempt each other inside one `writev()`, so
   both runs show 0 interleaved records.
   
   ## 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]

Reply via email to