When kmodpy is not available call kmod binary directly
PATCH 1/1 When kmodpy is not available call kmod binary directly
kmodpy is an unmaintained project. Python is not really good at backwards compatibility. With the upstream project not keeping up with python churn using the library is a maintenance burden.
nvmet does not use the python library in any substantial way, it only loads a module once. This can be easily accomplished without any library using the modprobe tool directly.
--- nvmet/nvme.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
nvmet/nvme.py +14 -3
@@ -256,9 +256,20 @@ class Root(CFSNode): # Try the ctypes library included with the libkmod itself. try: import kmod - kmod.Kmod().modprobe(modname) - except Exception as e: - pass + + try: + kmod.Kmod().modprobe(modname) + except Exception as e: + pass + except ImportError: + # Try the binary specified in /proc + try: + kmod = None + with open('/proc/sys/kernel/modprobe', 'r') as f: + kmod = f.read().rstrip() + os.system(kmod + ' ' + modname) + except Exception as e: + pass def _list_subsystems(self): self._check_self()
Signature · 1 line
2.47.1
Quoted 3 lines · Michal Suchanek
kmodpy is an unmaintained project. Python is not really good at backwards compatibility. With the upstream project not keeping up with python churn using the library is a maintenance burden.
Well, the original maintainer abandoned it, I did what I could to make kmod able to run with latest Cython v3
However I think that the fallback is ok and I will do the same on targetcli too, soon or later.
Maurizio
Quoted 36 lines
nvmet does not use the python library in any substantial way, it only loads a module once. This can be easily accomplished without any library using the modprobe tool directly.
--- nvmet/nvme.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)nvmet/nvme.py +14
-3@@ -256,9 +256,20 @@ class Root(CFSNode): # Try the ctypes library included with the libkmod itself. try: import kmod - kmod.Kmod().modprobe(modname) - except Exception as e: - pass + + try: + kmod.Kmod().modprobe(modname) + except Exception as e: + pass + except ImportError: + # Try the binary specified in /proc + try: + kmod = None + with open('/proc/sys/kernel/modprobe', 'r') as f: + kmod = f.read().rstrip() + os.system(kmod + ' ' + modname) + except Exception as e: + pass def _list_subsystems(self): self._check_self()
Quoted 7 lines · Michal Suchanek
kmodpy is an unmaintained project. Python is not really good at backwards compatibility. With the upstream project not keeping up with python churn using the library is a maintenance burden.
nvmet does not use the python library in any substantial way, it only loads a module once. This can be easily accomplished without any library using the modprobe tool directly.
Forgot
Quoted 35 lines
--- nvmet/nvme.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)nvmet/nvme.py +14
-3@@ -256,9 +256,20 @@ class Root(CFSNode): # Try the ctypes library included with the libkmod itself. try: import kmod - kmod.Kmod().modprobe(modname) - except Exception as e: - pass + + try: + kmod.Kmod().modprobe(modname) + except Exception as e: + pass + except ImportError: + # Try the binary specified in /proc + try: + kmod = None + with open('/proc/sys/kernel/modprobe', 'r') as f: + kmod = f.read().rstrip() + os.system(kmod + ' ' + modname) + except Exception as e: + pass def _list_subsystems(self): self._check_self()Signature · 1 line
2.47.1