nodedev: Add the missing PCI dev checks for 'mdev_types' capability

Similar to commit @f44ec9c1, commit @500cbc06 introduced a new nested
'mdev_types' capability, however the mentioned commit didn't adjust
virNodeDeviceNumOfCaps and virNodeDeviceListCaps functions accordingly
to provide proper support for this capability.

After applying this patch the following python snippet returns the
expected results:
    import libvirt
    conn = libvirt.openReadOnly('qemu:///system')
    devs = conn.listAllDevices()
    for dev in devs:
        if 'mdev_types' in dev.listCaps():
            print dev.name(),dev.numOfCaps(),dev.listCaps()

Signed-off-by: Dan Zheng <dzheng@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Dan Zheng 2018-01-16 12:21:21 +08:00 committed by Erik Skultety
parent 74416b1d48
commit 75cfb8434e

View File

@ -382,6 +382,12 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device)
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)
ncaps++;
}
if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
if (caps->data.pci_dev.flags &
VIR_NODE_DEV_CAP_FLAG_PCI_MDEV)
ncaps++;
}
}
ret = ncaps;
@ -432,6 +438,15 @@ nodeDeviceListCaps(virNodeDevicePtr device,
goto cleanup;
}
}
if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
if (ncaps < maxnames &&
caps->data.pci_dev.flags &
VIR_NODE_DEV_CAP_FLAG_PCI_MDEV) {
if (VIR_STRDUP(names[ncaps++],
virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES)) < 0)
goto cleanup;
}
}
}
ret = ncaps;