mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
vmm: Handle ApiRequest::VmCreate in a separate function
It simplifies a bit the `Vmm::control_loop` and reads better to be consistent with other `ApiRequest` handlers. Also, it removes the repetitive `ApiError::VmAlreadyCreated` and makes `ApiError::VmCreate` useful. No functional changes. Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
parent
54c552f90d
commit
1075209e2a
@ -64,9 +64,6 @@ pub enum ApiError {
|
||||
/// The VM could not boot.
|
||||
VmBoot(VmError),
|
||||
|
||||
/// The VM is already created.
|
||||
VmAlreadyCreated,
|
||||
|
||||
/// The VM could not be created.
|
||||
VmCreate(VmError),
|
||||
|
||||
|
@ -343,6 +343,17 @@ impl Vmm {
|
||||
})
|
||||
}
|
||||
|
||||
fn vm_create(&mut self, config: Arc<Mutex<VmConfig>>) -> result::Result<(), VmError> {
|
||||
// We only store the passed VM config.
|
||||
// The VM will be created when being asked to boot it.
|
||||
if self.vm_config.is_none() {
|
||||
self.vm_config = Some(config);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(VmError::VmAlreadyCreated)
|
||||
}
|
||||
}
|
||||
|
||||
fn vm_boot(&mut self) -> result::Result<(), VmError> {
|
||||
// Create a new VM if we don't have one yet.
|
||||
if self.vm.is_none() {
|
||||
@ -1142,14 +1153,10 @@ impl Vmm {
|
||||
info!("API request event: {:?}", api_request);
|
||||
match api_request {
|
||||
ApiRequest::VmCreate(config, sender) => {
|
||||
// We only store the passed VM config.
|
||||
// The VM will be created when being asked to boot it.
|
||||
let response = if self.vm_config.is_none() {
|
||||
self.vm_config = Some(config);
|
||||
Ok(ApiResponsePayload::Empty)
|
||||
} else {
|
||||
Err(ApiError::VmAlreadyCreated)
|
||||
};
|
||||
let response = self
|
||||
.vm_create(config)
|
||||
.map_err(ApiError::VmCreate)
|
||||
.map(|_| ApiResponsePayload::Empty);
|
||||
|
||||
sender.send(response).map_err(Error::ApiResponseSend)?;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user