vmm: Fix --platform syntax with optional feature flags

The `--platform` help string was hardcoded and did not reflect which
optional features (tdx, sev_snp) were actually enabled in. Build the
syntax string dynamically as `PlatformConfig::syntax()`, conditionally
appending feature-gated options so the CLI help stays accurate.

Signed-off-by: Bo Chen <bchen@crusoe.ai>
This commit is contained in:
Bo Chen
2025-08-19 21:35:22 +00:00
parent de601c5eaa
commit 7f377eadd9
2 changed files with 28 additions and 3 deletions

View File

@@ -33,8 +33,8 @@ use vmm::vm_config::FwCfgConfig;
use vmm::vm_config::IvshmemConfig;
use vmm::vm_config::{
BalloonConfig, DeviceConfig, DiskConfig, FsConfig, GenericVhostUserConfig, LandlockConfig,
NetConfig, NumaConfig, PciSegmentConfig, PmemConfig, RateLimiterGroupConfig, TpmConfig,
UserDeviceConfig, VdpaConfig, VmConfig, VsockConfig,
NetConfig, NumaConfig, PciSegmentConfig, PlatformConfig, PmemConfig, RateLimiterGroupConfig,
TpmConfig, UserDeviceConfig, VdpaConfig, VmConfig, VsockConfig,
};
use vmm_sys_util::eventfd::EventFd;
use vmm_sys_util::signal::block_signal;
@@ -388,7 +388,7 @@ fn get_cli_options_sorted(
Arg::new("platform")
.long("platform")
.help(
"num_pci_segments=<num_pci_segments>,iommu_segments=<list_of_segments>,iommu_address_width=<bits>,serial_number=<dmi_device_serial_number>,uuid=<dmi_device_uuid>,oem_strings=<list_of_strings>"
PlatformConfig::syntax()
)
.num_args(1)
.group("vm-config"),

View File

@@ -9,6 +9,7 @@ use std::fs;
use std::path::PathBuf;
use std::result;
use std::str::FromStr;
use std::sync::LazyLock;
use block::ImageType;
use clap::ArgMatches;
@@ -798,6 +799,30 @@ impl PciSegmentConfig {
}
impl PlatformConfig {
pub fn syntax() -> &'static str {
static SYNTAX: LazyLock<String> = LazyLock::new(|| {
let mut syntax = "Platform configuration parameters \
\"num_pci_segments=<num_pci_segments>,iommu_segments=<list_of_segments>,\
iommu_address_width=<bits>,serial_number=<dmi_device_serial_number>,\
uuid=<dmi_device_uuid>,oem_strings=<list_of_strings>"
.to_string();
if cfg!(feature = "tdx") {
syntax.push_str(",tdx=on|off");
}
if cfg!(feature = "sev_snp") {
syntax.push_str(",sev_snp=on|off");
}
syntax.push('"');
syntax
});
&SYNTAX
}
pub fn parse(platform: &str) -> Result<Self> {
let mut parser = OptionParser::new();
parser