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

   ## Summary
   
   This PR is a rework of the NuttX file descriptor implementation. The
   goal is two-fold:
   
   1. Improve POSIX compliance. The old implementation tied file description
   to inode only, not the file struct. POSIX however dictates otherwise.
   2. Fix a bug with descriptor duplication (dup2() and dup3()). There is
   an existing race condition with this POSIX API that currently results
   in a kernel side crash.
   
   The crash occurs when a partially open / closed file descriptor is
   duplicated. The reason for the crash is that even if the descriptor is
   closed, the file might still be in use by the kernel (due to e.g. ongoing
   write to file). The open file data is changed by file_dup3() and this
   causes a crash in the device / drivers themselves as they lose access to
   the inode and private data.
   
   The fix is done by separating struct file into file and file descriptor
   structs. The file struct can live on even if the descriptor is closed,
   fixing the crash. This also fixes the POSIX issue, as two descriptors
   can now point to the same file.
   ## Impact
   
   The impact is big, this is basically a re-write of the file descriptor 
subsystem, so the possibility of regression is big.
   This change also removes the option for CONFIG_FS_REFCOUNT, since it is not 
possible to implement the new descriptor logic without the reference counter.
   
   User: The impact to user is opaque, with the exception of the removed 
CONFIG_FS_REFCOUNT option.
   Documentation: Documentation impact is not clear, depends on the level of 
documentation for the old vfs implementation
   Security: none
   Build system: none
   
   ## Testing
   
   Tested on MPFS target with KERNEL_BUILD=y, SMP=y and 100+ threads
   rv-virt:nsh64 ostest
   rv-virt:knsh64 ostest
   rv-virt:smp64 ostest
   rv-virt:ksmp64 ostest
   
   The motivation for this change can be found here:
   https://github.com/apache/nuttx/pull/16326
   
   There are also open questions about some calls to e.g. file_dup2, it was not 
clear to me how to handle these.


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to