Blame SOURCES/kmod-modprobe-ignore-builtin-module-on-recursive-removing.patch

8e4cb0
From 52a0ba82e1ad180f9f91920db70a758fac49466a Mon Sep 17 00:00:00 2001
8e4cb0
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
8e4cb0
Date: Thu, 31 Oct 2019 20:12:53 +0200
8e4cb0
Subject: [PATCH] modprobe: ignore builtin module on recursive removing
8e4cb0
8e4cb0
If there are built-in dependencies and any of them is built-in in
8e4cb0
the kernel, modprobe -r fails with
8e4cb0
8e4cb0
modprobe: FATAL: Module module_name is builtin.
8e4cb0
8e4cb0
It makes sense to ignore such dependencies for the case when
8e4cb0
removing is called for non-top level module.
8e4cb0
8e4cb0
Example: cifs module, it declares bunch of softdeps and the first
8e4cb0
one fails on some kernel configs:
8e4cb0
8e4cb0
modprobe: FATAL: Module gcm is builtin.
8e4cb0
8e4cb0
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
8e4cb0
---
8e4cb0
 tools/modprobe.c | 18 ++++++++++++------
8e4cb0
 1 file changed, 12 insertions(+), 6 deletions(-)
8e4cb0
8e4cb0
diff --git a/tools/modprobe.c b/tools/modprobe.c
8e4cb0
index a9e2331567af..44cd15c2bf57 100644
8e4cb0
--- a/tools/modprobe.c
8e4cb0
+++ b/tools/modprobe.c
8e4cb0
@@ -353,7 +353,8 @@ static int rmmod_do_remove_module(struct kmod_module *mod)
8e4cb0
 	return err;
8e4cb0
 }
8e4cb0
 
8e4cb0
-static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies);
8e4cb0
+static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
8e4cb0
+			   bool ignore_builtin);
8e4cb0
 
8e4cb0
 static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
8e4cb0
 {
8e4cb0
@@ -361,7 +362,7 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
8e4cb0
 
8e4cb0
 	kmod_list_foreach_reverse(l, list) {
8e4cb0
 		struct kmod_module *m = kmod_module_get_module(l);
8e4cb0
-		int r = rmmod_do_module(m, false);
8e4cb0
+		int r = rmmod_do_module(m, false, true);
8e4cb0
 		kmod_module_unref(m);
8e4cb0
 
8e4cb0
 		if (r < 0 && stop_on_errors)
8e4cb0
@@ -371,7 +372,8 @@ static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
8e4cb0
 	return 0;
8e4cb0
 }
8e4cb0
 
8e4cb0
-static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies)
8e4cb0
+static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies,
8e4cb0
+			   bool ignore_builtin)
8e4cb0
 {
8e4cb0
 	const char *modname = kmod_module_get_name(mod);
8e4cb0
 	struct kmod_list *pre = NULL, *post = NULL;
8e4cb0
@@ -401,8 +403,12 @@ static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies)
8e4cb0
 			}
8e4cb0
 			goto error;
8e4cb0
 		} else if (state == KMOD_MODULE_BUILTIN) {
8e4cb0
-			LOG("Module %s is builtin.\n", modname);
8e4cb0
-			err = -ENOENT;
8e4cb0
+			if (ignore_builtin) {
8e4cb0
+				err = 0;
8e4cb0
+			} else {
8e4cb0
+				LOG("Module %s is builtin.\n", modname);
8e4cb0
+				err = -ENOENT;
8e4cb0
+			}
8e4cb0
 			goto error;
8e4cb0
 		}
8e4cb0
 	}
8e4cb0
@@ -462,7 +468,7 @@ static int rmmod(struct kmod_ctx *ctx, const char *alias)
8e4cb0
 
8e4cb0
 	kmod_list_foreach(l, list) {
8e4cb0
 		struct kmod_module *mod = kmod_module_get_module(l);
8e4cb0
-		err = rmmod_do_module(mod, true);
8e4cb0
+		err = rmmod_do_module(mod, true, false);
8e4cb0
 		kmod_module_unref(mod);
8e4cb0
 		if (err < 0)
8e4cb0
 			break;
8e4cb0
-- 
8e4cb0
2.24.0
8e4cb0