Commit cd67725a authored by Jan Blunck's avatar Jan Blunck Committed by Linus Torvalds

[PATCH] d_drop should use per dentry lock

d_drop() must use the dentry->d_lock spinlock.  In some cases __d_drop()
was used without holding the dentry->d_lock spinlock, too.  This could end
in a race with __d_lookup().
Signed-off-by: default avatarJan Blunck <j.blunck@tu-harburg.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 02721572
...@@ -605,7 +605,9 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -605,7 +605,9 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
return -ENOTEMPTY; return -ENOTEMPTY;
} }
spin_lock(&dentry->d_lock);
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
dput(ino->dentry); dput(ino->dentry);
......
...@@ -340,13 +340,16 @@ void d_prune_aliases(struct inode *inode) ...@@ -340,13 +340,16 @@ void d_prune_aliases(struct inode *inode)
tmp = head; tmp = head;
while ((tmp = tmp->next) != head) { while ((tmp = tmp->next) != head) {
struct dentry *dentry = list_entry(tmp, struct dentry, d_alias); struct dentry *dentry = list_entry(tmp, struct dentry, d_alias);
spin_lock(&dentry->d_lock);
if (!atomic_read(&dentry->d_count)) { if (!atomic_read(&dentry->d_count)) {
__dget_locked(dentry); __dget_locked(dentry);
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
dput(dentry); dput(dentry);
goto restart; goto restart;
} }
spin_unlock(&dentry->d_lock);
} }
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
} }
......
...@@ -1685,17 +1685,13 @@ asmlinkage long sys_mkdir(const char __user * pathname, int mode) ...@@ -1685,17 +1685,13 @@ asmlinkage long sys_mkdir(const char __user * pathname, int mode)
void dentry_unhash(struct dentry *dentry) void dentry_unhash(struct dentry *dentry)
{ {
dget(dentry); dget(dentry);
spin_lock(&dcache_lock); if (atomic_read(&dentry->d_count))
switch (atomic_read(&dentry->d_count)) {
default:
spin_unlock(&dcache_lock);
shrink_dcache_parent(dentry); shrink_dcache_parent(dentry);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
if (atomic_read(&dentry->d_count) != 2) spin_lock(&dentry->d_lock);
break; if (atomic_read(&dentry->d_count) == 2)
case 2:
__d_drop(dentry); __d_drop(dentry);
} spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
} }
......
...@@ -1630,11 +1630,15 @@ struct dentry *proc_pid_unhash(struct task_struct *p) ...@@ -1630,11 +1630,15 @@ struct dentry *proc_pid_unhash(struct task_struct *p)
if (proc_dentry != NULL) { if (proc_dentry != NULL) {
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
spin_lock(&proc_dentry->d_lock);
if (!d_unhashed(proc_dentry)) { if (!d_unhashed(proc_dentry)) {
dget_locked(proc_dentry); dget_locked(proc_dentry);
__d_drop(proc_dentry); __d_drop(proc_dentry);
} else spin_unlock(&proc_dentry->d_lock);
} else {
spin_unlock(&proc_dentry->d_lock);
proc_dentry = NULL; proc_dentry = NULL;
}
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
} }
return proc_dentry; return proc_dentry;
......
...@@ -129,13 +129,17 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent) ...@@ -129,13 +129,17 @@ void sysfs_drop_dentry(struct sysfs_dirent * sd, struct dentry * parent)
if (dentry) { if (dentry) {
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
spin_lock(&dentry->d_lock);
if (!(d_unhashed(dentry) && dentry->d_inode)) { if (!(d_unhashed(dentry) && dentry->d_inode)) {
dget_locked(dentry); dget_locked(dentry);
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
simple_unlink(parent->d_inode, dentry); simple_unlink(parent->d_inode, dentry);
} else } else {
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
}
} }
} }
......
...@@ -162,17 +162,16 @@ extern spinlock_t dcache_lock; ...@@ -162,17 +162,16 @@ extern spinlock_t dcache_lock;
* d_drop - drop a dentry * d_drop - drop a dentry
* @dentry: dentry to drop * @dentry: dentry to drop
* *
* d_drop() unhashes the entry from the parent * d_drop() unhashes the entry from the parent dentry hashes, so that it won't
* dentry hashes, so that it won't be found through * be found through a VFS lookup any more. Note that this is different from
* a VFS lookup any more. Note that this is different * deleting the dentry - d_delete will try to mark the dentry negative if
* from deleting the dentry - d_delete will try to * possible, giving a successful _negative_ lookup, while d_drop will
* mark the dentry negative if possible, giving a
* successful _negative_ lookup, while d_drop will
* just make the cache lookup fail. * just make the cache lookup fail.
* *
* d_drop() is used mainly for stuff that wants * d_drop() is used mainly for stuff that wants to invalidate a dentry for some
* to invalidate a dentry for some reason (NFS * reason (NFS timeouts or autofs deletes).
* timeouts or autofs deletes). *
* __d_drop requires dentry->d_lock.
*/ */
static inline void __d_drop(struct dentry *dentry) static inline void __d_drop(struct dentry *dentry)
...@@ -186,7 +185,9 @@ static inline void __d_drop(struct dentry *dentry) ...@@ -186,7 +185,9 @@ static inline void __d_drop(struct dentry *dentry)
static inline void d_drop(struct dentry *dentry) static inline void d_drop(struct dentry *dentry)
{ {
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
spin_lock(&dentry->d_lock);
__d_drop(dentry); __d_drop(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&dcache_lock); spin_unlock(&dcache_lock);
} }
......
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