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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-05-20 16:32:18 +01:00 committed by Samuel Ortiz
parent b94d9a30d3
commit 10db2131bd

View File

@ -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<T: DiskFile> {