diff options
Diffstat (limited to 'src/vhost_user/master.rs')
-rw-r--r-- | src/vhost_user/master.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/vhost_user/master.rs b/src/vhost_user/master.rs index a721355..d27e4fb 100644 --- a/src/vhost_user/master.rs +++ b/src/vhost_user/master.rs @@ -53,6 +53,9 @@ pub trait VhostUserMaster: VhostBackend { /// Query the maximum amount of memory slots supported by the backend. fn get_max_mem_slots(&mut self) -> Result<u64>; + + /// Add a new guest memory mapping for vhost to use. + fn add_mem_region(&mut self, region: &VhostUserMemoryRegionInfo) -> Result<()>; } fn error_code<T>(err: VhostUserError) -> Result<T> { @@ -451,6 +454,27 @@ impl VhostUserMaster for Master { Ok(val.value) } + + fn add_mem_region(&mut self, region: &VhostUserMemoryRegionInfo) -> Result<()> { + let mut node = self.node(); + if node.acked_protocol_features & VhostUserProtocolFeatures::CONFIGURE_MEM_SLOTS.bits() == 0 + { + return error_code(VhostUserError::InvalidOperation); + } + if region.memory_size == 0 || region.mmap_handle < 0 { + return error_code(VhostUserError::InvalidParam); + } + + let body = VhostUserSingleMemoryRegion::new( + region.guest_phys_addr, + region.memory_size, + region.userspace_addr, + region.mmap_offset, + ); + let fds = [region.mmap_handle]; + let hdr = node.send_request_with_body(MasterReq::ADD_MEM_REG, &body, Some(&fds))?; + node.wait_for_ack(&hdr).map_err(|e| e.into()) + } } impl AsRawFd for Master { |