Skip to content

Commit 5f33b52

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: don't autoload drivers on stat
blkdev_get_no_open can trigger the legacy autoload of block drivers. A simple stat of a block device has not historically done that, so disable this behavior again. Fixes: 9abcfbd ("block: Add atomic write support for statx") Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christian Brauner <brauner@kernel.org> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20250423053810.1683309-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d13b709 commit 5f33b52

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

block/bdev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,13 +815,13 @@ static void blkdev_put_part(struct block_device *part)
815815
blkdev_put_whole(whole);
816816
}
817817

818-
struct block_device *blkdev_get_no_open(dev_t dev)
818+
struct block_device *blkdev_get_no_open(dev_t dev, bool autoload)
819819
{
820820
struct block_device *bdev;
821821
struct inode *inode;
822822

823823
inode = ilookup(blockdev_superblock, dev);
824-
if (!inode && IS_ENABLED(CONFIG_BLOCK_LEGACY_AUTOLOAD)) {
824+
if (!inode && autoload && IS_ENABLED(CONFIG_BLOCK_LEGACY_AUTOLOAD)) {
825825
blk_request_module(dev);
826826
inode = ilookup(blockdev_superblock, dev);
827827
if (inode)
@@ -1043,7 +1043,7 @@ struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder,
10431043
if (ret)
10441044
return ERR_PTR(ret);
10451045

1046-
bdev = blkdev_get_no_open(dev);
1046+
bdev = blkdev_get_no_open(dev, true);
10471047
if (!bdev)
10481048
return ERR_PTR(-ENXIO);
10491049

@@ -1321,7 +1321,7 @@ void bdev_statx(struct path *path, struct kstat *stat,
13211321
* use I_BDEV() here; the block device has to be looked up by i_rdev
13221322
* instead.
13231323
*/
1324-
bdev = blkdev_get_no_open(d_backing_inode(path->dentry)->i_rdev);
1324+
bdev = blkdev_get_no_open(d_backing_inode(path->dentry)->i_rdev, false);
13251325
if (!bdev)
13261326
return;
13271327

block/blk-cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ int blkg_conf_open_bdev(struct blkg_conf_ctx *ctx)
797797
return -EINVAL;
798798
input = skip_spaces(input);
799799

800-
bdev = blkdev_get_no_open(MKDEV(major, minor));
800+
bdev = blkdev_get_no_open(MKDEV(major, minor), true);
801801
if (!bdev)
802802
return -ENODEV;
803803
if (bdev_is_partition(bdev)) {

block/blk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static inline void blk_wait_io(struct completion *done)
9494
wait_for_completion_io(done);
9595
}
9696

97-
struct block_device *blkdev_get_no_open(dev_t dev);
97+
struct block_device *blkdev_get_no_open(dev_t dev, bool autoload);
9898
void blkdev_put_no_open(struct block_device *bdev);
9999

100100
#define BIO_INLINE_VECS 4

block/fops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)
642642
if (ret)
643643
return ret;
644644

645-
bdev = blkdev_get_no_open(inode->i_rdev);
645+
bdev = blkdev_get_no_open(inode->i_rdev, true);
646646
if (!bdev)
647647
return -ENXIO;
648648

0 commit comments

Comments
 (0)