X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fnfs4mount.c;h=028e7cd5447e16a8b20e50efa67ec703cca3f3d6;hp=8f95ab735966ebe10b2d70cdde6af45a07ffefa4;hb=HEAD;hpb=2f1ade1adf8074efbd661d41758d8844ab5f522e diff --git a/utils/mount/nfs4mount.c b/utils/mount/nfs4mount.c index 8f95ab7..028e7cd 100644 --- a/utils/mount/nfs4mount.c +++ b/utils/mount/nfs4mount.c @@ -18,6 +18,10 @@ * - Moved to nfs-utils/utils/mount from util-linux/mount. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -30,6 +34,7 @@ #include #include #include + #ifdef HAVE_RPCSVC_NFS_PROT_H #include #else @@ -41,6 +46,7 @@ #include "nls.h" #include "xcommon.h" +#include "mount.h" #include "mount_constants.h" #include "nfs4_mount.h" #include "nfs_mount.h" @@ -140,7 +146,7 @@ static int fill_ipv4_sockaddr(const char *hostname, struct sockaddr_in *addr) progname, hostname); return -1; } - if (hp->h_length > sizeof(struct in_addr)) { + if (hp->h_length > (int)sizeof(struct in_addr)) { nfs_error(_("%s: got bad hp->h_length"), progname); hp->h_length = sizeof(struct in_addr); } @@ -166,7 +172,7 @@ static int get_my_ipv4addr(char *ip_addr, int len) } int nfs4mount(const char *spec, const char *node, int flags, - char **extra_opts, int fake) + char **extra_opts, int fake, int running_bg) { static struct nfs4_mount_data data; static char hostdir[1024]; @@ -184,10 +190,9 @@ int nfs4mount(const char *spec, const char *node, int flags, int bg, soft, intr; int nocto, noac, unshared; int retry; - int retval; + int retval = EX_FAIL; time_t timeout, t; - retval = EX_FAIL; if (strlen(spec) >= sizeof(hostdir)) { nfs_error(_("%s: excessively long host:dir argument\n"), progname); @@ -212,8 +217,11 @@ int nfs4mount(const char *spec, const char *node, int flags, progname); goto fail; } - snprintf(new_opts, sizeof(new_opts), "%s%saddr=%s", - old_opts, *old_opts ? "," : "", s); + if (running_bg) + strncpy(new_opts, old_opts, sizeof(new_opts)); + else + snprintf(new_opts, sizeof(new_opts), "%s%saddr=%s", + old_opts, *old_opts ? "," : "", s); *extra_opts = xstrdup(new_opts); /* Set default options. @@ -234,7 +242,7 @@ int nfs4mount(const char *spec, const char *node, int flags, nocto = 0; noac = 0; unshared = 0; - retry = 10000; /* 10000 minutes ~ 1 week */ + retry = -1; /* * NFSv4 specifies that the default port should be 2049 @@ -328,6 +336,14 @@ int nfs4mount(const char *spec, const char *node, int flags, } } + /* if retry is still -1, then it wasn't set via an option */ + if (retry == -1) { + if (bg) + retry = 10000; /* 10000 mins == ~1 week */ + else + retry = 2; /* 2 min default on fg mounts */ + } + data.flags = (soft ? NFS4_MOUNT_SOFT : 0) | (intr ? NFS4_MOUNT_INTR : 0) | (nocto ? NFS4_MOUNT_NOCTO : 0) @@ -421,22 +437,31 @@ int nfs4mount(const char *spec, const char *node, int flags, break; } - switch(rpc_createerr.cf_stat){ - case RPC_TIMEDOUT: - break; - case RPC_SYSTEMERROR: - if (errno == ETIMEDOUT) + if (!bg) { + switch(rpc_createerr.cf_stat) { + case RPC_TIMEDOUT: break; - default: - mount_errors(hostname, 0, bg); + case RPC_SYSTEMERROR: + if (errno == ETIMEDOUT) + break; + default: + rpc_mount_errors(hostname, 0, bg); + goto fail; + } + } + + if (bg && !running_bg) { + if (retry > 0) + retval = EX_BG; goto fail; } + t = time(NULL); if (t >= timeout) { - mount_errors(hostname, 0, bg); + rpc_mount_errors(hostname, 0, bg); goto fail; } - mount_errors(hostname, 1, bg); + rpc_mount_errors(hostname, 1, bg); continue; } @@ -448,7 +473,7 @@ int nfs4mount(const char *spec, const char *node, int flags, } } - return 0; + return EX_SUCCESS; fail: return retval;