(
&mut self,
desired_vcpus: Option<u32>,
desired_memory: Option<u64>,
desired_balloon: Option<u64>,
)
| 2074 | } |
| 2075 | |
| 2076 | pub fn resize( |
| 2077 | &mut self, |
| 2078 | desired_vcpus: Option<u32>, |
| 2079 | desired_memory: Option<u64>, |
| 2080 | desired_balloon: Option<u64>, |
| 2081 | ) -> Result<()> { |
| 2082 | event!("vm", "resizing"); |
| 2083 | |
| 2084 | if let Some(desired_vcpus) = desired_vcpus { |
| 2085 | if self |
| 2086 | .cpu_manager |
| 2087 | .lock() |
| 2088 | .unwrap() |
| 2089 | .resize(desired_vcpus) |
| 2090 | .map_err(Error::CpuManager)? |
| 2091 | { |
| 2092 | self.device_manager |
| 2093 | .lock() |
| 2094 | .unwrap() |
| 2095 | .notify_hotplug(AcpiNotificationFlags::CPU_DEVICES_CHANGED) |
| 2096 | .map_err(Error::DeviceManager)?; |
| 2097 | } |
| 2098 | self.config.lock().unwrap().cpus.boot_vcpus = desired_vcpus; |
| 2099 | } |
| 2100 | |
| 2101 | if let Some(desired_memory) = desired_memory { |
| 2102 | let new_region = self |
| 2103 | .memory_manager |
| 2104 | .lock() |
| 2105 | .unwrap() |
| 2106 | .resize(desired_memory) |
| 2107 | .map_err(Error::MemoryManager)?; |
| 2108 | |
| 2109 | let memory_config = &mut self.config.lock().unwrap().memory; |
| 2110 | |
| 2111 | if let Some(new_region) = &new_region { |
| 2112 | self.device_manager |
| 2113 | .lock() |
| 2114 | .unwrap() |
| 2115 | .update_memory(new_region) |
| 2116 | .map_err(Error::DeviceManager)?; |
| 2117 | |
| 2118 | match memory_config.hotplug_method { |
| 2119 | HotplugMethod::Acpi => { |
| 2120 | self.device_manager |
| 2121 | .lock() |
| 2122 | .unwrap() |
| 2123 | .notify_hotplug(AcpiNotificationFlags::MEMORY_DEVICES_CHANGED) |
| 2124 | .map_err(Error::DeviceManager)?; |
| 2125 | } |
| 2126 | HotplugMethod::VirtioMem => {} |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | // We update the VM config regardless of the actual guest resize |
| 2131 | // operation result (happened or not), so that if the VM reboots |
| 2132 | // it will be running with the last configure memory size. |
| 2133 | match memory_config.hotplug_method { |
no test coverage detected