summaryrefslogtreecommitdiffstats
path: root/block/genhd.c
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2017-06-16 19:48:21 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-07-17 09:42:20 -0400
commit133d55cdb2f1f9e258d6dc34594a6c565f10b3fd (patch)
treeba2d42f4b9faaec0ddd8ffad9d5e73923b8ce39a /block/genhd.c
parent8a932f73e5b4227bf787474b44dc70b6961d6246 (diff)
block: order /proc/devices by major number
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>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 7f520fa25d16..51c1d407d93c 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -242,6 +242,7 @@ EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
242 * Can be deleted altogether. Later. 242 * Can be deleted altogether. Later.
243 * 243 *
244 */ 244 */
245#define BLKDEV_MAJOR_HASH_SIZE 255
245static struct blk_major_name { 246static struct blk_major_name {
246 struct blk_major_name *next; 247 struct blk_major_name *next;
247 int major; 248 int major;
@@ -259,12 +260,11 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
259{ 260{
260 struct blk_major_name *dp; 261 struct blk_major_name *dp;
261 262
262 if (offset < BLKDEV_MAJOR_HASH_SIZE) { 263 mutex_lock(&block_class_lock);
263 mutex_lock(&block_class_lock); 264 for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next)
264 for (dp = major_names[offset]; dp; dp = dp->next) 265 if (dp->major == offset)
265 seq_printf(seqf, "%3d %s\n", dp->major, dp->name); 266 seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
266 mutex_unlock(&block_class_lock); 267 mutex_unlock(&block_class_lock);
267 }
268} 268}
269#endif /* CONFIG_PROC_FS */ 269#endif /* CONFIG_PROC_FS */
270 270
@@ -309,6 +309,14 @@ int register_blkdev(unsigned int major, const char *name)
309 ret = major; 309 ret = major;
310 } 310 }
311 311
312 if (major >= BLKDEV_MAJOR_MAX) {
313 pr_err("register_blkdev: major requested (%d) is greater than the maximum (%d) for %s\n",
314 major, BLKDEV_MAJOR_MAX, name);
315
316 ret = -EINVAL;
317 goto out;
318 }
319
312 p = kmalloc(sizeof(struct blk_major_name), GFP_KERNEL); 320 p = kmalloc(sizeof(struct blk_major_name), GFP_KERNEL);
313 if (p == NULL) { 321 if (p == NULL) {
314 ret = -ENOMEM; 322 ret = -ENOMEM;