From 0f42b388432c4b898857660197ef13a40a82cd9d Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 17 Sep 2018 16:42:28 -0500 Subject: [PATCH] LU-11380 mdc: move empty xattr handling to mdc layer Extract duplicated logic around empty xattr handling from several places in llite and consolidate it in mdc_getxattr(). Signed-off-by: John L. Hammond Change-Id: I55b9653375a3cf2e6d9d3903743f2aa50ca2e322 Reviewed-on: https://review.whamcloud.com/33198 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Mike Pershin Reviewed-by: Emoly Liu Reviewed-by: Oleg Drokin --- lustre/llite/file.c | 14 ++++++------- lustre/llite/xattr.c | 43 ++++++---------------------------------- lustre/llite/xattr26.c | 43 ++++++---------------------------------- lustre/mdc/mdc_request.c | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 66 insertions(+), 85 deletions(-) diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 157bd4b..8007956 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -4914,7 +4914,6 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) { struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req; - struct mdt_body *body; void *lvbdata; void *lmm; int lmmsize; @@ -4934,17 +4933,16 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) * layout here. Please note that we can't use the LVB buffer in * completion AST because it doesn't have a large enough buffer */ rc = ll_get_default_mdsize(sbi, &lmmsize); - if (rc == 0) - rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), - OBD_MD_FLXATTR, XATTR_NAME_LOV, lmmsize, &req); if (rc < 0) RETURN(rc); - body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); - if (body == NULL) - GOTO(out, rc = -EPROTO); + rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), OBD_MD_FLXATTR, + XATTR_NAME_LOV, lmmsize, &req); + if (rc < 0) + RETURN(rc); - lmmsize = body->mbo_eadatasize; + lmmsize = rc; + rc = 0; if (lmmsize == 0) /* empty layout */ GOTO(out, rc = 0); diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index 7d98825..97f9725 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -343,7 +343,6 @@ int ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer, struct ll_inode_info *lli = ll_i2info(inode); struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; - struct mdt_body *body; void *xdata; int rc; ENTRY; @@ -375,50 +374,20 @@ getxattr_nocache: if (rc < 0) GOTO(out_xattr, rc); - body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); - LASSERT(body); - /* only detect the xattr size */ - if (size == 0) { - /* LU-11109: Older MDTs do not distinguish - * between nonexistent xattrs and zero length - * values in this case. Newer MDTs will return - * -ENODATA or set OBD_MD_FLXATTR. */ - GOTO(out, rc = body->mbo_eadatasize); - } + if (size == 0) + GOTO(out, rc); - if (size < body->mbo_eadatasize) { - CERROR("server bug: replied size %u > %u\n", - body->mbo_eadatasize, (int)size); + if (size < rc) GOTO(out, rc = -ERANGE); - } - - if (body->mbo_eadatasize == 0) { - /* LU-11109: Newer MDTs set OBD_MD_FLXATTR on - * success so that we can distinguish between - * zero length value and nonexistent xattr. - * - * If OBD_MD_FLXATTR is not set then we keep - * the old behavior and return -ENODATA for - * getxattr() when mbo_eadatasize is 0. But - * -ENODATA only makes sense for getxattr() - * and not for listxattr(). */ - if (body->mbo_valid & OBD_MD_FLXATTR) - GOTO(out, rc = 0); - else if (valid == OBD_MD_FLXATTR) - GOTO(out, rc = -ENODATA); - else - GOTO(out, rc = 0); - } /* do not need swab xattr data */ xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA, - body->mbo_eadatasize); + rc); if (!xdata) - GOTO(out, rc = -EFAULT); + GOTO(out, rc = -EPROTO); - memcpy(buffer, xdata, body->mbo_eadatasize); - rc = body->mbo_eadatasize; + memcpy(buffer, xdata, rc); } EXIT; diff --git a/lustre/llite/xattr26.c b/lustre/llite/xattr26.c index d3e18a5..28772dd 100644 --- a/lustre/llite/xattr26.c +++ b/lustre/llite/xattr26.c @@ -329,7 +329,6 @@ int ll_getxattr_common(struct inode *inode, const char *name, { struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; - struct mdt_body *body; int xattr_type, rc; void *xdata; struct ll_inode_info *lli = ll_i2info(inode); @@ -410,50 +409,20 @@ getxattr_nocache: if (rc < 0) GOTO(out_xattr, rc); - body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); - LASSERT(body); - /* only detect the xattr size */ - if (size == 0) { - /* LU-11109: Older MDTs do not distinguish - * between nonexistent xattrs and zero length - * values in this case. Newer MDTs will return - * -ENODATA or set OBD_MD_FLXATTR. */ - GOTO(out, rc = body->mbo_eadatasize); - } + if (size == 0) + GOTO(out, rc); - if (size < body->mbo_eadatasize) { - CERROR("server bug: replied size %u > %u\n", - body->mbo_eadatasize, (int)size); + if (size < rc) GOTO(out, rc = -ERANGE); - } - - if (body->mbo_eadatasize == 0) { - /* LU-11109: Newer MDTs set OBD_MD_FLXATTR on - * success so that we can distinguish between - * zero length value and nonexistent xattr. - * - * If OBD_MD_FLXATTR is not set then we keep - * the old behavior and return -ENODATA for - * getxattr() when mbo_eadatasize is 0. But - * -ENODATA only makes sense for getxattr() - * and not for listxattr(). */ - if (body->mbo_valid & OBD_MD_FLXATTR) - GOTO(out, rc = 0); - else if (valid == OBD_MD_FLXATTR) - GOTO(out, rc = -ENODATA); - else - GOTO(out, rc = 0); - } /* do not need swab xattr data */ xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA, - body->mbo_eadatasize); + rc); if (!xdata) - GOTO(out, rc = -EFAULT); + GOTO(out, rc = -EPROTO); - memcpy(buffer, xdata, body->mbo_eadatasize); - rc = body->mbo_eadatasize; + memcpy(buffer, xdata, rc); } EXIT; diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index bd723d4..bb53e0a 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -435,12 +435,57 @@ static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid, u64 obd_md_valid, const char *name, size_t buf_size, struct ptlrpc_request **req) { + struct mdt_body *body; + int rc; + LASSERT(obd_md_valid == OBD_MD_FLXATTR || obd_md_valid == OBD_MD_FLXATTRLS); - return mdc_xattr_common(exp, &RQF_MDS_GETXATTR, fid, MDS_GETXATTR, - obd_md_valid, name, NULL, 0, buf_size, 0, -1, - req); + rc = mdc_xattr_common(exp, &RQF_MDS_GETXATTR, fid, MDS_GETXATTR, + obd_md_valid, name, NULL, 0, buf_size, 0, -1, + req); + if (rc < 0) + GOTO(out, rc); + + body = req_capsule_server_get(&(*req)->rq_pill, &RMF_MDT_BODY); + if (body == NULL) + GOTO(out, rc = -EPROTO); + + /* only detect the xattr size */ + if (buf_size == 0) { + /* LU-11109: Older MDTs do not distinguish + * between nonexistent xattrs and zero length + * values in this case. Newer MDTs will return + * -ENODATA or set OBD_MD_FLXATTR. */ + GOTO(out, rc = body->mbo_eadatasize); + } + + if (body->mbo_eadatasize == 0) { + /* LU-11109: Newer MDTs set OBD_MD_FLXATTR on + * success so that we can distinguish between + * zero length value and nonexistent xattr. + * + * If OBD_MD_FLXATTR is not set then we keep + * the old behavior and return -ENODATA for + * getxattr() when mbo_eadatasize is 0. But + * -ENODATA only makes sense for getxattr() + * and not for listxattr(). */ + if (body->mbo_valid & OBD_MD_FLXATTR) + GOTO(out, rc = 0); + else if (obd_md_valid == OBD_MD_FLXATTR) + GOTO(out, rc = -ENODATA); + else + GOTO(out, rc = 0); + } + + GOTO(out, rc = body->mbo_eadatasize); +out: + if (rc < 0) { + ptlrpc_req_finished(*req); + *req = NULL; + } + + return rc; } #ifdef CONFIG_FS_POSIX_ACL -- 1.8.3.1