diff mbox series

[07/10] btrfs: merge alloc_device helpers

Message ID 2d6e3c341f5ed60f5fe3cffe81ad301f9cdfdee5.1627300614.git.dsterba@suse.com (mailing list archive)
State New, archived
Headers show
Series Misc small cleanups | expand

Commit Message

David Sterba July 26, 2021, 12:15 p.m. UTC
The device allocation is split to two functions, but one just calls the
other and they're very far in the file. Merge them together.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/volumes.c | 66 ++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 41 deletions(-)

Comments

Qu Wenruo July 26, 2021, 12:35 p.m. UTC | #1
On 2021/7/26 下午8:15, David Sterba wrote:
> The device allocation is split to two functions, but one just calls the
> other and they're very far in the file. Merge them together.
>
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>   fs/btrfs/volumes.c | 66 ++++++++++++++++++----------------------------
>   1 file changed, 25 insertions(+), 41 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 19feb64586fc..d98e29556d79 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -430,44 +430,6 @@ void __exit btrfs_cleanup_fs_uuids(void)
>   	}
>   }
>
> -/*
> - * Returns a pointer to a new btrfs_device on success; ERR_PTR() on error.
> - * Returned struct is not linked onto any lists and must be destroyed using
> - * btrfs_free_device.
> - */
> -static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)
> -{
> -	struct btrfs_device *dev;
> -
> -	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> -	if (!dev)
> -		return ERR_PTR(-ENOMEM);
> -
> -	/*
> -	 * Preallocate a bio that's always going to be used for flushing device
> -	 * barriers and matches the device lifespan
> -	 */
> -	dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
> -	if (!dev->flush_bio) {
> -		kfree(dev);
> -		return ERR_PTR(-ENOMEM);
> -	}
> -
> -	INIT_LIST_HEAD(&dev->dev_list);
> -	INIT_LIST_HEAD(&dev->dev_alloc_list);
> -	INIT_LIST_HEAD(&dev->post_commit_list);
> -
> -	atomic_set(&dev->reada_in_flight, 0);
> -	atomic_set(&dev->dev_stats_ccnt, 0);
> -	btrfs_device_data_ordered_init(dev);
> -	INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
> -	INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
> -	extent_io_tree_init(fs_info, &dev->alloc_state,
> -			    IO_TREE_DEVICE_ALLOC_STATE, NULL);
> -
> -	return dev;
> -}
> -
>   static noinline struct btrfs_fs_devices *find_fsid(
>   		const u8 *fsid, const u8 *metadata_fsid)
>   {
> @@ -6856,9 +6818,31 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
>   	if (WARN_ON(!devid && !fs_info))
>   		return ERR_PTR(-EINVAL);
>
> -	dev = __alloc_device(fs_info);
> -	if (IS_ERR(dev))
> -		return dev;
> +	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +	if (!dev)
> +		return ERR_PTR(-ENOMEM);
> +
> +	/*
> +	 * Preallocate a bio that's always going to be used for flushing device
> +	 * barriers and matches the device lifespan
> +	 */
> +	dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
> +	if (!dev->flush_bio) {
> +		kfree(dev);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	INIT_LIST_HEAD(&dev->dev_list);
> +	INIT_LIST_HEAD(&dev->dev_alloc_list);
> +	INIT_LIST_HEAD(&dev->post_commit_list);
> +
> +	atomic_set(&dev->reada_in_flight, 0);
> +	atomic_set(&dev->dev_stats_ccnt, 0);
> +	btrfs_device_data_ordered_init(dev);
> +	INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
> +	INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
> +	extent_io_tree_init(fs_info, &dev->alloc_state,
> +			    IO_TREE_DEVICE_ALLOC_STATE, NULL);
>
>   	if (devid)
>   		tmp = *devid;
>
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 19feb64586fc..d98e29556d79 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -430,44 +430,6 @@  void __exit btrfs_cleanup_fs_uuids(void)
 	}
 }
 
-/*
- * Returns a pointer to a new btrfs_device on success; ERR_PTR() on error.
- * Returned struct is not linked onto any lists and must be destroyed using
- * btrfs_free_device.
- */
-static struct btrfs_device *__alloc_device(struct btrfs_fs_info *fs_info)
-{
-	struct btrfs_device *dev;
-
-	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-	if (!dev)
-		return ERR_PTR(-ENOMEM);
-
-	/*
-	 * Preallocate a bio that's always going to be used for flushing device
-	 * barriers and matches the device lifespan
-	 */
-	dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
-	if (!dev->flush_bio) {
-		kfree(dev);
-		return ERR_PTR(-ENOMEM);
-	}
-
-	INIT_LIST_HEAD(&dev->dev_list);
-	INIT_LIST_HEAD(&dev->dev_alloc_list);
-	INIT_LIST_HEAD(&dev->post_commit_list);
-
-	atomic_set(&dev->reada_in_flight, 0);
-	atomic_set(&dev->dev_stats_ccnt, 0);
-	btrfs_device_data_ordered_init(dev);
-	INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
-	INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
-	extent_io_tree_init(fs_info, &dev->alloc_state,
-			    IO_TREE_DEVICE_ALLOC_STATE, NULL);
-
-	return dev;
-}
-
 static noinline struct btrfs_fs_devices *find_fsid(
 		const u8 *fsid, const u8 *metadata_fsid)
 {
@@ -6856,9 +6818,31 @@  struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info,
 	if (WARN_ON(!devid && !fs_info))
 		return ERR_PTR(-EINVAL);
 
-	dev = __alloc_device(fs_info);
-	if (IS_ERR(dev))
-		return dev;
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return ERR_PTR(-ENOMEM);
+
+	/*
+	 * Preallocate a bio that's always going to be used for flushing device
+	 * barriers and matches the device lifespan
+	 */
+	dev->flush_bio = bio_kmalloc(GFP_KERNEL, 0);
+	if (!dev->flush_bio) {
+		kfree(dev);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	INIT_LIST_HEAD(&dev->dev_list);
+	INIT_LIST_HEAD(&dev->dev_alloc_list);
+	INIT_LIST_HEAD(&dev->post_commit_list);
+
+	atomic_set(&dev->reada_in_flight, 0);
+	atomic_set(&dev->dev_stats_ccnt, 0);
+	btrfs_device_data_ordered_init(dev);
+	INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
+	INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
+	extent_io_tree_init(fs_info, &dev->alloc_state,
+			    IO_TREE_DEVICE_ALLOC_STATE, NULL);
 
 	if (devid)
 		tmp = *devid;