]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
block: order /proc/devices by major number
authorLogan Gunthorpe <logang@deltatee.com>
Fri, 16 Jun 2017 23:48:21 +0000 (17:48 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Jul 2017 13:42:20 +0000 (15:42 +0200)
Presently, the order of the block devices listed in /proc/devices is not
entirely sequential. If a block device has a major number greater than
BLKDEV_MAJOR_HASH_SIZE (255), it will be ordered as if its major were
module 255. For example, 511 appears after 1.

This patch cleans that up and prints each major number in the correct
order, regardless of where they are stored in the hash table.

In order to do this, we introduce BLKDEV_MAJOR_MAX as an artificial
limit (chosen to be 512). It will then print all devices in major
order number from 0 to the maximum.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jeff Layton <jlayton@poochiereds.net>
Cc: "J. Bruce Fields" <bfields@fieldses.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/genhd.c
fs/proc/devices.c
include/linux/fs.h

index 7f520fa25d16d47841cb892094d4615e4258534e..51c1d407d93cc79ad545bf9f664e845e4b147c59 100644 (file)
@@ -242,6 +242,7 @@ EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
  * Can be deleted altogether. Later.
  *
  */
+#define BLKDEV_MAJOR_HASH_SIZE 255
 static struct blk_major_name {
        struct blk_major_name *next;
        int major;
@@ -259,12 +260,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
 {
        struct blk_major_name *dp;
 
-       if (offset < BLKDEV_MAJOR_HASH_SIZE) {
-               mutex_lock(&block_class_lock);
-               for (dp = major_names[offset]; dp; dp = dp->next)
+       mutex_lock(&block_class_lock);
+       for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next)
+               if (dp->major == offset)
                        seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
-               mutex_unlock(&block_class_lock);
-       }
+       mutex_unlock(&block_class_lock);
 }
 #endif /* CONFIG_PROC_FS */
 
@@ -309,6 +309,14 @@ int register_blkdev(unsigned int major, const char *name)
                ret = major;
        }
 
+       if (major >= BLKDEV_MAJOR_MAX) {
+               pr_err("register_blkdev: major requested (%d) is greater than the maximum (%d) for %s\n",
+                      major, BLKDEV_MAJOR_MAX, name);
+
+               ret = -EINVAL;
+               goto out;
+       }
+
        p = kmalloc(sizeof(struct blk_major_name), GFP_KERNEL);
        if (p == NULL) {
                ret = -ENOMEM;
index d196e22c4f1c95c4d2c8a5ed2e081120bb5b4342..e5709343feb7fb63a22c3bb6897c9d8d02f2aee6 100644 (file)
@@ -25,7 +25,7 @@ static int devinfo_show(struct seq_file *f, void *v)
 
 static void *devinfo_start(struct seq_file *f, loff_t *pos)
 {
-       if (*pos < (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_MAX))
+       if (*pos < (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
                return pos;
        return NULL;
 }
@@ -33,7 +33,7 @@ static void *devinfo_start(struct seq_file *f, loff_t *pos)
 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
 {
        (*pos)++;
-       if (*pos >= (BLKDEV_MAJOR_HASH_SIZE + CHRDEV_MAJOR_MAX))
+       if (*pos >= (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
                return NULL;
        return pos;
 }
index b07433c335ca47aef43cdd552fe85fa1d7ae5084..570dcc61fda6c77205d953f1aeb30b5960cd76e8 100644 (file)
@@ -2503,14 +2503,14 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
 #define BDEVT_SIZE     10      /* Largest string for MAJ:MIN for blkdev */
 
 #ifdef CONFIG_BLOCK
-#define BLKDEV_MAJOR_HASH_SIZE 255
+#define BLKDEV_MAJOR_MAX       512
 extern const char *__bdevname(dev_t, char *buffer);
 extern const char *bdevname(struct block_device *bdev, char *buffer);
 extern struct block_device *lookup_bdev(const char *);
 extern void blkdev_show(struct seq_file *,off_t);
 
 #else
-#define BLKDEV_MAJOR_HASH_SIZE 0
+#define BLKDEV_MAJOR_MAX       0
 #endif
 
 extern void init_special_inode(struct inode *, umode_t, dev_t);