diff mbox series

[09/17] btrfs: move btrfs_chunk_item_size out of ctree.h

Message ID 3744e0ae6f8087daa9608174aeee00c53732f8bb.1663167823.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: initial ctree.h cleanups, simple stuff | expand

Commit Message

Josef Bacik Sept. 14, 2022, 3:06 p.m. UTC
This is more of a volumes related helper, additionally it has a BUG_ON()
which isn't defined in the related header.  Move the code to volumes.c,
change the BUG_ON() to an ASSERT(), and move the prototype to volumes.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h   | 7 -------
 fs/btrfs/volumes.c | 7 +++++++
 fs/btrfs/volumes.h | 2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

Comments

Qu Wenruo Sept. 15, 2022, 9:14 a.m. UTC | #1
On 2022/9/14 23:06, Josef Bacik wrote:
> This is more of a volumes related helper, additionally it has a BUG_ON()
> which isn't defined in the related header.  Move the code to volumes.c,
> change the BUG_ON() to an ASSERT(), and move the prototype to volumes.h.

Again a very small function, can it be inlined instead?

Thanks,
Qu
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>   fs/btrfs/ctree.h   | 7 -------
>   fs/btrfs/volumes.c | 7 +++++++
>   fs/btrfs/volumes.h | 2 +-
>   3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 2e6a947a48de..60f8817f5b7c 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -58,13 +58,6 @@ struct btrfs_ioctl_encoded_io_args;
>   
>   #define BTRFS_MAX_EXTENT_SIZE SZ_128M
>   
> -static inline unsigned long btrfs_chunk_item_size(int num_stripes)
> -{
> -	BUG_ON(num_stripes == 0);
> -	return sizeof(struct btrfs_chunk) +
> -		sizeof(struct btrfs_stripe) * (num_stripes - 1);
> -}
> -
>   /*
>    * Runtime (in-memory) states of filesystem
>    */
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 94ba46d57920..b4de4d5ed69f 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -160,6 +160,13 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
>   	},
>   };
>   
> +unsigned long btrfs_chunk_item_size(int num_stripes)
> +{
> +	ASSERT(num_stripes);
> +	return sizeof(struct btrfs_chunk) +
> +		sizeof(struct btrfs_stripe) * (num_stripes - 1);
> +}
> +
>   /*
>    * Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
>    * can be used as index to access btrfs_raid_array[].
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index f19a1cd1bfcf..96a7b437ff20 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -730,5 +730,5 @@ int btrfs_bg_type_to_factor(u64 flags);
>   const char *btrfs_bg_type_to_raid_name(u64 flags);
>   int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
>   bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
> -
> +unsigned long btrfs_chunk_item_size(int num_stripes);
>   #endif
Johannes Thumshirn Sept. 15, 2022, 2:19 p.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Oct. 7, 2022, 5:23 p.m. UTC | #3
On Thu, Sep 15, 2022 at 05:14:14PM +0800, Qu Wenruo wrote:
> 
> 
> On 2022/9/14 23:06, Josef Bacik wrote:
> > This is more of a volumes related helper, additionally it has a BUG_ON()
> > which isn't defined in the related header.  Move the code to volumes.c,
> > change the BUG_ON() to an ASSERT(), and move the prototype to volumes.h.
> 
> Again a very small function, can it be inlined instead?

I agree, such simple helpers it makes sense. The reason here is the
BUG_ON/ASSERT that's now definied in ctree.h so that would require some
more shuffling.

The assert makes some sense but in many cases the value is validated
before use so we might safely drop it.
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2e6a947a48de..60f8817f5b7c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -58,13 +58,6 @@  struct btrfs_ioctl_encoded_io_args;
 
 #define BTRFS_MAX_EXTENT_SIZE SZ_128M
 
-static inline unsigned long btrfs_chunk_item_size(int num_stripes)
-{
-	BUG_ON(num_stripes == 0);
-	return sizeof(struct btrfs_chunk) +
-		sizeof(struct btrfs_stripe) * (num_stripes - 1);
-}
-
 /*
  * Runtime (in-memory) states of filesystem
  */
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 94ba46d57920..b4de4d5ed69f 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -160,6 +160,13 @@  const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 	},
 };
 
+unsigned long btrfs_chunk_item_size(int num_stripes)
+{
+	ASSERT(num_stripes);
+	return sizeof(struct btrfs_chunk) +
+		sizeof(struct btrfs_stripe) * (num_stripes - 1);
+}
+
 /*
  * Convert block group flags (BTRFS_BLOCK_GROUP_*) to btrfs_raid_types, which
  * can be used as index to access btrfs_raid_array[].
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index f19a1cd1bfcf..96a7b437ff20 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -730,5 +730,5 @@  int btrfs_bg_type_to_factor(u64 flags);
 const char *btrfs_bg_type_to_raid_name(u64 flags);
 int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
 bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
-
+unsigned long btrfs_chunk_item_size(int num_stripes);
 #endif