!48 kmod:rmmod增加-r命令,用于内核热替换场景
From: @yang_yanchao Reviewed-by: @SuperSix173 Signed-off-by: @SuperSix173
This commit is contained in:
commit
e61010ac59
108
Module-replace-the-module-with-new-module.patch
Normal file
108
Module-replace-the-module-with-new-module.patch
Normal file
@ -0,0 +1,108 @@
|
||||
From 7b595d0319908149edb603c49da05f8d5904a8d3 Mon Sep 17 00:00:00 2001
|
||||
From: Jason Luan <luanjianhai@huawei.com>
|
||||
Date: Wed, 16 Sep 2020 01:21:50 +0000
|
||||
Subject: [PATCH 1/2] Module: replace the module with new module
|
||||
|
||||
Signed-off-by: fu.lin <fu.lin10@huawei.com>
|
||||
---
|
||||
libkmod/libkmod-module.c | 3 +++
|
||||
libkmod/libkmod.h | 6 ++++++
|
||||
shared/missing.h | 7 +++++++
|
||||
tools/insmod.c | 7 ++++++-
|
||||
4 files changed, 22 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
|
||||
index 714ee21..a243672 100644
|
||||
--- a/libkmod/libkmod-module.c
|
||||
+++ b/libkmod/libkmod-module.c
|
||||
@@ -854,8 +854,11 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
|
||||
kernel_flags |= MODULE_INIT_IGNORE_VERMAGIC;
|
||||
if (flags & KMOD_INSERT_FORCE_MODVERSION)
|
||||
kernel_flags |= MODULE_INIT_IGNORE_MODVERSIONS;
|
||||
+ if (flags & KMOD_INSERT_REPLACE)
|
||||
+ kernel_flags |= MODULE_REPLACE_MODULE;
|
||||
|
||||
err = finit_module(kmod_file_get_fd(mod->file), args, kernel_flags);
|
||||
+
|
||||
if (err == 0 || errno != ENOSYS)
|
||||
goto init_finished;
|
||||
}
|
||||
diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h
|
||||
index 3cab2e5..241431e 100644
|
||||
--- a/libkmod/libkmod.h
|
||||
+++ b/libkmod/libkmod.h
|
||||
@@ -148,6 +148,9 @@ enum kmod_remove {
|
||||
enum kmod_insert {
|
||||
KMOD_INSERT_FORCE_VERMAGIC = 0x1,
|
||||
KMOD_INSERT_FORCE_MODVERSION = 0x2,
|
||||
+
|
||||
+ /* custom flag */
|
||||
+ KMOD_INSERT_REPLACE = 0x1000,
|
||||
};
|
||||
|
||||
/* Flags to kmod_module_probe_insert_module() */
|
||||
@@ -159,6 +162,9 @@ enum kmod_probe {
|
||||
KMOD_PROBE_DRY_RUN = 0x00010,
|
||||
KMOD_PROBE_FAIL_ON_LOADED = 0x00020,
|
||||
|
||||
+ /* custom flag */
|
||||
+ KMOD_PROBE_REPLACE = 0x01000,
|
||||
+
|
||||
/* codes below can be used in return value, too */
|
||||
KMOD_PROBE_APPLY_BLACKLIST_ALL = 0x10000,
|
||||
KMOD_PROBE_APPLY_BLACKLIST = 0x20000,
|
||||
diff --git a/shared/missing.h b/shared/missing.h
|
||||
index 4c0d136..4d2253b 100644
|
||||
--- a/shared/missing.h
|
||||
+++ b/shared/missing.h
|
||||
@@ -15,6 +15,13 @@
|
||||
# define MODULE_INIT_IGNORE_VERMAGIC 2
|
||||
#endif
|
||||
|
||||
+#ifndef MODULE_REPLACE_MODULE
|
||||
+# define MODULE_REPLACE_MODULE 0x1000
|
||||
+#else
|
||||
+_Static_assert(MODULE_REPLACE_MODULE == 0x1000,
|
||||
+ "MODULE_REPLACE_MODULE != 0x1000, change `KMOD_INSERT_REPLACE` and `KMOD_PROBE_REPLACE` defination");
|
||||
+#endif
|
||||
+
|
||||
#ifndef __NR_finit_module
|
||||
# define __NR_finit_module -1
|
||||
#endif
|
||||
diff --git a/tools/insmod.c b/tools/insmod.c
|
||||
index c422971..f0be196 100644
|
||||
--- a/tools/insmod.c
|
||||
+++ b/tools/insmod.c
|
||||
@@ -29,9 +29,10 @@
|
||||
|
||||
#include "kmod.h"
|
||||
|
||||
-static const char cmdopts_s[] = "psfVh";
|
||||
+static const char cmdopts_s[] = "psfVrh";
|
||||
static const struct option cmdopts[] = {
|
||||
{"version", no_argument, 0, 'V'},
|
||||
+ {"replace", no_argument, 0, 'r'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{NULL, 0, 0, 0}
|
||||
};
|
||||
@@ -42,6 +43,7 @@ static void help(void)
|
||||
"\t%s [options] filename [args]\n"
|
||||
"Options:\n"
|
||||
"\t-V, --version show version\n"
|
||||
+ "\t-r, --replace replace module\n"
|
||||
"\t-h, --help show this help\n",
|
||||
program_invocation_short_name);
|
||||
}
|
||||
@@ -90,6 +92,9 @@ static int do_insmod(int argc, char *argv[])
|
||||
case 'h':
|
||||
help();
|
||||
return EXIT_SUCCESS;
|
||||
+ case 'r':
|
||||
+ flags |= KMOD_INSERT_REPLACE;
|
||||
+ break;
|
||||
case 'V':
|
||||
puts(PACKAGE " version " VERSION);
|
||||
puts(KMOD_FEATURES);
|
||||
--
|
||||
2.31.1
|
||||
|
||||
91
Module-suspend-the-module-by-rmmod-r-option.patch
Normal file
91
Module-suspend-the-module-by-rmmod-r-option.patch
Normal file
@ -0,0 +1,91 @@
|
||||
From 6a31ae1b9bdd731ffa71c2aeb1ce13e979c194d1 Mon Sep 17 00:00:00 2001
|
||||
From: Ruidong Cao <caoruidong@huawei.com>
|
||||
Date: Fri, 25 Sep 2020 03:00:25 -0400
|
||||
Subject: [PATCH 2/2] Module: suspend the module by rmmod r option
|
||||
|
||||
Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
|
||||
Signed-off-by: fu.lin <fu.lin10@huawei.com>
|
||||
---
|
||||
libkmod/libkmod-module.c | 2 +-
|
||||
libkmod/libkmod.h | 3 +++
|
||||
shared/missing.h | 2 +-
|
||||
tools/rmmod.c | 7 ++++++-
|
||||
4 files changed, 11 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
|
||||
index a243672..70b633f 100644
|
||||
--- a/libkmod/libkmod-module.c
|
||||
+++ b/libkmod/libkmod-module.c
|
||||
@@ -790,7 +790,7 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod,
|
||||
return -ENOENT;
|
||||
|
||||
/* Filter out other flags and force ONONBLOCK */
|
||||
- flags &= KMOD_REMOVE_FORCE;
|
||||
+ flags &= KMOD_REMOVE_FORCE | KMOD_REMOVE_REPLACE;
|
||||
flags |= KMOD_REMOVE_NOWAIT;
|
||||
|
||||
err = delete_module(mod->name, flags);
|
||||
diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h
|
||||
index 241431e..bcdefc4 100644
|
||||
--- a/libkmod/libkmod.h
|
||||
+++ b/libkmod/libkmod.h
|
||||
@@ -142,6 +142,9 @@ struct kmod_module *kmod_module_get_module(const struct kmod_list *entry);
|
||||
enum kmod_remove {
|
||||
KMOD_REMOVE_FORCE = O_TRUNC,
|
||||
KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */
|
||||
+
|
||||
+ /* custom flag */
|
||||
+ KMOD_REMOVE_REPLACE = 0x1000,
|
||||
};
|
||||
|
||||
/* Insertion flags */
|
||||
diff --git a/shared/missing.h b/shared/missing.h
|
||||
index 4d2253b..19fb36f 100644
|
||||
--- a/shared/missing.h
|
||||
+++ b/shared/missing.h
|
||||
@@ -19,7 +19,7 @@
|
||||
# define MODULE_REPLACE_MODULE 0x1000
|
||||
#else
|
||||
_Static_assert(MODULE_REPLACE_MODULE == 0x1000,
|
||||
- "MODULE_REPLACE_MODULE != 0x1000, change `KMOD_INSERT_REPLACE` and `KMOD_PROBE_REPLACE` defination");
|
||||
+ "MODULE_REPLACE_MODULE != 0x1000, change `KMOD_INSERT_REPLACE`, `KMOD_REMOVE_REPLACE` and `KMOD_PROBE_REPLACE` defination");
|
||||
#endif
|
||||
|
||||
#ifndef __NR_finit_module
|
||||
diff --git a/tools/rmmod.c b/tools/rmmod.c
|
||||
index 3942e7b..1278234 100644
|
||||
--- a/tools/rmmod.c
|
||||
+++ b/tools/rmmod.c
|
||||
@@ -36,9 +36,10 @@
|
||||
static int verbose = DEFAULT_VERBOSE;
|
||||
static int use_syslog;
|
||||
|
||||
-static const char cmdopts_s[] = "fsvVwh";
|
||||
+static const char cmdopts_s[] = "frsvVwh";
|
||||
static const struct option cmdopts[] = {
|
||||
{"force", no_argument, 0, 'f'},
|
||||
+ {"replace", no_argument, 0, 'r'},
|
||||
{"syslog", no_argument, 0, 's'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
@@ -54,6 +55,7 @@ static void help(void)
|
||||
"\t-f, --force forces a module unload and may crash your\n"
|
||||
"\t machine. This requires Forced Module Removal\n"
|
||||
"\t option in your kernel. DANGEROUS\n"
|
||||
+ "\t-r, --replace replace module\n"
|
||||
"\t-s, --syslog print to syslog, not stderr\n"
|
||||
"\t-v, --verbose enables more messages\n"
|
||||
"\t-V, --version show version\n"
|
||||
@@ -120,6 +122,9 @@ static int do_rmmod(int argc, char *argv[])
|
||||
case 'f':
|
||||
flags |= KMOD_REMOVE_FORCE;
|
||||
break;
|
||||
+ case 'r':
|
||||
+ flags |= KMOD_REMOVE_REPLACE;
|
||||
+ break;
|
||||
case 's':
|
||||
use_syslog = 1;
|
||||
break;
|
||||
--
|
||||
2.31.1
|
||||
|
||||
31
don-t-check-module-s-refcnt-when-rmmod-with-r.patch
Normal file
31
don-t-check-module-s-refcnt-when-rmmod-with-r.patch
Normal file
@ -0,0 +1,31 @@
|
||||
From e48b7f950e8a6c8b6ba825a14a5aeb8a5064cdfc Mon Sep 17 00:00:00 2001
|
||||
From: Liu Chao <liuchao173@huawei.com>
|
||||
Date: Mon, 7 Jun 2021 06:46:49 +0000
|
||||
Subject: [PATCH] kmod: don't check module's refcnt when rmmod with -r
|
||||
|
||||
When we remove module that only kernel livepatches depend on it by
|
||||
remmod -r, we want to only invoke resume function. But kmod will check
|
||||
refcnt first, if refcnt is more than zero, kmod won't call kernel's
|
||||
delete_module.
|
||||
|
||||
Signed-off-by: Liu Chao <liuchao173@huawei.com>
|
||||
---
|
||||
tools/rmmod.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/tools/rmmod.c b/tools/rmmod.c
|
||||
index 1278234..1d8d20b 100644
|
||||
--- a/tools/rmmod.c
|
||||
+++ b/tools/rmmod.c
|
||||
@@ -178,7 +178,7 @@ static int do_rmmod(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
- if (!(flags & KMOD_REMOVE_FORCE) && check_module_inuse(mod) < 0) {
|
||||
+ if (!(flags & KMOD_REMOVE_FORCE) && !(flags & KMOD_REMOVE_REPLACE) && check_module_inuse(mod) < 0) {
|
||||
r++;
|
||||
goto next;
|
||||
}
|
||||
--
|
||||
2.23.0
|
||||
|
||||
10
kmod.spec
10
kmod.spec
@ -1,6 +1,6 @@
|
||||
Name: kmod
|
||||
Version: 27
|
||||
Release: 7
|
||||
Release: 8
|
||||
Summary: Kernel module management
|
||||
# GPLv2+ is used by programs, LGPLv2+ is used for libraries.
|
||||
License: GPLv2+ and LGPLv2+
|
||||
@ -22,6 +22,9 @@ Patch6009: backport-libkmod-fix-possible-double-free-with-wrong-modules.patch
|
||||
Patch6010: backport-libkmod-module-check-new_from_name-return-value-in-g.patch
|
||||
|
||||
Patch9000: bugfix-kmod-20-8-depmod-Don-t-unlinkat-orig-depfile-and-add-fsync.patch
|
||||
Patch9001: Module-replace-the-module-with-new-module.patch
|
||||
Patch9002: Module-suspend-the-module-by-rmmod-r-option.patch
|
||||
Patch9003: don-t-check-module-s-refcnt-when-rmmod-with-r.patch
|
||||
|
||||
BuildRequires: gcc chrpath zlib-devel xz-devel libxslt openssl-devel
|
||||
|
||||
@ -116,6 +119,11 @@ install -m 0644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/depmod.d/dist.conf
|
||||
%doc TODO NEWS README
|
||||
|
||||
%changelog
|
||||
* Mon Nov 29 2021 Yang Yanchao <yangyanchao6@huawei.com> - 27-8
|
||||
- kmod: don't check module's refcnt when rmmod with -r
|
||||
Module: replace the module with new module
|
||||
Module: suspend the module by rmmod r option
|
||||
|
||||
* Wed Nov 24 2021 Yang Yanchao <yangyanchao6@huawei.com> - 27-7
|
||||
- Precisely filters ko files in "/lib/modules/$kernel/extra"
|
||||
to avoid creating unnecessary symbols.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user