Skip to content

Commit 383032f

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: always open the device read-only in btrfs_scan_one_device
btrfs_scan_one_device opens the block device only to read the super block. Instead of passing a blk_mode_t argument to sometimes open it for writing, just hard code BLK_OPEN_READ as it will never write to the device or hand the block_device out to someone else. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 9ccd7e2 commit 383032f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

fs/btrfs/super.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,9 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
364364
break;
365365
case Opt_device: {
366366
struct btrfs_device *device;
367-
blk_mode_t mode = btrfs_open_mode(fc);
368367

369368
mutex_lock(&uuid_mutex);
370-
device = btrfs_scan_one_device(param->string, mode, false);
369+
device = btrfs_scan_one_device(param->string, false);
371370
mutex_unlock(&uuid_mutex);
372371
if (IS_ERR(device))
373372
return PTR_ERR(device);
@@ -1855,7 +1854,7 @@ static int btrfs_get_tree_super(struct fs_context *fc)
18551854
* With 'true' passed to btrfs_scan_one_device() (mount time) we expect
18561855
* either a valid device or an error.
18571856
*/
1858-
device = btrfs_scan_one_device(fc->source, mode, true);
1857+
device = btrfs_scan_one_device(fc->source, true);
18591858
ASSERT(device != NULL);
18601859
if (IS_ERR(device)) {
18611860
mutex_unlock(&uuid_mutex);
@@ -2233,7 +2232,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
22332232
* Scanning outside of mount can return NULL which would turn
22342233
* into 0 error code.
22352234
*/
2236-
device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false);
2235+
device = btrfs_scan_one_device(vol->name, false);
22372236
ret = PTR_ERR_OR_ZERO(device);
22382237
mutex_unlock(&uuid_mutex);
22392238
break;
@@ -2251,7 +2250,7 @@ static long btrfs_control_ioctl(struct file *file, unsigned int cmd,
22512250
* Scanning outside of mount can return NULL which would turn
22522251
* into 0 error code.
22532252
*/
2254-
device = btrfs_scan_one_device(vol->name, BLK_OPEN_READ, false);
2253+
device = btrfs_scan_one_device(vol->name, false);
22552254
if (IS_ERR_OR_NULL(device)) {
22562255
mutex_unlock(&uuid_mutex);
22572256
if (IS_ERR(device))

fs/btrfs/volumes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ static bool btrfs_skip_registration(struct btrfs_super_block *disk_super,
14411441
* the device or return an error. Multi-device and seeding devices are registered
14421442
* in both cases.
14431443
*/
1444-
struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
1444+
struct btrfs_device *btrfs_scan_one_device(const char *path,
14451445
bool mount_arg_dev)
14461446
{
14471447
struct btrfs_super_block *disk_super;
@@ -1462,7 +1462,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
14621462
* values temporarily, as the device paths of the fsid are the only
14631463
* required information for assembling the volume.
14641464
*/
1465-
bdev_file = bdev_file_open_by_path(path, flags, NULL, NULL);
1465+
bdev_file = bdev_file_open_by_path(path, BLK_OPEN_READ, NULL, NULL);
14661466
if (IS_ERR(bdev_file))
14671467
return ERR_CAST(bdev_file);
14681468

fs/btrfs/volumes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans,
719719
void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info);
720720
int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
721721
blk_mode_t flags, void *holder);
722-
struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
722+
struct btrfs_device *btrfs_scan_one_device(const char *path,
723723
bool mount_arg_dev);
724724
int btrfs_forget_devices(dev_t devt);
725725
void btrfs_close_devices(struct btrfs_fs_devices *fs_devices);

0 commit comments

Comments
 (0)