Whamcloud - gitweb
LU-12137 osd-ldiskfs: create locked and unlocked versions of osd lookup code
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index 7712187..15c395f 100644 (file)
 #include "osd_oi.h"
 
 static void osd_push_ctxt(const struct osd_device *dev,
-                          struct lvfs_run_ctxt *newctxt,
-                          struct lvfs_run_ctxt *save)
+                         struct lvfs_run_ctxt *newctxt,
+                         struct lvfs_run_ctxt *save)
 {
        OBD_SET_CTXT_MAGIC(newctxt);
        newctxt->pwdmnt = dev->od_mnt;
        newctxt->pwd = dev->od_mnt->mnt_root;
-       newctxt->fs = get_ds();
+       newctxt->fs = KERNEL_DS;
        newctxt->umask = current_umask();
        newctxt->dt = NULL;
 
        push_ctxt(save, newctxt);
 }
 
+struct dentry *osd_lookup_one_len_common(struct osd_device *dev,
+                                        const char *name,
+                                        struct dentry *base, int len,
+                                        enum oi_check_flags flags)
+{
+       struct dentry *dchild;
+
+       /*
+        * We can't use inode_is_locked() directly since we can't know
+        * if the current thread context took the lock earlier or if
+        * another thread context took the lock. OI_LOCKED tells us
+        * if the current thread context has already taken the lock.
+        */
+       if (!(flags & OI_LOCKED)) {
+               /* If another thread took this lock already we will
+                * just have to wait until the other thread is done.
+                */
+               inode_lock(base->d_inode);
+               dchild = lookup_one_len(name, base, len);
+               inode_unlock(base->d_inode);
+       } else {
+               /* This thread context already has taken the lock.
+                * Other threads will have to wait until we are done.
+                */
+               dchild = lookup_one_len(name, base, len);
+       }
+       if (IS_ERR(dchild))
+               return dchild;
+
+       if (dchild->d_inode && unlikely(is_bad_inode(dchild->d_inode))) {
+               CERROR("%s: bad inode returned %lu/%u: rc = -ENOENT\n",
+                      osd_name(dev), dchild->d_inode->i_ino,
+                      dchild->d_inode->i_generation);
+               dput(dchild);
+               dchild = ERR_PTR(-ENOENT);
+       }
+
+       return dchild;
+}
+
+/**
+ * osd_lookup_one_len_unlocked
+ *
+ * @dev:       obd device we are searching
+ * @name:      pathname component to lookup
+ * @base:      base directory to lookup from
+ * @len:       maximum length @len should be interpreted to
+ *
+ * Unlike osd_lookup_one_len, this should be called without the parent
+ * i_mutex held, and will take the i_mutex itself.
+ */
+struct dentry *osd_lookup_one_len_unlocked(struct osd_device *dev,
+                                          const char *name,
+                                          struct dentry *base, int len)
+{
+       return osd_lookup_one_len_common(dev, name, base, len, ~OI_LOCKED);
+}
+
+/**
+ * osd_lookup_one_len - lookup single pathname component
+ *
+ * @dev:       obd device we are searching
+ * @name:      pathname component to lookup
+ * @base:      base directory to lookup from
+ * @len:       maximum length @len should be interpreted to
+ *
+ * The caller must hold inode lock
+ */
+struct dentry *osd_lookup_one_len(struct osd_device *dev, const char *name,
+                                 struct dentry *base, int len)
+{
+       return osd_lookup_one_len_common(dev, name, base, len, OI_LOCKED);
+}
+
 /* utility to make a directory */
 static struct dentry *
 simple_mkdir(const struct lu_env *env, struct osd_device *osd,
@@ -77,11 +151,12 @@ simple_mkdir(const struct lu_env *env, struct osd_device *osd,
        struct inode *inode;
        struct dentry *dchild;
        int err = 0;
+
        ENTRY;
 
        // ASSERT_KERNEL_CTXT("kernel doing mkdir outside kernel context\n");
        CDEBUG(D_INODE, "creating directory %.*s\n", (int)strlen(name), name);
-       dchild = ll_lookup_one_len(name, dir, strlen(name));
+       dchild = osd_lookup_one_len_unlocked(osd, name, dir, strlen(name));
        if (IS_ERR(dchild))
                RETURN(dchild);
 
@@ -153,27 +228,27 @@ out_err:
 
 static int osd_last_rcvd_subdir_count(struct osd_device *osd)
 {
-        struct lr_server_data lsd;
-        struct dentry        *dlast;
-        loff_t                off;
-        int                   rc = 0;
-       int                   count = OBJ_SUBDIR_COUNT;
-
-        ENTRY;
-
-        dlast = ll_lookup_one_len(LAST_RCVD, osd_sb(osd)->s_root,
-                                  strlen(LAST_RCVD));
-        if (IS_ERR(dlast))
-                return PTR_ERR(dlast);
-        else if (dlast->d_inode == NULL)
-                goto out;
-
-        off = 0;
-        rc = osd_ldiskfs_read(dlast->d_inode, &lsd, sizeof(lsd), &off);
-        if (rc == sizeof(lsd)) {
-                CDEBUG(D_INFO, "read last_rcvd header, uuid = %s, "
-                       "subdir count = %d\n", lsd.lsd_uuid,
-                       lsd.lsd_subdir_count);
+       struct lr_server_data lsd;
+       struct dentry *dlast;
+       loff_t off;
+       int rc = 0;
+       int count = OBJ_SUBDIR_COUNT;
+
+       ENTRY;
+
+       dlast = osd_lookup_one_len_unlocked(osd, LAST_RCVD, osd_sb(osd)->s_root,
+                                           strlen(LAST_RCVD));
+       if (IS_ERR(dlast))
+               return PTR_ERR(dlast);
+       else if (dlast->d_inode == NULL)
+               goto out;
+
+       off = 0;
+       rc = osd_ldiskfs_read(dlast->d_inode, &lsd, sizeof(lsd), &off);
+       if (rc == sizeof(lsd)) {
+               CDEBUG(D_INFO,
+                     "read last_rcvd header, uuid = %s, subdir count = %d\n",
+                     lsd.lsd_uuid, lsd.lsd_subdir_count);
                if (le16_to_cpu(lsd.lsd_subdir_count) > 0)
                        count = le16_to_cpu(lsd.lsd_subdir_count);
        } else if (rc != 0) {
@@ -191,14 +266,15 @@ out:
 
 static int osd_mdt_init(const struct lu_env *env, struct osd_device *dev)
 {
-       struct lvfs_run_ctxt    new;
-       struct lvfs_run_ctxt    save;
-       struct dentry           *parent;
-       struct osd_mdobj_map    *omm;
-       struct dentry           *d;
-       struct osd_thread_info  *info = osd_oti_get(env);
-       struct lu_fid           *fid = &info->oti_fid3;
-       int                     rc = 0;
+       struct lvfs_run_ctxt new;
+       struct lvfs_run_ctxt save;
+       struct dentry *parent;
+       struct osd_mdobj_map *omm;
+       struct dentry *d;
+       struct osd_thread_info *info = osd_oti_get(env);
+       struct lu_fid *fid = &info->oti_fid3;
+       int rc = 0;
+
        ENTRY;
 
        OBD_ALLOC_PTR(dev->od_mdt_map);
@@ -248,20 +324,22 @@ static void osd_mdt_fini(struct osd_device *osd)
 int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
                             struct osd_object *obj, struct osd_thandle *oh)
 {
-       struct osd_mdobj_map    *omm = osd->od_mdt_map;
-       struct osd_thread_info  *oti = osd_oti_get(env);
-       struct lustre_mdt_attrs *lma = &oti->oti_ost_attrs.loa_lma;
-       char                    *name = oti->oti_name;
-       struct osd_thread_info  *info = osd_oti_get(env);
-       struct dentry           *dentry;
-       struct dentry           *parent;
-       int                     rc;
+       struct osd_mdobj_map *omm = osd->od_mdt_map;
+       struct osd_thread_info *oti = osd_oti_get(env);
+       struct lustre_mdt_attrs *lma = &oti->oti_ost_attrs.loa_lma;
+       char *name = oti->oti_name;
+       struct osd_thread_info *info = osd_oti_get(env);
+       struct dentry *dentry;
+       struct dentry *parent;
+       int rc;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AGENTENT))
                RETURN(0);
 
-       /* Set REMOTE_PARENT in lma, so other process like unlink or lfsck
-        * can identify this object quickly */
+       /*
+        * Set REMOTE_PARENT in lma, so other process like unlink or lfsck
+        * can identify this object quickly
+        */
        rc = osd_get_lma(oti, obj->oo_inode, &oti->oti_obj_dentry,
                         &oti->oti_ost_attrs);
        if (rc)
@@ -278,7 +356,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
        sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu)));
        dentry = osd_child_dentry_by_inode(env, parent->d_inode,
                                           name, strlen(name));
-       mutex_lock(&parent->d_inode->i_mutex);
+       inode_lock(parent->d_inode);
        rc = osd_ldiskfs_add_entry(info, osd, oh->ot_handle, dentry,
                                   obj->oo_inode, NULL);
        if (!rc && S_ISDIR(obj->oo_inode->i_mode))
@@ -290,7 +368,7 @@ int osd_add_to_remote_parent(const struct lu_env *env, struct osd_device *osd,
        CDEBUG(D_INODE, "%s: create agent entry for %s: rc = %d\n",
               osd_name(osd), name, rc);
        mark_inode_dirty(parent->d_inode);
-       mutex_unlock(&parent->d_inode->i_mutex);
+       inode_unlock(parent->d_inode);
        RETURN(rc);
 }
 
@@ -299,25 +377,25 @@ int osd_delete_from_remote_parent(const struct lu_env *env,
                                  struct osd_object *obj,
                                  struct osd_thandle *oh, bool destroy)
 {
-       struct osd_mdobj_map       *omm = osd->od_mdt_map;
-       struct osd_thread_info     *oti = osd_oti_get(env);
-       struct lustre_mdt_attrs    *lma = &oti->oti_ost_attrs.loa_lma;
-       char                       *name = oti->oti_name;
-       struct dentry              *dentry;
-       struct dentry              *parent;
+       struct osd_mdobj_map *omm = osd->od_mdt_map;
+       struct osd_thread_info *oti = osd_oti_get(env);
+       struct lustre_mdt_attrs *lma = &oti->oti_ost_attrs.loa_lma;
+       char *name = oti->oti_name;
+       struct dentry *dentry;
+       struct dentry *parent;
        struct ldiskfs_dir_entry_2 *de;
-       struct buffer_head         *bh;
-       int                        rc;
+       struct buffer_head *bh;
+       int rc;
 
        parent = omm->omm_remote_parent;
        sprintf(name, DFID_NOBRACE, PFID(lu_object_fid(&obj->oo_dt.do_lu)));
        dentry = osd_child_dentry_by_inode(env, parent->d_inode,
                                           name, strlen(name));
-       mutex_lock(&parent->d_inode->i_mutex);
+       inode_lock(parent->d_inode);
        bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
                                    NULL, NULL);
        if (IS_ERR(bh)) {
-               mutex_unlock(&parent->d_inode->i_mutex);
+               inode_unlock(parent->d_inode);
                rc = PTR_ERR(bh);
                if (unlikely(rc == -ENOENT))
                        rc = 0;
@@ -327,7 +405,7 @@ int osd_delete_from_remote_parent(const struct lu_env *env,
                if (!rc && S_ISDIR(obj->oo_inode->i_mode))
                        ldiskfs_dec_count(oh->ot_handle, parent->d_inode);
                mark_inode_dirty(parent->d_inode);
-               mutex_unlock(&parent->d_inode->i_mutex);
+               inode_unlock(parent->d_inode);
                brelse(bh);
                CDEBUG(D_INODE, "%s: remove agent entry for %s: rc = %d\n",
                       osd_name(osd), name, rc);
@@ -360,13 +438,14 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
                                const struct lu_fid *fid,
                                struct osd_inode_id *id)
 {
-       struct osd_mdobj_map        *omm = osd->od_mdt_map;
-       char                        *name = oti->oti_name;
-       struct dentry               *parent;
-       struct dentry               *dentry;
+       struct osd_mdobj_map *omm = osd->od_mdt_map;
+       char *name = oti->oti_name;
+       struct dentry *parent;
+       struct dentry *dentry;
        struct ldiskfs_dir_entry_2 *de;
-       struct buffer_head         *bh;
-       int                         rc;
+       struct buffer_head *bh;
+       int rc;
+
        ENTRY;
 
        if (unlikely(osd->od_is_ost))
@@ -376,7 +455,7 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
        sprintf(name, DFID_NOBRACE, PFID(fid));
        dentry = osd_child_dentry_by_inode(oti->oti_env, parent->d_inode,
                                           name, strlen(name));
-       mutex_lock(&parent->d_inode->i_mutex);
+       inode_lock(parent->d_inode);
        bh = osd_ldiskfs_find_entry(parent->d_inode, &dentry->d_name, &de,
                                    NULL, NULL);
        if (IS_ERR(bh)) {
@@ -396,7 +475,7 @@ int osd_lookup_in_remote_parent(struct osd_thread_info *oti,
                        rc = 0;
                }
        }
-       mutex_unlock(&parent->d_inode->i_mutex);
+       inode_unlock(parent->d_inode);
        if (rc == 0)
                osd_add_oi_cache(oti, osd, id, fid);
        RETURN(rc);
@@ -419,6 +498,7 @@ static int osd_ost_init(const struct lu_env *env, struct osd_device *dev)
        struct dentry *d;
        int rc;
        bool created = false;
+
        ENTRY;
 
        OBD_ALLOC_PTR(dev->od_ost_map);
@@ -465,10 +545,10 @@ static void osd_seq_free(struct osd_obj_seq *osd_seq)
                for (j = 0; j < osd_seq->oos_subdir_count; j++) {
                        if (osd_seq->oos_dirs[j])
                                dput(osd_seq->oos_dirs[j]);
-                }
+               }
                OBD_FREE(osd_seq->oos_dirs,
                         sizeof(struct dentry *) * osd_seq->oos_subdir_count);
-        }
+       }
 
        if (osd_seq->oos_root)
                dput(osd_seq->oos_root);
@@ -478,9 +558,10 @@ static void osd_seq_free(struct osd_obj_seq *osd_seq)
 
 static void osd_ost_fini(struct osd_device *osd)
 {
-       struct osd_obj_seq    *osd_seq;
-       struct osd_obj_seq    *tmp;
-       struct osd_obj_map    *map = osd->od_ost_map;
+       struct osd_obj_seq *osd_seq;
+       struct osd_obj_seq *tmp;
+       struct osd_obj_map *map = osd->od_ost_map;
+
        ENTRY;
 
        if (map == NULL)
@@ -510,6 +591,7 @@ static int osd_index_backup_dir_init(const struct lu_env *env,
        struct lvfs_run_ctxt save;
        struct dentry *dentry;
        int rc = 0;
+
        ENTRY;
 
        lu_local_obj_fid(fid, INDEX_BACKUP_OID);
@@ -539,6 +621,7 @@ int osd_obj_map_init(const struct lu_env *env, struct osd_device *dev)
 {
        int rc;
        bool mdt_init = false;
+
        ENTRY;
 
        rc = osd_ost_init(env, dev);
@@ -607,16 +690,17 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
                                const struct osd_inode_id *id,
                                handle_t *th)
 {
-       struct inode               *parent = dir->d_inode;
-       struct dentry              *child;
+       struct inode *parent = dir->d_inode;
+       struct dentry *child;
        struct ldiskfs_dir_entry_2 *de;
-       struct buffer_head         *bh;
-       struct inode               *inode;
-       struct dentry              *dentry = &info->oti_obj_dentry;
-       struct osd_inode_id        *oi_id  = &info->oti_id3;
-       struct lustre_mdt_attrs    *lma    = &info->oti_ost_attrs.loa_lma;
-       struct lu_fid              *oi_fid = &lma->lma_self_fid;
-       int                         rc;
+       struct buffer_head *bh;
+       struct inode *inode;
+       struct dentry *dentry = &info->oti_obj_dentry;
+       struct osd_inode_id *oi_id = &info->oti_id3;
+       struct lustre_mdt_attrs *lma = &info->oti_ost_attrs.loa_lma;
+       struct lu_fid *oi_fid = &lma->lma_self_fid;
+       int rc;
+
        ENTRY;
 
        LASSERT(th != NULL);
@@ -628,8 +712,8 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
        child->d_name.name = name;
        child->d_name.len = strlen(name);
 
-       ll_vfs_dq_init(parent);
-       mutex_lock(&parent->i_mutex);
+       dquot_initialize(parent);
+       inode_lock(parent);
        bh = osd_ldiskfs_find_entry(parent, &child->d_name, &de, NULL, NULL);
        if (IS_ERR(bh))
                GOTO(out, rc = PTR_ERR(bh));
@@ -646,8 +730,10 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
                GOTO(out, rc);
        }
 
-       /* The EA inode should NOT be in OI, old OI scrub may added
-        * such OI mapping by wrong, replace it. */
+       /*
+        * The EA inode should NOT be in OI, old OI scrub may added
+        * such OI mapping by wrong, replace it.
+        */
        if (unlikely(osd_is_ea_inode(inode))) {
                iput(inode);
                goto update;
@@ -666,8 +752,10 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
        if (rc != 0)
                GOTO(out, rc);
 
-       /* If the OST-object has neither FID-in-LMA nor FID-in-ff, it is
-        * either a crashed object or a uninitialized one. Replace it. */
+       /*
+        * If the OST-object has neither FID-in-LMA nor FID-in-ff, it is
+        * either a crashed object or a uninitialized one. Replace it.
+        */
        if (oi_fid != NULL && lu_fid_eq(fid, oi_fid)) {
                CERROR("%s: the FID "DFID" is used by two objects: "
                       "%u/%u %u/%u\n", osd_name(osd), PFID(fid),
@@ -716,14 +804,16 @@ static int osd_obj_update_entry(struct osd_thread_info *info,
        }
 
 update:
-       /* There may be temporary inconsistency: On one hand, the new
+       /*
+        * There may be temporary inconsistency: On one hand, the new
         * object may be referenced by multiple entries, which is out
         * of our control unless we traverse the whole /O completely,
         * which is non-flat order and inefficient, should be avoided;
         * On the other hand, the old object may become orphan if it
         * is still valid. Since it was referenced by an invalid entry,
         * making it as invisible temporary may be not worse. OI scrub
-        * will process it later. */
+        * will process it later.
+        */
        rc = ldiskfs_journal_get_write_access(th, bh);
        if (rc != 0)
                GOTO(out, rc);
@@ -736,7 +826,7 @@ update:
 out:
        if (!IS_ERR(bh))
                brelse(bh);
-       mutex_unlock(&parent->i_mutex);
+       inode_unlock(parent);
        return rc;
 }
 
@@ -746,16 +836,16 @@ static int osd_obj_del_entry(struct osd_thread_info *info,
                             handle_t *th)
 {
        struct ldiskfs_dir_entry_2 *de;
-       struct buffer_head         *bh;
-       struct dentry              *child;
-       struct inode               *dir = dird->d_inode;
-       int                         rc;
+       struct buffer_head *bh;
+       struct dentry *child;
+       struct inode *dir = dird->d_inode;
+       int rc;
+
        ENTRY;
 
        LASSERT(th != NULL);
        LASSERT(th->h_transaction != NULL);
 
-
        child = &info->oti_child_dentry;
        child->d_name.hash = 0;
        child->d_name.name = name;
@@ -763,8 +853,8 @@ static int osd_obj_del_entry(struct osd_thread_info *info,
        child->d_parent = dird;
        child->d_inode = NULL;
 
-       ll_vfs_dq_init(dir);
-       mutex_lock(&dir->i_mutex);
+       dquot_initialize(dir);
+       inode_lock(dir);
        bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
        if (IS_ERR(bh)) {
                rc = PTR_ERR(bh);
@@ -772,7 +862,7 @@ static int osd_obj_del_entry(struct osd_thread_info *info,
                rc = ldiskfs_delete_entry(th, dir, de, bh);
                brelse(bh);
        }
-       mutex_unlock(&dir->i_mutex);
+       inode_unlock(dir);
 
        RETURN(rc);
 }
@@ -798,6 +888,7 @@ static int osd_obj_add_entry(struct osd_thread_info *info,
        inode = info->oti_inode;
        if (unlikely(inode == NULL)) {
                struct ldiskfs_inode_info *lii;
+
                OBD_ALLOC_PTR(lii);
                if (lii == NULL)
                        RETURN(-ENOMEM);
@@ -818,10 +909,10 @@ static int osd_obj_add_entry(struct osd_thread_info *info,
        if (OBD_FAIL_CHECK(OBD_FAIL_OSD_COMPAT_INVALID_ENTRY))
                inode->i_ino++;
 
-       ll_vfs_dq_init(dir->d_inode);
-       mutex_lock(&dir->d_inode->i_mutex);
+       dquot_initialize(dir->d_inode);
+       inode_lock(dir->d_inode);
        rc = osd_ldiskfs_add_entry(info, osd, th, child, inode, NULL);
-       mutex_unlock(&dir->d_inode->i_mutex);
+       inode_unlock(dir->d_inode);
 
        RETURN(rc);
 }
@@ -855,11 +946,12 @@ static int osd_seq_load_locked(struct osd_thread_info *info,
                               struct osd_device *osd,
                               struct osd_obj_seq *osd_seq)
 {
-       struct osd_obj_map  *map = osd->od_ost_map;
-       struct dentry       *seq_dir;
-       int                 rc = 0;
-       int                 i;
-       char                dir_name[32];
+       struct osd_obj_map *map = osd->od_ost_map;
+       struct dentry *seq_dir;
+       int rc = 0;
+       int i;
+       char dir_name[32];
+
        ENTRY;
 
        if (osd_seq->oos_root != NULL)
@@ -921,9 +1013,10 @@ out_err:
 static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
                                        struct osd_device *osd, u64 seq)
 {
-       struct osd_obj_map      *map;
-       struct osd_obj_seq      *osd_seq;
-       int                     rc = 0;
+       struct osd_obj_map *map;
+       struct osd_obj_seq *osd_seq;
+       int rc = 0;
+
        ENTRY;
 
        map = osd->od_ost_map;
@@ -952,8 +1045,10 @@ static struct osd_obj_seq *osd_seq_load(struct osd_thread_info *info,
 
        INIT_LIST_HEAD(&osd_seq->oos_seq_list);
        osd_seq->oos_seq = seq;
-       /* Init subdir count to be 32, but each seq can have
-        * different subdir count */
+       /*
+        * Init subdir count to be 32, but each seq can have
+        * different subdir count
+        */
        osd_seq->oos_subdir_count = map->om_subdir_count;
        rc = osd_seq_load_locked(info, osd, osd_seq);
        if (rc != 0)
@@ -977,26 +1072,26 @@ cleanup:
 int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
                       const struct lu_fid *fid, struct osd_inode_id *id)
 {
-       struct osd_obj_map              *map;
-       struct osd_obj_seq              *osd_seq;
-       struct dentry                   *d_seq;
-       struct dentry                   *child;
-       struct ost_id                   *ostid = &info->oti_ostid;
-       int                             dirn;
-       char                            name[32];
-       struct ldiskfs_dir_entry_2      *de;
-       struct buffer_head              *bh;
-       struct inode                    *dir;
-       struct inode                    *inode;
-        ENTRY;
-
-        /* on the very first lookup we find and open directories */
-
-        map = dev->od_ost_map;
-        LASSERT(map);
+       struct osd_obj_map *map;
+       struct osd_obj_seq *osd_seq;
+       struct dentry *d_seq;
+       struct dentry *child;
+       struct ost_id *ostid = &info->oti_ostid;
+       int dirn;
+       char name[32];
+       struct ldiskfs_dir_entry_2 *de;
+       struct buffer_head *bh;
+       struct inode *dir;
+       struct inode *inode;
+
+       ENTRY;
+
+       /* on the very first lookup we find and open directories */
+       map = dev->od_ost_map;
+       LASSERT(map);
        LASSERT(map->om_root);
 
-        fid_to_ostid(fid, ostid);
+       fid_to_ostid(fid, ostid);
        osd_seq = osd_seq_load(info, dev, ostid_seq(ostid));
        if (IS_ERR(osd_seq))
                RETURN(PTR_ERR(osd_seq));
@@ -1015,9 +1110,9 @@ int osd_obj_map_lookup(struct osd_thread_info *info, struct osd_device *dev,
        child->d_name.len = strlen(name);
 
        dir = d_seq->d_inode;
-       mutex_lock(&dir->i_mutex);
+       inode_lock(dir);
        bh = osd_ldiskfs_find_entry(dir, &child->d_name, &de, NULL, NULL);
-       mutex_unlock(&dir->i_mutex);
+       inode_unlock(dir);
 
        if (IS_ERR(bh))
                RETURN(PTR_ERR(bh));
@@ -1042,13 +1137,14 @@ int osd_obj_map_insert(struct osd_thread_info *info,
                       const struct osd_inode_id *id,
                       handle_t *th)
 {
-       struct osd_obj_map      *map;
-       struct osd_obj_seq      *osd_seq;
-       struct dentry           *d;
-       struct ost_id           *ostid = &info->oti_ostid;
-       u64                      oid;
-       int                     dirn, rc = 0;
-       char                    name[32];
+       struct osd_obj_map *map;
+       struct osd_obj_seq *osd_seq;
+       struct dentry *d;
+       struct ost_id *ostid = &info->oti_ostid;
+       u64 oid;
+       int dirn, rc = 0;
+       char name[32];
+
        ENTRY;
 
        map = osd->od_ost_map;
@@ -1085,19 +1181,20 @@ again:
 int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
                       const struct lu_fid *fid, handle_t *th)
 {
-       struct osd_obj_map      *map;
-       struct osd_obj_seq      *osd_seq;
-       struct dentry           *d;
-       struct ost_id           *ostid = &info->oti_ostid;
-       int                     dirn, rc = 0;
-       char                    name[32];
-        ENTRY;
+       struct osd_obj_map *map;
+       struct osd_obj_seq *osd_seq;
+       struct dentry *d;
+       struct ost_id *ostid = &info->oti_ostid;
+       int dirn, rc = 0;
+       char name[32];
 
-        map = osd->od_ost_map;
-        LASSERT(map);
+       ENTRY;
+
+       map = osd->od_ost_map;
+       LASSERT(map);
 
        /* map fid to seq:objid */
-        fid_to_ostid(fid, ostid);
+       fid_to_ostid(fid, ostid);
 
        osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
        if (IS_ERR(osd_seq))
@@ -1110,7 +1207,7 @@ int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
        osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
        rc = osd_obj_del_entry(info, osd, d, name, th);
 cleanup:
-        RETURN(rc);
+       RETURN(rc);
 }
 
 int osd_obj_map_update(struct osd_thread_info *info,
@@ -1119,11 +1216,12 @@ int osd_obj_map_update(struct osd_thread_info *info,
                       const struct osd_inode_id *id,
                       handle_t *th)
 {
-       struct osd_obj_seq      *osd_seq;
-       struct dentry           *d;
-       struct ost_id           *ostid = &info->oti_ostid;
-       int                     dirn, rc = 0;
-       char                    name[32];
+       struct osd_obj_seq *osd_seq;
+       struct dentry *d;
+       struct ost_id *ostid = &info->oti_ostid;
+       int dirn, rc = 0;
+       char name[32];
+
        ENTRY;
 
        fid_to_ostid(fid, ostid);
@@ -1147,18 +1245,19 @@ int osd_obj_map_recover(struct osd_thread_info *info,
                        struct dentry *src_child,
                        const struct lu_fid *fid)
 {
-       struct osd_obj_seq         *osd_seq;
-       struct dentry              *tgt_parent;
-       struct dentry              *tgt_child = &info->oti_child_dentry;
-       struct inode               *dir;
-       struct inode               *inode     = src_child->d_inode;
-       struct ost_id              *ostid     = &info->oti_ostid;
-       handle_t                   *jh;
+       struct osd_obj_seq *osd_seq;
+       struct dentry *tgt_parent;
+       struct dentry *tgt_child = &info->oti_child_dentry;
+       struct inode *dir;
+       struct inode *inode = src_child->d_inode;
+       struct ost_id *ostid = &info->oti_ostid;
+       handle_t *jh;
        struct ldiskfs_dir_entry_2 *de;
-       struct buffer_head         *bh;
-       char                        name[32];
-       int                         dirn;
-       int                         rc        = 0;
+       struct buffer_head *bh;
+       char name[32];
+       int dirn;
+       int rc = 0;
+
        ENTRY;
 
        if (fid_is_last_id(fid)) {
@@ -1196,21 +1295,22 @@ int osd_obj_map_recover(struct osd_thread_info *info,
        if (IS_ERR(jh))
                RETURN(PTR_ERR(jh));
 
-       ll_vfs_dq_init(src_parent);
-       ll_vfs_dq_init(dir);
+       dquot_initialize(src_parent);
+       dquot_initialize(dir);
 
-       mutex_lock(&src_parent->i_mutex);
-       mutex_lock(&dir->i_mutex);
+       inode_lock(src_parent);
+       inode_lock(dir);
        bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL);
        if (!IS_ERR(bh)) {
-               /* XXX: If some other object occupied the same slot. And If such
-                *      inode is zero-sized and with SUID+SGID, then means it is
-                *      a new created one. Maybe we can remove it and insert the
-                *      original one back to the /O/<seq>/d<x>. But there are
-                *      something to be considered:
+               /*
+                * XXX: If some other object occupied the same slot. And If such
+                *      inode is zero-sized and with SUID+SGID, then means it is
+                *      a new created one. Maybe we can remove it and insert the
+                *      original one back to the /O/<seq>/d<x>. But there are
+                *      something to be considered:
                 *
-                *      1) The OST-object under /lost+found has crashed LMA.
-                *         So it should not conflict with the current one.
+                *      1) The OST-object under /lost+found has crashed LMA.
+                *         So it should not conflict with the current one.
                 *
                 *      2) There are race conditions that: someone may just want
                 *         to modify the current one. Even if the OI scrub takes
@@ -1219,10 +1319,11 @@ int osd_obj_map_recover(struct osd_thread_info *info,
                 *         has been removed when the RPC service thread waiting
                 *         for the lock.
                 *
-                *      So keep it there before we have suitable solution. */
+                *      So keep it there before we have suitable solution.
+                */
                brelse(bh);
-               mutex_unlock(&dir->i_mutex);
-               mutex_unlock(&src_parent->i_mutex);
+               inode_unlock(dir);
+               inode_unlock(src_parent);
                ldiskfs_journal_stop(jh);
 
                rc = -EEXIST;
@@ -1233,7 +1334,8 @@ int osd_obj_map_recover(struct osd_thread_info *info,
                        if (unlikely(rc == -ENOENT))
                                rc = 0;
                }
-               RETURN(rc);
+               if (rc)
+                       RETURN(rc);
        }
 
        bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, &de,
@@ -1251,8 +1353,8 @@ int osd_obj_map_recover(struct osd_thread_info *info,
        GOTO(unlock, rc);
 
 unlock:
-       mutex_unlock(&dir->i_mutex);
-       mutex_unlock(&src_parent->i_mutex);
+       inode_unlock(dir);
+       inode_unlock(src_parent);
        ldiskfs_journal_stop(jh);
        return rc;
 }
@@ -1288,9 +1390,10 @@ int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
                        handle_t *th)
 {
-       struct dentry   *root;
-       char            *name = NULL;
-       int              rc;
+       struct dentry *root;
+       char *name = NULL;
+       int rc;
+
        ENTRY;
 
        root = osd_object_spec_find(info, osd, fid, &name);
@@ -1309,9 +1412,10 @@ int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, const struct osd_inode_id *id,
                        handle_t *th)
 {
-       struct dentry   *root;
-       char            *name = NULL;
-       int              rc;
+       struct dentry *root;
+       char *name = NULL;
+       int rc;
+
        ENTRY;
 
        root = osd_object_spec_find(info, osd, fid, &name);
@@ -1329,11 +1433,12 @@ int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
 int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
                        const struct lu_fid *fid, struct osd_inode_id *id)
 {
-       struct dentry   *root;
-       struct dentry   *dentry;
-       struct inode    *inode;
-       char            *name = NULL;
-       int             rc = -ENOENT;
+       struct dentry *root;
+       struct dentry *dentry;
+       struct inode *inode;
+       char *name = NULL;
+       int rc = -ENOENT;
+
        ENTRY;
 
        if (fid_is_last_id(fid)) {
@@ -1351,7 +1456,7 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
                        RETURN(-ENOENT);
        }
 
-       dentry = ll_lookup_one_len(name, root, strlen(name));
+       dentry = osd_lookup_one_len_unlocked(osd, name, root, strlen(name));
        if (!IS_ERR(dentry)) {
                inode = dentry->d_inode;
                if (inode) {
@@ -1363,11 +1468,43 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
                                rc = 0;
                        }
                }
-               /* if dentry is accessible after osd_compat_spec_insert it
-                * will still contain NULL inode, so don't keep it in cache */
+               /*
+                * if dentry is accessible after osd_compat_spec_insert it
+                * will still contain NULL inode, so don't keep it in cache
+                */
                d_invalidate(dentry);
                dput(dentry);
        }
 
        RETURN(rc);
 }
+
+#ifndef HAVE_BIO_INTEGRITY_ENABLED
+bool bio_integrity_enabled(struct bio *bio)
+{
+       struct blk_integrity *bi = blk_get_integrity(bio_get_disk(bio));
+
+       if (bio_op(bio) != REQ_OP_READ && bio_op(bio) != REQ_OP_WRITE)
+               return false;
+
+       if (!bio_sectors(bio))
+               return false;
+
+        /* Already protected? */
+       if (bio_integrity(bio))
+               return false;
+
+       if (bi == NULL)
+               return false;
+
+       if (bio_data_dir(bio) == READ && bi->profile->verify_fn != NULL &&
+           (bi->flags & BLK_INTEGRITY_VERIFY))
+               return true;
+
+       if (bio_data_dir(bio) == WRITE && bi->profile->generate_fn != NULL &&
+           (bi->flags & BLK_INTEGRITY_GENERATE))
+               return true;
+
+       return false;
+}
+#endif