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

Document atomicity of write and pwrite, and technical fix about POSIX #257

Merged
merged 7 commits into from
May 18, 2020

Conversation

igrep
Copy link
Contributor

@igrep igrep commented Apr 15, 2020

See the commit message of each commit for details.

@programmerjake
Copy link
Contributor

Is it technically possible to provide atomic writes with respect to non-WASI code, such as other processes? (Seems unlikely when a file is mmaped.) If not, wording should be added to limit the scope of the atomicity to the WASI process (implementable with a mutex or similar) or some other suitable scope.

@igrep
Copy link
Contributor Author

igrep commented Apr 16, 2020

Thanks for pointing out. Reviewing the related chapter of POSIX, it refers only to threads.
I'll fix.

@sunfishcode
Copy link
Member

The related chapter in POSIX only provides these guarantees when the functions are operating on regular files or symbolic links. Unless we intend WASI to differ, we should preserve that aspect of the guarantee.

write etc. don't have a guarantee to write all the data or nothing. POSIX only says these "functions shall be atomic with respect to each other", which I read as saying that these functions' I/O won't be interleaved with other I/O, however they can presumably still produce incomplete results if they encounter errors such as running out of space on an output device. And in practice, some OS's also impose their own limitations -- on 64-bit Linux for example, calling write with a 4 GiB buffer (which is below SSIZE_MAX) to a normal file writes only 0x7ffff000 bytes.

igrep added a commit to igrep/WASI that referenced this pull request Apr 22, 2020
WebAssembly#257 (comment)

The atomicity is guaranteed only for regular files or symbolic links (only symbolic links for a regular files, right?)

Delete expressions indicating 'all or nothing' to reflect the actual behavior of POSIX's`write` etc.
@igrep
Copy link
Contributor Author

igrep commented Apr 22, 2020

The related chapter in POSIX only provides these guarantees when the functions are operating on regular files or symbolic links

Thanks! I missed the phrase "when they operate on regular files or symbolic links".

write etc. don't have a guarantee to write all the data or nothing. POSIX only says these "functions shall be atomic with respect to each other", which I read as saying that these functions' I/O won't be interleaved with other I/O, however they can presumably still produce incomplete results if they encounter errors such as running out of space on an output device

I agree. So I rewrote about what "atomicity" stands for. 13ab34b 3339842.

igrep added a commit to igrep/WASI that referenced this pull request Apr 22, 2020
WebAssembly#257 (comment)

The atomicity is guaranteed only for regular files or symbolic links (only symbolic links for a regular files, right?)

Delete expressions indicating 'all or nothing' to reflect the actual behavior of POSIX's`write` etc.
igrep added a commit to igrep/WASI that referenced this pull request May 8, 2020
WebAssembly#257 (comment)

Delete the sentences related to 'all data' completely

Don't refer to symlink
igrep added 6 commits May 8, 2020 11:57
Related thread of ZULIP: https://bytecodealliance.zulipchat.com/#narrow/stream/219900-wasi/topic/Why.20is.20.60iovecs.60.20an.20array.20of.20strings.3F

The thread refers atomicity of `read`, but I couldn't make a good expression
for the atomicity of `read`.
So I add document only in `write` and `pwrite`.
The related POSIX document refers only to threads. https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_07

So the atomicity is limited in the process
WebAssembly#257 (comment)

The atomicity is guaranteed only for regular files or symbolic links (only symbolic links for a regular files, right?)

Delete expressions indicating 'all or nothing' to reflect the actual behavior of POSIX's`write` etc.
WebAssembly#257 (comment)

Delete the sentences related to 'all data' completely

Don't refer to symlink
@igrep
Copy link
Contributor Author

igrep commented May 12, 2020

@MaxDesiatov Thank you for the review!

@sunfishcode
Copy link
Member

This looks good to me, thanks for seeing this through!

@sunfishcode sunfishcode merged commit 7408db4 into WebAssembly:master May 18, 2020
@igrep igrep deleted the write-atomicity branch May 19, 2020 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants