Whamcloud - gitweb
LU-7991 quota: project quota against ZFS backend
[fs/lustre-release.git] / lustre / osd-zfs / osd_object.c
index e07b982..e9b127d 100644 (file)
@@ -38,7 +38,6 @@
 
 #define DEBUG_SUBSYSTEM S_OSD
 
-#include <lustre_ver.h>
 #include <libcfs/libcfs.h>
 #include <obd_support.h>
 #include <lustre_net.h>
@@ -107,37 +106,45 @@ osd_object_sa_init(struct osd_object *obj, struct osd_device *o)
 /*
  * Add object to list of dirty objects in tx handle.
  */
-static void
-osd_object_sa_dirty_add(struct osd_object *obj, struct osd_thandle *oh)
+void osd_object_sa_dirty_add(struct osd_object *obj, struct osd_thandle *oh)
 {
        if (!list_empty(&obj->oo_sa_linkage))
                return;
 
-       down(&oh->ot_sa_lock);
        write_lock(&obj->oo_attr_lock);
        if (likely(list_empty(&obj->oo_sa_linkage)))
                list_add(&obj->oo_sa_linkage, &oh->ot_sa_list);
        write_unlock(&obj->oo_attr_lock);
-       up(&oh->ot_sa_lock);
 }
 
 /*
  * Release spill block dbuf hold for all dirty SAs.
  */
-void osd_object_sa_dirty_rele(struct osd_thandle *oh)
+void osd_object_sa_dirty_rele(const struct lu_env *env, struct osd_thandle *oh)
 {
        struct osd_object *obj;
 
-       down(&oh->ot_sa_lock);
        while (!list_empty(&oh->ot_sa_list)) {
                obj = list_entry(oh->ot_sa_list.next,
                                 struct osd_object, oo_sa_linkage);
-               sa_spill_rele(obj->oo_sa_hdl);
                write_lock(&obj->oo_attr_lock);
                list_del_init(&obj->oo_sa_linkage);
                write_unlock(&obj->oo_attr_lock);
+               if (obj->oo_late_xattr) {
+                       /*
+                        * take oo_guard to protect oo_sa_xattr buffer
+                        * from concurrent update by osd_xattr_set()
+                        */
+                       LASSERT(oh->ot_assigned != 0);
+                       down_write(&obj->oo_guard);
+                       if (obj->oo_late_attr_set)
+                               __osd_sa_attr_init(env, obj, oh);
+                       else if (obj->oo_late_xattr)
+                               __osd_sa_xattr_update(env, obj, oh);
+                       up_write(&obj->oo_guard);
+               }
+               sa_spill_rele(obj->oo_sa_hdl);
        }
-       up(&oh->ot_sa_lock);
 }
 
 /*
@@ -207,6 +214,25 @@ int __osd_object_attr_get(const struct lu_env *env, struct osd_device *o,
        if (rc)
                GOTO(out_sa, rc);
 
+#ifdef ZFS_PROJINHERIT
+       if (o->od_projectused_dn && osa->flags & ZFS_PROJID) {
+               rc = -sa_lookup(obj->oo_sa_hdl, SA_ZPL_PROJID(o),
+                               &osa->projid, 8);
+               if (rc)
+                       GOTO(out_sa, rc);
+
+               la->la_projid = osa->projid;
+               la->la_valid |= LA_PROJID;
+               obj->oo_with_projid = 1;
+       } else {
+               la->la_projid = ZFS_DEFAULT_PROJID;
+               la->la_valid &= ~LA_PROJID;
+       }
+#else
+       la->la_projid = 0;
+       la->la_valid &= ~LA_PROJID;
+#endif
+
        la->la_atime = osa->atime[0];
        la->la_mtime = osa->mtime[0];
        la->la_ctime = osa->ctime[0];
@@ -257,7 +283,7 @@ int __osd_obj2dnode(objset_t *os, uint64_t oid, dnode_t **dnp)
        dmu_buf_impl_t *dbi;
        int rc;
 
-       rc = dmu_bonus_hold(os, oid, osd_obj_tag, &db);
+       rc = -dmu_bonus_hold(os, oid, osd_obj_tag, &db);
        if (rc)
                return rc;
 
@@ -371,6 +397,35 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
        RETURN(rc);
 }
 
+/**
+ * Helper function to retrieve DMU object id from fid for accounting object
+ */
+static dnode_t *osd_quota_fid2dmu(const struct osd_device *osd,
+                                 const struct lu_fid *fid)
+{
+       dnode_t *dn = NULL;
+
+       LASSERT(fid_is_acct(fid));
+
+       switch (fid_oid(fid)) {
+       case ACCT_USER_OID:
+               dn = osd->od_userused_dn;
+               break;
+       case ACCT_GROUP_OID:
+               dn = osd->od_groupused_dn;
+               break;
+#ifdef ZFS_PROJINHERIT
+       case ACCT_PROJECT_OID:
+               dn = osd->od_projectused_dn;
+               break;
+#endif
+       default:
+               break;
+       }
+
+       return dn;
+}
+
 /*
  * Concurrency: no concurrent access is possible that early in object
  * life-cycle.
@@ -378,10 +433,11 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj)
 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
                           const struct lu_object_conf *conf)
 {
-       struct osd_object       *obj = osd_obj(l);
-       struct osd_device       *osd = osd_obj2dev(obj);
-       uint64_t                 oid;
-       int                      rc;
+       struct osd_object *obj = osd_obj(l);
+       struct osd_device *osd = osd_obj2dev(obj);
+       const struct lu_fid *fid = lu_object_fid(l);
+       uint64_t oid;
+       int rc = 0;
        ENTRY;
 
        LASSERT(osd_invariant(obj));
@@ -395,7 +451,17 @@ static int osd_object_init(const struct lu_env *env, struct lu_object *l,
        if (conf != NULL && conf->loc_flags & LOC_F_NEW)
                GOTO(out, rc = 0);
 
-       rc = osd_fid_lookup(env, osd, lu_object_fid(l), &oid);
+       if (unlikely(fid_is_acct(fid))) {
+               obj->oo_dn = osd_quota_fid2dmu(osd, fid);
+               if (obj->oo_dn) {
+                       obj->oo_dt.do_index_ops = &osd_acct_index_ops;
+                       l->lo_header->loh_attr |= LOHA_EXISTS;
+               }
+
+               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);
@@ -447,7 +513,7 @@ osd_object_unlinked_add(struct osd_object *obj, struct osd_thandle *oh)
        LASSERT(obj->oo_destroy == OSD_DESTROY_ASYNC);
 
        /* the object is supposed to be exclusively locked by
-        * the caller (osd_object_destroy()), while the transaction
+        * the caller (osd_destroy()), while the transaction
         * (oh) is per-thread and not shared */
        if (likely(list_empty(&obj->oo_unlinked_linkage))) {
                list_add(&obj->oo_unlinked_linkage, &oh->ot_unlinked_list);
@@ -480,9 +546,8 @@ osd_object_set_destroy_type(struct osd_object *obj)
        up_write(&obj->oo_guard);
 }
 
-static int osd_declare_object_destroy(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     struct thandle *th)
+static int osd_declare_destroy(const struct lu_env *env, struct dt_object *dt,
+                              struct thandle *th)
 {
        const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
        struct osd_object       *obj = osd_dt_obj(dt);
@@ -507,13 +572,15 @@ static int osd_declare_object_destroy(const struct lu_env *env,
 
        /* one less inode */
        rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
-                              obj->oo_attr.la_gid, -1, oh, false, NULL, false);
+                              obj->oo_attr.la_gid, obj->oo_attr.la_projid,
+                              -1, oh, NULL, OSD_QID_INODE);
        if (rc)
                RETURN(rc);
 
        /* data to be truncated */
        rc = osd_declare_quota(env, osd, obj->oo_attr.la_uid,
-                              obj->oo_attr.la_gid, 0, oh, true, NULL, false);
+                              obj->oo_attr.la_gid, obj->oo_attr.la_projid,
+                              0, oh, NULL, OSD_QID_BLK);
        if (rc)
                RETURN(rc);
 
@@ -532,8 +599,8 @@ static int osd_declare_object_destroy(const struct lu_env *env,
        RETURN(0);
 }
 
-static int osd_object_destroy(const struct lu_env *env,
-                             struct dt_object *dt, struct thandle *th)
+static int osd_destroy(const struct lu_env *env, struct dt_object *dt,
+                      struct thandle *th)
 {
        struct osd_thread_info  *info = osd_oti_get(env);
        char                    *buf = info->oti_str;
@@ -617,15 +684,18 @@ out:
 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
 {
        struct osd_object *obj = osd_obj(l);
-
-       if (obj->oo_dn != NULL) {
-               osd_object_sa_fini(obj);
-               if (obj->oo_sa_xattr) {
-                       nvlist_free(obj->oo_sa_xattr);
-                       obj->oo_sa_xattr = NULL;
+       const struct lu_fid *fid = lu_object_fid(l);
+
+       if (obj->oo_dn) {
+               if (likely(!fid_is_acct(fid))) {
+                       osd_object_sa_fini(obj);
+                       if (obj->oo_sa_xattr) {
+                               nvlist_free(obj->oo_sa_xattr);
+                               obj->oo_sa_xattr = NULL;
+                       }
+                       osd_dnode_rele(obj->oo_dn);
+                       list_del(&obj->oo_sa_linkage);
                }
-               osd_dnode_rele(obj->oo_dn);
-               list_del(&obj->oo_sa_linkage);
                obj->oo_dn = NULL;
        }
 }
@@ -649,8 +719,8 @@ static int osd_object_print(const struct lu_env *env, void *cookie,
        return (*p)(env, cookie, LUSTRE_OSD_ZFS_NAME"-object@%p", o);
 }
 
-static void osd_object_read_lock(const struct lu_env *env,
-                                struct dt_object *dt, unsigned role)
+static void osd_read_lock(const struct lu_env *env, struct dt_object *dt,
+                         unsigned role)
 {
        struct osd_object *obj = osd_dt_obj(dt);
 
@@ -659,8 +729,8 @@ static void osd_object_read_lock(const struct lu_env *env,
        down_read_nested(&obj->oo_sem, role);
 }
 
-static void osd_object_write_lock(const struct lu_env *env,
-                                 struct dt_object *dt, unsigned role)
+static void osd_write_lock(const struct lu_env *env, struct dt_object *dt,
+                          unsigned role)
 {
        struct osd_object *obj = osd_dt_obj(dt);
 
@@ -669,8 +739,7 @@ static void osd_object_write_lock(const struct lu_env *env,
        down_write_nested(&obj->oo_sem, role);
 }
 
-static void osd_object_read_unlock(const struct lu_env *env,
-                                  struct dt_object *dt)
+static void osd_read_unlock(const struct lu_env *env, struct dt_object *dt)
 {
        struct osd_object *obj = osd_dt_obj(dt);
 
@@ -678,17 +747,15 @@ static void osd_object_read_unlock(const struct lu_env *env,
        up_read(&obj->oo_sem);
 }
 
-static void osd_object_write_unlock(const struct lu_env *env,
-                                    struct dt_object *dt)
+static void osd_write_unlock(const struct lu_env *env, struct dt_object *dt)
 {
-        struct osd_object *obj = osd_dt_obj(dt);
+       struct osd_object *obj = osd_dt_obj(dt);
 
-        LASSERT(osd_invariant(obj));
+       LASSERT(osd_invariant(obj));
        up_write(&obj->oo_sem);
 }
 
-static int osd_object_write_locked(const struct lu_env *env,
-                                  struct dt_object *dt)
+static int osd_write_locked(const struct lu_env *env, struct dt_object *dt)
 {
        struct osd_object *obj = osd_dt_obj(dt);
        int rc = 1;
@@ -716,6 +783,9 @@ static int osd_attr_get(const struct lu_env *env,
        if (unlikely(!dt_object_exists(dt) || obj->oo_destroyed))
                GOTO(out, rc = -ENOENT);
 
+       if (unlikely(fid_is_acct(lu_object_fid(&dt->do_lu))))
+               GOTO(out, rc = 0);
+
        LASSERT(osd_invariant(obj));
        LASSERT(obj->oo_dn);
 
@@ -861,7 +931,7 @@ static int osd_declare_attr_set(const struct lu_env *env,
                 * anything else */
        }
 
-       if (attr && (attr->la_valid & (LA_UID | LA_GID))) {
+       if (attr && (attr->la_valid & (LA_UID | LA_GID | LA_PROJID))) {
                sa_object_size(obj->oo_sa_hdl, &blksize, &bspace);
                bspace = toqb(bspace * blksize);
        }
@@ -888,7 +958,38 @@ static int osd_declare_attr_set(const struct lu_env *env,
                                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,
+                                         &oh->ot_quota_trans, PRJQUOTA,
+                                         obj->oo_attr.la_projid,
+                                         attr->la_projid, bspace,
+                                         &info->oti_qi);
+                       if (rc)
+                               GOTO(out, rc);
+               }
+       }
+#endif
 out:
        up_read(&obj->oo_guard);
        RETURN(rc);
@@ -973,13 +1074,30 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                        if (rc < 0) {
                                CWARN("%s: failed to set LMA flags: rc = %d\n",
                                       osd->od_svname, rc);
-                               RETURN(rc);
+                               GOTO(out, rc);
                        }
                }
        }
 
        write_lock(&obj->oo_attr_lock);
        cnt = 0;
+
+       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);
+
+               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;
+#endif
+       }
+
        if (valid & LA_ATIME) {
                osa->atime[0] = obj->oo_attr.la_atime = la->la_atime;
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(osd), NULL,
@@ -1023,6 +1141,10 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt,
                /* many flags are not supported by zfs, so ensure a good cached
                 * copy */
                obj->oo_attr.la_flags = attrs_zfs2fs(osa->flags);
+#ifdef ZFS_PROJINHERIT
+               if (obj->oo_with_projid)
+                       osa->flags |= ZFS_PROJID;
+#endif
                SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_FLAGS(osd), NULL,
                                 &osa->flags, 8);
        }
@@ -1070,12 +1192,11 @@ static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
        }
 }
 
-static int osd_declare_object_create(const struct lu_env *env,
-                                    struct dt_object *dt,
-                                    struct lu_attr *attr,
-                                    struct dt_allocation_hint *hint,
-                                    struct dt_object_format *dof,
-                                    struct thandle *handle)
+static int osd_declare_create(const struct lu_env *env, struct dt_object *dt,
+                             struct lu_attr *attr,
+                             struct dt_allocation_hint *hint,
+                             struct dt_object_format *dof,
+                             struct thandle *handle)
 {
        const struct lu_fid     *fid = lu_object_fid(&dt->do_lu);
        struct osd_object       *obj = osd_dt_obj(dt);
@@ -1137,15 +1258,16 @@ static int osd_declare_object_create(const struct lu_env *env,
        /* will help to find FID->ino mapping at dt_insert() */
        osd_idc_find_and_init(env, osd, obj);
 
-       rc = osd_declare_quota(env, osd, attr->la_uid, attr->la_gid, 1, oh,
-                              false, NULL, false);
+       rc = osd_declare_quota(env, osd, attr->la_uid, attr->la_gid,
+                              attr->la_projid, 1, oh, NULL, OSD_QID_INODE);
 
        RETURN(rc);
 }
 
 int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
-                   sa_handle_t *sa_hdl, dmu_tx_t *tx,
-                   struct lu_attr *la, uint64_t parent)
+                   struct osd_object *obj, sa_handle_t *sa_hdl, dmu_tx_t *tx,
+                   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;
@@ -1154,6 +1276,9 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
        timestruc_t      now;
        int              cnt;
        int              rc;
+       char *dxattr = NULL;
+       size_t sa_size;
+
 
        LASSERT(sa_hdl);
 
@@ -1169,16 +1294,32 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
        osa->gid = la->la_gid;
        osa->rdev = la->la_rdev;
        osa->nlink = la->la_nlink;
-       osa->flags = attrs_fs2zfs(la->la_flags);
+       if (la->la_valid & LA_FLAGS)
+               osa->flags = attrs_fs2zfs(la->la_flags);
+       else
+               osa->flags = 0;
        osa->size  = la->la_size;
+#ifdef ZFS_PROJINHERIT
+       if (osd->od_projectused_dn) {
+               if (la->la_valid & LA_PROJID)
+                       osa->projid = la->la_projid;
+               else
+                       osa->projid = ZFS_DEFAULT_PROJID;
+               osa->flags |= ZFS_PROJID;
+               if (obj)
+                       obj->oo_with_projid = 1;
+       } else {
+               osa->flags &= ~ZFS_PROJID;
+       }
+#endif
 
        /*
         * we need to create all SA below upon object create.
         *
         * XXX The attribute order matters since the accounting callback relies
         * on static offsets (i.e. SA_*_OFFSET, see zfs_space_delta_cb()) to
-        * look up the UID/GID attributes. Moreover, the callback does not seem
-        * to support the spill block.
+        * look up the UID/GID/PROJID attributes. Moreover, the callback does
+        * not seem to support the spill block.
         * We define attributes in the same order as SA_*_OFFSET in order to
         * work around the problem. See ORI-610.
         */
@@ -1195,10 +1336,32 @@ int __osd_attr_init(const struct lu_env *env, struct osd_device *osd,
        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_LINKS(osd), NULL, &osa->nlink, 8);
+#ifdef ZFS_PROJINHERIT
+       if (osd->od_projectused_dn)
+               SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_PROJID(osd), NULL,
+                                &osa->projid, 8);
+#endif
        SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_RDEV(osd), NULL, &osa->rdev, 8);
        LASSERT(cnt <= ARRAY_SIZE(osd_oti_get(env)->oti_attr_bulk));
 
+       if (xattr) {
+               rc = -nvlist_size(xattr, &sa_size, NV_ENCODE_XDR);
+               LASSERT(rc == 0);
+
+               dxattr = osd_zio_buf_alloc(sa_size);
+               LASSERT(dxattr);
+
+               rc = -nvlist_pack(xattr, &dxattr, &sa_size,
+                               NV_ENCODE_XDR, KM_SLEEP);
+               LASSERT(rc == 0);
+
+               SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_DXATTR(osd),
+                               NULL, dxattr, sa_size);
+       }
+
        rc = -sa_replace_all_by_template(sa_hdl, bulk, cnt, tx);
+       if (dxattr)
+               osd_zio_buf_free(dxattr, sa_size);
 
        return rc;
 }
@@ -1245,6 +1408,43 @@ static int osd_find_new_dnode(const struct lu_env *env, dmu_tx_t *tx,
        return rc;
 }
 
+#ifdef HAVE_DMU_OBJECT_ALLOC_DNSIZE
+static int osd_find_dnsize(struct osd_object *obj)
+{
+       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)
+                               break;
+                       dnsize <<= 1;
+               } while (dnsize < DNODE_MAX_SIZE);
+               if (dnsize > DNODE_MAX_SIZE)
+                       dnsize = DNODE_MAX_SIZE;
+       } else if (osd->od_dnsize == ZFS_DNSIZE_1K) {
+               dnsize = 1024;
+       } else if (osd->od_dnsize == ZFS_DNSIZE_2K) {
+               dnsize = 2048;
+       } else if (osd->od_dnsize == ZFS_DNSIZE_4K) {
+               dnsize = 4096;
+       } else if (osd->od_dnsize == ZFS_DNSIZE_8K) {
+               dnsize = 8192;
+       } else if (osd->od_dnsize == ZFS_DNSIZE_16K) {
+               dnsize = 16384;
+       } else {
+               dnsize = DNODE_MIN_SIZE;
+       }
+       return dnsize;
+}
+#else
+static int inline osd_find_dnsize(struct osd_object *obj)
+{
+       return DN_MAX_BONUSLEN;
+}
+#endif
+
 /*
  * The transaction passed to this routine must have
  * dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT) called and then assigned
@@ -1265,7 +1465,8 @@ 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. */
-       oid = osd_dmu_object_alloc(osd->od_os, type, 0, 0, tx);
+       oid = osd_dmu_object_alloc(osd->od_os, type, 0,
+                                  osd_find_dnsize(obj), tx);
 
        LASSERT(la->la_valid & LA_MODE);
        la->la_size = 0;
@@ -1286,7 +1487,7 @@ int __osd_object_create(const struct lu_env *env, struct osd_object *obj,
  * a conversion from the different internal ZAP hash formats being used. */
 int __osd_zap_create(const struct lu_env *env, struct osd_device *osd,
                     dnode_t **dnp, dmu_tx_t *tx, struct lu_attr *la,
-                    zap_flags_t flags)
+                    unsigned dnsize, zap_flags_t flags)
 {
        uint64_t oid;
 
@@ -1299,7 +1500,7 @@ int __osd_zap_create(const struct lu_env *env, struct osd_device *osd,
                                   DMU_OT_DIRECTORY_CONTENTS,
                                   14, /* == ZFS fzap_default_blockshift */
                                   DN_MAX_INDBLKSHIFT, /* indirect blockshift */
-                                  0, tx);
+                                  dnsize, tx);
 
        la->la_size = 2;
        la->la_nlink = 1;
@@ -1319,7 +1520,7 @@ static dnode_t *osd_mkidx(const struct lu_env *env, struct osd_object *obj,
         * binary keys */
        LASSERT(S_ISREG(la->la_mode));
        rc = __osd_zap_create(env, osd_obj2dev(obj), &dn, oh->ot_tx, la,
-                             ZAP_FLAG_UINT64_KEY);
+                             osd_find_dnsize(obj), ZAP_FLAG_UINT64_KEY);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1332,7 +1533,8 @@ static dnode_t *osd_mkdir(const struct lu_env *env, struct osd_object *obj,
        int rc;
 
        LASSERT(S_ISDIR(la->la_mode));
-       rc = __osd_zap_create(env, osd_obj2dev(obj), &dn, oh->ot_tx, la, 0);
+       rc = __osd_zap_create(env, osd_obj2dev(obj), &dn, oh->ot_tx, la,
+                             osd_find_dnsize(obj), 0);
        if (rc)
                return ERR_PTR(rc);
        return dn;
@@ -1432,11 +1634,9 @@ static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
 /*
  * Concurrency: @dt is write locked.
  */
-static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
-                            struct lu_attr *attr,
-                            struct dt_allocation_hint *hint,
-                            struct dt_object_format *dof,
-                            struct thandle *th)
+static int osd_create(const struct lu_env *env, struct dt_object *dt,
+                     struct lu_attr *attr, struct dt_allocation_hint *hint,
+                     struct dt_object_format *dof, struct thandle *th)
 {
        struct osd_thread_info  *info = osd_oti_get(env);
        struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
@@ -1452,6 +1652,8 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
 
        ENTRY;
 
+       LASSERT(!fid_is_acct(fid));
+
        /* concurrent create declarations should not see
         * the object inconsistent (db, attr, etc).
         * in regular cases acquisition should be cheap */
@@ -1478,6 +1680,14 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
        obj->oo_attr = *attr;
        obj->oo_attr.la_valid |= LA_SIZE | LA_NLINK | LA_TYPE;
 
+#ifdef ZFS_PROJINHERIT
+       if (osd->od_projectused_dn) {
+               if (!(obj->oo_attr.la_valid & LA_PROJID))
+                       obj->oo_attr.la_projid = ZFS_DEFAULT_PROJID;
+               obj->oo_with_projid = 1;
+       }
+#endif
+
        dn = osd_create_type_f(dof->dof_type)(env, obj, &obj->oo_attr, oh);
        if (IS_ERR(dn)) {
                rc = PTR_ERR(dn);
@@ -1500,33 +1710,31 @@ static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
        if (rc)
                GOTO(out, rc);
 
-       /* configure new osd object */
-       parent = parent != 0 ? parent : zapid;
-       rc = __osd_attr_init(env, osd, obj->oo_sa_hdl, oh->ot_tx,
-                            &obj->oo_attr, parent);
-       if (rc)
-               GOTO(out, rc);
-
-       /* XXX: oo_lma_flags */
-       obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
-       if (likely(!fid_is_acct(lu_object_fid(&obj->oo_dt.do_lu))))
-               /* no body operations for accounting objects */
-               obj->oo_dt.do_body_ops = &osd_body_ops;
-
        rc = -nvlist_alloc(&obj->oo_sa_xattr, NV_UNIQUE_NAME, KM_SLEEP);
        if (rc)
                GOTO(out, rc);
 
        /* initialize LMA */
-       lustre_lma_init(lma, lu_object_fid(&obj->oo_dt.do_lu), 0, 0);
+       lustre_lma_init(lma, fid, 0, 0);
        lustre_lma_swab(lma);
        rc = -nvlist_add_byte_array(obj->oo_sa_xattr, XATTR_NAME_LMA,
                                    (uchar_t *)lma, sizeof(*lma));
        if (rc)
                GOTO(out, rc);
-       rc = __osd_sa_xattr_update(env, obj, oh);
+
+       /* configure new osd object */
+       obj->oo_parent = parent != 0 ? parent : zapid;
+       obj->oo_late_attr_set = 1;
+       rc = __osd_sa_xattr_schedule_update(env, obj, oh);
        if (rc)
                GOTO(out, rc);
+
+       /* XXX: oo_lma_flags */
+       obj->oo_dt.do_lu.lo_header->loh_attr |= obj->oo_attr.la_mode & S_IFMT;
+       if (likely(!fid_is_acct(lu_object_fid(&obj->oo_dt.do_lu))))
+               /* no body operations for accounting objects */
+               obj->oo_dt.do_body_ops = &osd_body_ops;
+
        osd_idc_find_and_init(env, osd, obj);
 
 out:
@@ -1541,9 +1749,8 @@ out:
        RETURN(rc);
 }
 
-static int osd_declare_object_ref_add(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     struct thandle *th)
+static int osd_declare_ref_add(const struct lu_env *env, struct dt_object *dt,
+                              struct thandle *th)
 {
        return osd_declare_attr_set(env, dt, NULL, th);
 }
@@ -1551,9 +1758,8 @@ static int osd_declare_object_ref_add(const struct lu_env *env,
 /*
  * Concurrency: @dt is write locked.
  */
-static int osd_object_ref_add(const struct lu_env *env,
-                             struct dt_object *dt,
-                             struct thandle *handle)
+static int osd_ref_add(const struct lu_env *env, struct dt_object *dt,
+                      struct thandle *handle)
 {
        struct osd_object       *obj = osd_dt_obj(dt);
        struct osd_thandle      *oh;
@@ -1583,9 +1789,8 @@ out:
        RETURN(rc);
 }
 
-static int osd_declare_object_ref_del(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     struct thandle *handle)
+static int osd_declare_ref_del(const struct lu_env *env, struct dt_object *dt,
+                              struct thandle *handle)
 {
        return osd_declare_attr_set(env, dt, NULL, handle);
 }
@@ -1593,9 +1798,8 @@ static int osd_declare_object_ref_del(const struct lu_env *env,
 /*
  * Concurrency: @dt is write locked.
  */
-static int osd_object_ref_del(const struct lu_env *env,
-                             struct dt_object *dt,
-                             struct thandle *handle)
+static int osd_ref_del(const struct lu_env *env, struct dt_object *dt,
+                      struct thandle *handle)
 {
        struct osd_object       *obj = osd_dt_obj(dt);
        struct osd_thandle      *oh;
@@ -1649,24 +1853,24 @@ static int osd_invalidate(const struct lu_env *env, struct dt_object *dt)
 }
 
 static struct dt_object_operations osd_obj_ops = {
-       .do_read_lock           = osd_object_read_lock,
-       .do_write_lock          = osd_object_write_lock,
-       .do_read_unlock         = osd_object_read_unlock,
-       .do_write_unlock        = osd_object_write_unlock,
-       .do_write_locked        = osd_object_write_locked,
+       .do_read_lock           = osd_read_lock,
+       .do_write_lock          = osd_write_lock,
+       .do_read_unlock         = osd_read_unlock,
+       .do_write_unlock        = osd_write_unlock,
+       .do_write_locked        = osd_write_locked,
        .do_attr_get            = osd_attr_get,
        .do_declare_attr_set    = osd_declare_attr_set,
        .do_attr_set            = osd_attr_set,
        .do_ah_init             = osd_ah_init,
-       .do_declare_create      = osd_declare_object_create,
-       .do_create              = osd_object_create,
-       .do_declare_destroy     = osd_declare_object_destroy,
-       .do_destroy             = osd_object_destroy,
+       .do_declare_create      = osd_declare_create,
+       .do_create              = osd_create,
+       .do_declare_destroy     = osd_declare_destroy,
+       .do_destroy             = osd_destroy,
        .do_index_try           = osd_index_try,
-       .do_declare_ref_add     = osd_declare_object_ref_add,
-       .do_ref_add             = osd_object_ref_add,
-       .do_declare_ref_del     = osd_declare_object_ref_del,
-       .do_ref_del             = osd_object_ref_del,
+       .do_declare_ref_add     = osd_declare_ref_add,
+       .do_ref_add             = osd_ref_add,
+       .do_declare_ref_del     = osd_declare_ref_del,
+       .do_ref_del             = osd_ref_del,
        .do_xattr_get           = osd_xattr_get,
        .do_declare_xattr_set   = osd_declare_xattr_set,
        .do_xattr_set           = osd_xattr_set,
@@ -1695,6 +1899,6 @@ static int osd_otable_it_attr_get(const struct lu_env *env,
 }
 
 static struct dt_object_operations osd_obj_otable_it_ops = {
-        .do_attr_get    = osd_otable_it_attr_get,
-        .do_index_try   = osd_index_try,
+       .do_attr_get            = osd_otable_it_attr_get,
+       .do_index_try           = osd_index_try,
 };