mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +00:00
vmm: api: ch-remote: Add balloon to VmResizeData
Signed-off-by: Hui Zhu <teawater@antfin.com>
This commit is contained in:
parent
f729b25a10
commit
8ffbc3d031
@ -23,6 +23,7 @@ enum Error {
|
|||||||
ServerResponse(StatusCode, Option<String>),
|
ServerResponse(StatusCode, Option<String>),
|
||||||
InvalidCPUCount(std::num::ParseIntError),
|
InvalidCPUCount(std::num::ParseIntError),
|
||||||
InvalidMemorySize(std::num::ParseIntError),
|
InvalidMemorySize(std::num::ParseIntError),
|
||||||
|
InvalidBalloonSize(std::num::ParseIntError),
|
||||||
AddDeviceConfig(vmm::config::Error),
|
AddDeviceConfig(vmm::config::Error),
|
||||||
AddDiskConfig(vmm::config::Error),
|
AddDiskConfig(vmm::config::Error),
|
||||||
AddFsConfig(vmm::config::Error),
|
AddFsConfig(vmm::config::Error),
|
||||||
@ -49,6 +50,7 @@ impl fmt::Display for Error {
|
|||||||
}
|
}
|
||||||
InvalidCPUCount(e) => write!(f, "Error parsing CPU count: {}", e),
|
InvalidCPUCount(e) => write!(f, "Error parsing CPU count: {}", e),
|
||||||
InvalidMemorySize(e) => write!(f, "Error parsing memory size: {}", e),
|
InvalidMemorySize(e) => write!(f, "Error parsing memory size: {}", e),
|
||||||
|
InvalidBalloonSize(e) => write!(f, "Error parsing balloon size: {}", e),
|
||||||
AddDeviceConfig(e) => write!(f, "Error parsing device syntax: {}", e),
|
AddDeviceConfig(e) => write!(f, "Error parsing device syntax: {}", e),
|
||||||
AddDiskConfig(e) => write!(f, "Error parsing disk syntax: {}", e),
|
AddDiskConfig(e) => write!(f, "Error parsing disk syntax: {}", e),
|
||||||
AddFsConfig(e) => write!(f, "Error parsing filesystem syntax: {}", e),
|
AddFsConfig(e) => write!(f, "Error parsing filesystem syntax: {}", e),
|
||||||
@ -204,6 +206,7 @@ fn resize_api_command(
|
|||||||
socket: &mut UnixStream,
|
socket: &mut UnixStream,
|
||||||
cpus: Option<&str>,
|
cpus: Option<&str>,
|
||||||
memory: Option<&str>,
|
memory: Option<&str>,
|
||||||
|
balloon: Option<&str>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let desired_vcpus: Option<u8> = if let Some(cpus) = cpus {
|
let desired_vcpus: Option<u8> = if let Some(cpus) = cpus {
|
||||||
Some(cpus.parse().map_err(Error::InvalidCPUCount)?)
|
Some(cpus.parse().map_err(Error::InvalidCPUCount)?)
|
||||||
@ -217,9 +220,16 @@ fn resize_api_command(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let desired_ram_w_balloon: Option<u64> = if let Some(balloon) = balloon {
|
||||||
|
Some(balloon.parse().map_err(Error::InvalidBalloonSize)?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let resize = vmm::api::VmResizeData {
|
let resize = vmm::api::VmResizeData {
|
||||||
desired_vcpus,
|
desired_vcpus,
|
||||||
desired_ram,
|
desired_ram,
|
||||||
|
desired_ram_w_balloon,
|
||||||
};
|
};
|
||||||
|
|
||||||
simple_api_command(
|
simple_api_command(
|
||||||
@ -348,6 +358,10 @@ fn do_command(matches: &ArgMatches) -> Result<(), Error> {
|
|||||||
.subcommand_matches("resize")
|
.subcommand_matches("resize")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.value_of("memory"),
|
.value_of("memory"),
|
||||||
|
matches
|
||||||
|
.subcommand_matches("resize")
|
||||||
|
.unwrap()
|
||||||
|
.value_of("balloon"),
|
||||||
),
|
),
|
||||||
Some("add-device") => add_device_api_command(
|
Some("add-device") => add_device_api_command(
|
||||||
&mut socket,
|
&mut socket,
|
||||||
@ -518,6 +532,13 @@ fn main() {
|
|||||||
.help("New memory size (in MiB)")
|
.help("New memory size (in MiB)")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.number_of_values(1),
|
.number_of_values(1),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("balloon")
|
||||||
|
.long("balloon")
|
||||||
|
.help("New memory with balloon size")
|
||||||
|
.takes_value(true)
|
||||||
|
.number_of_values(1),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(SubCommand::with_name("resume").about("Resume the VM"))
|
.subcommand(SubCommand::with_name("resume").about("Resume the VM"))
|
||||||
|
@ -153,6 +153,7 @@ pub struct VmmPingResponse {
|
|||||||
pub struct VmResizeData {
|
pub struct VmResizeData {
|
||||||
pub desired_vcpus: Option<u8>,
|
pub desired_vcpus: Option<u8>,
|
||||||
pub desired_ram: Option<u64>,
|
pub desired_ram: Option<u64>,
|
||||||
|
pub desired_ram_w_balloon: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Deserialize, Serialize, Default)]
|
#[derive(Clone, Deserialize, Serialize, Default)]
|
||||||
|
@ -680,6 +680,10 @@ components:
|
|||||||
description: desired memory ram in bytes
|
description: desired memory ram in bytes
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
desired_ram_w_balloon:
|
||||||
|
description: desired ballon size in bytes
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
|
||||||
VmAddDevice:
|
VmAddDevice:
|
||||||
type: object
|
type: object
|
||||||
|
@ -490,9 +490,10 @@ impl Vmm {
|
|||||||
&mut self,
|
&mut self,
|
||||||
desired_vcpus: Option<u8>,
|
desired_vcpus: Option<u8>,
|
||||||
desired_ram: Option<u64>,
|
desired_ram: Option<u64>,
|
||||||
|
desired_ram_w_balloon: Option<u64>,
|
||||||
) -> result::Result<(), VmError> {
|
) -> result::Result<(), VmError> {
|
||||||
if let Some(ref mut vm) = self.vm {
|
if let Some(ref mut vm) = self.vm {
|
||||||
if let Err(e) = vm.resize(desired_vcpus, desired_ram) {
|
if let Err(e) = vm.resize(desired_vcpus, desired_ram, desired_ram_w_balloon) {
|
||||||
error!("Error when resizing VM: {:?}", e);
|
error!("Error when resizing VM: {:?}", e);
|
||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
@ -766,6 +767,7 @@ impl Vmm {
|
|||||||
.vm_resize(
|
.vm_resize(
|
||||||
resize_data.desired_vcpus,
|
resize_data.desired_vcpus,
|
||||||
resize_data.desired_ram,
|
resize_data.desired_ram,
|
||||||
|
resize_data.desired_ram_w_balloon,
|
||||||
)
|
)
|
||||||
.map_err(ApiError::VmResize)
|
.map_err(ApiError::VmResize)
|
||||||
.map(|_| ApiResponsePayload::Empty);
|
.map(|_| ApiResponsePayload::Empty);
|
||||||
|
@ -680,7 +680,12 @@ impl Vm {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&mut self, desired_vcpus: Option<u8>, desired_memory: Option<u64>) -> Result<()> {
|
pub fn resize(
|
||||||
|
&mut self,
|
||||||
|
desired_vcpus: Option<u8>,
|
||||||
|
desired_memory: Option<u64>,
|
||||||
|
desired_ram_w_balloon: Option<u64>,
|
||||||
|
) -> Result<()> {
|
||||||
if let Some(desired_vcpus) = desired_vcpus {
|
if let Some(desired_vcpus) = desired_vcpus {
|
||||||
if self
|
if self
|
||||||
.cpu_manager
|
.cpu_manager
|
||||||
@ -731,6 +736,15 @@ impl Vm {
|
|||||||
// it will be running with the last configure memory size.
|
// it will be running with the last configure memory size.
|
||||||
self.config.lock().unwrap().memory.size = desired_memory;
|
self.config.lock().unwrap().memory.size = desired_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(desired_ram_w_balloon) = desired_ram_w_balloon {
|
||||||
|
self.memory_manager
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.balloon_resize(desired_ram_w_balloon)
|
||||||
|
.map_err(Error::MemoryManager)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user