Whamcloud - gitweb
LU-12137 osd-ldiskfs: migrate ll_lookup_one_len to osd_compat.c 54/35454/2
authorJames Simmons <uja.ornl@yahoo.com>
Wed, 10 Jul 2019 14:18:03 +0000 (10:18 -0400)
committerOleg Drokin <green@whamcloud.com>
Sat, 20 Jul 2019 18:39:10 +0000 (18:39 +0000)
The function ll_lookup_one_len() in lvfs.h is only used for the
osd-ldiskfs layer so relocate it to osd_compat.c and rename it
to osd_lookup_one_len_unlocked(). We use unlocked in the name
since this signifies it must always be called with the inode lock
not taken since it will take the inode lock itself.

Test-Parameters: trivial

Change-Id: I507100a676f98448f4cacc94e902294903a67efb
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/35454
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Neil Brown <neilb@suse.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/include/lvfs.h
lustre/osd-ldiskfs/osd_compat.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_oi.c

index 856ee19..3544b53 100644 (file)
@@ -71,32 +71,4 @@ static inline void OBD_SET_CTXT_MAGIC(struct lvfs_run_ctxt *ctxt)
 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx);
 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx);
 
 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx);
 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx);
 
-/* We need to hold the inode semaphore over the dcache lookup itself, or we
- * run the risk of entering the filesystem lookup path concurrently on SMP
- * systems, and instantiating two inodes for the same entry.  We still
- * protect against concurrent addition/removal races with the DLM locking.
- */
-static inline struct dentry *
-ll_lookup_one_len(const char *fid_name, struct dentry *dparent,
-                 int fid_namelen)
-{
-       struct dentry *dchild;
-
-       inode_lock(dparent->d_inode);
-       dchild = lookup_one_len(fid_name, dparent, fid_namelen);
-       inode_unlock(dparent->d_inode);
-
-       if (IS_ERR(dchild) || dchild->d_inode == NULL)
-               return dchild;
-
-       if (is_bad_inode(dchild->d_inode)) {
-               CERROR("bad inode returned %lu/%u\n",
-                      dchild->d_inode->i_ino, dchild->d_inode->i_generation);
-               dput(dchild);
-               dchild = ERR_PTR(-ENOENT);
-       }
-
-       return dchild;
-}
-
 #endif
 #endif
index ae42d2c..d6ebf56 100644 (file)
@@ -67,6 +67,40 @@ static void osd_push_ctxt(const struct osd_device *dev,
 }
 
 /**
 }
 
 /**
+ * osd_lookup_one_len_unlocked
+ *
+ * @name:      pathname component to lookup
+ * @base:      base directory to lookup from
+ * @len:       maximum length @len should be interpreted to
+ *
+ * This should be called without the parent
+ * i_mutex held, and will take the i_mutex itself.
+ *
+ * Unlike osd_lookup_one_len dentry with NULL d_inode is valid
+ */
+struct dentry *osd_lookup_one_len_unlocked(const char *name,
+                                          struct dentry *base, int len)
+{
+       struct dentry *dchild;
+
+       inode_lock(base->d_inode);
+       dchild = lookup_one_len(name, base, len);
+       inode_unlock(base->d_inode);
+
+       if (IS_ERR(dchild) || dchild->d_inode == NULL)
+               return dchild;
+
+       if (is_bad_inode(dchild->d_inode)) {
+               CERROR("bad inode returned %lu/%u\n",
+                      dchild->d_inode->i_ino, dchild->d_inode->i_generation);
+               dput(dchild);
+               dchild = ERR_PTR(-ENOENT);
+       }
+
+       return dchild;
+}
+
+/**
  * osd_ios_lookup_one_len - lookup single pathname component
  *
  * @name:      pathname component to lookup
  * osd_ios_lookup_one_len - lookup single pathname component
  *
  * @name:      pathname component to lookup
@@ -81,7 +115,7 @@ struct dentry *osd_ios_lookup_one_len(const char *name, struct dentry *base,
 {
        struct dentry *dentry;
 
 {
        struct dentry *dentry;
 
-       dentry = ll_lookup_one_len(name, base, len);
+       dentry = osd_lookup_one_len_unlocked(name, base, len);
        if (IS_ERR(dentry)) {
                int rc = PTR_ERR(dentry);
 
        if (IS_ERR(dentry)) {
                int rc = PTR_ERR(dentry);
 
@@ -118,7 +152,7 @@ simple_mkdir(const struct lu_env *env, struct osd_device *osd,
 
        // ASSERT_KERNEL_CTXT("kernel doing mkdir outside kernel context\n");
        CDEBUG(D_INODE, "creating directory %.*s\n", (int)strlen(name), name);
 
        // 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(name, dir, strlen(name));
        if (IS_ERR(dchild))
                RETURN(dchild);
 
        if (IS_ERR(dchild))
                RETURN(dchild);
 
@@ -198,8 +232,8 @@ static int osd_last_rcvd_subdir_count(struct osd_device *osd)
 
        ENTRY;
 
 
        ENTRY;
 
-       dlast = ll_lookup_one_len(LAST_RCVD, osd_sb(osd)->s_root,
-                                 strlen(LAST_RCVD));
+       dlast = osd_lookup_one_len_unlocked(LAST_RCVD, osd_sb(osd)->s_root,
+                                           strlen(LAST_RCVD));
        if (IS_ERR(dlast))
                return PTR_ERR(dlast);
        else if (dlast->d_inode == NULL)
        if (IS_ERR(dlast))
                return PTR_ERR(dlast);
        else if (dlast->d_inode == NULL)
@@ -1418,7 +1452,7 @@ int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
                        RETURN(-ENOENT);
        }
 
                        RETURN(-ENOENT);
        }
 
-       dentry = ll_lookup_one_len(name, root, strlen(name));
+       dentry = osd_lookup_one_len_unlocked(name, root, strlen(name));
        if (!IS_ERR(dentry)) {
                inode = dentry->d_inode;
                if (inode) {
        if (!IS_ERR(dentry)) {
                inode = dentry->d_inode;
                if (inode) {
index 323bc32..c2df8b1 100644 (file)
@@ -793,6 +793,8 @@ int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
                   struct osd_inode_id *id);
 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev);
 
                   struct osd_inode_id *id);
 void osd_scrub_dump(struct seq_file *m, struct osd_device *dev);
 
+struct dentry *osd_lookup_one_len_unlocked(const char *name,
+                                          struct dentry *base, int len);
 struct dentry *osd_ios_lookup_one_len(const char *name, struct dentry *base,
                                      int len);
 
 struct dentry *osd_ios_lookup_one_len(const char *name, struct dentry *base,
                                      int len);
 
index cd7e696..bb9cd1b 100644 (file)
@@ -161,7 +161,8 @@ static struct inode *osd_oi_index_open(struct osd_thread_info *info,
         struct inode  *inode;
         int            rc;
 
         struct inode  *inode;
         int            rc;
 
-        dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
+       dentry = osd_lookup_one_len_unlocked(name, osd_sb(osd)->s_root,
+                                            strlen(name));
         if (IS_ERR(dentry))
                 return (void *) dentry;
 
         if (IS_ERR(dentry))
                 return (void *) dentry;
 
@@ -183,7 +184,8 @@ static struct inode *osd_oi_index_open(struct osd_thread_info *info,
         if (rc)
                return ERR_PTR(rc);
 
         if (rc)
                return ERR_PTR(rc);
 
-        dentry = ll_lookup_one_len(name, osd_sb(osd)->s_root, strlen(name));
+       dentry = osd_lookup_one_len_unlocked(name, osd_sb(osd)->s_root,
+                                            strlen(name));
         if (IS_ERR(dentry))
                 return (void *) dentry;
 
         if (IS_ERR(dentry))
                 return (void *) dentry;
 
@@ -341,7 +343,7 @@ static int osd_remove_oi_one(struct dentry *parent, const char *name,
        struct dentry *child;
        int rc;
 
        struct dentry *child;
        int rc;
 
-       child = ll_lookup_one_len(name, parent, namelen);
+       child = osd_lookup_one_len_unlocked(name, parent, namelen);
        if (IS_ERR(child)) {
                rc = PTR_ERR(child);
        } else {
        if (IS_ERR(child)) {
                rc = PTR_ERR(child);
        } else {