RFC/Patch - Implode devfs
The following patch replaces devfs with a ramfs-derived
implementation which is under one quarter the size although it eliminates certain functionality.
wc -l *.c Makefile size (text + data + bss)
devfs 3614 lines 25,863 bytes
mini-devfs 629 lines 5,367 bytes
Reduction 5.7x 4.8x
Further minor reductions may be possible from some additional
clean-ups and perhaps a simplification to the programming interface.
This code is probably very buggy. I've just gotten it working
on the machine on which I'm composing this message. It is not ready for integration yet. I would particularly appreciate help with the dentry manipulation and locking, which I think I've probably botched.
The notable differences between devfs and mini-devfs are:
1. devfsd has been replaced with the user mode helper/sbin/devfs_helper which is exec'ed for registration and initial lookup events (I could catch all the events that devfs does, but I don't think that's really necessary). I have yet to port devfsd to this interface. When sysfs support is added to the new kernel parameter system, I will make this a kernel parameter, so it can be off initially, and only turned on by systems that use it when the boot process is ready for it. This will also eliminate the problem where the boot process currently tries to do 200+ execs as each pseudo-terminal is registered.
2. The removable device code that cleared and reread partition
tables from removable media all the time preventing use of userland partitioning with devfs is eliminated. (Non-devfs systems never had this problem.)
3. devfs_handle_t is now a synonym for struct dentry*.
4. A lot of the devfs routines are unimplemented. I haven't
noticed much code that uses them, and I'm not sure that any code really should. I think arch/ia64/sn uses devfs_get_first_child, devfs_get_next_sibling. I need to understand what if any of the other routines are really necessary and why (for example, why can't we use struct dentry). My computer seems to run fine without them.
TODO:
First of all, I'd like to debug this code and I'd welcome any
help. The only malfunction (aside from routines that aren't written) that I've noticed is that previously xdm would give up after trying to start the X server about five times (it is not configured). With this smaller devfs, xdm keeps trying to start the X server. Also, I'm pretty sure that my code is at least releasing and reacquiring dcache_lock when it shouldn't, and I think there may be some similar inode->i_sem issues.
In the future, I'd like to shrink the devfs interface to
devfs_{create,delete}. If we prohibit file renaming in devfs, then drivers can be sure they've removed the devfs nodes that they've created when they delete the paths that they've created. A side-effect of this would be that devfs_handle_t would be eliminated. I still want the ability to pass a struct file_operations* to devfs_create as it may enable the elimination of fixed device numbers.
I think I'd like to change fs/super.c slightly to make it
easier to statically allocate the struct super_block for filesystems that can have only one instance even if they are mounted in multiple locations (devfs, procfs, sysfs, usbdevfs, etc.).
I started hacking on this code by making an approximately ten
line change to ramfs just to have it call a user level program on lookups and file creation. I had hoped to change the devfs routines to just generically operate on whatever was mounted on /dev. If the devfs API were shrunk substantially, it might be worth trying that approach again.
Comments?
Signature · 4 lines
Adam J. Richter __ ______________ 575 Oroville Road [email protected] \ / Milpitas, California 95035 +1 408 309-6081 | g g d r a s i l United States of America "Free Software For The Rest Of Us."
include/linux/devfs_fs_kernel.h +4 -0
@@ -24,7 +24,11 @@#define DEVFS_SPECIAL_CHR 0#define DEVFS_SPECIAL_BLK 1 +#ifdef CONFIG_DEVFS_SMALL +typedef struct dentry *devfs_handle_t ; +#else typedef struct devfs_entry *devfs_handle_t ; +#endif #ifdef CONFIG_DEVFS_FS
fs/namei.c +1 -1
@@ -1377,7 +1377,7 @@ }/* SMP-safe */ -static struct dentry *lookup_create (struct nameidata *nd,int is_dir) +struct dentry *lookup_create (struct nameidata *nd,int is_dir) {struct dentry *dentry;
fs/Kconfig +15 -1
@@ -318,7 +318,7 @@ # other users than ext3, we will simply make it be the same as CONFIG_EXT3_FS # dep_tristate ' Journal Block Device support (JBD for ext3)' CONFIG_JBD $CONFIG_EXT3_FS config JBD - bool + tristate default EXT3_FS ---help--- This is a generic journaling layer for block devices. It is
@@ -847,6 +847,20 @@ If unsure, say N. +config DEVFS_SMALL + bool "Smaller /dev file system (EXPERIMENTAL)" + depends on EXPERIMENTAL && DEVFS_FS + ---help--- + New smaller devfs without automatic partition rereading + (which impeded user level partition handling) and currently + without some features used by arch/ia64/sn. + + If unsure, say N. + +config DEVFS_BIG + bool + depends on DEVFS_FS && !DEVFS_SMALL + config DEVFS_MOUNT bool "Automatically mount at boot" depends on DEVFS_FS
fs/devfs2/Makefile +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for the linux ramfs routines. +# + +export-objs := inode.o numspace.o + +obj-$(CONFIG_RAMFS) += ramfs.o + +ramfs-objs := inode.o numspace.o
fs/devfs2/inode.c +543 -0
543 lines not on this page · raw message
fs/devfs2/numspace.c +76 -0
76 lines not on this page · raw message
Quoted 9 lines · Adam J. Richter
The following patch replaces devfs with a ramfs-derived
implementation which is under one quarter the size although it eliminates certain functionality.wc -l *.c
Makefilesize (text + data + bss)devfs 3614 lines 25,863 bytes
mini-devfs 629 lines 5,367 bytes
Reduction 5.7x 4.8x
Wow, that looks really cool! I just wonder where viro is hiding the last weeks, he promised more devfs API cleanups that likely clash with your changes.
Quoted 1 line
3.
devfs_handle_tis now a synonym for struct dentry*.
I wonder whether some code uses struct devfs_entry * directly, at least I was tempted to do so in the scsi midlayer.
Quoted 6 lines
4. A lot of the devfs routines are unimplemented. I haven't
noticed much code that uses them, and I'm not sure that any code really should. I thinkarch/ia64/snusesdevfs_get_first_child,devfs_get_next_sibling. I need to understand what if any of the other routines are really necessary and why (for example, why can't we use struct dentry). My computer seems to run fine without them.
The hcl code in arch/ia64/sn/ is supposed to get replaced by a filesystem on it's own once the sn port is properly updated for 2.5/2.6.
Quoted 2 lines
First of all, I'd like to debug this code and I'd welcome any
help.
Is it supposed to work out of the box on previously (and for 2.4 use) non-devfs systems? I still don't plan to use devfs, but such an effort is really worth some debugging help..
Quoted 4 lines
I think I'd like to change
fs/super.cslightly to make it
easier to statically allocate the structsuper_blockfor filesystems that can have only one instance even if they are mounted in multiple locations (devfs, procfs, sysfs, usbdevfs, etc.).
Why do you want to allocate it statically?
include/linux/devfs_fs_kernel.h line 31
Quoted 9 lines
include/linux/devfs_fs_kernel.h +4
-0@@ -24,7 +24,11 @@#define DEVFS_SPECIAL_CHR 0#define DEVFS_SPECIAL_BLK 1 +#ifdef CONFIG_DEVFS_SMALL +typedef struct dentry *devfs_handle_t ; +#else typedef struct devfs_entry *devfs_handle_t ; +#endif
Do you really need to keep both around?
fs/devfs2/inode.c line 305
Quoted 3 lines
fs/devfs2/inode.c +3
-0+/* On success, returns with (*parent_inode)->i_sem taken. */ +static int devfs_decode (devfs_handle_t dir,const char *name,int is_dir, +struct inode **parent_inode,struct dentry **dentry)
Do we really have to support this?
Quoted 5 lines
fs/devfs2/numspace.c +4
-0+++ linux/fs/devfs2/numspace.c 2002-12-25 17:44:14.000000000 -0800@@ -0,0 +1,76 @@ +#include <linux/module.h> +#include <linux/vmalloc.h> +#include <linux/devfs_fs_kernel.h>
fs/devfs2/numspace.c line 13
Quoted 10 lines
fs/devfs2/numspace.c +10
-0+ +/** +* devfs_alloc_unique_number - Allocate a unique (positive) number. +* @space: The number space to allocate from. +* +* Returns the allocated unique number, else a negative error code. +* This routine is thread safe and may block. +*/ + +int devfs_alloc_unique_number (struct unique_numspace *space)
Remove the devfs_ prefix here (it's not devfs-specific at all) and convert to sane indentation?