Whamcloud - gitweb
LU-2075 fld: use predefined FIDs
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_compat.c
index 22e4ff8..a0ff99e 100644 (file)
@@ -55,6 +55,7 @@
 #include <lvfs.h>
 
 #include "osd_internal.h"
+#include "osd_oi.h"
 
 struct osd_compat_objid_seq {
         /* protects on-fly initialization */
@@ -203,13 +204,11 @@ int osd_last_rcvd_subdir_count(struct osd_device *osd)
                        rc = -EFAULT;
                dput(dlast);
                return rc;
-       } else {
-               count = FILTER_SUBDIR_COUNT;
        }
 out:
        dput(dlast);
        LASSERT(count > 0);
-       return rc;
+       return count;
 }
 
 void osd_compat_fini(struct osd_device *dev)
@@ -315,16 +314,16 @@ int osd_compat_del_entry(struct osd_thread_info *info, struct osd_device *osd,
         child->d_parent = dird;
         child->d_inode = NULL;
 
-        LOCK_INODE_MUTEX(dir);
-        rc = -ENOENT;
-        bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
-        if (bh) {
-                rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
-                brelse(bh);
-        }
-        UNLOCK_INODE_MUTEX(dir);
+       mutex_lock(&dir->i_mutex);
+       rc = -ENOENT;
+       bh = osd_ldiskfs_find_entry(dir, child, &de, NULL);
+       if (bh) {
+               rc = ldiskfs_delete_entry(oh->ot_handle, dir, de, bh);
+               brelse(bh);
+       }
+       mutex_unlock(&dir->i_mutex);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 int osd_compat_add_entry(struct osd_thread_info *info, struct osd_device *osd,
@@ -344,8 +343,7 @@ int osd_compat_add_entry(struct osd_thread_info *info, struct osd_device *osd,
 
         inode = &info->oti_inode;
         inode->i_sb = osd_sb(osd);
-        inode->i_ino = id->oii_ino;
-        inode->i_generation = id->oii_gen;
+       osd_id_to_inode(inode, id);
 
         child = &info->oti_child_dentry;
         child->d_name.hash = 0;
@@ -354,11 +352,11 @@ int osd_compat_add_entry(struct osd_thread_info *info, struct osd_device *osd,
         child->d_parent = dir;
         child->d_inode = inode;
 
-        LOCK_INODE_MUTEX(dir->d_inode);
-        rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL);
-        UNLOCK_INODE_MUTEX(dir->d_inode);
+       mutex_lock(&dir->d_inode->i_mutex);
+       rc = osd_ldiskfs_add_entry(oh->ot_handle, child, inode, NULL);
+       mutex_unlock(&dir->d_inode->i_mutex);
 
-        RETURN(rc);
+       RETURN(rc);
 }
 
 int osd_compat_objid_lookup(struct osd_thread_info *info,
@@ -369,12 +367,12 @@ int osd_compat_objid_lookup(struct osd_thread_info *info,
         struct dentry              *d;
         struct dentry              *d_seq;
         struct ost_id              *ostid = &info->oti_ostid;
-        int                         rc = 0;
         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 */
@@ -400,30 +398,23 @@ int osd_compat_objid_lookup(struct osd_thread_info *info,
         /* XXX: we can use rc from sprintf() instead of strlen() */
         d_seq->d_name.len = strlen(name);
 
-        dir = d->d_inode;
-        LOCK_INODE_MUTEX(dir);
-        bh = osd_ldiskfs_find_entry(dir, d_seq, &de, NULL);
-        UNLOCK_INODE_MUTEX(dir);
+       dir = d->d_inode;
+       mutex_lock(&dir->i_mutex);
+       bh = osd_ldiskfs_find_entry(dir, d_seq, &de, NULL);
+       mutex_unlock(&dir->i_mutex);
 
-        rc = -ENOENT;
-        if (bh) {
-                struct inode *inode;
+       if (bh == NULL)
+               RETURN(-ENOENT);
 
-                id->oii_ino = le32_to_cpu(de->inode);
-                brelse(bh);
+       osd_id_gen(id, le32_to_cpu(de->inode), OSD_OII_NOGEN);
+       brelse(bh);
 
-                id->oii_gen = OSD_OII_NOGEN;
-                inode = osd_iget(info, dev, id);
+       inode = osd_iget(info, dev, id);
+       if (IS_ERR(inode))
+               RETURN(PTR_ERR(inode));
 
-                if (IS_ERR(inode))
-                        GOTO(cleanup, rc = PTR_ERR(inode));
-                rc = 0;
-                id->oii_gen = inode->i_generation;
-                iput(inode);
-        }
-
-cleanup:
-        RETURN(rc);
+       iput(inode);
+       RETURN(0);
 }
 
 int osd_compat_objid_insert(struct osd_thread_info *info,
@@ -492,20 +483,22 @@ struct named_oid {
 };
 
 static const struct named_oid oids[] = {
-        { FLD_INDEX_OID,        "" /* "fld" */ },
-        { FID_SEQ_CTL_OID,      "" /* "seq_ctl" */ },
-        { FID_SEQ_SRV_OID,      "" /* "seq_srv" */ },
-        { MDD_ROOT_INDEX_OID,   "" /* "ROOT" */ },
-        { MDD_ORPHAN_OID,       "" /* "PENDING" */ },
-        { MDD_LOV_OBJ_OID,      "" /* LOV_OBJID */ },
-        { MDD_CAPA_KEYS_OID,    "" /* CAPA_KEYS */ },
+       { FLD_INDEX_OID,        "fld" },
+       { FID_SEQ_CTL_OID,      "seq_ctl" },
+       { FID_SEQ_SRV_OID,      "seq_srv" },
+       { MDD_ROOT_INDEX_OID,   "" /* "ROOT" */ },
+       { MDD_ORPHAN_OID,       "" /* "PENDING" */ },
+       { MDD_LOV_OBJ_OID,      LOV_OBJID },
+       { MDD_CAPA_KEYS_OID,    "" /* CAPA_KEYS */ },
        { MDT_LAST_RECV_OID,    LAST_RCVD },
-        { OFD_LAST_RECV_OID,    "" /* LAST_RCVD */ },
-        { OFD_LAST_GROUP_OID,   "" /* "LAST_GROUP" */ },
-        { LLOG_CATALOGS_OID,    "" /* "CATALOGS" */ },
-        { MGS_CONFIGS_OID,      "" /* MOUNT_CONFIGS_DIR */ },
-        { OFD_HEALTH_CHECK_OID, "" /* HEALTH_CHECK */ },
-        { 0,                    NULL }
+       { LFSCK_BOOKMARK_OID,   "" /* "lfsck_bookmark" */ },
+       { OTABLE_IT_OID,        "" /* "otable iterator" */},
+       { OFD_LAST_RECV_OID,    "" /* LAST_RCVD */ },
+       { OFD_LAST_GROUP_OID,   "LAST_GROUP" },
+       { LLOG_CATALOGS_OID,    "CATALOGS" },
+       { MGS_CONFIGS_OID,      "" /* MOUNT_CONFIGS_DIR */ },
+       { OFD_HEALTH_CHECK_OID, HEALTH_CHECK },
+       { 0,                    NULL }
 };
 
 static char *oid2name(const unsigned long oid)
@@ -551,33 +544,33 @@ int osd_compat_spec_insert(struct osd_thread_info *info,
 }
 
 int osd_compat_spec_lookup(struct osd_thread_info *info,
-                           struct osd_device *osd, const struct lu_fid *fid,
-                           struct osd_inode_id *id)
+                          struct osd_device *osd, const struct lu_fid *fid,
+                          struct osd_inode_id *id)
 {
-        struct dentry *dentry;
-        char          *name;
-        int            rc = -ERESTART;
-
-        ENTRY;
+       struct dentry *dentry;
+       struct inode  *inode;
+       char          *name;
+       int            rc = -ENOENT;
+       ENTRY;
 
-        name = oid2name(fid_oid(fid));
-        if (name == NULL || strlen(name) == 0)
-                return -ERESTART;
-
-        dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
-        if (!IS_ERR(dentry)) {
-                if (dentry->d_inode) {
-                        if (is_bad_inode(dentry->d_inode)) {
-                                rc = -EIO;
-                        } else {
-                                id->oii_ino = dentry->d_inode->i_ino;
-                                id->oii_gen = dentry->d_inode->i_generation;
-                                rc = 0;
-                        }
-                }
-                dput(dentry);
-        }
+       name = oid2name(fid_oid(fid));
+       if (name == NULL || strlen(name) == 0)
+               RETURN(-ENOENT);
+
+       dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
+       if (!IS_ERR(dentry)) {
+               inode = dentry->d_inode;
+               if (inode) {
+                       if (is_bad_inode(inode)) {
+                               rc = -EIO;
+                       } else {
+                               osd_id_gen(id, inode->i_ino,
+                                          inode->i_generation);
+                               rc = 0;
+                       }
+               }
+               dput(dentry);
+       }
 
-        RETURN(rc);
+       RETURN(rc);
 }
-