Skip to content

Commit a160c61

Browse files
Christoph Hellwigaxboe
Christoph Hellwig
authored andcommitted
block: add an optional probe callback to major_names
Add a callback to the major_names array that allows a driver to override how to probe for dev_t that doesn't currently have a gendisk registered. This will help separating the lookup of the gendisk by dev_t vs probe action for a not currently registered dev_t. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bd8eff3 commit a160c61

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

block/genhd.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ static struct blk_major_name {
402402
struct blk_major_name *next;
403403
int major;
404404
char name[16];
405+
void (*probe)(dev_t devt);
405406
} *major_names[BLKDEV_MAJOR_HASH_SIZE];
406407
static DEFINE_MUTEX(major_names_lock);
407408

@@ -444,7 +445,8 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
444445
* See Documentation/admin-guide/devices.txt for the list of allocated
445446
* major numbers.
446447
*/
447-
int register_blkdev(unsigned int major, const char *name)
448+
int __register_blkdev(unsigned int major, const char *name,
449+
void (*probe)(dev_t devt))
448450
{
449451
struct blk_major_name **n, *p;
450452
int index, ret = 0;
@@ -483,6 +485,7 @@ int register_blkdev(unsigned int major, const char *name)
483485
}
484486

485487
p->major = major;
488+
p->probe = probe;
486489
strlcpy(p->name, name, sizeof(p->name));
487490
p->next = NULL;
488491
index = major_to_index(major);
@@ -505,8 +508,7 @@ int register_blkdev(unsigned int major, const char *name)
505508
mutex_unlock(&major_names_lock);
506509
return ret;
507510
}
508-
509-
EXPORT_SYMBOL(register_blkdev);
511+
EXPORT_SYMBOL(__register_blkdev);
510512

511513
void unregister_blkdev(unsigned int major, const char *name)
512514
{
@@ -1033,6 +1035,19 @@ static ssize_t disk_badblocks_store(struct device *dev,
10331035

10341036
static void request_gendisk_module(dev_t devt)
10351037
{
1038+
unsigned int major = MAJOR(devt);
1039+
struct blk_major_name **n;
1040+
1041+
mutex_lock(&major_names_lock);
1042+
for (n = &major_names[major_to_index(major)]; *n; n = &(*n)->next) {
1043+
if ((*n)->major == major && (*n)->probe) {
1044+
(*n)->probe(devt);
1045+
mutex_unlock(&major_names_lock);
1046+
return;
1047+
}
1048+
}
1049+
mutex_unlock(&major_names_lock);
1050+
10361051
if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
10371052
/* Make old-style 2.4 aliases work */
10381053
request_module("block-major-%d", MAJOR(devt));

include/linux/genhd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,10 @@ extern void blk_unregister_region(dev_t devt, unsigned long range);
367367

368368
#define alloc_disk(minors) alloc_disk_node(minors, NUMA_NO_NODE)
369369

370-
int register_blkdev(unsigned int major, const char *name);
370+
int __register_blkdev(unsigned int major, const char *name,
371+
void (*probe)(dev_t devt));
372+
#define register_blkdev(major, name) \
373+
__register_blkdev(major, name, NULL)
371374
void unregister_blkdev(unsigned int major, const char *name);
372375

373376
void revalidate_disk_size(struct gendisk *disk, bool verbose);

0 commit comments

Comments
 (0)