vmm: api: Add a VMM shutdown command

This shuts the current VM down, if any, and then exits the VMM process.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-10-08 15:23:29 +02:00
committed by Sebastien Boeuf
parent 228adebc32
commit a95fa1c4e8
5 changed files with 80 additions and 11 deletions

View File

@@ -69,6 +69,9 @@ pub enum Error {
/// Cannot create VMM thread
VmmThreadSpawn(io::Error),
/// Cannot shut the VMM down
VmmShutdown(VmError),
}
pub type Result<T> = result::Result<T, Error>;
@@ -168,14 +171,7 @@ pub fn start_vmm_thread(
// Continue and restart the VMM control loop
continue 'outer;
}
Ok(ExitBehaviour::Shutdown) => {
// The VMM control loop exites with a shutdown behaviour.
// We have to stop the VM and we exit thr thread.
if let Some(ref mut vm) = vmm.vm {
vm.shutdown().map_err(Error::VmShutdown)?;
}
break 'outer;
}
Ok(ExitBehaviour::Shutdown) => break 'outer,
Err(e) => return Err(e),
}
}
@@ -320,6 +316,10 @@ impl Vmm {
Ok(())
}
fn vmm_shutdown(&mut self) -> result::Result<(), VmError> {
self.vm_delete()
}
fn control_loop(&mut self, api_receiver: Arc<Receiver<ApiRequest>>) -> Result<ExitBehaviour> {
const EPOLL_EVENTS_LEN: usize = 100;
@@ -354,6 +354,7 @@ impl Vmm {
EpollDispatch::Exit => {
// Consume the event.
self.exit_evt.read().map_err(Error::EventFdRead)?;
self.vmm_shutdown().map_err(Error::VmmShutdown)?;
exit_behaviour = ExitBehaviour::Shutdown;
break 'outer;
@@ -438,6 +439,17 @@ impl Vmm {
sender.send(response).map_err(Error::ApiResponseSend)?;
}
ApiRequest::VmmShutdown(sender) => {
let response = self
.vmm_shutdown()
.map_err(ApiError::VmmShutdown)
.map(|_| ApiResponsePayload::Empty);
sender.send(response).map_err(Error::ApiResponseSend)?;
exit_behaviour = ExitBehaviour::Shutdown;
break 'outer;
}
}
}
}