Whamcloud - gitweb
b=1028 drop SOM dependency on quota
[fs/lustre-release.git] / lustre / osd / osd_handler.c
index 7235a3c..302923c 100644 (file)
 #include <linux/fs.h>
 /* XATTR_{REPLACE,CREATE} */
 #include <linux/xattr.h>
-/*
- * XXX temporary stuff: direct access to ldiskfs/jdb. Interface between osd
- * and file system is not yet specified.
- */
-/* handle_t, journal_start(), journal_stop() */
-#include <linux/jbd.h>
-/* LDISKFS_SB() */
-#include <linux/ldiskfs_fs.h>
-#include <linux/ldiskfs_jbd.h>
 /* simple_mkdir() */
 #include <lvfs.h>
 
@@ -77,7 +68,6 @@
 
 /* fid_is_local() */
 #include <lustre_fid.h>
-#include <linux/lustre_iam.h>
 
 #include "osd_internal.h"
 #include "osd_igif.h"
@@ -107,18 +97,18 @@ struct osd_object {
         /**
          * to protect index ops.
          */
-        struct rw_semaphore    oo_ext_idx_sem;
-        struct rw_semaphore    oo_sem;
+        cfs_rw_semaphore_t     oo_ext_idx_sem;
+        cfs_rw_semaphore_t     oo_sem;
         struct osd_directory  *oo_dir;
         /** protects inode attributes. */
-        spinlock_t             oo_guard;
+        cfs_spinlock_t         oo_guard;
         /**
          * Following two members are used to indicate the presence of dot and
          * dotdot in the given directory. This is required for interop mode
          * (b11826).
          */
-        int oo_compat_dot_created;
-        int oo_compat_dotdot_created;
+        int                    oo_compat_dot_created;
+        int                    oo_compat_dotdot_created;
 
         const struct lu_env   *oo_owner;
 #ifdef CONFIG_LOCKDEP
@@ -296,9 +286,9 @@ static struct lu_object *osd_object_alloc(const struct lu_env *env,
                         mo->oo_dt.do_ops = &osd_obj_ops;
 
                 l->lo_ops = &osd_lu_obj_ops;
-                init_rwsem(&mo->oo_sem);
-                init_rwsem(&mo->oo_ext_idx_sem);
-                spin_lock_init(&mo->oo_guard);
+                cfs_init_rwsem(&mo->oo_sem);
+                cfs_init_rwsem(&mo->oo_ext_idx_sem);
+                cfs_spin_lock_init(&mo->oo_guard);
                 return l;
         } else
                 return NULL;
@@ -311,9 +301,16 @@ static struct inode *osd_iget(struct osd_thread_info *info,
                               struct osd_device *dev,
                               const struct osd_inode_id *id)
 {
-        struct inode *inode;
+        struct inode *inode = NULL;
 
+#ifdef HAVE_EXT4_LDISKFS
+        inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
+        if (IS_ERR(inode))
+        /* Newer kernels return an error instead of a NULL pointer */
+                inode = NULL;
+#else
         inode = iget(osd_sb(dev), id->oii_ino);
+#endif
         if (inode == NULL) {
                 CERROR("no inode\n");
                 inode = ERR_PTR(-EACCES);
@@ -575,7 +572,7 @@ static struct thandle *osd_trans_start(const struct lu_env *env,
                          * be used.
                          */
 
-                        jh = journal_start(osd_journal(dev), p->tp_credits);
+                        jh = ldiskfs_journal_start_sb(osd_sb(dev), p->tp_credits);
                         if (!IS_ERR(jh)) {
                                 oh->ot_handle = jh;
                                 th = &oh->ot_super;
@@ -589,8 +586,8 @@ static struct thandle *osd_trans_start(const struct lu_env *env,
                                 /* add commit callback */
                                 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
                                 lu_context_enter(&th->th_ctx);
-                                journal_callback_set(jh, osd_trans_commit_cb,
-                                                     (struct journal_callback *)&oh->ot_jcb);
+                                osd_journal_callback_set(jh, osd_trans_commit_cb,
+                                                         (struct journal_callback *)&oh->ot_jcb);
                                         LASSERT(oti->oti_txns == 0);
                                         LASSERT(oti->oti_r_locks == 0);
                                         LASSERT(oti->oti_w_locks == 0);
@@ -632,7 +629,7 @@ static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
                 if (result != 0)
                         CERROR("Failure in transaction hook: %d\n", result);
                 oh->ot_handle = NULL;
-                result = journal_stop(hdl);
+                result = ldiskfs_journal_stop(hdl);
                 if (result != 0)
                         CERROR("Failure to stop transaction: %d\n", result);
         }
@@ -713,7 +710,7 @@ static void osd_object_release(const struct lu_env *env,
 
         LASSERT(!lu_object_is_dying(l->lo_header));
         if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
-                set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
+                cfs_set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
 }
 
 /*
@@ -740,13 +737,13 @@ static int osd_object_print(const struct lu_env *env, void *cookie,
  * Concurrency: shouldn't matter.
  */
 int osd_statfs(const struct lu_env *env, struct dt_device *d,
-               struct kstatfs *sfs)
+               cfs_kstatfs_t *sfs)
 {
         struct osd_device *osd = osd_dt_dev(d);
         struct super_block *sb = osd_sb(osd);
         int result = 0;
 
-        spin_lock(&osd->od_osfs_lock);
+        cfs_spin_lock(&osd->od_osfs_lock);
         /* cache 1 second */
         if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
                 result = ll_do_statfs(sb, &osd->od_kstatfs);
@@ -756,7 +753,7 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d,
 
         if (likely(result == 0))
                 *sfs = osd->od_kstatfs;
-        spin_unlock(&osd->od_osfs_lock);
+        cfs_spin_unlock(&osd->od_osfs_lock);
 
         return result;
 }
@@ -910,8 +907,8 @@ static const int osd_dto_credits_noquota[DTO_NR] = {
         /**
          * Xattr set. The same as xattr of EXT3.
          * DATA_TRANS_BLOCKS(14)
-         * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS are
-         *           also counted in. Do not know why?
+         * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
+         * are also counted in. Do not know why?
          */
         [DTO_XATTR_SET]     = 14,
         [DTO_LOG_REC]       = 14,
@@ -925,9 +922,9 @@ static const int osd_dto_credits_noquota[DTO_NR] = {
         [DTO_WRITE_BLOCK]   = 14,
         /**
          * Attr set credits for chown.
-         * 3 (inode bit, group, GDT)
+         * This is extra credits for setattr, and it is null without quota
          */
-        [DTO_ATTR_SET_CHOWN]= 3
+        [DTO_ATTR_SET_CHOWN]= 0
 };
 
 /**
@@ -990,11 +987,11 @@ static const int osd_dto_credits_quota[DTO_NR] = {
         [DTO_WRITE_BLOCK]   = 16,
         /**
          * Attr set credits for chown.
-         * 3 (inode bit, group, GDT) +
+         * It is added to already set setattr credits
          * 2 * QUOTA_INIT_BLOCKS(25) +
          * 2 * QUOTA_DEL_BLOCKS(9)
          */
-        [DTO_ATTR_SET_CHOWN]= 71
+        [DTO_ATTR_SET_CHOWN]= 68,
 };
 
 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
@@ -1034,7 +1031,7 @@ static void osd_object_read_lock(const struct lu_env *env,
         LINVRNT(osd_invariant(obj));
 
         LASSERT(obj->oo_owner != env);
-        down_read_nested(&obj->oo_sem, role);
+        cfs_down_read_nested(&obj->oo_sem, role);
 
         LASSERT(obj->oo_owner == NULL);
         oti->oti_r_locks++;
@@ -1049,7 +1046,7 @@ static void osd_object_write_lock(const struct lu_env *env,
         LINVRNT(osd_invariant(obj));
 
         LASSERT(obj->oo_owner != env);
-        down_write_nested(&obj->oo_sem, role);
+        cfs_down_write_nested(&obj->oo_sem, role);
 
         LASSERT(obj->oo_owner == NULL);
         obj->oo_owner = env;
@@ -1066,7 +1063,7 @@ static void osd_object_read_unlock(const struct lu_env *env,
 
         LASSERT(oti->oti_r_locks > 0);
         oti->oti_r_locks--;
-        up_read(&obj->oo_sem);
+        cfs_up_read(&obj->oo_sem);
 }
 
 static void osd_object_write_unlock(const struct lu_env *env,
@@ -1081,7 +1078,7 @@ static void osd_object_write_unlock(const struct lu_env *env,
         LASSERT(oti->oti_w_locks > 0);
         oti->oti_w_locks--;
         obj->oo_owner = NULL;
-        up_write(&obj->oo_sem);
+        cfs_up_write(&obj->oo_sem);
 }
 
 static int osd_object_write_locked(const struct lu_env *env,
@@ -1120,14 +1117,14 @@ static int capa_is_sane(const struct lu_env *env,
                 RETURN(-ESTALE);
         }
 
-        spin_lock(&capa_lock);
+        cfs_spin_lock(&capa_lock);
         for (i = 0; i < 2; i++) {
                 if (keys[i].lk_keyid == capa->lc_keyid) {
                         oti->oti_capa_key = keys[i];
                         break;
                 }
         }
-        spin_unlock(&capa_lock);
+        cfs_spin_unlock(&capa_lock);
 
         if (i == 2) {
                 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
@@ -1242,9 +1239,9 @@ static int osd_attr_get(const struct lu_env *env,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
                 return -EACCES;
 
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         osd_inode_getattr(env, obj->oo_inode, attr);
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
         return 0;
 }
 
@@ -1290,13 +1287,12 @@ static int osd_inode_setattr(const struct lu_env *env,
                 i_size_write(inode, attr->la_size);
         }
 
+#if 0
         /* OSD should not change "i_blocks" which is used by quota.
-         * "i_blocks" should be changed by ldiskfs only.
-         * Enable this assignment for SOM purpose now, until it is
-         * stored in SOM EA. */
+         * "i_blocks" should be changed by ldiskfs only. */
         if (bits & LA_BLOCKS)
                 inode->i_blocks = attr->la_blocks;
-
+#endif
         if (bits & LA_MODE)
                 inode->i_mode   = (inode->i_mode & S_IFMT) |
                         (attr->la_mode & ~S_IFMT);
@@ -1334,9 +1330,9 @@ static int osd_attr_set(const struct lu_env *env,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
                 return -EACCES;
 
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         rc = osd_inode_setattr(env, obj->oo_inode, attr);
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
 
         if (!rc)
                 mark_inode_dirty(obj->oo_inode);
@@ -1361,25 +1357,6 @@ static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
         return 0;
 }
 
-extern struct inode *ldiskfs_create_inode(handle_t *handle,
-                                          struct inode * dir, int mode);
-extern int ldiskfs_add_entry(handle_t *handle, struct dentry *dentry,
-                             struct inode *inode);
-extern int ldiskfs_delete_entry(handle_t *handle,
-                                struct inode * dir,
-                                struct ldiskfs_dir_entry_2 * de_del,
-                                struct buffer_head * bh);
-extern struct buffer_head * ldiskfs_find_entry(struct dentry *dentry,
-                                               struct ldiskfs_dir_entry_2
-                                               ** res_dir);
-extern int ldiskfs_add_dot_dotdot(handle_t *handle, struct inode *dir,
-                                  struct inode *inode);
-
-extern int ldiskfs_xattr_set_handle(handle_t *handle, struct inode *inode,
-                                    int name_index, const char *name,
-                                    const void *value, size_t value_len,
-                                    int flags);
-
 static struct dentry * osd_child_dentry_get(const struct lu_env *env,
                                             struct osd_object *obj,
                                             const char *name,
@@ -1402,7 +1379,7 @@ static struct dentry * osd_child_dentry_get(const struct lu_env *env,
 
 
 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
-                      umode_t mode,
+                      cfs_umode_t mode,
                       struct dt_allocation_hint *hint,
                       struct thandle *th)
 {
@@ -1446,13 +1423,6 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
         return result;
 }
 
-
-extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
-                           int recsize, handle_t *handle);
-
-extern int iam_lfix_create(struct inode *obj, int keysize, int ptrsize,
-                           int recsize, handle_t *handle);
-
 enum {
         OSD_NAME_LEN = 255
 };
@@ -1480,7 +1450,7 @@ static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
                  */
 
                 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
-                                         sizeof (struct lu_fid_pack),
+                                         sizeof (struct osd_fid_pack),
                                          oth->ot_handle);
         }
         return result;
@@ -1551,7 +1521,7 @@ static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
                      struct dt_object_format *dof,
                      struct thandle *th)
 {
-        umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
+        cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
         int result;
 
         LINVRNT(osd_invariant(obj));
@@ -1604,7 +1574,7 @@ static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
 
 
 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
-                        struct dt_object *parent, umode_t child_mode)
+                        struct dt_object *parent, cfs_umode_t child_mode)
 {
         LASSERT(ah);
 
@@ -1716,9 +1686,9 @@ static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
         rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
                                    buf->lb_len, fs_flags);
         /* ctime should not be updated with server-side time. */
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         inode->i_ctime = *t;
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
         mark_inode_dirty(inode);
         return rc;
 }
@@ -1739,8 +1709,8 @@ static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
         struct osd_thread_info  *info      = osd_oti_get(env);
         struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
 
-        fid_cpu_to_be(&mdt_attrs->lma_self_fid, fid);
-
+        lustre_lma_init(mdt_attrs, fid);
+        lustre_lma_swab(mdt_attrs);
         return __osd_xattr_set(env, dt,
                                osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
                                XATTR_NAME_LMA, LU_XATTR_CREATE);
@@ -1759,19 +1729,38 @@ static inline void osd_igif_get(const struct lu_env *env, struct inode  *inode,
 /**
  * Helper function to pack the fid
  */
-static inline void osd_fid_pack(const struct lu_env *env, const struct lu_fid *fid,
-                                struct dt_rec *pack)
+void osd_fid_pack(struct osd_fid_pack *pack, const struct dt_rec *fid,
+                  struct lu_fid *befider)
 {
-        fid_pack((struct lu_fid_pack *)pack, fid, &osd_oti_get(env)->oti_fid);
+        fid_cpu_to_be(befider, (struct lu_fid *)fid);
+        memcpy(pack->fp_area, befider, sizeof(*befider));
+        pack->fp_len =  sizeof(*befider) + 1;
+}
+
+int osd_fid_unpack(struct lu_fid *fid, const struct osd_fid_pack *pack)
+{
+        int result;
+
+        result = 0;
+        switch (pack->fp_len) {
+        case sizeof *fid + 1:
+                memcpy(fid, pack->fp_area, sizeof *fid);
+                fid_be_to_cpu(fid, fid);
+                break;
+        default:
+                CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
+                result = -EIO;
+        }
+        return result;
 }
 
 /**
  * Try to read the fid from inode ea into dt_rec, if return value
  * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
  *
- * \param fid, object fid.
+ * \param fid object fid.
  *
- * \retval 0, on success
+ * \retval 0 on success
  */
 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
                           __u32 ino, struct lu_fid *fid)
@@ -1804,15 +1793,16 @@ static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
 
         /* Check LMA compatibility */
         if (rc > 0 &&
-            (mdt_attrs->lma_incompat & ~cpu_to_be32(LMA_INCOMPAT_SUPP))) {
+            (mdt_attrs->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP))) {
                 CWARN("Inode %lx: Unsupported incompat LMA feature(s) %#x\n",
-                      inode->i_ino, be32_to_cpu(mdt_attrs->lma_incompat) &
+                      inode->i_ino, le32_to_cpu(mdt_attrs->lma_incompat) &
                       ~LMA_INCOMPAT_SUPP);
                 return -ENOSYS;
         }
 
         if (rc > 0) {
-                fid_be_to_cpu(fid, &mdt_attrs->lma_self_fid);
+                lustre_lma_swab(mdt_attrs);
+                memcpy(fid, &mdt_attrs->lma_self_fid, sizeof(*fid));
                 rc = 0;
         } else if (rc == -ENODATA) {
                 osd_igif_get(env, inode, fid);
@@ -1883,10 +1873,10 @@ static void osd_object_ref_add(const struct lu_env *env,
         LASSERT(osd_write_locked(env, obj));
         LASSERT(th != NULL);
 
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
         inode->i_nlink++;
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
         mark_inode_dirty(inode);
         LINVRNT(osd_invariant(obj));
 }
@@ -1906,10 +1896,10 @@ static void osd_object_ref_del(const struct lu_env *env,
         LASSERT(osd_write_locked(env, obj));
         LASSERT(th != NULL);
 
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         LASSERT(inode->i_nlink > 0);
         inode->i_nlink--;
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
         mark_inode_dirty(inode);
         LINVRNT(osd_invariant(obj));
 }
@@ -2006,9 +1996,9 @@ static int osd_xattr_del(const struct lu_env *env,
         *t = inode->i_ctime;
         rc = inode->i_op->removexattr(dentry, name);
         /* ctime should not be updated with server-side time. */
-        spin_lock(&obj->oo_guard);
+        cfs_spin_lock(&obj->oo_guard);
         inode->i_ctime = *t;
-        spin_unlock(&obj->oo_guard);
+        cfs_spin_unlock(&obj->oo_guard);
         mark_inode_dirty(inode);
         return rc;
 }
@@ -2055,9 +2045,9 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env,
                 __u32 d[4], s[4];
 
                 s[0] = obj->oo_inode->i_uid;
-                get_random_bytes(&(s[1]), sizeof(__u32));
+                ll_get_random_bytes(&(s[1]), sizeof(__u32));
                 s[2] = obj->oo_inode->i_gid;
-                get_random_bytes(&(s[3]), sizeof(__u32));
+                ll_get_random_bytes(&(s[3]), sizeof(__u32));
                 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
                 if (unlikely(rc))
                         RETURN(ERR_PTR(rc));
@@ -2083,9 +2073,9 @@ static struct obd_capa *osd_capa_get(const struct lu_env *env,
                 RETURN(oc);
         }
 
-        spin_lock(&capa_lock);
+        cfs_spin_lock(&capa_lock);
         *key = dev->od_capa_keys[1];
-        spin_unlock(&capa_lock);
+        cfs_spin_unlock(&capa_lock);
 
         capa->lc_keyid = key->lk_keyid;
         capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
@@ -2167,7 +2157,6 @@ static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
                            const struct dt_index_features *feat)
 {
         struct iam_descr *descr;
-        struct dt_object *dt = &o->oo_dt;
 
         if (osd_object_is_root(o))
                 return feat == &dt_directory_features;
@@ -2176,21 +2165,10 @@ static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
 
         descr = o->oo_dir->od_container.ic_descr;
         if (feat == &dt_directory_features) {
-                if (descr->id_rec_size == sizeof(struct lu_fid_pack))
+                if (descr->id_rec_size == sizeof(struct osd_fid_pack))
                         return 1;
-
-                if (descr == &iam_htree_compat_param) {
-                        /* if it is a HTREE dir then there is good chance that,
-                         * we dealing with ext3 directory here with no FIDs. */
-
-                        if (descr->id_rec_size ==
-                            sizeof ((struct ldiskfs_dir_entry_2 *)NULL)->inode) {
-
-                                dt->do_index_ops = &osd_index_ea_ops;
-                                return 1;
-                        }
-                }
-                return 0;
+                else
+                        return 0;
         } else {
                 return
                         feat->dif_keysize_min <= descr->id_key_size &&
@@ -2255,7 +2233,7 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
                 OBD_ALLOC_PTR(dir);
                 if (dir != NULL) {
 
-                        spin_lock(&obj->oo_guard);
+                        cfs_spin_lock(&obj->oo_guard);
                         if (obj->oo_dir == NULL)
                                 obj->oo_dir = dir;
                         else
@@ -2263,12 +2241,12 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
                                  * Concurrent thread allocated container data.
                                  */
                                 OBD_FREE_PTR(dir);
-                        spin_unlock(&obj->oo_guard);
+                        cfs_spin_unlock(&obj->oo_guard);
                         /*
                          * Now, that we have container data, serialize its
                          * initialization.
                          */
-                        down_write(&obj->oo_ext_idx_sem);
+                        cfs_down_write(&obj->oo_ext_idx_sem);
                         /*
                          * recheck under lock.
                          */
@@ -2276,7 +2254,7 @@ static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
                                 result = osd_iam_container_init(env, obj, dir);
                         else
                                 result = 0;
-                        up_write(&obj->oo_ext_idx_sem);
+                        cfs_up_write(&obj->oo_ext_idx_sem);
                 } else
                         result = -ENOMEM;
         } else
@@ -2418,7 +2396,7 @@ static const struct dt_body_operations osd_body_ops = {
 /**
  *      delete a (key, value) pair from index \a dt specified by \a key
  *
- *      \param  dt_object      osd index object
+ *      \param  dt      osd index object
  *      \param  key     key for index
  *      \param  rec     record reference
  *      \param  handle  transaction handler
@@ -2500,8 +2478,8 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
         dentry = osd_child_dentry_get(env, obj,
                                       (char *)key, strlen((char *)key));
 
-        down_write(&obj->oo_ext_idx_sem);
-        bh = ldiskfs_find_entry(dentry, &de);
+        cfs_down_write(&obj->oo_ext_idx_sem);
+        bh = ll_ldiskfs_find_entry(dir, dentry, &de);
         if (bh) {
                 struct osd_thread_info *oti = osd_oti_get(env);
                 struct timespec *ctime = &oti->oti_time;
@@ -2512,16 +2490,16 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
                 rc = ldiskfs_delete_entry(oh->ot_handle,
                                 dir, de, bh);
                 /* xtime should not be updated with server-side time. */
-                spin_lock(&obj->oo_guard);
+                cfs_spin_lock(&obj->oo_guard);
                 dir->i_ctime = *ctime;
                 dir->i_mtime = *mtime;
-                spin_unlock(&obj->oo_guard);
+                cfs_spin_unlock(&obj->oo_guard);
                 mark_inode_dirty(dir);
                 brelse(bh);
         } else
                 rc = -ENOENT;
 
-        up_write(&obj->oo_ext_idx_sem);
+        cfs_up_write(&obj->oo_ext_idx_sem);
         LASSERT(osd_invariant(obj));
         RETURN(rc);
 }
@@ -2529,7 +2507,7 @@ static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
 /**
  *      Lookup index for \a key and copy record to \a rec.
  *
- *      \param  dt_object      osd index object
+ *      \param  dt      osd index object
  *      \param  key     key for index
  *      \param  rec     record reference
  *
@@ -2546,6 +2524,7 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
         struct iam_container  *bag = &obj->oo_dir->od_container;
         struct osd_thread_info *oti = osd_oti_get(env);
         struct iam_iterator    *it = &oti->oti_idx_it;
+        struct iam_rec *iam_rec;
         int rc;
         ENTRY;
 
@@ -2564,9 +2543,17 @@ static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
         iam_it_init(it, bag, 0, ipd);
 
         rc = iam_it_get(it, (struct iam_key *)key);
-        if (rc >= 0)
-                iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)rec);
+        if (rc >= 0) {
+                if (S_ISDIR(obj->oo_inode->i_mode))
+                        iam_rec = (struct iam_rec *)oti->oti_fid_packed;
+                else
+                        iam_rec = (struct iam_rec *) rec;
 
+                iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
+                if (S_ISDIR(obj->oo_inode->i_mode))
+                        osd_fid_unpack((struct lu_fid *) rec,
+                                       (struct osd_fid_pack *)iam_rec);
+        }
         iam_it_put(it);
         iam_it_fini(it);
         osd_ipd_put(env, bag, ipd);
@@ -2599,6 +2586,8 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
 #ifdef HAVE_QUOTA_SUPPORT
         cfs_cap_t              save = current->cap_effective;
 #endif
+        struct osd_thread_info *oti = osd_oti_get(env);
+        struct iam_rec *iam_rec = (struct iam_rec *)oti->oti_fid_packed;
         int rc;
 
         ENTRY;
@@ -2624,8 +2613,12 @@ static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
         else
                 current->cap_effective &= ~CFS_CAP_SYS_RESOURCE_MASK;
 #endif
+        if (S_ISDIR(obj->oo_inode->i_mode))
+                osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
+        else
+                iam_rec = (struct iam_rec *) rec;
         rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
-                        (struct iam_rec *)rec, ipd);
+                        iam_rec, ipd);
 #ifdef HAVE_QUOTA_SUPPORT
         current->cap_effective = save;
 #endif
@@ -2746,11 +2739,10 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
                              struct dt_rec *rec, const struct dt_key *key)
 {
         struct inode               *dir    = obj->oo_inode;
-        struct osd_thread_info     *info   = osd_oti_get(env);
         struct dentry              *dentry;
         struct ldiskfs_dir_entry_2 *de;
         struct buffer_head         *bh;
-        struct lu_fid              *fid = &info->oti_fid;
+        struct lu_fid              *fid = (struct lu_fid *) rec;
         int ino;
         int rc;
 
@@ -2759,28 +2751,26 @@ static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
         dentry = osd_child_dentry_get(env, obj,
                                       (char *)key, strlen((char *)key));
 
-        down_read(&obj->oo_ext_idx_sem);
-        bh = ldiskfs_find_entry(dentry, &de);
+        cfs_down_read(&obj->oo_ext_idx_sem);
+        bh = ll_ldiskfs_find_entry(dir, dentry, &de);
         if (bh) {
                 ino = le32_to_cpu(de->inode);
                 brelse(bh);
                 rc = osd_ea_fid_get(env, obj, ino, fid);
-                if (rc == 0)
-                        osd_fid_pack(env, fid, rec);
         } else
                 rc = -ENOENT;
 
-        up_read(&obj->oo_ext_idx_sem);
+        cfs_up_read(&obj->oo_ext_idx_sem);
         RETURN (rc);
 }
 
 /**
  * Find the osd object for given fid.
  *
- * \param fid, need to find the osd object having this fid
+ * \param fid need to find the osd object having this fid
  *
- * \retval osd_object, on success
- * \retval        -ve, on error
+ * \retval osd_object on success
+ * \retval        -ve on error
  */
 struct osd_object *osd_object_find(const struct lu_env *env,
                                    struct dt_object *dt,
@@ -2822,7 +2812,7 @@ struct osd_object *osd_object_find(const struct lu_env *env,
 /**
  * Put the osd object once done with it.
  *
- * \param obj, osd object that needs to be put
+ * \param obj osd object that needs to be put
  */
 static inline void osd_object_put(const struct lu_env *env,
                                   struct osd_object *obj)
@@ -2835,8 +2825,8 @@ static inline void osd_object_put(const struct lu_env *env,
  * It will add the directory entry.This entry is needed to
  * maintain name->fid mapping.
  *
- * \param key, it is key i.e. file entry to be inserted
- * \param rec, it is value of given key i.e. fid
+ * \param key it is key i.e. file entry to be inserted
+ * \param rec it is value of given key i.e. fid
  *
  * \retval   0, on success
  * \retval -ve, on error
@@ -2847,8 +2837,7 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
                                struct lustre_capa *capa, int ignore_quota)
 {
         struct osd_object        *obj   = osd_dt_obj(dt);
-        struct lu_fid            *fid   = &osd_oti_get(env)->oti_fid;
-        const struct lu_fid_pack *pack  = (const struct lu_fid_pack *)rec;
+        struct lu_fid            *fid   = (struct lu_fid *) rec;
         const char               *name  = (const char *)key;
         struct osd_object        *child;
 #ifdef HAVE_QUOTA_SUPPORT
@@ -2865,9 +2854,6 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
                 RETURN(-EACCES);
 
-        rc = fid_unpack(pack, fid);
-        if (rc != 0)
-                RETURN(rc);
         child = osd_object_find(env, dt, fid);
         if (!IS_ERR(child)) {
                 struct inode *inode = obj->oo_inode;
@@ -2883,18 +2869,18 @@ static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
                 else
                         current->cap_effective &= ~CFS_CAP_SYS_RESOURCE_MASK;
 #endif
-                down_write(&obj->oo_ext_idx_sem);
+                cfs_down_write(&obj->oo_ext_idx_sem);
                 rc = osd_ea_add_rec(env, obj, child, name, th);
-                up_write(&obj->oo_ext_idx_sem);
+                cfs_up_write(&obj->oo_ext_idx_sem);
 #ifdef HAVE_QUOTA_SUPPORT
                 current->cap_effective = save;
 #endif
                 osd_object_put(env, child);
                 /* xtime should not be updated with server-side time. */
-                spin_lock(&obj->oo_guard);
+                cfs_spin_lock(&obj->oo_guard);
                 inode->i_ctime = *ctime;
                 inode->i_mtime = *mtime;
-                spin_unlock(&obj->oo_guard);
+                cfs_spin_unlock(&obj->oo_guard);
                 mark_inode_dirty(inode);
         } else {
                 rc = PTR_ERR(child);
@@ -3080,7 +3066,7 @@ static int osd_it_iam_rec(const struct lu_env *env,
         struct osd_it_iam *it        = (struct osd_it_iam *)di;
         struct osd_thread_info *info = osd_oti_get(env);
         struct lu_fid     *fid       = &info->oti_fid;
-        const struct lu_fid_pack *rec;
+        const struct osd_fid_pack *rec;
         char *name;
         int namelen;
         __u64 hash;
@@ -3092,11 +3078,11 @@ static int osd_it_iam_rec(const struct lu_env *env,
 
         namelen = iam_it_key_size(&it->oi_it);
 
-        rec = (const struct lu_fid_pack *) iam_it_rec_get(&it->oi_it);
+        rec = (const struct osd_fid_pack *) iam_it_rec_get(&it->oi_it);
         if (IS_ERR(rec))
                 RETURN(PTR_ERR(rec));
 
-        rc = fid_unpack(rec, fid);
+        rc = osd_fid_unpack(fid, rec);
         if (rc)
                 RETURN(rc);
 
@@ -3189,13 +3175,13 @@ static struct dt_it *osd_it_ea_init(const struct lu_env *env,
         it->oie_file.f_op         = obj->oo_inode->i_fop;
         it->oie_file.private_data = NULL;
         lu_object_get(lo);
-        RETURN((struct dt_it*) it);
+        RETURN((struct dt_it *) it);
 }
 
 /**
  * Destroy or finishes iterator context.
  *
- * \param di, struct osd_it_ea, iterator structure to be destroyed
+ * \param di iterator structure to be destroyed
  */
 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
 {
@@ -3246,11 +3232,11 @@ static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
  * iterator's in-memory data structure with required
  * information i.e. name, namelen, rec_size etc.
  *
- * \param buf, in which information to be filled in.
- * \param name, name of the file in given dir
+ * \param buf in which information to be filled in.
+ * \param name name of the file in given dir
  *
- * \retval 0, on success
- * \retval 1, on buffer full
+ * \retval 0 on success
+ * \retval 1 on buffer full
  */
 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
                                loff_t offset, __u64 ino,
@@ -3278,7 +3264,7 @@ static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
         memcpy(ent->oied_name, name, namelen);
 
         it->oie_rd_dirent++;
-        it->oie_dirent = (void *) ent + size_round(sizeof(*ent) + namelen);
+        it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
         RETURN(0);
 }
 
@@ -3286,10 +3272,10 @@ static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
  * Calls ->readdir() to load a directory entry at a time
  * and stored it in iterator's in-memory data structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di iterator's in memory structure
  *
- * \retval   0, on success
- * \retval -ve, on error
+ * \retval   0 on success
+ * \retval -ve on error
  */
 static int osd_ldiskfs_it_fill(const struct dt_it *di)
 {
@@ -3302,11 +3288,11 @@ static int osd_ldiskfs_it_fill(const struct dt_it *di)
         it->oie_dirent = it->oie_buf;
         it->oie_rd_dirent = 0;
 
-        down_read(&obj->oo_ext_idx_sem);
+        cfs_down_read(&obj->oo_ext_idx_sem);
         result = inode->i_fop->readdir(&it->oie_file, it,
                                        (filldir_t) osd_ldiskfs_filldir);
 
-        up_read(&obj->oo_ext_idx_sem);
+        cfs_up_read(&obj->oo_ext_idx_sem);
 
         if (it->oie_rd_dirent == 0) {
                 result = -EIO;
@@ -3323,11 +3309,11 @@ static int osd_ldiskfs_it_fill(const struct dt_it *di)
  * to load a directory entry at a time and stored it in
  * iterator's in-memory data structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di iterator's in memory structure
  *
- * \retval +ve, iterator reached to end
- * \retval   0, iterator not reached to end
- * \retval -ve, on error
+ * \retval +ve iterator reached to end
+ * \retval   0 iterator not reached to end
+ * \retval -ve on error
  */
 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
 {
@@ -3337,9 +3323,10 @@ static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
         ENTRY;
 
         if (it->oie_it_dirent < it->oie_rd_dirent) {
-                it->oie_dirent = (void *) it->oie_dirent +
-                                 size_round(sizeof(struct osd_it_ea_dirent) +
-                                            it->oie_dirent->oied_namelen);
+                it->oie_dirent =
+                        (void *) it->oie_dirent +
+                        cfs_size_round(sizeof(struct osd_it_ea_dirent) +
+                                       it->oie_dirent->oied_namelen);
                 it->oie_it_dirent++;
                 RETURN(0);
         } else {
@@ -3355,7 +3342,7 @@ static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
 /**
  * Returns the key at current position from iterator's in memory structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di iterator's in memory structure
  *
  * \retval key i.e. struct dt_key on success
  */
@@ -3370,7 +3357,7 @@ static struct dt_key *osd_it_ea_key(const struct lu_env *env,
 /**
  * Returns the key's size at current position from iterator's in memory structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di iterator's in memory structure
  *
  * \retval key_size i.e. struct dt_key on success
  */
@@ -3386,12 +3373,12 @@ static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
  * Returns the value (i.e. fid/igif) at current position from iterator's
  * in memory structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
- * \param attr, attr requested for dirent.
- * \param lde, lustre dirent
+ * \param di struct osd_it_ea, iterator's in memory structure
+ * \param attr attr requested for dirent.
+ * \param lde lustre dirent
  *
- * \retval   0, no error and \param lde has correct lustre dirent.
- * \retval -ve, on error
+ * \retval   0 no error and \param lde has correct lustre dirent.
+ * \retval -ve on error
  */
 static inline int osd_it_ea_rec(const struct lu_env *env,
                                 const struct dt_it *di,
@@ -3421,7 +3408,7 @@ static inline int osd_it_ea_rec(const struct lu_env *env,
  * Returns a cookie for current position of the iterator head, so that
  * user can use this cookie to load/start the iterator next time.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di iterator's in memory structure
  *
  * \retval cookie for current position, on success
  */
@@ -3437,10 +3424,10 @@ static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
  * to load a directory entry at a time and stored it i inn,
  * in iterator's in-memory data structure.
  *
- * \param di, struct osd_it_ea, iterator's in memory structure
+ * \param di struct osd_it_ea, iterator's in memory structure
  *
- * \retval +ve, on success
- * \retval -ve, on error
+ * \retval +ve on success
+ * \retval -ve on error
  */
 static int osd_it_ea_load(const struct lu_env *env,
                           const struct dt_it *di, __u64 hash)
@@ -3599,7 +3586,6 @@ static int osd_mount(const struct lu_env *env,
         struct lustre_sb_info    *lsi;
 
         ENTRY;
-
         if (o->od_mount != NULL) {
                 CERROR("Already mounted (%s)\n", dev);
                 RETURN(-EEXIST);
@@ -3669,7 +3655,7 @@ static struct lu_device *osd_device_alloc(const struct lu_env *env,
                         l = osd2lu_dev(o);
                         l->ld_ops = &osd_lu_ops;
                         o->od_dt_dev.dd_ops = &osd_dt_ops;
-                        spin_lock_init(&o->od_osfs_lock);
+                        cfs_spin_lock_init(&o->od_osfs_lock);
                         o->od_osfs_age = cfs_time_shift_64(-1000);
                         o->od_capa_hash = init_capa_hash();
                         if (o->od_capa_hash == NULL) {
@@ -3719,16 +3705,9 @@ static int osd_process_config(const struct lu_env *env,
         RETURN(err);
 }
 
-extern void ldiskfs_orphan_cleanup (struct super_block * sb,
-                                    struct ldiskfs_super_block * es);
-
 static int osd_recovery_complete(const struct lu_env *env,
                                  struct lu_device *d)
 {
-        struct osd_device *o = osd_dev(d);
-        ENTRY;
-        /* TODO: orphans handling */
-        ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
         RETURN(0);
 }