Skip to content

Commit a4a37b3

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 54f6b30 commit a4a37b3

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
@@ -2696,7 +2696,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
26962696
err_drop:
26972697
mnt_drop_write_file(file);
26982698
if (bdev_file)
2699-
fput(bdev_file);
2699+
bdev_fput(bdev_file);
27002700
out:
27012701
btrfs_put_dev_args_from_path(&args);
27022702
kfree(vol_args);
@@ -2747,7 +2747,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
27472747

27482748
mnt_drop_write_file(file);
27492749
if (bdev_file)
2750-
fput(bdev_file);
2750+
bdev_fput(bdev_file);
27512751
out:
27522752
btrfs_put_dev_args_from_path(&args);
27532753
out_free:

fs/btrfs/volumes.c

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

@@ -719,7 +719,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
719719

720720
error_free_page:
721721
btrfs_release_disk_super(disk_super);
722-
fput(bdev_file);
722+
bdev_fput(bdev_file);
723723

724724
return -EINVAL;
725725
}
@@ -1069,7 +1069,7 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
10691069
continue;
10701070

10711071
if (device->bdev_file) {
1072-
fput(device->bdev_file);
1072+
bdev_fput(device->bdev_file);
10731073
device->bdev = NULL;
10741074
device->bdev_file = NULL;
10751075
fs_devices->open_devices--;
@@ -1116,7 +1116,7 @@ static void btrfs_close_bdev(struct btrfs_device *device)
11161116
invalidate_bdev(device->bdev);
11171117
}
11181118

1119-
fput(device->bdev_file);
1119+
bdev_fput(device->bdev_file);
11201120
}
11211121

11221122
static void btrfs_close_one_device(struct btrfs_device *device)
@@ -1489,7 +1489,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path,
14891489
btrfs_release_disk_super(disk_super);
14901490

14911491
error_bdev_put:
1492-
fput(bdev_file);
1492+
bdev_fput(bdev_file);
14931493

14941494
return device;
14951495
}
@@ -2293,7 +2293,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
22932293
* free the device.
22942294
*
22952295
* We cannot call btrfs_close_bdev() here because we're holding the sb
2296-
* write lock, and fput() on the block device will pull in the
2296+
* write lock, and bdev_fput() on the block device will pull in the
22972297
* ->open_mutex on the block device and it's dependencies. Instead
22982298
* just flush the device and let the caller do the final bdev_release.
22992299
*/
@@ -2472,7 +2472,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
24722472
else
24732473
memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
24742474
btrfs_release_disk_super(disk_super);
2475-
fput(bdev_file);
2475+
bdev_fput(bdev_file);
24762476
return 0;
24772477
}
24782478

@@ -2920,7 +2920,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
29202920
error_free_device:
29212921
btrfs_free_device(device);
29222922
error:
2923-
fput(bdev_file);
2923+
bdev_fput(bdev_file);
29242924
if (locked) {
29252925
mutex_unlock(&uuid_mutex);
29262926
up_write(&sb->s_umount);

0 commit comments

Comments
 (0)