Martin Polednik has uploaded a new change for review.

Change subject: hostdev: report physfn
......................................................................

hostdev: report physfn

Each sr-iov virtual function is actually a separate function on a pci
bus. Libvirt reports these functions on the same level as physical
functions, but sysfs provides us means of determining which pf does
given vf belong to. This is useful in order to correctly construct the
tree.

Change-Id: I82294e22b4e301113de47c963d95fb0a2a537aa4
Signed-off-by: Martin Polednik <mpoled...@redhat.com>
---
M tests/hostdevTests.py
M vdsm/hostdev.py
2 files changed, 103 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/23/36123/1

diff --git a/tests/hostdevTests.py b/tests/hostdevTests.py
index d460883..30ff797 100644
--- a/tests/hostdevTests.py
+++ b/tests/hostdevTests.py
@@ -218,6 +218,63 @@
     </device>
     """]
 
+_SRIOV_PF_XML = """
+    <device>
+    <name>pci_0000_05_00_1</name>
+    <path>/sys/devices/pci0000:00/0000:00:09.0/0000:05:00.1</path>
+    <parent>pci_0000_00_09_0</parent>
+    <driver>
+        <name>igb</name>
+    </driver>
+    <capability type='pci'>
+        <domain>0</domain>
+        <bus>5</bus>
+        <slot>0</slot>
+        <function>1</function>
+        <product id='0x10c9'>82576 Gigabit Network Connection</product>
+        <vendor id='0x8086'>Intel Corporation</vendor>
+        <capability type='virt_functions'>
+        <address domain='0x0000' bus='0x05' slot='0x10' function='0x1'/>
+        <address domain='0x0000' bus='0x05' slot='0x10' function='0x3'/>
+        <address domain='0x0000' bus='0x05' slot='0x10' function='0x5'/>
+        <address domain='0x0000' bus='0x05' slot='0x10' function='0x7'/>
+        <address domain='0x0000' bus='0x05' slot='0x11' function='0x1'/>
+        <address domain='0x0000' bus='0x05' slot='0x11' function='0x3'/>
+        <address domain='0x0000' bus='0x05' slot='0x11' function='0x5'/>
+        </capability>
+        <iommuGroup number='15'>
+        <address domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
+        <address domain='0x0000' bus='0x05' slot='0x00' function='0x1'/>
+        </iommuGroup>
+    </capability>
+    </device>
+    """
+
+_SRIOV_VF_XML = """
+    <device>
+    <name>pci_0000_05_10_7</name>
+    <path>/sys/devices/pci0000:00/0000:00:09.0/0000:05:10.7</path>
+    <parent>pci_0000_00_09_0</parent>
+    <driver>
+        <name>igbvf</name>
+    </driver>
+    <capability type='pci'>
+        <domain>0</domain>
+        <bus>5</bus>
+        <slot>16</slot>
+        <function>7</function>
+        <product id='0x10ca'>82576 Virtual Function</product>
+        <vendor id='0x8086'>Intel Corporation</vendor>
+        <capability type='phys_function'>
+        <address domain='0x0000' bus='0x05' slot='0x00' function='0x1'/>
+        </capability>
+        <iommuGroup number='25'>
+        <address domain='0x0000' bus='0x05' slot='0x10' function='0x7'/>
+        </iommuGroup>
+    </capability>
+    </device>
+    """
+
 ADDITIONAL_DEVICE = """
     <device>
         <name>pci_0000_00_09_0</name>
@@ -286,7 +343,6 @@
                                         'product_id': '0x1502',
                                         'parent': 'computer',
                                         'vendor_id': '0x8086',
-                                        'totalvfs': '7',
                                         'capability': 'pci'},
                   u'usb_1_1_4': {'product': 'Broadcom Bluetooth Device',
                                  'vendor': 'Broadcom Corp',
@@ -311,6 +367,25 @@
                             'parent': 'computer',
                             'iommu_group': '4',
                             'vendor_id': '0x8086', 'capability': 'pci'}
+
+_SRIOV_PF_PARSED = {'capability': 'pci',
+                    'iommu_group': '15',
+                    'parent': 'pci_0000_00_09_0',
+                    'physfn': 'pci_0000_05_10_1',
+                    'product': '82576 Gigabit Network Connection',
+                    'product_id': '0x10c9',
+                    'totalvfs': '7',
+                    'vendor': 'Intel Corporation',
+                    'vendor_id': '0x8086'}
+
+_SRIOV_VF_PARSED = {'capability': 'pci',
+                    'iommu_group': '25',
+                    'parent': 'pci_0000_00_09_0',
+                    'physfn': 'pci_0000_05_00_1',
+                    'product': '82576 Virtual Function',
+                    'product_id': '0x10ca',
+                    'vendor': 'Intel Corporation',
+                    'vendor_id': '0x8086'}
 
 DEVICE_TO_VM_MAPPING = {'usb_1_1_4': 'vmId1', 'pci_0000_00_19_0': 'vmId2'}
 
@@ -391,6 +466,16 @@
 
         self.assertEquals(ADDITIONAL_DEVICE_PARSED, deviceXML)
 
+    def testParseSRIOV_PFDeviceParams(self):
+        deviceXML = hostdev._parse_device_params(_SRIOV_PF_XML)
+
+        self.assertEquals(_SRIOV_PF_PARSED, deviceXML)
+
+    def testParseSRIOV_VFDeviceParams(self):
+        deviceXML = hostdev._parse_device_params(_SRIOV_PF_XML)
+
+        self.assertEquals(_SRIOV_PF_PARSED, deviceXML)
+
     def testGetDevicesFromLibvirt(self):
         libvirt_devices = hostdev._get_devices_from_libvirt()
 
diff --git a/vdsm/hostdev.py b/vdsm/hostdev.py
index 3b5ed7c..d4b8a27 100644
--- a/vdsm/hostdev.py
+++ b/vdsm/hostdev.py
@@ -30,10 +30,21 @@
     return device_name[4:].replace('_', '.').replace('.', ':', 2)
 
 
+def _pci_address_to_name(domain, bus, slot, function):
+    """
+    Convert 4 attributes that identify the pci device on the bus to
+    libvirt's pci name: pci_${domain}_${bus}_${slot}_${function}
+    """
+    return 'pci_{}_{}_{}_{}'.format(domain[2:],
+                                    bus[2:],
+                                    slot[2:],
+                                    function[2:])
+
+
 def _sriov_totalvfs(device_name):
     with open('/sys/bus/pci/devices/{}/sriov_totalvfs'.format(
             _name_to_pci_path(device_name))) as f:
-        return int(f.read())
+        return str(int(f.read()))
 
 
 def _parse_device_params(device_xml):
@@ -59,6 +70,11 @@
             if elementXML.text:
                 params[element] = elementXML.text
 
+    physfn = caps.find('capability')
+    if physfn is not None and params['capability'] == 'pci':
+        address = physfn.find('address')
+        params['physfn'] = _pci_address_to_name(**address.attrib)
+
     iommu_group = caps.find('iommuGroup')
     if iommu_group is not None:
         params['iommu_group'] = iommu_group.attrib['number']


-- 
To view, visit http://gerrit.ovirt.org/36123
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I82294e22b4e301113de47c963d95fb0a2a537aa4
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpoled...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to