hotplug: add room for other hotplug solution

Add room in the code for other hotplug solution without upcall

Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
This commit is contained in:
Chao Wu 2022-07-04 19:47:14 +08:00
parent d88b1bf01c
commit bde6609b93
4 changed files with 29 additions and 13 deletions

View File

@ -323,11 +323,11 @@ impl DeviceOpContext {
}
}
#[cfg(not(feature = "hotplug"))]
#[cfg(all(feature = "hotplug", not(feature = "dbs-upcall")))]
impl DeviceOpContext {
pub(crate) fn insert_hotplug_mmio_device(
&self,
_dev: &Arc<dyn DeviceIo>,
_dev: &Arc<DbsMmioV2Device>,
_callback: Option<()>,
) -> Result<()> {
Err(DeviceMgrError::InvalidOperation)

View File

@ -149,12 +149,12 @@ pub enum StartMicroVmError {
#[error("vCPU related error: {0}")]
Vcpu(#[source] vcpu::VcpuManagerError),
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
/// Upcall initialize Error.
#[error("failure while initializing the upcall client: {0}")]
UpcallInitError(#[source] dbs_upcall::UpcallClientError),
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
/// Upcall connect Error.
#[error("failure while connecting the upcall client: {0}")]
UpcallConnectError(#[source] dbs_upcall::UpcallClientError),

View File

@ -147,6 +147,7 @@ pub enum VcpuResizeError {
#[error("Removable vcpu not enough, removable vcpu num: {0}, number to remove: {1}, present vcpu count {2}")]
LackRemovableVcpus(u16, u16, u16),
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
/// Cannot update the configuration by upcall channel.
#[error("cannot update the configuration by upcall channel: {0}")]
Upcall(#[source] dbs_upcall::UpcallClientError),
@ -782,13 +783,14 @@ impl VcpuManager {
#[cfg(feature = "hotplug")]
mod hotplug {
#[cfg(feature = "dbs-upcall")]
use super::*;
#[cfg(feature = "dbs-upcall")]
use dbs_upcall::{CpuDevRequest, DevMgrRequest};
#[cfg(feature = "dbs-upcall")]
use std::cmp::Ordering;
use dbs_upcall::{CpuDevRequest, DevMgrRequest};
use super::*;
#[cfg(all(target_arch = "x86_64"))]
#[cfg(all(target_arch = "x86_64", feature = "dbs-upcall"))]
use dbs_boot::mptable::APIC_VERSION;
#[cfg(all(target_arch = "aarch64"))]
const APIC_VERSION: u8 = 0;

View File

@ -20,7 +20,7 @@ use slog::{error, info};
use vm_memory::{Bytes, GuestAddress, GuestAddressSpace};
use vmm_sys_util::eventfd::EventFd;
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
use dbs_upcall::{DevMgrService, UpcallClient};
use crate::address_space_manager::{
@ -195,7 +195,7 @@ pub struct Vm {
#[cfg(target_arch = "aarch64")]
irqchip_handle: Option<Box<dyn dbs_arch::gic::GICDevice>>,
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
upcall_client: Option<Arc<UpcallClient<DevMgrService>>>,
}
@ -240,7 +240,7 @@ impl Vm {
#[cfg(target_arch = "aarch64")]
irqchip_handle: None,
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
upcall_client: None,
})
}
@ -305,7 +305,7 @@ impl Vm {
/// returns true if system upcall service is ready
pub fn is_upcall_client_ready(&self) -> bool {
#[cfg(feature = "hotplug")]
#[cfg(all(feature = "hotplug", feature = "dbs-upcall"))]
{
if let Some(upcall_client) = self.upcall_client() {
return upcall_client.is_ready();
@ -705,6 +705,7 @@ impl Vm {
.map_err(StartMicroVmError::Vcpu)?;
self.init_microvm(event_mgr.epoll_manager(), vm_as.clone(), request_ts)?;
self.init_configure_system(&vm_as)?;
#[cfg(feature = "dbs-upcall")]
self.init_upcall()?;
info!(self.logger, "VM: register events");
@ -730,6 +731,7 @@ impl Vm {
#[cfg(feature = "hotplug")]
impl Vm {
/// initialize upcall client for guest os
#[cfg(feature = "dbs-upcall")]
fn new_upcall(&mut self) -> std::result::Result<(), StartMicroVmError> {
// get vsock inner connector for upcall
let inner_connector = self
@ -752,6 +754,7 @@ impl Vm {
Ok(())
}
#[cfg(feature = "dbs-upcall")]
fn init_upcall(&mut self) -> std::result::Result<(), StartMicroVmError> {
info!(self.logger, "VM upcall init");
if let Err(e) = self.new_upcall() {
@ -769,10 +772,12 @@ impl Vm {
}
/// Get upcall client.
#[cfg(feature = "dbs-upcall")]
pub fn upcall_client(&self) -> &Option<Arc<UpcallClient<DevMgrService>>> {
&self.upcall_client
}
#[cfg(feature = "dbs-upcall")]
fn create_device_hotplug_context(
&self,
epoll_mgr: Option<EpollManager>,
@ -785,6 +790,15 @@ impl Vm {
Err(StartMicroVmError::UpcallNotReady)
}
}
// We will support hotplug without upcall in future stages.
#[cfg(not(feature = "dbs-upcall"))]
fn create_device_hotplug_context(
&self,
_epoll_mgr: Option<EpollManager>,
) -> std::result::Result<DeviceOpContext, StartMicroVmError> {
Err(StartMicroVmError::MicroVMAlreadyRunning)
}
}
#[cfg(not(feature = "hotplug"))]