summaryrefslogtreecommitdiff
path: root/src/vhost_user/master.rs
diff options
context:
space:
mode:
authorSebastien Boeuf <sebastien.boeuf@intel.com>2021-03-04 17:43:35 +0100
committerJiang Liu <gerry@linux.alibaba.com>2021-03-10 23:37:29 +0800
commit7e3ab1af4e1c2157e206798683b64eb384c3693a (patch)
treefb40e5705f62b2374b8dc5d639b60d1792b3a89d /src/vhost_user/master.rs
parente7d46d6980ed1312e16243ff2ec4bb018f9aec5f (diff)
downloadvmm_vhost-7e3ab1af4e1c2157e206798683b64eb384c3693a.tar.gz
vhost_user: Add support for ADD_MEM_REG
Adding support for a new message ADD_MEM_REG. This command request a new region to be added and mapped by the vhost-user backend. It is designed for supporting memory hotplug, avoiding the limitation from SET_MEM_TABLE (supports only 8 regions). It is only available if the protocol feature VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS has been negotiated. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Diffstat (limited to 'src/vhost_user/master.rs')
-rw-r--r--src/vhost_user/master.rs24
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 {