mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
devices: Add fw_cfg cli options
This allows us to enable/disable the fw_cfg device via the cli We can also now upload files into the guest vm using fw_cfg_items via the cli Signed-off-by: Alex Orozco <alexorozco@google.com>
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
//
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::path::PathBuf;
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
use std::str::FromStr;
|
||||
use std::{fs, result};
|
||||
|
||||
use net_util::MacAddr;
|
||||
@@ -699,6 +701,79 @@ pub struct PayloadConfig {
|
||||
#[cfg(feature = "sev_snp")]
|
||||
#[serde(default)]
|
||||
pub host_data: Option<String>,
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
pub fw_cfg_config: Option<FwCfgConfig>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct FwCfgConfig {
|
||||
pub e820: bool,
|
||||
pub kernel: bool,
|
||||
pub cmdline: bool,
|
||||
pub initramfs: bool,
|
||||
pub acpi_tables: bool,
|
||||
pub items: Option<FwCfgItemList>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
impl Default for FwCfgConfig {
|
||||
fn default() -> Self {
|
||||
FwCfgConfig {
|
||||
e820: true,
|
||||
kernel: true,
|
||||
cmdline: true,
|
||||
initramfs: true,
|
||||
acpi_tables: true,
|
||||
items: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct FwCfgItemList {
|
||||
#[serde(default)]
|
||||
pub item_list: Vec<FwCfgItem>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct FwCfgItem {
|
||||
#[serde(default)]
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub file: PathBuf,
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
pub enum FwCfgItemError {
|
||||
InvalidValue(String),
|
||||
}
|
||||
|
||||
#[cfg(feature = "fw_cfg")]
|
||||
impl FromStr for FwCfgItemList {
|
||||
type Err = FwCfgItemError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let body = s
|
||||
.trim()
|
||||
.strip_prefix('[')
|
||||
.and_then(|s| s.strip_suffix(']'))
|
||||
.ok_or_else(|| FwCfgItemError::InvalidValue(s.to_string()))?;
|
||||
|
||||
let mut fw_cfg_items: Vec<FwCfgItem> = vec![];
|
||||
let items: Vec<&str> = body.split(':').collect();
|
||||
for item in items {
|
||||
fw_cfg_items.push(
|
||||
FwCfgItem::parse(item)
|
||||
.map_err(|_| FwCfgItemError::InvalidValue(item.to_string()))?,
|
||||
);
|
||||
}
|
||||
Ok(FwCfgItemList {
|
||||
item_list: fw_cfg_items,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplyLandlock for PayloadConfig {
|
||||
|
||||
Reference in New Issue
Block a user