[libvirt] [PATCH] check/add for mdev_types capability

Dan Zheng posted 1 patch 6 years, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1989589958.4814.1516079093102.JavaMail.zimbra@redhat.com
src/node_device/node_device_driver.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
[libvirt] [PATCH] check/add for mdev_types capability
Posted by Dan Zheng 6 years, 3 months ago
>From be62ea5394d52fa168079edc3aa7e558363a3026 Mon Sep 17 00:00:00 2001
From: Dan Zheng <dzheng@redhat.com>
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@redhat.com>
---
 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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] check/add for mdev_types capability
Posted by Erik Skultety 6 years, 3 months ago
On Tue, Jan 16, 2018 at 12:04:53AM -0500, Dan Zheng wrote:
> >From be62ea5394d52fa168079edc3aa7e558363a3026 Mon Sep 17 00:00:00 2001
> From: Dan Zheng <dzheng@redhat.com>
> 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@redhat.com>
> ---

Reviewed-by: Erik Skultety <eskultet@redhat.com> (and safe for freeze) - I
shortened the commit message a bit before pushing.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list