From 6fd0c6f223b9337e9583b9cbce1cf1cab9872076 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Thu, 12 Jul 2018 16:10:13 -0700 Subject: [PATCH] devices: block: Support flush command The "supports flush" bit wasn't set in the device features, so the guest wasn't syncing. Handle the request, which is 0 length so needs special casing in the `parse` function. Change-Id: I079611df912cd077362b2ee9925cf730ba86d9e5 Signed-off-by: Dylan Reid Reviewed-on: https://chromium-review.googlesource.com/1135940 --- devices/src/virtio/block.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index d322388bbc..1b9b558787 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -28,6 +28,8 @@ const VIRTIO_BLK_S_OK: u8 = 0; const VIRTIO_BLK_S_IOERR: u8 = 1; const VIRTIO_BLK_S_UNSUPP: u8 = 2; +const VIRTIO_BLK_F_FLUSH: u32 = 0x200; + pub trait DiskFile: Read + Seek + Write {} impl DiskFile for D {} @@ -131,6 +133,16 @@ impl Request { } let req_type = request_type(&mem, avail_desc.addr)?; + if req_type == RequestType::Flush { + return Ok(Request { + request_type: req_type, + sector: 0, + data_addr: GuestAddress(0), + data_len: 0, + status_addr: GuestAddress(0), + }) + } + let sector = sector(&mem, avail_desc.addr)?; let data_desc = avail_desc .next_descriptor() @@ -356,6 +368,13 @@ impl VirtioDevice for Block { keep_fds } + fn features(&self, page: u32) -> u32 { + match page { + 0 => VIRTIO_BLK_F_FLUSH, + _ => 0, + } + } + fn device_type(&self) -> u32 { TYPE_BLOCK }