Skip to content

Commit c0d0b3a

Browse files
adam900710kdave
authored andcommitted
btrfs: call bdev_fput() to reclaim the blk_holder immediately
As part of the preparation for btrfs blk_holder_ops, we want to ensure the holder of a block device has a proper lifespan. However btrfs is always using fput() to close a block device, which has one problem: - fput() is deferred Meaning we can have a block device with invalid (aka, freed) holder. To avoid the problem, and align the behavior to all the existing codes, just call bdev_fput() instead. There is some extra requirement on the locking, but that's all resolved by previous patches and we should be safe to call bdev_fput(). Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 366943b commit c0d0b3a

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

fs/btrfs/dev-replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
327327
return 0;
328328

329329
error:
330-
fput(bdev_file);
330+
bdev_fput(bdev_file);
331331
return ret;
332332
}
333333

fs/btrfs/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
27002700
err_drop:
27012701
mnt_drop_write_file(file);
27022702
if (bdev_file)
2703-
fput(bdev_file);
2703+
bdev_fput(bdev_file);
27042704
out:
27052705
btrfs_put_dev_args_from_path(&args);
27062706
kfree(vol_args);
@@ -2751,7 +2751,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
27512751

27522752
mnt_drop_write_file(file);
27532753
if (bdev_file)
2754-
fput(bdev_file);
2754+
bdev_fput(bdev_file);
27552755
out:
27562756
btrfs_put_dev_args_from_path(&args);
27572757
out_free:

fs/btrfs/volumes.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,15 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
489489
if (holder) {
490490
ret = set_blocksize(*bdev_file, BTRFS_BDEV_BLOCKSIZE);
491491
if (ret) {
492-
fput(*bdev_file);
492+
bdev_fput(*bdev_file);
493493
goto error;
494494
}
495495
}
496496
invalidate_bdev(bdev);
497497
*disk_super = btrfs_read_disk_super(bdev, 0, false);
498498
if (IS_ERR(*disk_super)) {
499499
ret = PTR_ERR(*disk_super);
500-
fput(*bdev_file);
500+
bdev_fput(*bdev_file);
501501
goto error;
502502
}
503503

@@ -721,7 +721,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
721721

722722
error_free_page:
723723
btrfs_release_disk_super(disk_super);
724-
fput(bdev_file);
724+
bdev_fput(bdev_file);
725725

726726
return -EINVAL;
727727
}
@@ -1071,7 +1071,7 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
10711071
continue;
10721072

10731073
if (device->bdev_file) {
1074-
fput(device->bdev_file);
1074+
bdev_fput(device->bdev_file);
10751075
device->bdev = NULL;
10761076
device->bdev_file = NULL;
10771077
fs_devices->open_devices--;
@@ -1118,7 +1118,7 @@ static void btrfs_close_bdev(struct btrfs_device *device)
11181118
invalidate_bdev(device->bdev);
11191119
}
11201120

1121-
fput(device->bdev_file);
1121+
bdev_fput(device->bdev_file);
11221122
}
11231123

11241124
static void btrfs_close_one_device(struct btrfs_device *device)
@@ -1491,7 +1491,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
14911491
btrfs_release_disk_super(disk_super);
14921492

14931493
error_bdev_put:
1494-
fput(bdev_file);
1494+
bdev_fput(bdev_file);
14951495

14961496
return device;
14971497
}
@@ -2295,7 +2295,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
22952295
* free the device.
22962296
*
22972297
* We cannot call btrfs_close_bdev() here because we're holding the sb
2298-
* write lock, and fput() on the block device will pull in the
2298+
* write lock, and bdev_fput() on the block device will pull in the
22992299
* ->open_mutex on the block device and it's dependencies. Instead
23002300
* just flush the device and let the caller do the final bdev_release.
23012301
*/
@@ -2474,7 +2474,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
24742474
else
24752475
memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
24762476
btrfs_release_disk_super(disk_super);
2477-
fput(bdev_file);
2477+
bdev_fput(bdev_file);
24782478
return 0;
24792479
}
24802480

@@ -2922,7 +2922,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
29222922
error_free_device:
29232923
btrfs_free_device(device);
29242924
error:
2925-
fput(bdev_file);
2925+
bdev_fput(bdev_file);
29262926
if (locked) {
29272927
mutex_unlock(&uuid_mutex);
29282928
up_write(&sb->s_umount);

0 commit comments

Comments
 (0)