tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Kernel modules - documentation?



On Sep 5,  6:12pm, Paul Goyette wrote:
}
} Is there any documentation on the modules interface or API?  There does 
} not seem to be anything in the man pages...

     I'm not aware of any.  Probably the best documentation for the
moment is src/sys/modules/example/example.c.  This is an example of a
very simple module, but it has all the pieces.  You might also want to
look at modctl(2), which is the syscall that modload/modstat/modunload
call.  I should probably add some cross references.

} My specific questions:
} 
} What actually triggers an autoload of a module?  (There seem to be very 
} few places where module_autoload() is called.)

     This depends on the type of module, i.e. filesystem modules are
handled differently from device driver modules.  Basically the part of
the kernel that needs functionality that might be provided by a module
needs to check to see if the functionality is currently available and
if it isn't, then it needs to call module_autoload() for the
appropriate module.

} What is the semantic difference between module_autoload() and a "normal" 
} module_load()?

     From the module's perspective, there is none.

     More generally, the kern.module.autoload sysctl will be checked to
see if module autoloading is allowed, there are restrictions on the
path passed to module_autoload(), and a timer will be kicked off to try
to automatically unload the module.

} Does the code which calls either of these routines need to be concerned 
} with whether the module has been previously loaded?  Is it OK to load a 
} module that has already been loaded?

     You will get EEXIST if the module is already loaded.  Also, if it
is a built-in module then autoload will fail.  It can only be reloaded
by doing 'modload -f <module>'.

} Given that there is a kernel thread that runs around and attempts to 
} unload any unreferenced modules that have been loaded "for a while", is 
} it ever necessary or desirable to explicitly unload a module?

     Code that autoloads a module doesn't need to worry about this.

} What happens if a global symbol referenced by a module doesn't exist? 
} Does the module get loaded anyway, leaving the reference unresolved?

     It will fail to link and thus will fail to load.  I don't know the
exact error that you will get off hand.  It was ENOENT, but there was
talk about changing it to ENOEXEC.  I will check on this, and if it
hasn't been done yet, I'll probably make the change.

}-- End of excerpt from Paul Goyette


Home | Main Index | Thread Index | Old Index