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>
This commit is contained in:
Dylan Reid 2018-05-15 20:18:41 -07:00 committed by chrome-bot
parent fe0abe4a78
commit 2494ddefb1
3 changed files with 10 additions and 2 deletions

View file

@ -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()
}
}

View file

@ -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

View file

@ -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
epoll_wait: 1