All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: steved@redhat.com, linux-nfs@vger.kernel.org
Subject: Re: [PATCH 1/2] mount.nfs: Refactor mount version and protocol autonegotiation
Date: Mon, 13 Sep 2010 13:51:57 -0400	[thread overview]
Message-ID: <20100913175157.GC16253@fieldses.org> (raw)
In-Reply-To: <20100913171736.18926.97496.stgit-x+BlCsqV7M/wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>

On Mon, Sep 13, 2010 at 01:17:36PM -0400, Chuck Lever wrote:
> Clean up.
> 
> I'm beginning to agree with Bruce and Steve's assessment that the
> fallthrough switch case in nfs_try_mount() is more difficult to read
> and understand than it needs to be.  The logic that manages
> negotiating NFS version and protocol settings is getting more complex
> over time anyway.
> 
> So let's split the autonegotiation piece out of nfs_try_mount().
> 
> We can reduce indenting, and use cleaner switch-based logic.  Also,
> adding more comments can only help.

Looks OK to me, thanks.--b.

> 
> Neil also suggested replacing the pre-call "errno = 0" trick.  The
> lower-level functions may try to mount several times (given a list of
> addresses to try).  errno could be set by any of those.  The mount
> request will succeed at some point, and "success" is returned, but
> errno is still set to some non-zero value.
> 
> The kernel version check in nfs_try_mount() is more or less loop
> invariant: it's impossible for the result of that test to change
> between retries.  So we should be able to safely move it to the logic
> that sets the initial value of mi->version.
> 
> This patch is not supposed to cause a behavioral change.
> 
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> 
>  utils/mount/stropts.c |   67 +++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
> index c82ddfe..c5c4ba1 100644
> --- a/utils/mount/stropts.c
> +++ b/utils/mount/stropts.c
> @@ -304,6 +304,16 @@ static int nfs_set_version(struct nfsmount_info *mi)
>  		mi->version = 4;
>  
>  	/*
> +	 * Before 2.6.32, the kernel NFS client didn't
> +	 * support "-t nfs vers=4" mounts, so NFS version
> +	 * 4 cannot be included when autonegotiating
> +	 * while running on those kernels.
> +	 */
> +	if (mi->version == 0 &&
> +	    linux_version_code() <= MAKE_VERSION(2, 6, 31))
> +		mi->version = 3;
> +
> +	/*
>  	 * If we still don't know, check for version-specific
>  	 * mount options.
>  	 */
> @@ -746,6 +756,47 @@ static int nfs_try_mount_v4(struct nfsmount_info *mi)
>  }
>  
>  /*
> + * Handle NFS version and transport protocol
> + * autonegotiation.
> + *
> + * When no version or protocol is specified on the
> + * command line, mount.nfs negotiates with the server
> + * to determine appropriate settings for the new
> + * mount point.
> + *
> + * Returns TRUE if successful, otherwise FALSE.
> + * "errno" is set to reflect the individual error.
> + */
> +static int nfs_autonegotiate(struct nfsmount_info *mi)
> +{
> +	int result;
> +
> +	result = nfs_try_mount_v4(mi);
> +	if (result)
> +		return result;
> +		
> +	switch (errno) {
> +	case EPROTONOSUPPORT:
> +		/* A clear indication that the server or our
> +		 * client does not support NFS version 4. */
> +		goto fall_back;
> +	case ENOENT:
> +		/* Legacy Linux servers don't export an NFS
> +		 * version 4 pseudoroot. */
> +		goto fall_back;
> +	case EPERM:
> +		/* Linux servers prior to 2.6.25 may return
> +		 * EPERM when NFS version 4 is not supported. */
> +		goto fall_back;
> +	default:
> +		return result;
> +	}
> +
> +fall_back:
> +	return nfs_try_mount_v3v2(mi);
> +}
> +
> +/*
>   * This is a single pass through the fg/bg loop.
>   *
>   * Returns TRUE if successful, otherwise FALSE.
> @@ -757,20 +808,8 @@ static int nfs_try_mount(struct nfsmount_info *mi)
>  
>  	switch (mi->version) {
>  	case 0:
> -		if (linux_version_code() > MAKE_VERSION(2, 6, 31)) {
> -			errno = 0;
> -			result = nfs_try_mount_v4(mi);
> -			if (errno != EPROTONOSUPPORT) {
> -				/* 
> -				 * To deal with legacy Linux servers that don't
> -				 * automatically export a pseudo root, retry
> -				 * ENOENT errors using version 3. And for
> -				 * Linux servers prior to 2.6.25, retry EPERM
> -				 */
> -				if (errno != ENOENT && errno != EPERM)
> -					break;
> -			}
> -		}
> +		result = nfs_autonegotiate(mi);
> +		break;
>  	case 2:
>  	case 3:
>  		result = nfs_try_mount_v3v2(mi);
> 
> --
> 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

  parent reply	other threads:[~2010-09-13 17:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-13 17:17 [PATCH 0/2] Two more fixes for mount.nfs Chuck Lever
2010-09-13 17:17 ` [PATCH 1/2] mount.nfs: Refactor mount version and protocol autonegotiation Chuck Lever
     [not found]   ` <20100913171736.18926.97496.stgit-x+BlCsqV7M/wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2010-09-13 17:51     ` J. Bruce Fields [this message]
2010-09-13 17:17 ` [PATCH 2/2] mount.nfs: Don't do anything fancy if this is a remount Chuck Lever
     [not found] ` <20100913171100.18926.77712.stgit-x+BlCsqV7M/wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2010-09-14 19:49   ` [PATCH 0/2] Two more fixes for mount.nfs Jeff Layton
2010-09-16 12:00   ` Steve Dickson
  -- strict thread matches above, loose matches on Subject: below --
2010-08-31 19:11 [PATCH 0/2] Improvements to mount's autonegotiation Chuck Lever
2010-08-31 19:11 ` [PATCH 1/2] mount.nfs: Refactor mount version and protocol autonegotiation Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100913175157.GC16253@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.