Annotation of /trunk/kmod/patches/0001-kmod-module-lookup-search-module.builtin-file-too.patch
Parent Directory | Revision Log
Revision 1659 -
(hide annotations)
(download)
Mon Feb 20 13:50:36 2012 UTC (12 years, 7 months ago) by niro
File size: 7132 byte(s)
Mon Feb 20 13:50:36 2012 UTC (12 years, 7 months ago) by niro
File size: 7132 byte(s)
-add upstream patch to search modules.builtin too
1 | niro | 1659 | From 3805274bf5e1e0acbd072ac7d523db8c8057130c Mon Sep 17 00:00:00 2001 |
2 | From: Lucas De Marchi <lucas.demarchi@profusion.mobi> | ||
3 | Date: Thu, 16 Feb 2012 20:43:16 -0200 | ||
4 | Subject: [PATCH] kmod-module: lookup: search modules.builtin file too | ||
5 | |||
6 | Search modules.builtin file before saying the module was not found. | ||
7 | Note: these "modules" should not appear as dependencies of other modules | ||
8 | (in modules.dep) even if they appear in modinfo. This fixes the return | ||
9 | code of modprobe with builtin modules. | ||
10 | |||
11 | Also fixes a small coding style issue in module_is_inkernel(). | ||
12 | --- | ||
13 | TODO | 3 --- | ||
14 | libkmod/libkmod-module.c | 24 ++++++++++++++++++++++-- | ||
15 | libkmod/libkmod-private.h | 2 ++ | ||
16 | libkmod/libkmod.c | 21 ++++++++++++++++++++- | ||
17 | libkmod/libkmod.h | 1 + | ||
18 | testsuite/test-modprobe.c | 1 - | ||
19 | 6 files changed, 45 insertions(+), 7 deletions(-) | ||
20 | |||
21 | diff --git a/TODO b/TODO | ||
22 | index 315878e..4aa6f7a 100644 | ||
23 | --- a/TODO | ||
24 | +++ b/TODO | ||
25 | @@ -49,9 +49,6 @@ Features: | ||
26 | * add quirk so we don't calculate dependencies for modules already loaded - | ||
27 | that shall fix the bug of vboxdrv and alsa above | ||
28 | |||
29 | -* search /lib/modules/$(uname -r)/modules.builtin.bin before returning error | ||
30 | - that module was not found | ||
31 | - | ||
32 | Known Bugs: | ||
33 | =========== | ||
34 | |||
35 | diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c | ||
36 | index 835896f..4226bbb 100644 | ||
37 | --- a/libkmod/libkmod-module.c | ||
38 | +++ b/libkmod/libkmod-module.c | ||
39 | @@ -80,6 +80,13 @@ struct kmod_module { | ||
40 | * whether the module's command and softdep should be ignored | ||
41 | */ | ||
42 | bool ignorecmd : 1; | ||
43 | + | ||
44 | + /* | ||
45 | + * if module was created by searching the modules.builtin file, this | ||
46 | + * is set. There's nothing much useful one can do with such a | ||
47 | + * "module", except knowing it's builtin. | ||
48 | + */ | ||
49 | + bool builtin : 1; | ||
50 | }; | ||
51 | |||
52 | static inline const char *path_join(const char *path, size_t prefixlen, | ||
53 | @@ -101,12 +108,13 @@ static inline const char *path_join(const char *path, size_t prefixlen, | ||
54 | static inline bool module_is_inkernel(struct kmod_module *mod) | ||
55 | { | ||
56 | int state = kmod_module_get_initstate(mod); | ||
57 | + | ||
58 | if (state == KMOD_MODULE_LIVE || | ||
59 | state == KMOD_MODULE_COMING || | ||
60 | state == KMOD_MODULE_BUILTIN) | ||
61 | return true; | ||
62 | - else | ||
63 | - return false; | ||
64 | + | ||
65 | + return false; | ||
66 | } | ||
67 | |||
68 | int kmod_module_parse_depline(struct kmod_module *mod, char *line) | ||
69 | @@ -191,6 +199,11 @@ void kmod_module_set_visited(struct kmod_module *mod, bool visited) | ||
70 | mod->visited = visited; | ||
71 | } | ||
72 | |||
73 | +void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) | ||
74 | +{ | ||
75 | + mod->builtin = builtin; | ||
76 | +} | ||
77 | + | ||
78 | /* | ||
79 | * Memory layout with alias: | ||
80 | * | ||
81 | @@ -526,6 +539,10 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx, | ||
82 | err = kmod_lookup_alias_from_aliases_file(ctx, alias, list); | ||
83 | CHECK_ERR_AND_FINISH(err, fail, list, finish); | ||
84 | |||
85 | + DBG(ctx, "lookup modules.builtin %s\n", alias); | ||
86 | + err = kmod_lookup_alias_from_builtin_file(ctx, alias, list); | ||
87 | + CHECK_ERR_AND_FINISH(err, fail, list, finish); | ||
88 | + | ||
89 | finish: | ||
90 | DBG(ctx, "lookup %s=%d, list=%p\n", alias, err, *list); | ||
91 | return err; | ||
92 | @@ -1593,6 +1610,9 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct kmod_module *mod) | ||
93 | if (mod == NULL) | ||
94 | return -ENOENT; | ||
95 | |||
96 | + if (mod->builtin) | ||
97 | + return KMOD_MODULE_BUILTIN; | ||
98 | + | ||
99 | pathlen = snprintf(path, sizeof(path), | ||
100 | "/sys/module/%s/initstate", mod->name); | ||
101 | fd = open(path, O_RDONLY|O_CLOEXEC); | ||
102 | diff --git a/libkmod/libkmod-private.h b/libkmod/libkmod-private.h | ||
103 | index 0ee37d4..ebda945 100644 | ||
104 | --- a/libkmod/libkmod-private.h | ||
105 | +++ b/libkmod/libkmod-private.h | ||
106 | @@ -81,6 +81,7 @@ int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name, struct | ||
107 | int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | ||
108 | int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | ||
109 | int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | ||
110 | +int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | ||
111 | int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name, struct kmod_list **list) __attribute__((nonnull(1, 2, 3))); | ||
112 | void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited) __attribute__((nonnull((1)))); | ||
113 | |||
114 | @@ -137,6 +138,7 @@ int kmod_module_parse_depline(struct kmod_module *mod, char *line) __attribute__ | ||
115 | void kmod_module_set_install_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); | ||
116 | void kmod_module_set_remove_commands(struct kmod_module *mod, const char *cmd) __attribute__((nonnull(1))); | ||
117 | void kmod_module_set_visited(struct kmod_module *mod, bool visited) __attribute__((nonnull(1))); | ||
118 | +void kmod_module_set_builtin(struct kmod_module *mod, bool builtin) __attribute__((nonnull((1)))); | ||
119 | |||
120 | /* libkmod-hash.c */ | ||
121 | |||
122 | diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c | ||
123 | index 4990d3e..36af201 100644 | ||
124 | --- a/libkmod/libkmod.c | ||
125 | +++ b/libkmod/libkmod.c | ||
126 | @@ -37,7 +37,7 @@ | ||
127 | |||
128 | #define KMOD_HASH_SIZE (256) | ||
129 | #define KMOD_LRU_MAX (128) | ||
130 | -#define _KMOD_INDEX_MODULES_SIZE KMOD_INDEX_MODULES_SYMBOL + 1 | ||
131 | +#define _KMOD_INDEX_MODULES_SIZE KMOD_INDEX_MODULES_BUILTIN + 1 | ||
132 | |||
133 | /** | ||
134 | * SECTION:libkmod | ||
135 | @@ -54,6 +54,7 @@ static struct _index_files { | ||
136 | [KMOD_INDEX_MODULES_DEP] = { .fn = "modules.dep", .prefix = "" }, | ||
137 | [KMOD_INDEX_MODULES_ALIAS] = { .fn = "modules.alias", .prefix = "alias " }, | ||
138 | [KMOD_INDEX_MODULES_SYMBOL] = { .fn = "modules.symbols", .prefix = "alias "}, | ||
139 | + [KMOD_INDEX_MODULES_BUILTIN] = { .fn = "modules.builtin", .prefix = ""}, | ||
140 | }; | ||
141 | |||
142 | static const char *default_config_paths[] = { | ||
143 | @@ -476,6 +477,24 @@ int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name, | ||
144 | name, list); | ||
145 | } | ||
146 | |||
147 | +int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name, | ||
148 | + struct kmod_list **list) | ||
149 | +{ | ||
150 | + const struct kmod_list *l; | ||
151 | + | ||
152 | + int err = kmod_lookup_alias_from_alias_bin(ctx, | ||
153 | + KMOD_INDEX_MODULES_BUILTIN, name, list); | ||
154 | + if (err < 0) | ||
155 | + return err; | ||
156 | + | ||
157 | + kmod_list_foreach(l, *list) { | ||
158 | + struct kmod_module *m = l->data; | ||
159 | + kmod_module_set_builtin(m, true); | ||
160 | + } | ||
161 | + | ||
162 | + return err; | ||
163 | +} | ||
164 | + | ||
165 | char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name) | ||
166 | { | ||
167 | struct index_file *idx; | ||
168 | diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h | ||
169 | index 6992e77..424640a 100644 | ||
170 | --- a/libkmod/libkmod.h | ||
171 | +++ b/libkmod/libkmod.h | ||
172 | @@ -69,6 +69,7 @@ enum kmod_index { | ||
173 | KMOD_INDEX_MODULES_DEP = 0, | ||
174 | KMOD_INDEX_MODULES_ALIAS, | ||
175 | KMOD_INDEX_MODULES_SYMBOL, | ||
176 | + KMOD_INDEX_MODULES_BUILTIN, | ||
177 | /* Padding to make sure enum is not mapped to char */ | ||
178 | _KMOD_INDEX_PAD = (1 << 31), | ||
179 | }; | ||
180 | diff --git a/testsuite/test-modprobe.c b/testsuite/test-modprobe.c | ||
181 | index 0022c06..3aebcae 100644 | ||
182 | --- a/testsuite/test-modprobe.c | ||
183 | +++ b/testsuite/test-modprobe.c | ||
184 | @@ -83,7 +83,6 @@ static __noreturn int modprobe_builtin(const struct test *t) | ||
185 | } | ||
186 | static DEFINE_TEST(modprobe_builtin, | ||
187 | .description = "check if modprobe return 0 for builtin", | ||
188 | - .expected_fail = true, | ||
189 | .config = { | ||
190 | [TC_UNAME_R] = "4.4.4", | ||
191 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-modprobe/builtin", | ||
192 | -- | ||
193 | 1.7.6.5 | ||
194 |