Fix FDs becoming invalid once their file is unlinked#6467
Fix FDs becoming invalid once their file is unlinked#6467Arshia001 wants to merge 14 commits intowasmerio:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes cases where unlinking a file could invalidate existing open handles (FDs), aligning VirtualFile::unlink() behavior with expected POSIX-like semantics (path removed, handle remains usable until last close).
Changes:
- Add lifecycle tracking to
mem_fsinodes so unlinked files remain backed while handles are open, and are reclaimed on last-handle drop. - Adjust
overlay_fsto support unlinking files opened from secondaries without breaking the open handle, including COW/unlink interactions. - Add new regression tests (Rust unit tests + WASIX C test + harness script) covering write/read after unlink.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/wasix/unlink-open-fd-write-after-unlink/run.sh | Adds a WASIX test runner asserting expected stdout and host-volume behavior. |
| tests/wasix/unlink-open-fd-write-after-unlink/main.c | New WASIX regression reproducer verifying handle validity across unlink + recreate. |
| lib/virtual-fs/src/overlay_fs.rs | Adds SecondaryFile wrapper and updates COW unlink behavior; adds overlay-specific regression tests. |
| lib/virtual-fs/src/mem_fs/mod.rs | Introduces FileLifecycle and threads it through inode node types. |
| lib/virtual-fs/src/mem_fs/filesystem.rs | Centralizes unlink behavior via unlink_file_inode and updates tests for unlinked-but-open retention. |
| lib/virtual-fs/src/mem_fs/file_opener.rs | Plumbs lifecycle into opened handles and newly created nodes. |
| lib/virtual-fs/src/mem_fs/file.rs | Tracks handle open/close and reclaims storage on last-handle drop after unlink; expands tests. |
| lib/virtual-fs/src/lib.rs | Clarifies VirtualFile::unlink() semantics in trait documentation. |
syrusakbary
left a comment
There was a problem hiding this comment.
@theduke will be better at reviewing this
theduke
left a comment
There was a problem hiding this comment.
I found two correctness issues in the new overlay unlink handling.
|
This PR seems like fixing that as well #6431 |
|
@Arshia001 can you add a few unit tests to avoid regressions? Here one Wasix (i've just created it before I've remembered about your PR :)) #include <assert.h>
#include <fcntl.h>
#include <unistd.h>
int main(void) {
const char* path = "/tmp/wasix_fd_append_create_unlink_read.tmp";
unlink(path);
int fd = open(path, O_RDWR | O_APPEND | O_CREAT, 0600);
assert(fd >= 0);
assert(unlink(path) == 0);
char buf;
assert(read(fd, &buf, 1) == 0);
}And the a second one from #6431 (probably need to be converted to C). It's important to have those to avoid future regressions |
Shield - Regression 💩💩💩
Example crash from Rust
More changed tests
Install shield
Artifacts
|
Fixes: #6360.