Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Suchanek <msuchanek@suse.de>
To: linux-nvme@lists.infradead.org
Cc: Michal Suchanek <msuchanek@suse.de>
Subject: [PATCH] When kmodpy is not available call kmod binary directly
Date: Fri, 21 Mar 2025 11:59:10 +0100	[thread overview]
Message-ID: <20250321105915.8971-1-msuchanek@suse.de> (raw)

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(-)

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()
-- 
2.47.1



             reply	other threads:[~2025-03-21 10:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21 10:59 Michal Suchanek [this message]
2025-03-21 12:39 ` [PATCH] When kmodpy is not available call kmod binary directly Maurizio Lombardi
2026-07-07 13:37 ` Michal Suchánek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250321105915.8971-1-msuchanek@suse.de \
    --to=msuchanek@suse.de \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox