On Wed, Jul 24, 2024 at 09:57:05AM +0800, Youling Tang wrote:- It doesn't feel good to have only one subinit/exit in a file.
module_init(initfn)/module_exit(exitfn) has two definitions (via MODULE):Yes.
- 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.
This does not guarantee the order in which init will be executed (althoughHmm, so the normal built-in initcalls depend on the link order, but when
the init/exit order will remain the same)
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?