Add vm subcommand to check support for protected and unprotected VMs.

Test: adb shell /apex/com.android.virt/bin/vm info
Change-Id: I9ed881a82818edacb81446b7684e90ae684bf1e8
This commit is contained in:
Andrew Walbran 2022-02-03 15:26:02 +00:00
parent 926806da78
commit c4b1bde4ff
2 changed files with 34 additions and 1 deletions

View File

@ -15,6 +15,7 @@ rust_binary {
"liblibc",
"liblog_rust",
"libmicrodroid_payload_config",
"librustutils",
"libserde_json",
"libserde",
"libstructopt",

View File

@ -26,7 +26,8 @@ use android_system_virtualizationservice::binder::{wait_for_interface, ProcessSt
use anyhow::{Context, Error};
use create_partition::command_create_partition;
use run::{command_run, command_run_app};
use std::path::PathBuf;
use rustutils::system_properties;
use std::path::{Path, PathBuf};
use structopt::clap::AppSettings;
use structopt::StructOpt;
@ -126,6 +127,8 @@ enum Opt {
},
/// List running virtual machines
List,
/// Print information about virtual machine support
Info,
/// Create a new empty partition to be used as a writable partition for a VM
CreatePartition {
/// Path at which to create the image file
@ -212,6 +215,7 @@ fn main() -> Result<(), Error> {
}
Opt::Stop { cid } => command_stop(service, cid),
Opt::List => command_list(service),
Opt::Info => command_info(),
Opt::CreatePartition { path, size, partition_type } => {
command_create_partition(service, &path, size, partition_type)
}
@ -233,3 +237,31 @@ fn command_list(service: Strong<dyn IVirtualizationService>) -> Result<(), Error
println!("Running VMs: {:#?}", vms);
Ok(())
}
/// Print information about supported VM types.
fn command_info() -> Result<(), Error> {
let unprotected_vm_supported =
system_properties::read_bool("ro.boot.hypervisor.vm.supported", false)?;
let protected_vm_supported =
system_properties::read_bool("ro.boot.hypervisor.protected_vm.supported", false)?;
match (unprotected_vm_supported, protected_vm_supported) {
(false, false) => println!("VMs are not supported."),
(false, true) => println!("Only protected VMs are supported."),
(true, false) => println!("Only unprotected VMs are supported."),
(true, true) => println!("Both protected and unprotected VMs are supported."),
}
if let Ok(version) = system_properties::read("ro.boot.hypervisor.version") {
println!("Hypervisor version: {}", version);
} else {
println!("Hypervisor version not set.");
}
if Path::new("/dev/kvm").exists() {
println!("/dev/kvm exists.");
} else {
println!("/dev/kvm does not exist.");
}
Ok(())
}