mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: add enum PayloadConfigError validation to improve error reporting
Currently, the following scenarios are supported by Cloud Hypervisor to bootstrap a VM: 1. provide firmware 2. provide kernel 3. provide kernel + cmdline 4. provide kernel + initrd 5. provide kernel + cmdline + initrd As the difference between `--firmware` and `--kernel` is not very clear currently, especially as both use/support a Xen PVH entry, adding this helps to identify the cause of misconfiguration. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Bo Chen
parent
dac0638fe8
commit
dd8687aebb
@@ -181,9 +181,6 @@ pub enum Error {
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Error)]
|
||||
pub enum ValidationError {
|
||||
/// No kernel specified
|
||||
#[error("No kernel specified")]
|
||||
KernelMissing,
|
||||
/// Missing file value for console
|
||||
#[error("Path missing when using file console mode")]
|
||||
ConsoleFileMissing,
|
||||
@@ -356,6 +353,8 @@ pub enum ValidationError {
|
||||
/// Invalid Ivshmem backend file path
|
||||
#[error("Invalid ivshmem backend file path")]
|
||||
InvalidIvshmemPath,
|
||||
#[error("Payload configuration is not bootable")]
|
||||
PayloadError(#[from] PayloadConfigError),
|
||||
}
|
||||
|
||||
type ValidationResult<T> = std::result::Result<T, ValidationError>;
|
||||
@@ -2507,9 +2506,13 @@ impl VmConfig {
|
||||
pub fn validate(&mut self) -> ValidationResult<BTreeSet<String>> {
|
||||
let mut id_list = BTreeSet::new();
|
||||
|
||||
// Is the payload configuration bootable?
|
||||
self.payload
|
||||
.as_ref()
|
||||
.ok_or(ValidationError::KernelMissing)?;
|
||||
.as_mut()
|
||||
.ok_or(ValidationError::PayloadError(
|
||||
PayloadConfigError::MissingBootitem,
|
||||
))?
|
||||
.validate()?;
|
||||
|
||||
#[cfg(feature = "tdx")]
|
||||
{
|
||||
@@ -4216,7 +4219,9 @@ mod tests {
|
||||
invalid_config.payload = None;
|
||||
assert_eq!(
|
||||
invalid_config.validate(),
|
||||
Err(ValidationError::KernelMissing)
|
||||
Err(ValidationError::PayloadError(
|
||||
PayloadConfigError::MissingBootitem
|
||||
))
|
||||
);
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
|
||||
Reference in New Issue
Block a user