Skip to content

Commit b85c429

Browse files
author
Al Viro
committed
btrfs_get_bdev_and_sb(): call set_blocksize() only for exclusive opens
btrfs_get_bdev_and_sb() has two callers - btrfs_open_one_device(), which asks for open to be exclusive and btrfs_get_dev_args_from_path(), which doesn't. Currently it does set_blocksize() in all cases. I'm rather dubious about the need to do set_blocksize() anywhere in btrfs, to be honest - there's some access to page cache of underlying block devices in there, but it's nowhere near the hot paths, AFAICT. In any case, btrfs_get_dev_args_from_path() only needs to read the on-disk superblock and copy several fields out of it; all callers are only interested in devices that are already opened and brought into per-filesystem set, so setting the block size is redundant for those and actively harmful if we are given a pathname of unrelated device. So we only need btrfs_get_bdev_and_sb() to call set_blocksize() when it's asked to open exclusive. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent b1439b1 commit b85c429

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/btrfs/volumes.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,12 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
482482

483483
if (flush)
484484
sync_blockdev(bdev);
485-
ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
486-
if (ret) {
487-
fput(*bdev_file);
488-
goto error;
485+
if (holder) {
486+
ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE);
487+
if (ret) {
488+
fput(*bdev_file);
489+
goto error;
490+
}
489491
}
490492
invalidate_bdev(bdev);
491493
*disk_super = btrfs_read_dev_super(bdev);
@@ -498,6 +500,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
498500
return 0;
499501

500502
error:
503+
*disk_super = NULL;
501504
*bdev_file = NULL;
502505
return ret;
503506
}

0 commit comments

Comments
 (0)