Skip to contentSkip to conversation

Simplify proc/devices and fix early termination regression

PATCH New Joe Korty 1 participant 1 message Mar 24, 2006

Subsystems (3)
lore
Share & tools
lore

Joe Korty

author
#0 lore raw

PATCH 1/1 Simplify proc/devices and fix early termination regression

Make baby-simple the code for /proc/devices. Based on the proven design for /proc/interrupts.

This also fixes the early-termination regression 2.6.16 introduced, as demonstrated by:

    # dd if=/proc/devices bs=1
    Character devices:
      1 mem
    27+0 records in
    27+0 records out

This should also work (but is untested) when /proc/devices

Quoted 1 line

4096 bytes, which I believe is what the original 2.6.16

rewrite fixed.

 2.6.16-git9-jak/block/genhd.c       |   98 ++--------------------
 2.6.16-git9-jak/fs/char_dev.c       |   82 ++----------------
 2.6.16-git9-jak/fs/proc/proc_misc.c |  159 +++++++-----------------------------
 2.6.16-git9-jak/include/linux/fs.h  |   15 ---
 4 files changed, 61 insertions(+), 293 deletions(-)
block/genhd.c renamed from block/genhd.c~simplify.proc.devices.and.fix.early.termination.regression +12 -86
diff -puNa block/genhd.c~simplify.proc.devices.and.fix.early.termination.regression block/genhd.c
@@ -39,100 +39,26 @@ static inline int major_to_index(int maj
 	return major % MAX_PROBE_HASH;
 }
 
-struct blkdev_info {
-        int index;
-        struct blk_major_name *bd;
-};
-
-/*
- * iterate over a list of blkdev_info structures.  allows
- * the major_names array to be iterated over from outside this file
- * must be called with the block_subsys_lock held
- */
-void *get_next_blkdev(void *dev)
-{
-        struct blkdev_info *info;
-
-        if (dev == NULL) {
-                info = kmalloc(sizeof(*info), GFP_KERNEL);
-                if (!info)
-                        goto out;
-                info->index=0;
-                info->bd = major_names[info->index];
-                if (info->bd)
-                        goto out;
-        } else {
-                info = dev;
-        }
-
-        while (info->index < ARRAY_SIZE(major_names)) {
-                if (info->bd)
-                        info->bd = info->bd->next;
-                if (info->bd)
-                        goto out;
-                /*
-                 * No devices on this chain, move to the next
-                 */
-                info->index++;
-                info->bd = (info->index < ARRAY_SIZE(major_names)) ?
-			major_names[info->index] : NULL;
-                if (info->bd)
-                        goto out;
-        }
-
-out:
-        return info;
-}
-
-void *acquire_blkdev_list(void)
-{
-        mutex_lock(&block_subsys_lock);
-        return get_next_blkdev(NULL);
-}
+#ifdef CONFIG_PROC_FS
 
-void release_blkdev_list(void *dev)
-{
-        mutex_unlock(&block_subsys_lock);
-        kfree(dev);
+fastcall int blkdev_size(void) {
+	return MAX_PROBE_HASH;
 }
 
-
-/*
- * Count the number of records in the blkdev_list.
- * must be called with the block_subsys_lock held
- */
-int count_blkdev_list(void)
+void blkdev_show(struct seq_file *f, off_t offset)
 {
-	struct blk_major_name *n;
-	int i, count;
-
-	count = 0;
+	struct blk_major_name *dp;
 
-	for (i = 0; i < ARRAY_SIZE(major_names); i++) {
-		for (n = major_names[i]; n; n = n->next)
-				count++;
+	if (offset < MAX_PROBE_HASH) {
+		mutex_lock(&block_subsys_lock);
+		for (dp = major_names[offset] ;dp; dp=dp->next) {
+			seq_printf(f, "%3d %s\n", dp->major, dp->name);
+		}
+		mutex_unlock(&block_subsys_lock);
 	}
-
-	return count;
-}
-
-/*
- * extract the major and name values from a blkdev_info struct
- * passed in as a void to *dev.  Must be called with
- * block_subsys_lock held
- */
-int get_blkdev_info(void *dev, int *major, char **name)
-{
-        struct blkdev_info *info = dev;
-
-        if (info->bd == NULL)
-                return 1;
-
-        *major = info->bd->major;
-        *name = info->bd->name;
-        return 0;
 }
 
+#endif /* CONFIG_PROC_FS */
 
 int register_blkdev(unsigned int major, const char *name)
 {
fs/char_dev.c renamed from fs/char_dev.c~simplify.proc.devices.and.fix.early.termination.regression +12 -70

103 lines not on this page · raw message

fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c~simplify.proc.devices.and.fix.early.termination.regression +33 -126

190 lines not on this page · raw message

include/linux/fs.h renamed from include/linux/fs.h~simplify.proc.devices.and.fix.early.termination.regression +4 -11
diff -puNa include/linux/fs.h~simplify.proc.devices.and.fix.early.termination.regression include/linux/fs.h
@@ -1408,12 +1408,8 @@ extern int register_chrdev(unsigned int,
 extern int unregister_chrdev(unsigned int, const char *);
 extern void unregister_chrdev_region(dev_t, unsigned);
 extern int chrdev_open(struct inode *, struct file *);
-extern int get_chrdev_list(char *);
-extern void *acquire_chrdev_list(void);
-extern int count_chrdev_list(void);
-extern void *get_next_chrdev(void *);
-extern int get_chrdev_info(void *, int *, char **);
-extern void release_chrdev_list(void *);
+extern fastcall int chrdev_size(void);
+extern void chrdev_show(struct seq_file *,off_t);
 
 /* fs/block_dev.c */
 #define BDEVNAME_SIZE	32	/* Largest string for a blockdev identifier */
@@ -1422,11 +1418,8 @@ extern const char *bdevname(struct block
 extern struct block_device *lookup_bdev(const char *);
 extern struct block_device *open_bdev_excl(const char *, int, void *);
 extern void close_bdev_excl(struct block_device *);
-extern void *acquire_blkdev_list(void);
-extern int count_blkdev_list(void);
-extern void *get_next_blkdev(void *);
-extern int get_blkdev_info(void *, int *, char **);
-extern void release_blkdev_list(void *);
+extern fastcall int blkdev_size(void);
+extern void blkdev_show(struct seq_file *,off_t);
 
 extern void init_special_inode(struct inode *, umode_t, dev_t);
 

_