提交 f44ec9c1 编写于 作者: J John Ferlan

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()
上级 e8fcac8e
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册