Skip to contentSkip to conversation

module-init-tools/udev and module auto-loading

DISCUSSION Martin Schlemmer 5 participants 17 messages Feb 1, 2004 – Feb 4, 2004 VFS

lore
Share & tools
lore
#0 lore raw

Hi

A quick question on module-init-tools/udev and module auto-loading ... lets say I have a module called 'foo', that I want the kernel to auto-load.

If I now have in modprobe.conf:

--
alias char-major-<foo_major>-* foo
alias /dev/foo foo
--

and /dev/foo exists, it works just fine. If I delete /dev/foo however, it does not. Say the module _do_ support sysfs (meaning udev will create /dev/foo on loading, this do not really affect things, as without /dev/foo it do not work anyhow.

This a known issue (sure I know I can add it to local initscript to load, but this is not always the preferred 'fix')? Any ideas on how to 'fix' this?

Then a distant related issue - anybody thought about dynamic major numbers of 2.7/2.8 (?) and the 'alias char-major-<whatever>-* whatever' type modprobe rules (as the whole fact of them being dynamic, will make that alias type worthless ...)?

Thanks,

Signature · 1 line
Martin Schlemmer
#1 lore raw

In message <[email protected]> you write:

Quoted 3 lines

A quick question on module-init-tools/udev and module auto-loading ... lets say I have a module called 'foo', that I want the kernel to auto-load.

The *idea* of udev et al is that the kernel finds the devices, /sbin/hotplug loads the driver etc.

This does not cover the class of things which are entirely created by the driver (eg. dummy devices, socket families), so cannot be "detected". Many of these (eg. socket families) can be handled by explicit request_module() in the core and MODULE_ALIAS in the driver. Some of them cannot at the moment: the first the kernel knows of them is an attempt to open the device. Some variant of devfs would solve this.

Quoted 4 lines

Then a distant related issue - anybody thought about dynamic major numbers of 2.7/2.8 (?) and the 'alias char-major-<whatever>-* whatever' type modprobe rules (as the whole fact of them being dynamic, will make that alias type worthless ...)?

Yes. This could be changed to probe by device name, not number though. And most names can't be dynamic: /dev/null has certain, fixed semantics.

The "I found this hardware, who will drive it?" mechanism of udev, and the "User asked for this, who will supply it?" mechanism of kmod have some overlap, but I think both will end up being required.

Cheers,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#2 lore raw
Quoted 8 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 3 lines

A quick question on module-init-tools/udev and module auto-loading ... lets say I have a module called 'foo', that I want the kernel to auto-load.

The *idea* of udev et al is that the kernel finds the devices, /sbin/hotplug loads the driver etc.

Right.

Quoted 8 lines

This does not cover the class of things which are entirely created by the driver (eg. dummy devices, socket families), so cannot be "detected". Many of these (eg. socket families) can be handled by explicit request_module() in the core and MODULE_ALIAS in the driver. Some of them cannot at the moment: the first the kernel knows of them is an attempt to open the device. Some variant of devfs would solve this.

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

Understand me correctly, I do not want devfs back. I am just checking if we could do something for similar behaviour. I know it has not _really_ hit the lists, but I have already had complaints about this not being supported anymore. I think the complaints will start even more if raminitfs eventually hits functionality (as /dev will then be then consisting only of loaded drivers (if I am not mistaken).

Once again I do not say we should give in to it, but it _does_ make things easier. So if there is a lightweight way to do this, then great - and this is what I was trying to get discussion directed to.

Quoted 5 lines
Quoted 4 lines

Then a distant related issue - anybody thought about dynamic major numbers of 2.7/2.8 (?) and the 'alias char-major-<whatever>-* whatever' type modprobe rules (as the whole fact of them being dynamic, will make that alias type worthless ...)?

Quoted 8 lines

Yes. This could be changed to probe by device name, not number though. And most names can't be dynamic: /dev/null has certain, fixed semantics.

The "I found this hardware, who will drive it?" mechanism of udev, and the "User asked for this, who will supply it?" mechanism of kmod have some overlap, but I think both will end up being required.

Ok, was just wondering.

Thanks,

Signature · 1 line
Martin Schlemmer
#3 lore raw

In message <[email protected]> you write:

Quoted 9 lines
Quoted 8 lines

This does not cover the class of things which are entirely created by the driver (eg. dummy devices, socket families), so cannot be "detected". Many of these (eg. socket families) can be handled by explicit request_module() in the core and MODULE_ALIAS in the driver. Some of them cannot at the moment: the first the kernel knows of them is an attempt to open the device. Some variant of devfs would solve this.

Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

I think it's an excellent idea, although ideally we would have this mechanism in userspace as much as possible. Anything from some special hack to block -ENOENT on directory lookups and notify an fd, to some exotic overlay filesystem.

I'm sure Al Viro has an opinion on this...

Cheers,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#4 lore raw
Quoted 10 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 9 lines
Quoted 8 lines

This does not cover the class of things which are entirely created by the driver (eg. dummy devices, socket families), so cannot be "detected". Many of these (eg. socket families) can be handled by explicit request_module() in the core and MODULE_ALIAS in the driver. Some of them cannot at the moment: the first the kernel knows of them is an attempt to open the device. Some variant of devfs would solve this.

Quoted 9 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

I think it's an excellent idea, although ideally we would have this mechanism in userspace as much as possible. Anything from some special hack to block -ENOENT on directory lookups and notify an fd, to some exotic overlay filesystem.

I was thinking of just delaying the failure or such, depending on the modprobe outcome. Should not be much if any overhead, although I have not looked at the code.

Signature · 1 line
Martin Schlemmer
#5 lore raw
In reply to Rusty Russell
Quoted 10 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 9 lines
Quoted 8 lines

This does not cover the class of things which are entirely created by the driver (eg. dummy devices, socket families), so cannot be "detected". Many of these (eg. socket families) can be handled by explicit request_module() in the core and MODULE_ALIAS in the driver. Some of them cannot at the moment: the first the kernel knows of them is an attempt to open the device. Some variant of devfs would solve this.

Quoted 9 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

I think it's an excellent idea, although ideally we would have this mechanism in userspace as much as possible. Anything from some special hack to block -ENOENT on directory lookups and notify an fd, to some exotic overlay filesystem.

Something like attached. Besides me not knowing if there is a better place for it, it have the following issues:

1) Its a bit racy - iow, I get this (but only for urandom):

request_module: runaway loop modprobe /dev/urandom

I am not sure if its the kthread patches with the one for kthread use in modules that contributes to this (have not checked yet).

2) Although it does work (load the right module), it seems to do it too late. I have removed the sleep in udev, so it cannot be this. I do not know if this might be another kthread contribution (if I understand the module/kthread patches correctly). It does seem from the request_module code though that it 'should' wait for modprobe to complete ... Maybe add some sort of locking (this be efficient?)?

3) Might be nice to keep track of "/dev/foo" 'aliases' that modprobe fails for, and not try them again.

4) It only works if the whatever opened's name start with "/dev/", but I do not think that is an issue, as it should (?) be how most things access nodes, and should minimise complexity.

I know its very basic, I just thought to get something out of the door for discussion and to give direction (or what direction not to take ...).

Thanks,

Signature · 1 line
Martin Schlemmer
fs/namei.c +18 -3
@@ -1240,7 +1240,7 @@ int open_namei(const char * pathname, in
 	int acc_mode, error = 0;
 	struct dentry *dentry;
 	struct dentry *dir;
-	int count = 0;
+	int count = 0, retry = 0;
 
 	acc_mode = ACC_MODE(flag);
 
@@ -1253,13 +1253,14 @@ int open_namei(const char * pathname, in
 	nd->intent.open.flags = flag;
 	nd->intent.open.create_mode = mode;
 
+retry_open:
 	/*
 	 * The simplest case - just a plain lookup.
 	 */
 	if (!(flag & O_CREAT)) {
 		error = path_lookup(pathname, lookup_flags(flag)|LOOKUP_OPEN, nd);
 		if (error)
-			return error;
+			goto error;
 		dentry = nd->dentry;
 		goto ok;
 	}
@@ -1269,7 +1270,7 @@ int open_namei(const char * pathname, in
 	 */
 	error = path_lookup(pathname, LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE, nd);
 	if (error)
-		return error;
+		goto error;
 
 	/*
 	 * We have the parent and last component. First of all, check
@@ -1343,8 +1344,22 @@ ok:
 exit_dput:
 	dput(dentry);
 exit:
+	if (error != 0 && strstr(pathname, "/dev/") == pathname && !retry) {
+		if (request_module(pathname) == 0) {
+			retry = 1;
+			goto retry_open;
+		}
+	}
 	path_release(nd);
 	return error;
+error:
+	if (error != 0 && strstr(pathname, "/dev/") == pathname && !retry) {
+		if (request_module(pathname) == 0) {
+			retry = 1;
+			goto retry_open;
+		}
+	}
+	return error;
 
 do_link:
 	error = -ELOOP;
#6 lore raw
Quoted 3 lines · Martin Schlemmer
Quoted 3 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

Vetoed. _Especially_ when you are checking that on "pathname prefix" level - namei.c is not a place for such special-casing.

#7 lore raw
Quoted 8 lines · On Tue, 2004-02-03 at 21:33, [email protected] wrote:
Quoted 3 lines · Martin Schlemmer
Quoted 3 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

Vetoed. _Especially_ when you are checking that on "pathname prefix" level - namei.c is not a place for such special-casing.

Well, I do not scratch around in there in general. I guess the question is:

1) This this idea is Ok to make it (not patch or where it is, but the idea in general.

2) If yes to 1), any suggested place I should have a look at?

Thanks,

Signature · 1 line
Martin Schlemmer
#8 lore raw
Quoted 11 lines · Martin Schlemmer
Quoted 8 lines · On Tue, 2004-02-03 at 21:33, [email protected] wrote:
Quoted 3 lines · Martin Schlemmer
Quoted 3 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

Vetoed. _Especially_ when you are checking that on "pathname prefix" level - namei.c is not a place for such special-casing.

Quoted 5 lines

Well, I do not scratch around in there in general. I guess the question is:

1) This this idea is Ok to make it (not patch or where it is, but the idea in general.

It is not. Consider the effect of cd /dev followed by lookups. Do you really want a different behaviour in that case? Ditto for use of symlinks, yadda, yadda.

#9 lore raw
Quoted 15 lines · On Tue, 2004-02-03 at 22:53, [email protected] wrote:
Quoted 14 lines · Martin Schlemmer
Quoted 8 lines · On Tue, 2004-02-03 at 21:33, [email protected] wrote:
Quoted 3 lines · Martin Schlemmer
Quoted 3 lines
Quoted 3 lines

I guess there will be cries of murder if 'somebody' suggested that if a node in /dev is opened, but not there, the kernel can call 'modprobe -q /dev/foo' to load whatever alias there might have been?

Vetoed. _Especially_ when you are checking that on "pathname prefix" level - namei.c is not a place for such special-casing.

Well, I do not scratch around in there in general. I guess the question is:

Quoted 6 lines
Quoted 2 lines

1) This this idea is Ok to make it (not patch or where it is, but the idea in general.

It is not. Consider the effect of cd /dev followed by lookups. Do you really want a different behaviour in that case? Ditto for use of symlinks, yadda, yadda.

Any other ideas for the problem in general? =)

Thanks,

Signature · 1 line
Martin Schlemmer
#10 lore raw
In reply to Martin Schlemmer

In message <[email protected]> you write:

Quoted 7 lines
Quoted 4 lines

I think it's an excellent idea, although ideally we would have this mechanism in userspace as much as possible. Anything from some special hack to block -ENOENT on directory lookups and notify an fd, to some exotic overlay filesystem.

Something like attached. Besides me not knowing if there is a better place for it, it have the following issues:

Dude, you're brave. I mean, really, really brave.

However, it strikes me that the automounter does similar tricks, and so a similar setup should be possible for /dev.

Al? Suggestions appreciated?

Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#11 lore raw
Quoted 9 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 7 lines
Quoted 4 lines

I think it's an excellent idea, although ideally we would have this mechanism in userspace as much as possible. Anything from some special hack to block -ENOENT on directory lookups and notify an fd, to some exotic overlay filesystem.

Something like attached. Besides me not knowing if there is a better place for it, it have the following issues:

Quoted 6 lines

Dude, you're brave. I mean, really, really brave.

However, it strikes me that the automounter does similar tricks, and so a similar setup should be possible for /dev.

Al? Suggestions appreciated?

<shrug> If you want to mount autofs on /dev, more power to you. However, it got to be explicit "I mount <this> at /dev" - _anything_ based on "if pathname starts with /dev, it's special" is FUBAR.

#12 lore raw

In message <[email protected]> you write:

Quoted 3 lines

<shrug> If you want to mount autofs on /dev, more power to you. However, it got to be explicit "I mount <this> at /dev" - _anything_ based on "if pathname starts with /dev, it's special" is FUBAR.

Having a process say "tell me when something non-existent under this dir gets accessed" seems to be what is desired. And (from my v. limited understanding) autofs comes close already, yes?

That at least gives Martin somewhere to start...
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#13 lore raw
In reply to Martin Schlemmer
Quoted 5 lines · Martin Schlemmer

Hi

A quick question on module-init-tools/udev and module auto-loading ... lets say I have a module called 'foo', that I want the kernel to auto-load.

Wait, stop right there. When do you want the module autoloaded?

If you want it loaded when the device is plugged in, then great, the hotplug scripts will do that.

If you want the module loaded when you try to access the /dev node, then see the FAQ about udev for that :)

Quoted 4 lines

Then a distant related issue - anybody thought about dynamic major numbers of 2.7/2.8 (?) and the 'alias char-major-<whatever>-* whatever' type modprobe rules (as the whole fact of them being dynamic, will make that alias type worthless ...)?

Yes, it will make the char-major-* stuff worthless, however the distro I use has not used that style of alias for years, why would yours? :)

Rusty had it correct in that you need to try to load for the type of module:
alias eth1 tulip
alias usb-controller usb-ohci
and so on. That's the much better way.

thanks,

greg (I hate kmod) k-h

#14 lore raw
Quoted 5 lines · Greg KH

Rusty had it correct in that you need to try to load for the type of module:
alias eth1 tulip
alias usb-controller usb-ohci
and so on. That's the much better way.

Shouldn't these things be autodetected?

"alias usb-controller" is a poor example. Shouldn't the kernel automatically load drivers for all USB controllers that are found? (On my system, there's more than one type, which makes "alias usb-controller" even uglier).

"alias eth1" may be necessary to bind discovered NICs with the right interface names, but it's unfortunate. One system where I had "alias eth0 ..." failed to boot after a kernel upgrade when the named driver no longer supported that network card (a different driver took over support).

-- Jamie

#15 lore raw
Quoted 9 lines · Jamie Lokier
Quoted 5 lines · Greg KH

Rusty had it correct in that you need to try to load for the type of module:
alias eth1 tulip
alias usb-controller usb-ohci
and so on. That's the much better way.

Shouldn't these things be autodetected?

My general experience is that it does work fine in most cases, except maybe sound and net which you need your aliases.

Signature · 1 line
Martin Schlemmer
#16 lore raw
In reply to Greg KH
Quoted 7 lines · Greg KH
Quoted 5 lines · Martin Schlemmer

Hi

A quick question on module-init-tools/udev and module auto-loading ... lets say I have a module called 'foo', that I want the kernel to auto-load.

Quoted 8 lines

Wait, stop right there. When do you want the module autoloaded?

If you want it loaded when the device is plugged in, then great, the hotplug scripts will do that.

If you want the module loaded when you try to access the /dev node, then see the FAQ about udev for that :)

Whoa, stop the horses :) I do not want to start another devfs/udev argument 8)

As I said - this feature _does_ work of autoloading the module _if_ the device node and alias exists. If the node is deleted however it does not. So this tells me there functionality is half way there, and I was wondering if it could be completed without too much extra overhead.

You can check the mail to Rusty for more what I mean (hopefully it comes through correctly).

Quoted 5 lines
Quoted 4 lines

Then a distant related issue - anybody thought about dynamic major numbers of 2.7/2.8 (?) and the 'alias char-major-<whatever>-* whatever' type modprobe rules (as the whole fact of them being dynamic, will make that alias type worthless ...)?

Quoted 9 lines

Yes, it will make the char-major-* stuff worthless, however the distro I use has not used that style of alias for years, why would yours? :)

Rusty had it correct in that you need to try to load for the type of module:
alias eth1 tulip
alias usb-controller usb-ohci
and so on. That's the much better way.

Stupid question - is there a complete list of all these aliases?

Thanks,

Signature · 1 line
Martin Schlemmer