On 24/07/2024 23:43, Christoph Hellwig wrote:
On Wed, Jul 24, 2024 at 09:57:05AM +0800, Youling Tang wrote:
module_init(initfn)/module_exit(exitfn) has two definitions (via MODULE):
- buindin: uses do_initcalls() to iterate over the contents of the specified
section and executes all initfn functions in the section in the order in
which they are stored (exitfn is not required).
- ko: run do_init_module(mod)->do_one_initcall(mod->init) to execute initfn
of the specified module.
If we change module_subinit to something like this, not called in
module_init,
Not only do we want to ensure that exit is executed in reverse order of
init, but we also want to ensure the order of init.
Yes.
This does not guarantee the order in which init will be executed (although
the init/exit order will remain the same)
Hmm, so the normal built-in initcalls depend on the link order, but when
they are in the same file, the compiler can reorder them before we even
get to the linker.
I wonder what a good syntax would be to still avoid the boilerplate
code. We'd probably need one macro to actually define the init/exit
table in a single statement so that it can't be reordered, but that
would lose the ability to actually declare the module subinit/exit
handlers in multiple files, which really is the biggest win of this
scheme as it allows to keep the functions static instead of exposing
them to other compilation units.
And in fact even in your three converted file systems, most
subinit/exit handler are in separate files, so maybe instead
enforcing that there is just one per file and slightly refactoring
the code so that this is the case might be the best option?
- It doesn't feel good to have only one subinit/exit in a file.
Assuming that there is only one file in each file, how do we
ensure that the files are linked in order?(Is it sorted by *.o
in the Makefile?)
- Even if the order of each init is linked correctly, then the
runtime will be iterated through the .subinitcall.init section,
which executes each initfn in sequence (similar to do_initcalls),
which means that no other code can be inserted between each subinit.
If module_subinit is called in module_init, other code can be inserted
between subinit, similar to the following:
```
static int __init init_example(void)
{
module_subinit(inita, exita);
otherthing...
module_subinit(initb, exitb);
return 0;
}
module_init(init_example);
```
IMHO, module_subinit() might be better called in module_init().
Thanks,
Youling.