nfsd: assorted clean-ups
Subsystems (2)
cover nfsd: assorted clean-ups
My recent series (that may not now be needed) to allow fh_verify() to not be given an rqstp pointer (instead taking the individual fields that it actually needs) exposed several opportunities for improving code cleanliness. This series provides just those.
I'm not convinced that the last 2 are a genuine improvement, but that follow a pattern set by earlier patches, and maybe they are a good idea.
There is some minor behavioural change in that some error codes are changed as described in patch 3.
Thanks,
NeilBrown
[PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find() [PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions. [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code. [PATCH 4/6] nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease() [PATCH 5/6] nfsd: further centralize protocol version checks. [PATCH 6/6] nfsd: move V4ROOT version check to nfsd_set_fh_dentry()
PATCH 1/6 nfsd: Don't pass all of rqst into rqst_exp_find()
Rather than passing the whole rqst, pass the pieces that are actually needed. This makes the inputs to rqst_exp_find() more obvious.
--- fs/nfsd/export.c | 35 ++++++++++++++++++++++++++--------- fs/nfsd/export.h | 4 +++- fs/nfsd/nfs4proc.c | 4 +++- fs/nfsd/nfsfh.c | 4 +++- 4 files changed, 35 insertions(+), 12 deletions(-)
fs/nfsd/export.c +26 -9
@@ -1164,19 +1164,35 @@ rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)return gssexp; } +/** +* rqst_exp_find - Find an svc_export in the context of a rqst or similar +* @reqp: The handle to be used to suspend the request if a cache-upcall is needed +* If NULL, missing in-cache information will result in failure. +* @net: The network namespace in which the request exists +* @cl: default auth_domain to use for looking up the export +* @gsscl: an alternate auth_domain defined using deprecated gss/krb5 format. +* @fsid_type: The type of fsid to look for +* @fsidv: The actual fsid to look up in the context of either client. +* +* Perform a lookup for @cl/@fsidv in the given @net for an export. If +* none found and @gsscl specified, repeat the lookup. +* +* Returns an export, or an error pointer. +*/ struct svc_export * -rqst_exp_find (struct svc_rqst *rqstp,int fsid_type,u32 *fsidv) +rqst_exp_find (struct cache_req *reqp,struct net *net, +struct auth_domain *cl,struct auth_domain *gsscl, +int fsid_type,u32 *fsidv) { +struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct svc_export *gssexp, *exp =ERR_PTR (-ENOENT ); -struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct cache_detail *cd = nn->svc_export_cache; -if (rqstp->rq_client ==NULL ) +if (!cl) goto gss;/* First try the auth_unix client: */ - exp =exp_find (cd, rqstp->rq_client, fsid_type, - fsidv, &rqstp->rq_chandle); + exp =exp_find (cd, cl, fsid_type, fsidv, reqp);if (PTR_ERR (exp) == -ENOENT ) goto gss;if (IS_ERR (exp))
@@ -1186,10 +1202,9 @@ rqst_exp_find(struct svc_rqst *rqstp, int fsid_type, u32 *fsidv)return exp; gss:/* Otherwise, try falling back on gss client */ -if (rqstp->rq_gssclient ==NULL ) +if (!gsscl)return exp; - gssexp =exp_find (cd, rqstp->rq_gssclient, fsid_type, fsidv, - &rqstp->rq_chandle); + gssexp =exp_find (cd, gsscl, fsid_type, fsidv, reqp);if (PTR_ERR (gssexp) == -ENOENT )return exp;if (!IS_ERR (exp))
@@ -1220,7 +1235,9 @@ struct svc_export *rqst_find_fsidzero_export(struct svc_rqst *rqstp)mk_fsid (FSID_NUM , fsidv,0 ,0 ,0 ,NULL ); -return rqst_exp_find (rqstp,FSID_NUM , fsidv); +return rqst_exp_find (&rqstp->rq_chandle,SVC_NET (rqstp), + rqstp->rq_client, rqstp->rq_gssclient, +FSID_NUM , fsidv); }/*
fs/nfsd/export.h +3 -1
@@ -127,6 +127,8 @@ static inline struct svc_export *exp_get(struct svc_export *exp)cache_get (&exp->h); return exp; } -struct svc_export *rqst_exp_find (struct svc_rqst *,int ,u32 *); +struct svc_export *rqst_exp_find (struct cache_req *reqp,struct net *net, +struct auth_domain *cl,struct auth_domain *gsscl, +int fsid_type,u32 *fsidv);#endif /* NFSD_EXPORT_H */
fs/nfsd/nfs4proc.c +3 -1
@@ -2231,7 +2231,9 @@ nfsd4_getdeviceinfo(struct svc_rqst *rqstp,return nfserr_noent; } - exp =rqst_exp_find (rqstp, map->fsid_type, map->fsid); + exp =rqst_exp_find (&rqstp->rq_chandle,SVC_NET (rqstp), + rqstp->rq_client, rqstp->rq_gssclient, + map->fsid_type, map->fsid);if (IS_ERR (exp)) {dprintk ("%s: could not find device id\n" , __func__);return nfserr_noent;
fs/nfsd/nfsfh.c +3 -1
@@ -195,7 +195,9 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp) data_left -= len;if (data_left <0 )return error; - exp =rqst_exp_find (rqstp, fh->fh_fsid_type, fh->fh_fsid); + exp =rqst_exp_find (&rqstp->rq_chandle,SVC_NET (rqstp), + rqstp->rq_client, rqstp->rq_gssclient, + fh->fh_fsid_type, fh->fh_fsid); fid = (struct fid *)(fh->fh_fsid + len); error = nfserr_stale;
Signature · 1 line
2.44.0
PATCH 2/6 nfsd: Pass 'cred' instead of 'rqstp' to some functions.
In reply to NeilBrownnfsd_permission(), exp_rdonly(), nfsd_setuser(), and nfsexp_flags() only ever need the cred out of rqstp, so pass it explicitly instead of the whole rqstp.
This makes the interfaces cleaner.
--- fs/nfsd/auth.c | 14 +++++++------- fs/nfsd/auth.h | 2 +- fs/nfsd/export.h | 3 ++- fs/nfsd/nfs4state.c | 3 ++- fs/nfsd/nfsfh.c | 6 +++--- fs/nfsd/nfsproc.c | 9 +++++---- fs/nfsd/vfs.c | 21 ++++++++++++--------- fs/nfsd/vfs.h | 2 +- 8 files changed, 33 insertions(+), 27 deletions(-)
fs/nfsd/auth.c +7 -7
@@ -5,26 +5,26 @@#include "nfsd.h" #include "auth.h" -int nfsexp_flags (struct svc_rqst *rqstp,struct svc_export *exp) +int nfsexp_flags (struct svc_cred *cred,struct svc_export *exp) {struct exp_flavor_info *f;struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;for (f = exp->ex_flavors; f < end; f++) { -if (f->pseudoflavor == rqstp->rq_cred.cr_flavor) +if (f->pseudoflavor == cred->cr_flavor)return f->flags; }return exp->ex_flags; } -int nfsd_setuser (struct svc_rqst *rqstp,struct svc_export *exp) +int nfsd_setuser (struct svc_cred *cred,struct svc_export *exp) {struct group_info *rqgi;struct group_info *gi;struct cred *new;int i; -int flags =nfsexp_flags (rqstp, exp); +int flags =nfsexp_flags (cred, exp);/* discard any old override before preparing the new set */ revert_creds (get_cred (current_real_cred ()));
@@ -32,10 +32,10 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)if (!new)return -ENOMEM ; - new->fsuid = rqstp->rq_cred.cr_uid; - new->fsgid = rqstp->rq_cred.cr_gid; + new->fsuid = cred->cr_uid; + new->fsgid = cred->cr_gid; - rqgi = rqstp->rq_cred.cr_group_info; + rqgi = cred->cr_group_info;if (flags &NFSEXP_ALLSQUASH ) { new->fsuid = exp->ex_anon_uid;
fs/nfsd/auth.h +1 -1
@@ -12,6 +12,6 @@* Set the current process's fsuid/fsgid etc to those of the NFS * client user */ -int nfsd_setuser (struct svc_rqst *,struct svc_export *); +int nfsd_setuser (struct svc_cred *,struct svc_export *);#endif /* LINUX_NFSD_AUTH_H */
fs/nfsd/export.h +2 -1
@@ -99,7 +99,8 @@ struct svc_expkey {#define EX_NOHIDE (exp) ((exp)->ex_flags & NFSEXP_NOHIDE)#define EX_WGATHER (exp) ((exp)->ex_flags & NFSEXP_GATHERED_WRITES) -int nfsexp_flags (struct svc_rqst *rqstp,struct svc_export *exp); +struct svc_cred ; +int nfsexp_flags (struct svc_cred *cred,struct svc_export *exp);__be32 check_nfsd_access (struct svc_export *exp,struct svc_rqst *rqstp);/*
fs/nfsd/nfs4state.c +2 -1
@@ -6889,7 +6889,8 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s, nf =nfs4_find_file (s, flags);if (nf) { - status =nfsd_permission (rqstp, fhp->fh_export, fhp->fh_dentry, + status =nfsd_permission (&rqstp->rq_cred, + fhp->fh_export, fhp->fh_dentry, acc |NFSD_MAY_OWNER_OVERRIDE );if (status) {nfsd_file_put (nf);
fs/nfsd/nfsfh.c +3 -3
@@ -102,7 +102,7 @@ static bool nfsd_originating_port_ok(struct svc_rqst *rqstp, int flags)static __be32 nfsd_setuser_and_check_port (struct svc_rqst *rqstp,struct svc_export *exp) { -int flags =nfsexp_flags (rqstp, exp); +int flags =nfsexp_flags (&rqstp->rq_cred, exp);/* Check if the request originated from a secure port. */ if (!nfsd_originating_port_ok (rqstp, flags)) {
@@ -113,7 +113,7 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp, }/* Set user creds for this exportpoint */ -return nfserrno (nfsd_setuser (rqstp, exp)); +return nfserrno (nfsd_setuser (&rqstp->rq_cred, exp)); } static inline __be32 check_pseudo_root(struct svc_rqst *rqstp,
@@ -394,7 +394,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access) skip_pseudoflavor_check:/* Finally, check access permissions. */ - error =nfsd_permission (rqstp, exp, dentry, access); + error =nfsd_permission (&rqstp->rq_cred, exp, dentry, access); out:trace_nfsd_fh_verify_err (rqstp, fhp, type, access, error);if (error == nfserr_stale)
fs/nfsd/nfsproc.c +5 -4
@@ -331,10 +331,11 @@ nfsd_proc_create(struct svc_rqst *rqstp)* echo thing > device-special-file-or-pipe * by doing a CREATE with type==0 */ - resp->status =nfsd_permission (rqstp, - newfhp->fh_export, - newfhp->fh_dentry, -NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS ); + resp->status =nfsd_permission ( + &rqstp->rq_cred, + newfhp->fh_export, + newfhp->fh_dentry, +NFSD_MAY_WRITE |NFSD_MAY_LOCAL_ACCESS );if (resp->status && resp->status != nfserr_rofs) goto out_unlock; }
fs/nfsd/vfs.c +12 -9
@@ -421,8 +421,9 @@ nfsd_get_write_access(struct svc_rqst *rqstp, struct svc_fh *fhp,if (iap->ia_size < inode->i_size) {__be32 err; - err =nfsd_permission (rqstp, fhp->fh_export, fhp->fh_dentry, -NFSD_MAY_TRUNC |NFSD_MAY_OWNER_OVERRIDE ); + err =nfsd_permission (&rqstp->rq_cred, + fhp->fh_export, fhp->fh_dentry, +NFSD_MAY_TRUNC |NFSD_MAY_OWNER_OVERRIDE );if (err)return err; }
@@ -814,7 +815,8 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor sresult |= map->access; - err2 =nfsd_permission (rqstp, export, dentry, map->how); + err2 =nfsd_permission (&rqstp->rq_cred, export, + dentry, map->how);switch (err2) {case nfs_ok: result |= map->access;
@@ -1475,7 +1477,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp, dirp =d_inode (dentry); dchild =dget (resfhp->fh_dentry); - err =nfsd_permission (rqstp, fhp->fh_export, dentry,NFSD_MAY_CREATE ); + err =nfsd_permission (&rqstp->rq_cred, fhp->fh_export, dentry, +NFSD_MAY_CREATE );if (err) goto out;
@@ -2255,9 +2258,9 @@ nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat, inreturn err; } -static int exp_rdonly (struct svc_rqst *rqstp,struct svc_export *exp) +static int exp_rdonly (struct svc_cred *cred,struct svc_export *exp) { -return nfsexp_flags (rqstp, exp) &NFSEXP_READONLY ; +return nfsexp_flags (cred, exp) &NFSEXP_READONLY ; }#ifdef CONFIG_NFSD_V4
@@ -2501,8 +2504,8 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,* Check for a user's access permissions to this inode. */ __be32 -nfsd_permission (struct svc_rqst *rqstp,struct svc_export *exp, -struct dentry *dentry,int acc) +nfsd_permission (struct svc_cred *cred,struct svc_export *exp, +struct dentry *dentry,int acc) {struct inode *inode =d_inode (dentry);int err;
@@ -2533,7 +2536,7 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,*/ if (!(acc &NFSD_MAY_LOCAL_ACCESS ))if (acc & (NFSD_MAY_WRITE |NFSD_MAY_SATTR |NFSD_MAY_TRUNC )) { -if (exp_rdonly (rqstp, exp) || +if (exp_rdonly (cred, exp) ||__mnt_is_readonly (exp->ex_path.mnt))return nfserr_rofs;if (/* (acc & NFSD_MAY_WRITE) && */ IS_IMMUTABLE (inode))
fs/nfsd/vfs.h +1 -1
@@ -153,7 +153,7 @@ __be32 nfsd_readdir(struct svc_rqst *, struct svc_fh *,__be32 nfsd_statfs (struct svc_rqst *,struct svc_fh *,struct kstatfs *,int access); -__be32 nfsd_permission (struct svc_rqst *,struct svc_export *, +__be32 nfsd_permission (struct svc_cred *,struct svc_export *,struct dentry *,int );void nfsd_filp_close (struct file *fp);
Signature · 1 line
2.44.0
PATCH 3/6 nfsd: Move error code mapping to per-version xdr code.
In reply to NeilBrownThere 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.
--- 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(-)
fs/nfsd/export.c +1 -1
@@ -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; }/*
fs/nfsd/nfs3xdr.c +17 -0
@@ -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;
fs/nfsd/nfs4proc.c +3 -8
@@ -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)
fs/nfsd/nfs4xdr.c +15 -0
@@ -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);
fs/nfsd/nfsd.h +19 -4
@@ -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] == '.'))
fs/nfsd/nfsfh.c +10 -16
@@ -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;
fs/nfsd/nfsxdr.c +19 -0
@@ -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;
fs/nfsd/vfs.c +4 -10
@@ -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); }
include/linux/nfs4.h +3 -0
@@ -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 */
Signature · 1 line
2.44.0
Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
Quoted 6 lines · NeilBrown
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).
Quoted 4 lines
One complication is that the NFSv4 code
NFS4ERR_SYMLINKmight be used where v3 expectsNFSERR_NOTDIRofNFSERR_INVAL. To handle this we introduce an internal error codeNFSERR_SYMLINK_NOT_DIRand 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.
Quoted 49 lines
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_TYPEwhen that is appropriate. It previously returnedNFS4ERR_SYMLINKas that seemed best for NFSv4.0. According to RFC5661 15.1.2.9 NFSv4.0 was expected to returnNFSERR_INVALin these cases, so that is how the code now behaves.Signed-off-by NeilBrown <[email protected]>--- 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(-)fs/nfsd/export.c +1
-1@@ -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; }/* fs/nfsd/nfs3xdr.c +7
-0@@ -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;
fs/nfsd/nfs3xdr.c svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status) · line 130
Quoted 10 lines
fs/nfsd/nfs3xdr.c +10
-0+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.
Quoted 31 lines
fs/nfsd/nfs3xdr.c +0
-0p =xdr_reserve_space (xdr,sizeof (status));if (!p)return false;fs/nfsd/nfs4proc.c +3
-8@@ -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)fs/nfsd/nfs4xdr.c +0
-0@@ -5748,6 +5748,14 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
fs/nfsd/nfs4xdr.c nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) · line 5758
Quoted 10 lines
fs/nfsd/nfs4xdr.c +8
-0if (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.
Quoted 4 lines
fs/nfsd/nfs4xdr.c +0
-0if (op->status && opdesc && !(opdesc->op_flags &OP_NONTRIVIAL_ERROR_ENCODE )) goto status;
fs/nfsd/nfs4xdr.c nfs4svc_encode_compoundres(struct svc_rqst *rqstp, struct xdr_stream *xdr) · line 5887
Quoted 10 lines
fs/nfsd/nfs4xdr.c +7
-0@@ -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.
Quoted 26 lines
fs/nfsd/nfs4xdr.c +0
-0*p++ = resp->cstate.status; *p++ =htonl (resp->taglen);memcpy (p, resp->tag, resp->taglen);fs/nfsd/nfsd.h +7
-3@@ -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)
fs/nfsd/nfsd.h void nfsd_lockd_shutdown(void); · line 350
Quoted 10 lines
fs/nfsd/nfsd.h +8
-1+ 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
fs/nfsd/nfsd.h void nfsd_lockd_shutdown(void); · line 354
Quoted 4 lines
fs/nfsd/nfsd.h +4
-0+*/ + 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.
Quoted 89 lines
fs/nfsd/nfsd.h +0
-0/* Check for dir entries '.' and '..' */ #define isdotent (n, l) (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))fs/nfsd/nfsfh.c +10
-16@@ -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;fs/nfsd/nfsxdr.c +9
-0@@ -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:
fs/nfsd/nfsxdr.c svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status) · line 59
Quoted 10 lines
fs/nfsd/nfsxdr.c +10
-0+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.
Quoted 66 lines
fs/nfsd/nfsxdr.c +0
-0p =xdr_reserve_space (xdr,sizeof (status));if (!p)return false;fs/nfsd/vfs.c +4
-10@@ -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); }include/linux/nfs4.h +3
-0@@ -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 */ Signature · 1 line
2.44.0
Signature · 1 line
Chuck Lever
Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
Quoted 18 lines · Chuck Lever
Quoted 6 lines · NeilBrown
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).
Quoted 4 lines
One complication is that the NFSv4 code
NFS4ERR_SYMLINKmight be used where v3 expectsNFSERR_NOTDIRofNFSERR_INVAL. To handle this we introduce an internal error codeNFSERR_SYMLINK_NOT_DIRand convert that as appropriate for all versions.
Quoted 6 lines
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.
Quoted 26 lines
More specific comments below.
Quoted 21 lines
fs/nfsd/nfs3xdr.c +13
-0@@ -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:
Quoted 8 lines
fs/nfsd/nfs3xdr.c svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status) · line 130
Quoted 4 lines
fs/nfsd/nfs3xdr.c +4
-0+ 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?
Quoted 11 lines
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.
Quoted 21 lines
Quoted 21 lines
fs/nfsd/nfs3xdr.c +10
-3/* 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 */
Quoted 9 lines
fs/nfsd/nfs3xdr.c
Quoted 6 lines
fs/nfsd/nfs3xdr.c +5
-1-#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.
Quoted 10 lines
fs/nfsd/nfs3xdr.c
Quoted 5 lines
+ */
fs/nfsd/nfs3xdr.c +3
-0+ 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.
Quoted 5 lines
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
__be32result that actually does sometimes carry an on-the-wire status code.
Yes exactly. I'll add some text like that.
Thanks,
NeilBrown
Quoted 178 lines
As a note about patch series organization, it would be helpful to split this hunk into a separate, preceding patch, IMO.
Quoted 89 lines
/* Check for dir entries '.' and '..' */
#defineisdotent(n, l)(l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))fs/nfsd/nfsfh.c +10
-16@@ -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;fs/nfsd/nfsxdr.c +9
-0@@ -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:fs/nfsd/nfsxdr.c svcxdr_encode_stat(struct xdr_stream *xdr, __be32 status) · line 59
Quoted 10 lines
fs/nfsd/nfsxdr.c +10
-0+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.
Quoted 66 lines
fs/nfsd/nfsxdr.c +0
-0p =xdr_reserve_space (xdr,sizeof (status));if (!p)return false;fs/nfsd/vfs.c +4
-10@@ -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); }include/linux/nfs4.h +3
-0@@ -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 */ Signature · 1 line
2.44.0Signature · 1 line
Chuck Lever
Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
Quoted 33 lines · NeilBrown
Quoted 23 lines · Chuck Lever
Quoted 21 lines · NeilBrown
fs/nfsd/nfs3xdr.c +13
-0@@ -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:Quoted 8 lines
fs/nfsd/nfs3xdr.c svcxdr_encode_nfsstat3(struct xdr_stream *xdr, __be32 status) · line 130
Quoted 4 lines
fs/nfsd/nfs3xdr.c +4
-0+ 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.
Quoted 3 lines
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.
Quoted 10 lines
We could put the mapping in each .pc_func function, or between the
proc->pc_func()call innfsd_dispatch()and the followingproc->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.
Quoted 8 lines
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.
Quoted 6 lines
Quoted 6 lines
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.
Quoted 7 lines
Quoted 4 lines
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.)
Quoted 13 lines
Quoted 4 lines
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_xdevis an internal error code. From the perspective of NFSv3 it is not. Should it have 'int'?]
Quoted 2 lines
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.
Quoted 6 lines
Quoted 4 lines
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
__be32result that actually does sometimes carry an on-the-wire status code.Yes exactly. I'll add some text like that.
Thanks for your feedback.
Signature · 1 line
Chuck Lever
PATCH 4/6 nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease()
In reply to NeilBrownnfsd_breaker_owns_lease() current open-codes the same test that nfsd_v4client() performs.
With this patch we use nfsd_v4client() instead.
Also as i_am_nfsd() is only used in combination with kthread_data(), replace it with nfsd_current_rqst() which combines the two and returns a valid svc_rqst, or NULL.
The test for NULL is moved into nfsd_v4client() for code clarity.
--- fs/nfsd/nfs4state.c | 7 ++----- fs/nfsd/nfsd.h | 4 ++-- fs/nfsd/nfssvc.c | 6 ++++-- 3 files changed, 8 insertions(+), 9 deletions(-)
fs/nfsd/nfs4state.c +2 -5
@@ -5274,11 +5274,8 @@ static bool nfsd_breaker_owns_lease(struct file_lease *fl)struct svc_rqst *rqst;struct nfs4_client *clp; -if (!i_am_nfsd ()) -return false; - rqst =kthread_data (current); -/* Note rq_prog == NFS_ACL_PROGRAM is also possible: */ -if (rqst->rq_prog !=NFS_PROGRAM || rqst->rq_vers <4 ) + rqst =nfsd_current_rqst (); +if (!nfsd_v4client (rqst))return false; clp = *(rqst->rq_lease_breaker);return dl->dl_stid.sc_client == clp;
fs/nfsd/nfsd.h +2 -2
@@ -114,7 +114,7 @@ int nfsd_pool_stats_open(struct inode *, struct file *);int nfsd_pool_stats_release (struct inode *,struct file *);void nfsd_shutdown_threads (struct net *net); -bool i_am_nfsd (void ); +struct svc_rqst *nfsd_current_rqst (void );struct nfsdfs_client {struct kref cl_ref;
@@ -155,7 +155,7 @@ extern int nfsd_max_blksize;static inline int nfsd_v4client (struct svc_rqst *rq) { -return rq->rq_prog ==NFS_PROGRAM && rq->rq_vers ==4 ; +return rq && rq->rq_prog ==NFS_PROGRAM && rq->rq_vers ==4 ; }static inline struct user_namespace *nfsd_user_namespace (const struct svc_rqst *rqstp)
fs/nfsd/nfssvc.c +4 -2
@@ -642,9 +642,11 @@ void nfsd_shutdown_threads(struct net *net)mutex_unlock (&nfsd_mutex); } -bool i_am_nfsd (void ) +struct svc_rqst *nfsd_current_rqst (void ) { -return kthread_func (current) == nfsd; +if (kthread_func (current) == nfsd) +return kthread_data (current); +return NULL ; }int nfsd_create_serv (struct net *net)
Signature · 1 line
2.44.0
PATCH 5/6 nfsd: further centralize protocol version checks.
In reply to NeilBrownWith this patch the only places that test ->rq_vers against a specific version are nfsd_v4client() and nfsd_set_fh_dentry().
The latter sets some flags in the svc_fh, which now includes:
fh_64bit_cookies
fh_use_wgather
--- fs/nfsd/nfsfh.c | 4 ++++ fs/nfsd/nfsfh.h | 2 ++ fs/nfsd/vfs.c | 9 +++------ 3 files changed, 9 insertions(+), 6 deletions(-)
fs/nfsd/nfsfh.c +4 -0
@@ -278,13 +278,17 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)case 4 :if (dentry->d_sb->s_export_op->flags &EXPORT_OP_NOATOMIC_ATTR ) fhp->fh_no_atomic_attr = true; + fhp->fh_64bit_cookies = true;break ;case 3 :if (dentry->d_sb->s_export_op->flags &EXPORT_OP_NOWCC ) fhp->fh_no_wcc = true; + fhp->fh_64bit_cookies = true;break ;case 2 : fhp->fh_no_wcc = true; +if (EX_WGATHER (exp)) + fhp->fh_use_wgather = true; }return 0 ;
fs/nfsd/nfsfh.h +2 -0
@@ -88,6 +88,8 @@ typedef struct svc_fh {* wcc data is not atomic with * operation */ +bool fh_use_wgather;/* NFSv2 wgather option */ +bool fh_64bit_cookies;/* readdir cookie size */ int fh_flags;/* FH flags */ bool fh_post_saved;/* post-op attrs saved */ bool fh_pre_saved;/* pre-op attrs saved */
fs/nfsd/vfs.c +3 -6
@@ -1162,7 +1162,6 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,errseq_t since;__be32 nfserr;int host_err; -int use_wgather;loff_t pos = offset;unsigned long exp_op_flags =0 ;unsigned int pflags = current->flags;
@@ -1188,12 +1187,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, } exp = fhp->fh_export; - use_wgather = (rqstp->rq_vers ==2 ) &&EX_WGATHER (exp);if (!EX_ISSYNC (exp)) stable =NFS_UNSTABLE ; -if (stable && !use_wgather) +if (stable && !fhp->fh_use_wgather) flags |=RWF_SYNC ;iov_iter_kvec (&iter,ITER_SOURCE , vec, vlen, *cnt);
@@ -1212,7 +1210,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,if (host_err <0 ) goto out_nfserr; -if (stable && use_wgather) { +if (stable && fhp->fh_use_wgather) { host_err =wait_for_concurrent_writes (file);if (host_err <0 )commit_reset_write_verifier (nn, rqstp, host_err);
@@ -2175,8 +2173,7 @@ nfsd_readdir(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t *offsetp,loff_t offset = *offsetp;int may_flags =NFSD_MAY_READ ; -/* NFSv2 only supports 32 bit cookies */ -if (rqstp->rq_vers >2 ) +if (fhp->fh_64bit_cookies) may_flags |=NFSD_MAY_64BIT_COOKIE ; err =nfsd_open (rqstp, fhp,S_IFDIR , may_flags, &file);
Signature · 1 line
2.44.0
PATCH 6/6 nfsd: move V4ROOT version check to nfsd_set_fh_dentry()
In reply to NeilBrownThis further centralizes version number checks.
--- fs/nfsd/nfsfh.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
fs/nfsd/nfsfh.c +7 -11
@@ -114,19 +114,11 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,return nfserrno (nfsd_setuser (&rqstp->rq_cred, exp)); } -static inline __be32 check_pseudo_root (struct svc_rqst *rqstp, -struct dentry *dentry,struct svc_export *exp) +static inline __be32 check_pseudo_root (struct dentry *dentry, +struct svc_export *exp) {if (!(exp->ex_flags &NFSEXP_V4ROOT ))return nfs_ok; -/* -* v2/v3 clients have no need for the V4ROOT export--they use -* the mount protocl instead; also, further V4ROOT checks may be -* in v4-specific code, in which case v2/v3 clients could bypass -* them. -*/ -if (!nfsd_v4client (rqstp)) -return nfserr_stale;/* * We're exposing only the directories and symlinks that have to be * traversed on the way to real exports:
@@ -284,11 +276,15 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)if (dentry->d_sb->s_export_op->flags &EXPORT_OP_NOWCC ) fhp->fh_no_wcc = true; fhp->fh_64bit_cookies = true; +if (exp->ex_flags &NFSEXP_V4ROOT ) + goto out;break ;case 2 : fhp->fh_no_wcc = true;if (EX_WGATHER (exp)) fhp->fh_use_wgather = true; +if (exp->ex_flags &NFSEXP_V4ROOT ) + goto out; }return 0 ;
@@ -358,7 +354,7 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int access)* (for example, if different id-squashing options are in * effect on the new filesystem). */ - error =check_pseudo_root (rqstp, dentry, exp); + error =check_pseudo_root (dentry, exp);if (error) goto out;
Signature · 1 line
2.44.0
Quoted 14 lines · NeilBrown
My recent series (that may not now be needed) to allow
fh_verify()to not be given an rqstp pointer (instead taking the individual fields that it actually needs) exposed several opportunities for improving code cleanliness. This series provides just those.I'm not convinced that the last 2 are a genuine improvement, but that follow a pattern set by earlier patches, and maybe they are a good idea.
There is some minor behavioural change in that some error codes are changed as described in patch 3.
Thanks,
NeilBrown
Quoted 6 lines
[PATCH 1/6] nfsd: Don't pass all of rqst into
rqst_exp_find()[PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions. [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code. [PATCH 4/6] nfsd: usenfsd_v4client()innfsd_breaker_owns_lease()[PATCH 5/6] nfsd: further centralize protocol version checks. [PATCH 6/6] nfsd: move V4ROOT version check tonfsd_set_fh_dentry()
This all looks reasonable to me. The last two do seem more marginal than the first four, but I think they make the code more readable, on balance.