vmm: Add RwLock to the GuestMemoryMmap

Following the refactoring of the code allowing multiple threads to
access the same instance of the guest memory, this patch goes one step
further by adding RwLock to it. This anticipates the future need for
being able to modify the content of the guest memory at runtime.

The reasons for adding regions to an existing guest memory could be:
- Add virtio-pmem and virtio-fs regions after the guest memory was
  created.
- Support future hotplug of devices, memory, or anything that would
  require more memory at runtime.

Because most of the time, the lock will be taken as read only, using
RwLock instead of Mutex is the right approach.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2019-08-20 15:43:23 -07:00
committed by Rob Bradford
parent ec0b5567c8
commit 0b8856d148
11 changed files with 82 additions and 79 deletions

View File

@@ -7,7 +7,7 @@
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
use super::*;
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use vm_memory::{GuestAddress, GuestMemoryMmap, GuestUsize};
use vmm_sys_util::eventfd::EventFd;
@@ -67,7 +67,7 @@ pub trait VirtioDevice: Send {
/// Activates this device for real usage.
fn activate(
&mut self,
mem: Arc<GuestMemoryMmap>,
mem: Arc<RwLock<GuestMemoryMmap>>,
interrupt_evt: Arc<VirtioInterrupt>,
queues: Vec<Queue>,
queue_evts: Vec<EventFd>,