[PATCH 10/46] hostfs: simplify locking

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Nick Piggin
Date: Saturday, November 27, 2010 - 2:44 am

Remove dcache_lock locking from hostfs filesystem, and move it into dcache
helpers. All that should really be required is a coherent path name, protection
from concurrent modification is not provided outside path name generation
because dcache_lock is dropped before the path is used.

Signed-off-by: Nick Piggin <npiggin@kernel.dk>
---
 fs/dcache.c             |   15 +++++++++++++--
 fs/hostfs/hostfs_kern.c |   24 ++++++++++--------------
 include/linux/dcache.h  |    2 +-
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 9fd5180..4f9ccbe 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2140,7 +2140,7 @@ char *dynamic_dname(struct dentry *dentry, char *buffer, int buflen,
 /*
  * Write full pathname from the root of the filesystem into the buffer.
  */
-char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
+static char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
 {
 	char *end = buf + buflen;
 	char *retval;
@@ -2167,7 +2167,18 @@ char *__dentry_path(struct dentry *dentry, char *buf, int buflen)
 Elong:
 	return ERR_PTR(-ENAMETOOLONG);
 }
-EXPORT_SYMBOL(__dentry_path);
+
+char *dentry_path_raw(struct dentry *dentry, char *buf, int buflen)
+{
+	char *retval;
+
+	spin_lock(&dcache_lock);
+	retval = __dentry_path(dentry, buf, buflen);
+	spin_unlock(&dcache_lock);
+
+	return retval;
+}
+EXPORT_SYMBOL(dentry_path_raw);
 
 char *dentry_path(struct dentry *dentry, char *buf, int buflen)
 {
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index cfe8bc7..39dc505 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -92,12 +92,10 @@ __uml_setup("hostfs=", hostfs_args,
 
 static char *__dentry_name(struct dentry *dentry, char *name)
 {
-	char *p = __dentry_path(dentry, name, PATH_MAX);
+	char *p = dentry_path_raw(dentry, name, PATH_MAX);
 	char *root;
 	size_t len;
 
-	spin_unlock(&dcache_lock);
-
 	root = dentry->d_sb->s_fs_info;
 	len = strlen(root);
 	if (IS_ERR(p)) {
@@ -123,25 +121,23 @@ static char *dentry_name(struct dentry *dentry)
 	if (!name)
 		return NULL;
 
-	spin_lock(&dcache_lock);
 	return __dentry_name(dentry, name); /* will unlock */
 }
 
 static char *inode_name(struct inode *ino)
 {
 	struct dentry *dentry;
-	char *name = __getname();
-	if (!name)
-		return NULL;
+	char *name;
 
-	spin_lock(&dcache_lock);
-	if (list_empty(&ino->i_dentry)) {
-		spin_unlock(&dcache_lock);
-		__putname(name);
+	dentry = d_find_alias(ino);
+	if (!dentry)
 		return NULL;
-	}
-	dentry = list_first_entry(&ino->i_dentry, struct dentry, d_alias);
-	return __dentry_name(dentry, name); /* will unlock */
+
+	name = dentry_name(dentry);
+
+	dput(dentry);
+
+	return name;
 }
 
 static char *follow_link(char *link)
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 4ef2af7..6b5760b 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -309,7 +309,7 @@ extern char *dynamic_dname(struct dentry *, char *, int, const char *, ...);
 extern char *__d_path(const struct path *path, struct path *root, char *, int);
 extern char *d_path(const struct path *, char *, int);
 extern char *d_path_with_unreachable(const struct path *, char *, int);
-extern char *__dentry_path(struct dentry *, char *, int);
+extern char *dentry_path_raw(struct dentry *, char *, int);
 extern char *dentry_path(struct dentry *, char *, int);
 
 /* Allocation counts.. */
-- 
1.7.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 02/46] fs: d_validate fixes, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 08/46] fs: change d_compare for rcu-walk, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 09/46] fs: change d_hash for rcu-walk, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 10/46] hostfs: simplify locking, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 11/46] fs: dcache scale hash, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 15/46] fs: dcache scale subdirs, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 16/46] fs: scale inode alias list, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 23/46] fs: dcache reduce dcache_inode_lock, Nick Piggin, (Sat Nov 27, 2:44 am)
[PATCH 30/46] fs: icache RCU free inodes, Nick Piggin, (Sat Nov 27, 2:45 am)
[PATCH 35/46] fs: dcache remove d_mounted, Nick Piggin, (Sat Nov 27, 2:45 am)
[PATCH 45/46] fs: dcache per-inode inode alias locking, Nick Piggin, (Sat Nov 27, 2:45 am)
[PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Sat Nov 27, 3:15 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Anca Emanuel, (Sat Nov 27, 8:04 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Sat Nov 27, 8:28 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Sedat Dilek, (Sat Nov 27, 11:24 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, David Miller, (Wed Dec 1, 11:03 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Fri Dec 3, 9:55 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Tue Dec 7, 8:24 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Peter Zijlstra, (Tue Dec 7, 8:49 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Tue Dec 7, 8:59 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Peter Zijlstra, (Tue Dec 7, 9:23 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Dave Chinner, (Tue Dec 7, 2:56 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Tue Dec 7, 6:47 pm)
Re: [PATCH 02/46] fs: d_validate fixes, Dave Chinner, (Tue Dec 7, 6:53 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Tue Dec 7, 8:28 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Dave Chinner, (Tue Dec 7, 8:32 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Dave Chinner, (Tue Dec 7, 9:28 pm)
Re: [PATCH 02/46] fs: d_validate fixes, Nick Piggin, (Tue Dec 7, 11:59 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Nick Piggin, (Wed Dec 8, 12:09 am)
Re: [PATCH 02/46] fs: d_validate fixes, Dave Chinner, (Wed Dec 8, 5:50 pm)
Re: [PATCH 02/46] fs: d_validate fixes, Nick Piggin, (Wed Dec 8, 9:50 pm)
Re: [PATCH 11/46] fs: dcache scale hash, Dave Chinner, (Wed Dec 8, 11:09 pm)
Re: [PATCH 11/46] fs: dcache scale hash, Nick Piggin, (Wed Dec 8, 11:28 pm)
Re: [PATCH 11/46] fs: dcache scale hash, Dave Chinner, (Thu Dec 9, 1:17 am)
Re: [PATCH 11/46] fs: dcache scale hash, Nick Piggin, (Thu Dec 9, 5:53 am)
Re: [PATCH 11/46] fs: dcache scale hash, Dave Chinner, (Thu Dec 9, 4:42 pm)
Re: [PATCH 11/46] fs: dcache scale hash, Nick Piggin, (Thu Dec 9, 7:35 pm)
Re: [PATCH 11/46] fs: dcache scale hash, Dave Chinner, (Fri Dec 10, 2:01 am)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Paul E. McKenney, (Fri Dec 10, 1:32 pm)
Re: [PATCH 00/46] rcu-walk and dcache scaling, Paul E. McKenney, (Sun Dec 12, 7:54 am)
Re: [PATCH 11/46] fs: dcache scale hash, Nick Piggin, (Sun Dec 12, 9:48 pm)