Re: how does kernel know?

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

 



On Fri, Oct 01, 2004 at 09:56:58AM +0500, Zeeshan Ali wrote:
> Hello,
> 
> > kernel can load modules as and when needed. For example, if you have
> > compiled the kernel making parport and parport_pc as modules; these modules
> > are not loaded at boot time (until configured to load at boot time by
> > /etc/modules). Whenever any application needs these modules, kernel loads
> > the modules first (using modprobe) and then applications can avail the
> > functionality provided by module.
> 
>    My question is HOW does it do it. If you had read my question
> carefully, then you should have realized that I already know that it
> is happening (rather I am seeing it happening) and now i am asking HOW
> does it do it.

	- A device node is opened (block or char, let's pick char for
	  now.)
	- The sys_open call in the kernel detects that this is a special
	  device node, and calls down into the char code to figure out
	  who gets the open call (this is done in fs/char_dev.c)
	- When the device is looked up in the kmap of all char majors,
	  the function base_probe() in char_dev.c is called by the kmap
	  core.
	- base_probe() creates a major/minor string based on the
	  requested major/minor number and calls request_module() with
	  that string.
	- request_module() is a real function only if CONFIG_KMOD is
	  selected as a build option.
	- request_module() (in kernel/kmod.c) builds up a userspace
	  environment list, and calls call_usermodehelper().
	- call_usermodehelper() calls out to userspace, and runs the
	  program /sbin/modprobe with the string of the major/minor
	  alias for the module being requested.
	- modprobe looks up all aliases of modules to try to find one
	  that matches this major/minor number and if it finds one, it
	  loads it into the kernel.

I hate this code, and want to rip it out of the kernel yesterday, as it
doesn't really work at all (think dynamic major/minor numbers, and the
sharing of major numbers by a wide range of different devices (like the
USB major or the Sound major.))

Oh, and if you use udev, none of this works at all, as the device node
isn't present in the first place, see the udev FAQ for more info about
this.

Hope this helps,

greg k-h

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux