vmm: Refactor common PCI based device configuration - #7962
Conversation
|
Seems reasonable. Would it make sense to merge #7631 first to minimize the need for another substantial rebase? It has already gone through several review iterations (since Jan), and requiring further large-scale changes at this stage could negatively impact the contributor experience 🤔 |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
85859df to
6b27998
Compare
scholzp
left a comment
There was a problem hiding this comment.
I really like the refactoring you did! I think the improvements speak for them self. Thanks for putting time into this!
I left a few comments.
|
ping @rbradford: @scholzp and I'd love to move this PR forward. Apart from the existing remarks, there are no further concerns from our side |
6b27998 to
76eff16
Compare
PR updated! Thanks for the patience. |
76eff16 to
9eaf43e
Compare
Refactor parse() into a version that can control whether to tolerate unknown options. This can then be used to then parse a subset of the options. Signed-off-by: Rob Bradford <[email protected]>
Add an OptionParser::add_all method that takes a slice of option names and use that to add to the set of parameters that the parser works on. Signed-off-by: Rob Bradford <[email protected]>
Autogenerated with Claude Opus 4.6 and reviewed with human eyes. Signed-off-by: Rob Bradford <[email protected]>
The error message for the InvalidSyntax was copied from UnknownOption. Correct it to "invalid syntax". Signed-off-by: Rob Bradford <[email protected]>
Add unit tests generated with Claude Opus 4.6 and reviewed by human eyes. Signed-off-by: Rob Bradford <[email protected]>
This unit test was trying to test with extra "="s in the input but was instead testing using an unknown option. Add the option to the parser to not hit that incorrect error. Signed-off-by: Rob Bradford <[email protected]>
Introduce a common struct that can encompass all the config fields used by devices that are PCI based. The use of `skip_serializing_if` means that the iommu field will only be included if set (otherwise falling back to default false). This neatly handles the devices that don't support an iommu. Signed-off-by: Rob Bradford <[email protected]>
This parses a subset of the device configuration options used for devices that are PCI based. Signed-off-by: Rob Bradford <[email protected]>
Implement some common PCI segment validation. This can be used to reduce duplication across the different validation methods. Signed-off-by: Rob Bradford <[email protected]>
Switch DiskConfig 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. Signed-off-by: Rob Bradford <[email protected]>
Switch NetConfig 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. Signed-off-by: Rob Bradford <[email protected]>
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 <[email protected]>
Switch GenericVhostUserConfig 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 generic vhost-user devices do not support being placed behind an IOMMU an error is now raised if iommu is set. This can't happen via the CLI but could via the JSON/API. Signed-off-by: Rob Bradford <[email protected]>
Switch PmemConfig 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. Signed-off-by: Rob Bradford <[email protected]>
Switch DeviceConfig 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. Signed-off-by: Rob Bradford <[email protected]>
Switch UserDeviceConfig 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 VFIO user devices do not support being placed behind an IOMMU an error is now raised if iommu is set. This can't happen via the CLI but could via the JSON/API. Signed-off-by: Rob Bradford <[email protected]>
Switch VdpaConfig 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. Signed-off-by: Rob Bradford <[email protected]>
Switch VsockConfig 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. Signed-off-by: Rob Bradford <[email protected]>
The IommuNotSupportedOnSegment variant is no longer needed as the common PciDeviceCommonConfig::validate() handles this case with the OnIommuSegment variant along with more use of the IommuNotSupported error variant. Signed-off-by: Rob Bradford <[email protected]>
This can then be used with the OptionParser::add_all() API to reduce the number of locations the same options are added to the parser. The only quirk is that some devices do not support an IOMMU (because they are vhost-user / vfio-user based). There are two different versions of the array to support that. Signed-off-by: Rob Bradford <[email protected]>
This struct has the same members and it can be reused to reduce complexity now and if other common PCI related fields need to be added in the future. Signed-off-by: Rob Bradford <[email protected]>
Use a more idiomatic Rust approach when establishing an autogenerated ID when none is set. Signed-off-by: Rob Bradford <[email protected]>
9eaf43e to
9905375
Compare
scholzp
left a comment
There was a problem hiding this comment.
Looks good. Thank you very much! :)
I noticed that we have a lot of common shared PCI configuration options between
our different config structs. By consolidating into a common struct we can then
use this to reduce code duplication but also make it easier for the work to add a
pci_device_idas required in #7631