mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: config: Switch FsConfig to use PciDeviceCommonConfig
Switch FsConfig over to using the newly extracted struct members as used by all PCI based devices. The use of #[serde(flatten)] means that this change has no impact on the JSON format that the data is stored as. As virtio-fs does not support being placed behind an IOMMU an error is now raised if iommu is set. This option is not exposed via the CLI but could happen with a miscontructed JSON/API call. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -1937,20 +1937,14 @@ impl FsConfig {
|
||||
.map_err(Error::ParseFileSystem)?
|
||||
.unwrap_or_else(default_fsconfig_num_queues);
|
||||
|
||||
let id = parser.get("id");
|
||||
|
||||
let pci_segment = parser
|
||||
.convert("pci_segment")
|
||||
.map_err(Error::ParseFileSystem)?
|
||||
.unwrap_or_default();
|
||||
let pci_common = PciDeviceCommonConfig::parse(fs)?;
|
||||
|
||||
Ok(FsConfig {
|
||||
pci_common,
|
||||
tag,
|
||||
socket,
|
||||
num_queues,
|
||||
queue_size,
|
||||
id,
|
||||
pci_segment,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1962,21 +1956,11 @@ impl FsConfig {
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(platform_config) = vm_config.platform.as_ref() {
|
||||
if self.pci_segment >= platform_config.num_pci_segments {
|
||||
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
|
||||
}
|
||||
|
||||
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
|
||||
&& iommu_segments.contains(&self.pci_segment)
|
||||
{
|
||||
return Err(ValidationError::IommuNotSupportedOnSegment(
|
||||
self.pci_segment,
|
||||
));
|
||||
}
|
||||
if self.pci_common.iommu {
|
||||
return Err(ValidationError::IommuNotSupported);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
self.pci_common.validate(vm_config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3059,7 +3043,7 @@ impl VmConfig {
|
||||
for fs in fses {
|
||||
fs.validate(self)?;
|
||||
|
||||
Self::validate_identifier(&mut id_list, &fs.id)?;
|
||||
Self::validate_identifier(&mut id_list, &fs.pci_common.id)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3530,7 +3514,7 @@ impl VmConfig {
|
||||
// Remove if fs device
|
||||
if let Some(fs) = self.fs.as_mut() {
|
||||
let len = fs.len();
|
||||
fs.retain(|dev| dev.id.as_ref().map(|id| id.as_ref()) != Some(id));
|
||||
fs.retain(|dev| dev.pci_common.id.as_ref().map(|id| id.as_ref()) != Some(id));
|
||||
removed |= fs.len() != len;
|
||||
}
|
||||
|
||||
@@ -4256,12 +4240,11 @@ mod unit_tests {
|
||||
|
||||
fn fs_fixture() -> FsConfig {
|
||||
FsConfig {
|
||||
pci_common: PciDeviceCommonConfig::default(),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
num_queues: 1,
|
||||
queue_size: 1024,
|
||||
id: None,
|
||||
pci_segment: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5471,7 +5454,7 @@ id=\"{id}\",pci_segment={pci_segment},queue_sizes={queue_sizes}"
|
||||
}]);
|
||||
assert_eq!(
|
||||
invalid_config.validate(),
|
||||
Err(ValidationError::IommuNotSupportedOnSegment(1))
|
||||
Err(ValidationError::OnIommuSegment(1))
|
||||
);
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
@@ -5495,12 +5478,15 @@ id=\"{id}\",pci_segment={pci_segment},queue_sizes={queue_sizes}"
|
||||
..platform_fixture()
|
||||
});
|
||||
invalid_config.fs = Some(vec![FsConfig {
|
||||
pci_segment: 1,
|
||||
pci_common: PciDeviceCommonConfig {
|
||||
pci_segment: 1,
|
||||
..Default::default()
|
||||
},
|
||||
..fs_fixture()
|
||||
}]);
|
||||
assert_eq!(
|
||||
invalid_config.validate(),
|
||||
Err(ValidationError::IommuNotSupportedOnSegment(1))
|
||||
Err(ValidationError::OnIommuSegment(1))
|
||||
);
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
|
||||
@@ -3216,11 +3216,11 @@ impl DeviceManager {
|
||||
&mut self,
|
||||
fs_cfg: &mut FsConfig,
|
||||
) -> DeviceManagerResult<MetaVirtioDevice> {
|
||||
let id = if let Some(id) = &fs_cfg.id {
|
||||
let id = if let Some(id) = &fs_cfg.pci_common.id {
|
||||
id.clone()
|
||||
} else {
|
||||
let id = self.next_device_name(FS_DEVICE_NAME_PREFIX)?;
|
||||
fs_cfg.id = Some(id.clone());
|
||||
fs_cfg.pci_common.id = Some(id.clone());
|
||||
id
|
||||
};
|
||||
|
||||
@@ -3257,7 +3257,7 @@ impl DeviceManager {
|
||||
as Arc<Mutex<dyn virtio_devices::VirtioDevice>>,
|
||||
iommu: false,
|
||||
id,
|
||||
pci_segment: fs_cfg.pci_segment,
|
||||
pci_segment: fs_cfg.pci_common.pci_segment,
|
||||
dma_handler: None,
|
||||
})
|
||||
} else {
|
||||
@@ -5039,7 +5039,7 @@ impl DeviceManager {
|
||||
}
|
||||
|
||||
pub fn add_fs(&mut self, fs_cfg: &mut FsConfig) -> DeviceManagerResult<PciDeviceInfo> {
|
||||
self.validate_identifier(&fs_cfg.id)?;
|
||||
self.validate_identifier(&fs_cfg.pci_common.id)?;
|
||||
|
||||
let device = self.make_virtio_fs_device(fs_cfg)?;
|
||||
self.hotplug_virtio_pci_device(device)
|
||||
|
||||
@@ -471,16 +471,14 @@ pub struct PvmemcontrolConfig {}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct FsConfig {
|
||||
#[serde(flatten)]
|
||||
pub pci_common: PciDeviceCommonConfig,
|
||||
pub tag: String,
|
||||
pub socket: PathBuf,
|
||||
#[serde(default = "default_fsconfig_num_queues")]
|
||||
pub num_queues: usize,
|
||||
#[serde(default = "default_fsconfig_queue_size")]
|
||||
pub queue_size: u16,
|
||||
#[serde(default)]
|
||||
pub id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub pci_segment: u16,
|
||||
}
|
||||
|
||||
pub fn default_fsconfig_num_queues() -> usize {
|
||||
|
||||
Reference in New Issue
Block a user