Commit 3a708694 authored by Maneesh Soni's avatar Maneesh Soni Committed by Linus Torvalds

[PATCH] dcache usage cleanups

This cleans up the dcache code to always use the proper dcache functions
(d_unhashed and __d_drop) instead of accessing the dentry lists
directly.

In other words: use "d_unhashed(dentry)" instead of doing a manual
"list_empty(&dentry->d_hash)" test.  And use "__d_drop(dentry)" instead
of doing "list_del_init(&dentry->d_hash)" by hand.

This will help the dcache-rcu patches.
parent 1cef7264
......@@ -255,7 +255,7 @@ static void d_unhash(struct dentry *dentry)
if (atomic_read(&dentry->d_count) != 2)
break;
case 2:
list_del_init(&dentry->d_hash);
__d_drop(dentry);
}
spin_unlock(&dcache_lock);
}
......
......@@ -418,7 +418,7 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
unlock_kernel();
return -ENOTEMPTY;
}
list_del_init(&dentry->d_hash);
__d_drop(dentry);
spin_unlock(&dcache_lock);
dput(ino->dentry);
......
......@@ -137,7 +137,7 @@ void dput(struct dentry *dentry)
goto unhash_it;
}
/* Unreachable? Get rid of it */
if (list_empty(&dentry->d_hash))
if (d_unhashed(dentry))
goto kill_it;
list_add(&dentry->d_lru, &dentry_unused);
dentry_stat.nr_unused++;
......@@ -146,7 +146,7 @@ void dput(struct dentry *dentry)
return;
unhash_it:
list_del_init(&dentry->d_hash);
__d_drop(dentry);
kill_it: {
struct dentry *parent;
......@@ -181,7 +181,7 @@ int d_invalidate(struct dentry * dentry)
* If it's already been dropped, return OK.
*/
spin_lock(&dcache_lock);
if (list_empty(&dentry->d_hash)) {
if (d_unhashed(dentry)) {
spin_unlock(&dcache_lock);
return 0;
}
......@@ -212,7 +212,7 @@ int d_invalidate(struct dentry * dentry)
}
}
list_del_init(&dentry->d_hash);
__d_drop(dentry);
spin_unlock(&dcache_lock);
return 0;
}
......@@ -259,7 +259,7 @@ struct dentry * d_find_alias(struct inode *inode)
tmp = next;
next = tmp->next;
alias = list_entry(tmp, struct dentry, d_alias);
if (!list_empty(&alias->d_hash)) {
if (!d_unhashed(alias)) {
if (alias->d_flags & DCACHE_DISCONNECTED)
discon_alias = alias;
else {
......@@ -308,7 +308,7 @@ static inline void prune_one_dentry(struct dentry * dentry)
{
struct dentry * parent;
list_del_init(&dentry->d_hash);
__d_drop(dentry);
list_del(&dentry->d_child);
dentry_stat.nr_dentry--; /* For d_free, below */
dentry_iput(dentry);
......@@ -997,7 +997,7 @@ void d_delete(struct dentry * dentry)
void d_rehash(struct dentry * entry)
{
struct list_head *list = d_hash(entry->d_parent, entry->d_name.hash);
if (!list_empty(&entry->d_hash)) BUG();
if (!d_unhashed(entry)) BUG();
spin_lock(&dcache_lock);
list_add(&entry->d_hash, list);
spin_unlock(&dcache_lock);
......@@ -1065,11 +1065,10 @@ void d_move(struct dentry * dentry, struct dentry * target)
spin_lock(&dcache_lock);
/* Move the dentry to the target hash queue */
list_del(&dentry->d_hash);
list_add(&dentry->d_hash, &target->d_hash);
list_move(&dentry->d_hash, &target->d_hash);
/* Unhash the target: dput() will then get rid of it */
list_del_init(&target->d_hash);
__d_drop(target);
list_del(&dentry->d_child);
list_del(&target->d_child);
......@@ -1121,7 +1120,7 @@ static char * __d_path( struct dentry *dentry, struct vfsmount *vfsmnt,
*--end = '\0';
buflen--;
if (!IS_ROOT(dentry) && list_empty(&dentry->d_hash)) {
if (!IS_ROOT(dentry) && d_unhashed(dentry)) {
buflen -= 10;
end -= 10;
memcpy(end, " (deleted)", 10);
......@@ -1223,7 +1222,7 @@ asmlinkage long sys_getcwd(char *buf, unsigned long size)
error = -ENOENT;
/* Has the current directory has been unlinked? */
spin_lock(&dcache_lock);
if (pwd->d_parent == pwd || !list_empty(&pwd->d_hash)) {
if (pwd->d_parent == pwd || !d_unhashed(pwd)) {
unsigned long len;
char * cwd;
......
......@@ -524,9 +524,9 @@ static struct dentry *clean_proc_dentry(struct task_struct *p)
if (proc_dentry) {
spin_lock(&dcache_lock);
if (!list_empty(&proc_dentry->d_hash)) {
if (!d_unhashed(proc_dentry)) {
dget_locked(proc_dentry);
list_del_init(&proc_dentry->d_hash);
__d_drop(proc_dentry);
} else
proc_dentry = NULL;
spin_unlock(&dcache_lock);
......
......@@ -261,7 +261,7 @@ char * presto_path(struct dentry *dentry, struct dentry *root,
*--end = '\0';
buflen--;
if (dentry->d_parent != dentry && list_empty(&dentry->d_hash)) {
if (dentry->d_parent != dentry && d_unhashed(dentry)) {
buflen -= 10;
end -= 10;
memcpy(end, " (deleted)", 10);
......@@ -1518,7 +1518,7 @@ int presto_journal_setattr(struct rec_info *rec, struct presto_file_set *fset,
}
if (!dentry->d_inode || (dentry->d_inode->i_nlink == 0)
|| ((dentry->d_parent != dentry) && list_empty(&dentry->d_hash))) {
|| ((dentry->d_parent != dentry) && d_unhashed(dentry))) {
EXIT;
return 0;
}
......@@ -2129,7 +2129,7 @@ presto_journal_close(struct rec_info *rec, struct presto_file_set *fset,
}
if (!dentry->d_inode || (dentry->d_inode->i_nlink == 0)
|| ((dentry->d_parent != dentry) && list_empty(&dentry->d_hash))) {
|| ((dentry->d_parent != dentry) && d_unhashed(dentry))) {
EXIT;
return 0;
}
......@@ -2391,7 +2391,7 @@ int presto_journal_set_ext_attr (struct rec_info *rec,
}
if (!dentry->d_inode || (dentry->d_inode->i_nlink == 0)
|| ((dentry->d_parent != dentry) && list_empty(&dentry->d_hash))) {
|| ((dentry->d_parent != dentry) && d_unhashed(dentry))) {
EXIT;
return 0;
}
......
......@@ -70,7 +70,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
while (n && p != &file->f_dentry->d_subdirs) {
struct dentry *next;
next = list_entry(p, struct dentry, d_child);
if (!list_empty(&next->d_hash) && next->d_inode)
if (!d_unhashed(next) && next->d_inode)
n--;
p = p->next;
}
......@@ -127,7 +127,7 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
struct dentry *next;
next = list_entry(p, struct dentry, d_child);
if (list_empty(&next->d_hash) || !next->d_inode)
if (d_unhashed(next) || !next->d_inode)
continue;
spin_unlock(&dcache_lock);
......
......@@ -1551,7 +1551,7 @@ static void d_unhash(struct dentry *dentry)
if (atomic_read(&dentry->d_count) != 2)
break;
case 2:
list_del_init(&dentry->d_hash);
__d_drop(dentry);
}
spin_unlock(&dcache_lock);
}
......
......@@ -1001,7 +1001,7 @@ static int nfs_unlink(struct inode *dir, struct dentry *dentry)
return error;
}
if (!d_unhashed(dentry)) {
list_del_init(&dentry->d_hash);
__d_drop(dentry);
need_rehash = 1;
}
spin_unlock(&dcache_lock);
......
......@@ -160,10 +160,15 @@ extern rwlock_t dparent_lock;
* timeouts or autofs deletes).
*/
static __inline__ void __d_drop(struct dentry * dentry)
{
list_del_init(&dentry->d_hash);
}
static __inline__ void d_drop(struct dentry * dentry)
{
spin_lock(&dcache_lock);
list_del_init(&dentry->d_hash);
__d_drop(dentry);
spin_unlock(&dcache_lock);
}
......
......@@ -47,9 +47,9 @@ static struct dentry * __unhash_process(struct task_struct *p)
proc_dentry = p->proc_dentry;
if (unlikely(proc_dentry != NULL)) {
spin_lock(&dcache_lock);
if (!list_empty(&proc_dentry->d_hash)) {
if (!d_unhashed(proc_dentry)) {
dget_locked(proc_dentry);
list_del_init(&proc_dentry->d_hash);
__d_drop(proc_dentry);
} else
proc_dentry = NULL;
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