From b09b533b6f443c359e671e7b65208355d5c201dd Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Tue, 28 Jul 2020 14:33:18 +0300 Subject: [PATCH] LU-13599 mdt: fix mti_big_lmm buffer usage The mti_big_lmm buffer can be used just as temporary buffer in some cases. It should drop mti_big_lmm_used flag after that to avoid assertion in mdt_big_attr_get(). This fix is extracted from bigger patch of LU-11025 in master branch. Lustre-change: https://review.whamcloud.com/37284 Lustre-commit: a336d7c7c1cd62a5a5213835aa85b8eaa87b076a Signed-off-by: Mikhail Pershin Change-Id: I3718d6c413ef1d5f8242e548868602ef6476006e Reviewed-on: https://review.whamcloud.com/39521 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Stephane Thiell Reviewed-by: Andreas Dilger Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_handler.c | 44 +++++++++++++++++++++++++++++++++++++++----- lustre/mdt/mdt_internal.h | 2 ++ lustre/mdt/mdt_reint.c | 20 -------------------- lustre/mdt/mdt_xattr.c | 11 ----------- 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index da2547d..54a6b78 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -921,8 +921,8 @@ int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o, RETURN(rc); } -int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, - struct md_attr *ma, const char *name) +int __mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, + struct md_attr *ma, const char *name) { struct md_object *next = mdt_object_child(o); struct lu_buf *buf = &info->mti_buf; @@ -998,6 +998,40 @@ got: return rc; } +int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, + struct md_attr *ma, const char *name) +{ + int rc; + + if (!info->mti_big_lmm) { + OBD_ALLOC(info->mti_big_lmm, PAGE_SIZE); + if (!info->mti_big_lmm) + return -ENOMEM; + info->mti_big_lmmsize = PAGE_SIZE; + } + + if (strcmp(name, XATTR_NAME_LOV) == 0) { + ma->ma_lmm = info->mti_big_lmm; + ma->ma_lmm_size = info->mti_big_lmmsize; + ma->ma_valid &= ~MA_LOV; + } else if (strcmp(name, XATTR_NAME_LMV) == 0) { + ma->ma_lmv = info->mti_big_lmm; + ma->ma_lmv_size = info->mti_big_lmmsize; + ma->ma_valid &= ~MA_LMV; + } else { + LBUG(); + } + + LASSERT(!info->mti_big_lmm_used); + rc = __mdt_stripe_get(info, o, ma, name); + /* since big_lmm is always used here, clear 'used' flag to avoid + * assertion in mdt_big_xattr_get(). + */ + info->mti_big_lmm_used = 0; + + return rc; +} + int mdt_attr_get_pfid(struct mdt_thread_info *info, struct mdt_object *o, struct lu_fid *pfid) { @@ -1082,19 +1116,19 @@ int mdt_attr_get_complex(struct mdt_thread_info *info, } if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) { - rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LOV); + rc = __mdt_stripe_get(info, o, ma, XATTR_NAME_LOV); if (rc) GOTO(out, rc); } if (need & MA_LMV && S_ISDIR(mode)) { - rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LMV); + rc = __mdt_stripe_get(info, o, ma, XATTR_NAME_LMV); if (rc != 0) GOTO(out, rc); } if (need & MA_LMV_DEF && S_ISDIR(mode)) { - rc = mdt_stripe_get(info, o, ma, XATTR_NAME_DEFAULT_LMV); + rc = __mdt_stripe_get(info, o, ma, XATTR_NAME_DEFAULT_LMV); if (rc != 0) GOTO(out, rc); } diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 45c7e8a..86f162a 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -835,6 +835,8 @@ int mdt_attr_get_complex(struct mdt_thread_info *info, struct mdt_object *o, struct md_attr *ma); int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o, const char *name); +int __mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, + struct md_attr *ma, const char *name); int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o, struct md_attr *ma, const char *name); int mdt_attr_get_pfid(struct mdt_thread_info *info, struct mdt_object *o, diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index 74f5a8a..80764c0 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -1739,9 +1739,6 @@ static int mdt_migrate_object_lock(struct mdt_thread_info *info, if (S_ISDIR(lu_object_attr(&obj->mot_obj))) { struct md_attr *ma = &info->mti_attr; - ma->ma_lmv = info->mti_big_lmm; - ma->ma_lmv_size = info->mti_big_lmmsize; - ma->ma_valid = 0; rc = mdt_stripe_get(info, obj, ma, XATTR_NAME_LMV); if (rc) { mdt_object_unlock(info, obj, lh, rc); @@ -2011,16 +2008,6 @@ static int mdt_reint_migrate(struct mdt_thread_info *info, if (IS_ERR(pobj)) GOTO(unlock_rename, rc = PTR_ERR(pobj)); - if (unlikely(!info->mti_big_lmm)) { - info->mti_big_lmmsize = lmv_mds_md_size(64, LMV_MAGIC); - OBD_ALLOC(info->mti_big_lmm, info->mti_big_lmmsize); - if (!info->mti_big_lmm) - GOTO(put_parent, rc = -ENOMEM); - } - - ma->ma_lmv = info->mti_big_lmm; - ma->ma_lmv_size = info->mti_big_lmmsize; - ma->ma_valid = 0; rc = mdt_stripe_get(info, pobj, ma, XATTR_NAME_LMV); if (rc) GOTO(put_parent, rc); @@ -2056,9 +2043,6 @@ static int mdt_reint_migrate(struct mdt_thread_info *info, /* TODO: DoM migration is not supported yet */ if (S_ISREG(lu_object_attr(&sobj->mot_obj))) { - ma->ma_lmm = info->mti_big_lmm; - ma->ma_lmm_size = info->mti_big_lmmsize; - ma->ma_valid = 0; rc = mdt_stripe_get(info, sobj, ma, XATTR_NAME_LOV); if (rc) GOTO(put_source, rc); @@ -2226,10 +2210,6 @@ static int mdt_rename_determine_lock_order(struct mdt_thread_info *info, return 0; /* check whether sobj and tobj are sibling stripes */ - ma->ma_need = MA_LMV; - ma->ma_valid = 0; - ma->ma_lmv = (union lmv_mds_md *)info->mti_xattr_buf; - ma->ma_lmv_size = sizeof(info->mti_xattr_buf); rc = mdt_stripe_get(info, sobj, ma, XATTR_NAME_LMV); if (rc) return rc; diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index 483cd45..132cf87 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -345,14 +345,6 @@ static int mdt_dir_layout_shrink(struct mdt_thread_info *info) mdt->mdt_enable_remote_dir_gid != -1) RETURN(-EPERM); - /* mti_big_lmm is used to save LMV, but it may be uninitialized. */ - if (unlikely(!info->mti_big_lmm)) { - info->mti_big_lmmsize = lmv_mds_md_size(64, LMV_MAGIC); - OBD_ALLOC(info->mti_big_lmm, info->mti_big_lmmsize); - if (!info->mti_big_lmm) - RETURN(-ENOMEM); - } - obj = mdt_object_find(env, mdt, rr->rr_fid1); if (IS_ERR(obj)) RETURN(PTR_ERR(obj)); @@ -396,9 +388,6 @@ static int mdt_dir_layout_shrink(struct mdt_thread_info *info) if (rc) GOTO(unlock_pobj, rc); - ma->ma_lmv = info->mti_big_lmm; - ma->ma_lmv_size = info->mti_big_lmmsize; - ma->ma_valid = 0; rc = mdt_stripe_get(info, obj, ma, XATTR_NAME_LMV); if (rc) GOTO(unlock_obj, rc); -- 1.8.3.1