]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: check/add for scsi_host caps for NumOfCaps and ListCaps
authorJohn Ferlan <jferlan@redhat.com>
Wed, 4 Feb 2015 13:10:52 +0000 (08:10 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 5 Feb 2015 12:50:32 +0000 (07:50 -0500)
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

index c1ad3cd7e230d30581eddb4f3b259e3faafe332a..b8d9f4f5655502a97b3f77e421a3d00bf1bc0b57 100644 (file)
@@ -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;