From eb8452240bce761062d49ff7cbd6398a239d431c Mon Sep 17 00:00:00 2001 From: Fan Yong Date: Thu, 4 Sep 2014 09:37:08 +0800 Subject: [PATCH] LU-5865 lfsck: avoid NULL pointer NOT pass "NULL" as the parameter of @lmv for lfsck_record_lmv(), then the subsequent handling inside lfsck_record_lmv() needs NOT to worry about the case of "lmv == NULL". Signed-off-by: Fan Yong Change-Id: I5f308818edd5ded2c4ccc7d59fb0908791b8aae3 Reviewed-on: http://review.whamcloud.com/12597 Tested-by: Jenkins Reviewed-by: Dmitry Eremin Reviewed-by: Lai Siyao Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/lfsck/lfsck_striped_dir.c | 70 ++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/lustre/lfsck/lfsck_striped_dir.c b/lustre/lfsck/lfsck_striped_dir.c index d0bbd4e..c42d233 100644 --- a/lustre/lfsck/lfsck_striped_dir.c +++ b/lustre/lfsck/lfsck_striped_dir.c @@ -387,7 +387,8 @@ static int lfsck_replace_lmv(const struct lu_env *env, struct lmv_mds_md_v1 *lmv, __u32 index, __u32 flags) { - int rc; + struct lfsck_lmv *llmv = lnr->lnr_lmv; + int rc; rc = lfsck_remove_dirent(env, com, lnr->lnr_obj, &lslr->lslr_fid, index); @@ -396,26 +397,17 @@ static int lfsck_replace_lmv(const struct lu_env *env, lslr->lslr_fid = lnr->lnr_fid; lslr->lslr_flags = flags; - if (lmv != NULL) { - struct lfsck_lmv *llmv = lnr->lnr_lmv; - - lslr->lslr_stripe_count = lmv->lmv_stripe_count; - lslr->lslr_index = lmv->lmv_master_mdt_index; - lslr->lslr_hash_type = lmv->lmv_hash_type; - - if (flags == LSLF_NONE && - llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && + lslr->lslr_stripe_count = lmv->lmv_stripe_count; + lslr->lslr_index = lmv->lmv_master_mdt_index; + lslr->lslr_hash_type = lmv->lmv_hash_type; + if (flags == LSLF_NONE) { + if (llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && lmv_is_known_hash_type(lmv->lmv_hash_type)) llmv->ll_hash_type = lmv->lmv_hash_type; - if (flags == LSLF_NONE && - lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && + if (lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && llmv->ll_max_stripe_count < lslr->lslr_stripe_count) llmv->ll_max_stripe_count = lslr->lslr_stripe_count; - } else { - lslr->lslr_stripe_count = 0; - lslr->lslr_index = 0; - lslr->lslr_hash_type = 0; } return 0; @@ -535,26 +527,22 @@ static int lfsck_record_lmv(const struct lu_env *env, if (fid_is_zero(&lslr->lslr_fid)) { lslr->lslr_fid = *fid; - if (lmv != NULL) { - lslr->lslr_stripe_count = lmv->lmv_stripe_count; - lslr->lslr_index = lmv->lmv_master_mdt_index; - lslr->lslr_hash_type = lmv->lmv_hash_type; - - if (flags == LSLF_NONE && - llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && + lslr->lslr_stripe_count = lmv->lmv_stripe_count; + lslr->lslr_index = lmv->lmv_master_mdt_index; + lslr->lslr_hash_type = lmv->lmv_hash_type; + lslr->lslr_flags = flags; + llmv->ll_stripes_filled++; + if (flags == LSLF_NONE) { + if (llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && lmv_is_known_hash_type(lmv->lmv_hash_type)) llmv->ll_hash_type = lmv->lmv_hash_type; - if (flags == LSLF_NONE && - lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && + if (lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && llmv->ll_max_stripe_count < lslr->lslr_stripe_count) llmv->ll_max_stripe_count = lslr->lslr_stripe_count; } - lslr->lslr_flags = flags; - llmv->ll_stripes_filled++; - if (llmv->ll_max_filled_off < index) llmv->ll_max_filled_off = index; @@ -773,25 +761,18 @@ none: lslr->lslr_fid = *fid; lslr->lslr_flags = flags; - if (lmv != NULL) { - lslr->lslr_stripe_count = lmv->lmv_stripe_count; - lslr->lslr_index = lmv->lmv_master_mdt_index; - lslr->lslr_hash_type = lmv->lmv_hash_type; - - if (flags == LSLF_NONE && - llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && + lslr->lslr_stripe_count = lmv->lmv_stripe_count; + lslr->lslr_index = lmv->lmv_master_mdt_index; + lslr->lslr_hash_type = lmv->lmv_hash_type; + if (flags == LSLF_NONE) { + if (llmv->ll_hash_type == LMV_HASH_TYPE_UNKNOWN && lmv_is_known_hash_type(lmv->lmv_hash_type)) llmv->ll_hash_type = lmv->lmv_hash_type; - if (flags == LSLF_NONE && - lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && + if (lslr->lslr_stripe_count <= LFSCK_LMV_MAX_STRIPES && llmv->ll_max_stripe_count < lslr->lslr_stripe_count) llmv->ll_max_stripe_count = lslr->lslr_stripe_count; - } else { - lslr->lslr_stripe_count = 0; - lslr->lslr_index = 0; - lslr->lslr_hash_type = 0; } break; @@ -2275,9 +2256,12 @@ int lfsck_namespace_handle_striped_master(const struct lu_env *env, dangling: rc = lfsck_namespace_check_exist(env, dir, obj, lnr->lnr_name); - if (rc == 0) - rc = lfsck_record_lmv(env, com, lnr, NULL, stripe, + if (rc == 0) { + memset(lmv, 0, sizeof(*lmv)); + lmv->lmv_magic = LMV_MAGIC; + rc = lfsck_record_lmv(env, com, lnr, lmv, stripe, LSLF_DANGLING, LSLF_NONE, &depth); + } GOTO(out, rc); } -- 1.8.3.1