From a50828d1abeae82309f161b1cb2b05b1bf32ba09 Mon Sep 17 00:00:00 2001 From: wangdi Date: Fri, 4 Aug 2006 10:15:10 +0000 Subject: [PATCH] Branch: b_new_cmd 1)add lmv getxattr md method. 2)some fixes about getxattr in mdt and mdc --- lustre/lmv/lmv_obd.c | 64 +++++++++++++++++++++++++++++++++++++++++------ lustre/mdc/mdc_internal.h | 2 +- lustre/mdc/mdc_request.c | 16 +++++++----- lustre/mdt/mdt_xattr.c | 21 +++++++++------- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index b04ddd4..36855fc 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -936,6 +936,59 @@ static int lmv_getstatus(struct obd_export *exp, struct lu_fid *fid) RETURN(rc); } +static int lmv_getxattr(struct obd_export *exp, struct lu_fid *fid, + obd_valid valid, const char *name, + const char *input, int input_size, + int output_size, int flags, + struct ptlrpc_request **request) +{ + struct obd_device *obd = exp->exp_obd; + struct lmv_obd *lmv = &obd->u.lmv; + int rc, i; + ENTRY; + + rc = lmv_check_connect(obd); + if (rc) + RETURN(rc); + + i = lmv_fld_lookup(obd, fid); + if (i < 0) + RETURN(i); + + LASSERT(i < lmv->desc.ld_tgt_count); + + rc = md_getxattr(lmv->tgts[i].ltd_exp, fid, valid, name, + input, input_size, output_size, flags, request); + + RETURN(rc); +} + +static int lmv_setxattr(struct obd_export *exp, struct lu_fid *fid, + obd_valid valid, const char *name, + const char *input, int input_size, + int output_size, int flags, + struct ptlrpc_request **request) +{ + struct obd_device *obd = exp->exp_obd; + struct lmv_obd *lmv = &obd->u.lmv; + int rc, i; + ENTRY; + + rc = lmv_check_connect(obd); + if (rc) + RETURN(rc); + + i = lmv_fld_lookup(obd, fid); + if (i < 0) + RETURN(i); + + LASSERT(i < lmv->desc.ld_tgt_count); + + rc = md_setxattr(lmv->tgts[i].ltd_exp, fid, valid, name, + input, input_size, output_size, flags, request); + + RETURN(rc); +} static int lmv_getattr(struct obd_export *exp, struct lu_fid *fid, obd_valid valid, int ea_size, @@ -1986,8 +2039,7 @@ static int lmv_get_info(struct obd_export *exp, __u32 keylen, } RETURN(-EINVAL); } else if ((keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) || - (keylen == strlen("max_easize") && - !memcmp(key, "max_easize", strlen("max_easize")))) { + (keylen >= strlen("max_easize") && !strcmp(key, "max_easize"))) { rc = lmv_check_connect(obd); if (rc) @@ -1998,11 +2050,7 @@ static int lmv_get_info(struct obd_export *exp, __u32 keylen, rc = obd_get_info(lmv->tgts[0].ltd_exp, keylen, key, vallen, val); RETURN(rc); - } else if (keylen == strlen("max_easize") && - memcmp(key, "max_easize", strlen("max_easize")) == 0) { - - } - /* else if (keylen >= strlen("getext") && !strcmp(key, "getext")) { + } /* else if (keylen >= strlen("getext") && !strcmp(key, "getext")) { struct lmv_tgt_desc *tgts; int i; @@ -2530,11 +2578,13 @@ struct md_ops lmv_md_ops = { .m_done_writing = lmv_done_writing, .m_enqueue = lmv_enqueue, .m_getattr = lmv_getattr, + .m_getxattr = lmv_getxattr, .m_getattr_name = lmv_getattr_name, .m_intent_lock = lmv_intent_lock, .m_link = lmv_link, .m_rename = lmv_rename, .m_setattr = lmv_setattr, + .m_setxattr = lmv_setxattr, .m_sync = lmv_sync, .m_readpage = lmv_readpage, .m_unlink = lmv_unlink, diff --git a/lustre/mdc/mdc_internal.h b/lustre/mdc/mdc_internal.h index 07e3faf..41cea63 100644 --- a/lustre/mdc/mdc_internal.h +++ b/lustre/mdc/mdc_internal.h @@ -149,7 +149,7 @@ int mdc_setxattr(struct obd_export *exp, struct lu_fid *fid, int mdc_getxattr(struct obd_export *exp, struct lu_fid *fid, obd_valid valid, const char *xattr_name, const char *input, int input_size, - int output_size, struct ptlrpc_request **request); + int output_size, int flags, struct ptlrpc_request **request); int mdc_open(struct obd_export *exp, obd_id ino, int type, int flags, struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh, struct ptlrpc_request **); diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index e1cc2d6..67a5534 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -243,7 +243,7 @@ int mdc_xattr_common(struct obd_export *exp, struct lu_fid *fid, { struct ptlrpc_request *req; struct mdt_body *body; - int size[3] = {sizeof(*body)}, bufcnt = 1; + int size[3] = {sizeof(*body)}, bufcnt = 1, offset; int xattr_namelen = 0, rc; void *tmp; ENTRY; @@ -279,13 +279,15 @@ int mdc_xattr_common(struct obd_export *exp, struct lu_fid *fid, /* reply buffers */ if (opcode == MDS_GETXATTR) { size[0] = sizeof(*body); - bufcnt = 1; + bufcnt = 2; + offset = 1; } else { - bufcnt = 0; + bufcnt = 1; + offset = 0; } if (output_size) - size[bufcnt++] = output_size; + size[offset++] = output_size; req->rq_replen = lustre_msg_size(bufcnt, size); /* make rpc */ @@ -330,10 +332,10 @@ int mdc_setxattr(struct obd_export *exp, struct lu_fid *fid, int mdc_getxattr(struct obd_export *exp, struct lu_fid *fid, obd_valid valid, const char *xattr_name, const char *input, int input_size, - int output_size, struct ptlrpc_request **request) + int output_size, int flags, struct ptlrpc_request **request) { return mdc_xattr_common(exp, fid, MDS_GETXATTR, valid, xattr_name, - input, input_size, output_size, 0, request); + input, input_size, output_size, flags, request); } #ifdef CONFIG_FS_POSIX_ACL @@ -1310,6 +1312,8 @@ struct md_ops mdc_md_ops = { .m_link = mdc_link, .m_rename = mdc_rename, .m_setattr = mdc_setattr, + .m_setxattr = mdc_setxattr, + .m_getxattr = mdc_getxattr, .m_sync = mdc_sync, .m_readpage = mdc_readpage, .m_unlink = mdc_unlink, diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index 9b1fe8e..3b57a1e 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -52,7 +52,7 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info) char *xattr_name; __u64 valid = info->mti_body->valid; static const char user_string[] = "user."; - int rc; + int rc, rc1; if (MDT_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK)) return -ENOMEM; @@ -90,9 +90,10 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info) rc = min_t(int, info->mti_body->eadatasize, rc); } req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER, rc); - - rc = req_capsule_pack(pill); - return rc; + + rc1 = req_capsule_pack(pill); + + return rc = !rc1? rc1 : rc; } @@ -119,14 +120,16 @@ int mdt_getxattr(struct mdt_thread_info *info) next = mdt_object_child(info->mti_object); rc = mdt_getxattr_pack_reply(info); - if (rc != 0) + if (rc < 0) RETURN(rc); + + rep_body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY); + /*No EA, just go back*/ + if (rc == 0) + GOTO(no_xattr, rc); buf = req_capsule_server_get(&info->mti_pill, &RMF_EADATA); - rep_body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY); - buflen = req_capsule_get_size(&info->mti_pill, &RMF_EADATA, RCL_SERVER); - if (buflen == 0) - GOTO(no_xattr, rc = 0); + buflen = rc; if (info->mti_body->valid & OBD_MD_FLXATTR) { char *xattr_name = req_capsule_client_get(&info->mti_pill, -- 1.8.3.1