diff options
| author | Viacheslav <v.gletenko@vyos.io> | 2025-08-18 18:19:57 +0000 |
|---|---|---|
| committer | Viacheslav <v.gletenko@vyos.io> | 2025-08-21 13:43:45 +0000 |
| commit | c273672867b7ca4e462d2c1898260b132c64ca8e (patch) | |
| tree | 7983101c3371cbf79db1d74af000f9f681a1a22d /src | |
| parent | 69cd4845861c88285ab496339f19103dec7a32b6 (diff) | |
| download | vyos-1x-c273672867b7ca4e462d2c1898260b132c64ca8e.tar.gz vyos-1x-c273672867b7ca4e462d2c1898260b132c64ca8e.zip | |
T7732: VPP add modprobe vfio modules
Add vfio modules before VPP starting and remove modules after
the VPP configuration deleted
modules:
- vfio
- vfio_iommu_type1
- vfio_pci
Diffstat (limited to 'src')
| -rwxr-xr-x | src/conf_mode/vpp.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/conf_mode/vpp.py b/src/conf_mode/vpp.py index 90e71e522..6dd30fa85 100755 --- a/src/conf_mode/vpp.py +++ b/src/conf_mode/vpp.py @@ -32,8 +32,12 @@ from vyos.config import Config, config_dict_merge from vyos.configdep import set_dependents, call_dependents from vyos.configdict import node_changed, leaf_node_changed from vyos.ifconfig import Section +from vyos.logger import getLogger from vyos.template import render from vyos.utils.boot import boot_configuration_complete +from vyos.utils.kernel import check_kmod +from vyos.utils.kernel import unload_kmod +from vyos.utils.kernel import list_loaded_modules from vyos.utils.process import call from vyos.utils.system import sysctl_read, sysctl_apply @@ -66,6 +70,10 @@ service_name = 'vpp' service_conf = Path(f'/run/vpp/{service_name}.conf') systemd_override = '/run/systemd/system/vpp.service.d/10-override.conf' +vpp_log = getLogger( + service_name, format='%(filename)s[%(process)d]: %(message)s', address='/dev/log' +) + dependency_interface_type_map = { 'vpp_interfaces_bonding': 'bonding', 'vpp_interfaces_bridge': 'bridge', @@ -104,6 +112,42 @@ drivers_support_interrupt: dict[str, list] = { } +def _load_module(module_name: str): + """ + Load a kernel module + + Args: + module_name (str): Name of the module to load. + """ + if module_name in list_loaded_modules(): + vpp_log.info(f"Module '{module_name}' is alrady loaded") + return + try: + check_kmod(module_name) + vpp_log.info(f"Module '{module_name}' loaded successfully") + except Exception as e: + vpp_log.error(f"Failed to load module '{module_name}': {e}") + raise + + +def _unload_module(module_name: str): + """ + Unload a kernel module + + Args: + module_name (str): Name of the module to unload. + """ + if module_name not in list_loaded_modules(): + vpp_log.info(f"Module '{module_name}' is not loaded") + return + try: + unload_kmod(module_name) + vpp_log.info(f"Module '{module_name}' unloaded successfully") + except Exception as e: + vpp_log.error(f"Failed to unload module '{module_name}': {e}") + raise + + def get_config(config=None): # use persistent config to store interfaces data between executions # this is required because some interfaces after they are connected @@ -531,6 +575,8 @@ def initialize_interface(iface, driver, iface_config) -> None: def apply(config): + # modrpobe modules + modules = ('vfio_iommu_type1', 'vfio_pci', 'vfio_pci_core', 'vfio') # Open persistent config # It is required for operations with interfaces persist_config = JSONStorage('vpp_conf') @@ -539,9 +585,20 @@ def apply(config): persist_config.delete() # And stop the service call(f'systemctl stop {service_name}.service') + # Unlod modules (modprobe -r) + for module in modules: + _unload_module(module) else: # Some interfaces required extra preparation before VPP can be started if 'settings' in config and 'interface' in config.get('settings'): + # modprobe vfio + if any( + iface_config.get('driver') == 'dpdk' + for iface_config in config['settings']['interface'].values() + ): + for module in modules: + _load_module(module) + for iface, iface_config in config['settings']['interface'].items(): if iface_config['driver'] == 'dpdk': # ena interfaces require noiommu mode |
