Re: [PATCH 1/4] module: Add module_subinit{_noexit} and module_subeixt helper macros

From: Youling Tang
Date: Sun Jul 28 2024 - 23:02:15 EST


On 29/07/2024 10:44, Theodore Ts'o wrote:
On Mon, Jul 29, 2024 at 09:46:17AM +0800, Youling Tang wrote:
1. Previous version implementation: array mode (see link 1) :
   Advantages:
   - Few changes, simple principle, easy to understand code.
   Disadvantages:
   - Each modified module needs to maintain an array, more code.

2. Current implementation: explicit call subinit in initcall (see link 2) :
   Advantages:
   - Direct use of helpes macros, the subinit call sequence is
     intuitive, and the implementation is relatively simple.
   Disadvantages:
   - helper macros need to be implemented compared to array mode.

3. Only one module_subinit per file (not implemented, see link 3) :
   Advantage:
   - No need to display to call subinit.
   Disadvantages:
   - Magic order based on Makefile makes code more fragile,
   - Make sure that each file has only one module_subinit,
   - It is not intuitive to know which subinits the module needs
     and in what order (grep and Makefile are required),
   - With multiple subinits per module, it would be difficult to
     define module_{subinit, subexit} by MODULE, and difficult to
     rollback when initialization fails (I haven't found a good way
     to do this yet).


Personally, I prefer the implementation of method two.
But there's also method zero --- keep things the way they are, and
don't try to add a new astraction.

Advantage:

-- Code has worked for decades, so it is very well tested
-- Very easy to understand and maintain

Disadvantage

--- A few extra lines of C code.
The number of lines of code is not important, the main point is to
better ensure that subexit runs in the reverse order of subinit when
init fails.

Thanks,
Youling.


which we need to weigh against the other choices.

- Ted