Skip to content

Commit

Permalink
block: deprecate autoloading based on dev_t
Browse files Browse the repository at this point in the history
Make the legacy dev_t based autoloading optional and add a deprecation
warning.  This kind of autoloading has ceased to be useful about 20 years
ago.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220104071647.164918-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Feb 2, 2022
1 parent 26291c5 commit fbdee71
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions block/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ menuconfig BLOCK

if BLOCK

config BLOCK_LEGACY_AUTOLOAD
bool "Legacy autoloading support"
help
Enable loading modules and creating block device instances based on
accesses through their device special file. This is a historic Linux
feature and makes no sense in a udev world where device files are
created on demand.

Say N here unless booting or other functionality broke without it, in
which case you should also send a report to your distribution and
linux-block@vger.kernel.org.

config BLK_RQ_ALLOC_TIME
bool

Expand Down
9 changes: 6 additions & 3 deletions block/bdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,15 @@ struct block_device *blkdev_get_no_open(dev_t dev)
struct inode *inode;

inode = ilookup(blockdev_superblock, dev);
if (!inode) {
if (!inode && IS_ENABLED(CONFIG_BLOCK_LEGACY_AUTOLOAD)) {
blk_request_module(dev);
inode = ilookup(blockdev_superblock, dev);
if (!inode)
return NULL;
if (inode)
pr_warn_ratelimited(
"block device autoloading is deprecated. It will be removed in Linux 5.19\n");
}
if (!inode)
return NULL;

/* switch from the inode reference to a device mode one: */
bdev = &BDEV_I(inode)->bdev;
Expand Down
6 changes: 6 additions & 0 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ static struct blk_major_name {
struct blk_major_name *next;
int major;
char name[16];
#ifdef CONFIG_BLOCK_LEGACY_AUTOLOAD
void (*probe)(dev_t devt);
#endif
} *major_names[BLKDEV_MAJOR_HASH_SIZE];
static DEFINE_MUTEX(major_names_lock);
static DEFINE_SPINLOCK(major_names_spinlock);
Expand Down Expand Up @@ -275,7 +277,9 @@ int __register_blkdev(unsigned int major, const char *name,
}

p->major = major;
#ifdef CONFIG_BLOCK_LEGACY_AUTOLOAD
p->probe = probe;
#endif
strlcpy(p->name, name, sizeof(p->name));
p->next = NULL;
index = major_to_index(major);
Expand Down Expand Up @@ -679,6 +683,7 @@ static ssize_t disk_badblocks_store(struct device *dev,
return badblocks_store(disk->bb, page, len, 0);
}

#ifdef CONFIG_BLOCK_LEGACY_AUTOLOAD
void blk_request_module(dev_t devt)
{
unsigned int major = MAJOR(devt);
Expand All @@ -698,6 +703,7 @@ void blk_request_module(dev_t devt)
/* Make old-style 2.4 aliases work */
request_module("block-major-%d", MAJOR(devt));
}
#endif /* CONFIG_BLOCK_LEGACY_AUTOLOAD */

/*
* print a full list of all partitions - intended for places where the root
Expand Down

0 comments on commit fbdee71

Please sign in to comment.