mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-04 13:41:31 +00:00
feature(krata): first pass on cpu hotplug support (#340)
* fix(runtime): adjust memory resources inside a transaction * feature(krata): first pass on cpu hotplug support
This commit is contained in:
@ -664,22 +664,42 @@ impl ControlService for DaemonControlService {
|
||||
.into());
|
||||
}
|
||||
|
||||
let resources = request.resources.unwrap_or_default();
|
||||
let mut resources = request.resources.unwrap_or_default();
|
||||
if resources.target_memory > resources.max_memory {
|
||||
resources.max_memory = resources.target_memory;
|
||||
}
|
||||
|
||||
if resources.target_cpus < 1 {
|
||||
resources.target_cpus = 1;
|
||||
}
|
||||
|
||||
let initial_resources = zone
|
||||
.spec
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.initial_resources
|
||||
.unwrap_or_default();
|
||||
if resources.target_cpus > initial_resources.max_cpus {
|
||||
resources.target_cpus = initial_resources.max_cpus;
|
||||
}
|
||||
resources.max_cpus = initial_resources.max_cpus;
|
||||
|
||||
self.runtime
|
||||
.set_max_memory(status.domid, resources.max_memory * 1024 * 1024)
|
||||
.set_memory_resources(
|
||||
status.domid,
|
||||
resources.target_memory * 1024 * 1024,
|
||||
resources.max_memory * 1024 * 1024,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| ApiError {
|
||||
message: format!("failed to set maximum memory: {}", error),
|
||||
message: format!("failed to set memory resources: {}", error),
|
||||
})?;
|
||||
|
||||
self.runtime
|
||||
.set_target_memory(status.domid, resources.target_memory * 1024 * 1024)
|
||||
.set_cpu_resources(status.domid, resources.target_cpus)
|
||||
.await
|
||||
.map_err(|error| ApiError {
|
||||
message: format!("failed to set target memory: {}", error),
|
||||
message: format!("failed to set cpu resources: {}", error),
|
||||
})?;
|
||||
|
||||
status.resource_status = Some(ZoneResourceStatus {
|
||||
active_resources: Some(resources),
|
||||
});
|
||||
|
@ -76,7 +76,7 @@ impl ZoneCreator<'_> {
|
||||
}
|
||||
|
||||
pub async fn create(&self, uuid: Uuid, zone: &mut Zone) -> Result<ZoneReconcilerResult> {
|
||||
let Some(ref spec) = zone.spec else {
|
||||
let Some(ref mut spec) = zone.spec else {
|
||||
return Err(anyhow!("zone spec not specified"));
|
||||
};
|
||||
|
||||
@ -176,7 +176,14 @@ impl ZoneCreator<'_> {
|
||||
|
||||
let reservation = self.ip_assignment.assign(uuid).await?;
|
||||
|
||||
let initial_resources = spec.initial_resources.unwrap_or_default();
|
||||
let mut initial_resources = spec.initial_resources.unwrap_or_default();
|
||||
if initial_resources.target_cpus < 1 {
|
||||
initial_resources.target_cpus = 1;
|
||||
}
|
||||
if initial_resources.target_cpus > initial_resources.max_cpus {
|
||||
initial_resources.max_cpus = initial_resources.target_cpus;
|
||||
}
|
||||
spec.initial_resources = Some(initial_resources);
|
||||
let info = self
|
||||
.runtime
|
||||
.launch(ZoneLaunchRequest {
|
||||
@ -190,7 +197,8 @@ impl ZoneCreator<'_> {
|
||||
image,
|
||||
kernel,
|
||||
initrd,
|
||||
cpus: initial_resources.cpus,
|
||||
target_cpus: initial_resources.target_cpus,
|
||||
max_cpus: initial_resources.max_cpus,
|
||||
max_memory: initial_resources.max_memory,
|
||||
target_memory: initial_resources.target_memory,
|
||||
pcis,
|
||||
|
Reference in New Issue
Block a user