On Fri, 9 Dec 2005, Ian Kent wrote:

> On Thu, 8 Dec 2005, Paul Raines wrote:
> 
> > 
> > Where can I get the disable-mount-locking patch for 4.1.4?  And
> > the patch for mount?
> > 
> > The locking is an absolute killer for me.  One user on a big interactive 
> > server accessing a mount on a down box causes every other user accessing 
> > perfectly valid mounts to have their accesses fail (giving the aquire_lock 
> > error in the log) while the first mount takes forever to timeout.
> 
> I'll have a look and see if I can find it.

I've got 2 patches.
Both have descriptions of what they do.

One fixes a bug in the locking and the other does what you are seeking.

Attached

Ian
This patch fixes two things.

First, sloppy error handling when spawning a sub task.

Second, if the process receives a signal while waiting on the lock
file it will return a "timed out" error after only a little more
than a tenth of a second. This was due to the wait time variable
not being reset after each tenth of a second wait.

diff -Nurp autofs-4.1.4.orig/daemon/spawn.c autofs-4.1.4/daemon/spawn.c
--- autofs-4.1.4.orig/daemon/spawn.c    2005-02-10 20:56:53.000000000 +0800
+++ autofs-4.1.4/daemon/spawn.c 2005-11-01 18:36:35.000000000 +0800
@@ -214,14 +214,15 @@ static int do_spawn(int logpri, int use_
        sigfillset(&allsignals);
        sigprocmask(SIG_BLOCK, &allsignals, &oldsig);
 
-       if (pipe(pipefd))
+       if (pipe(pipefd)) {
+               if (use_lock)
+                       release_lock();
+               sigprocmask(SIG_SETMASK, &oldsig, NULL);
                return -1;
+       }
 
        f = fork();
-       if (f < 0) {
-               sigprocmask(SIG_SETMASK, &oldsig, NULL);
-               return -1;
-       } else if (f == 0) {
+       if (f == 0) {
                reset_signals();
                close(pipefd[0]);
                dup2(pipefd[1], STDOUT_FILENO);
@@ -243,6 +244,8 @@ static int do_spawn(int logpri, int use_
 
                if (f < 0) {
                        close(pipefd[0]);
+                       if (use_lock)
+                               release_lock();
                        sigprocmask(SIG_SETMASK, &oldsig, NULL);
                        return -1;
                }
@@ -287,11 +290,11 @@ static int do_spawn(int logpri, int use_
                if (waitpid(f, &status, 0) != f)
                        status = -1;    /* waitpid() failed */
 
-               sigprocmask(SIG_SETMASK, &oldsig, NULL);
-
                if (use_lock)
                        release_lock();
 
+               sigprocmask(SIG_SETMASK, &oldsig, NULL);
+
                return status;
        }
 }
diff -Nurp autofs-4.1.4.orig/lib/lock.c autofs-4.1.4/lib/lock.c
--- autofs-4.1.4.orig/lib/lock.c        2005-01-17 23:09:28.000000000 +0800
+++ autofs-4.1.4/lib/lock.c     2005-11-01 20:12:28.000000000 +0800
@@ -208,9 +208,6 @@ void release_lock(void)
  */
 static int wait_for_lockf(const char *lockf)
 {
-       struct timespec t = { 0, WAIT_INTERVAL };
-       struct timespec r;
-       int ts_size = sizeof(struct timespec);
        int tries = WAIT_TRIES;
        int status = 0;
        struct stat st;
@@ -218,10 +215,13 @@ static int wait_for_lockf(const char *lo
        while (tries-- && !status) {
                status = stat(lockf, &st);
                if (!status) {
+                       struct timespec t = { 0, WAIT_INTERVAL };
+                       struct timespec r;
+
                        while (nanosleep(&t, &r) == -1 && errno == EINTR) {
                                if (got_term)
                                        return 0;
-                               memcpy(&t, &r, ts_size);
+                               memcpy(&t, &r, sizeof(struct timespec));
                        }
                }
        }
This patch provides a configure option to disable the use of a lock
file when calling mount from autofs. It also adds a patch to the
"patches" directory that needs to be used for mount to (hopefuully)
prevent /etc/mtab corruption when rapidly mounting filesystems
when autofs does not use locking.

To disable the locking add the configure option --disable-mount-locking.

diff -Nurp autofs-4.1.4.orig/configure autofs-4.1.4/configure
--- autofs-4.1.4.orig/configure 2005-04-06 23:24:37.000000000 +0800
+++ autofs-4.1.4/configure      2005-10-23 11:33:44.000000000 +0800
@@ -842,6 +842,7 @@ Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
 --disable-ext-env          disable search in environment for substitution 
variable
+--disable-mount-locking          disable use of locking when spawning mount 
command
 
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
@@ -4308,6 +4309,23 @@ _ACEOF
 fi
 
 #
+# Disable use of locking when spawning mount command
+#
+# Check whether --enable-mount-locking or --disable-mount-locking was given.
+if test "${enable_mount_locking+set}" = set; then
+  enableval="$enable_mount_locking"
+
+else
+  enableval=yes
+fi;
+if test x$enable_mount_locking = xyes -o x$enableval = xyes; then
+       cat >>confdefs.h <<\_ACEOF
+#define ENABLE_MOUNT_LOCKING 1
+_ACEOF
+
+fi
+
+#
 # Write Makefile.conf and include/config.h
 #
           ac_config_headers="$ac_config_headers include/config.h"
diff -Nurp autofs-4.1.4.orig/configure.in autofs-4.1.4/configure.in
--- autofs-4.1.4.orig/configure.in      2005-04-06 23:24:37.000000000 +0800
+++ autofs-4.1.4/configure.in   2005-10-23 11:33:35.000000000 +0800
@@ -167,6 +167,16 @@ if test x$enable_ext_env = xyes; then
 fi
 
 #
+# Disable use of locking when spawning mount command
+#
+AC_ARG_ENABLE(mount-locking,
+--disable-mount-locking          disable use of locking when spawning mount 
command,,
+       enableval=yes)
+if test x$enable_mount_locking = xyes -o x$enableval = xyes; then
+       AC_DEFINE(ENABLE_MOUNT_LOCKING, 1)
+fi
+
+#
 # Write Makefile.conf and include/config.h
 #
 AC_CONFIG_HEADER(include/config.h)
diff -Nurp autofs-4.1.4.orig/daemon/spawn.c autofs-4.1.4/daemon/spawn.c
--- autofs-4.1.4.orig/daemon/spawn.c    2005-02-10 20:56:53.000000000 +0800
+++ autofs-4.1.4/daemon/spawn.c 2005-10-23 10:51:10.000000000 +0800
@@ -322,6 +322,7 @@ int spawnl(int logpri, const char *prog,
        return do_spawn(logpri, 0, prog, (const char **) argv);
 }
 
+#ifdef ENABLE_MOUNT_LOCKING
 int spawnll(int logpri, const char *prog, ...)
 {
        va_list arg;
@@ -342,3 +343,4 @@ int spawnll(int logpri, const char *prog
 
        return do_spawn(logpri, 1, prog, (const char **) argv);
 }
+#endif
diff -Nurp autofs-4.1.4.orig/include/automount.h 
autofs-4.1.4/include/automount.h
--- autofs-4.1.4.orig/include/automount.h       2005-01-26 21:03:02.000000000 
+0800
+++ autofs-4.1.4/include/automount.h    2005-10-23 10:51:10.000000000 +0800
@@ -121,9 +121,13 @@ extern struct autofs_point ap; 
 
 int aquire_lock(void);
 void release_lock(void);
-int spawnll(int logpri, const char *prog, ...);
 int spawnl(int logpri, const char *prog, ...);
-int spawnv(int logpri, const char *prog, const char *const *argv);
+#ifdef ENABLE_MOUNT_LOCKING
+int spawnll(int logpri, const char *prog, ...);
+#else
+#define spawnll        spawnl
+#endif
+int spawnv(int ogpri, const char *prog, const char *const *argv);
 void reset_signals(void);
 void ignore_signals(void);
 void discard_pending(int sig);
diff -Nurp autofs-4.1.4.orig/include/config.h.in 
autofs-4.1.4/include/config.h.in
--- autofs-4.1.4.orig/include/config.h.in       2004-02-03 23:23:21.000000000 
+0800
+++ autofs-4.1.4/include/config.h.in    2005-10-23 10:51:10.000000000 +0800
@@ -25,3 +25,5 @@
 #undef HAVE_SLOPPY_MOUNT
 
 #undef ENABLE_EXT_ENV
+
+#undef ENABLE_MOUNT_LOCKING
diff -Nurp autofs-4.1.4.orig/patches/util-linux-2.12a-flock.patch 
autofs-4.1.4/patches/util-linux-2.12a-flock.patch
--- autofs-4.1.4.orig/patches/util-linux-2.12a-flock.patch      1970-01-01 
08:00:00.000000000 +0800
+++ autofs-4.1.4/patches/util-linux-2.12a-flock.patch   2005-10-23 
10:51:10.000000000 +0800
@@ -0,0 +1,30 @@
+--- util-linux-2.12a/mount/fstab.c.flock       2005-09-17 01:36:03.000000000 
+0800
++++ util-linux-2.12a/mount/fstab.c     2005-09-17 01:41:12.000000000 +0800
+@@ -488,7 +488,7 @@ lock_mtab (void) {
+                               }
+                               /* proceed anyway */
+                       }
+-                      we_created_lockfile = 1;
++                      we_created_lockfile = fd;
+               } else {
+                       static int tries = 0;
+ 
+@@ -510,9 +510,8 @@ lock_mtab (void) {
+                                            MOUNTED_LOCK);
+                               sleep(1);
+                       }
++                      close(fd);
+               }
+-
+-              close(fd);
+       }
+ }
+ 
+@@ -520,6 +519,7 @@ lock_mtab (void) {
+ void
+ unlock_mtab (void) {
+       if (we_created_lockfile) {
++              close(we_created_lockfile);
+               unlink (MOUNTED_LOCK);
+               we_created_lockfile = 0;
+       }
diff -Nurp autofs-4.1.4.orig/patches/util-linux-2.12q-flock.patch 
autofs-4.1.4/patches/util-linux-2.12q-flock.patch
--- autofs-4.1.4.orig/patches/util-linux-2.12q-flock.patch      1970-01-01 
08:00:00.000000000 +0800
+++ autofs-4.1.4/patches/util-linux-2.12q-flock.patch   2005-10-23 
10:51:10.000000000 +0800
@@ -0,0 +1,29 @@
+--- util-linux-2.12q/mount/fstab.c.flock       2005-09-17 01:10:37.000000000 
+0800
++++ util-linux-2.12q/mount/fstab.c     2005-09-17 01:16:51.000000000 +0800
+@@ -417,6 +417,7 @@
+ unlock_mtab (void) {
+       if (we_created_lockfile) {
+               unlink (MOUNTED_LOCK);
++              close(we_created_lock_file);
+               we_created_lockfile = 0;
+       }
+ }
+@@ -528,6 +529,7 @@
+                               }
+                               /* proceed anyway */
+                       }
++                      we_created_lock_file = fd;
+               } else {
+                       static int tries = 0;
+ 
+@@ -549,9 +551,8 @@
+                                            MOUNTED_LOCK);
+                               sleep(1);
+                       }
++                      close(fd);
+               }
+-
+-              close(fd);
+       }
+ }
+ 
_______________________________________________
autofs mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

Reply via email to