mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: DeviceConfig: Add fd field for an externally-opened vfio cdev
Add a new `fd: Option<i32>` field to DeviceConfig so a caller can supply a pre-opened vfio cdev FD (e.g. /dev/vfio/devices/vfioN) in addition to the existing sysfs path. The CLI `--device` option now accepts `fd=<n>`, parsed alongside the existing options. Signed-off-by: Bo Chen <bchen@crusoe.ai> Assisted-by: Claude:Opus-4.7
This commit is contained in:
@@ -760,12 +760,30 @@ pub struct DeviceConfig {
|
||||
pub pci_common: PciDeviceCommonConfig,
|
||||
#[serde(default)]
|
||||
pub path: Option<PathBuf>,
|
||||
// FDs are not serialized and any deserialized value is invalid; see NetConfig::fds.
|
||||
#[serde(default, deserialize_with = "deserialize_deviceconfig_fd")]
|
||||
pub fd: Option<i32>,
|
||||
#[serde(default)]
|
||||
pub x_nv_gpudirect_clique: Option<u8>,
|
||||
#[serde(default)]
|
||||
pub x_exclude_mmap_bars: Vec<u64>,
|
||||
}
|
||||
|
||||
fn deserialize_deviceconfig_fd<'de, D>(d: D) -> Result<Option<i32>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let invalid_fd: Option<i32> = Option::deserialize(d)?;
|
||||
if invalid_fd.is_some() {
|
||||
debug!(
|
||||
"FD in 'DeviceConfig' won't be deserialized as it is most likely invalid now. Deserializing it as -1."
|
||||
);
|
||||
Ok(Some(-1))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplyLandlock for DeviceConfig {
|
||||
fn apply_landlock(&self, landlock: &mut Landlock) -> LandlockResult<()> {
|
||||
let path = self
|
||||
|
||||
Reference in New Issue
Block a user