From: Ian Kent <ikent@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
autofs mailing list <autofs@linux.kernel.org>
Subject: [PATCH] autofs4 - fix get_next_positive_subdir()
Date: Wed, 23 May 2012 10:49:50 +0800 [thread overview]
Message-ID: <20120523024950.3905.89811.stgit@perseus.themaw.net> (raw)
From: Ian Kent <raven@themaw.net>
The locking for the list traversal in get_next_positive_subdir() is
wrong, so fix it.
Signed-off-by: Ian Kent <raven@themaw.net>
---
fs/autofs4/expire.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
index 1feb68e..20cc9fd 100644
--- a/fs/autofs4/expire.c
+++ b/fs/autofs4/expire.c
@@ -97,9 +97,9 @@ static struct dentry *get_next_positive_subdir(struct dentry *prev,
struct dentry *p, *q;
spin_lock(&sbi->lookup_lock);
+ spin_lock(&root->d_lock);
if (prev == NULL) {
- spin_lock(&root->d_lock);
prev = dget_dlock(root);
next = prev->d_subdirs.next;
p = prev;
@@ -107,12 +107,13 @@ static struct dentry *get_next_positive_subdir(struct dentry *prev,
}
p = prev;
- spin_lock(&p->d_lock);
+ spin_lock_nested(&p->d_lock, DENTRY_D_LOCK_NESTED);
again:
next = p->d_u.d_child.next;
start:
if (next == &root->d_subdirs) {
spin_unlock(&p->d_lock);
+ spin_unlock(&root->d_lock);
spin_unlock(&sbi->lookup_lock);
dput(prev);
return NULL;
@@ -121,8 +122,8 @@ start:
q = list_entry(next, struct dentry, d_u.d_child);
spin_lock_nested(&q->d_lock, DENTRY_D_LOCK_NESTED);
- /* Negative dentry - try next */
- if (!simple_positive(q)) {
+ /* Negative dentry or already gone - try next */
+ if (q->d_count == 0 || !simple_positive(q)) {
spin_unlock(&p->d_lock);
lock_set_subclass(&q->d_lock.dep_map, 0, _RET_IP_);
p = q;
@@ -131,6 +132,7 @@ start:
dget_dlock(q);
spin_unlock(&q->d_lock);
spin_unlock(&p->d_lock);
+ spin_unlock(&root->d_lock);
spin_unlock(&sbi->lookup_lock);
dput(prev);
next reply other threads:[~2012-05-23 2:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-23 2:49 Ian Kent [this message]
2012-05-23 2:53 ` Linus Torvalds
2012-05-23 6:19 ` Ian Kent
2012-05-23 7:22 ` Ian Kent
2012-05-23 7:30 ` Ian Kent
2012-05-23 9:03 ` Ian Kent
2012-08-06 1:37 Ian Kent
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120523024950.3905.89811.stgit@perseus.themaw.net \
--to=ikent@redhat.com \
--cc=autofs@linux.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®