提交 a5370553 编写于 作者: I Ian Kent 提交者: Linus Torvalds

[PATCH] autofs4: NFY_NONE wait race fix

This patch fixes two problems.

First, the comparison of entries in the waitq.c was incorrect.

Second, the NFY_NONE check was incorrect. The test of whether the dentry
is mounted if ineffective, for example, if an expire fails then we could
wait forever on a non existant expire. The bug was identified by Jeff
Moyer.

The patch changes autofs4 to wait on expires only as this is all that's
needed.  If there is no existing wait when autofs4_wait is call with a type
of NFY_NONE it delays until either a wait appears or the the expire flag is
cleared.
Signed-off-by: NIan Kent <raven@themaw.net>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 6aff5cb8
...@@ -74,8 +74,8 @@ struct autofs_wait_queue { ...@@ -74,8 +74,8 @@ struct autofs_wait_queue {
struct autofs_wait_queue *next; struct autofs_wait_queue *next;
autofs_wqt_t wait_queue_token; autofs_wqt_t wait_queue_token;
/* We use the following to see what we are waiting for */ /* We use the following to see what we are waiting for */
int hash; unsigned int hash;
int len; unsigned int len;
char *name; char *name;
u32 dev; u32 dev;
u64 ino; u64 ino;
...@@ -85,7 +85,6 @@ struct autofs_wait_queue { ...@@ -85,7 +85,6 @@ struct autofs_wait_queue {
pid_t tgid; pid_t tgid;
/* This is for status reporting upon return */ /* This is for status reporting upon return */
int status; int status;
atomic_t notify;
atomic_t wait_ctr; atomic_t wait_ctr;
}; };
......
...@@ -327,6 +327,7 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags) ...@@ -327,6 +327,7 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags)
static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
{ {
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
struct autofs_info *ino = autofs4_dentry_ino(dentry);
int oz_mode = autofs4_oz_mode(sbi); int oz_mode = autofs4_oz_mode(sbi);
unsigned int lookup_type; unsigned int lookup_type;
int status; int status;
...@@ -340,13 +341,8 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) ...@@ -340,13 +341,8 @@ static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
if (oz_mode || !lookup_type) if (oz_mode || !lookup_type)
goto done; goto done;
/* /* If an expire request is pending wait for it. */
* If a request is pending wait for it. if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
* If it's a mount then it won't be expired till at least
* a liitle later and if it's an expire then we might need
* to mount it again.
*/
if (autofs4_ispending(dentry)) {
DPRINTK("waiting for active request %p name=%.*s", DPRINTK("waiting for active request %p name=%.*s",
dentry, dentry->d_name.len, dentry->d_name.name); dentry, dentry->d_name.len, dentry->d_name.name);
......
...@@ -189,14 +189,30 @@ static int autofs4_getpath(struct autofs_sb_info *sbi, ...@@ -189,14 +189,30 @@ static int autofs4_getpath(struct autofs_sb_info *sbi,
return len; return len;
} }
static struct autofs_wait_queue *
autofs4_find_wait(struct autofs_sb_info *sbi,
char *name, unsigned int hash, unsigned int len)
{
struct autofs_wait_queue *wq;
for (wq = sbi->queues; wq; wq = wq->next) {
if (wq->hash == hash &&
wq->len == len &&
wq->name && !memcmp(wq->name, name, len))
break;
}
return wq;
}
int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
enum autofs_notify notify) enum autofs_notify notify)
{ {
struct autofs_info *ino;
struct autofs_wait_queue *wq; struct autofs_wait_queue *wq;
char *name; char *name;
unsigned int len = 0; unsigned int len = 0;
unsigned int hash = 0; unsigned int hash = 0;
int status; int status, type;
/* In catatonic mode, we don't wait for nobody */ /* In catatonic mode, we don't wait for nobody */
if (sbi->catatonic) if (sbi->catatonic)
...@@ -223,21 +239,41 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, ...@@ -223,21 +239,41 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
return -EINTR; return -EINTR;
} }
for (wq = sbi->queues ; wq ; wq = wq->next) { wq = autofs4_find_wait(sbi, name, hash, len);
if (wq->hash == dentry->d_name.hash && ino = autofs4_dentry_ino(dentry);
wq->len == len && if (!wq && ino && notify == NFY_NONE) {
wq->name && !memcmp(wq->name, name, len)) /*
break; * Either we've betean the pending expire to post it's
} * wait or it finished while we waited on the mutex.
* So we need to wait till either, the wait appears
* or the expire finishes.
*/
while (ino->flags & AUTOFS_INF_EXPIRING) {
mutex_unlock(&sbi->wq_mutex);
schedule_timeout_interruptible(HZ/10);
if (mutex_lock_interruptible(&sbi->wq_mutex)) {
kfree(name);
return -EINTR;
}
wq = autofs4_find_wait(sbi, name, hash, len);
if (wq)
break;
}
if (!wq) { /*
/* Can't wait for an expire if there's no mount */ * Not ideal but the status has already gone. Of the two
if (notify == NFY_NONE && !d_mountpoint(dentry)) { * cases where we wait on NFY_NONE neither depend on the
* return status of the wait.
*/
if (!wq) {
kfree(name); kfree(name);
mutex_unlock(&sbi->wq_mutex); mutex_unlock(&sbi->wq_mutex);
return -ENOENT; return 0;
} }
}
if (!wq) {
/* Create a new wait queue */ /* Create a new wait queue */
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL); wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
if (!wq) { if (!wq) {
...@@ -263,20 +299,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, ...@@ -263,20 +299,7 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
wq->tgid = current->tgid; wq->tgid = current->tgid;
wq->status = -EINTR; /* Status return if interrupted */ wq->status = -EINTR; /* Status return if interrupted */
atomic_set(&wq->wait_ctr, 2); atomic_set(&wq->wait_ctr, 2);
atomic_set(&wq->notify, 1);
mutex_unlock(&sbi->wq_mutex);
} else {
atomic_inc(&wq->wait_ctr);
mutex_unlock(&sbi->wq_mutex); mutex_unlock(&sbi->wq_mutex);
kfree(name);
DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
(unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
}
if (notify != NFY_NONE && atomic_read(&wq->notify)) {
int type;
atomic_dec(&wq->notify);
if (sbi->version < 5) { if (sbi->version < 5) {
if (notify == NFY_MOUNT) if (notify == NFY_MOUNT)
...@@ -299,6 +322,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry, ...@@ -299,6 +322,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
/* autofs4_notify_daemon() may block */ /* autofs4_notify_daemon() may block */
autofs4_notify_daemon(sbi, wq, type); autofs4_notify_daemon(sbi, wq, type);
} else {
atomic_inc(&wq->wait_ctr);
mutex_unlock(&sbi->wq_mutex);
kfree(name);
DPRINTK("existing wait id = 0x%08lx, name = %.*s, nfy=%d",
(unsigned long) wq->wait_queue_token, wq->len, wq->name, notify);
} }
/* wq->name is NULL if and only if the lock is already released */ /* wq->name is NULL if and only if the lock is already released */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册