From: Lai Siyao Date: Thu, 25 Oct 2018 21:58:49 +0000 (+0800) Subject: LU-11668 mdt: check parent type in rename/migrate X-Git-Tag: 2.12.0-RC1~7 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=214b12adc315c4adc3c56deb7e790fdc6f0095c8 LU-11668 mdt: check parent type in rename/migrate Check parent existence and type in rename and migrate to avoid potential race. Signed-off-by: Lai Siyao Change-Id: I583e2f5a6f47073601e36c06890a6b22dfc734ad Reviewed-on: https://review.whamcloud.com/33709 Reviewed-by: Andreas Dilger Tested-by: Jenkins Reviewed-by: Bobi Jam Tested-by: Maloo --- diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index a4ea444..b1809dd 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -1275,7 +1275,7 @@ static void mdt_rename_unlock(struct lustre_handle *lh) EXIT; } -static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info, +static struct mdt_object *mdt_parent_find_check(struct mdt_thread_info *info, const struct lu_fid *fid, int idx) { @@ -1293,6 +1293,12 @@ static struct mdt_object *mdt_object_find_check(struct mdt_thread_info *info, if (rc) GOTO(out_put, rc); + if (!mdt_object_exists(dir)) + GOTO(out_put, rc = -ENOENT); + + if (!S_ISDIR(lu_object_attr(&dir->mot_obj))) + GOTO(out_put, rc = -ENOTDIR); + RETURN(dir); out_put: mdt_object_put(info->mti_env, dir); @@ -1966,7 +1972,7 @@ static int mdt_reint_migrate_internal(struct mdt_thread_info *info) RETURN(-EPERM); /* pobj is master object of parent */ - pobj = mdt_object_find_check(info, rr->rr_fid1, 0); + pobj = mdt_parent_find_check(info, rr->rr_fid1, 0); if (IS_ERR(pobj)) RETURN(PTR_ERR(pobj)); @@ -2261,7 +2267,7 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, PFID(rr->rr_fid2), PNAME(&rr->rr_tgt_name)); /* find both parents. */ - msrcdir = mdt_object_find_check(info, rr->rr_fid1, 0); + msrcdir = mdt_parent_find_check(info, rr->rr_fid1, 0); if (IS_ERR(msrcdir)) RETURN(PTR_ERR(msrcdir)); @@ -2271,7 +2277,7 @@ static int mdt_reint_rename_internal(struct mdt_thread_info *info, mtgtdir = msrcdir; mdt_object_get(info->mti_env, mtgtdir); } else { - mtgtdir = mdt_object_find_check(info, rr->rr_fid2, 1); + mtgtdir = mdt_parent_find_check(info, rr->rr_fid2, 1); if (IS_ERR(mtgtdir)) GOTO(out_put_srcdir, rc = PTR_ERR(mtgtdir)); }