From patchwork Fri Jul 29 05:03:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9252081 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 832CE601C0 for ; Fri, 29 Jul 2016 05:04:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 764D327F46 for ; Fri, 29 Jul 2016 05:04:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AE6727F96; Fri, 29 Jul 2016 05:04:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 095FB27F46 for ; Fri, 29 Jul 2016 05:04:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750962AbcG2FEz (ORCPT ); Fri, 29 Jul 2016 01:04:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:35090 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750835AbcG2FEy (ORCPT ); Fri, 29 Jul 2016 01:04:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2F1D0AAF2; Fri, 29 Jul 2016 05:04:53 +0000 (UTC) From: NeilBrown To: Steve Dickson Date: Fri, 29 Jul 2016 15:03:36 +1000 Subject: [PATCH 3/7] mount: don't treat temporary name resolution failure as permanent. Cc: "J. Bruce Fields" , Linux NFS Mailing list Message-ID: <146976861666.20186.10594715887070996846.stgit@noble> In-Reply-To: <146976807524.20186.8871903418718212567.stgit@noble> References: <146976807524.20186.8871903418718212567.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- utils/mount/stropts.c | 54 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c index d60b484ab960..9de6794c6177 100644 --- 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 */ @@ -371,39 +372,19 @@ static int nfs_set_version(struct nfsmount_info *mi) */ 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)) + if (!nfs_nfs_proto_family(mi->options, &mi->family)) 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 */ - if (mi->flags & MS_REMOUNT) { - po_remove_all(mi->options, "addr"); - } else { - 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; - return 0; - } - - if (!nfs_append_addr_option(mi->address->ai_addr, - mi->address->ai_addrlen, mi->options)) - return 0; - } + po_remove_all(mi->options, "addr"); if (!nfs_set_version(mi)) return 0; @@ -903,6 +884,32 @@ static int nfs_try_mount(struct nfsmount_info *mi) { 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.major) { case 2: case 3: @@ -941,6 +948,7 @@ static int nfs_is_permanent_error(int error) case ETIMEDOUT: case ECONNREFUSED: case EHOSTUNREACH: + case EAGAIN: return 0; /* temporary */ default: return 1; /* permanent */