Repository navigation
Conversation
While porting the Go toolchain to WASIX, I ran into failing filesystem tests in the Go repository. These fixes let the toolchain build on WASIX. POSIX requires `open(path, O_CREAT | O_EXCL, ...)` to check and create the final directory entry atomically. If that entry exists, the call must fail with `EEXIST`, even when it is a dangling symlink. If two callers race to create the same absent file, only one can succeed. [POSIX `open()`](https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html) *The bug before this PR* `path_open2` applied ordinary symlink lookup rules to an exclusive create, so a final symlink could yield `ELOOP`. If another caller won the create race, Wasmer translated the backing filesystem’s `AlreadyExists` into `EPERM`. The overlay filesystem also cleared the exclusive flag while checking its writable layer, which could open or truncate an existing file. *This PR fixes* The fix checks the final entry without following it, returns `EEXIST` when a competing create wins, and preserves the exclusive flag in the overlay. On backends that emulate symlinks, file creation and symlink registration share a lock so they cannot both claim the same name. The overlay uses a deletion marker to hide a file from a lower layer. When a guest reuses that name for a symlink, the overlay now removes the marker only after the writable layer creates the link. If the backend needs an in-memory symlink instead, the marker stays in place. The guest can read through the link and later remove it without making the original file visible again. *Tests* - [new] `exclusive-create-symlink` opens a dangling symlink with `O_CREAT | O_EXCL`. Adding `O_NOFOLLOW` used to yield `ELOOP`. Both opens must return `EEXIST` and leave the target absent. - [new] `concurrent-exclusive-create` races two threads to create each of 32 files. The losing thread could get `EPERM`. Each race must have one winner, and the loser must get `EEXIST`. - [new] `exclusive-create-symlink-fallback` makes a file appear between lookup and create on a backend that emulates symlinks. Wasmer used to translate that collision into `EPERM`. The guest must get `EEXIST`. - [new] `create_new_preserves_existing_primary_file` requests exclusive creation with truncation. The overlay used to open the existing file while checking its writable layer. The test checks both the error and the original contents. - [new] `symlink-over-deleted-file` deletes a file, reuses its name for a symlink, reads through the link, and removes it. On the fallback backend, attempting to create the link could expose the deleted file again. The original must stay hidden throughout. - [new] `ephemeral_symlink_and_backing_create_cannot_both_claim_a_name` pauses a file create while a second caller tries to register a symlink at the same name. The file must win and the link must get `EEXIST`. Releasing the lock before the backing create made this test fail. With this PR applied, all 46 guest path tests, 19 WASIX filesystem unit tests, and 144 virtual filesystem tests passed, with two existing ignores.
vardhan
force-pushed
the
fix/wasix-exclusive-create-symlink
branch
from
November 21, 2026 17:16
207f91b to
61555fb
Compare
Author
|
hi @theduke & @Arshia001 ; would you be able to look at this PR, or provide some guidance on the fixes? happy to address any feedback! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While porting the Go toolchain to WASIX, I ran into failing filesystem tests in the Go repository. These fixes let the toolchain build on WASIX. The primary issue is that path_open2() doesn't fully adhere to posix semantics.
POSIX requires
open(path, O_CREAT | O_EXCL, ...)to check and create the final directory entry atomically. If that entry exists, the call must fail withEEXIST, even when it is a dangling symlink. If two callers race to create the same absent file, only one can succeed. POSIXopen()The bug before this PR
path_open2applied ordinary symlink lookup rules to an exclusive create, so a final symlink could yieldELOOP. If another caller won the create race, Wasmer translated the backing filesystem’sAlreadyExistsintoEPERM. The overlay filesystem also cleared the exclusive flag while checking its writable layer, which could open or truncate an existing file.This PR fixes
The fix checks the final entry without following it, returns
EEXISTwhen a competing create wins, and preserves the exclusive flag in the overlay. On backends that emulate symlinks, file creation and symlink registration share a lock so they cannot both claim the same name.The overlay uses a deletion marker to hide a file from a lower layer. When a guest reuses that name for a symlink, the overlay now removes the marker only after the writable layer creates the link. If the backend needs an in-memory symlink instead, the marker stays in place. The guest can read through the link and later remove it without making the original file visible again.
Tests
exclusive-create-symlinkopens a dangling symlink withO_CREAT | O_EXCL. AddingO_NOFOLLOWused to yieldELOOP. Both opens must returnEEXISTand leave the target absent.concurrent-exclusive-createraces two threads to create each of 32 files. The losing thread could getEPERM. Each race must have one winner, and the loser must getEEXIST.exclusive-create-symlink-fallbackmakes a file appear between lookup and create on a backend that emulates symlinks. Wasmer used to translate that collision intoEPERM. The guest must getEEXIST.create_new_preserves_existing_primary_filerequests exclusive creation with truncation. The overlay used to open the existing file while checking its writable layer. The test checks both the error and the original contents.symlink-over-deleted-filedeletes a file, reuses its name for a symlink, reads through the link, and removes it. On the fallback backend, attempting to create the link could expose the deleted file again. The original must stay hidden throughout.ephemeral_symlink_and_backing_create_cannot_both_claim_a_namepauses a file create while a second caller tries to register a symlink at the same name. The file must win and the link must getEEXIST. Releasing the lock before the backing create made this test fail.With this PR applied, all 46 guest path tests, 19 WASIX filesystem unit tests, and 144 virtual filesystem tests passed, with two existing ignores.