Is it possible to access sysfs from within the kernel?
Why? Lets see.
Sysfs describes the system with all its devices etc but is also an interface to access kernel internal data.
Sysfs data could easily be put into a hierarchical tree. (I think it even is, but it's not so obvious, because it's done using the fs code (inodes, dentries), maybe the kobjects do play a big role here, too). To access sysfs from an application, you have to use extensively open() and close() for each file (attributes) and readdir for directories... or use libsysfs which does these things for you. While the current design is good for users (cat /sys/.../.../attribute), it's not very efficient for applications (due to the many syscalls).
IMO it would be much better (for the applications) to have a device node in /dev which could be used to access the sysfs tree. No ioctl but using simple packets.
Besides the simple query/result things, you could register for recieving events (now hotplug), with the difference that the current hotplug (AFAIK) can inform (execute) only one application (/sbin/hotplug). Or even make it possible to recieve events only from certain classes/devices/subsystems etc.
tom
Quoted 11 lines · Tomas Carnecky
Why? Lets see.
Sysfs describes the system with all its devices etc but is also an interface to access kernel internal data.
Sysfs data could easily be put into a hierarchical tree. (I think it even is, but it's not so obvious, because it's done using the fs code (inodes, dentries), maybe the kobjects do play a big role here, too). To access sysfs from an application, you have to use extensivelyopen()andclose()for each file (attributes) and readdir for directories... or use libsysfs which does these things for you.
While the current design is good for users (cat/sys/.../.../attribute), it's not very efficient for applications (due to the many syscalls).
Why not? Do you have numbers showing that this is inefficient? Have you looked at using libsysfs to make it easier for your program to access sysfs?
Quoted 3 lines
IMO it would be much better (for the applications) to have a device node in /dev which could be used to access the sysfs tree. No ioctl but using simple packets.
No, please just use the filesystem.
Quoted 2 lines
Besides the simple query/result things, you could register for recieving events (now hotplug),
And netlink.
Quoted 2 lines
with the difference that the current hotplug
(AFAIK) can inform (execute) only one application (/sbin/hotplug).
Not true. Please read the /sbin/hotplug script to find out how your program can get those notifications.
Quoted 2 lines
Or even make it possible to recieve events only from certain classes/devices/subsystems etc.
It does that already today. Again, please read the documentation that is already included in the program.
thanks,
greg k-h