mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices, vmm: Simplify virtio-mem resize operation
There's no need to delegate the resize operation to the virtio-mem thread. This can come directly from the vmm thread which will use the Mem object to update the VIRTIO configuration and trigger the interrupt for the guest to be notified. In order to achieve what's described above, the VirtioMemZone structure now has a handle onto the Mem object directly. This avoids the need for intermediate Resize and ResizeSender structures. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -87,7 +87,7 @@ struct HotPlugState {
|
||||
|
||||
pub struct VirtioMemZone {
|
||||
region: Arc<GuestRegionMmap>,
|
||||
resize_handler: virtio_devices::Resize,
|
||||
virtio_device: Option<Arc<Mutex<virtio_devices::Mem>>>,
|
||||
hotplugged_size: u64,
|
||||
hugepages: bool,
|
||||
blocks_state: Arc<Mutex<BlocksState>>,
|
||||
@@ -97,8 +97,8 @@ impl VirtioMemZone {
|
||||
pub fn region(&self) -> &Arc<GuestRegionMmap> {
|
||||
&self.region
|
||||
}
|
||||
pub fn resize_handler(&self) -> &virtio_devices::Resize {
|
||||
&self.resize_handler
|
||||
pub fn set_virtio_device(&mut self, virtio_device: Arc<Mutex<virtio_devices::Mem>>) {
|
||||
self.virtio_device = Some(virtio_device);
|
||||
}
|
||||
pub fn hotplugged_size(&self) -> u64 {
|
||||
self.hotplugged_size
|
||||
@@ -130,6 +130,9 @@ impl MemoryZone {
|
||||
pub fn virtio_mem_zone(&self) -> &Option<VirtioMemZone> {
|
||||
&self.virtio_mem_zone
|
||||
}
|
||||
pub fn virtio_mem_zone_mut(&mut self) -> Option<&mut VirtioMemZone> {
|
||||
self.virtio_mem_zone.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub type MemoryZones = HashMap<String, MemoryZone>;
|
||||
@@ -579,8 +582,7 @@ impl MemoryManager {
|
||||
let region_size = region.len();
|
||||
memory_zone.virtio_mem_zone = Some(VirtioMemZone {
|
||||
region,
|
||||
resize_handler: virtio_devices::Resize::new(hotplugged_size)
|
||||
.map_err(Error::EventFdFail)?,
|
||||
virtio_device: None,
|
||||
hotplugged_size,
|
||||
hugepages: zone_config.hugepages,
|
||||
blocks_state: Arc::new(Mutex::new(BlocksState::new(region_size))),
|
||||
@@ -1002,8 +1004,7 @@ impl MemoryManager {
|
||||
let region_size = region.len();
|
||||
memory_zone.virtio_mem_zone = Some(VirtioMemZone {
|
||||
region,
|
||||
resize_handler: virtio_devices::Resize::new(hotplugged_size)
|
||||
.map_err(Error::EventFdFail)?,
|
||||
virtio_device: None,
|
||||
hotplugged_size,
|
||||
hugepages: zone.hugepages,
|
||||
blocks_state: Arc::new(Mutex::new(BlocksState::new(region_size))),
|
||||
@@ -1628,10 +1629,13 @@ impl MemoryManager {
|
||||
pub fn virtio_mem_resize(&mut self, id: &str, size: u64) -> Result<(), Error> {
|
||||
if let Some(memory_zone) = self.memory_zones.get_mut(id) {
|
||||
if let Some(virtio_mem_zone) = &mut memory_zone.virtio_mem_zone {
|
||||
virtio_mem_zone
|
||||
.resize_handler()
|
||||
.work(size)
|
||||
.map_err(Error::VirtioMemResizeFail)?;
|
||||
if let Some(virtio_mem_device) = virtio_mem_zone.virtio_device.as_ref() {
|
||||
virtio_mem_device
|
||||
.lock()
|
||||
.unwrap()
|
||||
.resize(size)
|
||||
.map_err(Error::VirtioMemResizeFail)?;
|
||||
}
|
||||
|
||||
// Keep the hotplugged_size up to date.
|
||||
virtio_mem_zone.hotplugged_size = size;
|
||||
@@ -1821,6 +1825,10 @@ impl MemoryManager {
|
||||
&self.memory_zones
|
||||
}
|
||||
|
||||
pub fn memory_zones_mut(&mut self) -> &mut MemoryZones {
|
||||
&mut self.memory_zones
|
||||
}
|
||||
|
||||
pub fn memory_range_table(
|
||||
&self,
|
||||
snapshot: bool,
|
||||
|
||||
Reference in New Issue
Block a user