From 591ba03a9b6eb2cc2c349db25319806955f3f5d4 Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Tue, 30 Jul 2019 10:53:14 +0530 Subject: [PATCH] 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 c5ae935753f2bf7ed1b4b8a8f1b536d077e0cc20) --- os_net_config/tests/test_utils.py | 30 ++++++++++++++++++++++++++++++ os_net_config/utils.py | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/os_net_config/tests/test_utils.py b/os_net_config/tests/test_utils.py index 2e01df2c..35cb812d 100644 --- a/os_net_config/tests/test_utils.py +++ b/os_net_config/tests/test_utils.py @@ -471,6 +471,36 @@ class TestUtils(base.TestCase): utils.bind_dpdk_interfaces, 'eth2', 'vfio-pci', False) + def test_bind_dpdk_interfaces_same_driver(self): + mocked_open = mock.mock_open(read_data='DRIVER=vfio-pci\n') + self.stub_out('os_net_config.utils.open', mocked_open) + mocked_logger = mock.Mock() + self.stub_out('os_net_config.utils.logger.info', mocked_logger) + try: + utils.bind_dpdk_interfaces('eth1', 'vfio-pci', False) + except utils.OvsDpdkBindException: + self.fail("Received OvsDpdkBindException unexpectedly") + msg = "Driver (vfio-pci) is already bound to the device (eth1)" + mocked_logger.assert_called_with(msg) + + def test_get_interface_driver(self): + mocked_open = mock.mock_open(read_data='DRIVER=vfio-pci\n') + self.stub_out('os_net_config.utils.open', mocked_open) + driver = utils.get_interface_driver('eth1') + self.assertEqual(driver, 'vfio-pci') + + def test_get_interface_driver_fail_none(self): + mocked_open = mock.mock_open(read_data='') + self.stub_out('os_net_config.utils.open', mocked_open) + driver = utils.get_interface_driver('eth1') + self.assertFalse(driver) + + def test_get_interface_driver_fail_empty(self): + mocked_open = mock.mock_open(read_data='DRIVER\n') + self.stub_out('os_net_config.utils.open', mocked_open) + driver = utils.get_interface_driver('eth1') + self.assertFalse(driver) + def test__update_dpdk_map_new(self): utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06', 'vfio-pci') diff --git a/os_net_config/utils.py b/os_net_config/utils.py index 620ce269..a597b469 100644 --- a/os_net_config/utils.py +++ b/os_net_config/utils.py @@ -251,6 +251,11 @@ def diff(filename, data): def bind_dpdk_interfaces(ifname, driver, noop): + iface_driver = get_interface_driver(ifname) + if iface_driver == driver: + logger.info("Driver (%s) is already bound to the device (%s)" % + (driver, ifname)) + return pci_address = get_pci_address(ifname, noop) if not noop: if pci_address: @@ -362,6 +367,20 @@ def get_device_id(ifname): return +def get_interface_driver(ifname): + try: + uevent = '%s/%s/device/uevent' % (_SYS_CLASS_NET, ifname) + with open(uevent, 'r') as f: + out = f.read().strip() + for line in out.split('\n'): + if 'DRIVER' in line: + driver = line.split('=') + if len(driver) == 2: + return driver[1] + except IOError: + return + + def get_dpdk_devargs(ifname, noop): if not noop: vendor_id = get_vendor_id(ifname)