Specify virtual platform version and enforce it
VM config can now specify the requirement on the virtual platform
version. At runtime, the requirement is matched against the actual
virtual platform version that crosvm implements. If they don't match,
the VM can't be created. The version format follows SemVer, allowing us
to express backwards compatible and incompatible changes in the future.
Bug: 193504487
Test: atest VirtualizationTestCases
Change-Id: I23d370081e10399502178b9cfe8a46b05addf186
diff --git a/virtualizationservice/src/crosvm.rs b/virtualizationservice/src/crosvm.rs
index df7a7d2..94cb78f 100644
--- a/virtualizationservice/src/crosvm.rs
+++ b/virtualizationservice/src/crosvm.rs
@@ -19,6 +19,7 @@
use anyhow::{bail, Error};
use command_fds::CommandFdExt;
use log::{debug, error, info};
+use semver::{Version, VersionReq};
use shared_child::SharedChild;
use std::fs::{remove_dir_all, File};
use std::io;
@@ -36,6 +37,12 @@
const CROSVM_PATH: &str = "/apex/com.android.virt/bin/crosvm";
+/// Version of the platform that crosvm currently implements. The format follows SemVer. This
+/// should be updated when there is a platform change in the crosvm side. Having this value here is
+/// fine because virtualizationservice and crosvm are supposed to be updated together in the virt
+/// APEX.
+const CROSVM_PLATFORM_VERSION: &str = "1.0.0";
+
/// The exit status which crosvm returns when it has an error starting a VM.
const CROSVM_ERROR_STATUS: i32 = 1;
/// The exit status which crosvm returns when a VM requests a reboot.
@@ -59,6 +66,7 @@
pub console_fd: Option<File>,
pub log_fd: Option<File>,
pub indirect_files: Vec<File>,
+ pub platform_version: VersionReq,
}
/// A disk image to pass to crosvm for a VM.
@@ -365,6 +373,16 @@
if config.bootloader.is_some() && (config.kernel.is_some() || config.initrd.is_some()) {
bail!("Can't have both bootloader and kernel/initrd image.");
}
+ let version = Version::parse(CROSVM_PLATFORM_VERSION).unwrap();
+ if !config.platform_version.matches(&version) {
+ bail!(
+ "Incompatible platform version. The config is compatible with platform version(s) \
+ {}, but the actual platform version is {}",
+ config.platform_version,
+ version
+ );
+ }
+
Ok(())
}