diff mbox

[v2,1/2,Xenial,SRU] vfs: add lookup_hash() helper

Message ID 1485813986-58913-2-git-send-email-seth.forshee@canonical.com
State New
Headers show

Commit Message

Seth Forshee Jan. 30, 2017, 10:06 p.m. UTC
From: Miklos Szeredi <mszeredi@redhat.com>

BugLink: http://bugs.launchpad.net/bugs/1659417

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>
(backported from commit 3c9fe8cdff1b889a059a30d22f130372f2b3885f)
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
---
 fs/namei.c            | 26 ++++++++++++++++++++++++++
 include/linux/namei.h |  2 ++
 2 files changed, 28 insertions(+)
diff mbox

Patch

diff --git a/fs/namei.c b/fs/namei.c
index f251a018e79f..773df05712d5 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1537,6 +1537,32 @@  static struct dentry *__lookup_hash(struct qstr *name,
 	return lookup_real(base->d_inode, dentry, flags);
 }
 
+/**
+ * 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(struct qstr *name, struct dentry *base)
+{
+	struct dentry *dentry;
+
+	mutex_lock(&base->d_inode->i_mutex);
+	dentry = __lookup_hash(name, base, 0);
+	mutex_unlock(&base->d_inode->i_mutex);
+	return dentry;
+}
+EXPORT_SYMBOL(lookup_hash);
+
 /*
  *  It's more convoluted than I'd like it to be, but... it's still fairly
  *  small and for now I'd prefer to have fast path as straight as possible.
diff --git a/include/linux/namei.h b/include/linux/namei.h
index d8c6334cd150..0a6a1ab47b38 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -77,6 +77,8 @@  extern struct dentry *kern_path_locked(const char *, struct path *);
 extern int kern_path_mountpoint(int, const char *, struct path *, unsigned int);
 
 extern struct dentry *lookup_one_len(const char *, struct dentry *, int);
+struct qstr;
+extern struct dentry *lookup_hash(struct qstr *, struct dentry *);
 
 extern int follow_down_one(struct path *);
 extern int follow_down(struct path *);