218 lines
7.5 KiB
Diff
218 lines
7.5 KiB
Diff
From 753b9dc20b825a08ecad8d7e00da451153354f00 Mon Sep 17 00:00:00 2001
|
|
From: liuxu <liuxu156@huawei.com>
|
|
Date: Fri, 25 Oct 2024 17:25:19 +0800
|
|
Subject: [PATCH] vmm:qemu support config_qemu.toml
|
|
|
|
Signed-off-by: liuxu <liuxu156@huawei.com>
|
|
---
|
|
Makefile | 18 +++++++------
|
|
vmm/sandbox/config_qemu_aarch64.toml | 38 ++++++++++++++++++++++++++++
|
|
vmm/sandbox/config_qemu_x86_64.toml | 38 ++++++++++++++++++++++++++++
|
|
vmm/sandbox/src/args.rs | 6 ++---
|
|
vmm/sandbox/src/bin/qemu/main.rs | 8 +++---
|
|
vmm/sandbox/src/qemu/config.rs | 1 +
|
|
6 files changed, 95 insertions(+), 14 deletions(-)
|
|
create mode 100644 vmm/sandbox/config_qemu_aarch64.toml
|
|
create mode 100644 vmm/sandbox/config_qemu_x86_64.toml
|
|
|
|
diff --git a/Makefile b/Makefile
|
|
index 60b3273..a6fff58 100644
|
|
--- a/Makefile
|
|
+++ b/Makefile
|
|
@@ -52,10 +52,11 @@ wasm: bin/wasm-sandboxer
|
|
quark: bin/quark-sandboxer
|
|
runc: bin/runc-sandboxer
|
|
|
|
-ifeq ($(HYPERVISOR), stratovirt)
|
|
-vmm: bin/vmm-sandboxer bin/kuasar.initrd bin/vmlinux.bin
|
|
-else
|
|
+ifeq ($(HYPERVISOR), cloud_hypervisor)
|
|
vmm: bin/vmm-sandboxer bin/kuasar.img bin/vmlinux.bin
|
|
+else
|
|
+# stratovirt or qemu
|
|
+vmm: bin/vmm-sandboxer bin/kuasar.initrd bin/vmlinux.bin
|
|
endif
|
|
|
|
clean:
|
|
@@ -76,12 +77,13 @@ install-vmm:
|
|
@install -d -m 750 ${DEST_DIR}${SYSTEMD_CONF_DIR}
|
|
@install -p -m 640 vmm/service/kuasar-vmm ${DEST_DIR}${SYSTEMD_CONF_DIR}/kuasar-vmm
|
|
|
|
-ifeq ($(HYPERVISOR), stratovirt)
|
|
- @install -p -m 640 bin/kuasar.initrd ${DEST_DIR}${INSTALL_DIR}/kuasar.initrd
|
|
- @install -p -m 640 vmm/sandbox/config_stratovirt_${ARCH}.toml ${DEST_DIR}${INSTALL_DIR}/config_stratovirt.toml
|
|
-else
|
|
+ifeq ($(HYPERVISOR), cloud_hypervisor)
|
|
@install -p -m 640 bin/kuasar.img ${DEST_DIR}${INSTALL_DIR}/kuasar.img
|
|
- @install -p -m 640 vmm/sandbox/config_clh.toml ${DEST_DIR}${INSTALL_DIR}/config_clh.toml
|
|
+ @install -p -m 640 vmm/sandbox/config_clh.toml ${DEST_DIR}${INSTALL_DIR}/config.toml
|
|
+else
|
|
+# stratovirt or qemu
|
|
+ @install -p -m 640 bin/kuasar.initrd ${DEST_DIR}${INSTALL_DIR}/kuasar.initrd
|
|
+ @install -p -m 640 vmm/sandbox/config_${HYPERVISOR}_${ARCH}.toml ${DEST_DIR}${INSTALL_DIR}/config.toml
|
|
endif
|
|
|
|
install-wasm:
|
|
diff --git a/vmm/sandbox/config_qemu_aarch64.toml b/vmm/sandbox/config_qemu_aarch64.toml
|
|
new file mode 100644
|
|
index 0000000..c4608e0
|
|
--- /dev/null
|
|
+++ b/vmm/sandbox/config_qemu_aarch64.toml
|
|
@@ -0,0 +1,38 @@
|
|
+[sandbox]
|
|
+log_level = "info"
|
|
+
|
|
+[hypervisor]
|
|
+memory_in_mb = 2048
|
|
+vcpus = 1
|
|
+kernel_params = "task.log_level=debug task.sharefs_type=9p tsc=reliable rcupdate.rcu_expedited=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 i8042.noaux=1 noreplace-smp= reboot=k console=hvc0 console=hvc1 iommu=off cryptomgr.notests= net.ifnames=0 pci=lastbus=0"
|
|
+kernel_path = "/var/lib/kuasar/vmlinux.bin"
|
|
+initrd_path = "/var/lib/kuasar/kuasar.initrd"
|
|
+machine_accelerators = ""
|
|
+firmware_path = ""
|
|
+cpu_features = "pmu=off"
|
|
+cpu_model = "host"
|
|
+qemu_path = "/usr/bin/qemu-system-aarch64"
|
|
+machine_type = "virt"
|
|
+default_bridges = 1
|
|
+default_max_vcpus = 0
|
|
+entropy_source = "/dev/urandom"
|
|
+mem_slots = 1
|
|
+mem_offset = 0
|
|
+memory_path = ""
|
|
+file_backend_mem_path = ""
|
|
+mem_prealloc = false
|
|
+hugepages = false
|
|
+enable_vhost_user_store = false
|
|
+enable_swap = false
|
|
+virtiofs_daemon_path = "/usr/libexec/virtiofsd"
|
|
+virtiofs_cache = "auto"
|
|
+virtiofs_extra_args = ["--thread-pool-size=1", "--announce-submounts"]
|
|
+virtiofs_cache_size = 0
|
|
+msize_9p = 8192
|
|
+virtio_9p_direct_io = false
|
|
+virtio_9p_multidevs = ""
|
|
+enable_iothreads = false
|
|
+block_device_driver = "VirtioScsi"
|
|
+disable_nvdimm = true
|
|
+share_fs = "Virtio9P"
|
|
+use_vsock = true
|
|
diff --git a/vmm/sandbox/config_qemu_x86_64.toml b/vmm/sandbox/config_qemu_x86_64.toml
|
|
new file mode 100644
|
|
index 0000000..340f694
|
|
--- /dev/null
|
|
+++ b/vmm/sandbox/config_qemu_x86_64.toml
|
|
@@ -0,0 +1,38 @@
|
|
+[sandbox]
|
|
+log_level = "info"
|
|
+
|
|
+[hypervisor]
|
|
+memory_in_mb = 2048
|
|
+vcpus = 1
|
|
+kernel_params = "task.log_level=debug task.sharefs_type=9p tsc=reliable rcupdate.rcu_expedited=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 i8042.noaux=1 noreplace-smp= reboot=k console=hvc0 console=hvc1 iommu=off cryptomgr.notests= net.ifnames=0 pci=lastbus=0"
|
|
+kernel_path = "/var/lib/kuasar/vmlinux.bin"
|
|
+initrd_path = "/var/lib/kuasar/kuasar.initrd"
|
|
+machine_accelerators = ""
|
|
+firmware_path = ""
|
|
+cpu_features = ""
|
|
+cpu_model = "host"
|
|
+qemu_path = "/usr/bin/qemu-system-x86_64"
|
|
+machine_type = "pc"
|
|
+default_bridges = 1
|
|
+default_max_vcpus = 0
|
|
+entropy_source = "/dev/urandom"
|
|
+mem_slots = 1
|
|
+mem_offset = 0
|
|
+memory_path = ""
|
|
+file_backend_mem_path = ""
|
|
+mem_prealloc = false
|
|
+hugepages = false
|
|
+enable_vhost_user_store = false
|
|
+enable_swap = false
|
|
+virtiofs_daemon_path = "/usr/bin/virtiofsd"
|
|
+virtiofs_cache = "always"
|
|
+virtiofs_extra_args = []
|
|
+virtiofs_cache_size = 1024
|
|
+msize_9p = 8192
|
|
+virtio_9p_direct_io = false
|
|
+virtio_9p_multidevs = ""
|
|
+enable_iothreads = false
|
|
+block_device_driver = "VirtioBlk"
|
|
+disable_nvdimm = true
|
|
+share_fs = "Virtio9P"
|
|
+use_vsock = true
|
|
diff --git a/vmm/sandbox/src/args.rs b/vmm/sandbox/src/args.rs
|
|
index 72e74d3..d6262dc 100644
|
|
--- a/vmm/sandbox/src/args.rs
|
|
+++ b/vmm/sandbox/src/args.rs
|
|
@@ -22,12 +22,12 @@ pub struct Args {
|
|
#[arg(short, long)]
|
|
pub version: bool,
|
|
|
|
- /// Config file path, only for cloud hypervisor and stratovirt, default is `/var/lib/kuasar/config_clh.toml`
|
|
+ /// Config file path, for cloud hypervisor, qemu and stratovirt, default is `/var/lib/kuasar/config.toml`
|
|
#[arg(
|
|
short,
|
|
long,
|
|
value_name = "FILE",
|
|
- default_value = "/var/lib/kuasar/config_clh.toml"
|
|
+ default_value = "/var/lib/kuasar/config.toml"
|
|
)]
|
|
pub config: String,
|
|
|
|
@@ -61,7 +61,7 @@ mod tests {
|
|
fn test_args_parse_default() {
|
|
let args = Args::parse();
|
|
assert!(!args.version);
|
|
- assert_eq!(args.config, "/var/lib/kuasar/config_clh.toml");
|
|
+ assert_eq!(args.config, "/var/lib/kuasar/config.toml");
|
|
assert_eq!(args.dir, "/run/kuasar-vmm");
|
|
assert_eq!(args.listen, "/run/vmm-sandboxer.sock");
|
|
assert!(args.log_level.is_none());
|
|
diff --git a/vmm/sandbox/src/bin/qemu/main.rs b/vmm/sandbox/src/bin/qemu/main.rs
|
|
index 4d76f9e..8edb32a 100644
|
|
--- a/vmm/sandbox/src/bin/qemu/main.rs
|
|
+++ b/vmm/sandbox/src/bin/qemu/main.rs
|
|
@@ -34,8 +34,7 @@ async fn main() {
|
|
}
|
|
|
|
// For compatibility with kata config
|
|
- let config_path = std::env::var("KATA_CONFIG_PATH")
|
|
- .unwrap_or_else(|_| "/usr/share/defaults/kata-containers/configuration.toml".to_string());
|
|
+ let config_path = std::env::var("KATA_CONFIG_PATH").unwrap_or_default();
|
|
let path = std::path::Path::new(&config_path);
|
|
|
|
let config = if path.exists() {
|
|
@@ -54,12 +53,15 @@ async fn main() {
|
|
// Initialize log
|
|
init_logger(&config.sandbox.log_level());
|
|
|
|
- let sandboxer: KuasarSandboxer<QemuVMFactory, QemuHooks> = KuasarSandboxer::new(
|
|
+ let mut sandboxer: KuasarSandboxer<QemuVMFactory, QemuHooks> = KuasarSandboxer::new(
|
|
config.sandbox,
|
|
config.hypervisor.clone(),
|
|
QemuHooks::new(config.hypervisor),
|
|
);
|
|
|
|
+ // Do recovery job
|
|
+ sandboxer.recover(&args.dir).await;
|
|
+
|
|
// Run the sandboxer
|
|
containerd_sandbox::run(
|
|
"kuasar-vmm-sandboxer-qemu",
|
|
diff --git a/vmm/sandbox/src/qemu/config.rs b/vmm/sandbox/src/qemu/config.rs
|
|
index bf3c986..408a39b 100644
|
|
--- a/vmm/sandbox/src/qemu/config.rs
|
|
+++ b/vmm/sandbox/src/qemu/config.rs
|
|
@@ -64,6 +64,7 @@ lazy_static! {
|
|
|
|
#[derive(Clone, Debug, Deserialize)]
|
|
pub struct QemuVMConfig {
|
|
+ #[serde(flatten)]
|
|
pub common: HypervisorCommonConfig,
|
|
pub machine_accelerators: String,
|
|
pub firmware_path: String,
|
|
--
|
|
2.43.0
|
|
|