Whamcloud - gitweb
LU-13974 llog: check stale osp object
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index 4a3ac47..338a47e 100644 (file)
@@ -66,11 +66,8 @@ 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;
-extern struct dt_body_operations osd_body_ops;
 static struct dt_object_operations osd_obj_otable_it_ops;
 
-extern struct kmem_cache *osd_object_kmem;
-
 static void
 osd_object_sa_fini(struct osd_object *obj)
 {
@@ -186,23 +183,27 @@ osd_object_sa_bulk_update(struct osd_object *obj, sa_bulk_attr_t *attrs,
 /*
  * Retrieve the attributes of a DMU object
  */
-int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
-                         struct osd_object *obj, struct lu_attr *la)
+static int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
+                                struct osd_object *obj, struct lu_attr *la)
 {
-       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
-       sa_bulk_attr_t  *bulk = osd_oti_get(env)->oti_attr_bulk;
-       int              cnt = 0;
+       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
+       sa_bulk_attr_t *bulk = osd_oti_get(env)->oti_attr_bulk;
+       struct lustre_mdt_attrs *lma;
+       struct lu_buf buf;
+       int cnt = 0;
        int              rc;
        ENTRY;
 
        LASSERT(obj->oo_dn != NULL);
 
-       la->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE | LA_TYPE |
-                       LA_SIZE | LA_UID | LA_GID | LA_FLAGS | LA_NLINK;
+       la->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_BTIME | LA_MODE |
+                       LA_TYPE | LA_SIZE | LA_UID | LA_GID | LA_FLAGS |
+                       LA_NLINK;
 
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(o), NULL, osa->atime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(o), NULL, osa->mtime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(o), NULL, osa->ctime, 16);
+       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(o), NULL, osa->btime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(o), NULL, &osa->mode, 8);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_SIZE(o), NULL, &osa->size, 8);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(o), NULL, &osa->nlink, 8);
@@ -237,6 +238,7 @@ int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
        la->la_atime = osa->atime[0];
        la->la_mtime = osa->mtime[0];
        la->la_ctime = osa->ctime[0];
+       la->la_btime = osa->btime[0];
        la->la_mode = osa->mode;
        la->la_uid = osa->uid;
        la->la_gid = osa->gid;
@@ -244,27 +246,22 @@ int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
        la->la_flags = attrs_zfs2fs(osa->flags);
        la->la_size = osa->size;
 
-       /* Try to get extra flag from LMA. Right now, only LMAI_ORPHAN
-        * flags is stored in LMA, and it is only for orphan directory */
-       if (S_ISDIR(la->la_mode) && dt_object_exists(&obj->oo_dt)) {
-               struct osd_thread_info *info = osd_oti_get(env);
-               struct lustre_mdt_attrs *lma;
-               struct lu_buf buf;
-
-               lma = (struct lustre_mdt_attrs *)info->oti_buf;
-               buf.lb_buf = lma;
-               buf.lb_len = sizeof(info->oti_buf);
-               rc = osd_xattr_get(env, &obj->oo_dt, &buf, XATTR_NAME_LMA);
-               if (rc > 0) {
-                       rc = 0;
-                       lma->lma_incompat = le32_to_cpu(lma->lma_incompat);
-                       obj->oo_lma_flags =
-                               lma_to_lustre_flags(lma->lma_incompat);
-
-               } else if (rc == -ENODATA) {
-                       rc = 0;
-               }
+       /* Try to get extra flags from LMA */
+       lma = (struct lustre_mdt_attrs *)osd_oti_get(env)->oti_buf;
+       buf.lb_buf = lma;
+       buf.lb_len = sizeof(osd_oti_get(env)->oti_buf);
+       down_read(&obj->oo_guard);
+       rc = osd_xattr_get_lma(env, obj, &buf);
+       if (!rc) {
+               lma->lma_incompat = le32_to_cpu(lma->lma_incompat);
+               obj->oo_lma_flags =
+                       lma_to_lustre_flags(lma->lma_incompat);
+       } else if (rc == -ENODATA ||
+                  !(S_ISDIR(la->la_mode) &&
+                    dt_object_exists(&obj->oo_dt))) {
+               rc = 0;
        }
+       up_read(&obj->oo_guard);
 
        if (S_ISCHR(la->la_mode) || S_ISBLK(la->la_mode)) {
                rc = -sa_lookup(obj->oo_sa_hdl, SA_ZPL_RDEV(o), &osa->rdev, 8);
@@ -291,6 +288,7 @@ int __osd_obj2dnode(objset_t *os, uint64_t oid, dnode_t **dnp)
        dbi = (dmu_buf_impl_t *)db;
        DB_DNODE_ENTER(dbi);
        *dnp = DB_DNODE(dbi);
+       DB_DNODE_EXIT(dbi);
        LASSERT(*dnp != NULL);
 
        return 0;
@@ -406,7 +404,7 @@ out:
 /*
  * Concurrency: shouldn't matter.
  */
-int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
+static int osd_object_init0(const struct lu_env *env, struct osd_object *obj)
 {
        struct osd_device       *osd = osd_obj2dev(obj);
        const struct lu_fid     *fid = lu_object_fid(&obj->oo_dt.do_lu);
@@ -457,7 +455,7 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
        const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu);
        ENTRY;
 
-       CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
+       BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*lma));
        lma = (struct lustre_mdt_attrs *)info->oti_buf;
        buf.lb_buf = lma;
        buf.lb_len = sizeof(info->oti_buf);
@@ -643,7 +641,7 @@ trigger:
        }
 
        /* The case someone triggered the OI scrub already. */
-       if (thread_is_running(&scrub->os_thread)) {
+       if (scrub->os_running) {
                if (!rc) {
                        LASSERT(remote);
 
@@ -696,11 +694,10 @@ static void osd_object_free(const struct lu_env *env, struct lu_object *l)
        LASSERT(osd_invariant(obj));
 
        dt_object_fini(&obj->oo_dt);
+       /* obj doesn't contain an lu_object_header, so we don't need call_rcu */
        OBD_SLAB_FREE_PTR(obj, osd_object_kmem);
-       if (unlikely(h)) {
-               lu_object_header_fini(h);
-               OBD_FREE_PTR(h);
-       }
+       if (unlikely(h))
+               lu_object_header_free(h);
 }
 
 static int
@@ -759,9 +756,11 @@ static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
        LASSERT(th != NULL);
        LASSERT(dt_object_exists(dt));
 
-       oh = container_of0(th, struct osd_thandle, ot_super);
+       oh = container_of(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);
@@ -823,7 +822,7 @@ static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
 
        LASSERT(obj->oo_dn != NULL);
 
-       oh = container_of0(th, struct osd_thandle, ot_super);
+       oh = container_of(th, struct osd_thandle, ot_super);
        LASSERT(oh != NULL);
        LASSERT(oh->ot_tx != NULL);
 
@@ -982,14 +981,14 @@ static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
        return rc;
 }
 
-static int osd_attr_get(const struct lu_env *env,
-                       struct dt_object *dt,
+static int osd_attr_get(const struct lu_env *env, struct dt_object *dt,
                        struct lu_attr *attr)
 {
-       struct osd_object       *obj = osd_dt_obj(dt);
-       uint64_t                 blocks;
-       uint32_t                 blksize;
-       int                      rc = 0;
+       struct osd_object *obj = osd_dt_obj(dt);
+       struct osd_device *osd = osd_obj2dev(obj);
+       uint64_t blocks;
+       uint32_t blksize;
+       int rc = 0;
 
        down_read(&obj->oo_guard);
 
@@ -1004,9 +1003,20 @@ static int osd_attr_get(const struct lu_env *env,
 
        read_lock(&obj->oo_attr_lock);
        *attr = obj->oo_attr;
-       if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL)
+       if (obj->oo_lma_flags & LUSTRE_ORPHAN_FL) {
+               attr->la_valid |= LA_FLAGS;
                attr->la_flags |= LUSTRE_ORPHAN_FL;
+       }
+       if (obj->oo_lma_flags & LUSTRE_ENCRYPT_FL) {
+               attr->la_valid |= LA_FLAGS;
+               attr->la_flags |= LUSTRE_ENCRYPT_FL;
+       }
        read_unlock(&obj->oo_attr_lock);
+       if (attr->la_valid & LA_FLAGS && attr->la_flags & LUSTRE_ORPHAN_FL)
+               CDEBUG(D_INFO, "%s: set orphan flag on "DFID" (%llx/%x)\n",
+                      osd_obj2dev(obj)->od_svname,
+                      PFID(lu_object_fid(&dt->do_lu)),
+                      attr->la_valid, obj->oo_lma_flags);
 
        /* with ZFS_DEBUG zrl_add_debug() called by DB_DNODE_ENTER()
         * from within sa_object_size() can block on a mutex, so
@@ -1014,8 +1024,11 @@ static int osd_attr_get(const struct lu_env *env,
        sa_object_size(obj->oo_sa_hdl, &blksize, &blocks);
        /* we do not control size of indices, so always calculate
         * it from number of blocks reported by DMU */
-       if (S_ISDIR(attr->la_mode))
+       if (S_ISDIR(attr->la_mode)) {
                attr->la_size = 512 * blocks;
+               rc = -zap_count(osd->od_os, obj->oo_dn->dn_object,
+                               &attr->la_dirent_count);
+       }
        /* Block size may be not set; suggest maximal I/O transfers. */
        if (blksize == 0)
                blksize = osd_spa_maxblocksize(
@@ -1037,7 +1050,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;
 
@@ -1054,7 +1067,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;
@@ -1076,7 +1089,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;
@@ -1111,7 +1124,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
        LASSERT(handle != NULL);
        LASSERT(osd_invariant(obj));
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
 
        down_read(&obj->oo_guard);
        if (unlikely(!dt_object_exists(dt) || obj->oo_destroyed))
@@ -1146,16 +1159,21 @@ 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) {
                /* quota enforcement for user */
                if (attr->la_uid != obj->oo_attr.la_uid) {
-                       rc = qsd_transfer(env, osd->od_quota_slave,
+                       rc = qsd_transfer(env, osd_def_qsd(osd),
                                          &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);
                }
@@ -1163,41 +1181,45 @@ static int osd_declare_attr_set(const struct lu_env *env,
        if (attr && attr->la_valid & LA_GID) {
                /* quota enforcement for group */
                if (attr->la_gid != obj->oo_attr.la_gid) {
-                       rc = qsd_transfer(env, osd->od_quota_slave,
+                       rc = qsd_transfer(env, osd_def_qsd(osd),
                                          &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);
                }
        }
 #ifdef ZFS_PROJINHERIT
        if (attr && attr->la_valid & LA_PROJID) {
-               if (!osd->od_projectused_dn)
-                       GOTO(out, rc = -EOPNOTSUPP);
-
-               /* Usually, if project quota is upgradable for the device,
-                * then the upgrade will be done before or when mount the
-                * device. So when we come here, this project should have
-                * project ID attribute already (that is zero by default).
-                * Otherwise, there was something wrong during the former
-                * upgrade, let's return failure to report that.
-                *
-                * Please note that, different from other attributes, you
-                * can NOT simply set the project ID attribute under such
-                * case, because adding (NOT change) project ID attribute
-                * needs to change the object's attribute layout to match
-                * zfs backend quota accounting requirement. */
-               if (unlikely(!obj->oo_with_projid))
-                       GOTO(out, rc = -ENXIO);
-
                /* quota enforcement for project */
                if (attr->la_projid != obj->oo_attr.la_projid) {
-                       rc = qsd_transfer(env, osd->od_quota_slave,
+                       if (!osd->od_projectused_dn)
+                               GOTO(out, rc = -EOPNOTSUPP);
+
+                       /* Usually, if project quota is upgradable for the
+                        * device, then the upgrade will be done before or when
+                        * mount the device. So when we come here, this project
+                        * should have project ID attribute already (that is
+                        * zero by default).  Otherwise, there was something
+                        * wrong during the former upgrade, let's return failure
+                        * to report that.
+                        *
+                        * Please note that, different from other attributes,
+                        * you can NOT simply set the project ID attribute under
+                        * such case, because adding (NOT change) project ID
+                        * attribute needs to change the object's attribute
+                        * layout to match zfs backend quota accounting
+                        * requirement. */
+                       if (unlikely(!obj->oo_with_projid))
+                               GOTO(out, rc = -ENXIO);
+
+                       rc = qsd_transfer(env, osd_def_qsd(osd),
                                          &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);
                }
@@ -1238,7 +1260,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
        LASSERT(osd_invariant(obj));
        LASSERT(obj->oo_sa_hdl);
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
        /* Assert that the transaction has been assigned to a
           transaction group. */
        LASSERT(oh->ot_tx->tx_txg != 0);
@@ -1258,9 +1280,9 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                        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);
+               if (rc > 0)
+                       rc = 0;
+               GOTO(out, rc);
        }
 
        /* Only allow set size for regular file */
@@ -1282,16 +1304,22 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
        if (valid & LA_FLAGS) {
                struct lustre_mdt_attrs *lma;
                struct lu_buf buf;
+               int size = 0;
 
                if (la->la_flags & LUSTRE_LMA_FL_MASKS) {
                        LASSERT(!obj->oo_pfid_in_lma);
-                       CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma));
+                       BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*lma));
                        lma = (struct lustre_mdt_attrs *)&info->oti_buf;
                        buf.lb_buf = lma;
                        buf.lb_len = sizeof(info->oti_buf);
-                       rc = osd_xattr_get(env, &obj->oo_dt, &buf,
-                                          XATTR_NAME_LMA);
-                       if (rc > 0) {
+
+                       /* Please do NOT call osd_xattr_get() directly, that
+                        * will cause recursive down_read() on oo_guard. */
+                       rc = osd_xattr_get_internal(env, obj, &buf,
+                                                   XATTR_NAME_LMA, &size);
+                       if (!rc && unlikely(size < sizeof(*lma))) {
+                               rc = -EINVAL;
+                       } else if (!rc) {
                                lma->lma_incompat =
                                        le32_to_cpu(lma->lma_incompat);
                                lma->lma_incompat |=
@@ -1309,6 +1337,9 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                                CWARN("%s: failed to set LMA flags: rc = %d\n",
                                       osd->od_svname, rc);
                                GOTO(out, rc);
+                       } else {
+                               obj->oo_lma_flags =
+                                       la->la_flags & LUSTRE_LMA_FL_MASKS;
                        }
                }
        }
@@ -1318,18 +1349,15 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
 
        if (valid & LA_PROJID) {
 #ifdef ZFS_PROJINHERIT
-               /* osd_declare_attr_set() must be called firstly.
-                * If osd::od_projectused_dn is not set, then we
-                * can not arrive at here. */
-               LASSERT(osd->od_projectused_dn);
-               LASSERT(obj->oo_with_projid);
+               if (osd->od_projectused_dn) {
+                       LASSERT(obj->oo_with_projid);
 
-               osa->projid = obj->oo_attr.la_projid = la->la_projid;
-               SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_PROJID(osd), NULL,
-                                &osa->projid, 8);
-#else
-               valid &= ~LA_PROJID;
+                       osa->projid = obj->oo_attr.la_projid = la->la_projid;
+                       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_PROJID(osd), NULL,
+                                        &osa->projid, 8);
+               } else
 #endif
+                       valid &= ~LA_PROJID;
        }
 
        if (valid & LA_ATIME) {
@@ -1376,7 +1404,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                 * copy */
                obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
 #ifdef ZFS_PROJINHERIT
-               if (obj->oo_with_projid)
+               if (obj->oo_with_projid && osd->od_projectused_dn)
                        osa->flags |= ZFS_PROJID;
 #endif
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(osd), NULL,
@@ -1455,7 +1483,7 @@ static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
        }
 
        LASSERT(handle != NULL);
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
        LASSERT(oh->ot_tx != NULL);
 
        /* this is the minimum set of EAs on every Lustre object */
@@ -1466,6 +1494,7 @@ static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
        switch (dof->dof_type) {
                case DFT_DIR:
                        dt->do_index_ops = &osd_dir_ops;
+                       /* fallthrough */
                case DFT_INDEX:
                        /* for zap create */
                        dmu_tx_hold_zap(oh->ot_tx, DMU_NEW_OBJECT, FALSE, NULL);
@@ -1501,13 +1530,12 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
                    struct lu_attr *la, uint64_t parent,
                    nvlist_t *xattr)
 {
-       sa_bulk_attr_t  *bulk = osd_oti_get(env)->oti_attr_bulk;
-       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
-       uint64_t         gen;
-       uint64_t         crtime[2];
-       timestruc_t      now;
-       int              cnt;
-       int              rc;
+       sa_bulk_attr_t *bulk = osd_oti_get(env)->oti_attr_bulk;
+       struct osa_attr *osa = &osd_oti_get(env)->oti_osa;
+       uint64_t gen;
+       inode_timespec_t now;
+       int cnt;
+       int rc;
        char *dxattr = NULL;
        size_t sa_size;
 
@@ -1516,7 +1544,7 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
 
        gen = dmu_tx_get_txg(tx);
        gethrestime(&now);
-       ZFS_TIME_ENCODE(&now, crtime);
+       ZFS_TIME_ENCODE(&now, osa->btime);
 
        osa->atime[0] = la->la_atime;
        osa->ctime[0] = la->la_ctime;
@@ -1566,7 +1594,7 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL, osa->atime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(osd), NULL, osa->mtime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CTIME(osd), NULL, osa->ctime, 16);
-       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(osd), NULL, crtime, 16);
+       SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_CRTIME(osd), NULL, osa->btime, 16);
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_LINKS(osd), NULL, &osa->nlink, 8);
 #ifdef ZFS_PROJINHERIT
        if (osd->od_projectused_dn)
@@ -1625,11 +1653,12 @@ int osd_find_new_dnode(const struct lu_env *env, dmu_tx_t *tx,
                LASSERT(db);
                LASSERT(dn->dn_handle);
                DB_DNODE_ENTER(db);
-               if (refcount_add(&db->db_holds, osd_obj_tag) == 1) {
-                       refcount_add(&dn->dn_holds, tag);
+               if (zfs_refcount_add(&db->db_holds, osd_obj_tag) == 1) {
+                       zfs_refcount_add(&dn->dn_holds, osd_obj_tag);
                        atomic_inc_32(&dn->dn_dbufs_count);
                }
                *dnp = dn;
+               DB_DNODE_EXIT(db);
                dbuf_read(db, NULL, DB_RF_MUST_SUCCEED | DB_RF_NOPREFETCH);
                break;
        }
@@ -1797,6 +1826,14 @@ static dnode_t *osd_mkreg(const struct lu_env *env, struct osd_object *obj,
                               osd->od_svname, rc);
                        return ERR_PTR(rc);
                }
+       } else if ((fid_is_llog(fid))) {
+               rc = -dmu_object_set_blocksize(osd->od_os, dn->dn_object,
+                                              LLOG_MIN_CHUNK_SIZE, 0, oh->ot_tx);
+               if (unlikely(rc)) {
+                       CERROR("%s: can't change blocksize: %d\n",
+                              osd->od_svname, rc);
+                       return ERR_PTR(rc);
+               }
        }
 
        return dn;
@@ -1902,7 +1939,7 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
        LASSERT(dof != NULL);
 
        LASSERT(th != NULL);
-       oh = container_of0(th, struct osd_thandle, ot_super);
+       oh = container_of(th, struct osd_thandle, ot_super);
 
        LASSERT(obj->oo_dn == NULL);
 
@@ -1914,6 +1951,8 @@ static int osd_create(const struct lu_env *env, struct dt_object *dt,
 
        /* we may fix some attributes, better do not change the source */
        obj->oo_attr = *attr;
+       obj->oo_attr.la_size = 0;
+       obj->oo_attr.la_nlink = 0;
        obj->oo_attr.la_valid |= LA_SIZE | LA_NLINK | LA_TYPE;
 
 #ifdef ZFS_PROJINHERIT
@@ -1937,20 +1976,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)) {
-               if (osd->od_is_ost &&
-                   OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_INVALID_ENTRY))
-                       zde->zde_dnode++;
-
-               if (!osd->od_is_ost ||
-                   !OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_NO_ENTRY)) {
-                       rc = osd_zap_add(osd, zapid, zdn, buf, 8, 1,
-                                        zde, oh->ot_tx);
-                       if (rc)
-                               GOTO(out, rc);
-               }
-       }
+       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);
@@ -2001,6 +2038,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);
 }
 
@@ -2025,7 +2063,7 @@ static int osd_ref_add(const struct lu_env *env, struct dt_object *dt,
        LASSERT(osd_invariant(obj));
        LASSERT(obj->oo_sa_hdl != NULL);
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
 
        write_lock(&obj->oo_attr_lock);
        nlink = ++obj->oo_attr.la_nlink;
@@ -2041,6 +2079,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);
 }
 
@@ -2066,7 +2105,7 @@ static int osd_ref_del(const struct lu_env *env, struct dt_object *dt,
        LASSERT(osd_invariant(obj));
        LASSERT(obj->oo_sa_hdl != NULL);
 
-       oh = container_of0(handle, struct osd_thandle, ot_super);
+       oh = container_of(handle, struct osd_thandle, ot_super);
        LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
 
        write_lock(&obj->oo_attr_lock);
@@ -2084,15 +2123,17 @@ static int osd_object_sync(const struct lu_env *env, struct dt_object *dt,
                           __u64 start, __u64 end)
 {
        struct osd_device *osd = osd_obj2dev(osd_dt_obj(dt));
+       uint64_t txg = 0;
        ENTRY;
 
-       /* XXX: no other option than syncing the whole filesystem until we
-        * 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) {
+       if (osd->od_dt_dev.dd_rdonly)
+               RETURN(0);
+
+       txg = osd_db_dirty_txg(osd_dt_obj(dt)->oo_dn->dn_dbuf);
+       if (txg) {
+               /* the object is dirty or being synced */
                if (osd_object_sync_delay_us < 0)
-                       txg_wait_synced(dmu_objset_pool(osd->od_os), 0ULL);
+                       txg_wait_synced(dmu_objset_pool(osd->od_os), txg);
                else
                        udelay(osd_object_sync_delay_us);
        }
@@ -2105,6 +2146,11 @@ static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
        return 0;
 }
 
+static bool osd_check_stale(struct dt_object *dt)
+{
+       return false;
+}
+
 static struct dt_object_operations osd_obj_ops = {
        .do_read_lock           = osd_read_lock,
        .do_write_lock          = osd_write_lock,
@@ -2132,6 +2178,7 @@ static struct dt_object_operations osd_obj_ops = {
        .do_xattr_list          = osd_xattr_list,
        .do_object_sync         = osd_object_sync,
        .do_invalidate          = osd_invalidate,
+       .do_check_stale         = osd_check_stale,
 };
 
 static struct lu_object_operations osd_lu_obj_ops = {