1 diff -Nurp autofs-4.1.4.orig/modules/mount_nfs.c autofs-4.1.4/modules/mount_nfs.c
2 --- autofs-4.1.4.orig/modules/mount_nfs.c 2005-04-25 10:55:27.000000000 +0800
3 +++ autofs-4.1.4/modules/mount_nfs.c 2005-04-25 10:56:15.000000000 +0800
5 #include <netinet/in.h>
7 #include <linux/nfs2.h>
11 #include "automount.h"
12 @@ -105,28 +106,117 @@ int is_local_addr(const char *host, cons
18 + * If the entry doesn't contain a ',' or doesn't contain more than
19 + * one ':' then @what is not a replicated server entry.
21 +static int inline is_replicated_entry(char *what)
23 + return strchr(what, ',') ||
24 + (strchr(what, ':') != strrchr(what, ':'));
28 + * Check to see if the 'host:path' or 'host' is on the local machine
29 + * Returns < 0 if there is a host lookup problem, otherwise returns 0
30 + * if it's not a local mount, and returns > 0 if it is a local mount.
32 +int is_local_mount(const char *hostpath)
41 + debug(MODPREFIX "is_local_mount: %s", hostpath);
42 + delim = strpbrk(hostpath,":");
45 + hostnamelen = delim - hostpath;
47 + hostnamelen = strlen(hostpath);
49 + hostname = malloc(hostnamelen+1);
50 + strncpy(hostname, hostpath, hostnamelen);
51 + hostname[hostnamelen] = '\0';
52 + he = gethostbyname(hostname);
54 + error(MODPREFIX "host %s: lookup failure", hostname);
58 + for (haddr = he->h_addr_list; *haddr; haddr++) {
59 + local = is_local_addr(hostname, *haddr, he->h_length);
63 + debug(MODPREFIX "host %s: is localhost",
72 * Given a mount string, return (in the same string) the
73 - * best mount to use based on weight/locality/rpctime
74 + * best mount to use based on locality/weight/rpctime.
76 + * If longtimeout is set to 0 then we only do 100 ms pings to hosts. In
77 + * the event that this fails, we call ourself recursively with the
78 + * longtimeout option set to 1. In this case we ping for up to 10s and
79 + * skip logic for detecting if a localhost has been passed. (if a local
80 + * host had been passed, we would have returned that mount as the best
81 + * mount. The skipping of local maps in this case is an optimization).
83 * - return -1 and what = '\0' on error,
84 * 1 and what = local mount path if local bind,
85 * else 0 and what = remote mount path
87 -int get_best_mount(char *what, const char *original, int longtimeout, int skiplocal)
88 +int get_best_mount(char *what, const char *original, int longtimeout)
92 int winner_weight = INT_MAX, local = 0;
93 double winner_time = 0;
95 + char *delim, *pstrip;
96 int sec = (longtimeout) ? 10 : 0;
97 int micros = (longtimeout) ? 0 : 100000;
98 + int skiplocal = longtimeout; /* clearly local is not available */
106 + * If only one mountpoint has been passed in, we don't need to
107 + * do anything except strip whitespace from the end of the string.
109 + if (!is_replicated_entry(p)) {
110 + for (pstrip = p+strlen(p) - 1; pstrip >= p; pstrip--)
111 + if (isspace(*pstrip))
114 + /* Check if the host is the localhost */
115 + if (is_local_mount(p) > 0) {
116 + debug(MODPREFIX "host %s: is localhost", p);
118 + /* Strip off hostname and ':' */
119 + delim = strchr(p,':');
120 + while (delim && *delim != '\0') {
132 unsigned int ping_stat = 0;
133 @@ -171,37 +261,17 @@ int get_best_mount(char *what, const cha
134 /* p points to a server, "next is our next parse point */
136 /* Check if it's localhost */
137 - struct hostent *he;
140 - he = gethostbyname(p);
142 - error(MODPREFIX "host %s: lookup failure", p);
147 - /* Check each host in round robin list */
148 - for (haddr = he->h_addr_list; *haddr; haddr++) {
149 - local = is_local_addr(p, *haddr, he->h_length);
160 + local = is_local_mount(p);
174 /* ping each (or the) entry to see if it's alive. */
175 @@ -214,6 +284,7 @@ int get_best_mount(char *what, const cha
176 /* First unweighted or only host is alive so set winner */
180 /* No more to check, return it */
183 @@ -256,7 +327,7 @@ int get_best_mount(char *what, const cha
185 if (!local && winner_weight == INT_MAX) {
186 /* We had more than one contender and none responded in time */
187 - if (winner_time != 0 && winner_time > 500) {
188 + if (winner_time == 0 || winner_time > 500) {
189 /* We've already tried a longer timeout */
191 /* Reset string and try again */
192 @@ -267,16 +338,14 @@ int get_best_mount(char *what, const cha
193 "retrying with longer timeout",
196 - return get_best_mount(what, original, 1, 1);
197 + return get_best_mount(what, original, 1);
202 - /* No winner found so bail */
207 + /* No winner found so return first */
212 * We now have our winner, copy it to the front of the string,
213 @@ -395,7 +464,7 @@ int mount_mount(const char *root, const
214 /* No colon, take this as a bind (local) entry */
216 } else if (!nosymlink) {
217 - local = get_best_mount(whatstr, what, 0, 0);
218 + local = get_best_mount(whatstr, what, 0);
220 warn(MODPREFIX "no host elected");