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
)
This commit is contained in:
parent
8509562dc4
commit
9e0e649ba2
|
@ -478,6 +478,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')
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue