From 10db2131bd65566774caa21e05d2641fd539abc7 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 20 May 2020 16:32:18 +0100 Subject: [PATCH] vm-virtio: block: Add "writeback" control to Request When this is set to false the write needs to be followed by a flush on the underlying disk (leading to a fsync()). The default behaviour is not changed with this change. Signed-off-by: Rob Bradford --- vm-virtio/src/block.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vm-virtio/src/block.rs b/vm-virtio/src/block.rs index 90e4026dd..0a2448f76 100755 --- a/vm-virtio/src/block.rs +++ b/vm-virtio/src/block.rs @@ -479,6 +479,7 @@ pub struct Request { data_addr: GuestAddress, data_len: u32, pub status_addr: GuestAddress, + writeback: bool, } impl Request { @@ -497,6 +498,7 @@ impl Request { data_addr: GuestAddress(0), data_len: 0, status_addr: GuestAddress(0), + writeback: true, }; let data_desc; @@ -576,13 +578,11 @@ impl Request { RequestType::Out => { mem.write_all_to(self.data_addr, disk, self.data_len as usize) .map_err(ExecuteError::Write)?; - } - RequestType::Flush => match disk.flush() { - Ok(_) => { - return Ok(0); + if !self.writeback { + disk.flush().map_err(ExecuteError::Flush)?; } - Err(e) => return Err(ExecuteError::Flush(e)), - }, + } + RequestType::Flush => disk.flush().map_err(ExecuteError::Flush)?, RequestType::GetDeviceID => { if (self.data_len as usize) < disk_id.len() { return Err(ExecuteError::BadRequest(Error::InvalidOffset)); @@ -594,6 +594,10 @@ impl Request { }; Ok(0) } + + pub fn set_writeback(&mut self, writeback: bool) { + self.writeback = writeback + } } struct BlockEpollHandler {