Commit be94d117 authored by Mark Fasheh's avatar Mark Fasheh

ocfs2: Provide convenience function for ino lookup

A couple paths which needed to just match a parent dir + name pair to an
inode number were a bit messy because they had to deal with
ocfs2_find_files_on_disk() which returns a larger number of values. Provide
a convenience function, ocfs2_lookup_ino_from_name() which internalizes all
the extra accounting.
Signed-off-by: default avatarMark Fasheh <mark.fasheh@oracle.com>
Reviewed-by: default avatarJoel Becker <joel.becker@oracle.com>
parent 0bfbbf62
...@@ -628,6 +628,23 @@ int ocfs2_find_files_on_disk(const char *name, ...@@ -628,6 +628,23 @@ int ocfs2_find_files_on_disk(const char *name,
return status; return status;
} }
/*
* Convenience function for callers which just want the block number
* mapped to a name and don't require the full dirent info, etc.
*/
int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name,
int namelen, u64 *blkno)
{
int ret;
struct buffer_head *bh = NULL;
struct ocfs2_dir_entry *dirent = NULL;
ret = ocfs2_find_files_on_disk(name, namelen, blkno, dir, &bh, &dirent);
brelse(bh);
return ret;
}
/* Check for a name within a directory. /* Check for a name within a directory.
* *
* Return 0 if the name does not exist * Return 0 if the name does not exist
......
...@@ -61,6 +61,8 @@ int ocfs2_find_files_on_disk(const char *name, ...@@ -61,6 +61,8 @@ int ocfs2_find_files_on_disk(const char *name,
struct inode *inode, struct inode *inode,
struct buffer_head **dirent_bh, struct buffer_head **dirent_bh,
struct ocfs2_dir_entry **dirent); struct ocfs2_dir_entry **dirent);
int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name,
int namelen, u64 *blkno);
int ocfs2_readdir(struct file *filp, void *dirent, filldir_t filldir); int ocfs2_readdir(struct file *filp, void *dirent, filldir_t filldir);
int ocfs2_dir_foreach(struct inode *inode, loff_t *f_pos, void *priv, int ocfs2_dir_foreach(struct inode *inode, loff_t *f_pos, void *priv,
filldir_t filldir); filldir_t filldir);
......
...@@ -88,8 +88,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child) ...@@ -88,8 +88,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
struct dentry *parent; struct dentry *parent;
struct inode *inode; struct inode *inode;
struct inode *dir = child->d_inode; struct inode *dir = child->d_inode;
struct buffer_head *dirent_bh = NULL;
struct ocfs2_dir_entry *dirent;
mlog_entry("(0x%p, '%.*s')\n", child, mlog_entry("(0x%p, '%.*s')\n", child,
child->d_name.len, child->d_name.name); child->d_name.len, child->d_name.name);
...@@ -105,8 +103,7 @@ static struct dentry *ocfs2_get_parent(struct dentry *child) ...@@ -105,8 +103,7 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
goto bail; goto bail;
} }
status = ocfs2_find_files_on_disk("..", 2, &blkno, dir, &dirent_bh, status = ocfs2_lookup_ino_from_name(dir, "..", 2, &blkno);
&dirent);
if (status < 0) { if (status < 0) {
parent = ERR_PTR(-ENOENT); parent = ERR_PTR(-ENOENT);
goto bail_unlock; goto bail_unlock;
...@@ -131,9 +128,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child) ...@@ -131,9 +128,6 @@ static struct dentry *ocfs2_get_parent(struct dentry *child)
bail_unlock: bail_unlock:
ocfs2_meta_unlock(dir, 0); ocfs2_meta_unlock(dir, 0);
if (dirent_bh)
brelse(dirent_bh);
bail: bail:
mlog_exit_ptr(parent); mlog_exit_ptr(parent);
......
...@@ -101,10 +101,8 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry, ...@@ -101,10 +101,8 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
{ {
int status; int status;
u64 blkno; u64 blkno;
struct buffer_head *dirent_bh = NULL;
struct inode *inode = NULL; struct inode *inode = NULL;
struct dentry *ret; struct dentry *ret;
struct ocfs2_dir_entry *dirent;
struct ocfs2_inode_info *oi; struct ocfs2_inode_info *oi;
mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry, mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,
...@@ -126,9 +124,8 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry, ...@@ -126,9 +124,8 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
goto bail; goto bail;
} }
status = ocfs2_find_files_on_disk(dentry->d_name.name, status = ocfs2_lookup_ino_from_name(dir, dentry->d_name.name,
dentry->d_name.len, &blkno, dentry->d_name.len, &blkno);
dir, &dirent_bh, &dirent);
if (status < 0) if (status < 0)
goto bail_add; goto bail_add;
...@@ -183,8 +180,6 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry, ...@@ -183,8 +180,6 @@ static struct dentry *ocfs2_lookup(struct inode *dir, struct dentry *dentry,
ocfs2_meta_unlock(dir, 0); ocfs2_meta_unlock(dir, 0);
bail: bail:
if (dirent_bh)
brelse(dirent_bh);
mlog_exit_ptr(ret); mlog_exit_ptr(ret);
......
...@@ -100,17 +100,14 @@ static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb, ...@@ -100,17 +100,14 @@ static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb,
char namebuf[40]; char namebuf[40];
struct inode *inode = NULL; struct inode *inode = NULL;
u64 blkno; u64 blkno;
struct buffer_head *dirent_bh = NULL;
struct ocfs2_dir_entry *de = NULL;
int status = 0; int status = 0;
ocfs2_sprintf_system_inode_name(namebuf, ocfs2_sprintf_system_inode_name(namebuf,
sizeof(namebuf), sizeof(namebuf),
type, slot); type, slot);
status = ocfs2_find_files_on_disk(namebuf, strlen(namebuf), status = ocfs2_lookup_ino_from_name(osb->sys_root_inode, namebuf,
&blkno, osb->sys_root_inode, strlen(namebuf), &blkno);
&dirent_bh, &de);
if (status < 0) { if (status < 0) {
goto bail; goto bail;
} }
...@@ -122,8 +119,7 @@ static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb, ...@@ -122,8 +119,7 @@ static struct inode * _ocfs2_get_system_file_inode(struct ocfs2_super *osb,
goto bail; goto bail;
} }
bail: bail:
if (dirent_bh)
brelse(dirent_bh);
return inode; return inode;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment