<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Ian Kent &lt;raven@themaw.net&gt;

While this is not a solution to bind and move mounts on autofs owned 
directories it is necessary to fix the trady error handling.

At least it avoids the kernel panic I observed checking out bug #4589.

Signed-off-by: Ian Kent &lt;raven@themaw.net&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 fs/autofs4/autofs_i.h |   13 +++++++++++++
 fs/autofs4/expire.c   |    5 +----
 fs/autofs4/root.c     |    6 +++++-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff -puN fs/autofs4/autofs_i.h~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory fs/autofs4/autofs_i.h
--- 25/fs/autofs4/autofs_i.h~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory	2005-06-05 23:34:50.000000000 -0700
+++ 25-akpm/fs/autofs4/autofs_i.h	2005-06-05 23:34:50.000000000 -0700
@@ -185,6 +185,19 @@ int autofs4_wait(struct autofs_sb_info *
 int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
 void autofs4_catatonic_mode(struct autofs_sb_info *);
 
+static inline int autofs4_follow_mount(struct vfsmount **mnt, struct dentry **dentry)
+{
+	int res = 0;
+
+	while (d_mountpoint(*dentry)) {
+		int followed = follow_down(mnt, dentry);
+		if (!followed)
+			break;
+		res = 1;
+	}
+	return res;
+}
+
 static inline int simple_positive(struct dentry *dentry)
 {
 	return dentry-&gt;d_inode &amp;&amp; !d_unhashed(dentry);
diff -puN fs/autofs4/expire.c~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory fs/autofs4/expire.c
--- 25/fs/autofs4/expire.c~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory	2005-06-05 23:34:50.000000000 -0700
+++ 25-akpm/fs/autofs4/expire.c	2005-06-05 23:34:50.000000000 -0700
@@ -56,12 +56,9 @@ static int autofs4_check_mount(struct vf
 	mntget(mnt);
 	dget(dentry);
 
-	if (!follow_down(&amp;mnt, &amp;dentry))
+	if (!autofs4_follow_mount(&amp;mnt, &amp;dentry))
 		goto done;
 
-	while (d_mountpoint(dentry) &amp;&amp; follow_down(&amp;mnt, &amp;dentry))
-		;
-
 	/* This is an autofs submount, we can't expire it */
 	if (is_autofs4_dentry(dentry))
 		goto done;
diff -puN fs/autofs4/root.c~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory fs/autofs4/root.c
--- 25/fs/autofs4/root.c~autofs4-avoid-panic-on-bind-mount-of-autofs-owned-directory	2005-06-05 23:34:50.000000000 -0700
+++ 25-akpm/fs/autofs4/root.c	2005-06-05 23:34:50.000000000 -0700
@@ -205,7 +205,11 @@ static int autofs4_dir_open(struct inode
 		struct vfsmount *fp_mnt = mntget(mnt);
 		struct dentry *fp_dentry = dget(dentry);
 
-		while (follow_down(&amp;fp_mnt, &amp;fp_dentry) &amp;&amp; d_mountpoint(fp_dentry));
+		if (!autofs4_follow_mount(&amp;fp_mnt, &amp;fp_dentry)) {
+			dput(fp_dentry);
+			mntput(fp_mnt);
+			return -ENOENT;
+		}
 
 		fp = dentry_open(fp_dentry, fp_mnt, file-&gt;f_flags);
 		status = PTR_ERR(fp);
_
</pre></body></html>