From: Lai Siyao Date: Thu, 23 Sep 2021 10:31:06 +0000 (-0400) Subject: LU-14448 lod: verify LOV before set/inherit X-Git-Tag: 2.14.56~150 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=6a08df2d0effc7aa9d2a4428ff38c3b5df73d118 LU-14448 lod: verify LOV before set/inherit DoM layout can only be set as entry in composite layout, and its stripe count should always be 0. Verify LOV before setting and inheriting. Add sanity 270i. Signed-off-by: Lai Siyao Change-Id: I016d1a202960bfebc72dd808de5f80e09051a01e Reviewed-on: https://review.whamcloud.com/45039 Reviewed-by: Mike Pershin Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index ab139b7..3dd8696 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -1653,7 +1653,9 @@ static inline struct lov_comp_md_entry_v1 *comp_entry_v1(struct lov_comp_md_v1 *comp, int i) { LASSERTF((le32_to_cpu(comp->lcm_magic) & ~LOV_MAGIC_DEFINED) == - LOV_USER_MAGIC_COMP_V1, "Wrong magic %x\n", + LOV_USER_MAGIC_COMP_V1 || + (le32_to_cpu(comp->lcm_magic) & ~LOV_MAGIC_DEFINED) == + LOV_USER_MAGIC_SEL, "Wrong magic %x\n", le32_to_cpu(comp->lcm_magic)); LASSERTF(i >= 0 && i < le16_to_cpu(comp->lcm_entry_count), "bad index %d, max = %d\n", @@ -1935,18 +1937,22 @@ int lod_verify_striping(const struct lu_env *env, struct lod_device *d, RETURN(-EINVAL); } - if (magic != LOV_USER_MAGIC_V1 && - magic != LOV_USER_MAGIC_V3 && - magic != LOV_USER_MAGIC_SPECIFIC && - magic != LOV_USER_MAGIC_COMP_V1) { + switch (magic) { + case LOV_USER_MAGIC_FOREIGN: + RETURN(0); + case LOV_USER_MAGIC_V1: + case LOV_USER_MAGIC_V3: + case LOV_USER_MAGIC_SPECIFIC: + RETURN(lod_verify_v1v3(d, buf, is_from_disk)); + case LOV_USER_MAGIC_COMP_V1: + case LOV_USER_MAGIC_SEL: + break; + default: CDEBUG(D_LAYOUT, "bad userland LOV MAGIC: %#x\n", le32_to_cpu(lum->lmm_magic)); RETURN(-EINVAL); } - if (magic != LOV_USER_MAGIC_COMP_V1) - RETURN(lod_verify_v1v3(d, buf, is_from_disk)); - /* magic == LOV_USER_MAGIC_COMP_V1 */ comp_v1 = buf->lb_buf; if (buf->lb_len < le32_to_cpu(comp_v1->lcm_size)) { @@ -2058,8 +2064,10 @@ recheck: else if (rc) RETURN(rc); + if (le16_to_cpu(lum->lmm_stripe_count) == 1) + lum->lmm_stripe_count = 0; /* Any stripe count is forbidden on DoM component */ - if (lum->lmm_stripe_count) { + if (lum->lmm_stripe_count > 0) { CDEBUG(D_LAYOUT, "invalid DoM layout stripe count %u, must be 0\n", le16_to_cpu(lum->lmm_stripe_count)); diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 21d9a03..95319e5 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -5125,6 +5125,8 @@ static int lod_get_default_lov_striping(const struct lu_env *env, ENTRY; + lds->lds_def_striping_set = 0; + rc = lod_get_lov_ea(env, lo); if (rc < 0) RETURN(rc); @@ -5514,7 +5516,12 @@ static void lod_ah_init(const struct lu_env *env, */ if (likely(lp != NULL)) { lod_get_default_striping(env, lp, lds); - + if (lds->lds_def_striping_set) { + rc = lod_verify_striping(env, d, lp, + &info->lti_buf, false); + if (rc) + lds->lds_def_striping_set = 0; + } /* inherit default striping except ROOT */ if ((lds->lds_def_striping_set || lds->lds_dir_def_striping_set) && @@ -5583,8 +5590,12 @@ static void lod_ah_init(const struct lu_env *env, */ if (likely(lp != NULL)) { rc = lod_get_default_lov_striping(env, lp, lds, ah); - if (rc == 0) - lod_striping_from_default(lc, lds, child_mode); + if (rc == 0 && lds->lds_def_striping_set) { + rc = lod_verify_striping(env, d, lp, &info->lti_buf, + false); + if (rc == 0) + lod_striping_from_default(lc, lds, child_mode); + } } /* Initialize lod_device::lod_md_root object reference */ @@ -5614,8 +5625,14 @@ static void lod_ah_init(const struct lu_env *env, lod_need_inherit_more(lc, true, ah->dah_append_pool)) { rc = lod_get_default_lov_striping(env, d->lod_md_root, lds, ah); + if (rc || !lds->lds_def_striping_set) + goto out; + + rc = lod_verify_striping(env, d, d->lod_md_root, &info->lti_buf, + false); if (rc) goto out; + if (lc->ldo_comp_cnt == 0) { lod_striping_from_default(lc, lds, child_mode); } else if (!lds->lds_def_striping_is_composite) { diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index dbb5cc1..308d6a5 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -22055,6 +22055,16 @@ test_270h() { } run_test 270h "DoM: DoM stripe removal when disabled on server" +test_270i() { + (( $MDS1_VERSION >= $(version_code 2.14.54) )) || + skip "Need MDS version at least 2.14.54" + + mkdir $DIR/$tdir + $LFS setstripe -L mdt -S 128k -c -1 $DIR/$tdir && + error "setstripe should fail" || true +} +run_test 270i "DoM: setting invalid DoM striping should fail" + test_271a() { [ $MDS1_VERSION -lt $(version_code 2.10.55) ] && skip "Need MDS version at least 2.10.55"