Skip to content

Commit

Permalink
vmm: add task config to cloud hypervisor
Browse files Browse the repository at this point in the history
1. hypervisor.task.debug default false
2. hypervisor.task.sharefs_type default virtiofs
  • Loading branch information
morningtzh committed Sep 11, 2023
1 parent 7c18d6f commit d3792a8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions vmm/sandbox/config_clh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ kernel_params = ""
hugepages = false
entropy_source = "/dev/urandom"
debug = true
[hypervisor.task]
debug = false
sharefs_type = "virtiofs"
[hypervisor.virtiofsd]
path = "/usr/local/bin/virtiofsd"
log_level = "info"
Expand Down
63 changes: 61 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,28 @@ impl Default for CloudHypervisorVMConfig {
common: Default::default(),
hugepages: false,
entropy_source: "/dev/urandom".to_string(),
task: Default::default(),
virtiofsd: Default::default(),
}
}
}

#[derive(CmdLineParamSet, Deserialize, Clone, Serialize)]
pub struct TaskConfig {
#[param(ignore)]
pub debug: bool,
pub sharefs_type: String,
}

impl Default for TaskConfig {
fn default() -> Self {
Self {
debug: false,
sharefs_type: "virtiofs".to_string()
}
}
}

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

cmdline.push_str(format!(" task.sharefs_type={}", vm_config.task.sharefs_type).as_str());

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 +257,9 @@ initrd_path = \"\"
kernel_params = \"\"
hugepages = true
entropy_source = \"/dev/urandom\"
[hypervisor.task]
debug = true
sharefs_type = \"9p\"
[hypervisor.virtiofsd]
path = \"/usr/local/bin/virtiofsd\"
log_level = \"info\"
Expand All @@ -246,9 +272,42 @@ 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.task.sharefs_type, "9p");

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
sharefs_type = \"9p\"
[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.sharefs_type=9p task.log_level=debug");
}
}

0 comments on commit d3792a8

Please sign in to comment.