mod host_vmm;
mod load;
mod paravisor_vmm;
mod run;
use clap::Parser;
use pal_async::DefaultDriver;
use pal_async::DefaultPool;
use run::CommonState;
use std::path::PathBuf;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
.pretty()
.map_event_format(|e| e.with_source_location(false))
.fmt_fields(tracing_helpers::formatter::FieldFormatter)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE),
)
.with(
tracing_subscriber::EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.with_env_var("TMK_LOG")
.from_env_lossy(),
)
.init();
DefaultPool::run_with(do_main)
}
#[derive(Parser)]
struct Options {
#[clap(long)]
hv: HypervisorOpt,
#[clap(long)]
tmk: PathBuf,
}
#[derive(clap::ValueEnum, Clone)]
enum HypervisorOpt {
#[cfg(target_os = "linux")]
Kvm,
#[cfg(all(target_os = "linux", guest_arch = "x86_64"))]
Mshv,
#[cfg(target_os = "linux")]
MshvVtl,
#[cfg(target_os = "windows")]
Whp,
#[cfg(target_os = "macos")]
Hvf,
}
async fn do_main(driver: DefaultDriver) -> anyhow::Result<()> {
let opts = Options::parse();
let mut state = CommonState::new(driver, opts).await?;
match state.opts.hv {
#[cfg(target_os = "linux")]
HypervisorOpt::Kvm => state.run_host_vmm(virt_kvm::Kvm).await,
#[cfg(all(target_os = "linux", guest_arch = "x86_64"))]
HypervisorOpt::Mshv => state.run_host_vmm(virt_mshv::LinuxMshv).await,
#[cfg(target_os = "linux")]
HypervisorOpt::MshvVtl => state.run_paravisor_vmm(virt::IsolationType::None).await,
#[cfg(windows)]
HypervisorOpt::Whp => state.run_host_vmm(virt_whp::Whp).await,
#[cfg(target_os = "macos")]
HypervisorOpt::Hvf => state.run_host_vmm(virt_hvf::HvfHypervisor).await,
}
}