From 2494ddefb17cf4f05a84412c39005b5dd9805245 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Tue, 15 May 2018 20:18:41 -0700 Subject: [PATCH] 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 Reviewed-on: https://chromium-review.googlesource.com/1060696 Reviewed-by: Zach Reizner --- qcow/src/qcow.rs | 6 +++++- seccomp/aarch64/block_device.policy | 2 ++ 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 4f1cf7b4a0..2052545dfb 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 f4d51354ea..cb9dce2679 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 22a6846f25..ec79413789 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