diff mbox series

[3/6] nfsd: Move error code mapping to per-version xdr code.

Message ID 20240726022538.32076-4-neilb@suse.de (mailing list archive)
State New
Headers show
Series nfsd: assorted clean-ups | expand

Commit Message

NeilBrown July 26, 2024, 2:21 a.m. UTC
There is code scatter around nfsd which chooses an error status based on
the particular version of nfs being used.  It is cleaner to have the
version specific choices in version specific code.

With this patch common code returns the most specific error code
possible and the version specific code maps that if necessary.

One complication is that the NFSv4 code NFS4ERR_SYMLINK might be used
where v3 expects NFSERR_NOTDIR of NFSERR_INVAL.  To handle this we
introduce an internal error code NFSERR_SYMLINK_NOT_DIR and convert that
as appropriate for all versions.

The selection of numbers for internal error codes was previously ad hoc.
Now it uses an enum which starts at the first unused error code.

NFSv4.1+ now returns NFS4ERR_WRONG_TYPE when that is appropriate.  It
previously returned NFS4ERR_SYMLINK as that seemed best for NFSv4.0.
According to RFC5661 15.1.2.9 NFSv4.0 was expected to return
NFSERR_INVAL in these cases, so that is how the code now behaves.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 fs/nfsd/export.c     |  2 +-
 fs/nfsd/nfs3xdr.c    | 17 +++++++++++++++++
 fs/nfsd/nfs4proc.c   | 11 +++--------
 fs/nfsd/nfs4xdr.c    | 15 +++++++++++++++
 fs/nfsd/nfsd.h       | 23 +++++++++++++++++++----
 fs/nfsd/nfsfh.c      | 26 ++++++++++----------------
 fs/nfsd/nfsxdr.c     | 19 +++++++++++++++++++
 fs/nfsd/vfs.c        | 14 ++++----------
 include/linux/nfs4.h |  3 +++
 9 files changed, 91 insertions(+), 39 deletions(-)

Comments

Chuck Lever July 26, 2024, 3:40 p.m. UTC | #1
On Thu, Jul 25, 2024 at 10:21:32PM -0400, NeilBrown wrote:
> There is code scatter around nfsd which chooses an error status based on
> the particular version of nfs being used.  It is cleaner to have the
> version specific choices in version specific code.
> 
> With this patch common code returns the most specific error code
> possible and the version specific code maps that if necessary.

I applaud the top-level goal of this patch. There are some details
that I'm not comfortable with. (And I've already applied the other
patches in this series; nice work).


> One complication is that the NFSv4 code NFS4ERR_SYMLINK might be used
> where v3 expects NFSERR_NOTDIR of NFSERR_INVAL.  To handle this we
> introduce an internal error code NFSERR_SYMLINK_NOT_DIR and convert that
> as appropriate for all versions.

IMO this patch is trying to do too much at once, both from a review
standpoint and also in terms of bisectability.

Can you break it up so that the SYMLINK-related changes are
separated from, eg, the xdev and other changes which are somewhat
less controversial?

More specific comments below.


> The selection of numbers for internal error codes was previously ad hoc.
> Now it uses an enum which starts at the first unused error code.
> 
> NFSv4.1+ now returns NFS4ERR_WRONG_TYPE when that is appropriate.  It
> previously returned NFS4ERR_SYMLINK as that seemed best for NFSv4.0.
> According to RFC5661 15.1.2.9 NFSv4.0 was expected to return
> NFSERR_INVAL in these cases, so that is how the code now behaves.
> 
> Signed-off-by: NeilBrown <neilb@suse.de>
> ---
>  fs/nfsd/export.c     |  2 +-
>  fs/nfsd/nfs3xdr.c    | 17 +++++++++++++++++
>  fs/nfsd/nfs4proc.c   | 11 +++--------
>  fs/nfsd/nfs4xdr.c    | 15 +++++++++++++++
>  fs/nfsd/nfsd.h       | 23 +++++++++++++++++++----
>  fs/nfsd/nfsfh.c      | 26 ++++++++++----------------
>  fs/nfsd/nfsxdr.c     | 19 +++++++++++++++++++
>  fs/nfsd/vfs.c        | 14 ++++----------
>  include/linux/nfs4.h |  3 +++
>  9 files changed, 91 insertions(+), 39 deletions(-)
> 
> diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
> index 9aa5f95f18a8..7bb4f2075ac5 100644
> --- a/fs/nfsd/export.c
> +++ b/fs/nfsd/export.c
> @@ -1121,7 +1121,7 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
>  		return 0;
>  
>  denied:
> -	return rqstp->rq_vers < 4 ? nfserr_acces : nfserr_wrongsec;
> +	return nfserr_wrongsec;
>  }
>  
>  /*
> diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> index a7a07470c1f8..8d75759c600d 100644
> --- a/fs/nfsd/nfs3xdr.c
> +++ b/fs/nfsd/nfs3xdr.c
> @@ -111,6 +111,23 @@ svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status)
>  {
>  	__be32 *p;
>  
> +	switch (status) {
> +	case nfserr_symlink_not_dir:
> +		status = nfserr_notdir;
> +		break;
> +	case nfserr_symlink:
> +	case nfserr_wrong_type:
> +		status = nfserr_inval;
> +		break;
> +	case nfserr_nofilehandle:
> +		status = nfserr_badhandle;
> +		break;
> +	case nfserr_wrongsec:
> +	case nfserr_file_open:
> +		status = nfserr_acces;
> +		break;
> +	}
> +

This is entirely the wrong place for this logic. It is specific to
symlinks, and it is not XDR layer functionality. I prefer to see
this moved to the proc functions that need it.

The layering here is that XDR should handle only data serialization.
Transformations like this go upstairs in the proc layer. I know NFSD
doesn't always adhere to this layering model, very often out of
convenience, but I want new code to try to stick to a stricter
layering model.

Again, the reason for this is that eventually much of the existing
XDR code will be replaced by machine-generated code. Adding bespoke
bits of logic here makes the task of converting this code more
difficult.


>  	p = xdr_reserve_space(xdr, sizeof(status));
>  	if (!p)
>  		return false;
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index d5ed01c72910..c4b65f747d8b 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -166,14 +166,9 @@ static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
>  		return nfs_ok;
>  	if (S_ISDIR(mode))
>  		return nfserr_isdir;
> -	/*
> -	 * Using err_symlink as our catch-all case may look odd; but
> -	 * there's no other obvious error for this case in 4.0, and we
> -	 * happen to know that it will cause the linux v4 client to do
> -	 * the right thing on attempts to open something other than a
> -	 * regular file.
> -	 */
> -	return nfserr_symlink;
> +	if (S_ISLNK(mode))
> +		return nfserr_symlink;
> +	return nfserr_wrong_type;
>  }
>  
>  static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index c7bfd2180e3f..117dea18cbc8 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -5748,6 +5748,14 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
>  
>  	if (op->opnum == OP_ILLEGAL)
>  		goto status;
> +
> +	if (op->status == nfserr_wrong_type &&
> +	    resp->cstate.minorversion == 0)
> +		/* RFC5661 - 15.1.2.9 */
> +		op->status = nfserr_inval;
> +	if (op->status == nfserr_symlink_not_dir)
> +		op->status = nfserr_symlink;
> +

Ditto here.


>  	if (op->status && opdesc &&
>  			!(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE))
>  		goto status;
> @@ -5870,6 +5878,13 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
>  	 */
>  	p = resp->statusp;
>  
> +	if (resp->cstate.status == nfserr_wrong_type &&
> +	    resp->cstate.minorversion == 0)
> +		/* RFC5661 - 15.1.2.9 */
> +		resp->cstate.status = nfserr_inval;
> +	if (resp->cstate.status == nfserr_symlink_not_dir)
> +		resp->cstate.status = nfserr_symlink;
> +

And here.

>  	*p++ = resp->cstate.status;
>  	*p++ = htonl(resp->taglen);
>  	memcpy(p, resp->tag, resp->taglen);
> diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
> index 8f4f239d9f8a..0f499066aa72 100644
> --- a/fs/nfsd/nfsd.h
> +++ b/fs/nfsd/nfsd.h
> @@ -327,16 +327,31 @@ void		nfsd_lockd_shutdown(void);
>  #define nfserr_noxattr			cpu_to_be32(NFS4ERR_NOXATTR)
>  
>  /* error codes for internal use */
> +enum {
> +	NFSERR_DROPIT = NFS4ERR_FIRST_FREE,
>  /* if a request fails due to kmalloc failure, it gets dropped.
>   *  Client should resend eventually
>   */
> -#define	nfserr_dropit		cpu_to_be32(30000)
> +#define	nfserr_dropit		cpu_to_be32(NFSERR_DROPIT)
> +
>  /* end-of-file indicator in readdir */
> -#define	nfserr_eof		cpu_to_be32(30001)
> +	NFSERR_EOF,
> +#define	nfserr_eof		cpu_to_be32(NFSERR_EOF)
> +
>  /* replay detected */
> -#define	nfserr_replay_me	cpu_to_be32(11001)
> +	NFSERR_REPLAY_ME,
> +#define	nfserr_replay_me	cpu_to_be32(NFSERR_REPLAY_ME)
> +
>  /* nfs41 replay detected */
> -#define	nfserr_replay_cache	cpu_to_be32(11002)
> +	NFSERR_REPLAY_CACHE,
> +#define	nfserr_replay_cache	cpu_to_be32(NFSERR_REPLAY_CACHE)
> +
> +/* symlink found where dir expected - handled differently to
> + * other symlink found errors by NSv3.

^NSv3^NFSv3


> + */
> +	NFSERR_SYMLINK_NOT_DIR,
> +#define	nfserr_symlink_not_dir	cpu_to_be32(NFSERR_SYMLINK_NOT_DIR)
> +};

It's confusing to me that we're using the same naming scheme for
symbolic status codes defined by spec and the ones defined for
internal use only. It would be nice to rename these, say, with an
_INT_ or _INTL_ in their name somewhere.

A short comment that explains why these /internal/ error codes need
big-endian versions would be helpful to add. I assume it's because
they will be stored or returned via a __be32 result that actually
does sometimes carry an on-the-wire status code.

As a note about patch series organization, it would be helpful to
split this hunk into a separate, preceding patch, IMO.


>  /* Check for dir entries '.' and '..' */
>  #define isdotent(n, l)	(l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
> diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
> index a485d630d10e..8fb56e2f896c 100644
> --- a/fs/nfsd/nfsfh.c
> +++ b/fs/nfsd/nfsfh.c
> @@ -62,8 +62,7 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)
>   * the write call).
>   */
>  static inline __be32
> -nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
> -		umode_t requested)
> +nfsd_mode_check(struct dentry *dentry, umode_t requested)
>  {
>  	umode_t mode = d_inode(dentry)->i_mode & S_IFMT;
>  
> @@ -76,17 +75,16 @@ nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
>  		}
>  		return nfs_ok;
>  	}
> -	/*
> -	 * v4 has an error more specific than err_notdir which we should
> -	 * return in preference to err_notdir:
> -	 */
> -	if (rqstp->rq_vers == 4 && mode == S_IFLNK)
> +	if (mode == S_IFLNK) {
> +		if (requested == S_IFDIR)
> +			return nfserr_symlink_not_dir;
>  		return nfserr_symlink;
> +	}
>  	if (requested == S_IFDIR)
>  		return nfserr_notdir;
>  	if (mode == S_IFDIR)
>  		return nfserr_isdir;
> -	return nfserr_inval;
> +	return nfserr_wrong_type;
>  }
>  
>  static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
> @@ -162,10 +160,8 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
>  	int len;
>  	__be32 error;
>  
> -	error = nfserr_stale;
> -	if (rqstp->rq_vers > 2)
> -		error = nfserr_badhandle;
> -	if (rqstp->rq_vers == 4 && fh->fh_size == 0)
> +	error = nfserr_badhandle;
> +	if (fh->fh_size == 0)
>  		return nfserr_nofilehandle;
>  
>  	if (fh->fh_version != 1)
> @@ -239,9 +235,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
>  	/*
>  	 * Look up the dentry using the NFS file handle.
>  	 */
> -	error = nfserr_stale;
> -	if (rqstp->rq_vers > 2)
> -		error = nfserr_badhandle;
> +	error = nfserr_badhandle;
>  
>  	fileid_type = fh->fh_fileid_type;
>  
> @@ -368,7 +362,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
>  	if (error)
>  		goto out;
>  
> -	error = nfsd_mode_check(rqstp, dentry, type);
> +	error = nfsd_mode_check(dentry, type);
>  	if (error)
>  		goto out;
>  
> diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
> index 5777f40c7353..9bb306bdc225 100644
> --- a/fs/nfsd/nfsxdr.c
> +++ b/fs/nfsd/nfsxdr.c
> @@ -38,6 +38,25 @@ svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status)
>  {
>  	__be32 *p;
>  
> +	switch (status) {
> +	case nfserr_symlink_not_dir:
> +		status = nfserr_notdir;
> +		break;
> +	case nfserr_symlink:
> +	case nfserr_wrong_type:
> +		status = nfserr_inval;
> +		break;
> +	case nfserr_nofilehandle:
> +	case nfserr_badhandle:
> +		status = nfserr_stale;
> +		break;
> +	case nfserr_wrongsec:
> +	case nfserr_xdev:
> +	case nfserr_file_open:
> +		status = nfserr_acces;
> +		break;
> +	}
> +

Same comment as above.


>  	p = xdr_reserve_space(xdr, sizeof(status));
>  	if (!p)
>  		return false;
> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 0862f6ae86a9..cf96a2ef6533 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
> @@ -1770,10 +1770,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
>  		if (!err)
>  			err = nfserrno(commit_metadata(tfhp));
>  	} else {
> -		if (host_err == -EXDEV && rqstp->rq_vers == 2)
> -			err = nfserr_acces;
> -		else
> -			err = nfserrno(host_err);
> +		err = nfserrno(host_err);
>  	}
>  	dput(dnew);
>  out_drop_write:
> @@ -1839,7 +1836,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
>  	if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
>  		goto out;
>  
> -	err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
> +	err = nfserr_xdev;
>  	if (ffhp->fh_export->ex_path.mnt != tfhp->fh_export->ex_path.mnt)
>  		goto out;
>  	if (ffhp->fh_export->ex_path.dentry != tfhp->fh_export->ex_path.dentry)
> @@ -1854,7 +1851,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
>  
>  	trap = lock_rename(tdentry, fdentry);
>  	if (IS_ERR(trap)) {
> -		err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
> +		err = nfserr_xdev;
>  		goto out_want_write;
>  	}
>  	err = fh_fill_pre_attrs(ffhp);
> @@ -2023,10 +2020,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
>  		/* name is mounted-on. There is no perfect
>  		 * error status.
>  		 */
> -		if (nfsd_v4client(rqstp))
> -			err = nfserr_file_open;
> -		else
> -			err = nfserr_acces;
> +		err = nfserr_file_open;
>  	} else {
>  		err = nfserrno(host_err);
>  	}
> diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
> index 0d896ce296ce..04dad965fa66 100644
> --- a/include/linux/nfs4.h
> +++ b/include/linux/nfs4.h
> @@ -290,6 +290,9 @@ enum nfsstat4 {
>  	/* xattr (RFC8276) */
>  	NFS4ERR_NOXATTR        = 10095,
>  	NFS4ERR_XATTR2BIG      = 10096,
> +
> +	/* can be used for internal errors */
> +	NFS4ERR_FIRST_FREE
>  };
>  
>  /* error codes for internal client use */
> -- 
> 2.44.0
>
NeilBrown July 26, 2024, 10:07 p.m. UTC | #2
On Sat, 27 Jul 2024, Chuck Lever wrote:
> On Thu, Jul 25, 2024 at 10:21:32PM -0400, NeilBrown wrote:
> > There is code scatter around nfsd which chooses an error status based on
> > the particular version of nfs being used.  It is cleaner to have the
> > version specific choices in version specific code.
> > 
> > With this patch common code returns the most specific error code
> > possible and the version specific code maps that if necessary.
> 
> I applaud the top-level goal of this patch. There are some details
> that I'm not comfortable with. (And I've already applied the other
> patches in this series; nice work).
> 
> 
> > One complication is that the NFSv4 code NFS4ERR_SYMLINK might be used
> > where v3 expects NFSERR_NOTDIR of NFSERR_INVAL.  To handle this we
> > introduce an internal error code NFSERR_SYMLINK_NOT_DIR and convert that
> > as appropriate for all versions.
> 
> IMO this patch is trying to do too much at once, both from a review
> standpoint and also in terms of bisectability.
> 
> Can you break it up so that the SYMLINK-related changes are
> separated from, eg, the xdev and other changes which are somewhat
> less controversial?

Yes, I can break it up as you suggest - makes sense.

> 
> More specific comments below.
> 
> 

> > diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> > index a7a07470c1f8..8d75759c600d 100644
> > --- a/fs/nfsd/nfs3xdr.c
> > +++ b/fs/nfsd/nfs3xdr.c
> > @@ -111,6 +111,23 @@ svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status)
> >  {
> >  	__be32 *p;
> >  
> > +	switch (status) {
> > +	case nfserr_symlink_not_dir:
> > +		status = nfserr_notdir;
> > +		break;
> > +	case nfserr_symlink:
> > +	case nfserr_wrong_type:
> > +		status = nfserr_inval;
> > +		break;
> > +	case nfserr_nofilehandle:
> > +		status = nfserr_badhandle;
> > +		break;
> > +	case nfserr_wrongsec:
> > +	case nfserr_file_open:
> > +		status = nfserr_acces;
> > +		break;
> > +	}
> > +
> 
> This is entirely the wrong place for this logic. It is specific to
> symlinks, and it is not XDR layer functionality. I prefer to see
> this moved to the proc functions that need it.

The logic in not specific to symlinks.  It is specific to RPC procedures
which act on things that are not expected to be symlinks.  There are
lots of procedures like that.

We could put the mapping in each .pc_func function, or between the
proc->pc_func() call in nfsd_dispatch() and the following
proc->pc_encode() call, or in each .pc_encode call.

Putting it in each .pc_func would mean changing the "return status;" at
the end of each nfs3_proc_* function to "return map_status(status);"

Putting it between ->pc_func() and ->pc_encode() would mean defining a
new ->pc_map_status() for each program/version and calling that.

Putting it in each .pc_encode is what I did.

It isn't clear to me that either of the first two are better than the
third, but neither are terrible.  However the second wouldn't work for
NFSv4.0 mapping (as individual ops need to be mapped).  But v4.0 needs
special handling anyway.

Where would you prefer I put it?

> 
> The layering here is that XDR should handle only data serialization.
> Transformations like this go upstairs in the proc layer. I know NFSD
> doesn't always adhere to this layering model, very often out of
> convenience, but I want new code to try to stick to a stricter
> layering model.
> 
> Again, the reason for this is that eventually much of the existing
> XDR code will be replaced by machine-generated code. Adding bespoke
> bits of logic here makes the task of converting this code more
> difficult.

I suspect it we won't be able to avoid the machine generated code
occasionally calling bespoke code - but we won't know until we try.

> >  
> >  /* error codes for internal use */
> > +enum {
> > +	NFSERR_DROPIT = NFS4ERR_FIRST_FREE,
> >  /* if a request fails due to kmalloc failure, it gets dropped.
> >   *  Client should resend eventually
> >   */
> > -#define	nfserr_dropit		cpu_to_be32(30000)
> > +#define	nfserr_dropit		cpu_to_be32(NFSERR_DROPIT)
> > +
> >  /* end-of-file indicator in readdir */
> > -#define	nfserr_eof		cpu_to_be32(30001)
> > +	NFSERR_EOF,
> > +#define	nfserr_eof		cpu_to_be32(NFSERR_EOF)
> > +
> >  /* replay detected */
> > -#define	nfserr_replay_me	cpu_to_be32(11001)
> > +	NFSERR_REPLAY_ME,
> > +#define	nfserr_replay_me	cpu_to_be32(NFSERR_REPLAY_ME)
> > +
> >  /* nfs41 replay detected */
> > -#define	nfserr_replay_cache	cpu_to_be32(11002)
> > +	NFSERR_REPLAY_CACHE,
> > +#define	nfserr_replay_cache	cpu_to_be32(NFSERR_REPLAY_CACHE)
> > +
> > +/* symlink found where dir expected - handled differently to
> > + * other symlink found errors by NSv3.
> 
> ^NSv3^NFSv3
> 

Thanks.

> 
> > + */
> > +	NFSERR_SYMLINK_NOT_DIR,
> > +#define	nfserr_symlink_not_dir	cpu_to_be32(NFSERR_SYMLINK_NOT_DIR)
> > +};
> 
> It's confusing to me that we're using the same naming scheme for
> symbolic status codes defined by spec and the ones defined for
> internal use only. It would be nice to rename these, say, with an
> _INT_ or _INTL_ in their name somewhere.

Well the spec say v4 statuses start NFS4ERR_ but we don't follow that.
It isn't clear to me that disambiguation the name would help.  At the
point where the error is returned the important thing is what the error
means, that that is spelt out in the text after nfserr_*.  At the point
where the error is interpreted the meaning is obvious in the code.
From the perspective of NFSv2, nfserr_xdev is an internal error code.
From the perspective of NFSv3 it is not.  Should it have 'int'?]

But if you really want this and you can tell me exactly where you want
the INT or INTL (and presumably int or intl for the be32 version) I'll do it.

> 
> A short comment that explains why these /internal/ error codes need
> big-endian versions would be helpful to add. I assume it's because
> they will be stored or returned via a __be32 result that actually
> does sometimes carry an on-the-wire status code.

Yes exactly.  I'll add some text like that.

Thanks,
NeilBrown

> 
> As a note about patch series organization, it would be helpful to
> split this hunk into a separate, preceding patch, IMO.
> 
> 
> >  /* Check for dir entries '.' and '..' */
> >  #define isdotent(n, l)	(l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
> > diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
> > index a485d630d10e..8fb56e2f896c 100644
> > --- a/fs/nfsd/nfsfh.c
> > +++ b/fs/nfsd/nfsfh.c
> > @@ -62,8 +62,7 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)
> >   * the write call).
> >   */
> >  static inline __be32
> > -nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
> > -		umode_t requested)
> > +nfsd_mode_check(struct dentry *dentry, umode_t requested)
> >  {
> >  	umode_t mode = d_inode(dentry)->i_mode & S_IFMT;
> >  
> > @@ -76,17 +75,16 @@ nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
> >  		}
> >  		return nfs_ok;
> >  	}
> > -	/*
> > -	 * v4 has an error more specific than err_notdir which we should
> > -	 * return in preference to err_notdir:
> > -	 */
> > -	if (rqstp->rq_vers == 4 && mode == S_IFLNK)
> > +	if (mode == S_IFLNK) {
> > +		if (requested == S_IFDIR)
> > +			return nfserr_symlink_not_dir;
> >  		return nfserr_symlink;
> > +	}
> >  	if (requested == S_IFDIR)
> >  		return nfserr_notdir;
> >  	if (mode == S_IFDIR)
> >  		return nfserr_isdir;
> > -	return nfserr_inval;
> > +	return nfserr_wrong_type;
> >  }
> >  
> >  static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
> > @@ -162,10 +160,8 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
> >  	int len;
> >  	__be32 error;
> >  
> > -	error = nfserr_stale;
> > -	if (rqstp->rq_vers > 2)
> > -		error = nfserr_badhandle;
> > -	if (rqstp->rq_vers == 4 && fh->fh_size == 0)
> > +	error = nfserr_badhandle;
> > +	if (fh->fh_size == 0)
> >  		return nfserr_nofilehandle;
> >  
> >  	if (fh->fh_version != 1)
> > @@ -239,9 +235,7 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
> >  	/*
> >  	 * Look up the dentry using the NFS file handle.
> >  	 */
> > -	error = nfserr_stale;
> > -	if (rqstp->rq_vers > 2)
> > -		error = nfserr_badhandle;
> > +	error = nfserr_badhandle;
> >  
> >  	fileid_type = fh->fh_fileid_type;
> >  
> > @@ -368,7 +362,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
> >  	if (error)
> >  		goto out;
> >  
> > -	error = nfsd_mode_check(rqstp, dentry, type);
> > +	error = nfsd_mode_check(dentry, type);
> >  	if (error)
> >  		goto out;
> >  
> > diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
> > index 5777f40c7353..9bb306bdc225 100644
> > --- a/fs/nfsd/nfsxdr.c
> > +++ b/fs/nfsd/nfsxdr.c
> > @@ -38,6 +38,25 @@ svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status)
> >  {
> >  	__be32 *p;
> >  
> > +	switch (status) {
> > +	case nfserr_symlink_not_dir:
> > +		status = nfserr_notdir;
> > +		break;
> > +	case nfserr_symlink:
> > +	case nfserr_wrong_type:
> > +		status = nfserr_inval;
> > +		break;
> > +	case nfserr_nofilehandle:
> > +	case nfserr_badhandle:
> > +		status = nfserr_stale;
> > +		break;
> > +	case nfserr_wrongsec:
> > +	case nfserr_xdev:
> > +	case nfserr_file_open:
> > +		status = nfserr_acces;
> > +		break;
> > +	}
> > +
> 
> Same comment as above.
> 
> 
> >  	p = xdr_reserve_space(xdr, sizeof(status));
> >  	if (!p)
> >  		return false;
> > diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> > index 0862f6ae86a9..cf96a2ef6533 100644
> > --- a/fs/nfsd/vfs.c
> > +++ b/fs/nfsd/vfs.c
> > @@ -1770,10 +1770,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
> >  		if (!err)
> >  			err = nfserrno(commit_metadata(tfhp));
> >  	} else {
> > -		if (host_err == -EXDEV && rqstp->rq_vers == 2)
> > -			err = nfserr_acces;
> > -		else
> > -			err = nfserrno(host_err);
> > +		err = nfserrno(host_err);
> >  	}
> >  	dput(dnew);
> >  out_drop_write:
> > @@ -1839,7 +1836,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
> >  	if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
> >  		goto out;
> >  
> > -	err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
> > +	err = nfserr_xdev;
> >  	if (ffhp->fh_export->ex_path.mnt != tfhp->fh_export->ex_path.mnt)
> >  		goto out;
> >  	if (ffhp->fh_export->ex_path.dentry != tfhp->fh_export->ex_path.dentry)
> > @@ -1854,7 +1851,7 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
> >  
> >  	trap = lock_rename(tdentry, fdentry);
> >  	if (IS_ERR(trap)) {
> > -		err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
> > +		err = nfserr_xdev;
> >  		goto out_want_write;
> >  	}
> >  	err = fh_fill_pre_attrs(ffhp);
> > @@ -2023,10 +2020,7 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
> >  		/* name is mounted-on. There is no perfect
> >  		 * error status.
> >  		 */
> > -		if (nfsd_v4client(rqstp))
> > -			err = nfserr_file_open;
> > -		else
> > -			err = nfserr_acces;
> > +		err = nfserr_file_open;
> >  	} else {
> >  		err = nfserrno(host_err);
> >  	}
> > diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
> > index 0d896ce296ce..04dad965fa66 100644
> > --- a/include/linux/nfs4.h
> > +++ b/include/linux/nfs4.h
> > @@ -290,6 +290,9 @@ enum nfsstat4 {
> >  	/* xattr (RFC8276) */
> >  	NFS4ERR_NOXATTR        = 10095,
> >  	NFS4ERR_XATTR2BIG      = 10096,
> > +
> > +	/* can be used for internal errors */
> > +	NFS4ERR_FIRST_FREE
> >  };
> >  
> >  /* error codes for internal client use */
> > -- 
> > 2.44.0
> > 
> 
> -- 
> Chuck Lever
>
Chuck Lever July 27, 2024, 4:25 p.m. UTC | #3
On Sat, Jul 27, 2024 at 08:07:12AM +1000, NeilBrown wrote:
> On Sat, 27 Jul 2024, Chuck Lever wrote:
> > On Thu, Jul 25, 2024 at 10:21:32PM -0400, NeilBrown wrote:

> > > diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
> > > index a7a07470c1f8..8d75759c600d 100644
> > > --- a/fs/nfsd/nfs3xdr.c
> > > +++ b/fs/nfsd/nfs3xdr.c
> > > @@ -111,6 +111,23 @@ svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status)
> > >  {
> > >  	__be32 *p;
> > >  
> > > +	switch (status) {
> > > +	case nfserr_symlink_not_dir:
> > > +		status = nfserr_notdir;
> > > +		break;
> > > +	case nfserr_symlink:
> > > +	case nfserr_wrong_type:
> > > +		status = nfserr_inval;
> > > +		break;
> > > +	case nfserr_nofilehandle:
> > > +		status = nfserr_badhandle;
> > > +		break;
> > > +	case nfserr_wrongsec:
> > > +	case nfserr_file_open:
> > > +		status = nfserr_acces;
> > > +		break;
> > > +	}
> > > +
> > 
> > This is entirely the wrong place for this logic. It is specific to
> > symlinks, and it is not XDR layer functionality. I prefer to see
> > this moved to the proc functions that need it.
> 
> The logic in not specific to symlinks.  It is specific to RPC procedures
> which act on things that are not expected to be symlinks.  There are
> lots of procedures like that.

Fair enough.

IMO, it will help our review to see exactly which procedures are
impacted. That suggests to me that moving the impact into specific
procedures will also make the design less brittle overall, but
that's just intuition at this point.


> We could put the mapping in each .pc_func function, or between the
> proc->pc_func() call in nfsd_dispatch() and the following
> proc->pc_encode() call, or in each .pc_encode call.
> 
> Putting it in each .pc_func would mean changing the "return status;" at
> the end of each nfs3_proc_* function to "return map_status(status);"
> 
> Putting it between ->pc_func() and ->pc_encode() would mean defining a
> new ->pc_map_status() for each program/version and calling that.
> 
> Putting it in each .pc_encode is what I did.
> 
> It isn't clear to me that either of the first two are better than the
> third, but neither are terrible.  However the second wouldn't work for
> NFSv4.0 mapping (as individual ops need to be mapped).  But v4.0 needs
> special handling anyway.
> 
> Where would you prefer I put it?

My thought was to put the status code mapping in the proc->pc_func
calls themselves. It sounds like that will work for NFSv4 too.

If this arrangement is too ugly for words we can rethink.


> > The layering here is that XDR should handle only data serialization.
> > Transformations like this go upstairs in the proc layer. I know NFSD
> > doesn't always adhere to this layering model, very often out of
> > convenience, but I want new code to try to stick to a stricter
> > layering model.
> > 
> > Again, the reason for this is that eventually much of the existing
> > XDR code will be replaced by machine-generated code. Adding bespoke
> > bits of logic here makes the task of converting this code more
> > difficult.
> 
> I suspect it we won't be able to avoid the machine generated code
> occasionally calling bespoke code - but we won't know until we try.

I think there are lots of simple encode/decode functions that will
work fine immediately with generated code. There are some areas
that will need plenty of massage. There are some spots that won't
work at all. I'm not planning for perfect coverage ;-)

(And, like a duck, I mention this plan every so often while gliding
along smoothly, but my little webbed feet are paddling away
furiously under the water's surface working on this project. Stay
tuned.)


> > It's confusing to me that we're using the same naming scheme for
> > symbolic status codes defined by spec and the ones defined for
> > internal use only. It would be nice to rename these, say, with an
> > _INT_ or _INTL_ in their name somewhere.
> 
> Well the spec say v4 statuses start NFS4ERR_ but we don't follow that.
> It isn't clear to me that disambiguation the name would help.  At the
> point where the error is returned the important thing is what the error
> means, that that is spelt out in the text after nfserr_*.  At the point
> where the error is interpreted the meaning is obvious in the code.
> From the perspective of NFSv2, nfserr_xdev is an internal error code.
> From the perspective of NFSv3 it is not.  Should it have 'int'?]
> 
> But if you really want this and you can tell me exactly where you want
> the INT or INTL (and presumably int or intl for the be32 version) I'll do it.

Points taken. Let's postpone renaming for now. If the symbol naming
scheme is still vexing me in a few weeks, I will write a patch for
it.


> > A short comment that explains why these /internal/ error codes need
> > big-endian versions would be helpful to add. I assume it's because
> > they will be stored or returned via a __be32 result that actually
> > does sometimes carry an on-the-wire status code.
> 
> Yes exactly.  I'll add some text like that.

Thanks for your feedback.
diff mbox series

Patch

diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 9aa5f95f18a8..7bb4f2075ac5 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1121,7 +1121,7 @@  __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
 		return 0;
 
 denied:
-	return rqstp->rq_vers < 4 ? nfserr_acces : nfserr_wrongsec;
+	return nfserr_wrongsec;
 }
 
 /*
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index a7a07470c1f8..8d75759c600d 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -111,6 +111,23 @@  svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status)
 {
 	__be32 *p;
 
+	switch (status) {
+	case nfserr_symlink_not_dir:
+		status = nfserr_notdir;
+		break;
+	case nfserr_symlink:
+	case nfserr_wrong_type:
+		status = nfserr_inval;
+		break;
+	case nfserr_nofilehandle:
+		status = nfserr_badhandle;
+		break;
+	case nfserr_wrongsec:
+	case nfserr_file_open:
+		status = nfserr_acces;
+		break;
+	}
+
 	p = xdr_reserve_space(xdr, sizeof(status));
 	if (!p)
 		return false;
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index d5ed01c72910..c4b65f747d8b 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -166,14 +166,9 @@  static __be32 nfsd_check_obj_isreg(struct svc_fh *fh)
 		return nfs_ok;
 	if (S_ISDIR(mode))
 		return nfserr_isdir;
-	/*
-	 * Using err_symlink as our catch-all case may look odd; but
-	 * there's no other obvious error for this case in 4.0, and we
-	 * happen to know that it will cause the linux v4 client to do
-	 * the right thing on attempts to open something other than a
-	 * regular file.
-	 */
-	return nfserr_symlink;
+	if (S_ISLNK(mode))
+		return nfserr_symlink;
+	return nfserr_wrong_type;
 }
 
 static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index c7bfd2180e3f..117dea18cbc8 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -5748,6 +5748,14 @@  nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
 
 	if (op->opnum == OP_ILLEGAL)
 		goto status;
+
+	if (op->status == nfserr_wrong_type &&
+	    resp->cstate.minorversion == 0)
+		/* RFC5661 - 15.1.2.9 */
+		op->status = nfserr_inval;
+	if (op->status == nfserr_symlink_not_dir)
+		op->status = nfserr_symlink;
+
 	if (op->status && opdesc &&
 			!(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE))
 		goto status;
@@ -5870,6 +5878,13 @@  nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 	 */
 	p = resp->statusp;
 
+	if (resp->cstate.status == nfserr_wrong_type &&
+	    resp->cstate.minorversion == 0)
+		/* RFC5661 - 15.1.2.9 */
+		resp->cstate.status = nfserr_inval;
+	if (resp->cstate.status == nfserr_symlink_not_dir)
+		resp->cstate.status = nfserr_symlink;
+
 	*p++ = resp->cstate.status;
 	*p++ = htonl(resp->taglen);
 	memcpy(p, resp->tag, resp->taglen);
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 8f4f239d9f8a..0f499066aa72 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -327,16 +327,31 @@  void		nfsd_lockd_shutdown(void);
 #define nfserr_noxattr			cpu_to_be32(NFS4ERR_NOXATTR)
 
 /* error codes for internal use */
+enum {
+	NFSERR_DROPIT = NFS4ERR_FIRST_FREE,
 /* if a request fails due to kmalloc failure, it gets dropped.
  *  Client should resend eventually
  */
-#define	nfserr_dropit		cpu_to_be32(30000)
+#define	nfserr_dropit		cpu_to_be32(NFSERR_DROPIT)
+
 /* end-of-file indicator in readdir */
-#define	nfserr_eof		cpu_to_be32(30001)
+	NFSERR_EOF,
+#define	nfserr_eof		cpu_to_be32(NFSERR_EOF)
+
 /* replay detected */
-#define	nfserr_replay_me	cpu_to_be32(11001)
+	NFSERR_REPLAY_ME,
+#define	nfserr_replay_me	cpu_to_be32(NFSERR_REPLAY_ME)
+
 /* nfs41 replay detected */
-#define	nfserr_replay_cache	cpu_to_be32(11002)
+	NFSERR_REPLAY_CACHE,
+#define	nfserr_replay_cache	cpu_to_be32(NFSERR_REPLAY_CACHE)
+
+/* symlink found where dir expected - handled differently to
+ * other symlink found errors by NSv3.
+ */
+	NFSERR_SYMLINK_NOT_DIR,
+#define	nfserr_symlink_not_dir	cpu_to_be32(NFSERR_SYMLINK_NOT_DIR)
+};
 
 /* Check for dir entries '.' and '..' */
 #define isdotent(n, l)	(l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index a485d630d10e..8fb56e2f896c 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -62,8 +62,7 @@  static int nfsd_acceptable(void *expv, struct dentry *dentry)
  * the write call).
  */
 static inline __be32
-nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
-		umode_t requested)
+nfsd_mode_check(struct dentry *dentry, umode_t requested)
 {
 	umode_t mode = d_inode(dentry)->i_mode & S_IFMT;
 
@@ -76,17 +75,16 @@  nfsd_mode_check(struct svc_rqst *rqstp, struct dentry *dentry,
 		}
 		return nfs_ok;
 	}
-	/*
-	 * v4 has an error more specific than err_notdir which we should
-	 * return in preference to err_notdir:
-	 */
-	if (rqstp->rq_vers == 4 && mode == S_IFLNK)
+	if (mode == S_IFLNK) {
+		if (requested == S_IFDIR)
+			return nfserr_symlink_not_dir;
 		return nfserr_symlink;
+	}
 	if (requested == S_IFDIR)
 		return nfserr_notdir;
 	if (mode == S_IFDIR)
 		return nfserr_isdir;
-	return nfserr_inval;
+	return nfserr_wrong_type;
 }
 
 static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)
@@ -162,10 +160,8 @@  static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
 	int len;
 	__be32 error;
 
-	error = nfserr_stale;
-	if (rqstp->rq_vers > 2)
-		error = nfserr_badhandle;
-	if (rqstp->rq_vers == 4 && fh->fh_size == 0)
+	error = nfserr_badhandle;
+	if (fh->fh_size == 0)
 		return nfserr_nofilehandle;
 
 	if (fh->fh_version != 1)
@@ -239,9 +235,7 @@  static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
 	/*
 	 * Look up the dentry using the NFS file handle.
 	 */
-	error = nfserr_stale;
-	if (rqstp->rq_vers > 2)
-		error = nfserr_badhandle;
+	error = nfserr_badhandle;
 
 	fileid_type = fh->fh_fileid_type;
 
@@ -368,7 +362,7 @@  fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)
 	if (error)
 		goto out;
 
-	error = nfsd_mode_check(rqstp, dentry, type);
+	error = nfsd_mode_check(dentry, type);
 	if (error)
 		goto out;
 
diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
index 5777f40c7353..9bb306bdc225 100644
--- a/fs/nfsd/nfsxdr.c
+++ b/fs/nfsd/nfsxdr.c
@@ -38,6 +38,25 @@  svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status)
 {
 	__be32 *p;
 
+	switch (status) {
+	case nfserr_symlink_not_dir:
+		status = nfserr_notdir;
+		break;
+	case nfserr_symlink:
+	case nfserr_wrong_type:
+		status = nfserr_inval;
+		break;
+	case nfserr_nofilehandle:
+	case nfserr_badhandle:
+		status = nfserr_stale;
+		break;
+	case nfserr_wrongsec:
+	case nfserr_xdev:
+	case nfserr_file_open:
+		status = nfserr_acces;
+		break;
+	}
+
 	p = xdr_reserve_space(xdr, sizeof(status));
 	if (!p)
 		return false;
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 0862f6ae86a9..cf96a2ef6533 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -1770,10 +1770,7 @@  nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
 		if (!err)
 			err = nfserrno(commit_metadata(tfhp));
 	} else {
-		if (host_err == -EXDEV && rqstp->rq_vers == 2)
-			err = nfserr_acces;
-		else
-			err = nfserrno(host_err);
+		err = nfserrno(host_err);
 	}
 	dput(dnew);
 out_drop_write:
@@ -1839,7 +1836,7 @@  nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
 	if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
 		goto out;
 
-	err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
+	err = nfserr_xdev;
 	if (ffhp->fh_export->ex_path.mnt != tfhp->fh_export->ex_path.mnt)
 		goto out;
 	if (ffhp->fh_export->ex_path.dentry != tfhp->fh_export->ex_path.dentry)
@@ -1854,7 +1851,7 @@  nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
 
 	trap = lock_rename(tdentry, fdentry);
 	if (IS_ERR(trap)) {
-		err = (rqstp->rq_vers == 2) ? nfserr_acces : nfserr_xdev;
+		err = nfserr_xdev;
 		goto out_want_write;
 	}
 	err = fh_fill_pre_attrs(ffhp);
@@ -2023,10 +2020,7 @@  nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
 		/* name is mounted-on. There is no perfect
 		 * error status.
 		 */
-		if (nfsd_v4client(rqstp))
-			err = nfserr_file_open;
-		else
-			err = nfserr_acces;
+		err = nfserr_file_open;
 	} else {
 		err = nfserrno(host_err);
 	}
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index 0d896ce296ce..04dad965fa66 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -290,6 +290,9 @@  enum nfsstat4 {
 	/* xattr (RFC8276) */
 	NFS4ERR_NOXATTR        = 10095,
 	NFS4ERR_XATTR2BIG      = 10096,
+
+	/* can be used for internal errors */
+	NFS4ERR_FIRST_FREE
 };
 
 /* error codes for internal client use */