* [PATCH 0/6] nfsd: assorted clean-ups
@ 2024-07-26 2:21 NeilBrown
2024-07-26 2:21 ` [PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find() NeilBrown
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
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()
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find()
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 2:21 ` [PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions NeilBrown
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
Rather than passing the whole rqst, pass the pieces that are actually
needed. This makes the inputs to rqst_exp_find() more obvious.
Signed-off-by: NeilBrown <neilb@suse.de>
---
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(-)
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 50b3135d07ac..9aa5f95f18a8 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -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);
}
/*
diff --git a/fs/nfsd/export.h b/fs/nfsd/export.h
index ca9dc230ae3d..cb17f05e3329 100644
--- a/fs/nfsd/export.h
+++ b/fs/nfsd/export.h
@@ -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 */
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 46bd20fe5c0f..d5ed01c72910 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -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;
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 0b75305fb5f5..4ebb3c334cc2 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -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;
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions.
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
2024-07-26 2:21 ` [PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find() NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 2:21 ` [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code NeilBrown
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
nfsd_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.
Signed-off-by: NeilBrown <neilb@suse.de>
---
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(-)
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
index e6beaaf4f170..93e33d1ee891 100644
--- a/fs/nfsd/auth.c
+++ b/fs/nfsd/auth.c
@@ -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;
diff --git a/fs/nfsd/auth.h b/fs/nfsd/auth.h
index dbd66424f600..fc75c5d90be4 100644
--- a/fs/nfsd/auth.h
+++ b/fs/nfsd/auth.h
@@ -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 */
diff --git a/fs/nfsd/export.h b/fs/nfsd/export.h
index cb17f05e3329..3794ae253a70 100644
--- a/fs/nfsd/export.h
+++ b/fs/nfsd/export.h
@@ -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);
/*
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a20c2c9d7d45..eadb7d1a7f13 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -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);
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 4ebb3c334cc2..a485d630d10e 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -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)
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c
index 36370b957b63..97aab34593ef 100644
--- a/fs/nfsd/nfsproc.c
+++ b/fs/nfsd/nfsproc.c
@@ -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;
}
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 29b1f3613800..0862f6ae86a9 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -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, in
return 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))
diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
index 57cd70062048..1565c1dc28b6 100644
--- a/fs/nfsd/vfs.h
+++ b/fs/nfsd/vfs.h
@@ -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);
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
2024-07-26 2:21 ` [PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find() NeilBrown
2024-07-26 2:21 ` [PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 15:40 ` Chuck Lever
2024-07-26 2:21 ` [PATCH 4/6] nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease() NeilBrown
` (3 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
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(-)
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 */
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/6] nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease()
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
` (2 preceding siblings ...)
2024-07-26 2:21 ` [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 2:21 ` [PATCH 5/6] nfsd: further centralize protocol version checks NeilBrown
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
nfsd_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.
Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/nfsd/nfs4state.c | 7 ++-----
fs/nfsd/nfsd.h | 4 ++--
fs/nfsd/nfssvc.c | 6 ++++--
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index eadb7d1a7f13..c2edd8a21bd4 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -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;
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 0f499066aa72..e6626b22ab17 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -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)
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 89d7918de7b1..f6ce51eb232e 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -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)
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/6] nfsd: further centralize protocol version checks.
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
` (3 preceding siblings ...)
2024-07-26 2:21 ` [PATCH 4/6] nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease() NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 2:21 ` [PATCH 6/6] nfsd: move V4ROOT version check to nfsd_set_fh_dentry() NeilBrown
2024-07-26 12:50 ` [PATCH 0/6] nfsd: assorted clean-ups Jeff Layton
6 siblings, 0 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
With 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
Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/nfsd/nfsfh.c | 4 ++++
fs/nfsd/nfsfh.h | 2 ++
fs/nfsd/vfs.c | 9 +++------
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 8fb56e2f896c..e21647cbfca9 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -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;
diff --git a/fs/nfsd/nfsfh.h b/fs/nfsd/nfsfh.h
index 6ebdf7ea27bf..8d46e203d139 100644
--- a/fs/nfsd/nfsfh.h
+++ b/fs/nfsd/nfsfh.h
@@ -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 */
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index cf96a2ef6533..ec99c91df173 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -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);
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/6] nfsd: move V4ROOT version check to nfsd_set_fh_dentry()
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
` (4 preceding siblings ...)
2024-07-26 2:21 ` [PATCH 5/6] nfsd: further centralize protocol version checks NeilBrown
@ 2024-07-26 2:21 ` NeilBrown
2024-07-26 12:50 ` [PATCH 0/6] nfsd: assorted clean-ups Jeff Layton
6 siblings, 0 replies; 11+ messages in thread
From: NeilBrown @ 2024-07-26 2:21 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton
Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
This further centralizes version number checks.
Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/nfsd/nfsfh.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index e21647cbfca9..845ab4f077ca 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -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;
--
2.44.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] nfsd: assorted clean-ups
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
` (5 preceding siblings ...)
2024-07-26 2:21 ` [PATCH 6/6] nfsd: move V4ROOT version check to nfsd_set_fh_dentry() NeilBrown
@ 2024-07-26 12:50 ` Jeff Layton
6 siblings, 0 replies; 11+ messages in thread
From: Jeff Layton @ 2024-07-26 12:50 UTC (permalink / raw)
To: NeilBrown, Chuck Lever; +Cc: linux-nfs, Olga Kornievskaia, Dai Ngo, Tom Talpey
On Fri, 2024-07-26 at 12:21 +1000, NeilBrown wrote:
> 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()
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.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
2024-07-26 2:21 ` [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code NeilBrown
@ 2024-07-26 15:40 ` Chuck Lever
2024-07-26 22:07 ` NeilBrown
0 siblings, 1 reply; 11+ messages in thread
From: Chuck Lever @ 2024-07-26 15:40 UTC (permalink / raw)
To: NeilBrown
Cc: Jeff Layton, linux-nfs@vger.kernel.org, Olga Kornievskaia,
Dai Ngo, Tom Talpey
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
>
--
Chuck Lever
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
2024-07-26 15:40 ` Chuck Lever
@ 2024-07-26 22:07 ` NeilBrown
2024-07-27 16:25 ` Chuck Lever
0 siblings, 1 reply; 11+ messages in thread
From: NeilBrown @ 2024-07-26 22:07 UTC (permalink / raw)
To: Chuck Lever
Cc: Jeff Layton, linux-nfs@vger.kernel.org, Olga Kornievskaia,
Dai Ngo, Tom Talpey
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
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code.
2024-07-26 22:07 ` NeilBrown
@ 2024-07-27 16:25 ` Chuck Lever
0 siblings, 0 replies; 11+ messages in thread
From: Chuck Lever @ 2024-07-27 16:25 UTC (permalink / raw)
To: NeilBrown
Cc: Jeff Layton, linux-nfs@vger.kernel.org, Olga Kornievskaia,
Dai Ngo, Tom Talpey
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.
--
Chuck Lever
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-07-27 16:25 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-26 2:21 [PATCH 0/6] nfsd: assorted clean-ups NeilBrown
2024-07-26 2:21 ` [PATCH 1/6] nfsd: Don't pass all of rqst into rqst_exp_find() NeilBrown
2024-07-26 2:21 ` [PATCH 2/6] nfsd: Pass 'cred' instead of 'rqstp' to some functions NeilBrown
2024-07-26 2:21 ` [PATCH 3/6] nfsd: Move error code mapping to per-version xdr code NeilBrown
2024-07-26 15:40 ` Chuck Lever
2024-07-26 22:07 ` NeilBrown
2024-07-27 16:25 ` Chuck Lever
2024-07-26 2:21 ` [PATCH 4/6] nfsd: use nfsd_v4client() in nfsd_breaker_owns_lease() NeilBrown
2024-07-26 2:21 ` [PATCH 5/6] nfsd: further centralize protocol version checks NeilBrown
2024-07-26 2:21 ` [PATCH 6/6] nfsd: move V4ROOT version check to nfsd_set_fh_dentry() NeilBrown
2024-07-26 12:50 ` [PATCH 0/6] nfsd: assorted clean-ups Jeff Layton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox