Adding a udev rule to save sriov interface name before configuring switchdev

After moving mlnx interfaces to switchdev mode in sriov, it may
change its name.
So adding a udev rule with PCI address to save the interface name.

Change-Id: I484f8a33ad16aa8815eb9ec60e5c77d776063c39
Closes-Bug: #1820050
This commit is contained in:
waleed mousa 2019-03-12 10:39:13 -04:00
parent 83ab4a196f
commit 97679372dd
1 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,7 @@ from oslo_concurrency import processutils
logger = logging.getLogger(__name__)
_SYS_CLASS_NET = '/sys/class/net'
_UDEV_RULE_FILE = '/etc/udev/rules.d/70-persistent-net.rules'
# Create a queue for passing the udev network events
vf_queue = Queue.Queue()
@ -122,6 +123,8 @@ def configure_sriov_pf():
if os.path.exists(vf_pci_path):
with open(MLNX_UNBIND_FILE_PATH, 'w') as f:
f.write("%s" % vf_pci)
# Adding a udev rule to save the sriov_pf name
add_udev_rule_for_sriov_pf(item['name'])
configure_switchdev(item['name'])
if_up_interface(item['name'])
@ -156,6 +159,34 @@ def _wait_for_vf_creation(pf_name, numvfs):
logger.info("Required VFs are created for PF %s" % pf_name)
def add_udev_rule_for_sriov_pf(pf_name):
pf_pci = get_pf_pci(pf_name)
udev_data_line = 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", '\
'KERNELS=="%s", NAME="%s"\n' % (pf_pci, pf_name)
add_udev_rule(udev_data_line, _UDEV_RULE_FILE)
def add_udev_rule(udev_data, udev_file):
if not os.path.exists(udev_file):
with open(udev_file, "w") as f:
f.write(udev_data)
reload_udev_rules()
else:
file_data = get_file_data(udev_file)
if udev_data not in file_data:
with open(udev_file, "a") as f:
f.write(udev_data)
reload_udev_rules()
def reload_udev_rules():
try:
processutils.execute('/usr/sbin/udevadm', 'control', '--reload-rules')
except processutils.ProcessExecutionError:
logger.error("Failed to reload udev rules")
raise
def configure_switchdev(pf_name):
pf_pci = get_pf_pci(pf_name)
pf_device_id = get_pf_device_id(pf_name)