From b20ec49e57d17b57e503c74aead8d0823d3ff5a0 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Tue, 23 Jan 2018 12:38:26 +0100 Subject: [PATCH] conf: nodedev: Convert virNodeDevObjHasCapStr to a simple wrapper This patch drops the capability matching redundancy by simply converting the string input to our internal types which are then in turn used for the actual capability matching. Signed-off-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 51 +++---------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index cf7f45e4bf..147de2135b 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -125,55 +125,12 @@ static bool virNodeDeviceObjHasCapStr(const virNodeDeviceObj *obj, const char *cap) { - virNodeDevCapsDefPtr caps = obj->def->caps; - const char *fc_host_cap = - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); - const char *vports_cap = - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); - const char *mdev_types = - virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES); + int type; - while (caps) { - if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) { - return true; - } else { - switch (caps->data.type) { - case VIR_NODE_DEV_CAP_PCI_DEV: - if ((STREQ(cap, mdev_types)) && - (caps->data.pci_dev.flags & VIR_NODE_DEV_CAP_FLAG_PCI_MDEV)) - return true; - break; + if ((type = virNodeDevCapTypeFromString(cap)) < 0) + return false; - case VIR_NODE_DEV_CAP_SCSI_HOST: - if ((STREQ(cap, fc_host_cap) && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) || - (STREQ(cap, vports_cap) && - (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))) - return true; - 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_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_LAST: - break; - } - } - - caps = caps->next; - } - return false; + return virNodeDeviceObjHasCap(obj, type); }