main: add --no-shutdown

Add a CLI-only --no-shutdown flag that keeps the VMM process alive
after a guest-triggered shutdown.

Management software may still need the Cloud Hypervisor process
after the guest has powered off. Exposing this separately lets
management software, for example libvirt, keep the VMM around in a
way that is closer to QEMU.

The flag only affects the GuestExit path. Fatal exits and other
existing VMM shutdown paths remain unchanged.

On-behalf-of: SAP leander.kohler@sap.com
Signed-off-by: Leander Kohler <leander.kohler@cyberus-technology.de>
This commit is contained in:
Leander Kohler
2026-03-09 16:35:34 +01:00
committed by Rob Bradford
parent a159152e41
commit 005ce38ffd
2 changed files with 24 additions and 3 deletions

View File

@@ -373,6 +373,12 @@ fn get_cli_options_sorted(
.num_args(1..)
.action(ArgAction::Append)
.group("vm-config"),
Arg::new("no-shutdown")
.long("no-shutdown")
.help("Do not exit the VMM when the guest shuts down")
.num_args(0)
.action(ArgAction::SetTrue)
.group("vmm-config"),
Arg::new("numa")
.long("numa")
.help(NumaConfig::SYNTAX)
@@ -637,6 +643,7 @@ fn start_vmm(
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateExitEventFd)?;
let landlock_enable = cmd_arguments.get_flag("landlock");
let no_shutdown = cmd_arguments.get_flag("no-shutdown");
#[allow(unused_mut)]
let mut event_monitor = cmd_arguments
@@ -733,6 +740,7 @@ fn start_vmm(
exit_evt.try_clone().unwrap(),
&seccomp_action,
hypervisor,
no_shutdown,
landlock_enable,
)
.map_err(Error::StartVmmThread)?;

View File

@@ -162,6 +162,10 @@ pub enum Error {
#[error("Error rebooting VM")]
VmReboot(#[source] VmError),
/// Cannot shut the VM down
#[error("Error shutting down VM")]
VmShutdown(#[source] VmError),
/// Cannot create VMM thread
#[error("Error spawning VMM thread")]
VmmThreadSpawn(#[source] io::Error),
@@ -449,6 +453,7 @@ pub fn start_vmm_thread(
exit_event: EventFd,
seccomp_action: &SeccompAction,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
no_shutdown: bool,
landlock_enable: bool,
) -> Result<VmmThreadHandle> {
#[cfg(feature = "guest_debug")]
@@ -488,6 +493,7 @@ pub fn start_vmm_thread(
vmm_seccomp_action,
hypervisor,
exit_event,
no_shutdown,
)?;
vmm.setup_signal_handler(landlock_enable)?;
@@ -627,6 +633,7 @@ pub struct Vmm {
original_termios_opt: Arc<Mutex<Option<termios>>>,
console_resize_pipe: Option<Arc<File>>,
console_info: Option<ConsoleInfo>,
no_shutdown: bool,
}
/// Just a wrapper for the data that goes into
@@ -781,6 +788,7 @@ impl Vmm {
seccomp_action: SeccompAction,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
exit_evt: EventFd,
no_shutdown: bool,
) -> Result<Self> {
let mut epoll = EpollContext::new().map_err(Error::Epoll)?;
let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
@@ -833,6 +841,7 @@ impl Vmm {
original_termios_opt: Arc::new(Mutex::new(None)),
console_resize_pipe: None,
console_info: None,
no_shutdown,
})
}
@@ -1688,9 +1697,12 @@ impl Vmm {
EpollDispatch::GuestExit => {
info!("VM guest exit event");
self.guest_exit_evt.read().map_err(Error::EventFdRead)?;
self.vmm_shutdown().map_err(Error::VmmShutdown)?;
break 'outer;
if self.no_shutdown {
self.vm_shutdown().map_err(Error::VmShutdown)?;
} else {
self.vmm_shutdown().map_err(Error::VmmShutdown)?;
break 'outer;
}
}
EpollDispatch::ActivateVirtioDevices => {
if let Some(ref vm) = self.vm {
@@ -2630,6 +2642,7 @@ mod unit_tests {
SeccompAction::Allow,
hypervisor::new().unwrap(),
EventFd::new(EFD_NONBLOCK).unwrap(),
false,
)
.unwrap()
}