From 7ff82af4b2ccbd77b84f5c3eda7752b1a951ca05 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 23 Mar 2020 13:21:39 +0100 Subject: [PATCH] vm-virtio: vhost-user: Factorize SET_MEM_TABLE setup By factorizing the setup of the memory table for vhost-user, we anticipate the fact that vhost-user devices are going to reuse this function when the guest memory will be updated. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/vhost_user/vu_common_ctrl.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/vm-virtio/src/vhost_user/vu_common_ctrl.rs b/vm-virtio/src/vhost_user/vu_common_ctrl.rs index 89318a2cf..67b177f0b 100644 --- a/vm-virtio/src/vhost_user/vu_common_ctrl.rs +++ b/vm-virtio/src/vhost_user/vu_common_ctrl.rs @@ -27,13 +27,7 @@ pub struct VhostUserConfig { pub queue_size: u16, } -pub fn setup_vhost_user_vring( - vu: &mut Master, - mem: &GuestMemoryMmap, - queues: Vec, - queue_evts: Vec, - virtio_interrupt: &Arc, -) -> Result, Queue)>> { +pub fn update_mem_table(vu: &mut Master, mem: &GuestMemoryMmap) -> Result<()> { let mut regions: Vec = Vec::new(); mem.with_regions_mut(|_, region| { let (mmap_handle, mmap_offset) = match region.file_offset() { @@ -58,6 +52,19 @@ pub fn setup_vhost_user_vring( vu.set_mem_table(regions.as_slice()) .map_err(Error::VhostUserSetMemTable)?; + Ok(()) +} + +pub fn setup_vhost_user_vring( + vu: &mut Master, + mem: &GuestMemoryMmap, + queues: Vec, + queue_evts: Vec, + virtio_interrupt: &Arc, +) -> Result, Queue)>> { + // Let's first provide the memory table to the backend. + update_mem_table(vu, mem)?; + let mut vu_interrupt_list = Vec::new(); for (queue_index, queue) in queues.into_iter().enumerate() {