On 04/05/2016 08:33 AM, Ján Tomko wrote:
On Thu, Mar 24, 2016 at 03:25:43PM -0400, Laine Stump wrote:
> There are two places in qemu_domain_address.c where we have a switch
> statement to convert PCI controller models
> (VIR_DOMAIN_CONTROLLER_MODEL_PCI*) into the connection type flag that
> is matched when looking for an upstream connection for that model of
> controller (VIR_PCI_CONNECT_TYPE_*). This patch makes a utility
> function in conf/domain_addr.c to do that, so that when a new PCI
> controller is added, we only need to add the new model-->connect-type
> in a single place.
> ---
> src/conf/domain_addr.c | 47 +++++++++++++++++++++++++
> src/conf/domain_addr.h | 4 +++
> src/libvirt_private.syms | 1 +
> src/qemu/qemu_domain_address.c | 80 +++++-------------------------------------
> 4 files changed, 61 insertions(+), 71 deletions(-)
>
> diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
> index 4408c4a..1bf2c9a 100644
> --- a/src/conf/domain_addr.c
> +++ b/src/conf/domain_addr.c
> @@ -32,6 +32,53 @@
>
> VIR_LOG_INIT("conf.domain_addr");
>
> +int
> +virDomainPCIControllerModelToConnectType(virDomainControllerModelPCI model,
> + virDomainPCIConnectFlags *connectType)
> +{
> + /* given a VIR_DOMAIN_CONTROLLER_MODEL_PCI*, set connectType to
> + * the equivalent VIR_PCI_CONNECT_TYPE_*. return 0 on success, -1
> + * if the model wasn't recognized.
> + */
> + switch (model) {
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
> + /* pci-root and pcie-root are implicit in the machine,
> + * and have no upstream connection
> + */
> + *connectType = 0;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
> + /* pci-bridge is treated like a standard PCI endpoint device, */
> + *connectType = VIR_PCI_CONNECT_TYPE_PCI_DEVICE;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE:
> + /* dmi-to-pci-bridge is treated like a PCIe device
> + * (e.g. it can be plugged directly into pcie-root)
> + */
> + *connectType = VIR_PCI_CONNECT_TYPE_PCIE_DEVICE;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT:
> + *connectType = VIR_PCI_CONNECT_TYPE_PCIE_ROOT_PORT;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
> + *connectType = VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_DOWNSTREAM_PORT:
> + *connectType = VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_DOWNSTREAM_PORT;
> + break;
> + case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
> + /* if this happens, there is an error in the code. A
> + * PCI controller should always have a proper model
> + * set
> + */
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("PCI controller model incorrectly set to
'last'"));
> + return -1;
This is dead code.
The function can just return virDomainPCIConnectFlags directly.
I was originally going to do that, but since the switch is over an enum,
all possible values must have cases. I suppose I could just hand-wave
over that case saying "This will never happen" and have it return 0.
Actually, I think I *will* do that; it would be reasonable to think that
someone would screw up by failing to set the model (in which case it
would be 0, i.e. "...PCI_ROOT"), but it would take some serious ill
intent to set it to "...PCI_LAST"