Skip to content

Commit

Permalink
vfs: add lookup_hash() helper
Browse files Browse the repository at this point in the history
Overlayfs needs lookup without inode_permission() and already has the name
hash (in form of dentry->d_name on overlayfs dentry).  It also doesn't
support filesystems with d_op->d_hash() so basically it only needs
the actual hashed lookup from lookup_one_len_unlocked()

So add a new helper that does unlocked lookup of a hashed name.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Miklos Szeredi authored and Al Viro committed May 11, 2016
1 parent 9409e22 commit 3c9fe8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 28 additions & 5 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,33 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
}
EXPORT_SYMBOL(vfs_path_lookup);

/**
* lookup_hash - lookup single pathname component on already hashed name
* @name: name and hash to lookup
* @base: base directory to lookup from
*
* The name must have been verified and hashed (see lookup_one_len()). Using
* this after just full_name_hash() is unsafe.
*
* This function also doesn't check for search permission on base directory.
*
* Use lookup_one_len_unlocked() instead, unless you really know what you are
* doing.
*
* Do not hold i_mutex; this helper takes i_mutex if necessary.
*/
struct dentry *lookup_hash(const struct qstr *name, struct dentry *base)
{
struct dentry *ret;

ret = lookup_dcache(name, base, 0);
if (!ret)
ret = lookup_slow(name, base, 0);

return ret;
}
EXPORT_SYMBOL(lookup_hash);

/**
* lookup_one_len - filesystem helper to lookup single pathname component
* @name: pathname component to lookup
Expand Down Expand Up @@ -2337,7 +2364,6 @@ struct dentry *lookup_one_len_unlocked(const char *name,
struct qstr this;
unsigned int c;
int err;
struct dentry *ret;

this.name = name;
this.len = len;
Expand Down Expand Up @@ -2369,10 +2395,7 @@ struct dentry *lookup_one_len_unlocked(const char *name,
if (err)
return ERR_PTR(err);

ret = lookup_dcache(&this, base, 0);
if (!ret)
ret = lookup_slow(&this, base, 0);
return ret;
return lookup_hash(&this, base);
}
EXPORT_SYMBOL(lookup_one_len_unlocked);

Expand Down
2 changes: 2 additions & 0 deletions include/linux/namei.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ extern int kern_path_mountpoint(int, const char *, struct path *, unsigned int);

extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
extern struct dentry *lookup_one_len_unlocked(const char *, struct dentry *, int);
struct qstr;
extern struct dentry *lookup_hash(const struct qstr *, struct dentry *);

extern int follow_down_one(struct path *);
extern int follow_down(struct path *);
Expand Down

0 comments on commit 3c9fe8c

Please sign in to comment.