mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 15:01:16 +00:00
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 <sebastien.boeuf@intel.com>
This commit is contained in:
parent
e54f8ec8a5
commit
7ff82af4b2
@ -27,13 +27,7 @@ pub struct VhostUserConfig {
|
|||||||
pub queue_size: u16,
|
pub queue_size: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_vhost_user_vring(
|
pub fn update_mem_table(vu: &mut Master, mem: &GuestMemoryMmap) -> Result<()> {
|
||||||
vu: &mut Master,
|
|
||||||
mem: &GuestMemoryMmap,
|
|
||||||
queues: Vec<Queue>,
|
|
||||||
queue_evts: Vec<EventFd>,
|
|
||||||
virtio_interrupt: &Arc<dyn VirtioInterrupt>,
|
|
||||||
) -> Result<Vec<(Option<EventFd>, Queue)>> {
|
|
||||||
let mut regions: Vec<VhostUserMemoryRegionInfo> = Vec::new();
|
let mut regions: Vec<VhostUserMemoryRegionInfo> = Vec::new();
|
||||||
mem.with_regions_mut(|_, region| {
|
mem.with_regions_mut(|_, region| {
|
||||||
let (mmap_handle, mmap_offset) = match region.file_offset() {
|
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())
|
vu.set_mem_table(regions.as_slice())
|
||||||
.map_err(Error::VhostUserSetMemTable)?;
|
.map_err(Error::VhostUserSetMemTable)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup_vhost_user_vring(
|
||||||
|
vu: &mut Master,
|
||||||
|
mem: &GuestMemoryMmap,
|
||||||
|
queues: Vec<Queue>,
|
||||||
|
queue_evts: Vec<EventFd>,
|
||||||
|
virtio_interrupt: &Arc<dyn VirtioInterrupt>,
|
||||||
|
) -> Result<Vec<(Option<EventFd>, Queue)>> {
|
||||||
|
// Let's first provide the memory table to the backend.
|
||||||
|
update_mem_table(vu, mem)?;
|
||||||
|
|
||||||
let mut vu_interrupt_list = Vec::new();
|
let mut vu_interrupt_list = Vec::new();
|
||||||
|
|
||||||
for (queue_index, queue) in queues.into_iter().enumerate() {
|
for (queue_index, queue) in queues.into_iter().enumerate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user