From: James Simmons Date: Wed, 10 Jul 2019 14:18:03 +0000 (-0400) Subject: LU-12137 osd-ldiskfs: migrate ll_lookup_one_len to osd_compat.c X-Git-Tag: 2.12.57~122 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=49f51ae420912b0259f9b9648cff32534fe11b50 LU-12137 osd-ldiskfs: migrate ll_lookup_one_len to osd_compat.c 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 Reviewed-on: https://review.whamcloud.com/35454 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: Alex Zhuravlev Reviewed-by: Andreas Dilger --- diff --git a/lustre/include/lvfs.h b/lustre/include/lvfs.h index 856ee19..3544b53 100644 --- a/lustre/include/lvfs.h +++ b/lustre/include/lvfs.h @@ -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); -/* 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 diff --git a/lustre/osd-ldiskfs/osd_compat.c b/lustre/osd-ldiskfs/osd_compat.c index ae42d2c..d6ebf56 100644 --- a/lustre/osd-ldiskfs/osd_compat.c +++ b/lustre/osd-ldiskfs/osd_compat.c @@ -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 @@ -81,7 +115,7 @@ struct dentry *osd_ios_lookup_one_len(const char *name, struct dentry *base, { 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); @@ -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); - 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); @@ -198,8 +232,8 @@ static int osd_last_rcvd_subdir_count(struct osd_device *osd) 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) @@ -1418,7 +1452,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(name, root, strlen(name)); if (!IS_ERR(dentry)) { inode = dentry->d_inode; if (inode) { diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 323bc32..c2df8b1 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -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 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); diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index cd7e696..bb9cd1b 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -161,7 +161,8 @@ static struct inode *osd_oi_index_open(struct osd_thread_info *info, 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; @@ -183,7 +184,8 @@ static struct inode *osd_oi_index_open(struct osd_thread_info *info, 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; @@ -341,7 +343,7 @@ static int osd_remove_oi_one(struct dentry *parent, const char *name, 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 {