diff --git a/0001-Remove-rmmod-w-documentation-and-getopt-entry.patch b/0001-Remove-rmmod-w-documentation-and-getopt-entry.patch index 55bb24b..f3a53f4 100644 --- a/0001-Remove-rmmod-w-documentation-and-getopt-entry.patch +++ b/0001-Remove-rmmod-w-documentation-and-getopt-entry.patch @@ -1,12 +1,13 @@ -From f81194e28e56dd57588edb5f19c5a3b1f38d1eb8 Mon Sep 17 00:00:00 2001 +From abf0e3b4ddb0c7348492309f8ccccdcafba91b2f Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Sun, 26 Jan 2014 18:00:23 -0200 -Subject: [PATCH 1/3] Remove "rmmod -w" documentation and getopt entry +Subject: [PATCH 01/10] Remove "rmmod -w" documentation and getopt entry This patch removes the cmdopts declaration and the documentation. They were leftover from the -w removal. -(cherry picked from commit a4bd1441e5c7e8903a9ae065801d4f06f13d06e9) +Patch-mainline: v17 +Git-commit: a4bd1441e5c7e8903a9ae065801d4f06f13d06e9 [mmarek: regenerated man/rmmod.8] --- man/rmmod.8 | 12 +----------- diff --git a/0002-modprobe-Recognize-allow-unsupported-modules-on-comm.patch b/0002-modprobe-Recognize-allow-unsupported-modules-on-comm.patch index ef5580d..9e0fa2f 100644 --- a/0002-modprobe-Recognize-allow-unsupported-modules-on-comm.patch +++ b/0002-modprobe-Recognize-allow-unsupported-modules-on-comm.patch @@ -1,13 +1,14 @@ -From 472b40d53f6a9121ade7b969151b5b14268d1172 Mon Sep 17 00:00:00 2001 +From 820ce4a006eeb230ee597e7565b17cec464ef15d Mon Sep 17 00:00:00 2001 From: Michal Marek Date: Wed, 26 Feb 2014 13:48:55 +0100 -Subject: [PATCH 2/3] modprobe: Recognize --allow-unsupported-modules on +Subject: [PATCH 02/10] modprobe: Recognize --allow-unsupported-modules on commandline The option does not do anything yet, but it does not return error either. References: fate#316971 +Patch-mainline: never --- tools/modprobe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/0003-libkmod-config-Recognize-allow_unsupported_modules-i.patch b/0003-libkmod-config-Recognize-allow_unsupported_modules-i.patch index a9a2c85..4c538f1 100644 --- a/0003-libkmod-config-Recognize-allow_unsupported_modules-i.patch +++ b/0003-libkmod-config-Recognize-allow_unsupported_modules-i.patch @@ -1,10 +1,11 @@ -From da1cb1dd16edb2533ac431793e5bb3d01b243cae Mon Sep 17 00:00:00 2001 +From 717e10547654bceebbcb84144be72a40d78e577a Mon Sep 17 00:00:00 2001 From: Michal Marek Date: Wed, 26 Feb 2014 13:53:38 +0100 -Subject: [PATCH 3/3] libkmod-config: Recognize allow_unsupported_modules in +Subject: [PATCH 03/10] libkmod-config: Recognize allow_unsupported_modules in the configuration References: fate#316971 +Patch-mainline: never --- libkmod/libkmod-config.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/0004-testsuite-Check-the-list-of-loaded-modules-after-a-t.patch b/0004-testsuite-Check-the-list-of-loaded-modules-after-a-t.patch new file mode 100644 index 0000000..9ac2182 --- /dev/null +++ b/0004-testsuite-Check-the-list-of-loaded-modules-after-a-t.patch @@ -0,0 +1,319 @@ +From 525e74c84547001548840f7a909350b366ed9b30 Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Thu, 27 Feb 2014 22:23:31 +0100 +Subject: [PATCH 04/10] testsuite: Check the list of loaded modules after a + test + +Add a ->modules_loaded member to struct test, which is a comma-separated +list of modules that should be present after the test finishes. Both +missing and excess modules cause an error. + +Patch-mainline: v17 +Git-commit: 88ac40840f0d13aaca844bb7198c252178968878 +--- + testsuite/test-init.c | 1 + + testsuite/test-modprobe.c | 13 +++- + testsuite/testsuite.c | 189 +++++++++++++++++++++++++++++++++++++++++++++- + testsuite/testsuite.h | 2 + + 4 files changed, 199 insertions(+), 6 deletions(-) + +diff --git a/testsuite/test-init.c b/testsuite/test-init.c +index 63b6501..d2aa4bd 100644 +--- a/testsuite/test-init.c ++++ b/testsuite/test-init.c +@@ -74,6 +74,7 @@ static DEFINE_TEST(test_insert, + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/", + [TC_INIT_MODULE_RETCODES] = "bla:1:20", + }, ++ .modules_loaded = "ext4", + .need_spawn = true); + + static noreturn int test_remove(const struct test *t) +diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c +index 637d363..c3ef31e 100644 +--- a/testsuite/test-modprobe.c ++++ b/testsuite/test-modprobe.c +@@ -91,7 +91,9 @@ static DEFINE_TEST(modprobe_show_alias_to_none, + }, + .output = { + .out = TESTSUITE_ROOTFS "test-modprobe/show-depends/correct-psmouse.txt", +- }); ++ }, ++ .modules_loaded = "", ++ ); + + + static noreturn int modprobe_builtin(const struct test *t) +@@ -131,7 +133,9 @@ static DEFINE_TEST(modprobe_softdep_loop, + [TC_UNAME_R] = "4.4.4", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/softdep-loop", + [TC_INIT_MODULE_RETCODES] = "", +- }); ++ }, ++ .modules_loaded = "btusb,bluetooth", ++ ); + + static noreturn int modprobe_install_cmd_loop(const struct test *t) + { +@@ -156,6 +160,7 @@ static DEFINE_TEST(modprobe_install_cmd_loop, + { "MODPROBE", ABS_TOP_BUILDDIR "/tools/modprobe" }, + { } + }, ++ .modules_loaded = "snd,snd-pcm", + ); + + static noreturn int modprobe_param_kcmdline(const struct test *t) +@@ -178,7 +183,9 @@ static DEFINE_TEST(modprobe_param_kcmdline, + }, + .output = { + .out = TESTSUITE_ROOTFS "test-modprobe/module-param-kcmdline/correct.txt", +- }); ++ }, ++ .modules_loaded = "", ++ ); + + + static const struct test *tests[] = { +diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c +index 9877a64..c29ca78 100644 +--- a/testsuite/testsuite.c ++++ b/testsuite/testsuite.c +@@ -20,6 +20,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -528,12 +529,189 @@ fail: + return true; + } + ++static int cmp_modnames(const void *m1, const void *m2) ++{ ++ const char *s1 = *(char *const *)m1; ++ const char *s2 = *(char *const *)m2; ++ int i; ++ ++ for (i = 0; s1[i] || s2[i]; i++) { ++ char c1 = s1[i], c2 = s2[i]; ++ if (c1 == '-') ++ c1 = '_'; ++ if (c2 == '-') ++ c2 = '_'; ++ if (c1 != c2) ++ return c1 - c2; ++ } ++ return 0; ++} ++ ++/* ++ * Store the expected module names in buf and return a list of pointers to ++ * them. ++ */ ++static const char **read_expected_modules(const struct test *t, ++ char **buf, int *count) ++{ ++ const char **res; ++ int len; ++ int i; ++ char *p; ++ ++ if (t->modules_loaded[0] == '\0') { ++ *count = 0; ++ *buf = NULL; ++ return NULL; ++ } ++ *buf = strdup(t->modules_loaded); ++ if (!*buf) { ++ *count = -1; ++ return NULL; ++ } ++ len = 1; ++ for (p = *buf; *p; p++) ++ if (*p == ',') ++ len++; ++ res = malloc(sizeof(char *) * len); ++ if (!res) { ++ perror("malloc"); ++ *count = -1; ++ free(*buf); ++ *buf = NULL; ++ return NULL; ++ } ++ i = 0; ++ res[i++] = *buf; ++ for (p = *buf; i < len; p++) ++ if (*p == ',') { ++ *p = '\0'; ++ res[i++] = p + 1; ++ } ++ *count = len; ++ return res; ++} ++ ++static char **read_loaded_modules(const struct test *t, char **buf, int *count) ++{ ++ char dirname[PATH_MAX]; ++ DIR *dir; ++ struct dirent *dirent; ++ int i; ++ int len = 0, bufsz; ++ char **res = NULL; ++ char *p; ++ const char *rootfs = t->config[TC_ROOTFS] ? t->config[TC_ROOTFS] : ""; ++ ++ /* Store the entries in /sys/module to res */ ++ if (snprintf(dirname, sizeof(dirname), "%s/sys/module", rootfs) ++ >= (int)sizeof(dirname)) { ++ ERR("rootfs path too long: %s\n", rootfs); ++ *buf = NULL; ++ len = -1; ++ goto out; ++ } ++ dir = opendir(dirname); ++ /* not an error, simply return empty list */ ++ if (!dir) { ++ *buf = NULL; ++ goto out; ++ } ++ bufsz = 0; ++ while ((dirent = readdir(dir))) { ++ if (dirent->d_name[0] == '.') ++ continue; ++ len++; ++ bufsz += strlen(dirent->d_name) + 1; ++ } ++ res = malloc(sizeof(char *) * len); ++ if (!res) { ++ perror("malloc"); ++ len = -1; ++ goto out_dir; ++ } ++ *buf = malloc(bufsz); ++ if (!*buf) { ++ perror("malloc"); ++ free(res); ++ res = NULL; ++ len = -1; ++ goto out_dir; ++ } ++ rewinddir(dir); ++ i = 0; ++ p = *buf; ++ while ((dirent = readdir(dir))) { ++ int size; ++ ++ if (dirent->d_name[0] == '.') ++ continue; ++ size = strlen(dirent->d_name) + 1; ++ memcpy(p, dirent->d_name, size); ++ res[i++] = p; ++ p += size; ++ } ++out_dir: ++ closedir(dir); ++out: ++ *count = len; ++ return res; ++} ++ ++static int check_loaded_modules(const struct test *t) ++{ ++ int l1, l2, i1, i2; ++ const char **a1; ++ char **a2; ++ char *buf1, *buf2; ++ int err = false; ++ ++ a1 = read_expected_modules(t, &buf1, &l1); ++ if (l1 < 0) ++ return err; ++ a2 = read_loaded_modules(t, &buf2, &l2); ++ if (l2 < 0) ++ goto out_a1; ++ qsort(a1, l1, sizeof(char *), cmp_modnames); ++ qsort(a2, l2, sizeof(char *), cmp_modnames); ++ i1 = i2 = 0; ++ err = true; ++ while (i1 < l1 || i2 < l2) { ++ int cmp; ++ ++ if (i1 >= l1) ++ cmp = 1; ++ else if (i2 >= l2) ++ cmp = -1; ++ else ++ cmp = cmp_modnames(&a1[i1], &a2[i2]); ++ if (cmp == 0) { ++ i1++; ++ i2++; ++ } else if (cmp < 0) { ++ err = false; ++ ERR("module %s not loaded\n", a1[i1]); ++ i1++; ++ } else { ++ err = false; ++ ERR("module %s is loaded but should not be \n", a2[i2]); ++ i2++; ++ } ++ } ++ free(a2); ++ free(buf2); ++out_a1: ++ free(a1); ++ free(buf1); ++ return err; ++} ++ + static inline int test_run_parent(const struct test *t, int fdout[2], + int fderr[2], int fdmonitor[2], pid_t child) + { + pid_t pid; + int err; +- bool matchout; ++ bool matchout, match_modules; + + /* Close write-fds */ + if (t->output.out != NULL) +@@ -578,16 +756,21 @@ static inline int test_run_parent(const struct test *t, int fdout[2], + + if (matchout) + matchout = check_generated_files(t); ++ if (t->modules_loaded) ++ match_modules = check_loaded_modules(t); ++ else ++ match_modules = true; + + if (t->expected_fail == false) { + if (err == 0) { +- if (matchout) ++ if (matchout && match_modules) + LOG("%sPASSED%s: %s\n", + ANSI_HIGHLIGHT_GREEN_ON, ANSI_HIGHLIGHT_OFF, + t->name); + else { +- ERR("%sFAILED%s: exit ok but outputs do not match: %s\n", ++ ERR("%sFAILED%s: exit ok but %s do not match: %s\n", + ANSI_HIGHLIGHT_RED_ON, ANSI_HIGHLIGHT_OFF, ++ matchout ? "loaded modules" : "outputs", + t->name); + err = EXIT_FAILURE; + } +diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h +index 97183cd..f2a75e5 100644 +--- a/testsuite/testsuite.h ++++ b/testsuite/testsuite.h +@@ -95,6 +95,8 @@ struct test { + */ + const struct keyval *files; + } output; ++ /* comma-separated list of loaded modules at the end of the test */ ++ const char *modules_loaded; + testfunc func; + const char *config[_TC_LAST]; + const char *path; +-- +1.8.4.5 + diff --git a/0005-testsuite-Add-test-for-modprobe-force.patch b/0005-testsuite-Add-test-for-modprobe-force.patch new file mode 100644 index 0000000..9fe5ae0 --- /dev/null +++ b/0005-testsuite-Add-test-for-modprobe-force.patch @@ -0,0 +1,59 @@ +From 5b532fd9616ba2a750e25378152bad4c9a2e7c27 Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Thu, 27 Feb 2014 22:34:24 +0100 +Subject: [PATCH 05/10] testsuite: Add test for modprobe --force + +There is no check if the correct flags are passed to finit_module, but +at least we cover the respective code path in kmod. + +Patch-mainline: v17 +Git-commit: 2ce5de0ae6c191920a4eeeab757ccfad092d9e0f +[mmarek: Dropped binary files from the patch] +--- + testsuite/test-modprobe.c | 23 +++++++++++++++++++++++ + 1 file changed, 23 insertions(+) + +diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c +index c3ef31e..92348b0 100644 +--- a/testsuite/test-modprobe.c ++++ b/testsuite/test-modprobe.c +@@ -187,6 +187,28 @@ static DEFINE_TEST(modprobe_param_kcmdline, + .modules_loaded = "", + ); + ++static noreturn int modprobe_force(const struct test *t) ++{ ++ const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; ++ const char *const args[] = { ++ progname, ++ "--force", "psmouse", ++ NULL, ++ }; ++ ++ test_spawn_prog(progname, args); ++ exit(EXIT_FAILURE); ++} ++static DEFINE_TEST(modprobe_force, ++ .description = "check modprobe --force", ++ .config = { ++ [TC_UNAME_R] = "4.4.4", ++ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/force", ++ [TC_INIT_MODULE_RETCODES] = "", ++ }, ++ .modules_loaded = "psmouse", ++ ); ++ + + static const struct test *tests[] = { + &smodprobe_show_depends, +@@ -196,6 +218,7 @@ static const struct test *tests[] = { + &smodprobe_softdep_loop, + &smodprobe_install_cmd_loop, + &smodprobe_param_kcmdline, ++ &smodprobe_force, + NULL, + }; + +-- +1.8.4.5 + diff --git a/0006-testsuite-Do-not-provide-finit_module-2-on-older-ker.patch b/0006-testsuite-Do-not-provide-finit_module-2-on-older-ker.patch new file mode 100644 index 0000000..90e24f4 --- /dev/null +++ b/0006-testsuite-Do-not-provide-finit_module-2-on-older-ker.patch @@ -0,0 +1,67 @@ +From 970b96f070b3f9ccd9c1850db44116a2b02da424 Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Thu, 27 Feb 2014 23:31:33 +0100 +Subject: [PATCH 06/10] testsuite: Do not provide finit_module(2) on older + kernels + +If the test's uname -r is less that 3.8, return -ENOSYS from +finit_module(), so that the fallback is tested. + +Patch-mainline: v17 +Git-commit: 063086e038657de64f9980bc51954b0817fa8e6c +--- + testsuite/init_module.c | 24 ++++++++++++++++++++++++ + 1 file changed, 24 insertions(+) + +diff --git a/testsuite/init_module.c b/testsuite/init_module.c +index 42177e7..269a471 100644 +--- a/testsuite/init_module.c ++++ b/testsuite/init_module.c +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + #include + + /* kmod_elf_get_section() is not exported, we need the private header */ +@@ -280,6 +281,25 @@ long init_module(void *mem, unsigned long len, const char *args) + return err; + } + ++static int check_kernel_version(int major, int minor) ++{ ++ struct utsname u; ++ const char *p; ++ int maj = 0, min = 0; ++ ++ if (uname(&u) < 0) ++ return false; ++ for (p = u.release; *p >= '0' && *p <= '9'; p++) ++ maj = maj * 10 + *p - '0'; ++ if (*p == '.') ++ for (p++; *p >= '0' && *p <= '9'; p++) ++ min = min * 10 + *p - '0'; ++ if (maj > major || (maj == major && min >= minor)) ++ return true; ++ return false; ++} ++ ++ + TS_EXPORT int finit_module(const int fd, const char *args, const int flags); + + int finit_module(const int fd, const char *args, const int flags) +@@ -289,6 +309,10 @@ int finit_module(const int fd, const char *args, const int flags) + unsigned long len; + struct stat st; + ++ if (!check_kernel_version(3, 8)) { ++ errno = ENOSYS; ++ return -1; ++ } + if (fstat(fd, &st) < 0) + return -1; + +-- +1.8.4.5 + diff --git a/0007-Add-some-tests-for-kernels-without-finit_module-2.patch b/0007-Add-some-tests-for-kernels-without-finit_module-2.patch new file mode 100644 index 0000000..ccdf949 --- /dev/null +++ b/0007-Add-some-tests-for-kernels-without-finit_module-2.patch @@ -0,0 +1,79 @@ +From 9a23dec3269fad1c4f03f6b9b4ceccedc136d4e2 Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Thu, 27 Feb 2014 23:33:38 +0100 +Subject: [PATCH 07/10] Add some tests for kernels without finit_module(2) + +Patch-mainline: v17 +Git-commit: be29c40e25b71d35708b9fad5772ebcd8e4685b3 +[mmarek: Dropped binary files from the patch] +--- + testsuite/test-modprobe.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 46 insertions(+) + +diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c +index 92348b0..b675f48 100644 +--- a/testsuite/test-modprobe.c ++++ b/testsuite/test-modprobe.c +@@ -209,6 +209,50 @@ static DEFINE_TEST(modprobe_force, + .modules_loaded = "psmouse", + ); + ++static noreturn int modprobe_oldkernel(const struct test *t) ++{ ++ const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; ++ const char *const args[] = { ++ progname, ++ "psmouse", ++ NULL, ++ }; ++ ++ test_spawn_prog(progname, args); ++ exit(EXIT_FAILURE); ++} ++static DEFINE_TEST(modprobe_oldkernel, ++ .description = "check modprobe --force", ++ .config = { ++ [TC_UNAME_R] = "3.3.3", ++ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel", ++ [TC_INIT_MODULE_RETCODES] = "", ++ }, ++ .modules_loaded = "psmouse", ++ ); ++ ++static noreturn int modprobe_oldkernel_force(const struct test *t) ++{ ++ const char *progname = ABS_TOP_BUILDDIR "/tools/modprobe"; ++ const char *const args[] = { ++ progname, ++ "--force", "psmouse", ++ NULL, ++ }; ++ ++ test_spawn_prog(progname, args); ++ exit(EXIT_FAILURE); ++} ++static DEFINE_TEST(modprobe_oldkernel_force, ++ .description = "check modprobe --force", ++ .config = { ++ [TC_UNAME_R] = "3.3.3", ++ [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/oldkernel-force", ++ [TC_INIT_MODULE_RETCODES] = "", ++ }, ++ .modules_loaded = "psmouse", ++ ); ++ + + static const struct test *tests[] = { + &smodprobe_show_depends, +@@ -219,6 +263,8 @@ static const struct test *tests[] = { + &smodprobe_install_cmd_loop, + &smodprobe_param_kcmdline, + &smodprobe_force, ++ &smodprobe_oldkernel, ++ &smodprobe_oldkernel_force, + NULL, + }; + +-- +1.8.4.5 + diff --git a/0008-libkmod-module-Simplify-kmod_module_insert_module.patch b/0008-libkmod-module-Simplify-kmod_module_insert_module.patch new file mode 100644 index 0000000..d92fb4b --- /dev/null +++ b/0008-libkmod-module-Simplify-kmod_module_insert_module.patch @@ -0,0 +1,95 @@ +From 40926774b6153bfd7f0321b3226323958bc4d81d Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Thu, 27 Feb 2014 11:32:22 +0100 +Subject: [PATCH 08/10] libkmod-module: Simplify kmod_module_insert_module() + +Store the file and elf pointer in the kmod_module structure and have it +freed together with the module. + +Patch-mainline: v17 +Git-commit: c2f4d85a9adea895958fc85b9b87ce95a7dc7774 +--- + libkmod/libkmod-module.c | 27 ++++++++++----------------- + 1 file changed, 10 insertions(+), 17 deletions(-) + +diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c +index 2f92e16..b94abd4 100644 +--- a/libkmod/libkmod-module.c ++++ b/libkmod/libkmod-module.c +@@ -791,8 +791,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + int err; + const void *mem; + off_t size; +- struct kmod_file *file; +- struct kmod_elf *elf = NULL; ++ struct kmod_elf *elf; + const char *path; + const char *args = options ? options : ""; + +@@ -805,13 +804,13 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + return -ENOSYS; + } + +- file = kmod_file_open(mod->ctx, path); +- if (file == NULL) { ++ mod->file = kmod_file_open(mod->ctx, path); ++ if (mod->file == NULL) { + err = -errno; + return err; + } + +- if (kmod_file_get_direct(file)) { ++ if (kmod_file_get_direct(mod->file)) { + unsigned int kernel_flags = 0; + + if (flags & KMOD_INSERT_FORCE_VERMAGIC) +@@ -819,19 +818,16 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + if (flags & KMOD_INSERT_FORCE_MODVERSION) + kernel_flags |= MODULE_INIT_IGNORE_MODVERSIONS; + +- err = finit_module(kmod_file_get_fd(file), args, kernel_flags); ++ err = finit_module(kmod_file_get_fd(mod->file), args, kernel_flags); + if (err == 0 || errno != ENOSYS) + goto init_finished; + } + +- size = kmod_file_get_size(file); +- mem = kmod_file_get_contents(file); +- + if (flags & (KMOD_INSERT_FORCE_VERMAGIC | KMOD_INSERT_FORCE_MODVERSION)) { +- elf = kmod_elf_new(mem, size); ++ elf = kmod_file_get_elf(mod->file); + if (elf == NULL) { + err = -errno; +- goto elf_failed; ++ return err; + } + + if (flags & KMOD_INSERT_FORCE_MODVERSION) { +@@ -847,7 +843,10 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + } + + mem = kmod_elf_get_memory(elf); ++ } else { ++ mem = kmod_file_get_contents(mod->file); + } ++ size = kmod_file_get_size(mod->file); + + err = init_module(mem, size, args); + init_finished: +@@ -855,12 +854,6 @@ init_finished: + err = -errno; + INFO(mod->ctx, "Failed to insert module '%s': %m\n", path); + } +- +- if (elf != NULL) +- kmod_elf_unref(elf); +-elf_failed: +- kmod_file_unref(file); +- + return err; + } + +-- +1.8.4.5 + diff --git a/0009-libkmod-Implement-filtering-of-unsupported-modules-o.patch b/0009-libkmod-Implement-filtering-of-unsupported-modules-o.patch new file mode 100644 index 0000000..3f57da9 --- /dev/null +++ b/0009-libkmod-Implement-filtering-of-unsupported-modules-o.patch @@ -0,0 +1,108 @@ +From 36bb8bc7f4100d7ffc4d6d0436e36e48fa7c075f Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Wed, 5 Mar 2014 14:40:14 +0100 +Subject: [PATCH 09/10] libkmod: Implement filtering of unsupported modules + (off by default) + +References: fate#316971 +Patch-mainline: never +--- + libkmod/libkmod-config.c | 12 ++++++++++-- + libkmod/libkmod-internal.h | 1 + + libkmod/libkmod-module.c | 31 +++++++++++++++++++++++++++++++ + 3 files changed, 42 insertions(+), 2 deletions(-) + +diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c +index 3950923..385a224 100644 +--- a/libkmod/libkmod-config.c ++++ b/libkmod/libkmod-config.c +@@ -663,8 +663,16 @@ static int kmod_config_parse(struct kmod_config *config, int fd, + ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n", + filename, cmd); + } else if (streq(cmd, "allow_unsupported_modules")) { +- /* dummy option for now */ +- ; ++ char *param = strtok_r(NULL, "\t ", &saveptr); ++ ++ if (param == NULL) ++ goto syntax_error; ++ if (streq(param, "yes") || streq(param, "1")) ++ config->block_unsupported = 0; ++ else if (streq(param, "no") || streq(param, "0")) ++ config->block_unsupported = 1; ++ else ++ goto syntax_error; + } else { + syntax_error: + ERR(ctx, "%s line %u: ignoring bad line starting with '%s'\n", +diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h +index 0180124..596db5d 100644 +--- a/libkmod/libkmod-internal.h ++++ b/libkmod/libkmod-internal.h +@@ -118,6 +118,7 @@ struct kmod_config { + struct kmod_list *softdeps; + + struct kmod_list *paths; ++ int block_unsupported; + }; + + int kmod_config_new(struct kmod_ctx *ctx, struct kmod_config **config, const char * const *config_paths) __attribute__((nonnull(1, 2,3))); +diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c +index b94abd4..ee52b97 100644 +--- a/libkmod/libkmod-module.c ++++ b/libkmod/libkmod-module.c +@@ -769,6 +769,24 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, + + extern long init_module(const void *mem, unsigned long len, const char *args); + ++static int check_module_supported(struct kmod_module *mod) ++{ ++ char **strings; ++ int i, count; ++ struct kmod_elf *elf; ++ ++ elf = kmod_file_get_elf(mod->file); ++ count = kmod_elf_get_strings(elf, ".modinfo", &strings); ++ if (count < 0) ++ return count; ++ for (i = 0; i < count; i++) ++ if (streq(strings[i], "supported=yes") || ++ streq(strings[i], "supported=external")) { ++ return 1; ++ } ++ return 0; ++} ++ + /** + * kmod_module_insert_module: + * @mod: kmod module +@@ -794,6 +812,7 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + struct kmod_elf *elf; + const char *path; + const char *args = options ? options : ""; ++ const struct kmod_config *config = kmod_get_config(mod->ctx); + + if (mod == NULL) + return -ENOENT; +@@ -810,6 +829,18 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, + return err; + } + ++ if (config->block_unsupported) { ++ err = check_module_supported(mod); ++ if (err < 0) ++ return err; ++ else if (err == 0) { ++ ERR(mod->ctx, "module '%s' is unsupported\n", mod->name); ++ ERR(mod->ctx, "Use --allow-unsupported or set allow_unsupported_modules 1 in\n"); ++ ERR(mod->ctx, "/etc/modprobe.d/10-unsupported-modules.conf\n"); ++ return -EPERM; ++ } ++ } ++ + if (kmod_file_get_direct(mod->file)) { + unsigned int kernel_flags = 0; + +-- +1.8.4.5 + diff --git a/0010-modprobe-Implement-allow-unsupported-modules.patch b/0010-modprobe-Implement-allow-unsupported-modules.patch new file mode 100644 index 0000000..164c9d5 --- /dev/null +++ b/0010-modprobe-Implement-allow-unsupported-modules.patch @@ -0,0 +1,102 @@ +From 714b9b5241f5fc6120c74f35d6a374e032bad6df Mon Sep 17 00:00:00 2001 +From: Michal Marek +Date: Wed, 5 Mar 2014 15:02:44 +0100 +Subject: [PATCH 10/10] modprobe: Implement --allow-unsupported-modules + +References: fate#316971 +Patch-mainline: never +--- + Makefile.am | 4 +++- + libkmod/libkmod-unsupported.c | 9 +++++++++ + libkmod/libkmod-unsupported.h | 8 ++++++++ + tools/modprobe.c | 7 ++++++- + 4 files changed, 26 insertions(+), 2 deletions(-) + create mode 100644 libkmod/libkmod-unsupported.c + create mode 100644 libkmod/libkmod-unsupported.h + +diff --git a/Makefile.am b/Makefile.am +index 46b7652..9986730 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -78,7 +78,9 @@ libkmod_libkmod_la_LIBADD = libkmod/libkmod-util.la \ + ${liblzma_LIBS} ${zlib_LIBS} + + noinst_LTLIBRARIES += libkmod/libkmod-internal.la +-libkmod_libkmod_internal_la_SOURCES = $(libkmod_libkmod_la_SOURCES) ++libkmod_libkmod_internal_la_SOURCES = $(libkmod_libkmod_la_SOURCES) \ ++ libkmod/libkmod-unsupported.c \ ++ libkmod/libkmod-unsupported.h + libkmod_libkmod_internal_la_LDFLAGS = $(AM_LDFLAGS) \ + -Wl,--version-script=$(top_srcdir)/libkmod/libkmod.sym + libkmod_libkmod_internal_la_DEPENDENCIES = $(libkmod_libkmod_la_DEPENDENCIES) +diff --git a/libkmod/libkmod-unsupported.c b/libkmod/libkmod-unsupported.c +new file mode 100644 +index 0000000..7ef9fc8 +--- /dev/null ++++ b/libkmod/libkmod-unsupported.c +@@ -0,0 +1,9 @@ ++#include "libkmod-internal.h" ++#include "libkmod-unsupported.h" ++ ++void kmod_internal_allow_unsupported(struct kmod_ctx *ctx) ++{ ++ struct kmod_config *config = (struct kmod_config *)kmod_get_config(ctx); ++ ++ config->block_unsupported = 0; ++} +diff --git a/libkmod/libkmod-unsupported.h b/libkmod/libkmod-unsupported.h +new file mode 100644 +index 0000000..a95b4a2 +--- /dev/null ++++ b/libkmod/libkmod-unsupported.h +@@ -0,0 +1,8 @@ ++#pragma once ++ ++/* ++ * This function implements the --allow-unsupported-modules modprobe ++ * option. It is not part of the kmod API and not exported by the shared ++ * library ++ */ ++void kmod_internal_allow_unsupported(struct kmod_ctx *ctx); +diff --git a/tools/modprobe.c b/tools/modprobe.c +index 589cc07..7d0949d 100644 +--- a/tools/modprobe.c ++++ b/tools/modprobe.c +@@ -33,6 +33,7 @@ + + #include "libkmod.h" + #include "libkmod-array.h" ++#include "libkmod-unsupported.h" + #include "macro.h" + + #include "kmod.h" +@@ -755,6 +756,7 @@ static int do_modprobe(int argc, char **orig_argv) + int do_remove = 0; + int do_show_config = 0; + int do_show_modversions = 0; ++ int allow_unsupported = 0; + int err; + + argv = prepend_options_from_env(&argc, orig_argv); +@@ -838,7 +840,7 @@ static int do_modprobe(int argc, char **orig_argv) + kversion = optarg; + break; + case 128: +- /* --allow-unsupported-modules does nothing for now */ ++ allow_unsupported = 1; + break; + case 's': + env_modprobe_options_append("-s"); +@@ -910,6 +912,9 @@ static int do_modprobe(int argc, char **orig_argv) + + log_setup_kmod_log(ctx, verbose); + ++ if (allow_unsupported) ++ kmod_internal_allow_unsupported(ctx); ++ + kmod_load_resources(ctx); + + if (do_show_config) +-- +1.8.4.5 + diff --git a/kmod.changes b/kmod.changes index 5017d89..7e1c20c 100644 --- a/kmod.changes +++ b/kmod.changes @@ -1,3 +1,15 @@ +------------------------------------------------------------------- +Wed Mar 5 14:50:34 UTC 2014 - mmarek@suse.cz + +- testsuite: Check the list of loaded modules after a test +- testsuite: Add test for modprobe --force +- testsuite: Do not provide finit_module(2) on older kernels +- Add some tests for kernels without finit_module(2) +- libkmod-module: Simplify kmod_module_insert_module() +- libkmod: Implement filtering of unsupported modules (fate#316971) +- modprobe: Implement --allow-unsupported-modules (fate#316971) +- make the %check section fatal + ------------------------------------------------------------------- Wed Feb 26 13:23:41 UTC 2014 - mmarek@suse.cz diff --git a/kmod.spec b/kmod.spec index 26e328a..6259db6 100644 --- a/kmod.spec +++ b/kmod.spec @@ -30,9 +30,18 @@ Url: http://www.jonmasters.org/blog/2011/12/20/libkmod-replaces-modul #Git-Clone: git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod Source: ftp://ftp.kernel.org/pub/linux/utils/kernel/kmod/%name-%version.tar.xz Source2: ftp://ftp.kernel.org/pub/linux/utils/kernel/kmod/%name-%version.tar.sign +# Files that would have been added by patches 5 and 7 +Source3: test-files.tar.xz Patch1: 0001-Remove-rmmod-w-documentation-and-getopt-entry.patch Patch2: 0002-modprobe-Recognize-allow-unsupported-modules-on-comm.patch Patch3: 0003-libkmod-config-Recognize-allow_unsupported_modules-i.patch +Patch4: 0004-testsuite-Check-the-list-of-loaded-modules-after-a-t.patch +Patch5: 0005-testsuite-Add-test-for-modprobe-force.patch +Patch6: 0006-testsuite-Do-not-provide-finit_module-2-on-older-ker.patch +Patch7: 0007-Add-some-tests-for-kernels-without-finit_module-2.patch +Patch8: 0008-libkmod-module-Simplify-kmod_module_insert_module.patch +Patch9: 0009-libkmod-Implement-filtering-of-unsupported-modules-o.patch +Patch10: 0010-modprobe-Implement-allow-unsupported-modules.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: autoconf BuildRequires: automake @@ -101,11 +110,18 @@ in %lname. %prep %{?gpg_verify: xz -dk "%{S:0}"; %gpg_verify %{S:2}} -%setup -q +%setup -q -a 3 %patch1 -p1 touch man/rmmod.8 %patch2 -p1 %patch3 -p1 +%patch4 -p1 +%patch5 -p1 +%patch6 -p1 +%patch7 -p1 +%patch8 -p1 +%patch9 -p1 +%patch10 -p1 %build autoreconf -fi @@ -159,7 +175,7 @@ ln -s "%_libdir/libkmod.so.2.2.6" "$b/%_lib/"; %endif %check -make check V=1 || :; +make check %post -n %lname -p /sbin/ldconfig diff --git a/test-files.tar.xz b/test-files.tar.xz new file mode 100644 index 0000000..94e8b8f --- /dev/null +++ b/test-files.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71f16a0d75d3c1cff13c6eb7bf490f4fa59020d4b11b8eed3a8635b020fa162a +size 26776