Skip to content
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

fix(vfs) Opening in append-mode must ignore seek operations #2545

Merged
merged 1 commit into from
Aug 31, 2021

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Aug 31, 2021

Description

When opening a file with the append option turned on, all seek
operations must be ignored. As described by
open(2), the
O_APPEND option describes this behavior well:

Before each write(2), the file offset is positioned at
the end of the file, as if with lseek(2). The
modification of the file offset and the write operation
are performed as a single atomic step.

O_APPEND may lead to corrupted files on NFS filesystems
if more than one process appends data to a file at once.
This is because NFS does not support appending to a file,
so the client kernel has to simulate it, which can't be
done without a race condition.

This patch implements that behavior.
Also, this patch rewind the file cursor if opened in read-mode.

When opening a file with the `append` option turned on, all `seek`
operations must be ignored. As described by
[`open(2)`](https://man7.org/linux/man-pages/man2/open.2.html), the
`O_APPEND` option describes this behavior well:

> Before each write(2), the file offset is positioned at
> the end of the file, as if with lseek(2).  The
> modification of the file offset and the write operation
> are performed as a single atomic step.
>
> O_APPEND may lead to corrupted files on NFS filesystems
> if more than one process appends data to a file at once.
> This is because NFS does not support appending to a file,
> so the client kernel has to simulate it, which can't be
> done without a race condition.

This patch implements that behavior.
Also, this patch rewind the file cursor if opened in read-mode.
@Hywan Hywan added the bug Something isn't working label Aug 31, 2021
@Hywan Hywan self-assigned this Aug 31, 2021
@Hywan Hywan added the 📦 lib-vfs About wasmer-vfs label Aug 31, 2021
@Hywan
Copy link
Contributor Author

Hywan commented Aug 31, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Aug 31, 2021

@bors bors bot merged commit 35be1e2 into wasmerio:master Aug 31, 2021
bors bot added a commit that referenced this pull request Sep 3, 2021
2546: test(wasi) Running all WASI tests with `wasmer_vfs::mem_fs` too r=Hywan a=Hywan

# Description

This WIP PR updates our WASI test framework to specifically test with `wasmer_vfs::host_fs` (the default, as of now) _and_ with `wasmer_vfs::mem_fs` (🆕!).

Bug trophies:

* #2545
* #2550
* #2551

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Ivan Enderlin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-vfs About wasmer-vfs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants