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 file sync shims #1418
Add file sync shims #1418
Conversation
Adds implementations for fsync, fdatasync, and sync_file_range
I am not familiar with the detailed semantics of all these variants of |
Whoops, I misspoke above, On non-ancient versions of Linux, fsync lines up well with File::sync_all(), as it writes out all data for a file and its file metadata, and then waits for the disk to finish writing. (on "older kernels", it did not flush disk caches) Likewise, fdatasync lines up well with File::sync_data(), as it skips writing out some file metadata. sync_file_range doesn't have an analogue in the Rust standard library, but it is closest to File::sync_data(), because it doesn't write out file metadata, and while sync_file_range allows selecting what range of the file should be written out, File::sync_data() writes out the whole file, so it's a stronger operation, and just loses out on performance. On macOS, fsync writes out file contents and metadata, but it does not block until the disk has finished writing. fcntl with F_FULLFSYNC writes out both and then waits for the disk to write. While File::sync_all() looks like it could describe either operation, as its docs don't mention flushing the drive's buffers, (only the filesystem's) fcntl with F_FULLFSYNC is the stronger of the two operations on macOS, and that's what the stdlib uses to implement File. And yes, I put the fsync shim in the posix.rs file since it's a POSIX function, even though it may not be used on macOS. |
Thanks for the explanation! I see the code already has a comment for this, so this seems fine.
I see. So on macOS, the Miri implementation is stronger than what the actual system does. That's fine, but please leave a comment along those lines. |
Thanks a lot! @bors r+ |
📌 Commit 3092b9e has been approved by |
Add file sync shims This PR adds shim implementations for these related file syncing functions. * `fsync`, for POSIX targets, backed by `File::sync_all()` * `fdatasync`, for POSIX targets, backed by `File::sync_data()` * `fcntl` with command `F_FULLFSYNC`, for macOS targets, backed by `File::sync_all()` * `sync_file_range`, for Linux targets, backed by `File::sync_data()`
💔 Test failed - status-appveyor |
Looks like |
Hm, the code should work... maybe this is an AppVeyor thing? |
Let's see if this reproduces. |
Add file sync shims This PR adds shim implementations for these related file syncing functions. * `fsync`, for POSIX targets, backed by `File::sync_all()` * `fdatasync`, for POSIX targets, backed by `File::sync_data()` * `fcntl` with command `F_FULLFSYNC`, for macOS targets, backed by `File::sync_all()` * `sync_file_range`, for Linux targets, backed by `File::sync_data()`
Add file sync shims This PR adds shim implementations for these related file syncing functions. * `fsync`, for POSIX targets, backed by `File::sync_all()` * `fdatasync`, for POSIX targets, backed by `File::sync_data()` * `fcntl` with command `F_FULLFSYNC`, for macOS targets, backed by `File::sync_all()` * `sync_file_range`, for Linux targets, backed by `File::sync_data()`
☀️ Try build successful - checks-travis, status-appveyor |
@bors try |
Add file sync shims This PR adds shim implementations for these related file syncing functions. * `fsync`, for POSIX targets, backed by `File::sync_all()` * `fdatasync`, for POSIX targets, backed by `File::sync_data()` * `fcntl` with command `F_FULLFSYNC`, for macOS targets, backed by `File::sync_all()` * `sync_file_range`, for Linux targets, backed by `File::sync_data()`
☀️ Try build successful - checks-travis, status-appveyor |
Argh, GH doesn't let me view the force-pushd diff. :/ |
I added similar logic to fcntl(F_FULLFSYNC) and sync_file_range, and added read-only files to both tests. @bors try |
Add file sync shims This PR adds shim implementations for these related file syncing functions. * `fsync`, for POSIX targets, backed by `File::sync_all()` * `fdatasync`, for POSIX targets, backed by `File::sync_data()` * `fcntl` with command `F_FULLFSYNC`, for macOS targets, backed by `File::sync_all()` * `sync_file_range`, for Linux targets, backed by `File::sync_data()`
☀️ Try build successful - checks-travis, status-appveyor |
src/shims/fs.rs
Outdated
} | ||
|
||
if let Some(FileHandle { file, writable }) = this.machine.file_handler.handles.get_mut(&fd) { | ||
if !*writable && cfg!(windows) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this same conditional 4 times now... can you factor this into a helper function?
I guess we can always clean up later. Thanks for the PR @divergentdave! |
📌 Commit e352d4f has been approved by |
Hang on, I just got the refactor done |
Oh okay, that's quick. :) |
Thanks. :) |
📌 Commit a60c130 has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
This PR adds shim implementations for these related file syncing functions.
fsync
, for POSIX targets, backed byFile::sync_all()
fdatasync
, for POSIX targets, backed byFile::sync_data()
fcntl
with commandF_FULLFSYNC
, for macOS targets, backed byFile::sync_all()
sync_file_range
, for Linux targets, backed byFile::sync_data()