Whamcloud - gitweb
LU-6047 mdt: remove Size on MDS support
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 0dd6781..cf82eb0 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -362,32 +362,61 @@ out:
        RETURN(rc);
 }
 
-/**
- * Pack SOM attributes into the reply.
- * Call under a DLM UPDATE lock.
+#ifdef CONFIG_FS_POSIX_ACL
+/*
+ * Pack ACL data into the reply. UIDs/GIDs are mapped and filtered by nodemap.
+ *
+ * \param      info    thread info object
+ * \param      repbody reply to pack ACLs into
+ * \param      o       mdt object of file to examine
+ * \param      nodemap nodemap of client to reply to
+ * \retval     0       success
+ * \retval     -errno  error getting or parsing ACL from disk
  */
-static void mdt_pack_size2body(struct mdt_thread_info *info,
-                               struct mdt_object *mo)
+int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody,
+                     struct mdt_object *o, struct lu_nodemap *nodemap)
 {
-        struct mdt_body *b;
-        struct md_attr *ma = &info->mti_attr;
-
-        LASSERT(ma->ma_attr.la_valid & LA_MODE);
-        b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
-
-        /* Check if Size-on-MDS is supported, if this is a regular file,
-         * if SOM is enabled on the object and if SOM cache exists and valid.
-         * Otherwise do not pack Size-on-MDS attributes to the reply. */
-        if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
-            !S_ISREG(ma->ma_attr.la_mode) ||
-            !mdt_object_is_som_enabled(mo) ||
-            !(ma->ma_valid & MA_SOM))
-                return;
+       const struct lu_env     *env = info->mti_env;
+       struct md_object        *next = mdt_object_child(o);
+       struct lu_buf           *buf = &info->mti_buf;
+       int rc;
 
-       b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
-       b->mbo_size = ma->ma_som->msd_size;
-       b->mbo_blocks = ma->ma_som->msd_blocks;
+       buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_ACL);
+       buf->lb_len = req_capsule_get_size(info->mti_pill, &RMF_ACL,
+                                          RCL_SERVER);
+       if (buf->lb_len == 0)
+               return 0;
+
+       rc = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_ACCESS);
+       if (rc < 0) {
+               if (rc == -ENODATA) {
+                       repbody->mbo_aclsize = 0;
+                       repbody->mbo_valid |= OBD_MD_FLACL;
+                       rc = 0;
+               } else if (rc == -EOPNOTSUPP) {
+                       rc = 0;
+               } else {
+                       CERROR("%s: unable to read "DFID" ACL: rc = %d\n",
+                              mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
+               }
+       } else {
+               rc = nodemap_map_acl(nodemap, buf->lb_buf,
+                                    rc, NODEMAP_FS_TO_CLIENT);
+               /* if all ACLs mapped out, rc is still >= 0 */
+               if (rc < 0) {
+                       CERROR("%s: nodemap_map_acl unable to parse "DFID
+                              " ACL: rc = %d\n", mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
+               } else {
+                       repbody->mbo_aclsize = rc;
+                       repbody->mbo_valid |= OBD_MD_FLACL;
+                       rc = 0;
+               }
+       }
+       return rc;
 }
+#endif
 
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
@@ -398,27 +427,60 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
 
        LASSERT(ma->ma_valid & MA_INODE);
 
-       b->mbo_atime      = attr->la_atime;
-       b->mbo_mtime      = attr->la_mtime;
-       b->mbo_ctime      = attr->la_ctime;
-       b->mbo_mode       = attr->la_mode;
-       b->mbo_size       = attr->la_size;
-       b->mbo_blocks     = attr->la_blocks;
-       b->mbo_uid        = nodemap_map_id(nodemap, NODEMAP_UID,
-                                          NODEMAP_FS_TO_CLIENT,
-                                          attr->la_uid);
-       b->mbo_gid        = nodemap_map_id(nodemap, NODEMAP_GID,
-                                          NODEMAP_FS_TO_CLIENT,
-                                          attr->la_gid);
-       b->mbo_flags      = attr->la_flags;
-       b->mbo_nlink      = attr->la_nlink;
-       b->mbo_rdev       = attr->la_rdev;
-
-       /* XXX should pack the reply body according to lu_valid */
-       b->mbo_valid |= OBD_MD_FLCTIME | OBD_MD_FLUID   |
-                       OBD_MD_FLGID   | OBD_MD_FLTYPE  |
-                       OBD_MD_FLMODE  | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
-                       OBD_MD_FLATIME | OBD_MD_FLMTIME ;
+       if (attr->la_valid & LA_ATIME) {
+               b->mbo_atime = attr->la_atime;
+               b->mbo_valid |= OBD_MD_FLATIME;
+       }
+       if (attr->la_valid & LA_MTIME) {
+               b->mbo_mtime = attr->la_mtime;
+               b->mbo_valid |= OBD_MD_FLMTIME;
+       }
+       if (attr->la_valid & LA_CTIME) {
+               b->mbo_ctime = attr->la_ctime;
+               b->mbo_valid |= OBD_MD_FLCTIME;
+       }
+       if (attr->la_valid & LA_FLAGS) {
+               b->mbo_flags = attr->la_flags;
+               b->mbo_valid |= OBD_MD_FLFLAGS;
+       }
+       if (attr->la_valid & LA_NLINK) {
+               b->mbo_nlink = attr->la_nlink;
+               b->mbo_valid |= OBD_MD_FLNLINK;
+       }
+       if (attr->la_valid & LA_UID) {
+               b->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
+                                           NODEMAP_FS_TO_CLIENT,
+                                           attr->la_uid);
+               b->mbo_valid |= OBD_MD_FLUID;
+       }
+       if (attr->la_valid & LA_GID) {
+               b->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
+                                           NODEMAP_FS_TO_CLIENT,
+                                           attr->la_gid);
+               b->mbo_valid |= OBD_MD_FLGID;
+       }
+       b->mbo_mode = attr->la_mode;
+       if (attr->la_valid & LA_MODE)
+               b->mbo_valid |= OBD_MD_FLMODE;
+       if (attr->la_valid & LA_TYPE)
+               b->mbo_valid |= OBD_MD_FLTYPE;
+
+       if (fid != NULL) {
+               b->mbo_fid1 = *fid;
+               b->mbo_valid |= OBD_MD_FLID;
+               CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, valid="LPX64"\n",
+                      PFID(fid), b->mbo_nlink, b->mbo_mode, b->mbo_valid);
+       }
+
+       if (info != NULL)
+               mdt_body_reverse_idmap(info, b);
+
+       if (!(attr->la_valid & LA_TYPE))
+               return;
+
+       b->mbo_rdev   = attr->la_rdev;
+       b->mbo_size   = attr->la_size;
+       b->mbo_blocks = attr->la_blocks;
 
        if (!S_ISREG(attr->la_mode)) {
                b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
@@ -443,17 +505,6 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
        }
 
-       if (fid) {
-               b->mbo_fid1 = *fid;
-               b->mbo_valid |= OBD_MD_FLID;
-               CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
-                               PFID(fid), b->mbo_nlink,
-                      b->mbo_mode, b->mbo_size);
-       }
-
-       if (info)
-               mdt_body_reverse_idmap(info, b);
-
        if (fid != NULL && (b->mbo_valid & OBD_MD_FLSIZE))
                CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
                       PFID(fid), (unsigned long long)b->mbo_size);
@@ -491,7 +542,8 @@ 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)
+static 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;
@@ -735,19 +787,6 @@ int mdt_attr_get_complex(struct mdt_thread_info *info,
                        GOTO(out, rc);
        }
 
-       if (need & MA_SOM && S_ISREG(mode)) {
-               buf->lb_buf = info->mti_xattr_buf;
-               buf->lb_len = sizeof(info->mti_xattr_buf);
-               CLASSERT(sizeof(struct som_attrs) <=
-                        sizeof(info->mti_xattr_buf));
-               rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
-               rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
-               if (rc2 == 0)
-                       ma->ma_valid |= MA_SOM;
-               else if (rc2 < 0 && rc2 != -ENODATA)
-                       GOTO(out, rc = rc2);
-       }
-
        if (need & MA_HSM && S_ISREG(mode)) {
                buf->lb_buf = info->mti_xattr_buf;
                buf->lb_len = sizeof(info->mti_xattr_buf);
@@ -862,8 +901,6 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                 ma->ma_need |= MA_LOV_DEF;
         }
         ma->ma_need |= ma_need;
-        if (ma->ma_need & MA_SOM)
-                ma->ma_som = &info->mti_u.som.data;
 
        rc = mdt_attr_get_complex(info, o, ma);
        if (unlikely(rc)) {
@@ -1006,43 +1043,8 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
        }
 #ifdef CONFIG_FS_POSIX_ACL
        else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
-                (reqbody->mbo_valid & OBD_MD_FLACL)) {
-                buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
-                buffer->lb_len = req_capsule_get_size(pill,
-                                                      &RMF_ACL, RCL_SERVER);
-                if (buffer->lb_len > 0) {
-                        rc = mo_xattr_get(env, next, buffer,
-                                          XATTR_NAME_ACL_ACCESS);
-                        if (rc < 0) {
-                                if (rc == -ENODATA) {
-                                       repbody->mbo_aclsize = 0;
-                                       repbody->mbo_valid |= OBD_MD_FLACL;
-                                        rc = 0;
-                                } else if (rc == -EOPNOTSUPP) {
-                                        rc = 0;
-                               } else {
-                                       CERROR("%s: unable to read "DFID
-                                              " ACL: rc = %d\n",
-                                              mdt_obd_name(info->mti_mdt),
-                                              PFID(mdt_object_fid(o)), rc);
-                               }
-                        } else {
-                               rc = nodemap_map_acl(nodemap, buffer->lb_buf,
-                                                    rc, NODEMAP_FS_TO_CLIENT);
-                               /* if all ACLs mapped out, rc is still >= 0 */
-                               if (rc < 0) {
-                                       CERROR("%s: nodemap_map_acl unable to"
-                                              " parse "DFID" ACL: rc = %d\n",
-                                              mdt_obd_name(info->mti_mdt),
-                                              PFID(mdt_object_fid(o)), rc);
-                               } else {
-                                       repbody->mbo_aclsize = rc;
-                                       repbody->mbo_valid |= OBD_MD_FLACL;
-                                       rc = 0;
-                               }
-                       }
-               }
-       }
+                (reqbody->mbo_valid & OBD_MD_FLACL))
+               rc = mdt_pack_acl2body(info, repbody, o, nodemap);
 #endif
 
        if (reqbody->mbo_valid & OBD_MD_FLMDSCAPA &&
@@ -1190,6 +1192,32 @@ out:
        return rc;
 }
 
+/**
+ * Exchange MOF_LOV_CREATED flags between two objects after a
+ * layout swap. No assumption is made on whether o1 or o2 have
+ * created objects or not.
+ *
+ * \param[in,out] o1   First swap layout object
+ * \param[in,out] o2   Second swap layout object
+ */
+static void mdt_swap_lov_flag(struct mdt_object *o1, struct mdt_object *o2)
+{
+       __u64   o1_flags;
+
+       mutex_lock(&o1->mot_lov_mutex);
+       mutex_lock(&o2->mot_lov_mutex);
+
+       o1_flags = o1->mot_flags;
+       o1->mot_flags = (o1->mot_flags & ~MOF_LOV_CREATED) |
+                       (o2->mot_flags & MOF_LOV_CREATED);
+
+       o2->mot_flags = (o2->mot_flags & ~MOF_LOV_CREATED) |
+                       (o1_flags & MOF_LOV_CREATED);
+
+       mutex_unlock(&o2->mot_lov_mutex);
+       mutex_unlock(&o1->mot_lov_mutex);
+}
+
 static int mdt_swap_layouts(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info;
@@ -1275,7 +1303,11 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi)
 
        rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
                             mdt_object_child(o2), msl->msl_flags);
-       GOTO(unlock2, rc);
+       if (rc < 0)
+               GOTO(unlock2, rc);
+
+       mdt_swap_lov_flag(o1, o2);
+
 unlock2:
        mdt_object_unlock(info, o2, lh2, rc);
 unlock1:
@@ -1288,43 +1320,32 @@ out:
 }
 
 static int mdt_raw_lookup(struct mdt_thread_info *info,
-                          struct mdt_object *parent,
-                          const struct lu_name *lname,
-                          struct ldlm_reply *ldlm_rep)
+                         struct mdt_object *parent,
+                         const struct lu_name *lname,
+                         struct ldlm_reply *ldlm_rep)
 {
-        struct md_object *next = mdt_object_child(info->mti_object);
-        const struct mdt_body *reqbody = info->mti_body;
-        struct lu_fid *child_fid = &info->mti_tmp_fid1;
-        struct mdt_body *repbody;
-        int rc;
-        ENTRY;
-
-       if (reqbody->mbo_valid != OBD_MD_FLID)
-                RETURN(0);
+       struct lu_fid   *child_fid = &info->mti_tmp_fid1;
+       int              rc;
+       ENTRY;
 
-        LASSERT(!info->mti_cross_ref);
+       LASSERT(!info->mti_cross_ref);
 
-        /* Only got the fid of this obj by name */
-        fid_zero(child_fid);
-        rc = mdo_lookup(info->mti_env, next, lname, child_fid,
-                        &info->mti_spec);
-#if 0
-        /* XXX is raw_lookup possible as intent operation? */
-        if (rc != 0) {
-                if (rc == -ENOENT)
-                        mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
-                RETURN(rc);
-        } else
-                mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
+       /* Only got the fid of this obj by name */
+       fid_zero(child_fid);
+       rc = mdo_lookup(info->mti_env, mdt_object_child(info->mti_object),
+                       lname, child_fid, &info->mti_spec);
+       if (rc == 0) {
+               struct mdt_body *repbody;
 
-        repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
-#endif
-        if (rc == 0) {
-                repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
+               repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
                repbody->mbo_fid1 = *child_fid;
                repbody->mbo_valid = OBD_MD_FLID;
-        }
-        RETURN(1);
+               mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
+       } else if (rc == -ENOENT) {
+               mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
+       }
+
+       RETURN(rc);
 }
 
 /*
@@ -1446,10 +1467,15 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
        }
 
        if (lu_name_is_valid(lname)) {
-               rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
-               if (rc != 0) {
-                       if (rc > 0)
-                               rc = 0;
+               /* Always allow to lookup ".." */
+               if (unlikely(lname->ln_namelen == 2 &&
+                            lname->ln_name[0] == '.' &&
+                            lname->ln_name[1] == '.'))
+                       info->mti_spec.sp_permitted = 1;
+
+               if (info->mti_body->mbo_valid == OBD_MD_FLID) {
+                       rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
+
                        RETURN(rc);
                }
 
@@ -1573,11 +1599,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
         }
 
         lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
-        /* Get MA_SOM attributes if update lock is given. */
-        if (lock &&
-            lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
-            S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
-                ma_need |= MA_SOM;
 
         /* finally, we can get attr for child. */
         mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
@@ -1592,8 +1613,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info,
                         "Lock res_id: "DLDLMRES", fid: "DFID"\n",
                         PLDLMRES(lock->l_resource),
                         PFID(mdt_object_fid(child)));
-               if (mdt_object_exists(child) && !mdt_object_remote(child))
-                       mdt_pack_size2body(info, child);
         }
         if (lock)
                 LDLM_LOCK_PUT(lock);
@@ -2352,7 +2371,7 @@ int mdt_check_resent_lock(struct mdt_thread_info *info,
                          struct mdt_lock_handle *lhc)
 {
        /* the lock might already be gotten in ldlm_handle_enqueue() */
-       if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
+       if (unlikely(lustre_handle_is_used(&lhc->mlh_reg_lh))) {
                struct ptlrpc_request *req = mdt_info_req(info);
                struct ldlm_lock      *lock;
 
@@ -2854,6 +2873,7 @@ void mdt_thread_info_init(struct ptlrpc_request *req,
 
         info->mti_spec.no_create = 0;
        info->mti_spec.sp_rm_entry = 0;
+       info->mti_spec.sp_permitted = 0;
 
        info->mti_spec.u.sp_ea.eadata = NULL;
        info->mti_spec.u.sp_ea.eadatalen = 0;
@@ -2920,7 +2940,8 @@ static int mdt_tgt_connect(struct tgt_session_info *tsi)
        if (OBD_FAIL_CHECK(OBD_FAIL_TGT_DELAY_CONDITIONAL) &&
            cfs_fail_val ==
            tsi2mdt_info(tsi)->mti_mdt->mdt_seq_site.ss_node_id)
-               schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, HZ * 3);
+               schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE,
+                       msecs_to_jiffies(3 * MSEC_PER_SEC));
 
        rc = tgt_connect(tsi);
        if (rc != 0)
@@ -3383,8 +3404,8 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
 
        /* the open lock or the lock for cross-ref object should be
         * returned to the client */
-       if (rc == -MDT_EREMOTE_OPEN || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
-               LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
+       if (lustre_handle_is_used(&lhc->mlh_reg_lh) &&
+           (rc == 0 || rc == -MDT_EREMOTE_OPEN)) {
                rep->lock_policy_res2 = 0;
                rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
                RETURN(rc);
@@ -3396,6 +3417,7 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
             mdt_get_disposition(rep, DISP_LOOKUP_NEG))
                 rep->lock_policy_res2 = 0;
 
+       lhc->mlh_reg_lh.cookie = 0ull;
         if (rc == -ENOTCONN || rc == -ENODEV ||
             rc == -EOVERFLOW) { /**< if VBR failure then return error */
                 /*
@@ -3404,28 +3426,13 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
                  * will detect this, then disconnect, reconnect the import
                  * immediately, instead of impacting the following the rpc.
                  */
-                lhc->mlh_reg_lh.cookie = 0ull;
                 RETURN(rc);
-        } else {
-                /*
-                 * For other cases, the error will be returned by intent.
-                 * and client will retrieve the result from intent.
-                 */
-                 /*
-                  * FIXME: when open lock is finished, that should be
-                  * checked here.
-                  */
-                if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
-                        LASSERTF(rc == 0, "Error occurred but lock handle "
-                                 "is still in use, rc = %d\n", rc);
-                        rep->lock_policy_res2 = 0;
-                       rc = mdt_intent_lock_replace(info, lockp, lhc, flags);
-                        RETURN(rc);
-                } else {
-                        lhc->mlh_reg_lh.cookie = 0ull;
-                        RETURN(ELDLM_LOCK_ABORTED);
-                }
         }
+       /*
+        * For other cases, the error will be returned by intent, and client
+        * will retrieve the result from intent.
+        */
+       RETURN(ELDLM_LOCK_ABORTED);
 }
 
 static int mdt_intent_code(long itcode)
@@ -3852,10 +3859,9 @@ static void mdt_stack_pre_fini(const struct lu_env *env,
        lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
        lustre_cfg_bufs_set_string(bufs, 1, NULL);
        lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
-       if (!lcfg) {
-               CERROR("%s: cannot alloc lcfg\n", mdt_obd_name(m));
-               return;
-       }
+       if (lcfg == NULL)
+               RETURN_EXIT;
+
        top->ld_ops->ldo_process_config(env, top, lcfg);
        lustre_cfg_free(lcfg);
        EXIT;
@@ -3888,10 +3894,9 @@ static void mdt_stack_fini(const struct lu_env *env,
                strcat(flags, "A");
        lustre_cfg_bufs_set_string(bufs, 1, flags);
        lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
-       if (!lcfg) {
-               CERROR("Cannot alloc lcfg!\n");
-               return;
-       }
+       if (lcfg == NULL)
+               RETURN_EXIT;
+
        LASSERT(top);
        top->ld_ops->ldo_process_config(env, top, lcfg);
        lustre_cfg_free(lcfg);
@@ -4015,7 +4020,7 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
        lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
 
        lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
-       if (!lcfg)
+       if (lcfg == NULL)
                GOTO(free_bufs, rc = -ENOMEM);
 
        rc = class_attach(lcfg);
@@ -4037,6 +4042,8 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
        lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
 
        lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
+       if (lcfg == NULL)
+               GOTO(class_detach, rc = -ENOMEM);
 
        rc = class_setup(obd, lcfg);
        if (rc)
@@ -4143,7 +4150,7 @@ static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
        lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
 
        lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
-       if (!lcfg)
+       if (lcfg == NULL)
                GOTO(cleanup_mem, rc = -ENOMEM);
 
        rc = class_attach(lcfg);
@@ -4168,6 +4175,8 @@ static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
                                   mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
 
        lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
+       if (lcfg == NULL)
+               GOTO(class_detach, rc = -ENOMEM);
 
        rc = class_setup(obd, lcfg);
        if (rc)
@@ -4235,7 +4244,7 @@ static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
 /* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper
  * for now. This will be removed along with converting rest of MDT code
  * to use tgt_session_info */
-int mdt_tgt_getxattr(struct tgt_session_info *tsi)
+static int mdt_tgt_getxattr(struct tgt_session_info *tsi)
 {
        struct mdt_thread_info  *info = tsi2mdt_info(tsi);
        int                      rc;
@@ -4265,8 +4274,6 @@ TGT_MDT_HDL(HABEO_CORPUS,         MDS_GETXATTR,   mdt_tgt_getxattr),
 TGT_MDT_HDL(0          | HABEO_REFERO, MDS_STATFS,     mdt_statfs),
 TGT_MDT_HDL(0          | MUTABOR,      MDS_REINT,      mdt_reint),
 TGT_MDT_HDL(HABEO_CORPUS,              MDS_CLOSE,      mdt_close),
-TGT_MDT_HDL(HABEO_CORPUS,              MDS_DONE_WRITING,
-                                                       mdt_done_writing),
 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO,        MDS_READPAGE,   mdt_readpage),
 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO,        MDS_SYNC,       mdt_sync),
 TGT_MDT_HDL(0,                         MDS_QUOTACTL,   mdt_quotactl),
@@ -4458,8 +4465,6 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
 
         m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
 
-        m->mdt_som_conf = 0;
-
         m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
 
        /* default is coordinator off, it is started through conf_param
@@ -4478,7 +4483,6 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
                obd->u.obt.obt_magic = OBT_MAGIC;
        }
 
-       spin_lock_init(&m->mdt_ioepoch_lock);
         m->mdt_capa_timeout = CAPA_TIMEOUT;
         m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
         m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
@@ -4773,7 +4777,7 @@ static struct lu_object *mdt_object_alloc(const struct lu_env *env,
                lu_object_init(o, h, d);
                lu_object_add_top(h, o);
                o->lo_ops = &mdt_obj_ops;
-               mutex_init(&mo->mot_ioepoch_mutex);
+               spin_lock_init(&mo->mot_write_lock);
                mutex_init(&mo->mot_lov_mutex);
                init_rwsem(&mo->mot_open_sem);
                RETURN(o);
@@ -4824,13 +4828,13 @@ static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
 }
 
 static int mdt_object_print(const struct lu_env *env, void *cookie,
-                            lu_printer_t p, const struct lu_object *o)
+                           lu_printer_t p, const struct lu_object *o)
 {
-        struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
-        return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
-                    "flags="LPX64", epochcount=%d, writecount=%d)",
-                    mdto, mdto->mot_ioepoch, mdto->mot_flags,
-                    mdto->mot_ioepoch_count, mdto->mot_writecount);
+       struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
+
+       return (*p)(env, cookie,
+                   LUSTRE_MDT_NAME"-object@%p(flags=%d, writecount=%d)",
+                   mdto, mdto->mot_flags, mdto->mot_write_count);
 }
 
 static int mdt_prepare(const struct lu_env *env,
@@ -4959,9 +4963,6 @@ static int mdt_connect_internal(struct obd_export *exp,
        if (!mdt->mdt_opts.mo_user_xattr)
                data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
 
-       if (!mdt->mdt_som_conf)
-               data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
-
        if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
                data->ocd_brw_size = min(data->ocd_brw_size,
                                         (__u32)MD_MAX_BRW_SIZE);
@@ -4999,15 +5000,6 @@ static int mdt_connect_internal(struct obd_export *exp,
                return -EBADE;
        }
 
-       if (mdt->mdt_som_conf &&
-           !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
-                                        OBD_CONNECT_MDS_MDS |
-                                        OBD_CONNECT_SOM))) {
-               CWARN("%s: MDS has SOM enabled, but client does not support "
-                     "it\n", mdt_obd_name(mdt));
-               return -EBADE;
-       }
-
        if (OCD_HAS_FLAG(data, PINGLESS)) {
                if (ptlrpc_pinger_suppress_pings()) {
                        spin_lock(&exp->exp_obd->obd_dev_lock);
@@ -5109,7 +5101,7 @@ static int mdt_export_cleanup(struct obd_export *exp)
                         * archive request into a noop if it's not actually
                         * dirty.
                         */
-                       if (mfd->mfd_mode & (FMODE_WRITE|MDS_FMODE_TRUNC))
+                       if (mfd->mfd_mode & FMODE_WRITE)
                                rc = mdt_ctxt_add_dirty_flag(&env, info, mfd);
 
                        /* Don't unlink orphan on failover umount, LU-184 */
@@ -5305,25 +5297,6 @@ static int mdt_destroy_export(struct obd_export *exp)
        RETURN(0);
 }
 
-/** The maximum depth that fid2path() will search.
- * This is limited only because we want to store the fids for
- * historical path lookup purposes.
- */
-#define MAX_PATH_DEPTH 100
-
-/** mdt_path() lookup structure. */
-struct path_lookup_info {
-       __u64                   pli_recno;      /**< history point */
-       __u64                   pli_currec;     /**< current record */
-       struct lu_fid           pli_fid;
-       struct lu_fid           pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
-       struct mdt_object       *pli_mdt_obj;
-       char                    *pli_path;      /**< full path */
-       int                     pli_pathlen;
-       int                     pli_linkno;     /**< which hardlink to follow */
-       int                     pli_fidcount;   /**< number of \a pli_fids */
-};
-
 int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
                   struct linkea_data *ldata)
 {
@@ -5355,8 +5328,21 @@ int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
        return linkea_init(ldata);
 }
 
+/**
+ * Given an MDT object, try to look up the full path to the object.
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in]     info  Per-thread common data shared by MDT level handlers.
+ * \param[in]     obj   Object to do path lookup of
+ * \param[in,out] fp    User-provided struct to store path information
+ *
+ * \retval 0 Lookup successful, path information stored in fp
+ * \retval -EAGAIN Lookup failed, usually because object is being moved
+ * \retval negative errno if there was a problem
+ */
 static int mdt_path_current(struct mdt_thread_info *info,
-                           struct path_lookup_info *pli)
+                           struct mdt_object *obj,
+                           struct getinfo_fid2path *fp)
 {
        struct mdt_device       *mdt = info->mti_mdt;
        struct mdt_object       *mdt_obj;
@@ -5367,8 +5353,9 @@ static int mdt_path_current(struct mdt_thread_info *info,
        struct lu_buf           *buf = &info->mti_big_buf;
        char                    *ptr;
        int                     reclen;
-       struct linkea_data      ldata = { 0 };
+       struct linkea_data      ldata = { NULL };
        int                     rc = 0;
+       bool                    first = true;
        ENTRY;
 
        /* temp buffer for path element, the buffer will be finally freed
@@ -5378,16 +5365,14 @@ static int mdt_path_current(struct mdt_thread_info *info,
                RETURN(-ENOMEM);
 
        ldata.ld_buf = buf;
-       ptr = pli->pli_path + pli->pli_pathlen - 1;
+       ptr = fp->gf_path + fp->gf_pathlen - 1;
        *ptr = 0;
        --ptr;
-       pli->pli_fidcount = 0;
-       pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
-       *tmpfid = pli->pli_fids[0];
+       *tmpfid = fp->gf_fid = *mdt_object_fid(obj);
+
        /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
         * so checking root_fid can only happen on MDT0. */
-       while (!lu_fid_eq(&mdt->mdt_md_root_fid,
-                         &pli->pli_fids[pli->pli_fidcount])) {
+       while (!lu_fid_eq(&mdt->mdt_md_root_fid, &fp->gf_fid)) {
                struct lu_buf           lmv_buf;
 
                mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid);
@@ -5415,18 +5400,17 @@ static int mdt_path_current(struct mdt_thread_info *info,
                linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
                /* If set, use link #linkno for path lookup, otherwise use
                   link #0.  Only do this for the final path element. */
-               if (pli->pli_fidcount == 0 &&
-                   pli->pli_linkno < leh->leh_reccount) {
+               if (first && fp->gf_linkno < leh->leh_reccount) {
                        int count;
-                       for (count = 0; count < pli->pli_linkno; count++) {
+                       for (count = 0; count < fp->gf_linkno; count++) {
                                lee = (struct link_ea_entry *)
                                     ((char *)lee + reclen);
                                linkea_entry_unpack(lee, &reclen, tmpname,
                                                    tmpfid);
                        }
-                       if (pli->pli_linkno < leh->leh_reccount - 1)
+                       if (fp->gf_linkno < leh->leh_reccount - 1)
                                /* indicate to user there are more links */
-                               pli->pli_linkno++;
+                               fp->gf_linkno++;
                }
 
                lmv_buf.lb_buf = info->mti_xattr_buf;
@@ -5440,7 +5424,7 @@ static int mdt_path_current(struct mdt_thread_info *info,
 
                        /* For slave stripes, get its master */
                        if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) {
-                               pli->pli_fids[pli->pli_fidcount] = *tmpfid;
+                               fp->gf_fid = *tmpfid;
                                continue;
                        }
                } else if (rc < 0 && rc != -ENODATA) {
@@ -5451,72 +5435,81 @@ static int mdt_path_current(struct mdt_thread_info *info,
 
                /* Pack the name in the end of the buffer */
                ptr -= tmpname->ln_namelen;
-               if (ptr - 1 <= pli->pli_path)
+               if (ptr - 1 <= fp->gf_path)
                        GOTO(out, rc = -EOVERFLOW);
                strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
                *(--ptr) = '/';
 
-               /* Store the parent fid for historic lookup */
-               if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
-                       GOTO(out, rc = -EOVERFLOW);
-               pli->pli_fids[pli->pli_fidcount] = *tmpfid;
+               /* keep the last resolved fid to the client, so the
+                * client will build the left path on another MDT for
+                * remote object */
+               fp->gf_fid = *tmpfid;
+
+               first = false;
        }
 
 remote_out:
        ptr++; /* skip leading / */
-       memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
+       memmove(fp->gf_path, ptr, fp->gf_path + fp->gf_pathlen - ptr);
 
-       EXIT;
 out:
-       return rc;
+       RETURN(rc);
 }
 
-/* Returns the full path to this fid, as of changelog record recno. */
+/**
+ * Given an MDT object, use mdt_path_current to get the path.
+ * Essentially a wrapper to retry mdt_path_current a set number of times
+ * if -EAGAIN is returned (usually because an object is being moved).
+ *
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in]     info  Per-thread common data shared by mdt level handlers.
+ * \param[in]     obj   Object to do path lookup of
+ * \param[in,out] fp    User-provided struct for arguments and to store path
+ *                     information
+ *
+ * \retval 0 Lookup successful, path information stored in fp
+ * \retval negative errno if there was a problem
+ */
 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
-                   char *path, int pathlen, __u64 *recno, int *linkno,
-                   struct lu_fid *fid)
+                   struct getinfo_fid2path *fp)
 {
        struct mdt_device       *mdt = info->mti_mdt;
-       struct path_lookup_info *pli;
        int                     tries = 3;
        int                     rc = -EAGAIN;
        ENTRY;
 
-       if (pathlen < 3)
+       if (fp->gf_pathlen < 3)
                RETURN(-EOVERFLOW);
 
        if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
-               path[0] = '\0';
+               fp->gf_path[0] = '\0';
                RETURN(0);
        }
 
-       OBD_ALLOC_PTR(pli);
-       if (pli == NULL)
-               RETURN(-ENOMEM);
-
-       pli->pli_mdt_obj = obj;
-       pli->pli_recno = *recno;
-       pli->pli_path = path;
-       pli->pli_pathlen = pathlen;
-       pli->pli_linkno = *linkno;
-
        /* Retry multiple times in case file is being moved */
        while (tries-- && rc == -EAGAIN)
-               rc = mdt_path_current(info, pli);
-
-       /* return the last resolved fids to the client, so the client will
-        * build the left path on another MDT for remote object */
-       *fid = pli->pli_fids[pli->pli_fidcount];
-
-       *recno = pli->pli_currec;
-       /* Return next link index to caller */
-       *linkno = pli->pli_linkno;
-
-       OBD_FREE_PTR(pli);
+               rc = mdt_path_current(info, obj, fp);
 
        RETURN(rc);
 }
 
+/**
+ * Get the full path of the provided FID, as of changelog record recno.
+ *
+ * This checks sanity and looks up object for user provided FID
+ * before calling the actual path lookup code.
+ *
+ * Part of the MDT layer implementation of lfs fid2path.
+ *
+ * \param[in]     info  Per-thread common data shared by mdt level handlers.
+ * \param[in,out] fp    User-provided struct for arguments and to store path
+ *                     information
+ *
+ * \retval 0 Lookup successful, path information and recno stored in fp
+ * \retval -ENOENT, object does not exist
+ * \retval negative errno if there was a problem
+ */
 static int mdt_fid2path(struct mdt_thread_info *info,
                        struct getinfo_fid2path *fp)
 {
@@ -5539,10 +5532,11 @@ static int mdt_fid2path(struct mdt_thread_info *info,
        }
 
        obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
-       if (obj == NULL || IS_ERR(obj)) {
-               CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
-                      PTR_ERR(obj));
-               RETURN(-EINVAL);
+       if (IS_ERR(obj)) {
+               rc = PTR_ERR(obj);
+               CDEBUG(D_IOCTL, "cannot find "DFID": rc = %d\n",
+                      PFID(&fp->gf_fid), rc);
+               RETURN(rc);
        }
 
        if (mdt_object_remote(obj))
@@ -5559,8 +5553,7 @@ static int mdt_fid2path(struct mdt_thread_info *info,
                RETURN(rc);
        }
 
-       rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
-                     &fp->gf_linkno, &fp->gf_fid);
+       rc = mdt_path(info, obj, fp);
 
        CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
               PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);