Skip to content
  • Tejun Heo's avatar
    cgroup: move module ref handling into rebind_subsystems() · 1d5be6b2
    Tejun Heo authored
    
    
    Module ref handling in cgroup is rather weird.
    parse_cgroupfs_options() grabs all the modules for the specified
    subsystems.  A module ref is kept if the specified subsystem is newly
    bound to the hierarchy.  If not, or the operation fails, the refs are
    dropped.  This scatters module ref handling across multiple functions
    making it difficult to track.  It also make the function nasty to use
    for dynamic subsystem binding which is necessary for the planned
    unified hierarchy.
    
    There's nothing which requires the subsystem modules to be pinned
    between parse_cgroupfs_options() and rebind_subsystems() in both mount
    and remount paths.  parse_cgroupfs_options() can just parse and
    rebind_subsystems() can handle pinning the subsystems that it wants to
    bind, which is a natural part of its task - binding - anyway.
    
    Move module ref handling into rebind_subsystems() which makes the code
    a lot simpler - modules are gotten iff it's gonna be bound and put iff
    unbound or binding fails.
    
    v2: Li pointed out that if a controller module is unloaded between
        parsing and binding, rebind_subsystems() won't notice the missing
        controller as it only iterates through existing controllers.  Fix
        it by updating rebind_subsystems() to compare @added_mask to
        @pinned and fail with -ENOENT if they don't match.
    
    Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Acked-by: default avatarLi Zefan <lizefan@huawei.com>
    1d5be6b2