MCPcopy Create free account
hub / github.com/F-Stack/f-stack / module_is_loaded

Function module_is_loaded

dpdk/usertools/dpdk-devbind.py:111–143  ·  view source on GitHub ↗
(module)

Source from the content-addressed store, hash-verified

109
110# check if a specific kernel module is loaded
111def module_is_loaded(module):
112 global loaded_modules
113
114 if module == 'vfio_pci':
115 module = 'vfio-pci'
116
117 if loaded_modules:
118 return module in loaded_modules
119
120 # Get list of sysfs modules (both built-in and dynamically loaded)
121 sysfs_path = '/sys/module/'
122
123 # Get the list of directories in sysfs_path
124 sysfs_mods = [m for m in os.listdir(sysfs_path)
125 if os.path.isdir(os.path.join(sysfs_path, m))]
126
127 # special case for vfio_pci (module is named vfio-pci,
128 # but its .ko is named vfio_pci)
129 sysfs_mods = [a if a != 'vfio_pci' else 'vfio-pci' for a in sysfs_mods]
130
131 loaded_modules = sysfs_mods
132
133 # add built-in modules as loaded
134 release = platform.uname().release
135 filename = os.path.join("/lib/modules/", release, "modules.builtin")
136 if os.path.exists(filename):
137 try:
138 with open(filename) as f:
139 loaded_modules += [os.path.splitext(os.path.basename(mod))[0] for mod in f]
140 except IOError:
141 print("Warning: cannot read list of built-in kernel modules")
142
143 return module in loaded_modules
144
145
146def check_modules():

Callers 2

check_modulesFunction · 0.85
bind_allFunction · 0.85

Calls 1

printFunction · 0.50

Tested by

no test coverage detected