Commit de339cbf authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba
Browse files

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 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: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9f43d0ff
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
}

+2 −2
Original line number Diff line number Diff line
@@ -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:
+9 −9
Original line number Diff line number Diff line
@@ -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 @@ struct btrfs_device *btrfs_scan_one_device(const char *path,
	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 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
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);