Skip to content

Commit

Permalink
Merge pull request #92 from morningtzh/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Burning1020 authored Sep 15, 2023
2 parents c189530 + b14f486 commit cec5440
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 2 additions & 0 deletions vmm/sandbox/config_clh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ kernel_params = ""
hugepages = false
entropy_source = "/dev/urandom"
debug = true
[hypervisor.task]
debug = false
[hypervisor.virtiofsd]
path = "/usr/local/bin/virtiofsd"
log_level = "info"
Expand Down
47 changes: 45 additions & 2 deletions vmm/sandbox/src/cloud_hypervisor/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct CloudHypervisorVMConfig {
pub common: HypervisorCommonConfig,
pub hugepages: bool,
pub entropy_source: String,
pub task: TaskConfig,
pub virtiofsd: VirtiofsdConfig,
}

Expand All @@ -42,11 +43,17 @@ impl Default for CloudHypervisorVMConfig {
common: Default::default(),
hugepages: false,
entropy_source: "/dev/urandom".to_string(),
task: Default::default(),
virtiofsd: Default::default(),
}
}
}

#[derive(Deserialize, Default)]
pub struct TaskConfig {
pub debug: bool,
}

#[derive(CmdLineParamSet, Deserialize, Clone, Serialize)]
pub struct VirtiofsdConfig {
#[param(ignore)]
Expand Down Expand Up @@ -151,8 +158,11 @@ impl CloudHypervisorConfig {
"{} {}",
DEFAULT_KERNEL_PARAMS, vm_config.common.kernel_params
);
// TODO: for temporarily debug
cmdline.push_str(" task.log_level=debug");

if vm_config.task.debug {
cmdline.push_str(" task.log_level=debug");
}

Self {
path: vm_config.path.to_string(),
api_socket: "".to_string(),
Expand Down Expand Up @@ -234,6 +244,8 @@ initrd_path = \"\"
kernel_params = \"\"
hugepages = true
entropy_source = \"/dev/urandom\"
[hypervisor.task]
debug = true
[hypervisor.virtiofsd]
path = \"/usr/local/bin/virtiofsd\"
log_level = \"info\"
Expand All @@ -246,9 +258,40 @@ thread_pool_size = 4
config.hypervisor.common.kernel_path,
"/var/lib/kuasar/vmlinux.bin"
);
assert_eq!(config.hypervisor.task.debug, true);

assert_eq!(config.hypervisor.common.vcpus, 1);
assert!(config.hypervisor.hugepages);
assert_eq!(config.hypervisor.virtiofsd.thread_pool_size, 4);
assert_eq!(config.hypervisor.virtiofsd.path, "/usr/local/bin/virtiofsd");
}

#[test]
fn test_task_cmdline() {
let toml_str = "
[sandbox]
[hypervisor]
path = \"/usr/local/bin/cloud-hypervisor\"
vcpus = 1
memory_in_mb = 1024
kernel_path = \"/var/lib/kuasar/vmlinux.bin\"
image_path = \"/var/lib/kuasar/kuasar.img\"
initrd_path = \"\"
kernel_params = \"\"
hugepages = true
entropy_source = \"/dev/urandom\"
[hypervisor.task]
debug = true
[hypervisor.virtiofsd]
path = \"/usr/local/bin/virtiofsd\"
log_level = \"info\"
cache = \"never\"
thread_pool_size = 4
";

let config: Config<CloudHypervisorVMConfig> = toml::from_str(toml_str).unwrap();
let chc = CloudHypervisorConfig::from(&config.hypervisor);

assert_eq!(chc.cmdline, "console=hvc0 root=/dev/pmem0p1 rootflags=data=ordered,errors=remount-ro ro rootfstype=ext4 task.sharefs_type=virtiofs task.log_level=debug");
}
}

0 comments on commit cec5440

Please sign in to comment.