mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-15 08:14:21 +08:00
btrfs-progs: add xxhash64 to mkfs
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
2a264c6b0a
commit
f070ece2e9
3
Makefile
3
Makefile
@ -156,7 +156,8 @@ libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
|
|||||||
free-space-tree.o repair.o inode-item.o file-item.o \
|
free-space-tree.o repair.o inode-item.o file-item.o \
|
||||||
kernel-lib/raid56.o kernel-lib/tables.o \
|
kernel-lib/raid56.o kernel-lib/tables.o \
|
||||||
common/device-scan.o common/path-utils.o \
|
common/device-scan.o common/path-utils.o \
|
||||||
common/utils.o libbtrfsutil/subvolume.o libbtrfsutil/stubs.o
|
common/utils.o libbtrfsutil/subvolume.o libbtrfsutil/stubs.o \
|
||||||
|
crypto/hash.o crypto/xxhash.o
|
||||||
libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
|
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/crc32c.h kernel-lib/list.h kerncompat.h \
|
||||||
kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
|
kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
|
||||||
|
@ -315,6 +315,7 @@ static bool is_valid_csum_type(u16 csum_type)
|
|||||||
{
|
{
|
||||||
switch (csum_type) {
|
switch (csum_type) {
|
||||||
case BTRFS_CSUM_TYPE_CRC32:
|
case BTRFS_CSUM_TYPE_CRC32:
|
||||||
|
case BTRFS_CSUM_TYPE_XXHASH:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
16
crypto/hash.c
Normal file
16
crypto/hash.c
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "crypto/hash.h"
|
||||||
|
#include "crypto/xxhash.h"
|
||||||
|
|
||||||
|
int hash_xxhash(const u8 *buf, size_t length, u8 *out)
|
||||||
|
{
|
||||||
|
XXH64_hash_t hash;
|
||||||
|
|
||||||
|
hash = XXH64(buf, length, 0);
|
||||||
|
/*
|
||||||
|
* NOTE: we're not taking the canonical form here but the plain hash to
|
||||||
|
* be compatible with the kernel implementation!
|
||||||
|
*/
|
||||||
|
memcpy(out, &hash, 8);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
10
crypto/hash.h
Normal file
10
crypto/hash.h
Normal file
@ -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
|
1
ctree.c
1
ctree.c
@ -43,6 +43,7 @@ static struct btrfs_csum {
|
|||||||
const char *name;
|
const char *name;
|
||||||
} btrfs_csums[] = {
|
} btrfs_csums[] = {
|
||||||
[BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" },
|
[BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" },
|
||||||
|
[BTRFS_CSUM_TYPE_XXHASH] = { 8, "xxhash64" },
|
||||||
};
|
};
|
||||||
|
|
||||||
u16 btrfs_super_csum_size(const struct btrfs_super_block *sb)
|
u16 btrfs_super_csum_size(const struct btrfs_super_block *sb)
|
||||||
|
1
ctree.h
1
ctree.h
@ -167,6 +167,7 @@ struct btrfs_free_space_ctl;
|
|||||||
/* csum types */
|
/* csum types */
|
||||||
enum btrfs_csum_type {
|
enum btrfs_csum_type {
|
||||||
BTRFS_CSUM_TYPE_CRC32 = 0,
|
BTRFS_CSUM_TYPE_CRC32 = 0,
|
||||||
|
BTRFS_CSUM_TYPE_XXHASH = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BTRFS_EMPTY_DIR_SIZE 0
|
#define BTRFS_EMPTY_DIR_SIZE 0
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "print-tree.h"
|
#include "print-tree.h"
|
||||||
#include "common/rbtree-utils.h"
|
#include "common/rbtree-utils.h"
|
||||||
#include "common/device-scan.h"
|
#include "common/device-scan.h"
|
||||||
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
/* specified errno for check_tree_block */
|
/* specified errno for check_tree_block */
|
||||||
#define BTRFS_BAD_BYTENR (-1)
|
#define BTRFS_BAD_BYTENR (-1)
|
||||||
@ -149,6 +150,8 @@ int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
|
|||||||
crc = crc32c(crc, data, len);
|
crc = crc32c(crc, data, len);
|
||||||
put_unaligned_le32(~crc, out);
|
put_unaligned_le32(~crc, out);
|
||||||
return 0;
|
return 0;
|
||||||
|
case BTRFS_CSUM_TYPE_XXHASH:
|
||||||
|
return hash_xxhash(data, len, out);
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "ERROR: unknown csum type: %d\n", csum_type);
|
fprintf(stderr, "ERROR: unknown csum type: %d\n", csum_type);
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
@ -392,6 +392,9 @@ static enum btrfs_csum_type parse_csum_type(const char *s)
|
|||||||
{
|
{
|
||||||
if (strcasecmp(s, "crc32c") == 0) {
|
if (strcasecmp(s, "crc32c") == 0) {
|
||||||
return BTRFS_CSUM_TYPE_CRC32;
|
return BTRFS_CSUM_TYPE_CRC32;
|
||||||
|
} else if (strcasecmp(s, "xxhash64") == 0 ||
|
||||||
|
strcasecmp(s, "xxhash") == 0) {
|
||||||
|
return BTRFS_CSUM_TYPE_XXHASH;
|
||||||
} else {
|
} else {
|
||||||
error("unknown csum type %s", s);
|
error("unknown csum type %s", s);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user