summary refs log tree commit diff
path: root/devices/src/virtio/block.rs
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2018-08-09 14:18:07 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-08-13 14:25:11 -0700
commit5f871eb8f4b152a5f97af0482edefe3a1708f033 (patch)
treefcf36859f822cc7c846ac3a4fd7945335d976d1b /devices/src/virtio/block.rs
parent660a653d0f5a381448a19fed28672de1065fb598 (diff)
downloadcrosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar.gz
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar.bz2
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar.lz
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar.xz
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.tar.zst
crosvm-5f871eb8f4b152a5f97af0482edefe3a1708f033.zip
devices: block: define features as shift counts
Convert the definition of VIRTIO_BLK_F_FLUSH to a shift count instead of
a bitmask.  This matches the way the features are defined in the virtio
spec and makes block consistent with other device models, such as p9.

BUG=chromium:872973
TEST=cargo test -p devices

Change-Id: Iece974c6f4d826b7bb76622973f08469a7936234
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1170303
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices/src/virtio/block.rs')
-rw-r--r--devices/src/virtio/block.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs
index 805ec1d..c828f12 100644
--- a/devices/src/virtio/block.rs
+++ b/devices/src/virtio/block.rs
@@ -28,7 +28,7 @@ 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;
+const VIRTIO_BLK_F_FLUSH: u32 = 9;
 
 pub trait DiskFile: Read + Seek + Write {}
 impl<D: Read + Seek + Write> DiskFile for D {}
@@ -400,7 +400,7 @@ impl<T: 'static + AsRawFd + DiskFile + Send> VirtioDevice for Block<T> {
 
     fn features(&self, page: u32) -> u32 {
         match page {
-            0 => VIRTIO_BLK_F_FLUSH,
+            0 => 1 << VIRTIO_BLK_F_FLUSH,
             _ => 0,
         }
     }
@@ -493,4 +493,17 @@ mod tests {
         // size is 0x1000, so msw_sectors is 0.
         assert_eq!([0x00, 0x00, 0x00, 0x00], msw_sectors);
     }
+
+    #[test]
+    fn read_features() {
+        let tempdir = TempDir::new("/tmp/block_read_test").unwrap();
+        let mut path = PathBuf::from(tempdir.as_path().unwrap());
+        path.push("disk_image");
+
+        let f = File::create(&path).unwrap();
+        let b = Block::new(f).unwrap();
+
+        // VIRTIO_BLK_F_FLUSH should always be set
+        assert_eq!(0x200, b.features(0));
+    }
 }