node_device: refactor address retrieval of node device

Use switch statements instead of if-else condition in the method
nodeDeviceFindAddressByName to retrieve address of a node device.

Signed-off-by: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Shalini Chellathurai Saroja 2020-12-03 18:59:41 +01:00 committed by Erik Skultety
parent 385ade999c
commit 09364608b4

View File

@ -638,7 +638,8 @@ nodeDeviceFindAddressByName(const char *name)
def = virNodeDeviceObjGetDef(dev); def = virNodeDeviceObjGetDef(dev);
for (caps = def->caps; caps != NULL; caps = caps->next) { for (caps = def->caps; caps != NULL; caps = caps->next) {
if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) { switch (caps->data.type) {
case VIR_NODE_DEV_CAP_PCI_DEV: {
virPCIDeviceAddress pci_addr = { virPCIDeviceAddress pci_addr = {
.domain = caps->data.pci_dev.domain, .domain = caps->data.pci_dev.domain,
.bus = caps->data.pci_dev.bus, .bus = caps->data.pci_dev.bus,
@ -648,7 +649,9 @@ nodeDeviceFindAddressByName(const char *name)
addr = virPCIDeviceAddressAsString(&pci_addr); addr = virPCIDeviceAddressAsString(&pci_addr);
break; break;
} else if (caps->data.type == VIR_NODE_DEV_CAP_CSS_DEV) { }
case VIR_NODE_DEV_CAP_CSS_DEV: {
virDomainDeviceCCWAddress ccw_addr = { virDomainDeviceCCWAddress ccw_addr = {
.cssid = caps->data.ccw_dev.cssid, .cssid = caps->data.ccw_dev.cssid,
.ssid = caps->data.ccw_dev.ssid, .ssid = caps->data.ccw_dev.ssid,
@ -658,6 +661,29 @@ nodeDeviceFindAddressByName(const char *name)
addr = virDomainCCWAddressAsString(&ccw_addr); addr = virDomainCCWAddressAsString(&ccw_addr);
break; break;
} }
case VIR_NODE_DEV_CAP_SYSTEM:
case VIR_NODE_DEV_CAP_USB_DEV:
case VIR_NODE_DEV_CAP_USB_INTERFACE:
case VIR_NODE_DEV_CAP_NET:
case VIR_NODE_DEV_CAP_SCSI_HOST:
case VIR_NODE_DEV_CAP_SCSI_TARGET:
case VIR_NODE_DEV_CAP_SCSI:
case VIR_NODE_DEV_CAP_STORAGE:
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
case VIR_NODE_DEV_CAP_SCSI_GENERIC:
case VIR_NODE_DEV_CAP_DRM:
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_MDEV:
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_VDPA:
case VIR_NODE_DEV_CAP_AP_CARD:
case VIR_NODE_DEV_CAP_AP_QUEUE:
case VIR_NODE_DEV_CAP_AP_MATRIX:
case VIR_NODE_DEV_CAP_LAST:
break;
}
} }
virNodeDeviceObjEndAPI(&dev); virNodeDeviceObjEndAPI(&dev);