]> git.ipfire.org Git - thirdparty/libvirt.git/commit
conf: add forgotten clause to virDomainPCIControllerConectTypeToModel()
authorLaine Stump <laine@redhat.com>
Mon, 11 Aug 2025 06:11:25 +0000 (02:11 -0400)
committerLaine Stump <laine@redhat.com>
Wed, 10 Sep 2025 17:12:41 +0000 (13:12 -0400)
commitce74632a611c61f0af223f996d3cade94a1f63b4
tree351d000195d72166818cc41784c04237bc87ed3c
parent82b794ca120fcc2fa2afd2f5213c498438480460
conf: add forgotten clause to virDomainPCIControllerConectTypeToModel()

When building the PCI topology of a domain that has PCI devices with
no assigned PCI addresses, the function virDomainPCIAddressSetGrow()
will attempt to add a new PCI controller with the appropriate type of
slot to connect a device that doesn't have a PCI address.

In some cases this isn't possible (for example, if the device you are
attempting to add to the topology requires a type of connection only
provided by some controller that *itself* requires a connection of a
type not available for the given architecture/machinetype, e.g. if you
want to add a pcie-root-port to a domain with a machine type that has
a pci-root (no PCIE)). In those cases, an error message is logged by
using virDomainPCIControllerConectTypeToModel() to extract the type of
device from the "flags" that are sent to virDomainPCIAddressSetGrow().
However, if virDomainPCIControllerConectTypeToModel() doesn't find a
device type in the connection flags, it will return -1, and
virDomainPCIAddressSetGrow() will log the very generic:

   Cannot automatically add a new PCI bus for a device with connect flags nnnn

Both of these functions were written prior to libvirt adding support
for the pcie-to-pci-bridge controller, and when that support was added
(in 2018), a new if() clause wasn't added to
virDomainPCIControllerConectTypeToModel(). Seven (!) years later, this
omission was noticed by someone adding a new test case to regression
testing.

This patches remedies the earlier omission, so that now when someone
tries to add a pcie-to-pci-bridge controller to a domain that doesn't
have PCIE, the message will be:

  a PCI slot is needed to connect a PCI controller model='pcie-to-pci-bridge', but none is available, and it cannot be automatically added

This is still not an ideal error message, but is arguably better.

(NB: Unfortunately it isn't possible to use a switch() statement with
no default case (in order to catch a similar error in the future),
since we are converting from bitmapped flags. Fortunately, we haven't
needed to add a new PCI controller type in the last 7 1/2 years :-)

Resolves: https://issues.redhat.com/browse/RHEL-62032
Fixes: 542f05e7756cc5614eb2ee7b0bac9aabb7aa016c
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_addr.c