From 6c0dedd560619cb0c2a1a596b1f9ab3084e9566f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 1 May 2024 09:24:48 +0100 Subject: [PATCH] block: Replace specific bitmap implementation with trait Replace the specific Bitmap implementation from the type signature used for functions that take memory. This allows more flexibility when using these functions in particular when these functions are used by the vhost-user-block backend. An updated vhost-user-backend crate requires extra constraints on the Bitmap implementation used (it must support BitmapReplace which AtomicBitmap does not.) Signed-off-by: Rob Bradford --- block/src/lib.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/block/src/lib.rs b/block/src/lib.rs index 164f8b0e9..8fb2e91a8 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -56,16 +56,14 @@ use thiserror::Error; use virtio_bindings::virtio_blk::*; use virtio_queue::DescriptorChain; use vm_memory::{ - bitmap::AtomicBitmap, bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, - GuestMemoryError, GuestMemoryLoadGuard, + bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, + GuestMemoryLoadGuard, }; use vm_virtio::{AccessPlatform, Translatable}; use vmm_sys_util::aio; use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr}; -type GuestMemoryMmap = vm_memory::GuestMemoryMmap; - const SECTOR_SHIFT: u8 = 9; pub const SECTOR_SIZE: u64 = 0x01 << SECTOR_SHIFT; @@ -195,8 +193,8 @@ pub enum RequestType { Unsupported(u32), } -pub fn request_type( - mem: &GuestMemoryMmap, +pub fn request_type( + mem: &vm_memory::GuestMemoryMmap, desc_addr: GuestAddress, ) -> result::Result { let type_ = mem.read_obj(desc_addr).map_err(Error::GuestMemory)?; @@ -209,7 +207,10 @@ pub fn request_type( } } -fn sector(mem: &GuestMemoryMmap, desc_addr: GuestAddress) -> result::Result { +fn sector( + mem: &vm_memory::GuestMemoryMmap, + desc_addr: GuestAddress, +) -> result::Result { const SECTOR_OFFSET: usize = 8; let addr = match mem.checked_offset(desc_addr, SECTOR_OFFSET) { Some(v) => v, @@ -239,8 +240,8 @@ pub struct Request { } impl Request { - pub fn parse( - desc_chain: &mut DescriptorChain>, + pub fn parse( + desc_chain: &mut DescriptorChain>>, access_platform: Option<&Arc>, ) -> result::Result { let hdr_desc = desc_chain @@ -331,11 +332,11 @@ impl Request { Ok(req) } - pub fn execute( + pub fn execute( &self, disk: &mut T, disk_nsectors: u64, - mem: &GuestMemoryMmap, + mem: &vm_memory::GuestMemoryMmap, serial: &[u8], ) -> result::Result { disk.seek(SeekFrom::Start(self.sector << SECTOR_SHIFT)) @@ -388,9 +389,9 @@ impl Request { Ok(len) } - pub fn execute_async( + pub fn execute_async( &mut self, - mem: &GuestMemoryMmap, + mem: &vm_memory::GuestMemoryMmap, disk_nsectors: u64, disk_image: &mut dyn AsyncIo, serial: &[u8],