Commit 06c86e66 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull dcache updates from Al Viro:
 "This is the first part of dealing with livelocks etc around
  shrink_dcache_parent()."

* 'work.dcache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  restore cond_resched() in shrink_dcache_parent()
  dput(): turn into explicit while() loop
  dcache: move cond_resched() into the end of __dentry_kill()
  d_walk(): kill 'finish' callback
  d_invalidate(): unhash immediately
parents f459c345 4fb48871
...@@ -580,6 +580,7 @@ static void __dentry_kill(struct dentry *dentry) ...@@ -580,6 +580,7 @@ static void __dentry_kill(struct dentry *dentry)
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
if (likely(can_free)) if (likely(can_free))
dentry_free(dentry); dentry_free(dentry);
cond_resched();
} }
static struct dentry *__lock_parent(struct dentry *dentry) static struct dentry *__lock_parent(struct dentry *dentry)
...@@ -827,10 +828,7 @@ static inline bool fast_dput(struct dentry *dentry) ...@@ -827,10 +828,7 @@ static inline bool fast_dput(struct dentry *dentry)
*/ */
void dput(struct dentry *dentry) void dput(struct dentry *dentry)
{ {
if (unlikely(!dentry)) while (dentry) {
return;
repeat:
might_sleep(); might_sleep();
rcu_read_lock(); rcu_read_lock();
...@@ -848,9 +846,6 @@ void dput(struct dentry *dentry) ...@@ -848,9 +846,6 @@ void dput(struct dentry *dentry)
} }
dentry = dentry_kill(dentry); dentry = dentry_kill(dentry);
if (dentry) {
cond_resched();
goto repeat;
} }
} }
EXPORT_SYMBOL(dput); EXPORT_SYMBOL(dput);
...@@ -1052,8 +1047,6 @@ static void shrink_dentry_list(struct list_head *list) ...@@ -1052,8 +1047,6 @@ static void shrink_dentry_list(struct list_head *list)
while (!list_empty(list)) { while (!list_empty(list)) {
struct dentry *dentry, *parent; struct dentry *dentry, *parent;
cond_resched();
dentry = list_entry(list->prev, struct dentry, d_lru); dentry = list_entry(list->prev, struct dentry, d_lru);
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
rcu_read_lock(); rcu_read_lock();
...@@ -1230,13 +1223,11 @@ enum d_walk_ret { ...@@ -1230,13 +1223,11 @@ enum d_walk_ret {
* @parent: start of walk * @parent: start of walk
* @data: data passed to @enter() and @finish() * @data: data passed to @enter() and @finish()
* @enter: callback when first entering the dentry * @enter: callback when first entering the dentry
* @finish: callback when successfully finished the walk
* *
* The @enter() and @finish() callbacks are called with d_lock held. * The @enter() callbacks are called with d_lock held.
*/ */
static void d_walk(struct dentry *parent, void *data, static void d_walk(struct dentry *parent, void *data,
enum d_walk_ret (*enter)(void *, struct dentry *), enum d_walk_ret (*enter)(void *, struct dentry *))
void (*finish)(void *))
{ {
struct dentry *this_parent; struct dentry *this_parent;
struct list_head *next; struct list_head *next;
...@@ -1325,8 +1316,6 @@ static void d_walk(struct dentry *parent, void *data, ...@@ -1325,8 +1316,6 @@ static void d_walk(struct dentry *parent, void *data,
if (need_seqretry(&rename_lock, seq)) if (need_seqretry(&rename_lock, seq))
goto rename_retry; goto rename_retry;
rcu_read_unlock(); rcu_read_unlock();
if (finish)
finish(data);
out_unlock: out_unlock:
spin_unlock(&this_parent->d_lock); spin_unlock(&this_parent->d_lock);
...@@ -1375,7 +1364,7 @@ int path_has_submounts(const struct path *parent) ...@@ -1375,7 +1364,7 @@ int path_has_submounts(const struct path *parent)
struct check_mount data = { .mnt = parent->mnt, .mounted = 0 }; struct check_mount data = { .mnt = parent->mnt, .mounted = 0 };
read_seqlock_excl(&mount_lock); read_seqlock_excl(&mount_lock);
d_walk(parent->dentry, &data, path_check_mount, NULL); d_walk(parent->dentry, &data, path_check_mount);
read_sequnlock_excl(&mount_lock); read_sequnlock_excl(&mount_lock);
return data.mounted; return data.mounted;
...@@ -1483,11 +1472,16 @@ void shrink_dcache_parent(struct dentry *parent) ...@@ -1483,11 +1472,16 @@ void shrink_dcache_parent(struct dentry *parent)
data.start = parent; data.start = parent;
data.found = 0; data.found = 0;
d_walk(parent, &data, select_collect, NULL); d_walk(parent, &data, select_collect);
if (!data.found)
break;
if (!list_empty(&data.dispose)) {
shrink_dentry_list(&data.dispose); shrink_dentry_list(&data.dispose);
continue;
}
cond_resched();
if (!data.found)
break;
} }
} }
EXPORT_SYMBOL(shrink_dcache_parent); EXPORT_SYMBOL(shrink_dcache_parent);
...@@ -1518,7 +1512,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry) ...@@ -1518,7 +1512,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
static void do_one_tree(struct dentry *dentry) static void do_one_tree(struct dentry *dentry)
{ {
shrink_dcache_parent(dentry); shrink_dcache_parent(dentry);
d_walk(dentry, dentry, umount_check, NULL); d_walk(dentry, dentry, umount_check);
d_drop(dentry); d_drop(dentry);
dput(dentry); dput(dentry);
} }
...@@ -1542,78 +1536,48 @@ void shrink_dcache_for_umount(struct super_block *sb) ...@@ -1542,78 +1536,48 @@ void shrink_dcache_for_umount(struct super_block *sb)
} }
} }
struct detach_data { static enum d_walk_ret find_submount(void *_data, struct dentry *dentry)
struct select_data select;
struct dentry *mountpoint;
};
static enum d_walk_ret detach_and_collect(void *_data, struct dentry *dentry)
{ {
struct detach_data *data = _data; struct dentry **victim = _data;
if (d_mountpoint(dentry)) { if (d_mountpoint(dentry)) {
__dget_dlock(dentry); __dget_dlock(dentry);
data->mountpoint = dentry; *victim = dentry;
return D_WALK_QUIT; return D_WALK_QUIT;
} }
return D_WALK_CONTINUE;
return select_collect(&data->select, dentry);
}
static void check_and_drop(void *_data)
{
struct detach_data *data = _data;
if (!data->mountpoint && list_empty(&data->select.dispose))
__d_drop(data->select.start);
} }
/** /**
* d_invalidate - detach submounts, prune dcache, and drop * d_invalidate - detach submounts, prune dcache, and drop
* @dentry: dentry to invalidate (aka detach, prune and drop) * @dentry: dentry to invalidate (aka detach, prune and drop)
*
* no dcache lock.
*
* The final d_drop is done as an atomic operation relative to
* rename_lock ensuring there are no races with d_set_mounted. This
* ensures there are no unhashed dentries on the path to a mountpoint.
*/ */
void d_invalidate(struct dentry *dentry) void d_invalidate(struct dentry *dentry)
{ {
/* bool had_submounts = false;
* If it's already been dropped, return OK.
*/
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
if (d_unhashed(dentry)) { if (d_unhashed(dentry)) {
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
return; return;
} }
__d_drop(dentry);
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
/* Negative dentries can be dropped without further checks */ /* Negative dentries can be dropped without further checks */
if (!dentry->d_inode) { if (!dentry->d_inode)
d_drop(dentry);
return; return;
}
shrink_dcache_parent(dentry);
for (;;) { for (;;) {
struct detach_data data; struct dentry *victim = NULL;
d_walk(dentry, &victim, find_submount);
data.mountpoint = NULL; if (!victim) {
INIT_LIST_HEAD(&data.select.dispose); if (had_submounts)
data.select.start = dentry; shrink_dcache_parent(dentry);
data.select.found = 0;
d_walk(dentry, &data, detach_and_collect, check_and_drop);
if (!list_empty(&data.select.dispose))
shrink_dentry_list(&data.select.dispose);
else if (!data.mountpoint)
return; return;
if (data.mountpoint) {
detach_mounts(data.mountpoint);
dput(data.mountpoint);
} }
had_submounts = true;
detach_mounts(victim);
dput(victim);
} }
} }
EXPORT_SYMBOL(d_invalidate); EXPORT_SYMBOL(d_invalidate);
...@@ -3134,7 +3098,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry) ...@@ -3134,7 +3098,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
void d_genocide(struct dentry *parent) void d_genocide(struct dentry *parent)
{ {
d_walk(parent, parent, d_genocide_kill, NULL); d_walk(parent, parent, d_genocide_kill);
} }
EXPORT_SYMBOL(d_genocide); EXPORT_SYMBOL(d_genocide);
......
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