Skip to content

Commit

Permalink
Merge pull request #420 from stlankes/nemo
Browse files Browse the repository at this point in the history
add support of a configuration file
  • Loading branch information
stlankes authored Feb 17, 2025
2 parents ec4e7a9 + 0df470f commit 51ced2f
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 7 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ nix = { version = "0.29", features = [
"user",
"zerocopy",
] }
toml = "0.8.20"
oci-spec = "0.7"
path-clean = "1.0"
procfs = { version = "0.17", default-features = false }
Expand Down
23 changes: 18 additions & 5 deletions src/hermit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get_qemu_args(
netconf: &NetworkConfig,
app_args: &[String],
micro_vm: bool,
kvm: bool,
kvm_support: bool,
tap_fd: &Option<i32>,
) -> Vec<String> {
let mut exec_args: Vec<String> = vec![
Expand All @@ -51,14 +51,27 @@ pub fn get_qemu_args(
.map(|s| s.to_string())
.collect();

if kvm {
exec_args.append(
&mut ["--enable-kvm", "-cpu", "host"]
if let Some(kvm) = crate::CONFIG.kvm {
if kvm && kvm_support {
exec_args.append(
&mut ["--enable-kvm", "-cpu", "host"]
.iter()
.map(|s| s.to_string())
.collect(),
);
} else {
exec_args.append(
&mut [
"-cpu",
"qemu64,apic,fsgsbase,rdtscp,xsave,xsaveopt,fxsr,rdrand",
]
.iter()
.map(|s| s.to_string())
.collect(),
);
);
}
} else {
// disable kvm support, if the configuration file doesn't enable it
exec_args.append(
&mut [
"-cpu",
Expand Down
34 changes: 32 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,39 @@ use crate::spec::*;
use crate::start::*;
use crate::state::*;
use clap::{crate_version, Parser, Subcommand};
use std::fs::DirBuilder;
use serde::Deserialize;
use std::fs::{read_to_string, DirBuilder};
use std::os::unix::fs::DirBuilderExt;
use std::{env, path::PathBuf};
use std::sync::LazyLock;
use std::{env, path::Path, path::PathBuf};

/// This is what we're going to decode into. Each field is optional, meaning
/// that it doesn't have to be present in TOML.
#[derive(Debug, Deserialize)]
struct Config {
kvm: Option<bool>,
}

impl Config {
pub const fn new() -> Self {
Self { kvm: None }
}
}

static CONFIG: LazyLock<Config> =
LazyLock::new(
|| match read_to_string(Path::new("/etc/runh/config.toml")) {
Ok(content) => {
let decoded: Result<Config, toml::de::Error> = toml::from_str(&content);
if let Ok(config) = decoded {
config
} else {
Config::new()
}
}
Err(_) => Config::new(),
},
);

fn parse_matches(cli: &Cli) {
let project_dir = &cli.root;
Expand Down

0 comments on commit 51ced2f

Please sign in to comment.