* [PATCH 1/2] autofs4 - fix lookup deadlock
@ 2009-03-16 3:17 Ian Kent
2009-03-16 3:17 ` [PATCH 2/2] autofs4 - fix kernel includes Ian Kent
0 siblings, 1 reply; 2+ messages in thread
From: Ian Kent @ 2009-03-16 3:17 UTC (permalink / raw)
To: Andrew Morton; +Cc: autofs mailing list, Kernel Mailing List, linux-fsdevel
A deadlock can occur when user space uses a signal (autofs version 4
uses SIGCHLD for this) to effect expire completion.
The order of events is:
Expire process completes, but before being able to send SIGCHLD to it's
parent ...
Another process walks onto a different mount point and drops the directory
inode semaphore prior to sending the request to the daemon as it must ...
A third process does an lstat on on the expired mount point causing it to
wait on expire completion (unfortunately) holding the directory semaphore.
The mount request then arrives at the daemon which does an lstat and,
deadlock.
For some time I was concerned about releasing the directory semaphore
around the expire wait in autofs4_lookup as well as for the mount call
back. I finally realized that the last round of changes in this function
made the expiring dentry and the lookup dentry separate and distinct so
the check and possible wait can be done anywhere prior to the mount call
back. This patch moves the check to just before the mount call back and
inside the directory inode mutex release.
Signed-off-by: Ian Kent <raven@themaw.net>
---
fs/autofs4/root.c | 41 +++++++++++++++++++++--------------------
1 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 2a41c2a..e8c55d2 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -485,22 +485,6 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
- expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
- if (expiring) {
- /*
- * If we are racing with expire the request might not
- * be quite complete but the directory has been removed
- * so it must have been successful, so just wait for it.
- */
- ino = autofs4_dentry_ino(expiring);
- autofs4_expire_wait(expiring);
- spin_lock(&sbi->lookup_lock);
- if (!list_empty(&ino->expiring))
- list_del_init(&ino->expiring);
- spin_unlock(&sbi->lookup_lock);
- dput(expiring);
- }
-
unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
if (unhashed)
dentry = unhashed;
@@ -538,14 +522,31 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
}
if (!oz_mode) {
+ mutex_unlock(&dir->i_mutex);
+ expiring = autofs4_lookup_expiring(sbi,
+ dentry->d_parent,
+ &dentry->d_name);
+ if (expiring) {
+ /*
+ * If we are racing with expire the request might not
+ * be quite complete but the directory has been removed
+ * so it must have been successful, so just wait for it.
+ */
+ ino = autofs4_dentry_ino(expiring);
+ autofs4_expire_wait(expiring);
+ spin_lock(&sbi->lookup_lock);
+ if (!list_empty(&ino->expiring))
+ list_del_init(&ino->expiring);
+ spin_unlock(&sbi->lookup_lock);
+ dput(expiring);
+ }
+
spin_lock(&dentry->d_lock);
dentry->d_flags |= DCACHE_AUTOFS_PENDING;
spin_unlock(&dentry->d_lock);
- if (dentry->d_op && dentry->d_op->d_revalidate) {
- mutex_unlock(&dir->i_mutex);
+ if (dentry->d_op && dentry->d_op->d_revalidate)
(dentry->d_op->d_revalidate)(dentry, nd);
- mutex_lock(&dir->i_mutex);
- }
+ mutex_lock(&dir->i_mutex);
}
/*
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] autofs4 - fix kernel includes
2009-03-16 3:17 [PATCH 1/2] autofs4 - fix lookup deadlock Ian Kent
@ 2009-03-16 3:17 ` Ian Kent
0 siblings, 0 replies; 2+ messages in thread
From: Ian Kent @ 2009-03-16 3:17 UTC (permalink / raw)
To: Andrew Morton; +Cc: autofs mailing list, Kernel Mailing List, linux-fsdevel
autofs_dev-ioctl.h is included by both the kernel module and user
space tools and it includes two kernel header files. Compiles
work if the kernel headers are installed but fail otherwise.
Signed-off-by: Ian Kent <raven@themaw.net>
---
include/linux/auto_dev-ioctl.h | 7 ++++++-
include/linux/auto_fs.h | 6 ++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/include/linux/auto_dev-ioctl.h b/include/linux/auto_dev-ioctl.h
index 91a7739..850f39b 100644
--- a/include/linux/auto_dev-ioctl.h
+++ b/include/linux/auto_dev-ioctl.h
@@ -10,8 +10,13 @@
#ifndef _LINUX_AUTO_DEV_IOCTL_H
#define _LINUX_AUTO_DEV_IOCTL_H
+#include <linux/auto_fs.h>
+
+#ifdef __KERNEL__
#include <linux/string.h>
-#include <linux/types.h>
+#else
+#include <string.h>
+#endif /* __KERNEL__ */
#define AUTOFS_DEVICE_NAME "autofs"
diff --git a/include/linux/auto_fs.h b/include/linux/auto_fs.h
index c21e597..6326585 100644
--- a/include/linux/auto_fs.h
+++ b/include/linux/auto_fs.h
@@ -17,11 +17,13 @@
#ifdef __KERNEL__
#include <linux/fs.h>
#include <linux/limits.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#else
#include <asm/types.h>
+#include <sys/ioctl.h>
#endif /* __KERNEL__ */
-#include <linux/ioctl.h>
-
/* This file describes autofs v3 */
#define AUTOFS_PROTO_VERSION 3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-16 3:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-16 3:17 [PATCH 1/2] autofs4 - fix lookup deadlock Ian Kent
2009-03-16 3:17 ` [PATCH 2/2] autofs4 - fix kernel includes Ian Kent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).