mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-25 03:02:17 +00:00
Merge pull request #11540 from Apokleos/coldplug-vfio-clh
runtime-rs: Add vfio support with coldplug for cloud-hypervisor
This commit is contained in:
commit
f22272b8f7
@ -109,6 +109,7 @@ impl TryFrom<NamedHypervisorConfig> for VmConfig {
|
|||||||
|
|
||||||
let fs = n.shared_fs_devices;
|
let fs = n.shared_fs_devices;
|
||||||
let net = n.network_devices;
|
let net = n.network_devices;
|
||||||
|
let host_devices = n.host_devices;
|
||||||
|
|
||||||
let cpus = CpusConfig::try_from((cfg.cpu_info, guest_protection_to_use.clone()))
|
let cpus = CpusConfig::try_from((cfg.cpu_info, guest_protection_to_use.clone()))
|
||||||
.map_err(VmConfigError::CPUError)?;
|
.map_err(VmConfigError::CPUError)?;
|
||||||
@ -197,6 +198,7 @@ impl TryFrom<NamedHypervisorConfig> for VmConfig {
|
|||||||
payload,
|
payload,
|
||||||
fs,
|
fs,
|
||||||
net,
|
net,
|
||||||
|
devices: host_devices,
|
||||||
pmem,
|
pmem,
|
||||||
disks,
|
disks,
|
||||||
vsock: Some(vsock),
|
vsock: Some(vsock),
|
||||||
|
@ -491,6 +491,7 @@ pub struct NamedHypervisorConfig {
|
|||||||
|
|
||||||
pub shared_fs_devices: Option<Vec<FsConfig>>,
|
pub shared_fs_devices: Option<Vec<FsConfig>>,
|
||||||
pub network_devices: Option<Vec<NetConfig>>,
|
pub network_devices: Option<Vec<NetConfig>>,
|
||||||
|
pub host_devices: Option<Vec<DeviceConfig>>,
|
||||||
|
|
||||||
// Set to the available guest protection *iff* BOTH of the following
|
// Set to the available guest protection *iff* BOTH of the following
|
||||||
// conditions are true:
|
// conditions are true:
|
||||||
|
@ -61,6 +61,7 @@ impl CloudHypervisorInner {
|
|||||||
match device {
|
match device {
|
||||||
DeviceType::ShareFs(_) => self.pending_devices.insert(0, device.clone()),
|
DeviceType::ShareFs(_) => self.pending_devices.insert(0, device.clone()),
|
||||||
DeviceType::Network(_) => self.pending_devices.insert(0, device.clone()),
|
DeviceType::Network(_) => self.pending_devices.insert(0, device.clone()),
|
||||||
|
DeviceType::Vfio(_) => self.pending_devices.insert(0, device.clone()),
|
||||||
_ => {
|
_ => {
|
||||||
debug!(
|
debug!(
|
||||||
sl!(),
|
sl!(),
|
||||||
@ -365,9 +366,14 @@ impl CloudHypervisorInner {
|
|||||||
|
|
||||||
pub(crate) async fn get_shared_devices(
|
pub(crate) async fn get_shared_devices(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<(Option<Vec<FsConfig>>, Option<Vec<NetConfig>>)> {
|
) -> Result<(
|
||||||
|
Option<Vec<FsConfig>>,
|
||||||
|
Option<Vec<NetConfig>>,
|
||||||
|
Option<Vec<DeviceConfig>>,
|
||||||
|
)> {
|
||||||
let mut shared_fs_devices = Vec::<FsConfig>::new();
|
let mut shared_fs_devices = Vec::<FsConfig>::new();
|
||||||
let mut network_devices = Vec::<NetConfig>::new();
|
let mut network_devices = Vec::<NetConfig>::new();
|
||||||
|
let mut host_devices = Vec::<DeviceConfig>::new();
|
||||||
|
|
||||||
while let Some(dev) = self.pending_devices.pop() {
|
while let Some(dev) = self.pending_devices.pop() {
|
||||||
match dev {
|
match dev {
|
||||||
@ -382,11 +388,38 @@ impl CloudHypervisorInner {
|
|||||||
let net_config = NetConfig::try_from(net_device.config)?;
|
let net_config = NetConfig::try_from(net_device.config)?;
|
||||||
network_devices.push(net_config);
|
network_devices.push(net_config);
|
||||||
}
|
}
|
||||||
|
DeviceType::Vfio(vfio_device) => {
|
||||||
|
// A device with multi-funtions, or a IOMMU group with one more
|
||||||
|
// devices, the Primary device is selected to be passed to VM.
|
||||||
|
// And the the first one is Primary device.
|
||||||
|
// safe here, devices is not empty.
|
||||||
|
let primary_device = vfio_device.devices.first().ok_or(anyhow!(
|
||||||
|
"Primary device list empty for vfio device {:?}",
|
||||||
|
vfio_device
|
||||||
|
))?;
|
||||||
|
|
||||||
|
let primary_device = primary_device.clone();
|
||||||
|
let sysfsdev = primary_device.sysfs_path.clone();
|
||||||
|
let device_config = DeviceConfig {
|
||||||
|
path: PathBuf::from(sysfsdev),
|
||||||
|
iommu: false,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
info!(
|
||||||
|
sl!(),
|
||||||
|
"get host_devices primary device {:?}", primary_device
|
||||||
|
);
|
||||||
|
host_devices.push(device_config);
|
||||||
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((Some(shared_fs_devices), Some(network_devices)))
|
Ok((
|
||||||
|
Some(shared_fs_devices),
|
||||||
|
Some(network_devices),
|
||||||
|
Some(host_devices),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +185,7 @@ impl CloudHypervisorInner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn boot_vm(&mut self) -> Result<()> {
|
async fn boot_vm(&mut self) -> Result<()> {
|
||||||
let (shared_fs_devices, network_devices) = self.get_shared_devices().await?;
|
let (shared_fs_devices, network_devices, host_devices) = self.get_shared_devices().await?;
|
||||||
|
|
||||||
let socket = self
|
let socket = self
|
||||||
.api_socket
|
.api_socket
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -215,6 +214,7 @@ impl CloudHypervisorInner {
|
|||||||
guest_protection_to_use: self.guest_protection_to_use.clone(),
|
guest_protection_to_use: self.guest_protection_to_use.clone(),
|
||||||
shared_fs_devices,
|
shared_fs_devices,
|
||||||
network_devices,
|
network_devices,
|
||||||
|
host_devices,
|
||||||
};
|
};
|
||||||
|
|
||||||
let cfg = VmConfig::try_from(named_cfg)?;
|
let cfg = VmConfig::try_from(named_cfg)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user