1 Star 0 Fork 28

openeuler-robot/kmod

forked from src-openEuler/kmod 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0002-Module-replace-the-module-with-new-module.patch 3.11 KB
一键复制 编辑 原始数据 按行查看 历史
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yang_yanchao/kmod.git
git@gitee.com:yang_yanchao/kmod.git
yang_yanchao
kmod
kmod
master

搜索帮助