Whamcloud - gitweb
LU-6846 osd: reset do_body_ops after creation
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index 9c8ea63..8c2486c 100644 (file)
@@ -831,7 +831,8 @@ static void osd_trans_commit_cb(struct super_block *sb,
         dt_txn_hook_commit(th);
 
        /* call per-transaction callbacks if any */
-       list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
+       list_for_each_entry_safe(dcb, tmp, &oh->ot_commit_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);
@@ -870,20 +871,68 @@ static struct thandle *osd_trans_create(const struct lu_env *env,
                th->th_result = 0;
                th->th_tags = LCT_TX_HANDLE;
                oh->ot_credits = 0;
-               INIT_LIST_HEAD(&oh->ot_dcb_list);
+               INIT_LIST_HEAD(&oh->ot_commit_dcb_list);
+               INIT_LIST_HEAD(&oh->ot_stop_dcb_list);
                osd_th_alloced(oh);
 
                memset(oti->oti_declare_ops, 0,
-                                       sizeof(oti->oti_declare_ops));
-               memset(oti->oti_declare_ops_rb, 0,
-                                       sizeof(oti->oti_declare_ops_rb));
+                      sizeof(oti->oti_declare_ops));
                memset(oti->oti_declare_ops_cred, 0,
-                                       sizeof(oti->oti_declare_ops_cred));
-               oti->oti_rollback = false;
+                      sizeof(oti->oti_declare_ops_cred));
+               memset(oti->oti_declare_ops_used, 0,
+                      sizeof(oti->oti_declare_ops_used));
        }
        RETURN(th);
 }
 
+void osd_trans_dump_creds(const struct lu_env *env, struct thandle *th)
+{
+       struct osd_thread_info  *oti = osd_oti_get(env);
+       struct osd_thandle      *oh;
+
+       oh = container_of0(th, struct osd_thandle, ot_super);
+       LASSERT(oh != NULL);
+
+       CWARN("  create: %u/%u/%u, destroy: %u/%u/%u\n",
+             oti->oti_declare_ops[OSD_OT_CREATE],
+             oti->oti_declare_ops_cred[OSD_OT_CREATE],
+             oti->oti_declare_ops_used[OSD_OT_CREATE],
+             oti->oti_declare_ops[OSD_OT_DESTROY],
+             oti->oti_declare_ops_cred[OSD_OT_DESTROY],
+             oti->oti_declare_ops_used[OSD_OT_DESTROY]);
+       CWARN("  attr_set: %u/%u/%u, xattr_set: %u/%u/%u\n",
+             oti->oti_declare_ops[OSD_OT_ATTR_SET],
+             oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
+             oti->oti_declare_ops_used[OSD_OT_ATTR_SET],
+             oti->oti_declare_ops[OSD_OT_XATTR_SET],
+             oti->oti_declare_ops_cred[OSD_OT_XATTR_SET],
+             oti->oti_declare_ops_used[OSD_OT_XATTR_SET]);
+       CWARN("  write: %u/%u/%u, punch: %u/%u/%u, quota %u/%u/%u\n",
+             oti->oti_declare_ops[OSD_OT_WRITE],
+             oti->oti_declare_ops_cred[OSD_OT_WRITE],
+             oti->oti_declare_ops_used[OSD_OT_WRITE],
+             oti->oti_declare_ops[OSD_OT_PUNCH],
+             oti->oti_declare_ops_cred[OSD_OT_PUNCH],
+             oti->oti_declare_ops_used[OSD_OT_PUNCH],
+             oti->oti_declare_ops[OSD_OT_QUOTA],
+             oti->oti_declare_ops_cred[OSD_OT_QUOTA],
+             oti->oti_declare_ops_used[OSD_OT_QUOTA]);
+       CWARN("  insert: %u/%u/%u, delete: %u/%u/%u\n",
+             oti->oti_declare_ops[OSD_OT_INSERT],
+             oti->oti_declare_ops_cred[OSD_OT_INSERT],
+             oti->oti_declare_ops_used[OSD_OT_INSERT],
+             oti->oti_declare_ops[OSD_OT_DELETE],
+             oti->oti_declare_ops_cred[OSD_OT_DELETE],
+             oti->oti_declare_ops_used[OSD_OT_DELETE]);
+       CWARN("  ref_add: %u/%u/%u, ref_del: %u/%u/%u\n",
+             oti->oti_declare_ops[OSD_OT_REF_ADD],
+             oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
+             oti->oti_declare_ops_used[OSD_OT_REF_ADD],
+             oti->oti_declare_ops[OSD_OT_REF_DEL],
+             oti->oti_declare_ops_cred[OSD_OT_REF_DEL],
+             oti->oti_declare_ops_used[OSD_OT_REF_DEL]);
+}
+
 /*
  * Concurrency: shouldn't matter.
  */
@@ -916,33 +965,8 @@ static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
                      LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
                      oh->ot_credits,
                      osd_journal(dev)->j_max_transaction_buffers);
-               CWARN("  create: %u/%u, destroy: %u/%u\n",
-                     oti->oti_declare_ops[OSD_OT_CREATE],
-                     oti->oti_declare_ops_cred[OSD_OT_CREATE],
-                     oti->oti_declare_ops[OSD_OT_DESTROY],
-                     oti->oti_declare_ops_cred[OSD_OT_DESTROY]);
-               CWARN("  attr_set: %u/%u, xattr_set: %u/%u\n",
-                     oti->oti_declare_ops[OSD_OT_ATTR_SET],
-                     oti->oti_declare_ops_cred[OSD_OT_ATTR_SET],
-                     oti->oti_declare_ops[OSD_OT_XATTR_SET],
-                     oti->oti_declare_ops_cred[OSD_OT_XATTR_SET]);
-               CWARN("  write: %u/%u, punch: %u/%u, quota %u/%u\n",
-                     oti->oti_declare_ops[OSD_OT_WRITE],
-                     oti->oti_declare_ops_cred[OSD_OT_WRITE],
-                     oti->oti_declare_ops[OSD_OT_PUNCH],
-                     oti->oti_declare_ops_cred[OSD_OT_PUNCH],
-                     oti->oti_declare_ops[OSD_OT_QUOTA],
-                     oti->oti_declare_ops_cred[OSD_OT_QUOTA]);
-               CWARN("  insert: %u/%u, delete: %u/%u\n",
-                     oti->oti_declare_ops[OSD_OT_INSERT],
-                     oti->oti_declare_ops_cred[OSD_OT_INSERT],
-                     oti->oti_declare_ops[OSD_OT_DELETE],
-                     oti->oti_declare_ops_cred[OSD_OT_DELETE]);
-               CWARN("  ref_add: %u/%u, ref_del: %u/%u\n",
-                     oti->oti_declare_ops[OSD_OT_REF_ADD],
-                     oti->oti_declare_ops_cred[OSD_OT_REF_ADD],
-                     oti->oti_declare_ops[OSD_OT_REF_DEL],
-                     oti->oti_declare_ops_cred[OSD_OT_REF_DEL]);
+
+               osd_trans_dump_creds(env, th);
 
                if (last_credits != oh->ot_credits &&
                    time_after(jiffies, last_printed +
@@ -1006,6 +1030,22 @@ static int osd_seq_exists(const struct lu_env *env,
        RETURN(ss->ss_node_id == range->lsr_index);
 }
 
+static void osd_trans_stop_cb(struct osd_thandle *oth, int result)
+{
+       struct dt_txn_commit_cb *dcb;
+       struct dt_txn_commit_cb *tmp;
+
+       /* call per-transaction stop callbacks if any */
+       list_for_each_entry_safe(dcb, tmp, &oth->ot_stop_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);
+               list_del_init(&dcb->dcb_linkage);
+               dcb->dcb_func(NULL, &oth->ot_super, dcb, result);
+       }
+}
+
 /*
  * Concurrency: shouldn't matter.
  */
@@ -1045,6 +1085,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
                        CERROR("%s: failed in transaction hook: rc = %d\n",
                               osd_name(osd), rc);
 
+               osd_trans_stop_cb(oh, rc);
                /* hook functions might modify th_sync */
                hdl->h_sync = th->th_sync;
 
@@ -1054,6 +1095,7 @@ static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
                        CERROR("%s: failed to stop transaction: rc = %d\n",
                               osd_name(osd), rc);
        } else {
+               osd_trans_stop_cb(oh, th->th_result);
                OBD_FREE_PTR(oh);
        }
 
@@ -1085,7 +1127,10 @@ 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);
-       list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
+       if (dcb->dcb_flags & DCB_TRANS_STOP)
+               list_add(&dcb->dcb_linkage, &oh->ot_stop_dcb_list);
+       else
+               list_add(&dcb->dcb_linkage, &oh->ot_commit_dcb_list);
 
        return 0;
 }
@@ -1189,10 +1234,14 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d,
        result = sb->s_op->statfs(sb->s_root, ksfs);
        if (likely(result == 0)) { /* N.B. statfs can't really fail */
                statfs_pack(sfs, ksfs);
-               if (sb->s_flags & MS_RDONLY)
+               if (unlikely(sb->s_flags & MS_RDONLY))
                        sfs->os_state = OS_STATE_READONLY;
+               if (LDISKFS_HAS_INCOMPAT_FEATURE(sb,
+                                             LDISKFS_FEATURE_INCOMPAT_EXTENTS))
+                       sfs->os_maxbytes = sb->s_maxbytes;
+               else
+                       sfs->os_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
        }
-
        spin_unlock(&osd->od_osfs_lock);
 
        if (unlikely(env == NULL))
@@ -1239,7 +1288,10 @@ static void osd_conf_get(const struct lu_env *env,
         param->ddp_max_nlink    = LDISKFS_LINK_MAX;
        param->ddp_block_shift  = sb->s_blocksize_bits;
        param->ddp_mount_type     = LDD_MT_LDISKFS;
-       param->ddp_maxbytes       = sb->s_maxbytes;
+       if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EXTENTS))
+               param->ddp_maxbytes = sb->s_maxbytes;
+       else
+               param->ddp_maxbytes = LDISKFS_SB(sb)->s_bitmap_maxbytes;
        /* Overhead estimate should be fairly accurate, so we really take a tiny
         * error margin which also avoids fragmenting the filesystem too much */
        param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
@@ -1810,6 +1862,9 @@ static int osd_attr_set(const struct lu_env *env,
 
         if (!rc)
                ll_dirty_inode(inode, I_DIRTY_DATASYNC);
+
+       osd_trans_exec_check(env, handle, OSD_OT_ATTR_SET);
+
         return rc;
 }
 
@@ -1843,8 +1898,9 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
         oth = container_of(th, struct osd_thandle, ot_super);
         LASSERT(oth->ot_handle->h_transaction != NULL);
 
-        if (hint && hint->dah_parent)
-                parent = hint->dah_parent;
+       if (hint != NULL && hint->dah_parent != NULL &&
+           !dt_object_remote(hint->dah_parent))
+               parent = hint->dah_parent;
 
         inode = ldiskfs_create_inode(oth->ot_handle,
                                      parent ? osd_dt_obj(parent)->oo_inode :
@@ -2078,6 +2134,8 @@ static int __osd_object_create(struct osd_thread_info *info,
        int     result;
        __u32   umask;
 
+       osd_trans_exec_op(info->oti_env, th, OSD_OT_CREATE);
+
        /* we drop umask so that permissions we pass are not affected */
        umask = current->fs->umask;
        current->fs->umask = 0;
@@ -2100,6 +2158,8 @@ static int __osd_object_create(struct osd_thread_info *info,
        /* restore previous umask value */
        current->fs->umask = umask;
 
+       osd_trans_exec_check(info->oti_env, th, OSD_OT_CREATE);
+
        return result;
 }
 
@@ -2115,14 +2175,19 @@ static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
        struct osd_inode_id    *id   = &info->oti_id;
        struct osd_device      *osd  = osd_obj2dev(obj);
        struct osd_thandle     *oh;
+       int                     rc;
 
        LASSERT(obj->oo_inode != NULL);
 
        oh = container_of0(th, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle);
+       osd_trans_exec_op(env, th, OSD_OT_INSERT);
 
        osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
-       return osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
+       rc = osd_oi_insert(info, osd, fid, id, oh->ot_handle, OI_CHECK_FLD);
+       osd_trans_exec_check(env, th, OSD_OT_INSERT);
+
+       return rc;
 }
 
 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
@@ -2170,24 +2235,18 @@ static int osd_declare_object_create(const struct lu_env *env,
        oh = container_of0(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle == NULL);
 
+       /* EA object consumes more credits than regular object: osd_mk_index
+        * vs. osd_mkreg: osd_mk_index will create 2 blocks for root_node and
+        * leaf_node, could involves the block, block bitmap, groups, GDT
+        * change for each block, so add 4 * 2 credits in that case. */
        osd_trans_declare_op(env, oh, OSD_OT_CREATE,
-                            osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
+                            osd_dto_credits_noquota[DTO_OBJECT_CREATE] +
+                            (dof->dof_type == DFT_INDEX) ? 4 * 2 : 0);
        /* Reuse idle OI block may cause additional one OI block
         * to be changed. */
        osd_trans_declare_op(env, oh, OSD_OT_INSERT,
                             osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
 
-       /* If this is directory, then we expect . and .. to be inserted as
-        * well. The one directory block always needs to be created for the
-        * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
-        * block), there is no danger of needing a tree for the first block.
-        */
-       if (attr && S_ISDIR(attr->la_mode)) {
-               osd_trans_declare_op(env, oh, OSD_OT_INSERT,
-                                    osd_dto_credits_noquota[DTO_WRITE_BASE]);
-               osd_trans_declare_op(env, oh, OSD_OT_INSERT, 0);
-       }
-
        if (!attr)
                RETURN(0);
 
@@ -2223,18 +2282,17 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
                 * 'tune2fs -O quota' will take care of creating them */
                RETURN(-EPERM);
 
-       osd_trans_exec_op(env, th, OSD_OT_CREATE);
-       osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
-
-        result = __osd_object_create(info, obj, attr, hint, dof, th);
-        if (result == 0)
-                result = __osd_oi_insert(env, obj, fid, th);
-
+       result = __osd_object_create(info, obj, attr, hint, dof, th);
+       if (result == 0) {
+               result = __osd_oi_insert(env, obj, fid, th);
+               if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
+                       obj->oo_dt.do_body_ops = &osd_body_ops;
+       }
        LASSERT(ergo(result == 0,
-                    dt_object_exists(dt) && !dt_object_remote(dt)));
+               dt_object_exists(dt) && !dt_object_remote(dt)));
 
-        LASSERT(osd_invariant(obj));
-        RETURN(result);
+       LASSERT(osd_invariant(obj));
+       RETURN(result);
 }
 
 /**
@@ -2314,13 +2372,15 @@ static int osd_object_destroy(const struct lu_env *env,
        result = osd_oi_delete(osd_oti_get(env), osd, fid, oh->ot_handle,
                               OI_CHECK_FLD);
 
-        /* XXX: add to ext3 orphan list */
-        /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
+       osd_trans_exec_check(env, th, OSD_OT_DESTROY);
+       /* XXX: add to ext3 orphan list */
+       /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
 
-        /* not needed in the cache anymore */
-        set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
+       /* not needed in the cache anymore */
+       set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
+       obj->oo_destroyed = 1;
 
-        RETURN(0);
+       RETURN(0);
 }
 
 /**
@@ -2343,6 +2403,9 @@ int osd_ea_fid_set(struct osd_thread_info *info, struct inode *inode,
        if (OBD_FAIL_CHECK(OBD_FAIL_FID_INLMA))
                RETURN(0);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_OSD_OST_EA_FID_SET))
+               rc = -ENOMEM;
+
        lustre_lma_init(lma, fid, compat, incompat);
        lustre_lma_swab(lma);
 
@@ -2436,8 +2499,9 @@ static int osd_add_dot_dotdot_internal(struct osd_thread_info *info,
 
        dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
        dot_ldp->edp_magic = 0;
+
        return ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
-                                       dir, dot_ldp, dot_dot_ldp);
+                                     dir, dot_ldp, dot_dot_ldp);
 }
 
 /**
@@ -2557,9 +2621,6 @@ static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
                 * 'tune2fs -O quota' will take care of creating them */
                RETURN(-EPERM);
 
-       osd_trans_exec_op(env, th, OSD_OT_CREATE);
-       osd_trans_declare_rb(env, th, OSD_OT_REF_ADD);
-
        result = __osd_object_create(info, obj, attr, hint, dof, th);
        if (result == 0) {
                if (fid_is_idif(fid) &&
@@ -2577,6 +2638,8 @@ static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
                                              fid, OI_CHECK_FLD) ?
                                LMAC_FID_ON_OST : 0, 0);
                }
+               if (obj->oo_dt.do_body_ops == &osd_body_ops_new)
+                       obj->oo_dt.do_body_ops = &osd_body_ops;
        }
 
        if (result == 0)
@@ -2657,6 +2720,8 @@ static int osd_object_ref_add(const struct lu_env *env,
        ll_dirty_inode(inode, I_DIRTY_DATASYNC);
        LINVRNT(osd_invariant(obj));
 
+       osd_trans_exec_check(env, th, OSD_OT_REF_ADD);
+
        return rc;
 }
 
@@ -2724,6 +2789,8 @@ static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
        ll_dirty_inode(inode, I_DIRTY_DATASYNC);
        LINVRNT(osd_invariant(obj));
 
+       osd_trans_exec_check(env, th, OSD_OT_REF_DEL);
+
        return 0;
 }
 
@@ -2792,15 +2859,20 @@ static int osd_declare_xattr_set(const struct lu_env *env,
        oh = container_of0(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle == NULL);
 
-       /* optimistic optimization: LMA is set first and usually fit inode */
        if (strcmp(name, XATTR_NAME_LMA) == 0) {
-               if (dt_object_exists(dt))
+               /* For non-upgrading case, the LMA is set first and
+                * usually fit inode. But for upgrade case, the LMA
+                * may be in another separated EA block. */
+               if (!dt_object_exists(dt))
                        credits = 0;
-               else
+               else if (fl == LU_XATTR_REPLACE)
                        credits = 1;
+               else
+                       goto upgrade;
        } else if (strcmp(name, XATTR_NAME_VERSION) == 0) {
                credits = 1;
        } else {
+upgrade:
                credits = osd_dto_credits_noquota[DTO_XATTR_SET];
                if (buf && buf->lb_len > sb->s_blocksize) {
                        credits *= (buf->lb_len + sb->s_blocksize - 1) >>
@@ -2810,7 +2882,7 @@ static int osd_declare_xattr_set(const struct lu_env *env,
                 * xattr set may involve inode quota change, reserve credits for
                 * dquot_initialize()
                 */
-               oh->ot_credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
+               credits += LDISKFS_MAXQUOTAS_INIT_BLOCKS(sb);
        }
 
        osd_trans_declare_op(env, oh, OSD_OT_XATTR_SET, credits);
@@ -2847,6 +2919,7 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
        struct inode           *inode    = obj->oo_inode;
        struct osd_thread_info *info     = osd_oti_get(env);
        int                     fs_flags = 0;
+       int                     rc;
        ENTRY;
 
         LASSERT(handle != NULL);
@@ -2890,8 +2963,11 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
            strcmp(name, XATTR_NAME_LINK) == 0)
                return -ENOSPC;
 
-       return __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
+       rc = __osd_xattr_set(info, inode, name, buf->lb_buf, buf->lb_len,
                               fs_flags);
+       osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
+
+       return rc;
 }
 
 /*
@@ -2967,6 +3043,7 @@ static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
        rc = inode->i_op->removexattr(dentry, name);
+       osd_trans_exec_check(env, handle, OSD_OT_XATTR_SET);
        return rc;
 }
 
@@ -2984,7 +3061,7 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
 
        dentry->d_inode = inode;
        dentry->d_sb = inode->i_sb;
-       file->f_dentry = dentry;
+       file->f_path.dentry = dentry;
        file->f_mapping = inode->i_mapping;
        file->f_op = inode->i_fop;
        set_file_inode(file, inode);
@@ -3120,9 +3197,9 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
         }
         LINVRNT(osd_invariant(obj));
 
-       if (result == 0 && is_quota_glb_feat(feat) &&
+       if (result == 0 && feat == &dt_quota_glb_features &&
            fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB)
-               result = osd_quota_migration(env, dt, feat);
+               result = osd_quota_migration(env, dt);
 
         return result;
 }
@@ -3266,6 +3343,7 @@ static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
         rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
         osd_ipd_put(env, bag, ipd);
         LINVRNT(osd_invariant(obj));
+       osd_trans_exec_check(env, handle, OSD_OT_DELETE);
         RETURN(rc);
 }
 
@@ -3285,8 +3363,10 @@ static int osd_index_declare_ea_delete(const struct lu_env *env,
        oh = container_of0(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle == NULL);
 
+       /* due to DNE we may need to remove an agent inode */
        osd_trans_declare_op(env, oh, OSD_OT_DELETE,
-                            osd_dto_credits_noquota[DTO_INDEX_DELETE]);
+                            osd_dto_credits_noquota[DTO_INDEX_DELETE] +
+                            osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
 
        inode = osd_dt_obj(dt)->oo_inode;
        LASSERT(inode);
@@ -3485,6 +3565,7 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
 out:
 
         LASSERT(osd_invariant(obj));
+       osd_trans_exec_check(env, handle, OSD_OT_DELETE);
         RETURN(rc);
 }
 
@@ -3637,6 +3718,7 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
                         iam_rec, ipd);
         osd_ipd_put(env, bag, ipd);
         LINVRNT(osd_invariant(obj));
+       osd_trans_exec_check(env, th, OSD_OT_INSERT);
         RETURN(rc);
 }
 
@@ -3761,13 +3843,6 @@ static int osd_add_dot_dotdot(struct osd_thread_info *info,
                        dir->oo_compat_dotdot_created = 1;
        }
 
-       /* ldiskfs_init_new_dir() doesn't call ldiskfs_mark_inode_dirty()
-        * this seem as an optimization as usually it's called
-        * later to refresh mtime of the parent. Lustre does not
-        * update mtime in few cases (e.g. PENDING, .lustre)
-        * we still need to transfer i_size/etc to the buffer cache */
-       ldiskfs_mark_inode_dirty(oth->ot_handle, dir->oo_inode);
-
        return result;
 }
 
@@ -4163,7 +4238,7 @@ static int osd_index_declare_ea_insert(const struct lu_env *env,
        struct osd_thandle      *oh;
        struct osd_device       *osd   = osd_dev(dt->do_lu.lo_dev);
        struct lu_fid           *fid = (struct lu_fid *)rec;
-       int                     rc;
+       int                      credits, rc = 0;
        ENTRY;
 
        LASSERT(!dt_object_remote(dt));
@@ -4172,8 +4247,21 @@ static int osd_index_declare_ea_insert(const struct lu_env *env,
        oh = container_of0(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_handle == NULL);
 
-       osd_trans_declare_op(env, oh, OSD_OT_INSERT,
-                            osd_dto_credits_noquota[DTO_INDEX_INSERT]);
+       credits = osd_dto_credits_noquota[DTO_INDEX_INSERT];
+       if (fid != NULL) {
+               rc = osd_remote_fid(env, osd, fid);
+               if (unlikely(rc < 0))
+                       RETURN(rc);
+               if (rc > 0) {
+                       /* a reference to remote inode is represented by an
+                        * agent inode which we have to create */
+                       credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
+                       credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
+               }
+               rc = 0;
+       }
+
+       osd_trans_declare_op(env, oh, OSD_OT_INSERT, credits);
 
        if (osd_dt_obj(dt)->oo_inode != NULL) {
                struct inode *inode = osd_dt_obj(dt)->oo_inode;
@@ -4186,22 +4274,6 @@ static int osd_index_declare_ea_insert(const struct lu_env *env,
                                           osd_dt_obj(dt), true, NULL, false);
        }
 
-       if (fid == NULL)
-               RETURN(0);
-
-       rc = osd_remote_fid(env, osd, fid);
-       if (rc <= 0)
-               RETURN(rc);
-
-       rc = 0;
-
-       osd_trans_declare_op(env, oh, OSD_OT_CREATE,
-                            osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
-       osd_trans_declare_op(env, oh, OSD_OT_INSERT,
-                            osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
-       osd_trans_declare_op(env, oh, OSD_OT_INSERT,
-                            osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
-
        RETURN(rc);
 }
 
@@ -4297,6 +4369,7 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
        if (child != NULL)
                osd_object_put(env, child);
        LASSERT(osd_invariant(obj));
+       osd_trans_exec_check(env, th, OSD_OT_INSERT);
        RETURN(rc);
 }
 
@@ -4597,7 +4670,7 @@ static struct dt_it *osd_it_ea_init(const struct lu_env *env,
        struct dentry           *obj_dentry;
        ENTRY;
 
-       if (!dt_object_exists(dt))
+       if (!dt_object_exists(dt) || obj->oo_destroyed)
                RETURN(ERR_PTR(-ENOENT));
 
        OBD_SLAB_ALLOC_PTR_GFP(oie, osd_itea_cachep, GFP_NOFS);
@@ -4629,8 +4702,8 @@ static struct dt_it *osd_it_ea_init(const struct lu_env *env,
                file->f_mode    = FMODE_64BITHASH;
        else
                file->f_mode    = FMODE_32BITHASH;
-       file->f_dentry          = obj_dentry;
-       file->f_mapping         = obj->oo_inode->i_mapping;
+       file->f_path.dentry     = obj_dentry;
+       file->f_mapping         = obj->oo_inode->i_mapping;
        file->f_op              = obj->oo_inode->i_fop;
        set_file_inode(file, obj->oo_inode);
 
@@ -5303,17 +5376,19 @@ static inline int osd_it_ea_rec(const struct lu_env *env,
        } else {
                attr &= ~LU_DIRENT_ATTRS_MASK;
                if (!fid_is_sane(fid)) {
+                       bool is_dotdot = false;
                        if (it->oie_dirent->oied_namelen == 2 &&
                            it->oie_dirent->oied_name[0] == '.' &&
-                           it->oie_dirent->oied_name[1] == '.') {
-                               /* 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.  */
-                               if (ino == osd_remote_parent_ino(dev))
-                                       rc = osd_get_pfid_from_linkea(env, obj,
-                                                                     fid);
+                           it->oie_dirent->oied_name[1] == '.')
+                               is_dotdot = true;
+                       /* 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.  */
+                       if (ino == osd_remote_parent_ino(dev) && is_dotdot) {
+                               rc = osd_get_pfid_from_linkea(env, obj, fid);
                        } else {
-                               if (OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
+                               if (is_dotdot == false &&
+                                   OBD_FAIL_CHECK(OBD_FAIL_FID_LOOKUP))
                                        RETURN(-ENOENT);
 
                                rc = osd_ea_fid_get(env, obj, ino, fid, id);
@@ -5648,7 +5723,7 @@ static int osd_mount(const struct lu_env *env,
        if (opts != NULL && strstr(opts, "force_over_128tb") != NULL)
                force_over_128tb = 1;
 
-       OBD_PAGE_ALLOC(__page, GFP_IOFS);
+       __page = alloc_page(GFP_IOFS);
        if (__page == NULL)
                GOTO(out, rc = -ENOMEM);
        page = (unsigned long)page_address(__page);
@@ -5763,7 +5838,7 @@ out_mnt:
 
 out:
        if (__page)
-               OBD_PAGE_FREE(__page);
+               __free_page(__page);
 
        return rc;
 }
@@ -5816,7 +5891,9 @@ static int osd_device_init0(const struct lu_env *env,
                GOTO(out, rc);
        }
 
-       if (server_name_is_ost(o->od_svname))
+       o->od_index = -1; /* -1 means index is invalid */
+       rc = server_name2index(o->od_svname, &o->od_index, NULL);
+       if (rc == LDD_F_SV_TYPE_OST)
                o->od_is_ost = 1;
 
        o->od_full_scrub_ratio = OFSR_DEFAULT;