Skip to content

virtio: sync data on virtio flush request #2185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/devices/src/virtio/block/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// found in the THIRD-PARTY file.

use std::convert::From;
use std::io::{self, Seek, SeekFrom, Write};
use std::io::{self, Seek, SeekFrom};
use std::mem;
use std::result;

Expand All @@ -21,7 +21,7 @@ use super::{Error, SECTOR_SHIFT, SECTOR_SIZE};
#[derive(Debug)]
pub enum ExecuteError {
BadRequest(Error),
Flush(io::Error),
SyncAll(io::Error),
Read(GuestMemoryError),
Seek(io::Error),
Write(GuestMemoryError),
Expand All @@ -32,7 +32,7 @@ impl ExecuteError {
pub fn status(&self) -> u32 {
match *self {
ExecuteError::BadRequest(_) => VIRTIO_BLK_S_IOERR,
ExecuteError::Flush(_) => VIRTIO_BLK_S_IOERR,
ExecuteError::SyncAll(_) => VIRTIO_BLK_S_IOERR,
ExecuteError::Read(_) => VIRTIO_BLK_S_IOERR,
ExecuteError::Seek(_) => VIRTIO_BLK_S_IOERR,
ExecuteError::Write(_) => VIRTIO_BLK_S_IOERR,
Expand Down Expand Up @@ -227,13 +227,10 @@ impl Request {
METRICS.block.write_bytes.add(self.data_len as usize);
METRICS.block.write_count.inc();
}
RequestType::Flush => match diskfile.flush() {
Ok(_) => {
METRICS.block.flush_count.inc();
return Ok(0);
}
Err(e) => return Err(ExecuteError::Flush(e)),
},
RequestType::Flush => {
diskfile.sync_all().map_err(ExecuteError::SyncAll)?;
METRICS.block.flush_count.inc();
}
RequestType::GetDeviceID => {
let disk_id = disk.image_id();
if (self.data_len as usize) < disk_id.len() {
Expand Down Expand Up @@ -304,7 +301,7 @@ mod tests {
VIRTIO_BLK_S_IOERR
);
assert_eq!(
ExecuteError::Flush(io::Error::from_raw_os_error(42)).status(),
ExecuteError::SyncAll(io::Error::from_raw_os_error(42)).status(),
VIRTIO_BLK_S_IOERR
);
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions src/vmm/src/default_syscalls/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn default_filter() -> Result<SeccompFilter, Error> {
allow_syscall(libc::SYS_timerfd_settime),
allow_syscall(libc::SYS_write),
allow_syscall(libc::SYS_writev),
allow_syscall(libc::SYS_fsync),
]
.into_iter()
.collect(),
Expand Down