linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size
@ 2018-02-07  9:19 Nikolay Borisov
  2018-02-07  9:23 ` Qu Wenruo
  2018-02-07  9:32 ` Su Yue
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Borisov @ 2018-02-07  9:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

Currently the function uses a hardcoded value for the checksum size of
a sector. This is fine, given that we currently support only a single
algorithm, whose checksum is 4 bytes == sizeof(u32). Despite not
having other algorithms, btrfs' design supports using a different
algorithm whith different space requirements. To future-proof the code
query the size of the currently used algorithm from the in-memory copy
of the super block. No functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/ordered-data.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 56c4c0ee6381..c53e2cfb72d9 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -151,7 +151,9 @@ static inline int btrfs_ordered_sum_size(struct btrfs_fs_info *fs_info,
 					 unsigned long bytes)
 {
 	int num_sectors = (int)DIV_ROUND_UP(bytes, fs_info->sectorsize);
-	return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32);
+	int csum_size = btrfs_super_csum_size(fs_info->super_copy);
+
+	return sizeof(struct btrfs_ordered_sum) + num_sectors * csum_size;
 }
 
 static inline void
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size
  2018-02-07  9:19 [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size Nikolay Borisov
@ 2018-02-07  9:23 ` Qu Wenruo
  2018-02-07  9:32 ` Su Yue
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-02-07  9:23 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 1382 bytes --]



On 2018年02月07日 17:19, Nikolay Borisov wrote:
> Currently the function uses a hardcoded value for the checksum size of
> a sector. This is fine, given that we currently support only a single
> algorithm, whose checksum is 4 bytes == sizeof(u32). Despite not
> having other algorithms, btrfs' design supports using a different
> algorithm whith different space requirements. To future-proof the code
> query the size of the currently used algorithm from the in-memory copy
> of the super block. No functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

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

Thanks,
Qu

> ---
>  fs/btrfs/ordered-data.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
> index 56c4c0ee6381..c53e2cfb72d9 100644
> --- a/fs/btrfs/ordered-data.h
> +++ b/fs/btrfs/ordered-data.h
> @@ -151,7 +151,9 @@ static inline int btrfs_ordered_sum_size(struct btrfs_fs_info *fs_info,
>  					 unsigned long bytes)
>  {
>  	int num_sectors = (int)DIV_ROUND_UP(bytes, fs_info->sectorsize);
> -	return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32);
> +	int csum_size = btrfs_super_csum_size(fs_info->super_copy);
> +
> +	return sizeof(struct btrfs_ordered_sum) + num_sectors * csum_size;
>  }
>  
>  static inline void
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 520 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size
  2018-02-07  9:19 [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size Nikolay Borisov
  2018-02-07  9:23 ` Qu Wenruo
@ 2018-02-07  9:32 ` Su Yue
  1 sibling, 0 replies; 3+ messages in thread
From: Su Yue @ 2018-02-07  9:32 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs



On 02/07/2018 05:19 PM, Nikolay Borisov wrote:
> Currently the function uses a hardcoded value for the checksum size of
> a sector. This is fine, given that we currently support only a single
> algorithm, whose checksum is 4 bytes == sizeof(u32). Despite not
> having other algorithms, btrfs' design supports using a different
> algorithm whith different space requirements. To future-proof the code
> query the size of the currently used algorithm from the in-memory copy
> of the super block. No functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com>
> ---
>   fs/btrfs/ordered-data.h | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
> index 56c4c0ee6381..c53e2cfb72d9 100644
> --- a/fs/btrfs/ordered-data.h
> +++ b/fs/btrfs/ordered-data.h
> @@ -151,7 +151,9 @@ static inline int btrfs_ordered_sum_size(struct btrfs_fs_info *fs_info,
>   					 unsigned long bytes)
>   {
>   	int num_sectors = (int)DIV_ROUND_UP(bytes, fs_info->sectorsize);
> -	return sizeof(struct btrfs_ordered_sum) + num_sectors * sizeof(u32);
> +	int csum_size = btrfs_super_csum_size(fs_info->super_copy);
> +
> +	return sizeof(struct btrfs_ordered_sum) + num_sectors * csum_size;
>   }
>   
>   static inline void
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-07  9:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-07  9:19 [PATCH] btrfs: Don't hardcode the csum size in btrfs_ordered_sum_size Nikolay Borisov
2018-02-07  9:23 ` Qu Wenruo
2018-02-07  9:32 ` Su Yue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).