LANANA: To Pending Device Number Registrants
The LANANA discussion has forked into a forest of vaguely related discussions. If I am not mistaken the only real question is how user space and kernel space communicate device identities.
Here "user space" is very different from "users".
Devices have a device path and device contents.
For the user it is very desirable to recognize things by contents. One invents labels and similar schemes, both readable with the eye and readable with software.
But devices vary quite a lot and labeling schemes vary quite a lot and user needs vary quite a lot.
Clearly, recognizing a device by contents is something that belongs to user space.
Of course the kernel can make functions available to simplify the work of a device manager, but the actual work of making the correspondence between the identity of a device as seen by the user and the device path belongs to user space. Be it a boot-time setup script working from a data base, or a daemon.
(A somewhat weaker function also belongs to user space:
Even if the user has not specified a name for a device it may be that the device has a serial number or other recognizable information, so that user space can guess or be sure that a certain device is the same as something seen earlier, perhaps before the last reboot.)
That was the user. She thinks about "my boot partition". And mount sees "UUID=e70bde8e-34d7-11d... /boot ext2 ..." or "LABEL=Boot /boot ext2 ..." and searches /proc/partitions for things that, when interpreted as an ext2 filesystem, have the specified UUID or label.
The communication between user space and kernel is not in terms of device "contents", since the kernel doesnt know about such things. The kernel knows only one thing: the device path. (the driver used, together with all parameters, the port address, the SCSI ID, the disk subinterval, ...)
But this path is a very complicated object. Moreover, it contains a lot of items that the user has never heard of. It is a bad idea to try to use such paths.
So we have: user space has file names and uses open() or mount(). Kernel space has device paths.
In principle the kernel could just number the devices it sees 1,2,... and export information about them, so that user space can choose the right number.
The part about exporting information is good. User space needs to be able to ask if a certain beast is a CD reader, and if so what manufacturer and model.
But the part about numbering 1,2,... may not be good enough, e.g. because it does not survive reboots. If we remain Unix-like and use device nodes in user space to pair a file name with a number, then it would be very nice if the number encoded the device path uniquely. Many programs expect this.
It cannot be done in all cases, but a good approximation is obtained if the number is a hash of the device path. In so far the hash is collision free we obtain numbers that stay unique over a reboot.
Andries
Quoted 15 lines · [email protected] [[email protected]] wrote:
In principle the kernel could just number the devices it sees 1,2,... and export information about them, so that user space can choose the right number.
The part about exporting information is good. User space needs to be able to ask if a certain beast is a CD reader, and if so what manufacturer and model.
But the part about numbering 1,2,... may not be good enough, e.g. because it does not survive reboots. If we remain Unix-like and use device nodes in user space to pair a file name with a number, then it would be very nice if the number encoded the device path uniquely. Many programs expect this.
It cannot be done in all cases, but a good approximation is obtained if the number is a hash of the device path. In so far the hash is collision free we obtain numbers that stay unique over a reboot.
Quoted 1 line
Andries
I disagree that the kernel should apply sequence numbers as devices are found or hash path information into the device name.
I am unclear of the need for the hashing the path into the name.
In the ptx operating system I previously worked on we ID'd everything that we could get a UUID from and one's that we could not we generated a pseudo one. We also split the UUID space up on config type. This is similar to the discussion in Andreas's mail. Non-id'd devices could possibly slip, but ID'd ones did not. In user space we allowed the user to select any name for a device (the user space to kernel connection was made by UUID. The solution worked on SCSI and FC based devices (Linux obviously deals with many more device name spaces).
I thought with devfs, devreg, and non allocated major, minors. A similar capability would be possible. The "/dev" usage would not need to know the path, but methods would be available to make the relationship when needed.
-Mike
Signature · 2 lines
Michael Anderson [email protected]
[email protected] wrote:
[lots of sensible comments to get this discussion "on track"]
Quoted 17 lines
So we have: user space has file names and uses
open()ormount(). Kernel space has device paths.In principle the kernel could just number the devices it sees 1,2,... and export information about them, so that user space can choose the right number.
The part about exporting information is good. User space needs to be able to ask if a certain beast is a CD reader, and if so what manufacturer and model.
But the part about numbering 1,2,... may not be good enough, e.g. because it does not survive reboots. If we remain Unix-like and use device nodes in user space to pair a file name with a number, then it would be very nice if the number encoded the device path uniquely. Many programs expect this.
It cannot be done in all cases, but a good approximation is obtained if the number is a hash of the device path. In so far the hash is collision free we obtain numbers that stay unique over a reboot.
I think here we might learn from the comments that people made about how AIX and OSF/1/Tru64 have been doing this.
You want the relation between a given /dev/xyz node and the corresponding device in the kernel to be relatively stable from the perspective of the user, so you can use it to implement device naming and access policies. What "stable" means technically is a matter of policy, since it depends very much on the perspective of the user.
You also want the relation between a given /dev/xyz node and the major/minor number of the related device to be "fixed", so you don't need to recreate all device nodes on every boot.
The issue is then how to establish the relation between major/minor numbers and (potentially very dynamic) kernel-internal device entities, in such a way that the type of stability desired by the user is provided.
As people noted, the mechanism used by AIX and Tru64 is essentially to have this relationship established by a user-level tool using a configuration file with policy information, and a status file to maintain state information across reboots.
This tool can implement any policy it likes, which means we can avoid all the policy discusions where the kernel is concerned, and can instead focus on methods.
For the people who want things to be backward compatible, it would be sufficient to implement a default tool that will set all the major/minor numbers exactly like they are now, so all existing device nodes will keep working as they did.
In order to support hot plugging of devices, I suppose this tool should either run as a daemon, or set itself up to be called by the kernel whenever something happens. (I think
I would prefer the daemon...) Sort of like /sbin/hotplug.
The next issue to discuss is then how to shape the mechanism by which the device manager tool and the kernel exchange information on what devices are out there, and what major/minor numbers each should be assigned.
The sort of information that a device manager might want to use, depending on how it is implemented and configured, would include such things as: device driver id, I/O bus, I/O port, IRQ nr, SCSI card/bus/id/lun, partition id, serial number, device model/type, filesystem label, filesystem UUID, phase of the moon, etc, etc.
Basically, anything that a driver or related subsystem can come up with that might help identify a device or resource in any particular situation, depending on user preferences.
I think this may fit somewhere in /proc/sys/dev or thereabout.
The big advantage of this approach is basically that we can continue to use the good old device nodes in the filesystem as we have done for the last 30 years, with all the advantages, but without the major/minor number allocation troubles.
Hmm, this all sounds too simple.
I must be talking nonsense. Please wake me up. ;-)
Signature · 3 lines
Willem Konynenberg <[email protected]> I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question -- Charles Babbage
Quoted 2 lines · Willem Konynenberg
I think here we might learn from the comments that people made about how AIX and OSF/1/Tru64 have been doing this.
However, I suspect that generally AIX and OSF/1 Tru64 systems come with system managers. Many Linux system do not (well presumably anybody who reads this mailing list has enough of a clue....). Also, I bet the number of USB and Firewire devices used on the above two systems is probably vanishingly small.
Signature · 4 lines
Michael Meissner, Red Hat, Inc. (GCC group) PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA Work: [email protected] phone: +1 978-486-9304 Non-work: [email protected] fax: +1 978-692-4482