libblockdev/0002-Check-also-for-aliases-in-bd_utils_have_kernel_module.patch
2024-05-30 15:38:18 +02:00

87 lines
3.1 KiB
Diff

From 91c22078e9d369d266c044f949b65ebd611f31b0 Mon Sep 17 00:00:00 2001
From: Vojtech Trefny <vtrefny@redhat.com>
Date: Tue, 21 May 2024 15:42:29 +0200
Subject: [PATCH] utils: Check also for aliases in bd_utils_have_kernel_module
We want to return true for ext2/3 which are now supported by ext4
module.
---
src/utils/module.c | 12 +++++++++++-
tests/utils_test.py | 22 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/src/utils/module.c b/src/utils/module.c
index 66d02343..71d53b46 100644
--- a/src/utils/module.c
+++ b/src/utils/module.c
@@ -85,6 +85,7 @@ gboolean bd_utils_have_kernel_module (const gchar *module_name, GError **error)
gint ret = 0;
struct kmod_ctx *ctx = NULL;
struct kmod_module *mod = NULL;
+ struct kmod_list *list = NULL;
gchar *null_config = NULL;
const gchar *path = NULL;
gboolean have_path = FALSE;
@@ -100,21 +101,30 @@ gboolean bd_utils_have_kernel_module (const gchar *module_name, GError **error)
}
set_kmod_logging (ctx);
- ret = kmod_module_new_from_name (ctx, module_name, &mod);
+ ret = kmod_module_new_from_lookup (ctx, module_name, &list);
if (ret < 0) {
g_set_error (error, BD_UTILS_MODULE_ERROR, BD_UTILS_MODULE_ERROR_FAIL,
"Failed to get the module: %s", strerror_l (-ret, c_locale));
kmod_unref (ctx);
+ kmod_module_unref_list (list);
+ freelocale (c_locale);
+ return FALSE;
+ }
+
+ if (list == NULL) {
+ kmod_unref (ctx);
freelocale (c_locale);
return FALSE;
}
+ mod = kmod_module_get_module (list);
path = kmod_module_get_path (mod);
have_path = (path != NULL) && (g_strcmp0 (path, "") != 0);
if (!have_path) {
builtin = kmod_module_get_initstate (mod) == KMOD_MODULE_BUILTIN;
}
kmod_module_unref (mod);
+ kmod_module_unref_list (list);
kmod_unref (ctx);
freelocale (c_locale);
diff --git a/tests/utils_test.py b/tests/utils_test.py
index d656d309..372228f8 100644
--- a/tests/utils_test.py
+++ b/tests/utils_test.py
@@ -484,3 +484,25 @@ def test_initialization(self):
self.assertEqual(ver.major, ver2.major)
self.assertEqual(ver.minor, ver2.minor)
self.assertEqual(ver.micro, ver2.micro)
+
+
+class UtilsKernelModuleTest(UtilsTestCase):
+ @tag_test(TestTags.NOSTORAGE, TestTags.CORE)
+ def test_have_kernel_module(self):
+ """ Test checking for kernel modules """
+
+ have = BlockDev.utils_have_kernel_module("definitely-not-existing-kernel-module")
+ self.assertFalse(have)
+
+ # loop should be everywhere, right?
+ have = BlockDev.utils_have_kernel_module("loop")
+ self.assertTrue(have)
+
+ # lets check some filesystems support and compare with 'modprobe' results
+ for fs in ("ext2", "ext3", "ext4", "xfs", "btrfs"):
+ have_fs = BlockDev.utils_have_kernel_module(fs)
+ ret, _out, _err = run_command("modprobe --dry-run %s" % fs)
+ if ret == 0:
+ self.assertTrue(have_fs)
+ else:
+ self.assertFalse(have_fs)