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/8.5.1
Saravanan KR 1 month ago
parent
commit
a52ab6784b
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

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