From c6a034b746bffc5a11f0c9ec4848d54dea90ca23 Mon Sep 17 00:00:00 2001 From: wang di Date: Sun, 11 May 2014 10:53:27 -0700 Subject: [PATCH] LU-4883 lmv: disable sub-stripe access from .lustre/fid 1. Disable sub-stripe access from .lustre/fid. 2. A few fixes for fid2patch with striped directory. 3. Add sanity 162b to test such cases. Signed-off-by: wang di Change-Id: Ic9372f456d452fbee4a3b05849026422264a00f6 Reviewed-on: http://review.whamcloud.com/10060 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- lustre/lmv/lmv_obd.c | 3 +++ lustre/mdt/mdt_handler.c | 33 ++++++++++++++++++++++++++++++--- lustre/tests/sanity.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 659d3de..c18a68b 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -2832,6 +2832,9 @@ int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp, RETURN(0); } + if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) + RETURN(-EPERM); + /* Unpack memmd */ if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 && le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) { diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 6b0c683..b49e4ae 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -5340,19 +5340,46 @@ static int mdt_path_current(struct mdt_thread_info *info, --ptr; pli->pli_fidcount = 0; pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj); - + *tmpfid = pli->pli_fids[0]; /* root FID only exists on MDT0, and fid2path should also ends at MDT0, * so checking root_fid can only happen on MDT0. */ while (!lu_fid_eq(&mdt->mdt_md_root_fid, &pli->pli_fids[pli->pli_fidcount])) { - mdt_obj = mdt_object_find(info->mti_env, mdt, - &pli->pli_fids[pli->pli_fidcount]); + struct lu_buf lmv_buf; + + mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid); if (IS_ERR(mdt_obj)) GOTO(out, rc = PTR_ERR(mdt_obj)); + if (mdt_object_remote(mdt_obj)) { mdt_object_put(info->mti_env, mdt_obj); GOTO(remote_out, rc = -EREMOTE); } + + lmv_buf.lb_buf = info->mti_xattr_buf; + lmv_buf.lb_len = sizeof(info->mti_xattr_buf); + + /* Check if it is slave stripes */ + rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj), + &lmv_buf, XATTR_NAME_LMV); + if (rc > 0) { + union lmv_mds_md *lmm = lmv_buf.lb_buf; + + /* For slave stripes, get its master */ + if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) { + struct lmv_mds_md_v1 *lmm1 = &lmm->lmv_md_v1; + + fid_le_to_cpu(tmpfid, &lmm1->lmv_master_fid); + if (!fid_is_sane(tmpfid)) { + mdt_object_put(info->mti_env, mdt_obj); + GOTO(out, rc = -EINVAL); + } + mdt_object_put(info->mti_env, mdt_obj); + pli->pli_fids[pli->pli_fidcount] = *tmpfid; + continue; + } + } + if (!mdt_object_exists(mdt_obj)) { mdt_object_put(info->mti_env, mdt_obj); GOTO(out, rc = -ENOENT); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index a22a7d0..c0a039a 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -10217,6 +10217,36 @@ test_162() { } run_test 162 "path lookup sanity" +test_162b() { + [ $PARALLEL == "yes" ] && skip "skip parallel run" && return + [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return + + mkdir $DIR/$tdir + $LFS setdirstripe -i0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir || + error "create striped dir failed" + + local FID=$($LFS getdirstripe $DIR/$tdir/striped_dir | + tail -n 1 | awk '{print $2}') + stat $MOUNT/.lustre/fid/$FID && error "sub_stripe can be accessed" + + touch $DIR/$tdir/striped_dir/f{0..4} || error "touch f0..4 failed" + mkdir $DIR/$tdir/striped_dir/d{0..4} || error "mkdir d0..4 failed" + + # regular file + for ((i=0;i<5;i++)); do + FID=$($LFS path2fid $DIR/$tdir/striped_dir/f$i | tr -d '[]') || + error "get fid for f$i failed" + check_path "$tdir/striped_dir/f$i" $FSNAME $FID --link 0 + + FID=$($LFS path2fid $DIR/$tdir/striped_dir/d$i | tr -d '[]') || + error "get fid for d$i failed" + check_path "$tdir/striped_dir/d$i" $FSNAME $FID --link 0 + done + + return 0 +} +run_test 162b "striped directory path lookup sanity" + test_169() { # do directio so as not to populate the page cache log "creating a 10 Mb file" -- 1.8.3.1