Skip to content

Commit

Permalink
vmm:qemu support config_qemu.toml
Browse files Browse the repository at this point in the history
Signed-off-by: liuxu <[email protected]>
  • Loading branch information
liuxu committed Nov 4, 2024
1 parent 056cc28 commit 313c2a6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 deletions.
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,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:
Expand All @@ -84,12 +85,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:
Expand Down
38 changes: 38 additions & 0 deletions vmm/sandbox/config_qemu_aarch64.toml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions vmm/sandbox/config_qemu_x86_64.toml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions vmm/sandbox/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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());
Expand Down
8 changes: 5 additions & 3 deletions vmm/sandbox/src/bin/qemu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -56,7 +55,7 @@ async fn main() {
trace::set_enabled(config.sandbox.enable_tracing);
trace::setup_tracing(&log_level, service_name).unwrap();

let sandboxer: KuasarSandboxer<QemuVMFactory, QemuHooks> = KuasarSandboxer::new(
let mut sandboxer: KuasarSandboxer<QemuVMFactory, QemuHooks> = KuasarSandboxer::new(
config.sandbox,
config.hypervisor.clone(),
QemuHooks::new(config.hypervisor),
Expand All @@ -66,6 +65,9 @@ async fn main() {
signal::handle_signals(&log_level, service_name).await;
});

// Do recovery job
sandboxer.recover(&args.dir).await;

// Run the sandboxer
containerd_sandbox::run(
"kuasar-vmm-sandboxer-qemu",
Expand Down
1 change: 1 addition & 0 deletions vmm/sandbox/src/qemu/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 313c2a6

Please sign in to comment.