Whamcloud - gitweb
LU-4008 mdt: update mdt_getattr comments about EA sizing
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 0fa9e83..ccbf2a9 100644 (file)
@@ -262,7 +262,7 @@ static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o
         EXIT;
 }
 
-int mdt_getstatus(struct tgt_session_info *tsi)
+static int mdt_getstatus(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        struct mdt_device       *mdt = info->mti_mdt;
@@ -306,7 +306,7 @@ out:
        return rc;
 }
 
-int mdt_statfs(struct tgt_session_info *tsi)
+static int mdt_statfs(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request           *req = tgt_ses_req(tsi);
        struct mdt_thread_info          *info = tsi2mdt_info(tsi);
@@ -481,6 +481,32 @@ void mdt_client_compatibility(struct mdt_thread_info *info)
         EXIT;
 }
 
+int mdt_attr_get_eabuf_size(struct mdt_thread_info *info, struct mdt_object *o)
+{
+       const struct lu_env *env = info->mti_env;
+       int rc, rc2;
+
+       rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
+                         XATTR_NAME_LOV);
+
+       if (rc == -ENODATA)
+               rc = 0;
+
+       if (rc < 0)
+               goto out;
+
+       /* Is it a directory? Let's check for the LMV as well */
+       if (S_ISDIR(lu_object_attr(&mdt_object_child(o)->mo_lu))) {
+               rc2 = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
+                                  XATTR_NAME_LMV);
+               if ((rc2 < 0 && rc2 != -ENODATA) || (rc2 > rc))
+                       rc = rc2;
+       }
+
+out:
+       return rc;
+}
+
 static int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
                             const char *name)
 {
@@ -591,8 +617,8 @@ int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o,
        return rc;
 }
 
-int mdt_attr_get_pfid(struct mdt_thread_info *info,
-                     struct mdt_object *o, struct lu_fid *pfid)
+static int mdt_attr_get_pfid(struct mdt_thread_info *info,
+                            struct mdt_object *o, struct lu_fid *pfid)
 {
        struct lu_buf           *buf = &info->mti_buf;
        struct link_ea_header   *leh;
@@ -767,13 +793,15 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                GOTO(out, rc = 0);
        }
 
-       buffer->lb_len = reqbody->eadatasize;
-       if (buffer->lb_len > 0) {
+       if (reqbody->eadatasize > 0) {
                buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
                if (buffer->lb_buf == NULL)
                        GOTO(out, rc = -EPROTO);
+               buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD,
+                                                     RCL_SERVER);
        } else {
                buffer->lb_buf = NULL;
+               buffer->lb_len = 0;
                ma_need &= ~(MA_LOV | MA_LMV);
                CDEBUG(D_INFO, "%s: RPC from %s: does not need LOVEA.\n",
                       mdt_obd_name(info->mti_mdt),
@@ -860,12 +888,12 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
         if (mdt_body_has_lov(la, reqbody)) {
                 if (ma->ma_valid & MA_LOV) {
                         LASSERT(ma->ma_lmm_size);
-                        mdt_dump_lmm(D_INFO, ma->ma_lmm);
                         repbody->eadatasize = ma->ma_lmm_size;
                         if (S_ISDIR(la->la_mode))
                                 repbody->valid |= OBD_MD_FLDIREA;
                         else
                                 repbody->valid |= OBD_MD_FLEASIZE;
+                        mdt_dump_lmm(D_INFO, ma->ma_lmm, repbody->valid);
                 }
                if (ma->ma_valid & MA_LMV) {
                        LASSERT(S_ISDIR(la->la_mode));
@@ -1026,14 +1054,13 @@ static int mdt_renew_capa(struct mdt_thread_info *info)
         RETURN(rc);
 }
 
-int mdt_getattr(struct tgt_session_info *tsi)
+static int mdt_getattr(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_object       *obj = info->mti_object;
         struct req_capsule      *pill = info->mti_pill;
         struct mdt_body         *reqbody;
         struct mdt_body         *repbody;
-        mode_t                   mode;
         int rc, rc2;
         ENTRY;
 
@@ -1051,13 +1078,36 @@ int mdt_getattr(struct tgt_session_info *tsi)
         LASSERT(obj != NULL);
        LASSERT(lu_object_assert_exists(&obj->mot_obj));
 
-       mode = lu_object_attr(&obj->mot_obj);
+       /* Unlike intent case where we need to pre-fill out buffers early on
+        * in intent policy for ldlm reasons, here we can have a much better
+        * guess at EA size by just reading it from disk.
+        * Exceptions are readdir and (missing) directory striping */
+       /* Readlink */
+       if (reqbody->valid & OBD_MD_LINKNAME) {
+               /* No easy way to know how long is the symlink, but it cannot
+                * be more than PATH_MAX, so we allocate +1 */
+               rc = PATH_MAX + 1;
+
+       /* A special case for fs ROOT: getattr there might fetch
+        * default EA for entire fs, not just for this dir!
+        */
+       } else if (lu_fid_eq(mdt_object_fid(obj),
+                            &info->mti_mdt->mdt_md_root_fid) &&
+                  (reqbody->valid & OBD_MD_FLDIREA) &&
+                  (lustre_msg_get_opc(mdt_info_req(info)->rq_reqmsg) ==
+                                                                MDS_GETATTR)) {
+               /* Should the default strping be bigger, mdt_fix_reply
+                * will reallocate */
+               rc = DEF_REP_MD_SIZE;
+       } else {
+               /* Read the actual EA size from disk */
+               rc = mdt_attr_get_eabuf_size(info, obj);
+       }
+
+       if (rc < 0)
+               GOTO(out_shrink, rc);
 
-       /* old clients may not report needed easize, use max value then */
-       req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
-                            reqbody->eadatasize == 0 ?
-                            info->mti_mdt->mdt_max_mdsize :
-                            reqbody->eadatasize);
+       req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, rc);
 
        rc = req_capsule_server_pack(pill);
        if (unlikely(rc != 0))
@@ -1096,7 +1146,7 @@ out:
        return rc;
 }
 
-int mdt_is_subdir(struct tgt_session_info *tsi)
+static int mdt_is_subdir(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_object     *o = info->mti_object;
@@ -1125,7 +1175,7 @@ int mdt_is_subdir(struct tgt_session_info *tsi)
        RETURN(rc);
 }
 
-int mdt_swap_layouts(struct tgt_session_info *tsi)
+static int mdt_swap_layouts(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info;
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
@@ -1147,6 +1197,10 @@ int mdt_swap_layouts(struct tgt_session_info *tsi)
                RETURN(-EOPNOTSUPP);
 
        info = tsi2mdt_info(tsi);
+
+       if (info->mti_dlm_req != NULL)
+               ldlm_request_cancel(req, info->mti_dlm_req, 0);
+
        if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
                mdt_set_capainfo(info, 0, &info->mti_body->fid1,
                                 req_capsule_client_get(info->mti_pill,
@@ -1278,88 +1332,36 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
         struct lu_name         *lname     = NULL;
         struct mdt_lock_handle *lhp       = NULL;
         struct ldlm_lock       *lock;
-        struct ldlm_res_id     *res_id;
-        int                     is_resent;
-        int                     ma_need = 0;
-        int                     rc;
-
-        ENTRY;
+       bool                    is_resent;
+       bool                    try_layout;
+       int                     ma_need = 0;
+       int                     rc;
+       ENTRY;
 
-        is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
-        LASSERT(ergo(is_resent,
-                     lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
+       is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
+       LASSERT(ergo(is_resent,
+                    lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
 
-        LASSERT(parent != NULL);
+       LASSERT(parent != NULL);
 
-       lname = &info->mti_name;
-       mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
-
-       if (!info->mti_cross_ref) {
-               /*
-                * XXX: Check for anonymous name is for getattr by fid
-                * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
-                * that is the name must contain at least one character and
-                * the terminating '\0'.
-                */
-               if (!lu_name_is_valid(lname)) {
-                       reqbody = req_capsule_client_get(info->mti_pill,
-                                                        &RMF_MDT_BODY);
-                       if (unlikely(reqbody == NULL))
-                               RETURN(err_serious(-EFAULT));
-
-                       if (unlikely(!fid_is_sane(&reqbody->fid2)))
-                               RETURN(err_serious(-EINVAL));
-
-                       CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
-                              "ldlm_rep = %p\n",
-                              PFID(mdt_object_fid(parent)),
-                              PFID(&reqbody->fid2), ldlm_rep);
+       if (info->mti_cross_ref) {
+               /* Only getattr on the child. Parent is on another node. */
+               mdt_set_disposition(info, ldlm_rep,
+                                   DISP_LOOKUP_EXECD | DISP_LOOKUP_POS);
+               child = parent;
+               CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
+                      "ldlm_rep = %p\n",
+                      PFID(mdt_object_fid(child)), ldlm_rep);
+
+               if (is_resent) {
+                       /* Do not take lock for resent case. */
+                       lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
+                       LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
+                                lhc->mlh_reg_lh.cookie);
+                       LASSERT(fid_res_name_eq(mdt_object_fid(child),
+                                               &lock->l_resource->lr_name));
+                       LDLM_LOCK_PUT(lock);
                } else {
-                       CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
-                              "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
-                              PNAME(lname), ldlm_rep);
-               }
-       }
-
-        mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
-
-       if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
-               LU_OBJECT_DEBUG(D_INODE, info->mti_env,
-                               &parent->mot_obj,
-                               "Parent doesn't exist!\n");
-               RETURN(-ESTALE);
-       } else if (!info->mti_cross_ref) {
-               LASSERTF(!mdt_object_remote(parent),
-                        "Parent "DFID" is on remote server\n",
-                        PFID(mdt_object_fid(parent)));
-       }
-
-       if (lu_name_is_valid(lname)) {
-                rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
-                if (rc != 0) {
-                        if (rc > 0)
-                                rc = 0;
-                        RETURN(rc);
-                }
-        }
-
-        if (info->mti_cross_ref) {
-                /* Only getattr on the child. Parent is on another node. */
-                mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-                child = parent;
-                CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
-                       "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
-
-                if (is_resent) {
-                        /* Do not take lock for resent case. */
-                        lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
-                        LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
-                                 lhc->mlh_reg_lh.cookie);
-                        LASSERT(fid_res_name_eq(mdt_object_fid(child),
-                                                &lock->l_resource->lr_name));
-                        LDLM_LOCK_PUT(lock);
-                        rc = 0;
-                } else {
                        mdt_lock_handle_init(lhc);
                        mdt_lock_reg_init(lhc, LCK_PR);
 
@@ -1373,27 +1375,74 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
 
                        rc = mdt_object_lock(info, child, lhc, child_bits,
                                             MDT_LOCAL_LOCK);
+                       if (rc < 0)
+                               RETURN(rc);
                }
-                if (rc == 0) {
-                        /* Finally, we can get attr for child. */
-                       if (!mdt_object_exists(child)) {
-                               LU_OBJECT_DEBUG(D_INFO, info->mti_env,
-                                               &child->mot_obj,
-                                            "remote object doesn't exist.\n");
-                                mdt_object_unlock(info, child, lhc, 1);
-                               RETURN(-ENOENT);
-                       }
 
-                        mdt_set_capainfo(info, 0, mdt_object_fid(child),
-                                         BYPASS_CAPA);
-                        rc = mdt_getattr_internal(info, child, 0);
-                        if (unlikely(rc != 0))
-                                mdt_object_unlock(info, child, lhc, 1);
-                }
+               /* Finally, we can get attr for child. */
+               if (!mdt_object_exists(child)) {
+                       LU_OBJECT_DEBUG(D_INFO, info->mti_env,
+                                       &child->mot_obj,
+                                       "remote object doesn't exist.\n");
+                       mdt_object_unlock(info, child, lhc, 1);
+                       RETURN(-ENOENT);
+               }
+
+               mdt_set_capainfo(info, 0, mdt_object_fid(child), BYPASS_CAPA);
+               rc = mdt_getattr_internal(info, child, 0);
+               if (unlikely(rc != 0))
+                       mdt_object_unlock(info, child, lhc, 1);
+
                 RETURN(rc);
         }
 
+       lname = &info->mti_name;
+       mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
+
        if (lu_name_is_valid(lname)) {
+               CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
+                      "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
+                      PNAME(lname), ldlm_rep);
+       } else {
+               reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
+               if (unlikely(reqbody == NULL))
+                       RETURN(err_serious(-EPROTO));
+
+               *child_fid = reqbody->fid2;
+
+               if (unlikely(!fid_is_sane(child_fid)))
+                       RETURN(err_serious(-EINVAL));
+
+               CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
+                      "ldlm_rep = %p\n",
+                      PFID(mdt_object_fid(parent)),
+                      PFID(&reqbody->fid2), ldlm_rep);
+       }
+
+       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
+
+       if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
+               LU_OBJECT_DEBUG(D_INODE, info->mti_env,
+                               &parent->mot_obj,
+                               "Parent doesn't exist!\n");
+               RETURN(-ESTALE);
+       }
+
+       if (mdt_object_remote(parent)) {
+               CERROR("%s: parent "DFID" is on remote target\n",
+                      mdt_obd_name(info->mti_mdt),
+                      PFID(mdt_object_fid(parent)));
+               RETURN(-EIO);
+       }
+
+       if (lu_name_is_valid(lname)) {
+               rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
+               if (rc != 0) {
+                       if (rc > 0)
+                               rc = 0;
+                       RETURN(rc);
+               }
+
                /* step 1: lock parent only if parent is a directory */
                if (S_ISDIR(lu_object_attr(&parent->mot_obj))) {
                        lhp = &info->mti_lh[MDT_LH_PARENT];
@@ -1409,18 +1458,14 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                 fid_zero(child_fid);
                 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
                                 &info->mti_spec);
+               if (rc == -ENOENT)
+                       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
 
-                if (rc != 0) {
-                        if (rc == -ENOENT)
-                                mdt_set_disposition(info, ldlm_rep,
-                                                    DISP_LOOKUP_NEG);
-                        GOTO(out_parent, rc);
-                } else
-                        mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-        } else {
-                *child_fid = reqbody->fid2;
-                mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
-        }
+               if (rc != 0)
+                       GOTO(out_parent, rc);
+       }
+
+       mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
 
        /*
         *step 3: find the child object by fid & lock it.
@@ -1447,7 +1492,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
                         lhc->mlh_reg_lh.cookie);
 
-               res_id = &lock->l_resource->lr_name;
                if (!fid_res_name_eq(mdt_object_fid(child),
                                     &lock->l_resource->lr_name)) {
                        LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
@@ -1464,14 +1508,12 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                        GOTO(relock, 0);
                }
                LDLM_LOCK_PUT(lock);
-               rc = 0;
        } else {
-               bool try_layout = false;
-
 relock:
                 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
                 mdt_lock_handle_init(lhc);
                mdt_lock_reg_init(lhc, LCK_PR);
+               try_layout = false;
 
                if (!mdt_object_exists(child)) {
                        LU_OBJECT_DEBUG(D_INODE, info->mti_env,
@@ -1553,7 +1595,6 @@ relock:
                 mdt_object_unlock(info, child, lhc, 1);
        } else if (lock) {
                /* Debugging code. */
-               res_id = &lock->l_resource->lr_name;
                LDLM_DEBUG(lock, "Returning lock to client");
                LASSERTF(fid_res_name_eq(mdt_object_fid(child),
                                         &lock->l_resource->lr_name),
@@ -1576,7 +1617,7 @@ out_parent:
 }
 
 /* normal handler: should release the child lock */
-int mdt_getattr_name(struct tgt_session_info *tsi)
+static int mdt_getattr_name(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
         struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
@@ -1617,7 +1658,7 @@ out_shrink:
 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                          void *karg, void *uarg);
 
-int mdt_set_info(struct tgt_session_info *tsi)
+static int mdt_set_info(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        char                    *key;
@@ -1675,7 +1716,7 @@ int mdt_set_info(struct tgt_session_info *tsi)
        RETURN(rc);
 }
 
-int mdt_readpage(struct tgt_session_info *tsi)
+static int mdt_readpage(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = mdt_th_info(tsi->tsi_env);
        struct mdt_object       *object = mdt_obj(tsi->tsi_corpus);
@@ -1764,7 +1805,7 @@ static int mdt_reint_internal(struct mdt_thread_info *info,
         /* for replay (no_create) lmm is not needed, client has it already */
         if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
                 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
-                                     info->mti_rr.rr_eadatalen);
+                                    DEF_REP_MD_SIZE);
 
        /* llog cookies are always 0, the field is kept for compatibility */
         if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
@@ -1841,7 +1882,7 @@ static long mdt_reint_opcode(struct ptlrpc_request *req,
        return opc;
 }
 
-int mdt_reint(struct tgt_session_info *tsi)
+static int mdt_reint(struct tgt_session_info *tsi)
 {
        long opc;
        int  rc;
@@ -1905,7 +1946,7 @@ static int mdt_object_sync(struct mdt_thread_info *info)
         RETURN(rc);
 }
 
-int mdt_sync(struct tgt_session_info *tsi)
+static int mdt_sync(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        struct req_capsule      *pill = tsi->tsi_pill;
@@ -1951,7 +1992,7 @@ int mdt_sync(struct tgt_session_info *tsi)
  * Handle quota control requests to consult current usage/limit, but also
  * to configure quota enforcement
  */
-int mdt_quotactl(struct tgt_session_info *tsi)
+static int mdt_quotactl(struct tgt_session_info *tsi)
 {
        struct obd_export       *exp  = tsi->tsi_exp;
        struct req_capsule      *pill = tsi->tsi_pill;
@@ -2103,7 +2144,7 @@ static int mdt_llog_ctxt_unclone(const struct lu_env *env,
 /*
  * sec context handlers
  */
-int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
+static int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
 {
        int rc;
 
@@ -2125,7 +2166,7 @@ int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
 /*
  * quota request handlers
  */
-int mdt_quota_dqacq(struct tgt_session_info *tsi)
+static int mdt_quota_dqacq(struct tgt_session_info *tsi)
 {
        struct mdt_device       *mdt = mdt_exp2dev(tsi->tsi_exp);
        struct lu_device        *qmt = mdt->mdt_qmt_dev;
@@ -2389,9 +2430,10 @@ static int mdt_object_local_lock(struct mdt_thread_info *info,
                          * want it slowed down due to possible cancels.
                          */
                         policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
-                        rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
-                                          policy, res_id, dlmflags,
-                                          &info->mti_exp->exp_handle.h_cookie);
+                       rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
+                                         policy, res_id, dlmflags,
+                                         info->mti_exp == NULL ? NULL :
+                                         &info->mti_exp->exp_handle.h_cookie);
                         if (unlikely(rc))
                                 RETURN(rc);
                 }
@@ -2410,9 +2452,10 @@ static int mdt_object_local_lock(struct mdt_thread_info *info,
          * going to be sent to client. If it is - mdt_intent_policy() path will
          * fix it up and turn FL_LOCAL flag off.
          */
-        rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
-                          res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
-                          &info->mti_exp->exp_handle.h_cookie);
+       rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
+                         res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
+                         info->mti_exp == NULL ? NULL :
+                         &info->mti_exp->exp_handle.h_cookie);
         if (rc)
                 mdt_object_unlock(info, o, lh, 1);
         else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
@@ -2424,9 +2467,10 @@ static int mdt_object_local_lock(struct mdt_thread_info *info,
         RETURN(rc);
 }
 
-int mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
-                            struct mdt_lock_handle *lh, __u64 ibits,
-                            bool nonblock, int locality)
+static int
+mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
+                        struct mdt_lock_handle *lh, __u64 ibits,
+                        bool nonblock, int locality)
 {
        int rc;
        ENTRY;
@@ -2696,7 +2740,7 @@ static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
                 /* Pack reply. */
                 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
                         req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
-                                             info->mti_body->eadatasize);
+                                            DEF_REP_MD_SIZE);
                 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
                        req_capsule_set_size(pill, &RMF_LOGCOOKIES,
                                             RCL_SERVER, 0);
@@ -2826,7 +2870,7 @@ struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi)
        return mti;
 }
 
-int mdt_tgt_connect(struct tgt_session_info *tsi)
+static int mdt_tgt_connect(struct tgt_session_info *tsi)
 {
        struct ptlrpc_request   *req = tgt_ses_req(tsi);
        int                      rc;
@@ -2953,11 +2997,10 @@ static struct mdt_it_flavor {
        }
 };
 
-int mdt_intent_lock_replace(struct mdt_thread_info *info,
-                            struct ldlm_lock **lockp,
-                            struct ldlm_lock *new_lock,
-                            struct mdt_lock_handle *lh,
-                           __u64 flags)
+static int
+mdt_intent_lock_replace(struct mdt_thread_info *info, struct ldlm_lock **lockp,
+                       struct ldlm_lock *new_lock, struct mdt_lock_handle *lh,
+                       __u64 flags)
 {
         struct ptlrpc_request  *req = mdt_info_req(info);
         struct ldlm_lock       *lock = *lockp;
@@ -3151,7 +3194,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode,
         struct ldlm_lock       *new_lock = NULL;
         __u64                   child_bits;
         struct ldlm_reply      *ldlm_rep;
-        struct ptlrpc_request  *req;
         struct mdt_body        *reqbody;
         struct mdt_body        *repbody;
         int                     rc, rc2;
@@ -3184,7 +3226,6 @@ static int mdt_intent_getattr(enum mdt_it_code opcode,
         if (rc)
                 GOTO(out_shrink, rc);
 
-        req = info->mti_pill->rc_req;
         ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
         mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
 
@@ -3222,8 +3263,7 @@ static int mdt_intent_layout(enum mdt_it_code opcode,
        struct layout_intent *layout;
        struct lu_fid *fid;
        struct mdt_object *obj = NULL;
-       struct md_object *child = NULL;
-       int rc;
+       int rc = 0;
        ENTRY;
 
        if (opcode != MDT_IT_LAYOUT) {
@@ -3240,11 +3280,10 @@ static int mdt_intent_layout(enum mdt_it_code opcode,
                RETURN(PTR_ERR(obj));
 
        if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
-               child = mdt_object_child(obj);
-
                /* get the length of lsm */
-               rc = mo_xattr_get(info->mti_env, child, &LU_BUF_NULL,
-                                 XATTR_NAME_LOV);
+               rc = mdt_attr_get_eabuf_size(info, obj);
+               if (rc < 0)
+                       RETURN(rc);
 
                if (rc > info->mti_mdt->mdt_max_mdsize)
                        info->mti_mdt->mdt_max_mdsize = rc;
@@ -3253,8 +3292,7 @@ static int mdt_intent_layout(enum mdt_it_code opcode,
        mdt_object_put(info->mti_env, obj);
 
        (*lockp)->l_lvb_type = LVB_T_LAYOUT;
-       req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
-                       ldlm_lvbo_size(*lockp));
+       req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER, rc);
        rc = req_capsule_server_pack(info->mti_pill);
        if (rc != 0)
                RETURN(-EINVAL);
@@ -3543,10 +3581,8 @@ static void mdt_seq_fini_cli(struct mdt_device *mdt)
        if (ss == NULL)
                return;
 
-       if (ss->ss_server_seq == NULL)
+       if (ss->ss_server_seq != NULL)
                seq_server_set_cli(NULL, ss->ss_server_seq, NULL);
-
-       return;
 }
 
 static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *mdt)
@@ -3763,7 +3799,6 @@ static int mdt_fld_init(const struct lu_env *env,
 static void mdt_stack_pre_fini(const struct lu_env *env,
                           struct mdt_device *m, struct lu_device *top)
 {
-       struct obd_device       *obd;
        struct lustre_cfg_bufs  *bufs;
        struct lustre_cfg       *lcfg;
        struct mdt_thread_info  *info;
@@ -3778,7 +3813,6 @@ static void mdt_stack_pre_fini(const struct lu_env *env,
 
        LASSERT(m->mdt_child_exp);
        LASSERT(m->mdt_child_exp->exp_obd);
-       obd = m->mdt_child_exp->exp_obd;
 
        /* process cleanup, pass mdt obd name to get obd umount flags */
        /* XXX: this is needed because all layers are referenced by
@@ -4220,8 +4254,9 @@ TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET,
 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION,        mdt_hsm_action),
 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST,
                                                        mdt_hsm_request),
-TGT_MDT_HDL(HABEO_CORPUS|HABEO_REFERO | MUTABOR, MDS_SWAP_LAYOUTS,
-                                                       mdt_swap_layouts)
+TGT_MDT_HDL(HABEO_CLAVIS | HABEO_CORPUS | HABEO_REFERO | MUTABOR,
+           MDS_SWAP_LAYOUTS,
+           mdt_swap_layouts),
 };
 
 static struct tgt_handler mdt_sec_ctx_ops[] = {
@@ -4299,6 +4334,10 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
        struct lfsck_stop        stop;
        ENTRY;
 
+       stop.ls_status = LS_PAUSED;
+       stop.ls_flags = 0;
+       next->md_ops->mdo_iocontrol(env, next, OBD_IOC_STOP_LFSCK, 0, &stop);
+
        target_recovery_fini(obd);
        ping_evictor_stop();
        mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
@@ -4335,10 +4374,6 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
                 m->mdt_nosquash_strlen = 0;
         }
 
-       stop.ls_status = LS_PAUSED;
-       stop.ls_flags = 0;
-       next->md_ops->mdo_iocontrol(env, next, OBD_IOC_STOP_LFSCK, 0, &stop);
-
         mdt_seq_fini(env, m);
         mdt_fld_fini(env, m);
 
@@ -4358,7 +4393,7 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
        EXIT;
 }
 
-int mdt_postrecov(const struct lu_env *, struct mdt_device *);
+static int mdt_postrecov(const struct lu_env *, struct mdt_device *);
 
 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
                      struct lu_device_type *ldt, struct lustre_cfg *cfg)
@@ -5718,7 +5753,7 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         RETURN(rc);
 }
 
-int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
+static int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
 {
         struct lu_device *ld = md2lu_dev(mdt->mdt_child);
         int rc;
@@ -5728,7 +5763,7 @@ int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
         RETURN(rc);
 }
 
-int mdt_obd_postrecov(struct obd_device *obd)
+static int mdt_obd_postrecov(struct obd_device *obd)
 {
         struct lu_env env;
         int rc;
@@ -5894,11 +5929,11 @@ static int __init mdt_mod_init(void)
                GOTO(lu_fini, rc);
 
        lprocfs_mdt_init_vars(&lvars);
-       rc = class_register_type(&mdt_obd_device_ops, NULL, NULL,
+       rc = class_register_type(&mdt_obd_device_ops, NULL, true, NULL,
 #ifndef HAVE_ONLY_PROCFS_SEQ
-                               lvars.module_vars,
+                                lvars.module_vars,
 #endif
-                               LUSTRE_MDT_NAME, &mdt_device_type);
+                                LUSTRE_MDT_NAME, &mdt_device_type);
        if (rc)
                GOTO(mds_fini, rc);
 lu_fini: