Browse Source

Avoid driverctl run if the driver is already bound

Check if the specified interface already has the required driver,
if yes, do not invoke driverctl to bind again. If there no
binding, then it will not be added to dpdk mapping file.

Change-Id: I707fd5f02dcbca31d925839a0b2c73b07a2f5974
Closes-Bug: # 1838363
(cherry picked from commit c5ae935753)
tags/10.4.1
Saravanan KR 1 month ago
parent
commit
9e0e649ba2
2 changed files with 49 additions and 0 deletions
  1. 30
    0
      os_net_config/tests/test_utils.py
  2. 19
    0
      os_net_config/utils.py

+ 30
- 0
os_net_config/tests/test_utils.py View File

@@ -478,6 +478,36 @@ class TestUtils(base.TestCase):
478 478
                           utils.bind_dpdk_interfaces, 'eth2', 'vfio-pci',
479 479
                           False)
480 480
 
481
+    def test_bind_dpdk_interfaces_same_driver(self):
482
+        mocked_open = mock.mock_open(read_data='DRIVER=vfio-pci\n')
483
+        self.stub_out('os_net_config.utils.open', mocked_open)
484
+        mocked_logger = mock.Mock()
485
+        self.stub_out('os_net_config.utils.logger.info', mocked_logger)
486
+        try:
487
+            utils.bind_dpdk_interfaces('eth1', 'vfio-pci', False)
488
+        except utils.OvsDpdkBindException:
489
+            self.fail("Received OvsDpdkBindException unexpectedly")
490
+        msg = "Driver (vfio-pci) is already bound to the device (eth1)"
491
+        mocked_logger.assert_called_with(msg)
492
+
493
+    def test_get_interface_driver(self):
494
+        mocked_open = mock.mock_open(read_data='DRIVER=vfio-pci\n')
495
+        self.stub_out('os_net_config.utils.open', mocked_open)
496
+        driver = utils.get_interface_driver('eth1')
497
+        self.assertEqual(driver, 'vfio-pci')
498
+
499
+    def test_get_interface_driver_fail_none(self):
500
+        mocked_open = mock.mock_open(read_data='')
501
+        self.stub_out('os_net_config.utils.open', mocked_open)
502
+        driver = utils.get_interface_driver('eth1')
503
+        self.assertFalse(driver)
504
+
505
+    def test_get_interface_driver_fail_empty(self):
506
+        mocked_open = mock.mock_open(read_data='DRIVER\n')
507
+        self.stub_out('os_net_config.utils.open', mocked_open)
508
+        driver = utils.get_interface_driver('eth1')
509
+        self.assertFalse(driver)
510
+
481 511
     def test__update_dpdk_map_new(self):
482 512
         utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
483 513
                                'vfio-pci')

+ 19
- 0
os_net_config/utils.py View File

@@ -251,6 +251,11 @@ def diff(filename, data):
251 251
 
252 252
 
253 253
 def bind_dpdk_interfaces(ifname, driver, noop):
254
+    iface_driver = get_interface_driver(ifname)
255
+    if iface_driver == driver:
256
+        logger.info("Driver (%s) is already bound to the device (%s)" %
257
+                    (driver, ifname))
258
+        return
254 259
     pci_address = get_pci_address(ifname, noop)
255 260
     if not noop:
256 261
         if pci_address:
@@ -362,6 +367,20 @@ def get_device_id(ifname):
362 367
         return
363 368
 
364 369
 
370
+def get_interface_driver(ifname):
371
+    try:
372
+        uevent = '%s/%s/device/uevent' % (_SYS_CLASS_NET, ifname)
373
+        with open(uevent, 'r') as f:
374
+            out = f.read().strip()
375
+            for line in out.split('\n'):
376
+                if 'DRIVER' in line:
377
+                    driver = line.split('=')
378
+                    if len(driver) == 2:
379
+                        return driver[1]
380
+    except IOError:
381
+        return
382
+
383
+
365 384
 def get_dpdk_devargs(ifname, noop):
366 385
     if not noop:
367 386
         vendor_id = get_vendor_id(ifname)

Loading…
Cancel
Save