Skip to content

Commit 94892d6

Browse files
mdouchapevik
authored andcommitted
lib: Add helper function for reloading kernel modules
Link: https://lore.kernel.org/ltp/[email protected]/ Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent 98da818 commit 94892d6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/tst_module.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ static inline void tst_requires_module_signature_disabled(void)
4747
tst_requires_module_signature_disabled_();
4848
}
4949

50+
void tst_modprobe(const char *mod_name, char *const argv[]);
51+
void tst_module_reload(const char *mod_name, char *const argv[]);
52+
5053
#endif /* TST_MODULE_H */

lib/tst_module.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,31 @@ void tst_requires_module_signature_disabled_(void)
146146
if (tst_module_signature_enforced_())
147147
tst_brkm(TCONF, NULL, "module signature is enforced, skip test");
148148
}
149+
150+
void tst_modprobe(const char *mod_name, char *const argv[])
151+
{
152+
const int offset = 2; /* command name & module path */
153+
int i, size = 0;
154+
155+
while (argv && argv[size])
156+
++size;
157+
size += offset;
158+
159+
const char *mod_argv[size + 1]; /* + NULL in the end */
160+
161+
mod_argv[size] = NULL;
162+
mod_argv[0] = "modprobe";
163+
mod_argv[1] = mod_name;
164+
165+
for (i = offset; i < size; ++i)
166+
mod_argv[i] = argv[i - offset];
167+
168+
tst_cmd(NULL, mod_argv, NULL, NULL, 0);
169+
}
170+
171+
void tst_module_reload(const char *mod_name, char *const argv[])
172+
{
173+
tst_resm(TINFO, "Reloading kernel module %s", mod_name);
174+
tst_module_unload_(NULL, mod_name);
175+
tst_modprobe(mod_name, argv);
176+
}

0 commit comments

Comments
 (0)