mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-14 05:19:21 +00:00
Merge pull request #8749 from Apokleos/fixup-dragonball-vfio
runtime-rs: fixup vfio device in runtime-rs/dragonball
This commit is contained in:
@@ -13,13 +13,16 @@ use dragonball::api::v1::{
|
|||||||
BlockDeviceConfigInfo, FsDeviceConfigInfo, FsMountConfigInfo, NetworkInterfaceConfig,
|
BlockDeviceConfigInfo, FsDeviceConfigInfo, FsMountConfigInfo, NetworkInterfaceConfig,
|
||||||
VsockDeviceConfigInfo,
|
VsockDeviceConfigInfo,
|
||||||
};
|
};
|
||||||
use dragonball::device_manager::blk_dev_mgr::BlockDeviceType;
|
use dragonball::device_manager::{
|
||||||
|
blk_dev_mgr::BlockDeviceType,
|
||||||
|
vfio_dev_mgr::{HostDeviceConfig, VfioPciDeviceConfig},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{build_dragonball_network_config, DragonballInner};
|
use super::{build_dragonball_network_config, DragonballInner};
|
||||||
use crate::VhostUserConfig;
|
use crate::VhostUserConfig;
|
||||||
use crate::{
|
use crate::{
|
||||||
device::DeviceType, HybridVsockConfig, NetworkConfig, ShareFsConfig, ShareFsMountConfig,
|
device::DeviceType, HybridVsockConfig, NetworkConfig, ShareFsConfig, ShareFsMountConfig,
|
||||||
ShareFsMountOperation, ShareFsMountType, VfioBusMode, VfioDevice, VmmState, JAILER_ROOT,
|
ShareFsMountOperation, ShareFsMountType, VfioDevice, VmmState, JAILER_ROOT,
|
||||||
};
|
};
|
||||||
|
|
||||||
const MB_TO_B: u32 = 1024 * 1024;
|
const MB_TO_B: u32 = 1024 * 1024;
|
||||||
@@ -134,47 +137,52 @@ impl DragonballInner {
|
|||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
let guest_dev_id = if let Some(pci_path) = primary_device.guest_pci_path {
|
// It's safe to unwrap the guest_pci_path and get device slot,
|
||||||
// safe here, dragonball's pci device directly connects to root bus.
|
// As it has been assigned in vfio device manager.
|
||||||
// usually, it has been assigned in vfio device manager.
|
let pci_path = primary_device.guest_pci_path.unwrap();
|
||||||
pci_path.get_device_slot().unwrap().0
|
let guest_dev_id = pci_path.get_device_slot().unwrap().0;
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
let bus_mode = VfioBusMode::to_string(vfio_device.bus_mode);
|
|
||||||
|
|
||||||
info!(sl!(), "Mock for dragonball insert host device.");
|
|
||||||
info!(
|
info!(
|
||||||
sl!(),
|
sl!(),
|
||||||
" Mock for dragonball insert host device.
|
"insert host device.
|
||||||
host device id: {:?},
|
host device id: {:?},
|
||||||
bus_slot_func: {:?},
|
bus_slot_func: {:?},
|
||||||
bus mod: {:?},
|
|
||||||
guest device id: {:?},
|
guest device id: {:?},
|
||||||
vendor/device id: {:?}",
|
vendor/device id: {:?}",
|
||||||
primary_device.hostdev_id,
|
primary_device.hostdev_id,
|
||||||
primary_device.bus_slot_func,
|
primary_device.bus_slot_func,
|
||||||
bus_mode,
|
|
||||||
guest_dev_id,
|
guest_dev_id,
|
||||||
vendor_device_id,
|
vendor_device_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME:
|
let vfio_dev_config = VfioPciDeviceConfig {
|
||||||
// interface implementation to be done when dragonball supports
|
bus_slot_func: primary_device.bus_slot_func,
|
||||||
// self.vmm_instance.insert_host_device(host_cfg)?;
|
vendor_device_id,
|
||||||
|
guest_dev_id: Some(guest_dev_id),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let host_dev_config = HostDeviceConfig {
|
||||||
|
hostdev_id: primary_device.hostdev_id,
|
||||||
|
sysfs_path: primary_device.sysfs_path.clone(),
|
||||||
|
dev_config: vfio_dev_config,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.vmm_instance
|
||||||
|
.insert_host_device(host_dev_config)
|
||||||
|
.context("insert host device failed")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_vfio_device(&mut self, hostdev_id: String) -> Result<()> {
|
fn remove_vfio_device(&mut self, hostdev_id: String) -> Result<()> {
|
||||||
info!(
|
info!(sl!(), "remove host_device with hostdev id {:?}", hostdev_id);
|
||||||
sl!(),
|
|
||||||
"Mock for dragonball remove host_device with hostdev id {:?}", hostdev_id
|
self.vmm_instance
|
||||||
);
|
.prepare_remove_host_device(&hostdev_id)
|
||||||
// FIXME:
|
.context("prepare to remove host device failed")?;
|
||||||
// interface implementation to be done when dragonball supports
|
self.vmm_instance
|
||||||
// self.vmm_instance.remove_host_device(hostdev_id)?;
|
.remove_host_device(&hostdev_id)
|
||||||
|
.context("remove host device failed")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,10 @@ use dragonball::{
|
|||||||
InstanceInfo, InstanceState, NetworkInterfaceConfig, VcpuResizeInfo, VmmAction,
|
InstanceInfo, InstanceState, NetworkInterfaceConfig, VcpuResizeInfo, VmmAction,
|
||||||
VmmActionError, VmmData, VmmRequest, VmmResponse, VmmService, VsockDeviceConfigInfo,
|
VmmActionError, VmmData, VmmRequest, VmmResponse, VmmService, VsockDeviceConfigInfo,
|
||||||
},
|
},
|
||||||
device_manager::{balloon_dev_mgr::BalloonDeviceConfigInfo, mem_dev_mgr::MemDeviceConfigInfo},
|
device_manager::{
|
||||||
|
balloon_dev_mgr::BalloonDeviceConfigInfo, mem_dev_mgr::MemDeviceConfigInfo,
|
||||||
|
vfio_dev_mgr::HostDeviceConfig,
|
||||||
|
},
|
||||||
vm::VmConfigInfo,
|
vm::VmConfigInfo,
|
||||||
Vmm,
|
Vmm,
|
||||||
};
|
};
|
||||||
@@ -194,6 +197,30 @@ impl VmmInstance {
|
|||||||
Err(anyhow!("Failed to get machine info"))
|
Err(anyhow!("Failed to get machine info"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn insert_host_device(&self, device_cfg: HostDeviceConfig) -> Result<()> {
|
||||||
|
self.handle_request_with_retry(Request::Sync(VmmAction::InsertHostDevice(
|
||||||
|
device_cfg.clone(),
|
||||||
|
)))
|
||||||
|
.with_context(|| format!("Failed to insert host device {:?}", device_cfg))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prepare_remove_host_device(&self, id: &str) -> Result<()> {
|
||||||
|
info!(sl!(), "prepare to remove host device {}", id);
|
||||||
|
self.handle_request(Request::Sync(VmmAction::PrepareRemoveHostDevice(
|
||||||
|
id.to_string(),
|
||||||
|
)))
|
||||||
|
.with_context(|| format!("Prepare to remove host device {:?} failed", id))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_host_device(&self, id: &str) -> Result<()> {
|
||||||
|
info!(sl!(), "remove host device {}", id);
|
||||||
|
self.handle_request(Request::Sync(VmmAction::RemoveHostDevice(id.to_string())))
|
||||||
|
.with_context(|| format!("Failed to remove host device {:?}", id))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn insert_block_device(&self, device_cfg: BlockDeviceConfigInfo) -> Result<()> {
|
pub fn insert_block_device(&self, device_cfg: BlockDeviceConfigInfo) -> Result<()> {
|
||||||
self.handle_request_with_retry(Request::Sync(VmmAction::InsertBlockDevice(
|
self.handle_request_with_retry(Request::Sync(VmmAction::InsertBlockDevice(
|
||||||
device_cfg.clone(),
|
device_cfg.clone(),
|
||||||
|
Reference in New Issue
Block a user