-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[BREAKING] fs/vfs: Separate file descriptors from file descriptions #16499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
So that the same code can be used with and without spinlocks. Signed-off-by: Ville Juven <ville.juven@unikie.com>
When a new pseudofile is created, the inode reference count needs to be bumped to protect the node. Signed-off-by: Ville Juven <ville.juven@unikie.com>
Currently the code is dumped into one massive file; fs_files. Move the different logical parts into their own files. Signed-off-by: Ville Juven <ville.juven@unikie.com> Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Previously, this config was added to ensure that the size of the struct file remained unchanged, thereby preventing the Flash memory of resource-constrained MCUs from being unnecessarily increased. However, we have now refactored the relationship between struct fd and struct file, reducing their memory footprint in both Flash and RAM. Consequently, this config can be removed. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
1. The call to file_close_without_clear in file_dup3 does not clear the tag information, so there is no need to back it up. 2. file_dup3 don't need to copy tag information, tag is only valid for fd. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
@jlaitine Our original intention was always to improve the patch as much as possible. The new PR has been revised following @pussuw the previous approach, and also maintained the original contributor as the owner of the patch. |
@pussuw Thank you. I'll continue to maintain it and address any issues that arise in the future until everything is working perfectly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a commit message to
0ec77cf
and change the title to
tools/pynuttx: update fs.py base on new structure fd and file
0ec77cf
to
4aaeb80
Compare
Done~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a commit message explaining the change
could you point out which patch need more info? @jerpelea |
update locked to f_locked Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
old: fs_getfilep, fs_putfilep, fs_reffilep new: file_get, file_put, file_ref Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch 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. Signed-off-by: Ville Juven <ville.juven@unikie.com> Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Update the Python script based on the PR "Separate file descriptors from file descriptions" in fs/vfs. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
4aaeb80
to
9b13fa4
Compare
Summary
This PR is a rework of the NuttX file descriptor implementation. The
goal is two-fold:
Improve POSIX compliance. The old implementation tied file description
to inode only, not the file struct. POSIX however dictates otherwise.
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.
The implementation of this PR is based on the modifications made in #16361.
Thank you @pussuw
DEPENDS ON: apache/nuttx-apps#3091
Impact
Testing
monkey(24 hours) and CI