Re: [PATCH v3 10/12] btrfs-progs: add xxhash64 as checksum algorithm

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 30.08.19 г. 14:32 ч., Johannes Thumshirn wrote:
> From: David Sterba <dsterba@xxxxxxxx>
> 
> Add xxhash64 as another checksumming algorithm.
> 
> Signed-off-by: David Sterba <dsterba@xxxxxxxx>
> Signed-off-by: Johannes Thumshirn <jthumshirn@xxxxxxx>
> 
> ---
> Changes to v2:
> - Integrated comments from Nikolay
> ---
>  Makefile                  |  3 ++-
>  cmds/inspect-dump-super.c | 24 +++++++++++++++---------
>  convert/common.c          |  2 +-
>  convert/main.c            |  2 +-
>  crypto/hash.c             | 16 ++++++++++++++++
>  crypto/hash.h             | 10 ++++++++++
>  crypto/xxhash.c           |  1 -
>  ctree.h                   | 14 ++++++++++----
>  disk-io.c                 |  7 +++++--
>  image/main.c              |  5 +++--
>  mkfs/common.c             | 14 +++++++-------
>  mkfs/main.c               |  6 +++++-
>  12 files changed, 75 insertions(+), 29 deletions(-)
>  create mode 100644 crypto/hash.c
>  create mode 100644 crypto/hash.h
> 
> diff --git a/Makefile b/Makefile
> index 370e0c37ff65..45530749e2b9 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -151,7 +151,8 @@ cmds_objects = cmds/subvolume.o cmds/filesystem.o cmds/device.o cmds/scrub.o \
>  	       mkfs/common.o check/mode-common.o check/mode-lowmem.o
>  libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
>  		   kernel-lib/crc32c.o common/messages.o \
> -		   uuid-tree.o utils-lib.o common/rbtree-utils.o
> +		   uuid-tree.o utils-lib.o common/rbtree-utils.o \
> +		   crypto/hash.o crypto/xxhash.o
>  libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
>  	       kernel-lib/crc32c.h kernel-lib/list.h kerncompat.h \
>  	       kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
> diff --git a/cmds/inspect-dump-super.c b/cmds/inspect-dump-super.c
> index 58bf82b0bbd3..2e2175fe9223 100644
> --- a/cmds/inspect-dump-super.c
> +++ b/cmds/inspect-dump-super.c
> @@ -311,6 +311,17 @@ static void print_readable_super_flag(u64 flag)
>  				     super_flags_num, BTRFS_SUPER_FLAG_SUPP);
>  }
>  
> +static bool is_valid_csum_type(u16 csum_type)
> +{
> +	switch (csum_type) {
> +	case BTRFS_CSUM_TYPE_CRC32:
> +	case BTRFS_CSUM_TYPE_XXHASH:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
>  static void dump_superblock(struct btrfs_super_block *sb, int full)
>  {
>  	int i;
> @@ -326,15 +337,11 @@ static void dump_superblock(struct btrfs_super_block *sb, int full)
>  	csum_type = btrfs_super_csum_type(sb);
>  	csum_size = BTRFS_CSUM_SIZE;
>  	printf("csum_type\t\t%hu (", csum_type);
> -	if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
> +	if (is_valid_csum_type(csum_type)) {

if (!is_valid_csum_type)

>  		printf("INVALID");
>  	} else {
> -		if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
> -			printf("crc32c");
> -			csum_size = btrfs_csum_sizes[csum_type];
> -		} else {
> -			printf("unknown");
> -		}
> +		printf("%s", btrfs_csums[csum_type].name);
> +		csum_size = btrfs_csums[csum_type].size;
>  	}
>  	printf(")\n");
>  	printf("csum_size\t\t%llu\n", (unsigned long long)csum_size);
> @@ -342,8 +349,7 @@ static void dump_superblock(struct btrfs_super_block *sb, int full)
>  	printf("csum\t\t\t0x");
>  	for (i = 0, p = sb->csum; i < csum_size; i++)
>  		printf("%02x", p[i]);
> -	if (csum_type != BTRFS_CSUM_TYPE_CRC32 ||
> -	    csum_size != btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32])
> +	if (is_valid_csum_type(csum_type))

ditto

>  		printf(" [UNKNOWN CSUM TYPE OR SIZE]");
>  	else if (check_csum_sblock(sb, csum_size, csum_type))
>  		printf(" [match]");

<snip>

> diff --git a/crypto/hash.h b/crypto/hash.h
> new file mode 100644
> index 000000000000..45c1ef17bc57
> --- /dev/null
> +++ b/crypto/hash.h
> @@ -0,0 +1,10 @@
> +#ifndef CRYPTO_HASH_H
> +#define CRYPTO_HASH_H
> +
> +#include "../kerncompat.h"
> +
> +#define CRYPTO_HASH_SIZE_MAX	32
> +
> +int hash_xxhash(const u8 *buf, size_t length, u8 *out);
> +
> +#endif
> diff --git a/crypto/xxhash.c b/crypto/xxhash.c
> index 58bb749d3078..7f381c8b56a0 100644
> --- a/crypto/xxhash.c
> +++ b/crypto/xxhash.c
> @@ -1021,5 +1021,4 @@ XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src
>  /* #include "xxh3.h" */
>  
>  
> -

unrelated whitespace fix

>  #endif  /* XXH_NO_LONG_LONG */

<snip>
> 



[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux