-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add advisory file locking support. #69
Conversation
Add functions which correspond to `flock` in Unix. This is not a POSIX interface, but it's sufficiently portable, there's a way to implement it on Windows, and it doesn't have problematic process-associated locks. Instead of having a single `flock` function that gets passed and enum, this has separate functions for shared vs. exclusive, and locking vs. non-locking. That's something we can revisit if needed, but it keeps the API simpler for now.
Also mention that exclusive locks may require write mode on file descriptors, as described in the [Linux `flock` man page]. [Linux `flock` man page]: https://man7.org/linux/man-pages/man2/flock.2.html
Trying to lock a file in one mode and then locking in another mode inside the same process (not wasm instance!) will silently switch the lock mode even if as I understand it the locking was done through a different fd. In addition this switching is not guaranteed to be atomic. Flock also doesn't work on NFS. Finally it is not clear to me how handling multiple locks for the same file in the same process is supposed behave. Maybe the best way would be to have a clean slatw design for wasi and have wasi runtimes emulate the right semantics using for example hidden files in combination with a single tightly controlled process global advisory or mandatory lock for the purpose of crash recovery. Or something like that. |
Linux's
It is emulated to some degree on some platforms, though there are caveats. But my overall idea is, the fact that some people want to use an API not designed to be used over networks, over networks, shouldn't mean that everyone else can't have nice things 😄. I'll add some documentation about this.
Linux documents that
We can do that if we need to, but my sense here is that |
I've now tried an experiment on NFS on Linux, where the man page says that |
To protect users from silent data corruption, I've added a note that implementations should know whether the filesystem they're on supports locking or not, and if not, they should make the lock functions here fail with |
|
This pulls in WebAssembly/wasi-filesystem#69.
This pulls in WebAssembly/wasi-filesystem#69.
This pulls in WebAssembly/wasi-filesystem#69.
This pulls in WebAssembly/wasi-filesystem#69.
Add functions which correspond to
flock
in Unix. This is not a POSIX interface, but it's sufficiently portable, there's a way to implement it on Windows, and it doesn't have problematic process-associated locks.Instead of having a single
flock
function that gets passed and enum, this has separate functions for shared vs. exclusive, and locking vs. non-locking. That's something we can revisit if needed, but it keeps the API simpler for now.