From f44ec9c1ab44415f826dfedb321fc20930e6a8a7 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Wed, 4 Feb 2015 08:10:52 -0500 Subject: [PATCH] nodedev: check/add for scsi_host caps for NumOfCaps and ListCaps Commit id '652a2ec6' introduced two new node device capability flags and the ability to use those flags as a way to search for a specific subset of a 'scsi_host' device - namely a 'fc_host' and/or 'vports'. The code modified the virNodeDeviceCapMatch whichs allows for searching using the 'virsh nodedev-list [cap]' via virConnectListAllNodeDevices. However, the original patches did not account for other searches for the same capability key from virNodeDeviceNumOfCaps and virNodeDeviceListCaps using nodeDeviceNumOfCaps and nodeDeviceListCaps. Since 'fc_host' and 'vports' are self defined bits of a 'scsi_host' device mere string comparison against the basic/root type is not sufficient. This patch adds the check for the 'fc_host' and 'vports' bits within a 'scsi_host' device and allows the following python code to find the capabilities for the device: import libvirt conn = libvirt.openReadOnly('qemu:///system') devs = conn.listAllDevices() for dev in devs: if 'fc_host' in dev.listCaps() or 'vports' in dev.listCaps(): print dev.name(),dev.numOfCaps(),dev.listCaps() --- src/node_device/node_device_driver.c | 32 +++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index c1ad3cd7e2..b8d9f4f565 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -383,8 +383,20 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, obj->def) < 0) goto cleanup; - for (caps = obj->def->caps; caps; caps = caps->next) + for (caps = obj->def->caps; caps; caps = caps->next) { ++ncaps; + + if (caps->type == VIR_NODE_DEV_CAP_SCSI_HOST) { + if (caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) + ncaps++; + + if (caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) + ncaps++; + } + } + ret = ncaps; cleanup: @@ -419,6 +431,24 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) { if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->type)) < 0) goto cleanup; + + if (caps->type == VIR_NODE_DEV_CAP_SCSI_HOST) { + if (ncaps < maxnames && + caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { + if (VIR_STRDUP(names[ncaps++], + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST)) < 0) + goto cleanup; + } + + if (ncaps < maxnames && + caps->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { + if (VIR_STRDUP(names[ncaps++], + virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS)) < 0) + goto cleanup; + } + } } ret = ncaps; -- GitLab