]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Add the missing PCI dev checks for 'mdev_types' capability v4.0.0-rc2
authorDan Zheng <dzheng@redhat.com>
Tue, 16 Jan 2018 04:21:21 +0000 (12:21 +0800)
committerErik Skultety <eskultet@redhat.com>
Tue, 16 Jan 2018 09:33:25 +0000 (10:33 +0100)
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>
src/node_device/node_device_driver.c

index facfeb695755eda2696387fc0f7907ddff7a78c1..6216a697737384ba921c00b13f29762f4ca11b73 100644 (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;