From bb60caa1c6e7c14c201916dc0423442d10c86a27 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 12 May 2021 19:20:04 -0600 Subject: [PATCH 1/1] LU-14459 lmv: change default hash type to crush Change the default hash type to CRUSH to minimize the number of directory entries that need to be migrated. Signed-off-by: Andreas Dilger Change-Id: I75aff45898044be9d12ae1bfad31b4693b3ebbe5 Reviewed-on: https://review.whamcloud.com/43684 Reviewed-by: Lai Siyao Tested-by: jenkins Tested-by: Maloo Reviewed-by: Hongchao Zhang Reviewed-by: Oleg Drokin --- lustre/include/uapi/linux/lustre/lustre_user.h | 2 +- lustre/llite/dir.c | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 723e47f..5bd1693 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -1004,7 +1004,7 @@ static __attribute__((unused)) const char *mdt_hash_name[] = { "crush", }; -#define LMV_HASH_TYPE_DEFAULT LMV_HASH_TYPE_FNV_1A_64 +#define LMV_HASH_TYPE_DEFAULT LMV_HASH_TYPE_CRUSH /* Right now only the lower part(0-16bits) of lmv_hash_type is being used, * and the higher part will be the flag to indicate the status of object, diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index b77a8af..5db622e 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -444,23 +444,17 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump, !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD)) RETURN(-ENOENT); + /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle + * unknown hash if client doesn't set a valid one. switch to fnv_1a_64. + */ if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) { - if ((lump->lum_hash_type & LMV_HASH_TYPE_MASK) == - LMV_HASH_TYPE_CRUSH) { - /* if server doesn't support 'crush' hash type, - * switch to fnv_1a_64. - */ - lump->lum_hash_type &= ~LMV_HASH_TYPE_MASK; - lump->lum_hash_type |= LMV_HASH_TYPE_FNV_1A_64; - } else if ((lump->lum_hash_type & LMV_HASH_TYPE_MASK) == - LMV_HASH_TYPE_UNKNOWN) { - /* from 2.14 MDT will choose default hash type if client - * doesn't set a valid one, while old server doesn't - * handle it. - */ - lump->lum_hash_type &= ~LMV_HASH_TYPE_MASK; - lump->lum_hash_type |= LMV_HASH_TYPE_DEFAULT; - } + enum lmv_hash_type type = lump->lum_hash_type & + LMV_HASH_TYPE_MASK; + + if (type == LMV_HASH_TYPE_CRUSH || + type == LMV_HASH_TYPE_UNKNOWN) + lump->lum_hash_type = (lump->lum_hash_type ^ type) | + LMV_HASH_TYPE_FNV_1A_64; } if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic)))) -- 1.8.3.1