Whamcloud - gitweb
LU-5040 osd: fix osd declare credit for quota
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index 9d20f5d..b542546 100644 (file)
@@ -41,7 +41,7 @@
  *         Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
  */
 
-#define DEBUG_SUBSYSTEM S_MDS
+#define DEBUG_SUBSYSTEM S_OSD
 
 #include <linux/module.h>
 
@@ -73,6 +73,7 @@
 #include <lustre_quota.h>
 
 #include <ldiskfs/xattr.h>
+#include <lustre_linkea.h>
 
 int ldiskfs_pdo = 1;
 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
@@ -558,7 +559,7 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
 
        LINVRNT(osd_invariant(obj));
        LASSERT(obj->oo_inode == NULL);
-       LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID, PFID(fid));
+       LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID"\n", PFID(fid));
 
        dev = osd_dev(ldev);
        scrub = &dev->od_scrub;
@@ -586,7 +587,7 @@ static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
        }
 
        id = &info->oti_id;
-       if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
+       if (!list_empty(&scrub->os_inconsistent_items)) {
                /* Search order: 2. OI scrub pending list. */
                result = osd_oii_lookup(dev, fid, id);
                if (result == 0)
@@ -890,7 +891,7 @@ static int osd_param_is_not_sane(const struct osd_device *dev,
 {
        struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
 
-       return oh->ot_credits > osd_journal(dev)->j_max_transaction_buffers;
+       return oh->ot_credits > osd_transaction_size(dev);
 }
 
 /*
@@ -912,11 +913,11 @@ static void osd_trans_commit_cb(struct super_block *sb,
         dt_txn_hook_commit(th);
 
        /* call per-transaction callbacks if any */
-       cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
+       list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
                LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
                         "commit callback entry: magic=%x name='%s'\n",
                         dcb->dcb_magic, dcb->dcb_name);
-               cfs_list_del_init(&dcb->dcb_linkage);
+               list_del_init(&dcb->dcb_linkage);
                dcb->dcb_func(NULL, th, dcb, error);
        }
 
@@ -954,7 +955,7 @@ static struct thandle *osd_trans_create(const struct lu_env *env,
                atomic_set(&th->th_refc, 1);
                th->th_alloc_size = sizeof(*oh);
                oti->oti_dev = osd_dt_dev(d);
-               CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
+               INIT_LIST_HEAD(&oh->ot_dcb_list);
                osd_th_alloced(oh);
 
                memset(oti->oti_declare_ops, 0,
@@ -1040,7 +1041,7 @@ int osd_trans_start(const struct lu_env *env, struct dt_device *d,
                 *
                 *     This should be removed when we can calculate the
                 *     credits precisely. */
-               oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
+               oh->ot_credits = osd_transaction_size(dev);
        }
 
         /*
@@ -1075,8 +1076,8 @@ static int osd_seq_exists(const struct lu_env *env,
        int                     rc;
        ENTRY;
 
-       if (ss == NULL)
-               RETURN(1);
+       LASSERT(ss != NULL);
+       LASSERT(ss->ss_server_fld != NULL);
 
        rc = osd_fld_lookup(env, osd, seq, range);
        if (rc != 0) {
@@ -1151,6 +1152,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
         */
        wait_event(iobuf->dr_wait,
                       atomic_read(&iobuf->dr_numreqs) == 0);
+       osd_fini_iobuf(oti->oti_dev, iobuf);
        if (!rc)
                rc = iobuf->dr_error;
 
@@ -1164,7 +1166,7 @@ static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
 
        LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
        LASSERT(&dcb->dcb_func != NULL);
-       cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
+       list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
 
        return 0;
 }
@@ -1190,8 +1192,8 @@ static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
         osd_index_fini(obj);
         if (inode != NULL) {
                struct qsd_instance     *qsd = osd_obj2dev(obj)->od_quota_slave;
-               qid_t                    uid = inode->i_uid;
-               qid_t                    gid = inode->i_gid;
+               qid_t                    uid = i_uid_read(inode);
+               qid_t                    gid = i_gid_read(inode);
 
                 iput(inode);
                 obj->oo_inode = NULL;
@@ -1686,26 +1688,26 @@ static struct timespec *osd_inode_time(const struct lu_env *env,
 
 
 static void osd_inode_getattr(const struct lu_env *env,
-                              struct inode *inode, struct lu_attr *attr)
-{
-        attr->la_valid      |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
-                               LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
-                               LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
-                              LA_TYPE;
-
-        attr->la_atime      = LTIME_S(inode->i_atime);
-        attr->la_mtime      = LTIME_S(inode->i_mtime);
-        attr->la_ctime      = LTIME_S(inode->i_ctime);
-        attr->la_mode       = inode->i_mode;
-        attr->la_size       = i_size_read(inode);
-        attr->la_blocks     = inode->i_blocks;
-        attr->la_uid        = inode->i_uid;
-        attr->la_gid        = inode->i_gid;
-        attr->la_flags      = LDISKFS_I(inode)->i_flags;
-        attr->la_nlink      = inode->i_nlink;
-        attr->la_rdev       = inode->i_rdev;
-       attr->la_blksize    = 1 << inode->i_blkbits;
-       attr->la_blkbits    = inode->i_blkbits;
+                             struct inode *inode, struct lu_attr *attr)
+{
+       attr->la_valid  |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
+                          LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
+                          LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE |
+                          LA_TYPE;
+
+       attr->la_atime   = LTIME_S(inode->i_atime);
+       attr->la_mtime   = LTIME_S(inode->i_mtime);
+       attr->la_ctime   = LTIME_S(inode->i_ctime);
+       attr->la_mode    = inode->i_mode;
+       attr->la_size    = i_size_read(inode);
+       attr->la_blocks  = inode->i_blocks;
+       attr->la_uid     = i_uid_read(inode);
+       attr->la_gid     = i_gid_read(inode);
+       attr->la_flags   = LDISKFS_I(inode)->i_flags;
+       attr->la_nlink   = inode->i_nlink;
+       attr->la_rdev    = inode->i_rdev;
+       attr->la_blksize = 1 << inode->i_blkbits;
+       attr->la_blkbits = inode->i_blkbits;
 }
 
 static int osd_attr_get(const struct lu_env *env,
@@ -1736,9 +1738,11 @@ static int osd_declare_attr_set(const struct lu_env *env,
        struct osd_object      *obj;
        struct osd_thread_info *info = osd_oti_get(env);
        struct lquota_id_info  *qi = &info->oti_qi;
+       qid_t                   uid;
+       qid_t                   gid;
        long long               bspace;
        int                     rc = 0;
-       bool                    allocated;
+       bool                    enforce;
        ENTRY;
 
        LASSERT(dt != NULL);
@@ -1766,27 +1770,28 @@ static int osd_declare_attr_set(const struct lu_env *env,
         * We still need to call the osd_declare_qid() to calculate the journal
         * credits for updating quota accounting files and to trigger quota
         * space adjustment once the operation is completed.*/
-       if ((attr->la_valid & LA_UID) != 0 &&
-            attr->la_uid != obj->oo_inode->i_uid) {
+       if (attr->la_valid & LA_UID || attr->la_valid & LA_GID) {
+               /* USERQUOTA */
+               uid = i_uid_read(obj->oo_inode);
                qi->lqi_type = USRQUOTA;
-
+               enforce = (attr->la_valid & LA_UID) && (attr->la_uid != uid);
                /* inode accounting */
                qi->lqi_is_blk = false;
 
-               /* one more inode for the new owner ... */
+               /* one more inode for the new uid ... */
                qi->lqi_id.qid_uid = attr->la_uid;
                qi->lqi_space      = 1;
-               allocated = (attr->la_uid == 0) ? true : false;
-               rc = osd_declare_qid(env, oh, qi, allocated, NULL);
+               /* Reserve credits for the new uid */
+               rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
                        RETURN(rc);
 
                /* and one less inode for the current uid */
-               qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
+               qi->lqi_id.qid_uid = uid;
                qi->lqi_space      = -1;
-               rc = osd_declare_qid(env, oh, qi, true, NULL);
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
@@ -1795,47 +1800,49 @@ static int osd_declare_attr_set(const struct lu_env *env,
                /* block accounting */
                qi->lqi_is_blk = true;
 
-               /* more blocks for the new owner ... */
+               /* more blocks for the new uid ... */
                qi->lqi_id.qid_uid = attr->la_uid;
                qi->lqi_space      = bspace;
-               allocated = (attr->la_uid == 0) ? true : false;
-               rc = osd_declare_qid(env, oh, qi, allocated, NULL);
+               /*
+                * Credits for the new uid has been reserved, re-use "obj"
+                * to save credit reservation.
+                */
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
                        RETURN(rc);
 
-               /* and finally less blocks for the current owner */
-               qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
+               /* and finally less blocks for the current uid */
+               qi->lqi_id.qid_uid = uid;
                qi->lqi_space      = -bspace;
-               rc = osd_declare_qid(env, oh, qi, true, NULL);
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
                        RETURN(rc);
-       }
 
-       if (attr->la_valid & LA_GID &&
-           attr->la_gid != obj->oo_inode->i_gid) {
+               /* GROUP QUOTA */
+               gid = i_gid_read(obj->oo_inode);
                qi->lqi_type = GRPQUOTA;
+               enforce = (attr->la_valid & LA_GID) && (attr->la_gid != gid);
 
                /* inode accounting */
                qi->lqi_is_blk = false;
 
-               /* one more inode for the new group owner ... */
+               /* one more inode for the new gid ... */
                qi->lqi_id.qid_gid = attr->la_gid;
                qi->lqi_space      = 1;
-               allocated = (attr->la_gid == 0) ? true : false;
-               rc = osd_declare_qid(env, oh, qi, allocated, NULL);
+               rc = osd_declare_qid(env, oh, qi, NULL, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
                        RETURN(rc);
 
                /* and one less inode for the current gid */
-               qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
+               qi->lqi_id.qid_gid = gid;
                qi->lqi_space      = -1;
-               rc = osd_declare_qid(env, oh, qi, true, NULL);
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
@@ -1844,20 +1851,19 @@ static int osd_declare_attr_set(const struct lu_env *env,
                /* block accounting */
                qi->lqi_is_blk = true;
 
-               /* more blocks for the new owner ... */
+               /* more blocks for the new gid ... */
                qi->lqi_id.qid_gid = attr->la_gid;
                qi->lqi_space      = bspace;
-               allocated = (attr->la_gid == 0) ? true : false;
-               rc = osd_declare_qid(env, oh, qi, allocated, NULL);
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
                        RETURN(rc);
 
-               /* and finally less blocks for the current owner */
-               qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
+               /* and finally less blocks for the current gid */
+               qi->lqi_id.qid_gid = gid;
                qi->lqi_space      = -bspace;
-               rc = osd_declare_qid(env, oh, qi, true, NULL);
+               rc = osd_declare_qid(env, oh, qi, obj, enforce, NULL);
                if (rc == -EDQUOT || rc == -EINPROGRESS)
                        rc = 0;
                if (rc)
@@ -1868,11 +1874,16 @@ static int osd_declare_attr_set(const struct lu_env *env,
 }
 
 static int osd_inode_setattr(const struct lu_env *env,
-                             struct inode *inode, const struct lu_attr *attr)
+                            struct inode *inode, const struct lu_attr *attr)
 {
-        __u64 bits;
+       __u64 bits = attr->la_valid;
+
+       /* Only allow set size for regular file */
+       if (!S_ISREG(inode->i_mode))
+               bits &= ~(LA_SIZE | LA_BLOCKS);
 
-        bits = attr->la_valid;
+       if (bits == 0)
+               return 0;
 
         if (bits & LA_ATIME)
                 inode->i_atime  = *osd_inode_time(env, inode, attr->la_atime);
@@ -1891,17 +1902,17 @@ static int osd_inode_setattr(const struct lu_env *env,
         if (bits & LA_BLOCKS)
                 inode->i_blocks = attr->la_blocks;
 #endif
-        if (bits & LA_MODE)
-                inode->i_mode   = (inode->i_mode & S_IFMT) |
-                        (attr->la_mode & ~S_IFMT);
-        if (bits & LA_UID)
-                inode->i_uid    = attr->la_uid;
-        if (bits & LA_GID)
-                inode->i_gid    = attr->la_gid;
-        if (bits & LA_NLINK)
+       if (bits & LA_MODE)
+               inode->i_mode = (inode->i_mode & S_IFMT) |
+                               (attr->la_mode & ~S_IFMT);
+       if (bits & LA_UID)
+               i_uid_write(inode, attr->la_uid);
+       if (bits & LA_GID)
+               i_gid_write(inode, attr->la_gid);
+       if (bits & LA_NLINK)
                set_nlink(inode, attr->la_nlink);
-        if (bits & LA_RDEV)
-                inode->i_rdev   = attr->la_rdev;
+       if (bits & LA_RDEV)
+               inode->i_rdev = attr->la_rdev;
 
         if (bits & LA_FLAGS) {
                 /* always keep S_NOCMTIME */
@@ -1913,24 +1924,25 @@ static int osd_inode_setattr(const struct lu_env *env,
 
 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
 {
-       if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
-           (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
+       if ((attr->la_valid & LA_UID && attr->la_uid != i_uid_read(inode)) ||
+           (attr->la_valid & LA_GID && attr->la_gid != i_gid_read(inode))) {
                struct iattr    iattr;
                int             rc;
 
+               ll_vfs_dq_init(inode);
                iattr.ia_valid = 0;
                if (attr->la_valid & LA_UID)
                        iattr.ia_valid |= ATTR_UID;
                if (attr->la_valid & LA_GID)
                        iattr.ia_valid |= ATTR_GID;
-               iattr.ia_uid = attr->la_uid;
-               iattr.ia_gid = attr->la_gid;
+               iattr.ia_uid = make_kuid(&init_user_ns, attr->la_uid);
+               iattr.ia_gid = make_kgid(&init_user_ns, attr->la_gid);
 
                rc = ll_vfs_dq_transfer(inode, &iattr);
                if (rc) {
                        CERROR("%s: quota transfer failed: rc = %d. Is quota "
-                              "enforcement enabled on the ldiskfs filesystem?",
-                              inode->i_sb->s_id, rc);
+                              "enforcement enabled on the ldiskfs "
+                              "filesystem?\n", inode->i_sb->s_id, rc);
                        return rc;
                }
        }
@@ -1982,7 +1994,6 @@ static int osd_attr_set(const struct lu_env *env,
        }
 
         inode = obj->oo_inode;
-       ll_vfs_dq_init(inode);
 
        rc = osd_quota_transfer(inode, attr);
        if (rc)
@@ -2242,7 +2253,7 @@ static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
                  * should not happen since quota enforcement is no longer
                  * enabled on ldiskfs (lquota takes care of it).
                  */
-                LASSERTF(result == 0, "%d", result);
+               LASSERTF(result == 0, "%d\n", result);
                ll_dirty_inode(inode, I_DIRTY_DATASYNC);
         }
 
@@ -2372,7 +2383,7 @@ static int osd_declare_object_create(const struct lu_env *env,
                RETURN(0);
 
        rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
-                                  false, false, NULL, false);
+                                  osd_dt_obj(dt), false, NULL, false);
        if (rc != 0)
                RETURN(rc);
 
@@ -2442,13 +2453,13 @@ static int osd_declare_object_destroy(const struct lu_env *env,
        osd_trans_declare_op(env, oh, OSD_OT_DELETE,
                             osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3);
        /* one less inode */
-       rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
-                                  false, true, NULL, false);
+       rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
+                                  -1, oh, obj, false, NULL, false);
        if (rc)
                RETURN(rc);
        /* data to be truncated */
-       rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
-                                  true, true, NULL, false);
+       rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
+                                  0, oh, obj, true, NULL, false);
        RETURN(rc);
 }
 
@@ -2563,9 +2574,9 @@ int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
  * its inmemory API.
  */
 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
-                                 const struct dt_rec *fid)
+                                 const struct lu_fid *fid)
 {
-       if (!fid_is_namespace_visible((const struct lu_fid *)fid) ||
+       if (!fid_is_namespace_visible(fid) ||
            OBD_FAIL_CHECK(OBD_FAIL_FID_IGIF)) {
                param->edp_magic = 0;
                return;
@@ -2602,9 +2613,9 @@ static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
 
 static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
                                        struct inode *dir,
-                                       struct inode  *parent_dir,
-                                       const struct dt_rec *dot_fid,
-                                       const struct dt_rec *dot_dot_fid,
+                                       struct inode *parent_dir,
+                                       const struct lu_fid *dot_fid,
+                                       const struct lu_fid *dot_dot_fid,
                                        struct osd_thandle *oth)
 {
        struct ldiskfs_dentry_param *dot_ldp;
@@ -2626,6 +2637,7 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
                                                  struct osd_device *osd,
                                                  struct osd_object *pobj,
                                                  const struct lu_fid *fid,
+                                                 __u32 type,
                                                  struct thandle *th)
 {
        struct osd_thread_info  *info = osd_oti_get(env);
@@ -2638,9 +2650,7 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
        oh = container_of(th, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle->h_transaction != NULL);
 
-       /* FIXME: Insert index api needs to know the mode of
-        * the remote object. Just use S_IFDIR for now */
-       local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, S_IFDIR);
+       local = ldiskfs_create_inode(oh->ot_handle, pobj->oo_inode, type);
        if (IS_ERR(local)) {
                CERROR("%s: create local error %d\n", osd_name(osd),
                       (int)PTR_ERR(local));
@@ -2655,9 +2665,12 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
                RETURN(ERR_PTR(rc));
        }
 
+       if (!S_ISDIR(type))
+               RETURN(local);
+
        rc = osd_add_dot_dotdot_internal(info, local, pobj->oo_inode,
-               (const struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
-               (const struct dt_rec *)fid, oh);
+                                        lu_object_fid(&pobj->oo_dt.do_lu),
+                                        fid, oh);
        if (rc != 0) {
                CERROR("%s: "DFID" add dot dotdot error: rc = %d\n",
                        osd_name(osd), PFID(fid), rc);
@@ -2800,8 +2813,14 @@ static int osd_object_ref_add(const struct lu_env *env,
         * in case they are being linked into the PENDING directory
         */
        spin_lock(&obj->oo_guard);
-       ldiskfs_inc_count(oh->ot_handle, inode);
-       LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
+       if (unlikely(inode->i_nlink == 0))
+               /* inc_nlink from 0 may cause WARN_ON */
+               set_nlink(inode, 1);
+       else {
+               ldiskfs_inc_count(oh->ot_handle, inode);
+               if (!S_ISDIR(inode->i_mode))
+                       LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
+       }
        spin_unlock(&obj->oo_guard);
 
        ll_dirty_inode(inode, I_DIRTY_DATASYNC);
@@ -2926,6 +2945,7 @@ static int osd_declare_xattr_set(const struct lu_env *env,
 {
        struct osd_thandle *oh;
        int credits;
+       struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
 
        LASSERT(handle != NULL);
 
@@ -2941,13 +2961,16 @@ static int osd_declare_xattr_set(const struct lu_env *env,
        } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
                credits = 1;
        } else {
-               struct osd_device  *osd = osd_dev(dt->do_lu.lo_dev);
-               struct super_block *sb = osd_sb(osd);
                credits = osd_dto_credits_noquota[DTO_XATTR_SET];
                if (buf && buf->lb_len > sb->s_blocksize) {
                        credits *= (buf->lb_len + sb->s_blocksize - 1) >>
                                        sb->s_blocksize_bits;
                }
+               /*
+                * xattr set may involve inode quota change, reserve credits for
+                * dquot_initialize()
+                */
+               oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
        }
 
        osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
@@ -3010,6 +3033,22 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
        if (fl & LU_XATTR_CREATE)
                fs_flags |= XATTR_CREATE;
 
+       if (strcmp(name, XATTR_NAME_LMV) == 0) {
+               struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
+               int                      rc;
+
+               rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
+               if (rc != 0)
+                       RETURN(rc);
+
+               lma->lma_incompat |= LMAI_STRIPED;
+               lustre_lma_swab(lma);
+               rc = __osd_xattr_set(info, inode, XATTR_NAME_LMA, lma,
+                                    sizeof(*lma), XATTR_REPLACE);
+               if (rc != 0)
+                       RETURN(rc);
+       }
+
        return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
                               fs_flags);
 }
@@ -3041,6 +3080,7 @@ static int osd_declare_xattr_del(const struct lu_env *env,
                                  struct thandle *handle)
 {
         struct osd_thandle *oh;
+       struct super_block *sb = osd_sb(osd_dev(dt->do_lu.lo_dev));
 
        LASSERT(dt_object_exists(dt) && !dt_object_remote(dt));
         LASSERT(handle != NULL);
@@ -3050,6 +3090,11 @@ static int osd_declare_xattr_del(const struct lu_env *env,
 
        osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET,
                             osd_dto_credits_noquota[DTO_XATTR_SET]);
+       /*
+        * xattr del may involve inode quota change, reserve credits for
+        * dquot_initialize()
+        */
+       oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
 
        return 0;
 }
@@ -3116,16 +3161,16 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env,
        case LC_ID_NONE:
                RETURN(NULL);
        case LC_ID_PLAIN:
-               capa->lc_uid = obj->oo_inode->i_uid;
-               capa->lc_gid = obj->oo_inode->i_gid;
+               capa->lc_uid = i_uid_read(obj->oo_inode);
+               capa->lc_gid = i_gid_read(obj->oo_inode);
                capa->lc_flags = LC_ID_PLAIN;
                break;
        case LC_ID_CONVERT: {
                __u32 d[4], s[4];
 
-               s[0] = obj->oo_inode->i_uid;
+               s[0] = i_uid_read(obj->oo_inode);
                cfs_get_random_bytes(&(s[1]), sizeof(__u32));
-               s[2] = obj->oo_inode->i_gid;
+               s[2] = i_uid_read(obj->oo_inode);
                cfs_get_random_bytes(&(s[3]), sizeof(__u32));
                rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
                if (unlikely(rc))
@@ -3321,7 +3366,8 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
                         * recheck under lock.
                         */
                        if (!osd_has_index(obj))
-                               result = osd_iam_container_init(env, obj, dir);
+                               result = osd_iam_container_init(env, obj,
+                                                               obj->oo_dir);
                        else
                                result = 0;
                        up_write(&obj->oo_ext_idx_sem);
@@ -3517,8 +3563,8 @@ static int osd_index_declare_ea_delete(const struct lu_env *env,
        inode = osd_dt_obj(dt)->oo_inode;
        LASSERT(inode);
 
-       rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
-                                  true, true, NULL, false);
+       rc = osd_declare_inode_qid(env, i_uid_read(inode), i_gid_read(inode),
+                                  0, oh, osd_dt_obj(dt), true, NULL, false);
        RETURN(rc);
 }
 
@@ -3536,14 +3582,22 @@ static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
 }
 
 static int osd_remote_fid(const struct lu_env *env, struct osd_device *osd,
-                         struct lu_fid *fid)
+                         const struct lu_fid *fid)
 {
+       struct seq_server_site  *ss = osd_seq_site(osd);
        ENTRY;
 
        /* FID seqs not in FLDB, must be local seq */
        if (unlikely(!fid_seq_in_fldb(fid_seq(fid))))
                RETURN(0);
 
+       /* If FLD is not being initialized yet, it only happens during the
+        * initialization, likely during mgs initialization, and we assume
+        * this is local FID. */
+       if (ss == NULL || ss->ss_server_fld == NULL)
+               RETURN(0);
+
+       /* Only check the local FLDB here */
        if (osd_seq_exists(env, osd, fid_seq(fid)))
                RETURN(0);
 
@@ -3868,9 +3922,9 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
  * \retval -ve, on error
  */
 static int __osd_ea_add_rec(struct osd_thread_info *info,
-                            struct osd_object *pobj, struct inode  *cinode,
-                            const char *name, const struct dt_rec *fid,
-                            struct htree_lock *hlock, struct thandle *th)
+                           struct osd_object *pobj, struct inode  *cinode,
+                           const char *name, const struct lu_fid *fid,
+                           struct htree_lock *hlock, struct thandle *th)
 {
         struct ldiskfs_dentry_param *ldp;
         struct dentry               *child;
@@ -3909,11 +3963,11 @@ static int __osd_ea_add_rec(struct osd_thread_info *info,
  * \retval -ve, on error
  */
 static int osd_add_dot_dotdot(struct osd_thread_info *info,
-                              struct osd_object *dir,
-                              struct inode  *parent_dir, const char *name,
-                              const struct dt_rec *dot_fid,
-                              const struct dt_rec *dot_dot_fid,
-                              struct thandle *th)
+                             struct osd_object *dir,
+                             struct inode *parent_dir, const char *name,
+                             const struct lu_fid *dot_fid,
+                             const struct lu_fid *dot_dot_fid,
+                             struct thandle *th)
 {
         struct inode                *inode = dir->oo_inode;
         struct osd_thandle          *oth;
@@ -3941,8 +3995,8 @@ static int osd_add_dot_dotdot(struct osd_thread_info *info,
                }
 
                result = osd_add_dot_dotdot_internal(info, dir->oo_inode,
-                                               parent_dir, dot_fid,
-                                               dot_dot_fid, oth);
+                                                    parent_dir, dot_fid,
+                                                    dot_dot_fid, oth);
                if (result == 0)
                        dir->oo_compat_dotdot_created = 1;
        }
@@ -3956,8 +4010,8 @@ static int osd_add_dot_dotdot(struct osd_thread_info *info,
  * value, return by respective functions.
  */
 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
-                          struct inode *cinode, const char *name,
-                          const struct dt_rec *fid, struct thandle *th)
+                         struct inode *cinode, const char *name,
+                         const struct lu_fid *fid, struct thandle *th)
 {
         struct osd_thread_info *info   = osd_oti_get(env);
         struct htree_lock      *hlock;
@@ -3972,9 +4026,10 @@ static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
                                            pobj->oo_inode, 0);
                 } else {
                        down_write(&pobj->oo_ext_idx_sem);
-                }
-                rc = osd_add_dot_dotdot(info, pobj, cinode, name,
-                     (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
+               }
+
+               rc = osd_add_dot_dotdot(info, pobj, cinode, name,
+                                       lu_object_fid(&pobj->oo_dt.do_lu),
                                         fid, th);
         } else {
                 if (hlock != NULL) {
@@ -3987,11 +4042,10 @@ static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
                if (OBD_FAIL_CHECK(OBD_FAIL_FID_INDIR)) {
                        struct lu_fid *tfid = &info->oti_fid;
 
-                       *tfid = *(const struct lu_fid *)fid;
+                       *tfid = *fid;
                        tfid->f_ver = ~0;
                        rc = __osd_ea_add_rec(info, pobj, cinode, name,
-                                             (const struct dt_rec *)tfid,
-                                             hlock, th);
+                                             tfid, hlock, th);
                } else {
                        rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
                                              hlock, th);
@@ -4090,6 +4144,83 @@ int osd_add_oi_cache(struct osd_thread_info *info, struct osd_device *osd,
 }
 
 /**
+ * Get parent FID from the linkEA.
+ *
+ * For a directory which parent resides on remote MDT, to satisfy the
+ * local e2fsck, we insert it into the /REMOTE_PARENT_DIR locally. On
+ * the other hand, to make the lookup(..) on the directory can return
+ * the real parent FID, we append the real parent FID after its ".."
+ * name entry in the /REMOTE_PARENT_DIR.
+ *
+ * Unfortunately, such PFID-in-dirent cannot be preserved via file-level
+ * backup. So after the restore, we cannot get the right parent FID from
+ * its ".." name entry in the /REMOTE_PARENT_DIR. Under such case, since
+ * we have stored the real parent FID in the directory object's linkEA,
+ * we can parse the linkEA for the real parent FID.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] obj      pointer to the object to be handled
+ * \param[out]fid      pointer to the buffer to hold the parent FID
+ *
+ * \retval             0 for getting the real parent FID successfully
+ * \retval             negative error number on failure
+ */
+static int osd_get_pfid_from_linkea(const struct lu_env *env,
+                                   struct osd_object *obj,
+                                   struct lu_fid *fid)
+{
+       struct osd_thread_info  *oti    = osd_oti_get(env);
+       struct lu_buf           *buf    = &oti->oti_big_buf;
+       struct dentry           *dentry = &oti->oti_obj_dentry;
+       struct inode            *inode  = obj->oo_inode;
+       struct linkea_data       ldata  = { 0 };
+       int                      rc;
+       ENTRY;
+
+       fid_zero(fid);
+       if (!S_ISDIR(inode->i_mode))
+               RETURN(-EIO);
+
+again:
+       rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
+                            buf->lb_buf, buf->lb_len);
+       if (rc == -ERANGE) {
+               rc = __osd_xattr_get(inode, dentry, XATTR_NAME_LINK,
+                                    NULL, 0);
+               if (rc > 0) {
+                       lu_buf_realloc(buf, rc);
+                       if (buf->lb_buf == NULL)
+                               RETURN(-ENOMEM);
+
+                       goto again;
+               }
+       }
+
+       if (unlikely(rc == 0))
+               RETURN(-ENODATA);
+
+       if (rc < 0)
+               RETURN(rc);
+
+       if (unlikely(buf->lb_buf == NULL)) {
+               lu_buf_realloc(buf, rc);
+               if (buf->lb_buf == NULL)
+                       RETURN(-ENOMEM);
+
+               goto again;
+       }
+
+       ldata.ld_buf = buf;
+       rc = linkea_init(&ldata);
+       if (rc == 0) {
+               linkea_first_entry(&ldata);
+               linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen, NULL, fid);
+       }
+
+       RETURN(rc);
+}
+
+/**
  * Calls ->lookup() to find dentry. From dentry get inode and
  * read inode's ea to get fid. This is required for  interoperability
  * mode (b11826)
@@ -4143,10 +4274,18 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
 
                /* done with de, release bh */
                brelse(bh);
-               if (rc != 0)
-                       rc = osd_ea_fid_get(env, obj, ino, fid, id);
-               else
+               if (rc != 0) {
+                       if (unlikely(ino == osd_remote_parent_ino(dev)))
+                               /* If the parent is on remote MDT, and there
+                                * is no FID-in-dirent, then we have to get
+                                * the parent FID from the linkEA.  */
+                               rc = osd_get_pfid_from_linkea(env, obj, fid);
+                       else
+                               rc = osd_ea_fid_get(env, obj, ino, fid, id);
+               } else {
                        osd_id_gen(id, ino, OSD_OII_NOGEN);
+               }
+
                if (rc != 0) {
                        fid_zero(&oic->oic_fid);
                        GOTO(out, rc);
@@ -4276,8 +4415,9 @@ static int osd_index_declare_ea_insert(const struct lu_env *env,
                /* We ignore block quota on meta pool (MDTs), so needn't
                 * calculate how many blocks will be consumed by this index
                 * insert */
-               rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0,
-                                          oh, true, true, NULL, false);
+               rc = osd_declare_inode_qid(env, i_uid_read(inode),
+                                          i_gid_read(inode), 0, oh,
+                                          osd_dt_obj(dt), true, NULL, false);
        }
 
        if (fid == NULL)
@@ -4317,7 +4457,8 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
 {
        struct osd_object       *obj = osd_dt_obj(dt);
        struct osd_device       *osd = osd_dev(dt->do_lu.lo_dev);
-       struct lu_fid           *fid = (struct lu_fid *) rec;
+       struct dt_insert_rec    *rec1   = (struct dt_insert_rec *)rec;
+       const struct lu_fid     *fid    = rec1->rec_fid;
        const char              *name = (const char *)key;
        struct osd_thread_info  *oti   = osd_oti_get(env);
        struct osd_inode_id     *id    = &oti->oti_id;
@@ -4326,16 +4467,16 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
        int                     rc;
        ENTRY;
 
-        LASSERT(osd_invariant(obj));
+       LASSERT(osd_invariant(obj));
        LASSERT(dt_object_exists(dt) && !dt_object_remote(dt));
-        LASSERT(th != NULL);
+       LASSERT(th != NULL);
 
        osd_trans_exec_op(env, th, OSD_OT_INSERT);
 
-        if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
-                RETURN(-EACCES);
+       if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
+               RETURN(-EACCES);
 
-       LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!", PFID(fid));
+       LASSERTF(fid_is_sane(fid), "fid"DFID" is insane!\n", PFID(fid));
 
        rc = osd_remote_fid(env, osd, fid);
        if (rc < 0) {
@@ -4364,8 +4505,7 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
                        child_inode = igrab(omm->omm_remote_parent->d_inode);
                } else {
                        child_inode = osd_create_local_agent_inode(env, osd,
-                                                                  obj, fid,
-                                                                  th);
+                                       obj, fid, rec1->rec_type & S_IFMT, th);
                        if (IS_ERR(child_inode))
                                RETURN(PTR_ERR(child_inode));
                }
@@ -4382,7 +4522,7 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
                child_inode = igrab(child->oo_inode);
        }
 
-       rc = osd_ea_add_rec(env, obj, child_inode, name, rec, th);
+       rc = osd_ea_add_rec(env, obj, child_inode, name, fid, th);
 
        CDEBUG(D_INODE, "parent %lu insert %s:%lu rc = %d\n",
               obj->oo_inode->i_ino, name, child_inode->i_ino, rc);
@@ -4977,22 +5117,12 @@ osd_dirent_update(handle_t *jh, struct super_block *sb,
        LASSERT(de->rec_len >= de->name_len + sizeof(struct osd_fid_pack));
 
        rc = ldiskfs_journal_get_write_access(jh, bh);
-       if (rc != 0) {
-               CERROR("%.16s: fail to write access for update dirent: "
-                      "name = %.*s, rc = %d\n",
-                      LDISKFS_SB(sb)->s_es->s_volume_name,
-                      ent->oied_namelen, ent->oied_name, rc);
+       if (rc != 0)
                RETURN(rc);
-       }
 
        rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
        fid_cpu_to_be((struct lu_fid *)rec->fp_area, fid);
        rc = ldiskfs_journal_dirty_metadata(jh, bh);
-       if (rc != 0)
-               CERROR("%.16s: fail to dirty metadata for update dirent: "
-                      "name = %.*s, rc = %d\n",
-                      LDISKFS_SB(sb)->s_es->s_volume_name,
-                      ent->oied_namelen, ent->oied_name, rc);
 
        RETURN(rc);
 }
@@ -5041,13 +5171,8 @@ osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
        if (osd_dirent_has_space(de->rec_len, ent->oied_namelen,
                                 dir->i_sb->s_blocksize)) {
                rc = ldiskfs_journal_get_write_access(jh, bh);
-               if (rc != 0) {
-                       CERROR("%.16s: fail to write access for reinsert "
-                              "dirent: name = %.*s, rc = %d\n",
-                              LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
-                              ent->oied_namelen, ent->oied_name, rc);
+               if (rc != 0)
                        RETURN(rc);
-               }
 
                de->name[de->name_len] = 0;
                rec = (struct osd_fid_pack *)(de->name + de->name_len + 1);
@@ -5056,38 +5181,29 @@ osd_dirent_reinsert(const struct lu_env *env, handle_t *jh,
                de->file_type |= LDISKFS_DIRENT_LUFID;
 
                rc = ldiskfs_journal_dirty_metadata(jh, bh);
-               if (rc != 0)
-                       CERROR("%.16s: fail to dirty metadata for reinsert "
-                              "dirent: name = %.*s, rc = %d\n",
-                              LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
-                              ent->oied_namelen, ent->oied_name, rc);
 
                RETURN(rc);
        }
 
        rc = ldiskfs_delete_entry(jh, dir, de, bh);
-       if (rc != 0) {
-               CERROR("%.16s: fail to delete entry for reinsert dirent: "
-                      "name = %.*s, rc = %d\n",
-                      LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
-                      ent->oied_namelen, ent->oied_name, rc);
+       if (rc != 0)
                RETURN(rc);
-       }
 
        dentry = osd_child_dentry_by_inode(env, dir, ent->oied_name,
                                           ent->oied_namelen);
        ldp = (struct ldiskfs_dentry_param *)osd_oti_get(env)->oti_ldp;
-       osd_get_ldiskfs_dirent_param(ldp, (const struct dt_rec *)fid);
+       osd_get_ldiskfs_dirent_param(ldp, fid);
        dentry->d_fsdata = (void *)ldp;
        ll_vfs_dq_init(dir);
        rc = osd_ldiskfs_add_entry(jh, dentry, inode, hlock);
        /* It is too bad, we cannot reinsert the name entry back.
         * That means we lose it! */
        if (rc != 0)
-               CERROR("%.16s: fail to insert entry for reinsert dirent: "
-                      "name = %.*s, rc = %d\n",
+               CDEBUG(D_LFSCK, "%.16s: fail to reinsert the dirent, "
+                      "dir = %lu/%u, name = %.*s, "DFID": rc = %d\n",
                       LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
-                      ent->oied_namelen, ent->oied_name, rc);
+                      dir->i_ino, dir->i_generation,
+                      ent->oied_namelen, ent->oied_name, PFID(fid), rc);
 
        RETURN(rc);
 }
@@ -5148,10 +5264,11 @@ again:
                jh = osd_journal_start_sb(sb, LDISKFS_HT_MISC, credits);
                if (IS_ERR(jh)) {
                        rc = PTR_ERR(jh);
-                       CERROR("%.16s: fail to start trans for dirent "
-                              "check_repair: credits %d, name %.*s, rc %d\n",
-                              devname, credits, ent->oied_namelen,
-                              ent->oied_name, rc);
+                       CDEBUG(D_LFSCK, "%.16s: fail to start trans for dirent "
+                              "check_repair, dir = %lu/%u, credits = %d, "
+                              "name = %.*s: rc = %d\n",
+                              devname, dir->i_ino, dir->i_generation, credits,
+                              ent->oied_namelen, ent->oied_name, rc);
                        RETURN(rc);
                }
 
@@ -5195,15 +5312,17 @@ again:
                if (rc == -ENOENT || rc == -ESTALE) {
                        *attr |= LUDA_IGNORE;
                        rc = 0;
+               } else {
+                       CDEBUG(D_LFSCK, "%.16s: fail to iget for dirent "
+                              "check_repair, dir = %lu/%u, name = %.*s: "
+                              "rc = %d\n",
+                              devname, dir->i_ino, dir->i_generation,
+                              ent->oied_namelen, ent->oied_name, rc);
                }
 
                GOTO(out_journal, rc);
        }
 
-       /* skip the REMOTE_PARENT_DIR. */
-       if (inode == dev->od_mdt_map->omm_remote_parent->d_inode)
-               GOTO(out_inode, rc = 0);
-
        rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
        if (rc == 0) {
                LASSERT(!(lma->lma_compat & LMAC_NOT_IN_OI));
@@ -5236,6 +5355,13 @@ again:
                        rc = osd_dirent_update(jh, sb, ent, fid, bh, de);
                        if (rc == 0)
                                *attr |= LUDA_REPAIR;
+                       else
+                               CDEBUG(D_LFSCK, "%.16s: fail to update FID "
+                                      "in the dirent, dir = %lu/%u, "
+                                      "name = %.*s, "DFID": rc = %d\n",
+                                      devname, dir->i_ino, dir->i_generation,
+                                      ent->oied_namelen, ent->oied_name,
+                                      PFID(fid), rc);
                } else {
                        /* Do not repair under dryrun mode. */
                        if (*attr & LUDA_VERIFY_DRYRUN) {
@@ -5262,6 +5388,13 @@ again:
                                                 fid, bh, de, hlock);
                        if (rc == 0)
                                *attr |= LUDA_REPAIR;
+                       else
+                               CDEBUG(D_LFSCK, "%.16s: fail to append FID "
+                                      "after the dirent, dir = %lu/%u, "
+                                      "name = %.*s, "DFID": rc = %d\n",
+                                      devname, dir->i_ino, dir->i_generation,
+                                      ent->oied_namelen, ent->oied_name,
+                                      PFID(fid), rc);
                }
        } else if (rc == -ENODATA) {
                /* Do not repair under dryrun mode. */
@@ -5294,6 +5427,13 @@ again:
                        rc = osd_ea_fid_set(info, inode, fid, 0, 0);
                        if (rc == 0)
                                *attr |= LUDA_REPAIR;
+                       else
+                               CDEBUG(D_LFSCK, "%.16s: fail to set LMA for "
+                                      "update dirent, dir = %lu/%u, "
+                                      "name = %.*s, "DFID": rc = %d\n",
+                                      devname, dir->i_ino, dir->i_generation,
+                                      ent->oied_namelen, ent->oied_name,
+                                      PFID(fid), rc);
                } else {
                        lu_igif_build(fid, inode->i_ino, inode->i_generation);
                        /* It is probably IGIF object. Only aappend the
@@ -5302,6 +5442,13 @@ again:
                                                 fid, bh, de, hlock);
                        if (rc == 0)
                                *attr |= LUDA_UPGRADE;
+                       else
+                               CDEBUG(D_LFSCK, "%.16s: fail to append IGIF "
+                                      "after the dirent, dir = %lu/%u, "
+                                      "name = %.*s, "DFID": rc = %d\n",
+                                      devname, dir->i_ino, dir->i_generation,
+                                      ent->oied_namelen, ent->oied_name,
+                                      PFID(fid), rc);
                }
        }
 
@@ -5355,11 +5502,15 @@ static inline int osd_it_ea_rec(const struct lu_env *env,
        int                     rc    = 0;
        ENTRY;
 
+       LASSERT(obj->oo_inode != dev->od_mdt_map->omm_remote_parent->d_inode);
+
        if (attr & LUDA_VERIFY) {
-               attr |= LUDA_TYPE;
-               if (unlikely(ino == osd_sb(dev)->s_root->d_inode->i_ino)) {
+               if (unlikely(ino == osd_remote_parent_ino(dev))) {
                        attr |= LUDA_IGNORE;
-                       rc = 0;
+                       /* If the parent is on remote MDT, and there
+                        * is no FID-in-dirent, then we have to get
+                        * the parent FID from the linkEA.  */
+                       osd_get_pfid_from_linkea(env, obj, fid);
                } else {
                        rc = osd_dirent_check_repair(env, obj, it, fid, id,
                                                     &attr);
@@ -5373,7 +5524,13 @@ static inline int osd_it_ea_rec(const struct lu_env *env,
                                   it->oie_dirent->oied_name[1] != '.'))
                                RETURN(-ENOENT);
 
-                       rc = osd_ea_fid_get(env, obj, ino, fid, id);
+                       if (unlikely(ino == osd_remote_parent_ino(dev)))
+                               /* If the parent is on remote MDT, and there
+                                * is no FID-in-dirent, then we have to get
+                                * the parent FID from the linkEA.  */
+                               rc = osd_get_pfid_from_linkea(env, obj, fid);
+                       else
+                               rc = osd_ea_fid_get(env, obj, ino, fid, id);
                } else {
                        osd_id_gen(id, ino, OSD_OII_NOGEN);
                }
@@ -5412,10 +5569,10 @@ static inline int osd_it_ea_rec(const struct lu_env *env,
  * \param[in] env      execution environment
  * \param[in] di       iterator's in memory structure
  * \param[in] attr     attribute of the entry, only requires LUDA_TYPE to
- *                     calculate the lu_dirent size.
+ *                      calculate the lu_dirent size.
  *
  * \retval     record size(in bytes & in memory) of the current lu_dirent
- *             entry.
+ *              entry.
  */
 static int osd_it_ea_rec_size(const struct lu_env *env, const struct dt_it *di,
                              __u32 attr)
@@ -5561,6 +5718,7 @@ static void osd_key_fini(const struct lu_context *ctx,
        OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
        lu_buf_free(&info->oti_iobuf.dr_pg_buf);
        lu_buf_free(&info->oti_iobuf.dr_bl_buf);
+       lu_buf_free(&info->oti_big_buf);
        OBD_FREE_PTR(info);
 }
 
@@ -5849,7 +6007,7 @@ static int osd_device_init0(const struct lu_env *env,
        /* self-repair LMA by default */
        o->od_lma_self_repair = 1;
 
-       CFS_INIT_LIST_HEAD(&o->od_ios_list);
+       INIT_LIST_HEAD(&o->od_ios_list);
        /* setup scrub, including OI files initialization */
        rc = osd_scrub_setup(env, o);
        if (rc < 0)
@@ -5955,13 +6113,12 @@ static int osd_process_config(const struct lu_env *env,
                break;
        case LCFG_PARAM:
                LASSERT(&o->od_dt_dev);
-               rc = class_process_proc_seq_param(PARAM_OSD,
-                                                 lprocfs_osd_obd_vars,
-                                                 cfg, &o->od_dt_dev);
+               rc = class_process_proc_param(PARAM_OSD, lprocfs_osd_obd_vars,
+                                             cfg, &o->od_dt_dev);
                if (rc > 0 || rc == -ENOSYS)
-                       rc = class_process_proc_seq_param(PARAM_OST,
-                                                         lprocfs_osd_obd_vars,
-                                                         cfg, &o->od_dt_dev);
+                       rc = class_process_proc_param(PARAM_OST,
+                                                     lprocfs_osd_obd_vars,
+                                                     cfg, &o->od_dt_dev);
                break;
        default:
                rc = -ENOSYS;
@@ -6124,9 +6281,6 @@ static int __init osd_mod_init(void)
 
        rc = class_register_type(&osd_obd_device_ops, NULL, true,
                                 lprocfs_osd_module_vars,
-#ifndef HAVE_ONLY_PROCFS_SEQ
-                                NULL,
-#endif
                                 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
        if (rc)
                lu_kmem_fini(ldiskfs_caches);