>From be62ea5394d52fa168079edc3aa7e558363a3026 Mon Sep 17 00:00:00 2001 From: Dan Zheng <dzheng@xxxxxxxxxx> Date: Tue, 16 Jan 2018 12:21:21 +0800 Subject: [PATCH] nodedev: check/add for mdev_types capability This is similar to commit f44ec9c1. Commit id '500cbc06' introduced a new nested capability element of type 'mdev_types' and the ability to use the flag as a way to search for a specific subset of a 'pci' device - namely a 'mdev_types'. 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. This patch adds the check for the 'mdev_types' bits within a 'pci' 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 'mdev_types' in dev.listCaps(): print dev.name(),dev.numOfCaps(),dev.listCaps() Signed-off-by: Dan Zheng <dzheng@xxxxxxxxxx> --- src/node_device/node_device_driver.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index facfeb6..6216a69 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -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; -- 1.8.3.1 -- Best Regards, Dan Zheng(郑丹) Red Hat Software (Beijing) Co. 9/F, North Tower C, Raycom Infotech Park No.2 Ke Xueyuan Nanlu, Haidian District Beijing 100190 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list