1 autofs-5.0.4 - force unlink umount at startup
3 From: Ian Kent <raven@themaw.net>
5 Version 5.0.3 autofs would unlink existing mounts at startup. This
6 functioned OK most of the time but caused processes whose working
7 directory was within unlinked automounted directories to not get a
8 correct pwd reported by the system.
10 There can be situations where the unlink umounting is desirable, such
11 as when the daemon is forceably killed and we want to get rid of any
12 existing mounts at startup. This change provides a way to force this
13 old behavior by passing the "--force" option to the daemon. This can
14 also be done by using the "forcestart" and "forcerestart" actions to
17 Note that the old behavior will always be used if the kernel does not
18 include the iotcl re-implementation which provides the ability to
19 re-connect to existing mounts.
23 daemon/automount.c | 14 +++++++++++++-
24 daemon/direct.c | 2 +-
25 daemon/indirect.c | 2 +-
26 include/automount.h | 3 +++
27 man/automount.8 | 13 +++++++++++++
28 redhat/autofs.init.in | 10 +++++++++-
29 samples/rc.autofs.in | 10 +++++++++-
30 8 files changed, 51 insertions(+), 5 deletions(-)
33 diff --git a/CHANGELOG b/CHANGELOG
34 index 7dee674..d4dd70b 100644
38 - fix hosts map use after free.
39 - fix uri list locking (again).
40 - check for stale SASL credentials upon connect fail.
41 +- add "forcestart" and "forcerestart" init script options to allow
42 + use of 5.0.3 strartup behavior if required.
44 4/11/2008 autofs-5.0.4
45 -----------------------
46 diff --git a/daemon/automount.c b/daemon/automount.c
47 index f04273f..e20e7c9 100644
48 --- a/daemon/automount.c
49 +++ b/daemon/automount.c
50 @@ -57,6 +57,7 @@ static char *pid_file = NULL; /* File in which to keep pid */
51 unsigned int global_random_selection; /* use random policy when selecting
52 * which multi-mount host to mount */
53 long global_negative_timeout = -1;
54 +int do_force_unlink = 0; /* Forceably unlink mount tree at startup */
56 static int start_pipefd[2];
57 static int st_stat = 0;
58 @@ -1798,6 +1799,7 @@ int main(int argc, char *argv[])
59 {"version", 0, 0, 'V'},
60 {"set-log-priority", 1, 0, 'l'},
61 {"dont-check-daemon", 0, 0, 'C'},
62 + {"force", 0, 0, 'F'},
66 @@ -1819,7 +1821,7 @@ int main(int argc, char *argv[])
70 - while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:C", long_options, NULL)) != EOF) {
71 + while ((opt = getopt_long(argc, argv, "+hp:t:vdD:fVrO:l:n:CF", long_options, NULL)) != EOF) {
75 @@ -1892,6 +1894,10 @@ int main(int argc, char *argv[])
80 + do_force_unlink = 1;
85 printf("%s: Ambiguous or unknown options\n", program);
86 @@ -2066,6 +2072,12 @@ int main(int argc, char *argv[])
91 + * Mmm ... reset force unlink umount so we don't also do this
92 + * in future when we receive a HUP signal.
94 + do_force_unlink = 0;
96 res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat));
97 close(start_pipefd[1]);
99 diff --git a/daemon/direct.c b/daemon/direct.c
100 index d9dda3d..2d979f1 100644
101 --- a/daemon/direct.c
102 +++ b/daemon/direct.c
103 @@ -335,7 +335,7 @@ int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struc
104 /* Calculate the timeouts */
105 ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
107 - if (ops->version) {
108 + if (ops->version && !do_force_unlink) {
109 ap->flags |= MOUNT_FLAG_REMOUNT;
110 ret = try_remount(ap, me, t_direct);
111 ap->flags &= ~MOUNT_FLAG_REMOUNT;
112 diff --git a/daemon/indirect.c b/daemon/indirect.c
113 index 0721707..2ccbc53 100644
114 --- a/daemon/indirect.c
115 +++ b/daemon/indirect.c
116 @@ -97,7 +97,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)
118 ap->exp_runfreq = (timeout + CHECK_RATIO - 1) / CHECK_RATIO;
120 - if (ops->version) {
121 + if (ops->version && !do_force_unlink) {
122 ap->flags |= MOUNT_FLAG_REMOUNT;
123 ret = try_remount(ap, NULL, t_indirect);
124 ap->flags &= ~MOUNT_FLAG_REMOUNT;
125 diff --git a/include/automount.h b/include/automount.h
126 index 46cb6c6..1f14d5b 100644
127 --- a/include/automount.h
128 +++ b/include/automount.h
129 @@ -428,6 +428,9 @@ struct autofs_point {
130 struct list_head submounts; /* List of child submounts */
133 +/* Foreably unlink existing mounts at startup. */
134 +extern int do_force_unlink;
136 /* Standard functions used by daemon or modules */
138 #define MOUNT_OFFSET_OK 0
139 diff --git a/man/automount.8 b/man/automount.8
140 index d9285bf..9fcaaf4 100644
141 --- a/man/automount.8
142 +++ b/man/automount.8
143 @@ -84,6 +84,11 @@ path name as specified in the master map.
145 .I "\-C, \-\-dont-check-daemon"
146 Don't check if the daemon is currently running (see NOTES).
149 +Force an unlink umount of existing mounts under autofs managed mount points
150 +during startup. This can cause problems for processes with working directories
151 +within these mounts (see NOTES).
153 \fBautomount\fP takes one optional argument, the name of the master map to
155 @@ -132,6 +137,14 @@ for certain types of automount maps. The mounts of the seperate daemons
156 might interfere with one another. The implications of running multiple
157 daemon instances needs to be checked and tested before we can say this
160 +If the option to force an unlink of mounts at startup is used then processes
161 +whose working directory is within unlinked automounted directories will not
162 +get the correct pwd from the system. This is because, after the mount is
163 +unlinked from the mount tree, anything that needs to walk back up the mount
164 +tree to construct a path, such as getcwd(2) and the proc filesystem
165 +/proc/<pid>/cwd, cannot work because the point from which the path is
166 +constructed has been detached from the mount tree.
170 diff --git a/redhat/autofs.init.in b/redhat/autofs.init.in
171 index 65c786e..471667e 100644
172 --- a/redhat/autofs.init.in
173 +++ b/redhat/autofs.init.in
174 @@ -137,6 +137,10 @@ case "$1" in
179 + OPTIONS="$OPTIONS --force"
185 @@ -146,6 +150,10 @@ case "$1" in
190 + OPTIONS="$OPTIONS --force"
196 @@ -155,7 +163,7 @@ case "$1" in
200 - echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
201 + echo $"Usage: $0 {start|forcestart|stop|status|restart|orcerestart|reload|condrestart}"
205 diff --git a/samples/rc.autofs.in b/samples/rc.autofs.in
206 index 51f5b02..2877fe2 100644
207 --- a/samples/rc.autofs.in
208 +++ b/samples/rc.autofs.in
209 @@ -117,17 +117,25 @@ case "$1" in
214 + OPTIONS="$OPTIONS --force"
224 + OPTIONS="$OPTIONS --force"
231 - echo $"Usage: $0 {start|stop|restart|reload}"
232 + echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}"