Message ID | 20250417034639.GG25659@frogsfrogsfrogs (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | loop: fix min directio size detection for nested loop devices | expand |
On Wed, Apr 16, 2025 at 08:46:39PM -0700, Darrick J. Wong wrote: > If however SCRATCH_DEV is itself a loop device that we've used to > simulate 4k LBA block devices, the minimum directio size discovery > introduced in commit f4774e92aab85d is wrong -- we should query the > logical block size of the underlying block device because file->f_path > points whatever filesystem /dev is. No, the problem is that special handling of block devices in stat sits in vfs_statx_path and not the exported vfs_getattr helper, and thus we don't call into bdev_statx which would return the right value. I'll send a separate VFS-level fix for this.
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 174e67ac729f3d..59d3e713c574b0 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -443,9 +443,17 @@ static void loop_reread_partitions(struct loop_device *lo) static unsigned int loop_query_min_dio_size(struct loop_device *lo) { struct file *file = lo->lo_backing_file; - struct block_device *sb_bdev = file->f_mapping->host->i_sb->s_bdev; + struct inode *inode = file->f_mapping->host; + struct block_device *sb_bdev = inode->i_sb->s_bdev; struct kstat st; + /* + * If the backing device is a block device, don't send directios + * smaller than its LBA size. + */ + if (S_ISBLK(inode->i_mode)) + return bdev_logical_block_size(I_BDEV(inode)); + /* * Use the minimal dio alignment of the file system if provided. */