weird
parent
9ed17eca06
commit
92452ce4d6
@ -0,0 +1,23 @@
|
||||
[qemu]
|
||||
script = "qemu.lua"
|
||||
|
||||
default = [
|
||||
"-rtc", "driftfix=slew",
|
||||
"-serial", "stdio",
|
||||
"-no-hpet",
|
||||
"-boot", "strict=on"
|
||||
]
|
||||
|
||||
arch.i686 = []
|
||||
arch.x86_64 = ["-global", "kvm-pit.lost_tick_policy=discard"]
|
||||
|
||||
uefi = [
|
||||
# OVMF will hang if S3 is not disabled
|
||||
# disable S4 too, since libvirt does that 🤷
|
||||
# https://bugs.archlinux.org/task/59465#comment172528
|
||||
"-global", "ICH9-LPC.disable_s3=1",
|
||||
"-global", "ICH9-LPC.disable_s4=1"
|
||||
]
|
||||
|
||||
[[disk.default]]
|
||||
flag = "blockdev"
|
@ -0,0 +1,37 @@
|
||||
function build_command(instance, args)
|
||||
args:add("-rtc", "driftfix=slew")
|
||||
args:add("-serial", "stdio")
|
||||
args:add("-no-hpet")
|
||||
args:add("-boot", "strict=on")
|
||||
|
||||
if instance.kvm then
|
||||
args:add("-enable-kvm")
|
||||
end
|
||||
|
||||
if instance.arch == "x86_64" or instance.arch == "i868" then
|
||||
args:add("-global", "kvm-pit.lost_tick_policy=discard")
|
||||
end
|
||||
|
||||
args:add("-no-user-config")
|
||||
args:add("-no-defaults")
|
||||
args:add("-no-shutdown")
|
||||
args:add("-m", tostring(instance.memory))
|
||||
|
||||
local cpu = instance.cpu;
|
||||
args:add(string.format("%d,sockets=%d,dies=%d,cores=%d,threads=%d",
|
||||
cpu.amount,
|
||||
cpu.sockets,
|
||||
cpu.dies,
|
||||
cpu.cores,
|
||||
cpu.threads))
|
||||
|
||||
if instance.uefi.enabled and string.find(instance.chipset, "q35") == 0 then
|
||||
-- OVMF will hang if S3 is not disabled
|
||||
-- disable S4 too, since libvirt does that 🤷
|
||||
-- https://bugs.archlinux.org/task/59465#comment172528
|
||||
args:add("-global", "ICH9-LPC.disable_s3=1")
|
||||
args:add("-global", "ICH9-LPC.disable_s4=1")
|
||||
end
|
||||
|
||||
return args
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
use anyhow::Context;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct GlobalConfig {
|
||||
pub qemu: GlobalQemuConfig,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct GlobalQemuConfig {
|
||||
pub default: Vec<String>,
|
||||
pub arch: HashMap<String, Vec<String>>,
|
||||
pub uefi: Vec<String>,
|
||||
}
|
||||
|
||||
impl GlobalConfig {
|
||||
pub fn load(toml: &str) -> Result<GlobalConfig, anyhow::Error> {
|
||||
toml::from_str(toml).context("Failed to parse toml for global config")
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
mod global_config;
|
||||
mod instance_config;
|
||||
mod qemu;
|
||||
|
||||
pub use global_config::*;
|
||||
pub use instance_config::*;
|
||||
pub use qemu::build_qemu_command;
|
||||
|
@ -0,0 +1,47 @@
|
||||
use crate::{GlobalConfig, InstanceConfig};
|
||||
use mlua::{Function, LuaSerdeExt, MultiValue, ToLua, UserData, UserDataMethods, Value};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Clone)]
|
||||
struct LuaFreeList(Vec<String>);
|
||||
|
||||
impl UserData for LuaFreeList {
|
||||
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||
methods.add_method_mut("add", |_, this, args: MultiValue| {
|
||||
for item in args.iter() {
|
||||
if let Value::String(item) = item {
|
||||
this.0.push(item.to_str()?.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Value::Nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build_qemu_command(config: &InstanceConfig, global_config: &GlobalConfig) -> Vec<String> {
|
||||
let lua = mlua::Lua::new();
|
||||
// TODO: load correct script
|
||||
lua.load(include_str!("../../config/qemu.lua"))
|
||||
.eval::<()>()
|
||||
.unwrap();
|
||||
let val: Function = lua.globals().get("build_command").unwrap();
|
||||
let item = LuaFreeList::default();
|
||||
let multi = MultiValue::from_vec(vec![
|
||||
lua.to_value(config).unwrap(),
|
||||
item.to_lua(&lua).unwrap(),
|
||||
]);
|
||||
let mut x = val.call::<MultiValue, LuaFreeList>(multi).unwrap();
|
||||
println!("{:?}", x);
|
||||
|
||||
let mut cmd: Vec<String> = vec![];
|
||||
cmd.push("-name".to_string());
|
||||
cmd.push(format!("guest={},debug-threads=on", config.name));
|
||||
|
||||
cmd.push("-S".to_string());
|
||||
cmd.push("-msg".to_string());
|
||||
cmd.push("timestamps=on".to_string());
|
||||
cmd.append(&mut x.0);
|
||||
|
||||
cmd
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
use crate::instance::build_qemu_command;
|
||||
use vore_core::InstanceConfig;
|
||||
use vore_core::{build_qemu_command, GlobalConfig, InstanceConfig};
|
||||
|
||||
mod instance;
|
||||
|
||||
fn main() {
|
||||
let cfg = InstanceConfig::from_toml(include_str!("../../config/example.toml")).unwrap();
|
||||
println!("Hello, world! {}", build_qemu_command(&cfg));
|
||||
let global = GlobalConfig::load(include_str!("../../config/global.toml")).unwrap();
|
||||
println!("Hello, world! {:?}", build_qemu_command(&cfg, &global));
|
||||
print!("hello world {:#?}", global);
|
||||
}
|
||||
|
Loading…
Reference in New Issue