File 0005-mount-don-t-treat-temporary-name-resolution-failure-.patch of Package nfs-utils.12699
From c5de9ba602fd10a236a2ed80c46e896c11eed63f Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.com>
Date: Thu, 14 Jul 2016 11:11:25 +1000
Subject: [PATCH] mount: don't treat temporary name resolution failure as
permanent.
If getaddrinfo() returns EAI_AGAIN, we shouldn't just give up, but
should continue normal retries as the nameserver may be unavailable
for the same reason as the NFS server.
So move the getaddrinfo() call from nfs_validate_options() into
nfs_try_mounts() which is always called soon after, except in the
'remount' case when we don't want it anyway.
If EAI_AGAIN is returned, set errno to EAGAIN and allow this to be a
temporary failure. Otherwise report error and set errno to EALREADY
so no further message is given.
Signed-off-by: NeilBrown <neilb@suse.com>
---
utils/mount/stropts.c | 56 ++++++++++++++++++++++++++++++++------------------
1 file changed, 36 insertions(+), 20 deletions(-)
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -84,6 +84,7 @@ struct nfsmount_info {
*type; /* "nfs" or "nfs4" */
char *hostname; /* server's hostname */
struct addrinfo *address; /* server's addresses */
+ sa_family_t family; /* Address family */
struct mount_options *options; /* parsed mount options */
char **extra_opts; /* string for /etc/mtab */
@@ -341,36 +342,24 @@ static int nfs_set_version(struct nfsmou
*/
static int nfs_validate_options(struct nfsmount_info *mi)
{
- struct addrinfo hint = {
- .ai_protocol = (int)IPPROTO_UDP,
- };
- sa_family_t family;
- int error;
-
if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
return 0;
- if (!nfs_nfs_proto_family(mi->options, &family))
- return 0;
-
- hint.ai_family = (int)family;
- error = getaddrinfo(mi->hostname, NULL, &hint, &mi->address);
- if (error != 0) {
- nfs_error(_("%s: Failed to resolve server %s: %s"),
- progname, mi->hostname, gai_strerror(error));
- mi->address = NULL;
+ if (!nfs_nfs_proto_family(mi->options, &mi->family))
return 0;
- }
if (!nfs_set_version(mi))
return 0;
if (!nfs_append_sloppy_option(mi->options))
return 0;
-
- if (!nfs_append_addr_option(mi->address->ai_addr,
- mi->address->ai_addrlen, mi->options))
- return 0;
+ /*
+ * A remount is not going to be able to change the server's address,
+ * nor should we try to resolve another address for the server as we
+ * may end up with a different address.
+ * A non-remount will set 'addr' from ->hostname
+ */
+ po_remove_all(mi->options, "addr");
return 1;
}
@@ -840,6 +829,32 @@ static int nfs_try_mount(struct nfsmount
{
int result = 0;
+ if (mi->address == NULL) {
+ struct addrinfo hint = {
+ .ai_protocol = (int)IPPROTO_UDP,
+ };
+ int error;
+ struct addrinfo *address;
+
+ hint.ai_family = (int)mi->family;
+ error = getaddrinfo(mi->hostname, NULL, &hint, &address);
+ if (error != 0) {
+ if (error == EAI_AGAIN)
+ errno = EAGAIN;
+ else {
+ nfs_error(_("%s: Failed to resolve server %s: %s"),
+ progname, mi->hostname, gai_strerror(error));
+ errno = EALREADY;
+ }
+ return 0;
+ }
+
+ if (!nfs_append_addr_option(address->ai_addr,
+ address->ai_addrlen, mi->options))
+ return 0;
+ mi->address = address;
+ }
+
switch (mi->version) {
case 0:
result = nfs_autonegotiate(mi);
@@ -878,6 +893,7 @@ static int nfs_is_permanent_error(int er
case ETIMEDOUT:
case ECONNREFUSED:
case EHOSTUNREACH:
+ case EAGAIN:
return 0; /* temporary */
default:
return 1; /* permanent */