Whamcloud - gitweb
JBD2_HAS_COMPAT_FEATURE was used instead of JBD2_HAS_INCOMPAT_FEATURE for
[fs/lustre-release.git] / lustre / kernel_patches / patches / modpost_external_module_updates_sles9.patch
1 This patch updates the SLES 9 module build system to properly support
2 dependencies between external modules, similarly to the way they are
3 supported in newer kernels.
4
5 Index: linux-2.6.5-7.286/scripts/Makefile.modpost
6 ===================================================================
7 --- linux-2.6.5-7.286.orig/scripts/Makefile.modpost
8 +++ linux-2.6.5-7.286/scripts/Makefile.modpost
9 @@ -38,7 +38,8 @@ _modpost: __modpost
10  include .config
11  include scripts/Makefile.lib
12  
13 -symverfile := $(objtree)/Module.symvers
14 +kernelsymfile := $(objtree)/Module.symvers
15 +modulesymfile := $(KBUILD_EXTMOD)/Module.symvers
16  
17  # Step 1), find all modules listed in $(MODVERDIR)/
18  __modules := $(shell head -q -n1 /dev/null $(wildcard $(MODVERDIR)/*.mod))
19 @@ -51,7 +52,9 @@ _modpost: $(modules)
20  #  Includes step 3,4
21  quiet_cmd_modpost = MODPOST
22        cmd_modpost = scripts/modpost \
23 -       $(if $(KBUILD_EXTMOD),-i,-o) $(symverfile) \
24 +       $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
25 +       $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
26 +       $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
27         -s $(firstword $(wildcard $(dir $(MODVERDIR))/Module.supported \
28                                   $(objtree)/Module.supported /dev/null)) \
29         $(filter-out FORCE,$^)
30 Index: linux-2.6.5-7.286/scripts/modpost.c
31 ===================================================================
32 --- linux-2.6.5-7.286.orig/scripts/modpost.c
33 +++ linux-2.6.5-7.286/scripts/modpost.c
34 @@ -1,7 +1,8 @@
35  /* Postprocess module symbol versions
36   *
37   * Copyright 2003       Kai Germaschewski
38 - *           2002-2003  Rusty Russell, IBM Corporation
39 + *           2002-2004  Rusty Russell, IBM Corporation
40 + * Copyright 2006       Sam Ravnborg
41   *
42   * Based in part on module-init-tools/depmod.c,file2alias
43   *
44 @@ -18,6 +19,8 @@
45  int modversions = 0;
46  /* Warn about undefined symbols? (do so if we have vmlinux) */
47  int have_vmlinux = 0;
48 +/* If we are modposting external module set to 1 */
49 +static int external_module = 0;
50  
51  void
52  fatal(const char *fmt, ...)
53 @@ -45,6 +48,19 @@ warn(const char *fmt, ...)
54         va_end(arglist);
55  }
56  
57 +int
58 +is_vmlinux(const char *modname)
59 +{
60 +       const char *myname;
61 +
62 +       if ((myname = strrchr(modname, '/')))
63 +               myname++;
64 +       else
65 +               myname = modname;
66 +
67 +       return strcmp(myname, "vmlinux") == 0;
68 +}
69 +
70  void *do_nofail(void *ptr, const char *expr)
71  {
72         if (!ptr) {
73 @@ -101,6 +117,9 @@ struct symbol {
74         struct module *module;
75         unsigned int crc;
76         int crc_valid;
77 +       unsigned int vmlinux:1;    /* 1 if symbol is defined in vmlinux */
78 +       unsigned int kernel:1;     /* 1 if symbol is from kernel
79 +                                   *  (only for external modules) **/
80         char name[0];
81  };
82  
83 @@ -135,8 +154,8 @@ alloc_symbol(const char *name, struct sy
84  
85  /* For the hash of exported symbols */
86  
87 -void
88 -new_symbol(const char *name, struct module *module, unsigned int *crc)
89 +static struct symbol *
90 +new_symbol(const char *name, struct module *module)
91  {
92         unsigned int hash;
93         struct symbol *new;
94 @@ -144,10 +163,7 @@ new_symbol(const char *name, struct modu
95         hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
96         new = symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
97         new->module = module;
98 -       if (crc) {
99 -               new->crc = *crc;
100 -               new->crc_valid = 1;
101 -       }
102 +       return new;
103  }
104  
105  struct symbol *
106 @@ -168,19 +184,28 @@ find_symbol(const char *name)
107  
108  /* Add an exported symbol - it may have already been added without a
109   * CRC, in this case just update the CRC */
110 -void
111 -add_exported_symbol(const char *name, struct module *module, unsigned int *crc)
112 +static struct symbol *
113 +sym_add_exported(const char *name, struct module *mod)
114  {
115         struct symbol *s = find_symbol(name);
116  
117         if (!s) {
118 -               new_symbol(name, module, crc);
119 -               return;
120 -       }
121 -       if (crc) {
122 -               s->crc = *crc;
123 -               s->crc_valid = 1;
124 +               s = new_symbol(name, mod);
125         }
126 +       s->vmlinux   = is_vmlinux(mod->name);
127 +       s->kernel    = 0;
128 +       return s;
129 +}
130 +
131 +static void
132 +sym_update_crc(const char *name, struct module *mod, unsigned int crc)
133 +{
134 +       struct symbol *s = find_symbol(name);
135 +
136 +       if (!s)
137 +               s = new_symbol(name, mod);
138 +       s->crc = crc;
139 +       s->crc_valid = 1;
140  }
141  
142  void *
143 @@ -339,8 +364,7 @@ handle_modversions(struct module *mod, s
144                 /* CRC'd symbol */
145                 if (memcmp(symname, CRC_PFX, strlen(CRC_PFX)) == 0) {
146                         crc = (unsigned int) sym->st_value;
147 -                       add_exported_symbol(symname + strlen(CRC_PFX),
148 -                                           mod, &crc);
149 +                       sym_update_crc(symname + strlen(CRC_PFX), mod, crc);
150                         modversions = 1;
151                 }
152                 break;
153 @@ -372,26 +396,12 @@ handle_modversions(struct module *mod, s
154         default:
155                 /* All exported symbols */
156                 if (memcmp(symname, KSYMTAB_PFX, strlen(KSYMTAB_PFX)) == 0) {
157 -                       add_exported_symbol(symname + strlen(KSYMTAB_PFX),
158 -                                           mod, NULL);
159 +                       sym_add_exported(symname + strlen(KSYMTAB_PFX), mod);
160                 }
161                 break;
162         }
163  }
164  
165 -int
166 -is_vmlinux(const char *modname)
167 -{
168 -       const char *myname;
169 -
170 -       if ((myname = strrchr(modname, '/')))
171 -               myname++;
172 -       else
173 -               myname = modname;
174 -
175 -       return strcmp(myname, "vmlinux") == 0;
176 -}
177 -
178  static struct {
179         void *file;
180         unsigned long size;
181 @@ -451,12 +461,7 @@ read_symbols(char *modname)
182         /* When there's no vmlinux, don't print warnings about
183          * unresolved symbols (since there'll be too many ;) */
184         if (is_vmlinux(modname)) {
185 -               unsigned int fake_crc = 0;
186                 have_vmlinux = 1;
187 -               /* May not have this if !CONFIG_MODULE_UNLOAD: fake it.
188 -                  If it appears, we'll get the real CRC. */
189 -               add_exported_symbol("cleanup_module", mod, &fake_crc);
190 -               add_exported_symbol("struct_module", mod, &fake_crc);
191                 mod->skip = 1;
192         }
193  
194 @@ -499,12 +504,7 @@ buf_printf(struct buffer *buf, const cha
195         
196         va_start(ap, fmt);
197         len = vsnprintf(tmp, SZ, fmt, ap);
198 -       if (buf->size - buf->pos < len + 1) {
199 -               buf->size += 128;
200 -               buf->p = realloc(buf->p, buf->size);
201 -       }
202 -       strncpy(buf->p + buf->pos, tmp, len + 1);
203 -       buf->pos += len;
204 +       buf_write(buf, tmp, len);
205         va_end(ap);
206  }
207  
208 @@ -512,7 +512,7 @@ void
209  buf_write(struct buffer *buf, const char *s, int len)
210  {
211         if (buf->size - buf->pos < len) {
212 -               buf->size += len;
213 +               buf->size += len + SZ;
214                 buf->p = realloc(buf->p, buf->size);
215         }
216         strncpy(buf->p + buf->pos, s, len);
217 @@ -522,7 +522,7 @@ buf_write(struct buffer *buf, const char
218  /* Header for the generated file */
219  
220  void
221 -add_header(struct buffer *b)
222 +add_header(struct buffer *b, struct module *mod)
223  {
224         buf_printf(b, "#include <linux/module.h>\n");
225         buf_printf(b, "#include <linux/vermagic.h>\n");
226 @@ -676,8 +676,11 @@ read_supported(const char *fname)
227                 ; /* ignore error */
228  }
229  
230 +/* parse Module.symvers file. line format:
231 + * 0x12345678<tab>symbol<tab>module[<tab>something]
232 + **/
233  void
234 -read_dump(const char *fname)
235 +read_dump(const char *fname, unsigned int kernel)
236  {
237         unsigned long size, pos = 0;
238         void *file = grab_file(fname, &size);
239 @@ -691,6 +694,7 @@ read_dump(const char *fname)
240                 char *symname, *modname, *d;
241                 unsigned int crc;
242                 struct module *mod;
243 +                struct symbol *s;
244  
245                 if (!(symname = strchr(line, '\t')))
246                         goto fail;
247 @@ -712,13 +716,29 @@ read_dump(const char *fname)
248                         mod = new_module(NOFAIL(strdup(modname)));
249                         mod->skip = 1;
250                 }
251 -               add_exported_symbol(symname, mod, &crc);
252 +                s = sym_add_exported(symname, mod);
253 +               s->kernel    = kernel;
254 +               sym_update_crc(symname, mod, crc);
255         }
256         return;
257  fail:
258         fatal("parse error in symbol dump file\n");
259  }
260  
261 +/* For normal builds always dump all symbols.
262 + * For external modules only dump symbols
263 + * that are not read from kernel Module.symvers.
264 + **/
265 +static int
266 +dump_sym(struct symbol *sym)
267 +{
268 +       if (!external_module)
269 +               return 1;
270 +       if (sym->vmlinux || sym->kernel)
271 +               return 0;
272 +       return 1;
273 +}
274 +
275  void
276  write_dump(const char *fname)
277  {
278 @@ -729,15 +749,10 @@ write_dump(const char *fname)
279         for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
280                 symbol = symbolhash[n];
281                 while (symbol) {
282 -                       symbol = symbol->next;
283 -               }
284 -       }
285 -
286 -       for (n = 0; n < SYMBOL_HASH_SIZE ; n++) {
287 -               symbol = symbolhash[n];
288 -               while (symbol) {
289 -                       buf_printf(&buf, "0x%08x\t%s\t%s\n", symbol->crc,
290 -                               symbol->name, symbol->module->name);
291 +                       if (dump_sym(symbol))
292 +                               buf_printf(&buf, "0x%08x\t%s\t%s\n",
293 +                                       symbol->crc, symbol->name,
294 +                                       symbol->module->name);
295                         symbol = symbol->next;
296                 }
297         }
298 @@ -750,14 +765,19 @@ main(int argc, char **argv)
299         struct module *mod;
300         struct buffer buf = { };
301         char fname[SZ];
302 -       char *dump_read = NULL, *dump_write = NULL;
303 +       char *kernel_read = NULL, *module_read = NULL;
304 +       char *dump_write = NULL;
305         char *supp = NULL;
306         int opt;
307  
308 -       while ((opt = getopt(argc, argv, "i:o:s:")) != -1) {
309 +       while ((opt = getopt(argc, argv, "i:I:o:s:")) != -1) {
310                 switch(opt) {
311                         case 'i':
312 -                               dump_read = optarg;
313 +                               kernel_read = optarg;
314 +                               break;
315 +                       case 'I':
316 +                               module_read = optarg;
317 +                               external_module = 1;
318                                 break;
319                         case 'o':
320                                 dump_write = optarg;
321 @@ -773,8 +793,10 @@ main(int argc, char **argv)
322         if (supp)
323                 read_supported(supp);
324  
325 -       if (dump_read)
326 -               read_dump(dump_read);
327 +       if (kernel_read)
328 +               read_dump(kernel_read, 1);
329 +       if (module_read)
330 +               read_dump(module_read, 0);
331  
332         while (optind < argc) {
333                 read_symbols(argv[optind++]);
334 @@ -786,7 +808,7 @@ main(int argc, char **argv)
335  
336                 buf.pos = 0;
337  
338 -               add_header(&buf);
339 +               add_header(&buf, mod);
340                 add_supported_flag(&buf, mod);
341                 add_versions(&buf, mod);
342                 add_depends(&buf, mod, modules);