diff mbox series

[RFC,v4,linux-next,03/19] block: remove sync_blockdev_range()

Message ID 20240222124555.2049140-4-yukuai1@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series fs & block: remove bdev->bd_inode | expand

Commit Message

Yu Kuai Feb. 22, 2024, 12:45 p.m. UTC
From: Yu Kuai <yukuai3@huawei.com>

Now that all filesystems stash the bdev file, it's ok to flush the file
mapping directly.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/bdev.c           |  7 -------
 fs/btrfs/dev-replace.c |  2 +-
 fs/btrfs/volumes.c     | 19 +++++++++++--------
 fs/btrfs/volumes.h     |  2 +-
 fs/exfat/fatent.c      |  2 +-
 include/linux/blkdev.h |  1 -
 6 files changed, 14 insertions(+), 19 deletions(-)

Comments

Jan Kara March 15, 2024, 2:37 p.m. UTC | #1
On Thu 22-02-24 20:45:39, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
> 
> Now that all filesystems stash the bdev file, it's ok to flush the file
> mapping directly.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/bdev.c           |  7 -------
>  fs/btrfs/dev-replace.c |  2 +-
>  fs/btrfs/volumes.c     | 19 +++++++++++--------
>  fs/btrfs/volumes.h     |  2 +-
>  fs/exfat/fatent.c      |  2 +-
>  include/linux/blkdev.h |  1 -
>  6 files changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/block/bdev.c b/block/bdev.c
> index 49dcff483289..e493d5c72edb 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -200,13 +200,6 @@ int sync_blockdev(struct block_device *bdev)
>  }
>  EXPORT_SYMBOL(sync_blockdev);
>  
> -int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
> -{
> -	return filemap_write_and_wait_range(bdev->bd_inode->i_mapping,
> -			lstart, lend);
> -}
> -EXPORT_SYMBOL(sync_blockdev_range);
> -
>  /**
>   * bdev_freeze - lock a filesystem and force it into a consistent state
>   * @bdev:	blockdevice to lock
> diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
> index 7057221a46c3..88d45118cc64 100644
> --- a/fs/btrfs/dev-replace.c
> +++ b/fs/btrfs/dev-replace.c
> @@ -982,7 +982,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
>  	btrfs_sysfs_remove_device(src_device);
>  	btrfs_sysfs_update_devid(tgt_device);
>  	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &src_device->dev_state))
> -		btrfs_scratch_superblocks(fs_info, src_device->bdev,
> +		btrfs_scratch_superblocks(fs_info, src_device->bdev_file,
>  					  src_device->name->str);
>  
>  	/* write back the superblocks */
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 493e33b4ae94..e12451ff911a 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2033,14 +2033,14 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
>  }
>  
>  static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
> -				     struct block_device *bdev, int copy_num)
> +				     struct file *bdev_file, int copy_num)
>  {
>  	struct btrfs_super_block *disk_super;
>  	const size_t len = sizeof(disk_super->magic);
>  	const u64 bytenr = btrfs_sb_offset(copy_num);
>  	int ret;
>  
> -	disk_super = btrfs_read_disk_super(bdev, bytenr, bytenr);
> +	disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, bytenr);
>  	if (IS_ERR(disk_super))
>  		return;
>  
> @@ -2048,26 +2048,29 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
>  	folio_mark_dirty(virt_to_folio(disk_super));
>  	btrfs_release_disk_super(disk_super);
>  
> -	ret = sync_blockdev_range(bdev, bytenr, bytenr + len - 1);
> +	ret = filemap_write_and_wait_range(bdev_file->f_mapping,
> +					   bytenr, bytenr + len - 1);
>  	if (ret)
>  		btrfs_warn(fs_info, "error clearing superblock number %d (%d)",
>  			copy_num, ret);
>  }
>  
>  void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
> -			       struct block_device *bdev,
> +			       struct file *bdev_file,
>  			       const char *device_path)
>  {
> +	struct block_device *bdev;
>  	int copy_num;
>  
> -	if (!bdev)
> +	if (!bdev_file)
>  		return;
>  
> +	bdev = file_bdev(bdev_file);
>  	for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX; copy_num++) {
>  		if (bdev_is_zoned(bdev))
>  			btrfs_reset_sb_log_zones(bdev, copy_num);
>  		else
> -			btrfs_scratch_superblock(fs_info, bdev, copy_num);
> +			btrfs_scratch_superblock(fs_info, bdev_file, copy_num);
>  	}
>  
>  	/* Notify udev that device has changed */
> @@ -2209,7 +2212,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,
>  	 *  just flush the device and let the caller do the final bdev_release.
>  	 */
>  	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
> -		btrfs_scratch_superblocks(fs_info, device->bdev,
> +		btrfs_scratch_superblocks(fs_info, device->bdev_file,
>  					  device->name->str);
>  		if (device->bdev) {
>  			sync_blockdev(device->bdev);
> @@ -2323,7 +2326,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
>  
>  	mutex_unlock(&fs_devices->device_list_mutex);
>  
> -	btrfs_scratch_superblocks(tgtdev->fs_info, tgtdev->bdev,
> +	btrfs_scratch_superblocks(tgtdev->fs_info, tgtdev->bdev_file,
>  				  tgtdev->name->str);
>  
>  	btrfs_close_bdev(tgtdev);
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 2ef78d3cc4c3..1d566f40b83d 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -818,7 +818,7 @@ struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
>  bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
>  					struct btrfs_device *failing_dev);
>  void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
> -			       struct block_device *bdev,
> +			       struct file *bdev_file,
>  			       const char *device_path);
>  
>  enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags);
> diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c
> index 56b870d9cc0d..1c86ec2465b7 100644
> --- a/fs/exfat/fatent.c
> +++ b/fs/exfat/fatent.c
> @@ -296,7 +296,7 @@ int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
>  	}
>  
>  	if (IS_DIRSYNC(dir))
> -		return sync_blockdev_range(sb->s_bdev,
> +		return filemap_write_and_wait_range(sb->s_bdev_file->f_mapping,
>  				EXFAT_BLK_TO_B(blknr, sb),
>  				EXFAT_BLK_TO_B(last_blknr, sb) - 1);
>  
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 9e96811c8915..c510f334c84f 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1527,7 +1527,6 @@ unsigned int block_size(struct block_device *bdev);
>  #ifdef CONFIG_BLOCK
>  void invalidate_bdev(struct block_device *bdev);
>  int sync_blockdev(struct block_device *bdev);
> -int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
>  void sync_bdevs(bool wait);
>  void bdev_statx_dioalign(struct inode *inode, struct kstat *stat);
>  void printk_all_partitions(void);
> -- 
> 2.39.2
>
Christoph Hellwig March 17, 2024, 9:21 p.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/block/bdev.c b/block/bdev.c
index 49dcff483289..e493d5c72edb 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -200,13 +200,6 @@  int sync_blockdev(struct block_device *bdev)
 }
 EXPORT_SYMBOL(sync_blockdev);
 
-int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend)
-{
-	return filemap_write_and_wait_range(bdev->bd_inode->i_mapping,
-			lstart, lend);
-}
-EXPORT_SYMBOL(sync_blockdev_range);
-
 /**
  * bdev_freeze - lock a filesystem and force it into a consistent state
  * @bdev:	blockdevice to lock
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 7057221a46c3..88d45118cc64 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -982,7 +982,7 @@  static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
 	btrfs_sysfs_remove_device(src_device);
 	btrfs_sysfs_update_devid(tgt_device);
 	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &src_device->dev_state))
-		btrfs_scratch_superblocks(fs_info, src_device->bdev,
+		btrfs_scratch_superblocks(fs_info, src_device->bdev_file,
 					  src_device->name->str);
 
 	/* write back the superblocks */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 493e33b4ae94..e12451ff911a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2033,14 +2033,14 @@  static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
 }
 
 static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
-				     struct block_device *bdev, int copy_num)
+				     struct file *bdev_file, int copy_num)
 {
 	struct btrfs_super_block *disk_super;
 	const size_t len = sizeof(disk_super->magic);
 	const u64 bytenr = btrfs_sb_offset(copy_num);
 	int ret;
 
-	disk_super = btrfs_read_disk_super(bdev, bytenr, bytenr);
+	disk_super = btrfs_read_disk_super(file_bdev(bdev_file), bytenr, bytenr);
 	if (IS_ERR(disk_super))
 		return;
 
@@ -2048,26 +2048,29 @@  static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
 	folio_mark_dirty(virt_to_folio(disk_super));
 	btrfs_release_disk_super(disk_super);
 
-	ret = sync_blockdev_range(bdev, bytenr, bytenr + len - 1);
+	ret = filemap_write_and_wait_range(bdev_file->f_mapping,
+					   bytenr, bytenr + len - 1);
 	if (ret)
 		btrfs_warn(fs_info, "error clearing superblock number %d (%d)",
 			copy_num, ret);
 }
 
 void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
-			       struct block_device *bdev,
+			       struct file *bdev_file,
 			       const char *device_path)
 {
+	struct block_device *bdev;
 	int copy_num;
 
-	if (!bdev)
+	if (!bdev_file)
 		return;
 
+	bdev = file_bdev(bdev_file);
 	for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX; copy_num++) {
 		if (bdev_is_zoned(bdev))
 			btrfs_reset_sb_log_zones(bdev, copy_num);
 		else
-			btrfs_scratch_superblock(fs_info, bdev, copy_num);
+			btrfs_scratch_superblock(fs_info, bdev_file, copy_num);
 	}
 
 	/* Notify udev that device has changed */
@@ -2209,7 +2212,7 @@  int btrfs_rm_device(struct btrfs_fs_info *fs_info,
 	 *  just flush the device and let the caller do the final bdev_release.
 	 */
 	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) {
-		btrfs_scratch_superblocks(fs_info, device->bdev,
+		btrfs_scratch_superblocks(fs_info, device->bdev_file,
 					  device->name->str);
 		if (device->bdev) {
 			sync_blockdev(device->bdev);
@@ -2323,7 +2326,7 @@  void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
 
 	mutex_unlock(&fs_devices->device_list_mutex);
 
-	btrfs_scratch_superblocks(tgtdev->fs_info, tgtdev->bdev,
+	btrfs_scratch_superblocks(tgtdev->fs_info, tgtdev->bdev_file,
 				  tgtdev->name->str);
 
 	btrfs_close_bdev(tgtdev);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2ef78d3cc4c3..1d566f40b83d 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -818,7 +818,7 @@  struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);
 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
 					struct btrfs_device *failing_dev);
 void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
-			       struct block_device *bdev,
+			       struct file *bdev_file,
 			       const char *device_path);
 
 enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags);
diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c
index 56b870d9cc0d..1c86ec2465b7 100644
--- a/fs/exfat/fatent.c
+++ b/fs/exfat/fatent.c
@@ -296,7 +296,7 @@  int exfat_zeroed_cluster(struct inode *dir, unsigned int clu)
 	}
 
 	if (IS_DIRSYNC(dir))
-		return sync_blockdev_range(sb->s_bdev,
+		return filemap_write_and_wait_range(sb->s_bdev_file->f_mapping,
 				EXFAT_BLK_TO_B(blknr, sb),
 				EXFAT_BLK_TO_B(last_blknr, sb) - 1);
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9e96811c8915..c510f334c84f 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1527,7 +1527,6 @@  unsigned int block_size(struct block_device *bdev);
 #ifdef CONFIG_BLOCK
 void invalidate_bdev(struct block_device *bdev);
 int sync_blockdev(struct block_device *bdev);
-int sync_blockdev_range(struct block_device *bdev, loff_t lstart, loff_t lend);
 void sync_bdevs(bool wait);
 void bdev_statx_dioalign(struct inode *inode, struct kstat *stat);
 void printk_all_partitions(void);