[pve-devel] [PATCH guest-common v4 3/6] mapping: pci: make sure all desired properties are checked
Dominik Csapak
d.csapak at proxmox.com
Thu Jun 6 11:21:58 CEST 2024
by placing all expected properties from the hardware into an 'expected_props'
and those fromt he config into 'configured_props'
the names makes clearer what's what, and we can easily extend it, even
if the data does not come from the mapping (like we'll do with 'mdev')
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v3:
* rebased on split out patches before
* don't merge keys but add all to expected_props instead
src/PVE/Mapping/PCI.pm | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/PVE/Mapping/PCI.pm b/src/PVE/Mapping/PCI.pm
index eb99819..aa56496 100644
--- a/src/PVE/Mapping/PCI.pm
+++ b/src/PVE/Mapping/PCI.pm
@@ -148,32 +148,37 @@ sub assert_valid {
my $info = PVE::SysFSTools::pci_device_info($path, 1);
die "pci device '$path' not found\n" if !defined($info);
- my $correct_props = {
+ # make sure to initialize all keys that should be checked below
+ my $expected_props = {
id => "$info->{vendor}:$info->{device}",
iommugroup => $info->{iommugroup},
+ 'subsystem-id' => undef,
};
if (defined($info->{'subsystem_vendor'}) && defined($info->{'subsystem_device'})) {
- $correct_props->{'subsystem-id'} = "$info->{'subsystem_vendor'}:$info->{'subsystem_device'}";
+ $expected_props->{'subsystem-id'} = "$info->{'subsystem_vendor'}:$info->{'subsystem_device'}";
}
- for my $prop (sort keys %$correct_props) {
+ my $configured_props = { $mapping->%{qw(id iommugroup subsystem-id)} };
+
+ for my $prop (sort keys $expected_props->%*) {
next if $prop eq 'iommugroup' && $idx > 0; # check iommu only on the first device
- next if !defined($correct_props->{$prop}) && !defined($mapping->{$prop});
+ next if !defined($expected_props->{$prop}) && !defined($configured_props->{$prop});
die "missing expected property '$prop' for device '$path'\n"
- if defined($correct_props->{$prop}) && !defined($mapping->{$prop});
+ if defined($expected_props->{$prop}) && !defined($configured_props->{$prop});
die "unexpected property '$prop' configured for device '$path'\n"
- if !defined($correct_props->{$prop}) && defined($mapping->{$prop});
+ if !defined($expected_props->{$prop}) && defined($configured_props->{$prop});
- my $correct_prop = $correct_props->{$prop};
- $correct_prop =~ s/0x//g;
- my $configured_prop = $mapping->{$prop};
+ my $expected_prop = $expected_props->{$prop};
+ $expected_prop =~ s/0x//g;
+ my $configured_prop = $configured_props->{$prop};
$configured_prop =~ s/0x//g;
- die "'$prop' does not match for '$name' ($correct_prop != $configured_prop)\n"
- if $correct_prop ne $configured_prop;
+ die "'$prop' does not match for '$name' ($expected_prop != $configured_prop)\n"
+ if $expected_prop ne $configured_prop;
}
+
$idx++;
}
--
2.39.2
More information about the pve-devel
mailing list