[PATCH] When kmodpy is not available call kmod binary directly

Maurizio Lombardi mlombard at bsdbackstore.eu
Fri Mar 21 05:39:30 PDT 2025


On Fri Mar 21, 2025 at 11:59 AM CET, Michal Suchanek wrote:
> 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

https://lore.kernel.org/target-devel/CAFL455=r4SuND7vL1Sr2vKzLTsgg-KL7GNzzJZPe2wDDH-NQyg@mail.gmail.com/

However I think that the fallback is ok and I will do the same
on targetcli too, soon or later.

Maurizio

>
> 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(-)
>
> diff --git a/nvmet/nvme.py b/nvmet/nvme.py
> index 59efdb5b7c1b..397f103abcdb 100644
> --- a/nvmet/nvme.py
> +++ b/nvmet/nvme.py
> @@ -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()




More information about the Linux-nvme mailing list