Skip to content

Commit bcd45c7

Browse files
committed
refactor command line
1 parent 6c69039 commit bcd45c7

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

petri/src/vm/hyperv/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::hyperv::powershell::HyperVSecureBootTemplate;
3030
use crate::kmsg_log_task;
3131
use crate::openhcl_diag::OpenHclDiagHandler;
3232
use crate::vm::append_cmdline;
33+
use crate::vm::append_log_params_to_cmdline;
3334
use anyhow::Context;
3435
use async_trait::async_trait;
3536
use get_resources::ged::FirmwareEvent;
@@ -434,9 +435,11 @@ impl PetriVmmBackend for HyperVPetriBackend {
434435
)
435436
.await?;
436437

437-
if let Some(command_line) = command_line {
438-
vm.set_vm_firmware_command_line(command_line).await?;
439-
}
438+
let mut command_line = command_line.clone();
439+
append_log_params_to_cmdline(&mut command_line);
440+
441+
vm.set_vm_firmware_command_line(command_line.unwrap())
442+
.await?;
440443

441444
vm.set_vmbus_redirect(*vmbus_redirect).await?;
442445

petri/src/vm/hyperv/vm.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,12 @@ impl HyperVVM {
484484
}
485485

486486
/// Sets the VM firmware command line.
487-
pub async fn set_vm_firmware_command_line(
487+
pub async fn set_vm_firmware_command_line<S: AsRef<str>>(
488488
&self,
489-
openhcl_command_line: &str,
489+
openhcl_command_line: S,
490490
) -> anyhow::Result<()> {
491-
powershell::run_set_vm_command_line(&self.vmid, &self.ps_mod, openhcl_command_line).await
491+
powershell::run_set_vm_command_line(&self.vmid, &self.ps_mod, openhcl_command_line.as_ref())
492+
.await
492493
}
493494

494495
/// Enable VMBusRelay

petri/src/vm/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,24 @@ fn append_cmdline(cmd: &mut Option<String>, add_cmd: impl AsRef<str>) {
17951795
}
17961796
}
17971797

1798+
fn append_log_params_to_cmdline(cmd: &mut Option<String>) {
1799+
// Forward OPENVMM_LOG and OPENVMM_SHOW_SPANS to OpenHCL if they're set.
1800+
let openhcl_tracing =
1801+
if let Ok(x) = std::env::var("OPENVMM_LOG").or_else(|_| std::env::var("HVLITE_LOG")) {
1802+
format!("OPENVMM_LOG={x}")
1803+
} else {
1804+
"OPENVMM_LOG=debug".to_owned()
1805+
};
1806+
let openhcl_show_spans = if let Ok(x) = std::env::var("OPENVMM_SHOW_SPANS") {
1807+
format!("OPENVMM_SHOW_SPANS={x}")
1808+
} else {
1809+
"OPENVMM_SHOW_SPANS=true".to_owned()
1810+
};
1811+
1812+
append_cmdline(cmd, openhcl_tracing);
1813+
append_cmdline(cmd, openhcl_show_spans);
1814+
}
1815+
17981816
async fn save_inspect(
17991817
name: &str,
18001818
inspect: std::pin::Pin<Box<dyn Future<Output = anyhow::Result<inspect::Node>> + Send>>,

petri/src/vm/openvmm/construct.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::linux_direct_serial_agent::LinuxDirectSerialAgent;
3030
use crate::openvmm::BOOT_NVME_INSTANCE;
3131
use crate::openvmm::memdiff_vmgs;
3232
use crate::vm::append_cmdline;
33+
use crate::vm::append_log_params_to_cmdline;
3334
use crate::vtl2_settings::ControllerType;
3435
use crate::vtl2_settings::Vtl2LunBuilder;
3536
use crate::vtl2_settings::Vtl2StorageBackingDeviceBuilder;
@@ -587,19 +588,6 @@ impl PetriVmConfigSetupCore<'_> {
587588
}
588589

589590
fn load_firmware(&self) -> anyhow::Result<LoadMode> {
590-
// Forward OPENVMM_LOG and OPENVMM_SHOW_SPANS to OpenHCL if they're set.
591-
let openhcl_tracing =
592-
if let Ok(x) = std::env::var("OPENVMM_LOG").or_else(|_| std::env::var("HVLITE_LOG")) {
593-
format!("OPENVMM_LOG={x}")
594-
} else {
595-
"OPENVMM_LOG=debug".to_owned()
596-
};
597-
let openhcl_show_spans = if let Ok(x) = std::env::var("OPENVMM_SHOW_SPANS") {
598-
format!("OPENVMM_SHOW_SPANS={x}")
599-
} else {
600-
"OPENVMM_SHOW_SPANS=true".to_owned()
601-
};
602-
603591
Ok(match (self.arch, &self.firmware) {
604592
(MachineArch::X86_64, Firmware::LinuxDirect { kernel, initrd }) => {
605593
let kernel = File::open(kernel.clone())
@@ -697,10 +685,8 @@ impl PetriVmConfigSetupCore<'_> {
697685

698686
let mut cmdline = command_line.clone();
699687

700-
append_cmdline(
701-
&mut cmdline,
702-
format!("panic=-1 reboot=triple {openhcl_tracing} {openhcl_show_spans}"),
703-
);
688+
append_cmdline(&mut cmdline, format!("panic=-1 reboot=triple"));
689+
append_log_params_to_cmdline(&mut cmdline);
704690

705691
let isolated = match self.firmware {
706692
Firmware::OpenhclLinuxDirect { .. } => {

0 commit comments

Comments
 (0)