diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2018-10-24 14:36:14 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-26 17:19:10 -0700 |
commit | 510c783c847b6d0c18516f31fbe3dbdc782f1252 (patch) | |
tree | 7b0d65280d5fccc631d6ccd0139a02dcdd6ad57b /qcow | |
parent | ac699881f26300c7776dff706a567f68a7475582 (diff) | |
download | crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar.gz crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar.bz2 crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar.lz crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar.xz crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.tar.zst crosvm-510c783c847b6d0c18516f31fbe3dbdc782f1252.zip |
sys_util: add trait to fsync File and QcowFile
File exposes sync_all() and sync_data() functions, which map to fsync() and fdatasync(), but these functions are not in a trait (they are just implemented directly on File), so they can't be implemented and used in a generic way for QcowFile. Add a new trait, FileSync, that exposes a fsync() function that may be used in the virtio block model. Previously, we were translating a block flush request into a call to File's flush() function, but this just flushes internal Rust library buffers to the file descriptor; it didn't actually result in a fsync() call. Using the new trait, we can cause an actual fsync() to occur for raw files, as intended. QcowFile was already safe, since its flush() function actually calls sync_all() under the hood. BUG=None TEST=sync with raw disk and verify fsync() in strace output Change-Id: I9bee2c0d2df3747aac1e7d9ec7d9b46a7862dc48 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1297839 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'qcow')
-rw-r--r-- | qcow/src/qcow.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index 22d022c..2be4a4c 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -23,7 +23,7 @@ use std::io::{self, Read, Seek, SeekFrom, Write}; use std::mem::size_of; use std::os::unix::io::{AsRawFd, RawFd}; -use sys_util::{PunchHole, SeekHole, WriteZeroes}; +use sys_util::{FileSync, PunchHole, SeekHole, WriteZeroes}; #[derive(Debug)] pub enum Error { @@ -1069,6 +1069,12 @@ impl Write for QcowFile { } } +impl FileSync for QcowFile { + fn fsync(&mut self) -> std::io::Result<()> { + self.flush() + } +} + impl PunchHole for QcowFile { fn punch_hole(&mut self, offset: u64, length: u64) -> std::io::Result<()> { let mut remaining = length; |