Whamcloud - gitweb
LU-8856 osd: mark specific transactions netfree
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index e9b127d..62f7a83 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -62,6 +62,7 @@
 #include <sys/txg.h>
 
 char *osd_obj_tag = "osd_object";
+static int osd_object_sync_delay_us = -1;
 
 static struct dt_object_operations osd_obj_ops;
 static struct lu_object_operations osd_lu_obj_ops;
@@ -308,9 +309,26 @@ struct lu_object *osd_object_alloc(const struct lu_env *env,
        OBD_SLAB_ALLOC_PTR_GFP(mo, osd_object_kmem, GFP_NOFS);
        if (mo != NULL) {
                struct lu_object *l;
+               struct lu_object_header *h;
+               struct osd_device *o = osd_dev(d);
 
                l = &mo->oo_dt.do_lu;
-               dt_object_init(&mo->oo_dt, NULL, d);
+               if (unlikely(o->od_in_init)) {
+                       OBD_ALLOC_PTR(h);
+                       if (!h) {
+                               OBD_FREE_PTR(mo);
+                               return NULL;
+                       }
+
+                       lu_object_header_init(h);
+                       lu_object_init(l, h, d);
+                       lu_object_add_top(h, l);
+                       mo->oo_header = h;
+               } else {
+                       dt_object_init(&mo->oo_dt, NULL, d);
+                       mo->oo_header = NULL;
+               }
+
                mo->oo_dt.do_ops = &osd_obj_ops;
                l->lo_ops = &osd_lu_obj_ops;
                INIT_LIST_HEAD(&mo->oo_sa_linkage);
@@ -325,6 +343,66 @@ struct lu_object *osd_object_alloc(const struct lu_env *env,
        }
 }
 
+static void osd_obj_set_blksize(const struct lu_env *env,
+                               struct osd_device *osd, struct osd_object *obj)
+{
+       const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
+       dmu_tx_t *tx;
+       dnode_t *dn = obj->oo_dn;
+       uint32_t blksz;
+       int rc = 0;
+       ENTRY;
+
+       LASSERT(!osd_oti_get(env)->oti_in_trans);
+
+       tx = dmu_tx_create(osd->od_os);
+       if (!tx) {
+               CERROR("%s: fail to create tx to set blksize for "DFID"\n",
+                      osd->od_svname, PFID(fid));
+               RETURN_EXIT;
+       }
+
+       dmu_tx_hold_bonus(tx, dn->dn_object);
+       rc = -dmu_tx_assign(tx, TXG_WAIT);
+       if (rc) {
+               dmu_tx_abort(tx);
+               CERROR("%s: fail to assign tx to set blksize for "DFID
+                      ": rc = %d\n", osd->od_svname, PFID(fid), rc);
+               RETURN_EXIT;
+       }
+
+       down_write(&obj->oo_guard);
+       if (unlikely((1 << dn->dn_datablkshift) >= PAGE_SIZE))
+               GOTO(out, rc = 1);
+
+       blksz = dn->dn_datablksz;
+       if (!is_power_of_2(blksz))
+               blksz = size_roundup_power2(blksz);
+
+       if (blksz > osd->od_max_blksz)
+               blksz = osd->od_max_blksz;
+       else if (blksz < PAGE_SIZE)
+               blksz = PAGE_SIZE;
+       rc = -dmu_object_set_blocksize(osd->od_os, dn->dn_object, blksz, 0, tx);
+
+       GOTO(out, rc);
+
+out:
+       up_write(&obj->oo_guard);
+       if (rc) {
+               dmu_tx_abort(tx);
+               if (unlikely(obj->oo_dn->dn_maxblkid > 0))
+                       rc = 1;
+               if (rc < 0)
+                       CERROR("%s: fail to set blksize for "DFID": rc = %d\n",
+                              osd->od_svname, PFID(fid), rc);
+       } else {
+               dmu_tx_commit(tx);
+               CDEBUG(D_INODE, "%s: set blksize as %u for "DFID"\n",
+                      osd->od_svname, blksz, PFID(fid));
+       }
+}
+
 /*
  * Concurrency: shouldn't matter.
  */
@@ -335,10 +413,7 @@ int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
        int                      rc = 0;
        ENTRY;
 
-       if (obj->oo_dn == NULL)
-               RETURN(0);
-
-       /* object exist */
+       LASSERT(obj->oo_dn);
 
        rc = osd_object_sa_init(obj, osd);
        if (rc)
@@ -349,10 +424,19 @@ int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
        if (rc)
                RETURN(rc);
 
-       if (likely(!fid_is_acct(fid)))
+       if (likely(!fid_is_acct(fid))) {
                /* no body operations for accounting objects */
                obj->oo_dt.do_body_ops = &osd_body_ops;
 
+               if (S_ISREG(obj->oo_attr.la_mode) &&
+                   obj->oo_dn->dn_maxblkid == 0 &&
+                   (1 << obj->oo_dn->dn_datablkshift) < PAGE_SIZE &&
+                   (fid_is_idif(fid) || fid_is_norm(fid) ||
+                    fid_is_echo(fid)) &&
+                   osd->od_is_ost && !osd->od_dt_dev.dd_rdonly)
+                       osd_obj_set_blksize(env, osd, obj);
+       }
+
        /*
         * initialize object before marking it existing
         */
@@ -370,6 +454,7 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
        struct lu_buf           buf;
        int                     rc;
        struct lustre_mdt_attrs *lma;
+       const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
        ENTRY;
 
        CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
@@ -386,8 +471,23 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
                        CWARN("%s: unsupported incompat LMA feature(s) %#x for "
                              "fid = "DFID"\n", osd_obj2dev(obj)->od_svname,
                              lma->lma_incompat & ~LMA_INCOMPAT_SUPP,
-                             PFID(lu_object_fid(&obj->oo_dt.do_lu)));
+                             PFID(rfid));
                        rc = -EOPNOTSUPP;
+               } else if (unlikely(!lu_fid_eq(rfid, &lma->lma_self_fid))) {
+                       CERROR("%s: FID-in-LMA "DFID" does not match the "
+                             "object self-fid "DFID"\n",
+                             osd_obj2dev(obj)->od_svname,
+                             PFID(&lma->lma_self_fid), PFID(rfid));
+                       rc = -EREMCHG;
+               } else {
+                       struct osd_device *osd = osd_obj2dev(obj);
+
+                       if (lma->lma_compat & LMAC_STRIPE_INFO &&
+                           osd->od_is_ost)
+                               obj->oo_pfid_in_lma = 1;
+                       if (unlikely(lma->lma_incompat & LMAI_REMOTE_PARENT) &&
+                           osd->od_remote_parent_dir != ZFS_NO_OBJECT)
+                               lu_object_set_agent_entry(&obj->oo_dt.do_lu);
                }
        } else if (rc == -ENODATA) {
                /* haven't initialize LMA xattr */
@@ -436,8 +536,15 @@ static int osd_object_init(const struct lu_env *env, struct lu_object *l,
        struct osd_object *obj = osd_obj(l);
        struct osd_device *osd = osd_obj2dev(obj);
        const struct lu_fid *fid = lu_object_fid(l);
+       struct lustre_scrub *scrub = &osd->od_scrub;
+       struct osd_thread_info *info = osd_oti_get(env);
+       struct luz_direntry *zde = &info->oti_zde;
+       struct osd_idmap_cache *idc;
+       char *name = info->oti_str;
        uint64_t oid;
        int rc = 0;
+       int rc1;
+       bool remote = false;
        ENTRY;
 
        LASSERT(osd_invariant(obj));
@@ -445,10 +552,11 @@ static int osd_object_init(const struct lu_env *env, struct lu_object *l,
        if (fid_is_otable_it(&l->lo_header->loh_fid)) {
                obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
                l->lo_header->loh_attr |= LOHA_EXISTS;
-               RETURN(0);
+
+               GOTO(out, rc = 0);
        }
 
-       if (conf != NULL && conf->loc_flags & LOC_F_NEW)
+       if (conf && conf->loc_flags & LOC_F_NEW)
                GOTO(out, rc = 0);
 
        if (unlikely(fid_is_acct(fid))) {
@@ -461,32 +569,117 @@ static int osd_object_init(const struct lu_env *env, struct lu_object *l,
                GOTO(out, rc = 0);
        }
 
-       rc = osd_fid_lookup(env, osd, fid, &oid);
-       if (rc == 0) {
-               LASSERT(obj->oo_dn == NULL);
-               rc = __osd_obj2dnode(osd->od_os, oid, &obj->oo_dn);
-               /* EEXIST will be returned if object is being deleted in ZFS */
-               if (rc == -EEXIST) {
-                       rc = 0;
-                       GOTO(out, rc);
+       idc = osd_idc_find(env, osd, fid);
+       if (idc && !idc->oic_remote && idc->oic_dnode != ZFS_NO_OBJECT) {
+               oid = idc->oic_dnode;
+               goto zget;
+       }
+
+       rc = -ENOENT;
+       if (!list_empty(&osd->od_scrub.os_inconsistent_items))
+               rc = osd_oii_lookup(osd, fid, &oid);
+
+       if (rc)
+               rc = osd_fid_lookup(env, osd, fid, &oid);
+
+       if (rc == -ENOENT) {
+               if (likely(!(fid_is_norm(fid) || fid_is_igif(fid)) ||
+                          fid_is_on_ost(env, osd, fid) ||
+                          !zfs_test_bit(osd_oi_fid2idx(osd, fid),
+                                        scrub->os_file.sf_oi_bitmap)))
+                       GOTO(out, rc = 0);
+
+               rc = -EREMCHG;
+               goto trigger;
+       }
+
+       if (rc)
+               GOTO(out, rc);
+
+zget:
+       LASSERT(obj->oo_dn == NULL);
+
+       rc = __osd_obj2dnode(osd->od_os, oid, &obj->oo_dn);
+       /* EEXIST will be returned if object is being deleted in ZFS */
+       if (rc == -EEXIST)
+               GOTO(out, rc = 0);
+
+       if (rc) {
+               CERROR("%s: lookup "DFID"/%#llx failed: rc = %d\n",
+                      osd->od_svname, PFID(lu_object_fid(l)), oid, rc);
+               GOTO(out, rc);
+       }
+
+       rc = osd_object_init0(env, obj);
+       if (rc)
+               GOTO(out, rc);
+
+       if (unlikely(obj->oo_header))
+               GOTO(out, rc = 0);
+
+       rc = osd_check_lma(env, obj);
+       if ((!rc && !remote) || (rc != -EREMCHG))
+               GOTO(out, rc);
+
+trigger:
+       /* We still have chance to get the valid dnode: for the object that is
+        * referenced by remote name entry, the object on the local MDT will be
+        * linked under the dir /REMOTE_PARENT_DIR with its FID string as name.
+        *
+        * During the OI scrub, if we cannot find the OI mapping, we may still
+        * have change to map the FID to local OID via lookup the dir
+        * /REMOTE_PARENT_DIR. */
+       if (!remote && !fid_is_on_ost(env, osd, fid)) {
+               osd_fid2str(name, fid, sizeof(info->oti_str));
+               rc = osd_zap_lookup(osd, osd->od_remote_parent_dir,
+                                   NULL, name, 8, 3, (void *)zde);
+               if (!rc) {
+                       oid = zde->lzd_reg.zde_dnode;
+                       osd_dnode_rele(obj->oo_dn);
+                       obj->oo_dn = NULL;
+                       remote = true;
+                       goto zget;
                }
-               if (rc != 0) {
-                       CERROR("%s: lookup "DFID"/%#llx failed: rc = %d\n",
-                              osd->od_svname, PFID(lu_object_fid(l)), oid, rc);
-                       GOTO(out, rc);
+       }
+
+       /* The case someone triggered the OI scrub already. */
+       if (thread_is_running(&scrub->os_thread)) {
+               if (!rc) {
+                       LASSERT(remote);
+
+                       lu_object_set_agent_entry(l);
+                       osd_oii_insert(env, osd, fid, oid, false);
+               } else {
+                       rc = -EINPROGRESS;
                }
-               LASSERT(obj->oo_dn);
-               rc = osd_object_init0(env, obj);
-               if (rc != 0)
-                       GOTO(out, rc);
 
-               rc = osd_check_lma(env, obj);
-               if (rc != 0)
-                       GOTO(out, rc);
-       } else if (rc == -ENOENT) {
-               rc = 0;
+               GOTO(out, rc);
        }
-       LASSERT(osd_invariant(obj));
+
+       /* The case NOT allow to trigger OI scrub automatically. */
+       if (osd->od_auto_scrub_interval == AS_NEVER)
+               GOTO(out, rc);
+
+       /* It is me to trigger the OI scrub. */
+       rc1 = osd_scrub_start(env, osd, SS_CLEAR_DRYRUN |
+                             SS_CLEAR_FAILOUT | SS_AUTO_FULL);
+       LCONSOLE_WARN("%s: trigger OI scrub by RPC for the "DFID": rc = %d\n",
+                     osd_name(osd), PFID(fid), rc1);
+       if (!rc) {
+               LASSERT(remote);
+
+               lu_object_set_agent_entry(l);
+               if (!rc1)
+                       osd_oii_insert(env, osd, fid, oid, false);
+       } else {
+               if (!rc1)
+                       rc = -EINPROGRESS;
+               else
+                       rc = -EREMCHG;
+       }
+
+       GOTO(out, rc);
+
 out:
        RETURN(rc);
 }
@@ -498,11 +691,16 @@ out:
 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
 {
        struct osd_object *obj = osd_obj(l);
+       struct lu_object_header *h = obj->oo_header;
 
        LASSERT(osd_invariant(obj));
 
        dt_object_fini(&obj->oo_dt);
        OBD_SLAB_FREE_PTR(obj, osd_object_kmem);
+       if (unlikely(h)) {
+               lu_object_header_fini(h);
+               OBD_FREE_PTR(h);
+       }
 }
 
 static int
@@ -564,6 +762,8 @@ static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
        oh = container_of0(th, struct osd_thandle, ot_super);
        LASSERT(oh->ot_tx != NULL);
 
+       dmu_tx_mark_netfree(oh->ot_tx);
+
        /* declare that we'll remove object from fid-dnode mapping */
        zapid = osd_get_name_n_idx(env, osd, fid, NULL, 0, &dn);
        osd_tx_hold_zap(oh->ot_tx, zapid, dn, FALSE, NULL);
@@ -592,6 +792,11 @@ static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
                osd_tx_hold_zap(oh->ot_tx, osd->od_unlinked->dn_object,
                                osd->od_unlinked, TRUE, NULL);
 
+       /* remove agent entry (if have) from remote parent */
+       if (lu_object_has_agent_entry(&obj->oo_dt.do_lu))
+               osd_tx_hold_zap(oh->ot_tx, osd->od_remote_parent_dir,
+                               NULL, FALSE, NULL);
+
        /* will help to find FID->ino when this object is being
         * added to PENDING/ */
        osd_idc_find_and_init(env, osd, obj);
@@ -627,13 +832,6 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
        /* remove obj ref from index dir (it depends) */
        zapid = osd_get_name_n_idx(env, osd, fid, buf,
                                   sizeof(info->oti_str), &zdn);
-       rc = osd_zap_remove(osd, zapid, zdn, buf, oh->ot_tx);
-       if (rc) {
-               CERROR("%s: zap_remove(%s) failed: rc = %d\n",
-                      osd->od_svname, buf, rc);
-               GOTO(out, rc);
-       }
-
        rc = osd_xattrs_destroy(env, obj, oh);
        if (rc) {
                CERROR("%s: cannot destroy xattrs for %s: rc = %d\n",
@@ -641,6 +839,12 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
                GOTO(out, rc);
        }
 
+       if (lu_object_has_agent_entry(&obj->oo_dt.do_lu)) {
+               rc = osd_delete_from_remote_parent(env, osd, obj, oh, true);
+               if (rc)
+                       GOTO(out, rc);
+       }
+
        oid = obj->oo_dn->dn_object;
        if (unlikely(obj->oo_destroy == OSD_DESTROY_NONE)) {
                /* this may happen if the destroy wasn't declared
@@ -672,6 +876,17 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
                               osd->od_svname, buf, oid, rc);
        }
 
+       /* Remove the OI mapping after the destroy to handle the race with
+        * OI scrub that may insert missed OI mapping during the interval. */
+       rc = osd_zap_remove(osd, zapid, zdn, buf, oh->ot_tx);
+       if (unlikely(rc == -ENOENT))
+               rc = 0;
+       if (rc)
+               CERROR("%s: zap_remove(%s) failed: rc = %d\n",
+                      osd->od_svname, buf, rc);
+
+       GOTO(out, rc);
+
 out:
        /* not needed in the cache anymore */
        set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
@@ -824,7 +1039,7 @@ static inline int qsd_transfer(const struct lu_env *env,
                               struct qsd_instance *qsd,
                               struct lquota_trans *trans, int qtype,
                               __u64 orig_id, __u64 new_id, __u64 bspace,
-                              struct lquota_id_info *qi)
+                              struct lquota_id_info *qi, bool ignore_edquot)
 {
        int     rc;
 
@@ -841,7 +1056,7 @@ static inline int qsd_transfer(const struct lu_env *env,
        qi->lqi_id.qid_uid = new_id;
        qi->lqi_space      = 1;
        rc = qsd_op_begin(env, qsd, trans, qi, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
        if (rc)
                return rc;
@@ -863,7 +1078,7 @@ static inline int qsd_transfer(const struct lu_env *env,
        qi->lqi_id.qid_uid = new_id;
        qi->lqi_space      = bspace;
        rc = qsd_op_begin(env, qsd, trans, qi, NULL);
-       if (rc == -EDQUOT || rc == -EINPROGRESS)
+       if (ignore_edquot && (rc == -EDQUOT || rc == -EINPROGRESS))
                rc = 0;
        if (rc)
                return rc;
@@ -933,7 +1148,11 @@ static int osd_declare_attr_set(const struct lu_env *env,
 
        if (attr && (attr->la_valid & (LA_UID | LA_GID | LA_PROJID))) {
                sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
-               bspace = toqb(bspace * blksize);
+               bspace = toqb(bspace * 512);
+
+               CDEBUG(D_QUOTA, "%s: enforce quota on UID %u, GID %u,"
+                      "the quota space is %lld (%u)\n", osd->od_svname,
+                      attr->la_uid, attr->la_gid, bspace, blksize);
        }
 
        if (attr && attr->la_valid & LA_UID) {
@@ -942,7 +1161,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
                        rc = qsd_transfer(env, osd->od_quota_slave,
                                          &oh->ot_quota_trans, USRQUOTA,
                                          obj->oo_attr.la_uid, attr->la_uid,
-                                         bspace, &info->oti_qi);
+                                         bspace, &info->oti_qi, true);
                        if (rc)
                                GOTO(out, rc);
                }
@@ -953,7 +1172,9 @@ static int osd_declare_attr_set(const struct lu_env *env,
                        rc = qsd_transfer(env, osd->od_quota_slave,
                                          &oh->ot_quota_trans, GRPQUOTA,
                                          obj->oo_attr.la_gid, attr->la_gid,
-                                         bspace, &info->oti_qi);
+                                         bspace, &info->oti_qi,
+                                         !(attr->la_flags &
+                                                       LUSTRE_SET_SYNC_FL));
                        if (rc)
                                GOTO(out, rc);
                }
@@ -984,7 +1205,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
                                          &oh->ot_quota_trans, PRJQUOTA,
                                          obj->oo_attr.la_projid,
                                          attr->la_projid, bspace,
-                                         &info->oti_qi);
+                                         &info->oti_qi, true);
                        if (rc)
                                GOTO(out, rc);
                }
@@ -1030,6 +1251,26 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
           transaction group. */
        LASSERT(oh->ot_tx->tx_txg != 0);
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_OSD_FID_MAPPING) && !osd->od_is_ost) {
+               struct zpl_direntry *zde = &info->oti_zde.lzd_reg;
+               char *buf = info->oti_str;
+               dnode_t *zdn = NULL;
+               uint64_t zapid;
+
+               zapid = osd_get_name_n_idx(env, osd, lu_object_fid(&dt->do_lu),
+                                          buf, sizeof(info->oti_str), &zdn);
+               rc = osd_zap_lookup(osd, zapid, zdn, buf, 8,
+                                   sizeof(*zde) / 8, zde);
+               if (!rc) {
+                       zde->zde_dnode -= 1;
+                       rc = -zap_update(osd->od_os, zapid, buf, 8,
+                                        sizeof(*zde) / 8, zde, oh->ot_tx);
+               }
+               up_read(&obj->oo_guard);
+
+               RETURN(rc > 0 ? 0 : rc);
+       }
+
        /* Only allow set size for regular file */
        if (!S_ISREG(dt->do_lu.lo_header->loh_attr))
                valid &= ~(LA_SIZE | LA_BLOCKS);
@@ -1051,6 +1292,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                struct lu_buf buf;
 
                if (la->la_flags & LUSTRE_LMA_FL_MASKS) {
+                       LASSERT(!obj->oo_pfid_in_lma);
                        CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
                        lma = (struct lustre_mdt_attrs *)&info->oti_buf;
                        buf.lb_buf = lma;
@@ -1225,9 +1467,7 @@ static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
        LASSERT(oh->ot_tx != NULL);
 
        /* this is the minimum set of EAs on every Lustre object */
-       obj->oo_ea_in_bonus = ZFS_SA_BASE_ATTR_SIZE +
-                               sizeof(__u64) + /* VBR VERSION */
-                               sizeof(struct lustre_mdt_attrs); /* LMA */
+       obj->oo_ea_in_bonus = OSD_BASE_EA_IN_BONUS;
        /* reserve 32 bytes for extra stuff like ACLs */
        dnode_size = size_roundup_power2(obj->oo_ea_in_bonus + 32);
 
@@ -1366,8 +1606,8 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
        return rc;
 }
 
-static int osd_find_new_dnode(const struct lu_env *env, dmu_tx_t *tx,
-                             uint64_t oid, dnode_t **dnp)
+int osd_find_new_dnode(const struct lu_env *env, dmu_tx_t *tx,
+                      uint64_t oid, dnode_t **dnp)
 {
        dmu_tx_hold_t *txh;
        int rc = 0;
@@ -1409,15 +1649,14 @@ static int osd_find_new_dnode(const struct lu_env *env, dmu_tx_t *tx,
 }
 
 #ifdef HAVE_DMU_OBJECT_ALLOC_DNSIZE
-static int osd_find_dnsize(struct osd_object *obj)
+int osd_find_dnsize(struct osd_device *osd, int ea_in_bonus)
 {
-       struct osd_device *osd = osd_obj2dev(obj);
        int dnsize;
 
        if (osd->od_dnsize == ZFS_DNSIZE_AUTO) {
                dnsize = DNODE_MIN_SIZE;
                do {
-                       if (DN_BONUS_SIZE(dnsize) >= obj->oo_ea_in_bonus + 32)
+                       if (DN_BONUS_SIZE(dnsize) >= ea_in_bonus + 32)
                                break;
                        dnsize <<= 1;
                } while (dnsize < DNODE_MAX_SIZE);
@@ -1438,11 +1677,6 @@ static int osd_find_dnsize(struct osd_object *obj)
        }
        return dnsize;
 }
-#else
-static int inline osd_find_dnsize(struct osd_object *obj)
-{
-       return DN_MAX_BONUSLEN;
-}
 #endif
 
 /*
@@ -1450,13 +1684,13 @@ static int inline osd_find_dnsize(struct osd_object *obj)
  * dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT) called and then assigned
  * to a transaction group.
  */
-int __osd_object_create(const struct lu_env *env, struct osd_object *obj,
+int __osd_object_create(const struct lu_env *env, struct osd_device *osd,
+                       struct osd_object *obj, const struct lu_fid *fid,
                        dnode_t **dnp, dmu_tx_t *tx, struct lu_attr *la)
 {
-       struct osd_device   *osd = osd_obj2dev(obj);
-       const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
-       dmu_object_type_t    type = DMU_OT_PLAIN_FILE_CONTENTS;
+       dmu_object_type_t type = DMU_OT_PLAIN_FILE_CONTENTS;
        uint64_t oid;
+       int size;
 
        /* Use DMU_OTN_UINT8_METADATA for local objects so their data blocks
         * would get an additional ditto copy */
@@ -1465,8 +1699,12 @@ int __osd_object_create(const struct lu_env *env, struct osd_object *obj,
                type = DMU_OTN_UINT8_METADATA;
 
        /* Create a new DMU object using the default dnode size. */
+       if (obj)
+               size = obj->oo_ea_in_bonus;
+       else
+               size = OSD_BASE_EA_IN_BONUS;
        oid = osd_dmu_object_alloc(osd->od_os, type, 0,
-                                  osd_find_dnsize(obj), tx);
+                                  osd_find_dnsize(osd, size), tx);
 
        LASSERT(la->la_valid & LA_MODE);
        la->la_size = 0;
@@ -1511,6 +1749,7 @@ int __osd_zap_create(const struct lu_env *env, struct osd_device *osd,
 static dnode_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj,
                          struct lu_attr *la, struct osd_thandle *oh)
 {
+       struct osd_device *osd = osd_obj2dev(obj);
        dnode_t *dn;
        int rc;
 
@@ -1519,8 +1758,8 @@ static dnode_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj,
         * We set ZAP_FLAG_UINT64_KEY to let ZFS know than we are going to use
         * binary keys */
        LASSERT(S_ISREG(la->la_mode));
-       rc = __osd_zap_create(env, osd_obj2dev(obj), &dn, oh->ot_tx, la,
-                             osd_find_dnsize(obj), ZAP_FLAG_UINT64_KEY);
+       rc = __osd_zap_create(env, osd, &dn, oh->ot_tx, la,
+               osd_find_dnsize(osd, obj->oo_ea_in_bonus), ZAP_FLAG_UINT64_KEY);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1529,12 +1768,13 @@ static dnode_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj,
 static dnode_t *osd_mkdir(const struct lu_env *env, struct osd_object *obj,
                          struct lu_attr *la, struct osd_thandle *oh)
 {
+       struct osd_device *osd = osd_obj2dev(obj);
        dnode_t *dn;
        int rc;
 
        LASSERT(S_ISDIR(la->la_mode));
-       rc = __osd_zap_create(env, osd_obj2dev(obj), &dn, oh->ot_tx, la,
-                             osd_find_dnsize(obj), 0);
+       rc = __osd_zap_create(env, osd, &dn, oh->ot_tx, la,
+                             osd_find_dnsize(osd, obj->oo_ea_in_bonus), 0);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1549,12 +1789,11 @@ static dnode_t *osd_mkreg(const struct lu_env *env, struct osd_object *obj,
        int rc;
 
        LASSERT(S_ISREG(la->la_mode));
-       rc = __osd_object_create(env, obj, &dn, oh->ot_tx, la);
+       rc = __osd_object_create(env, osd, obj, fid, &dn, oh->ot_tx, la);
        if (rc)
                return ERR_PTR(rc);
 
-       if ((fid_is_idif(fid) || fid_is_norm(fid) || fid_is_echo(fid)) &&
-           osd->od_is_ost) {
+       if ((fid_is_idif(fid) || fid_is_norm(fid) || fid_is_echo(fid))) {
                /* The minimum block size must be at least page size otherwise
                 * it will break the assumption in tgt_thread_big_cache where
                 * the array size is PTLRPC_MAX_BRW_PAGES. It will also affect
@@ -1578,7 +1817,9 @@ static dnode_t *osd_mksym(const struct lu_env *env, struct osd_object *obj,
        int rc;
 
        LASSERT(S_ISLNK(la->la_mode));
-       rc = __osd_object_create(env, obj, &dn, oh->ot_tx, la);
+       rc = __osd_object_create(env, osd_obj2dev(obj), obj,
+                                lu_object_fid(&obj->oo_dt.do_lu),
+                                &dn, oh->ot_tx, la);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1593,7 +1834,9 @@ static dnode_t *osd_mknod(const struct lu_env *env, struct osd_object *obj,
        if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode))
                la->la_valid |= LA_RDEV;
 
-       rc = __osd_object_create(env, obj, &dn, oh->ot_tx, la);
+       rc = __osd_object_create(env, osd_obj2dev(obj), obj,
+                                lu_object_fid(&obj->oo_dt.do_lu),
+                                &dn, oh->ot_tx, la);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1649,6 +1892,7 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
        dnode_t *dn = NULL, *zdn = NULL;
        uint64_t                 zapid, parent = 0;
        int                      rc;
+       __u32 compat = 0;
 
        ENTRY;
 
@@ -1701,9 +1945,18 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
 
        zapid = osd_get_name_n_idx(env, osd, fid, buf,
                                   sizeof(info->oti_str), &zdn);
+       if (CFS_FAIL_CHECK(OBD_FAIL_OSD_NO_OI_ENTRY) ||
+           (osd->od_is_ost && OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_NO_ENTRY)))
+               goto skip_add;
+
+       if (osd->od_is_ost && OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_INVALID_ENTRY))
+               zde->zde_dnode++;
+
        rc = osd_zap_add(osd, zapid, zdn, buf, 8, 1, zde, oh->ot_tx);
        if (rc)
                GOTO(out, rc);
+
+skip_add:
        obj->oo_dn = dn;
        /* Now add in all of the "SA" attributes */
        rc = osd_sa_handle_get(obj);
@@ -1715,7 +1968,9 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
                GOTO(out, rc);
 
        /* initialize LMA */
-       lustre_lma_init(lma, fid, 0, 0);
+       if (fid_is_idif(fid) || (fid_is_norm(fid) && osd->od_is_ost))
+               compat |= LMAC_FID_ON_OST;
+       lustre_lma_init(lma, fid, compat, 0);
        lustre_lma_swab(lma);
        rc = -nvlist_add_byte_array(obj->oo_sa_xattr, XATTR_NAME_LMA,
                                    (uchar_t *)lma, sizeof(*lma));
@@ -1752,6 +2007,7 @@ out:
 static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
                               struct thandle *th)
 {
+       osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev), osd_dt_obj(dt));
        return osd_declare_attr_set(env, dt, NULL, th);
 }
 
@@ -1792,6 +2048,7 @@ out:
 static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
                               struct thandle *handle)
 {
+       osd_idc_find_and_init(env, osd_dev(dt->do_lu.lo_dev), osd_dt_obj(dt));
        return osd_declare_attr_set(env, dt, NULL, handle);
 }
 
@@ -1841,8 +2098,12 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
         * support ZIL.  If the object tracked the txg that it was last
         * modified in, it could pass that txg here instead of "0".  Maybe
         * the changes are already committed, so no wait is needed at all? */
-       if (!osd->od_dt_dev.dd_rdonly)
-               txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
+       if (!osd->od_dt_dev.dd_rdonly) {
+               if (osd_object_sync_delay_us < 0)
+                       txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
+               else
+                       udelay(osd_object_sync_delay_us);
+       }
 
        RETURN(0);
 }
@@ -1902,3 +2163,7 @@ static struct dt_object_operations osd_obj_otable_it_ops = {
        .do_attr_get            = osd_otable_it_attr_get,
        .do_index_try           = osd_index_try,
 };
+
+module_param(osd_object_sync_delay_us, int, 0644);
+MODULE_PARM_DESC(osd_object_sync_delay_us,
+                "If zero or larger delay N usec instead of doing object sync");