autofs-5.0.1 - force unlink umount at startup From: Ian Kent <raven@themaw.net> Version 5.0.3 autofs would unlink existing mounts at startup. This functioned OK most of the time but caused processes whose working directory was within unlinked automounted directories to not get a correct pwd reported by the system. There can be situations where the unlink umounting is desirable, such as when the daemon is forceably killed and we want to get rid of any existing mounts at startup. This change provides a way to force this old behavior by passing the "--force" option to the daemon. This can also be done by using the "forcestart" and "forcerestart" actions to the init script. Note that the old behavior will always be used if the kernel does not include the iotcl re-implementation which provides the ability to re-connect to existing mounts. --- daemon/automount.c | 14 +++++++++++++- daemon/direct.c | 2 +- daemon/indirect.c | 2 +- include/automount.h | 3 +++ redhat/autofs.init.in | 10 +++++++++- samples/rc.autofs.in | 10 +++++++++- 6 files changed, 36 insertions(+), 5 deletions(-) --- autofs-5.0.1.orig/daemon/automount.c +++ autofs-5.0.1/daemon/automount.c @@ -58,6 +58,7 @@ static char *pid_file = NULL; /* File i unsigned int global_random_selection; /* use random policy when selecting * which multi-mount host to mount */ long global_negative_timeout = -1; +int do_force_unlink = 0; /* Forceably unlink mount tree at startup */ static int start_pipefd[2]; static int st_stat = 1; @@ -1845,6 +1846,7 @@ int main(int argc, char *argv[]) {"global-options", 1, 0, 'O'}, {"version", 0, 0, 'V'}, {"set-log-priority", 1, 0, 'l'}, + {"force", 0, 0, 'F'}, {0, 0, 0, 0} }; @@ -1864,7 +1866,7 @@ int main(int argc, char *argv[]) foreground = 0; opterr = 0; - while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:", long_options, NULL)) != EOF) { + while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:F", long_options, NULL)) != EOF) { switch (opt) { case 'h': usage(); @@ -1933,6 +1935,10 @@ int main(int argc, char *argv[]) } break; + case 'F': + do_force_unlink = 1; + break; + case '?': case ':': printf("%s: Ambiguous or unknown options\n", program); @@ -2113,6 +2119,12 @@ int main(int argc, char *argv[]) exit(3); } + /* + * Mmm ... reset force unlink umount so we don't also do this + * in future when we receive a HUP signal. + */ + do_force_unlink = 0; + st_stat = 0; res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); close(start_pipefd[1]); --- autofs-5.0.1.orig/daemon/direct.c +++ autofs-5.0.1/daemon/direct.c @@ -337,7 +337,7 @@ int do_mount_autofs_direct(struct autofs /* Calculate the timeouts */ ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO; - if (ops->version) { + if (ops->version && !do_force_unlink) { ap->flags |= MOUNT_FLAG_REMOUNT; ret = try_remount(ap, me, t_direct); ap->flags &= ~MOUNT_FLAG_REMOUNT; --- autofs-5.0.1.orig/daemon/indirect.c +++ autofs-5.0.1/daemon/indirect.c @@ -99,7 +99,7 @@ static int do_mount_autofs_indirect(stru ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO; - if (ops->version) { + if (ops->version && !do_force_unlink) { ap->flags |= MOUNT_FLAG_REMOUNT; ret = try_remount(ap, NULL, t_indirect); ap->flags &= ~MOUNT_FLAG_REMOUNT; --- autofs-5.0.1.orig/include/automount.h +++ autofs-5.0.1/include/automount.h @@ -426,6 +426,9 @@ struct autofs_point { struct list_head submounts; /* List of child submounts */ }; +/* Foreably unlink existing mounts at startup. */ +extern int do_force_unlink; + /* Standard functions used by daemon or modules */ #define MOUNT_OFFSET_OK 0 --- autofs-5.0.1.orig/redhat/autofs.init.in +++ autofs-5.0.1/redhat/autofs.init.in @@ -136,6 +136,10 @@ case "$1" in start) start ;; + forcestart) + OPTIONS="$OPTIONS --force" + start + ;; stop) stop ;; @@ -145,6 +149,10 @@ case "$1" in restart) restart ;; + forcerestart) + OPTIONS="$OPTIONS --force" + restart + ;; reload) reload ;; @@ -154,7 +162,7 @@ case "$1" in fi ;; *) - echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" + echo $"Usage: $0 {start|forcestart|stop|status|restart|orcerestart|reload|condrestart}" exit 1; ;; esac --- autofs-5.0.1.orig/samples/rc.autofs.in +++ autofs-5.0.1/samples/rc.autofs.in @@ -116,17 +116,25 @@ case "$1" in start) start ;; + forcestart) + OPTIONS="$OPTIONS --force" + start + ;; stop) stop ;; restart) restart ;; + forcerestart) + OPTIONS="$OPTIONS --force" + restart + ;; reload) reload ;; *) - echo $"Usage: $0 {start|stop|restart|reload}" + echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}" exit 1; ;; esac