Support cpu_topology in VmConfig
cpu_topology is included in RawConfig, so support it in VmConfig as well
Bug: 330256602
Test: add cpu_topology into json config, and then run `vm` tool
Change-Id: I1a1f5bcd473789ff4001d6fa717a6a5a1102ae9d
diff --git a/libs/vmconfig/src/lib.rs b/libs/vmconfig/src/lib.rs
index 50f3c8e..907e0d3 100644
--- a/libs/vmconfig/src/lib.rs
+++ b/libs/vmconfig/src/lib.rs
@@ -15,6 +15,7 @@
//! Struct for VM configuration with JSON (de)serialization and AIDL parcelables
use android_system_virtualizationservice::{
+ aidl::android::system::virtualizationservice::CpuTopology::CpuTopology,
aidl::android::system::virtualizationservice::DiskImage::DiskImage as AidlDiskImage,
aidl::android::system::virtualizationservice::Partition::Partition as AidlPartition,
aidl::android::system::virtualizationservice::VirtualMachineRawConfig::VirtualMachineRawConfig,
@@ -54,6 +55,8 @@
/// The amount of RAM to give the VM, in MiB.
#[serde(default)]
pub memory_mib: Option<NonZeroU32>,
+ /// The CPU topology: either "one_cpu"(default) or "match_host"
+ pub cpu_topology: Option<String>,
/// Version or range of versions of the virtual platform that this config is compatible with.
/// The format follows SemVer (https://semver.org).
pub platform_version: VersionReq,
@@ -96,7 +99,12 @@
} else {
0
};
-
+ let cpu_topology = match self.cpu_topology.as_deref() {
+ None => CpuTopology::ONE_CPU,
+ Some("one_cpu") => CpuTopology::ONE_CPU,
+ Some("match_host") => CpuTopology::MATCH_HOST,
+ Some(cpu_topology) => bail!("Invalid cpu topology {}", cpu_topology),
+ };
Ok(VirtualMachineRawConfig {
kernel: maybe_open_parcel_file(&self.kernel, false)?,
initrd: maybe_open_parcel_file(&self.initrd, false)?,
@@ -105,6 +113,7 @@
disks: self.disks.iter().map(DiskImage::to_parcelable).collect::<Result<_, Error>>()?,
protectedVm: self.protected,
memoryMib: memory_mib,
+ cpuTopology: cpu_topology,
platformVersion: self.platform_version.to_string(),
devices: self
.devices