aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Klozik <martinx.klozik@intel.com>2015-10-16 06:29:30 +0100
committerMaryam Tahhan <maryam.tahhan@intel.com>2015-10-20 13:44:52 +0000
commit0bb85c9c85b7aeb74761c6a565e554674a7661c1 (patch)
tree40cf8f6f697877cab7a598838ba40803638e41b4
parent6f35ae4f20e2f47fae569b29907fa77102ee9ee2 (diff)
Implement support of 'insmod' and 'modprobe' commands into ModuleManager
Module manager has been enhanced to support both 'insmod' and 'modprobe' commands for kernel module insertion. In case, that .ko suffix is detected then insmod will be used otherwise modprobe will be called. This allows user to specify full path to each module. For example vanilla ovs module can be defined as "OVS_DIR_VANILLA + 'datapath/linux/openvswitch.ko'" to load kernel module matching OVS vanilla source tree version. Change-Id: Ib8d16eca84449ad34d6b307ab836f58d2f0d341b JIRA: VSPERF-116 Signed-off-by: Martin Klozik <martinx.klozik@intel.com> Reviewed-by: Billy O Mahony <billy.o.mahony@intel.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com> Reviewed-by: Brian Castelli <brian.castelli@spirent.com>
-rw-r--r--src/dpdk/dpdk.py4
-rw-r--r--tools/module_manager.py42
-rw-r--r--vswitches/ovs_vanilla.py4
3 files changed, 21 insertions, 29 deletions
diff --git a/src/dpdk/dpdk.py b/src/dpdk/dpdk.py
index 0633c7a1..0a63c161 100644
--- a/src/dpdk/dpdk.py
+++ b/src/dpdk/dpdk.py
@@ -28,13 +28,13 @@ import locale
from tools import tasks
from conf import settings
-from tools.module_manager import ModuleManager, KernelModuleInsertMode
+from tools.module_manager import ModuleManager
_LOGGER = logging.getLogger(__name__)
RTE_PCI_TOOL = os.path.join(
settings.getValue('RTE_SDK'), 'tools', 'dpdk_nic_bind.py')
-_DPDK_MODULE_MANAGER = ModuleManager(KernelModuleInsertMode.MODPROBE)
+_DPDK_MODULE_MANAGER = ModuleManager()
#
# system management
diff --git a/tools/module_manager.py b/tools/module_manager.py
index 6ed80e93..39ad5cf4 100644
--- a/tools/module_manager.py
+++ b/tools/module_manager.py
@@ -19,34 +19,21 @@ import subprocess
import logging
from tools import tasks
-class KernelModuleInsertMode(object):
- """Module manager type of insert definition.
- """
- MODPROBE = 1
- INSMOD = 2 #NOT IMPLEMENTED
-
class ModuleManager(object):
"""Simple module manager which acts as system wrapper for Kernel Modules.
"""
_logger = logging.getLogger(__name__)
- def __init__(self, insert_mode=KernelModuleInsertMode.MODPROBE):
- """Initializes data and sets insert mode.
-
- :param insert_mode: insert mode defines how modules are going to
- be inserted in system.
+ def __init__(self):
+ """Initializes data
"""
self._modules = None
- self._insert_mode = insert_mode
def insert_modules(self, modules):
- """Method inserts list of modules using defined insert mode.
-
- :param modules: list of modules to be inserted. Each element on
- list should represent format which is expected
- by KernelModuleInsertMode (e.g. for MODPROBE it
- would be module name).
+ """Method inserts list of modules. In case that module name ends
+ with .ko suffix then insmod will be used for its insertion. Otherwise
+ modprobe will be called.
:returns: None
"""
@@ -56,13 +43,12 @@ class ModuleManager(object):
continue
try:
- if self._insert_mode == KernelModuleInsertMode.MODPROBE:
- tasks.run_task(['sudo', 'modprobe', module], self._logger,
- 'Inserting module \'%s\'...' % module, True)
+ if module.endswith('.ko'):
+ tasks.run_task(['sudo', 'insmod', module], self._logger,
+ 'Insmod module \'%s\'...' % module, True)
else:
- self._logger.error(
- "Kernel module insert mode NOT IMPLEMENTED.")
- raise
+ tasks.run_task(['sudo', 'modprobe', module], self._logger,
+ 'Modprobe module \'%s\'...' % module, True)
except subprocess.CalledProcessError:
self._logger.error('Unable to insert module \'%s\'.', module)
@@ -77,6 +63,8 @@ class ModuleManager(object):
continue
try:
+ # rmmod supports both simple module name and full module path
+ # with .ko suffix
tasks.run_task(['sudo', 'rmmod', module], self._logger,
'Removing module \'%s\'...' % module, True)
except subprocess.CalledProcessError:
@@ -87,11 +75,15 @@ class ModuleManager(object):
def is_module_inserted(module):
"""Check if a module is inserted on system.
"""
+ # get module base name, i.e strip path and .ko suffix if possible
+ module_base_name = module.split('.')[0].split('/').pop()
+
+ # get list of modules from kernel
with open('/proc/modules') as mod_file:
loaded_mods = mod_file.readlines()
# first check if module is loaded
for line in loaded_mods:
- if line.startswith(module):
+ if line.startswith(module_base_name):
return True
return False
diff --git a/vswitches/ovs_vanilla.py b/vswitches/ovs_vanilla.py
index 6716401d..36ad6054 100644
--- a/vswitches/ovs_vanilla.py
+++ b/vswitches/ovs_vanilla.py
@@ -19,7 +19,7 @@ import logging
from conf import settings
from vswitches.vswitch import IVSwitch
from src.ovs import VSwitchd, OFBridge
-from tools.module_manager import ModuleManager, KernelModuleInsertMode
+from tools.module_manager import ModuleManager
from tools import tasks
_LOGGER = logging.getLogger(__name__)
@@ -47,7 +47,7 @@ class OvsVanilla(IVSwitch):
self._vswitchd = VSwitchd(vswitchd_args=vswitchd_args,
expected_cmd="db.sock: connected")
self._bridges = {}
- self._module_manager = ModuleManager(KernelModuleInsertMode.MODPROBE)
+ self._module_manager = ModuleManager()
def start(self):
"""See IVswitch for general description