diff options
author | Dylan Reid <dgreid@chromium.org> | 2018-05-15 20:18:41 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-18 20:08:31 -0700 |
commit | 2494ddefb17cf4f05a84412c39005b5dd9805245 (patch) | |
tree | 73f43dd9d7d37dd4050246d5600bd5ede59d48d5 | |
parent | fe0abe4a7882e2db5eae45e9cf2c617ba5cf4c20 (diff) | |
download | crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar.gz crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar.bz2 crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar.lz crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar.xz crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.tar.zst crosvm-2494ddefb17cf4f05a84412c39005b5dd9805245.zip |
qcow: Call fsync(2) when we want to flush to disk
Signal to the OS that we want these writes committed all the way to disk. Replace an existing call to flush as that's not sufficient. Change-Id: I9df9e55d2182e283e15eebc02a54c1ce08434f42 Signed-off-by: Dylan Reid <dgreid@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1060696 Reviewed-by: Zach Reizner <zachr@chromium.org>
-rw-r--r-- | qcow/src/qcow.rs | 6 | ||||
-rw-r--r-- | seccomp/aarch64/block_device.policy | 2 | ||||
-rw-r--r-- | seccomp/x86_64/block_device.policy | 4 |
3 files changed, 10 insertions, 2 deletions
diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index 4f1cf7b..2052545 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -394,6 +394,8 @@ impl QcowFile { let cluster_size: u64 = self.cluster_size; let new_cluster_address: u64 = (file_end + cluster_size - 1) & !self.cluster_mask; self.file.set_len(new_cluster_address + cluster_size)?; + // Ensure the length is set before meta-data is updated. + self.file.sync_all()?; Ok(new_cluster_address) } @@ -405,6 +407,8 @@ impl QcowFile { let new_addr: u64 = self.append_new_cluster()?; // Save the new block to the table and mark it as used. write_u64_to_offset(&mut self.file, entry_addr, new_addr | CLUSTER_USED_FLAG)?; + // Ensure that the metadata update is commited before writing data. + self.file.sync_data()?; // The cluster refcount starts at one indicating it is used but doesn't need COW. self.set_cluster_refcount(new_addr, 1)?; Ok(new_addr) @@ -531,7 +535,7 @@ impl Write for QcowFile { } fn flush(&mut self) -> std::io::Result<()> { - self.file.flush() + self.file.sync_all() } } diff --git a/seccomp/aarch64/block_device.policy b/seccomp/aarch64/block_device.policy index f4d5135..cb9dce2 100644 --- a/seccomp/aarch64/block_device.policy +++ b/seccomp/aarch64/block_device.policy @@ -6,7 +6,9 @@ close: 1 dup: 1 dup2: 1 exit_group: 1 +fdatasync: 1 fstat64: 1 +fsync: 1 ftruncate64: 1 futex: 1 _llseek: 1 diff --git a/seccomp/x86_64/block_device.policy b/seccomp/x86_64/block_device.policy index 22a6846..ec79413 100644 --- a/seccomp/x86_64/block_device.policy +++ b/seccomp/x86_64/block_device.policy @@ -6,7 +6,9 @@ close: 1 dup: 1 dup2: 1 exit_group: 1 +fdatasync: 1 fstat: 1 +fsync: 1 ftruncate: 1 futex: 1 lseek: 1 @@ -34,4 +36,4 @@ prctl: arg0 == 15 restart_syscall: 1 epoll_create1: 1 epoll_ctl: 1 -epoll_wait: 1 \ No newline at end of file +epoll_wait: 1 |