From d050119351ad94c7b559a84c82509e40a5af1df4 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 3 Nov 2023 13:17:37 +0100 Subject: [PATCH] fcoe/iscsi: Use libblockdev to load modules instead of modprobe --- blivet/fcoe.py | 19 ++++++++++++++++--- blivet/iscsi.py | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/blivet/fcoe.py b/blivet/fcoe.py index 31297d2e3..371f8c201 100644 --- a/blivet/fcoe.py +++ b/blivet/fcoe.py @@ -18,6 +18,12 @@ # import os + +import gi +gi.require_version("BlockDev", "3.0") + +from gi.repository import BlockDev + from . import errors from . import udev from . import util @@ -33,11 +39,18 @@ def has_fcoe(): global _fcoe_module_loaded if not _fcoe_module_loaded: - util.run_program(["modprobe", "libfc"]) - _fcoe_module_loaded = True + try: + BlockDev.utils.load_kernel_module("libfc", None) + except BlockDev.UtilsError as e: + log.error("failed to load libfc: %s", str(e)) + else: + _fcoe_module_loaded = True if "bnx2x" in util.lsmod(): log.info("fcoe: loading bnx2fc") - util.run_program(["modprobe", "bnx2fc"]) + try: + BlockDev.utils.load_kernel_module("bnx2fc", None) + except BlockDev.UtilsError as e: + log.error("failed to load bnx2fc: %s", str(e)) return os.access("/sys/module/libfc", os.X_OK) diff --git a/blivet/iscsi.py b/blivet/iscsi.py index 3b243f6fb..b63468e9b 100644 --- a/blivet/iscsi.py +++ b/blivet/iscsi.py @@ -33,7 +33,9 @@ import gi gi.require_version("GLib", "2.0") +gi.require_version("BlockDev", "3.0") from gi.repository import GLib +from gi.repository import BlockDev import logging log = logging.getLogger("blivet") @@ -314,7 +316,10 @@ def _start_ibft(self): # Make sure iscsi_ibft is loaded otherwise any atttempts will fail with # 'Could not get list of targets from firmware. (err 21)' - util.run_program(['modprobe', '-a', 'iscsi_ibft']) + try: + BlockDev.utils.load_kernel_module("iscsi_ibft", None) + except BlockDev.UtilsError as e: + log.error("failed to load iscsi_ibft: %s", str(e)) args = GLib.Variant("(a{sv})", ([], )) try: @@ -394,7 +399,12 @@ def startup(self): os.makedirs(fulldir, 0o755) log.info("iSCSI startup") - util.run_program(['modprobe', '-a'] + ISCSI_MODULES) + for module in ISCSI_MODULES: + try: + BlockDev.utils.load_kernel_module(module, None) + except BlockDev.UtilsError as e: + log.error("failed to load %s: %s", module, str(e)) + # iscsiuio is needed by Broadcom offload cards (bnx2i). Currently # not present in iscsi-initiator-utils for Fedora. iscsiuio = shutil.which('iscsiuio')