]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: call bdev_fput() to reclaim the blk_holder immediately
authorQu Wenruo <wqu@suse.com>
Mon, 16 Jun 2025 00:12:20 +0000 (09:42 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 22:06:19 +0000 (00:06 +0200)
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 other code, 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>
fs/btrfs/dev-replace.c
fs/btrfs/ioctl.c
fs/btrfs/volumes.c

index bd276179918172377aeb665a4d38d556314927c1..473450ee0408d4f7a77c86ea8abe1458be1cbcc7 100644 (file)
@@ -327,7 +327,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
        return 0;
 
 error:
-       fput(bdev_file);
+       bdev_fput(bdev_file);
        return ret;
 }
 
index a48028ead359dfd40d8e2cc7a48ad8d543802cf7..c9ab1e12525ed247115dbbc6f20fb90615177c3f 100644 (file)
@@ -2696,7 +2696,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg)
 err_drop:
        mnt_drop_write_file(file);
        if (bdev_file)
-               fput(bdev_file);
+               bdev_fput(bdev_file);
 out:
        btrfs_put_dev_args_from_path(&args);
        kfree(vol_args);
@@ -2747,7 +2747,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 
        mnt_drop_write_file(file);
        if (bdev_file)
-               fput(bdev_file);
+               bdev_fput(bdev_file);
 out:
        btrfs_put_dev_args_from_path(&args);
 out_free:
index 50b1cc91daf525c73f8902510cde89b94aa15fc2..f49eb435487452767d54151fb1dd21b905c2ada8 100644 (file)
@@ -487,7 +487,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
        if (holder) {
                ret = set_blocksize(*bdev_file, BTRFS_BDEV_BLOCKSIZE);
                if (ret) {
-                       fput(*bdev_file);
+                       bdev_fput(*bdev_file);
                        goto error;
                }
        }
@@ -495,7 +495,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
        *disk_super = btrfs_read_disk_super(bdev, 0, false);
        if (IS_ERR(*disk_super)) {
                ret = PTR_ERR(*disk_super);
-               fput(*bdev_file);
+               bdev_fput(*bdev_file);
                goto error;
        }
 
@@ -719,7 +719,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices,
 
 error_free_page:
        btrfs_release_disk_super(disk_super);
-       fput(bdev_file);
+       bdev_fput(bdev_file);
 
        return -EINVAL;
 }
@@ -1069,7 +1069,7 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices,
                        continue;
 
                if (device->bdev_file) {
-                       fput(device->bdev_file);
+                       bdev_fput(device->bdev_file);
                        device->bdev = NULL;
                        device->bdev_file = NULL;
                        fs_devices->open_devices--;
@@ -1116,7 +1116,7 @@ static void btrfs_close_bdev(struct btrfs_device *device)
                invalidate_bdev(device->bdev);
        }
 
-       fput(device->bdev_file);
+       bdev_fput(device->bdev_file);
 }
 
 static void btrfs_close_one_device(struct btrfs_device *device)
@@ -1489,7 +1489,7 @@ free_disk_super:
        btrfs_release_disk_super(disk_super);
 
 error_bdev_put:
-       fput(bdev_file);
+       bdev_fput(bdev_file);
 
        return device;
 }
@@ -2293,7 +2293,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
         * free the device.
         *
         * We cannot call btrfs_close_bdev() here because we're holding the sb
-        * write lock, and fput() on the block device will pull in the
+        * write lock, and bdev_fput() on the block device will pull in the
         * ->open_mutex on the block device and it's dependencies.  Instead
         *  just flush the device and let the caller do the final bdev_release.
         */
@@ -2472,7 +2472,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
        else
                memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE);
        btrfs_release_disk_super(disk_super);
-       fput(bdev_file);
+       bdev_fput(bdev_file);
        return 0;
 }
 
@@ -2920,7 +2920,7 @@ error_free_zone:
 error_free_device:
        btrfs_free_device(device);
 error:
-       fput(bdev_file);
+       bdev_fput(bdev_file);
        if (locked) {
                mutex_unlock(&uuid_mutex);
                up_write(&sb->s_umount);