summaryrefslogtreecommitdiff
path: root/0002-Module-suspend-the-module-by-rmmod-r-option.patch
blob: d84410e0ff046dd3c86a74fc92b019e058ba2dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 3466b9698c4372ec81ed71384e1845898b7044d0 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 fd9861a..96f462a 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -846,7 +846,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 a56e5b4..78d11b3 100644
--- a/libkmod/libkmod.h
+++ b/libkmod/libkmod.h
@@ -147,6 +147,9 @@ enum kmod_remove {
 	KMOD_REMOVE_NOWAIT = O_NONBLOCK, /* always set */
 	/* libkmod-only defines, not passed to kernel */
 	KMOD_REMOVE_NOLOG = 1,
+
+	/* 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.35.1