bcachefs: Don't use sha256 for siphash str hash key
With the refactoring that's coming to add fuse support, we want bch2_hash_info_init() to be cheaper so we don't have to rely on anything cached besides the inode in the btree. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
bd09d26897
commit
73501ab82c
@ -1318,6 +1318,7 @@ enum bch_sb_features {
|
||||
BCH_FEATURE_EC = 4,
|
||||
BCH_FEATURE_JOURNAL_SEQ_BLACKLIST_V3 = 5,
|
||||
BCH_FEATURE_REFLINK = 6,
|
||||
BCH_FEATURE_NEW_SIPHASH = 7,
|
||||
BCH_FEATURE_NR,
|
||||
};
|
||||
|
||||
@ -1344,11 +1345,19 @@ enum bch_csum_opts {
|
||||
BCH_CSUM_OPT_NR = 3,
|
||||
};
|
||||
|
||||
enum bch_str_hash_opts {
|
||||
enum bch_str_hash_type {
|
||||
BCH_STR_HASH_CRC32C = 0,
|
||||
BCH_STR_HASH_CRC64 = 1,
|
||||
BCH_STR_HASH_SIPHASH = 2,
|
||||
BCH_STR_HASH_NR = 3,
|
||||
BCH_STR_HASH_SIPHASH_OLD = 2,
|
||||
BCH_STR_HASH_SIPHASH = 3,
|
||||
BCH_STR_HASH_NR = 4,
|
||||
};
|
||||
|
||||
enum bch_str_hash_opts {
|
||||
BCH_STR_HASH_OPT_CRC32C = 0,
|
||||
BCH_STR_HASH_OPT_CRC64 = 1,
|
||||
BCH_STR_HASH_OPT_SIPHASH = 2,
|
||||
BCH_STR_HASH_OPT_NR = 3,
|
||||
};
|
||||
|
||||
#define BCH_COMPRESSION_TYPES() \
|
||||
|
@ -6,8 +6,7 @@
|
||||
#include "error.h"
|
||||
#include "extents.h"
|
||||
#include "inode.h"
|
||||
#include "io.h"
|
||||
#include "keylist.h"
|
||||
#include "str_hash.h"
|
||||
|
||||
#include <linux/random.h>
|
||||
|
||||
@ -303,11 +302,13 @@ void bch2_inode_init(struct bch_fs *c, struct bch_inode_unpacked *inode_u,
|
||||
struct bch_inode_unpacked *parent)
|
||||
{
|
||||
s64 now = bch2_current_time(c);
|
||||
enum bch_str_hash_type str_hash =
|
||||
bch2_str_hash_opt_to_type(c, c->opts.str_hash);
|
||||
|
||||
memset(inode_u, 0, sizeof(*inode_u));
|
||||
|
||||
/* ick */
|
||||
inode_u->bi_flags |= c->opts.str_hash << INODE_STR_HASH_OFFSET;
|
||||
inode_u->bi_flags |= str_hash << INODE_STR_HASH_OFFSET;
|
||||
get_random_bytes(&inode_u->bi_hash_seed,
|
||||
sizeof(inode_u->bi_hash_seed));
|
||||
|
||||
|
@ -127,7 +127,7 @@ enum opt_type {
|
||||
x(str_hash, u8, \
|
||||
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
|
||||
OPT_STR(bch2_str_hash_types), \
|
||||
BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH, \
|
||||
BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_SIPHASH, \
|
||||
NULL, "Hash function for directory entries and xattrs")\
|
||||
x(foreground_target, u16, \
|
||||
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
|
||||
|
@ -14,6 +14,23 @@
|
||||
#include <crypto/hash.h>
|
||||
#include <crypto/sha2.h>
|
||||
|
||||
static inline enum bch_str_hash_type
|
||||
bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt)
|
||||
{
|
||||
switch (opt) {
|
||||
case BCH_STR_HASH_OPT_CRC32C:
|
||||
return BCH_STR_HASH_CRC32C;
|
||||
case BCH_STR_HASH_OPT_CRC64:
|
||||
return BCH_STR_HASH_CRC64;
|
||||
case BCH_STR_HASH_OPT_SIPHASH:
|
||||
return c->sb.features & (1ULL << BCH_FEATURE_NEW_SIPHASH)
|
||||
? BCH_STR_HASH_SIPHASH
|
||||
: BCH_STR_HASH_SIPHASH_OLD;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
struct bch_hash_info {
|
||||
u8 type;
|
||||
union {
|
||||
@ -23,21 +40,16 @@ struct bch_hash_info {
|
||||
};
|
||||
|
||||
static inline struct bch_hash_info
|
||||
bch2_hash_info_init(struct bch_fs *c,
|
||||
const struct bch_inode_unpacked *bi)
|
||||
bch2_hash_info_init(struct bch_fs *c, const struct bch_inode_unpacked *bi)
|
||||
{
|
||||
/* XXX ick */
|
||||
struct bch_hash_info info = {
|
||||
.type = (bi->bi_flags >> INODE_STR_HASH_OFFSET) &
|
||||
~(~0U << INODE_STR_HASH_BITS)
|
||||
~(~0U << INODE_STR_HASH_BITS),
|
||||
.crc_key = bi->bi_hash_seed,
|
||||
};
|
||||
|
||||
switch (info.type) {
|
||||
case BCH_STR_HASH_CRC32C:
|
||||
case BCH_STR_HASH_CRC64:
|
||||
info.crc_key = bi->bi_hash_seed;
|
||||
break;
|
||||
case BCH_STR_HASH_SIPHASH: {
|
||||
if (unlikely(info.type == BCH_STR_HASH_SIPHASH_OLD)) {
|
||||
SHASH_DESC_ON_STACK(desc, c->sha256);
|
||||
u8 digest[SHA256_DIGEST_SIZE];
|
||||
|
||||
@ -46,10 +58,6 @@ bch2_hash_info_init(struct bch_fs *c,
|
||||
crypto_shash_digest(desc, (void *) &bi->bi_hash_seed,
|
||||
sizeof(bi->bi_hash_seed), digest);
|
||||
memcpy(&info.siphash_key, digest, sizeof(info.siphash_key));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
|
||||
return info;
|
||||
@ -73,6 +81,7 @@ static inline void bch2_str_hash_init(struct bch_str_hash_ctx *ctx,
|
||||
case BCH_STR_HASH_CRC64:
|
||||
ctx->crc64 = crc64_be(~0, &info->crc_key, sizeof(info->crc_key));
|
||||
break;
|
||||
case BCH_STR_HASH_SIPHASH_OLD:
|
||||
case BCH_STR_HASH_SIPHASH:
|
||||
SipHash24_Init(&ctx->siphash, &info->siphash_key);
|
||||
break;
|
||||
@ -92,6 +101,7 @@ static inline void bch2_str_hash_update(struct bch_str_hash_ctx *ctx,
|
||||
case BCH_STR_HASH_CRC64:
|
||||
ctx->crc64 = crc64_be(ctx->crc64, data, len);
|
||||
break;
|
||||
case BCH_STR_HASH_SIPHASH_OLD:
|
||||
case BCH_STR_HASH_SIPHASH:
|
||||
SipHash24_Update(&ctx->siphash, data, len);
|
||||
break;
|
||||
@ -108,6 +118,7 @@ static inline u64 bch2_str_hash_end(struct bch_str_hash_ctx *ctx,
|
||||
return ctx->crc32c;
|
||||
case BCH_STR_HASH_CRC64:
|
||||
return ctx->crc64 >> 1;
|
||||
case BCH_STR_HASH_SIPHASH_OLD:
|
||||
case BCH_STR_HASH_SIPHASH:
|
||||
return SipHash24_End(&ctx->siphash) >> 1;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user