]> git.dujemihanovic.xyz Git - linux.git/commitdiff
nfsd: further centralize protocol version checks.
authorNeilBrown <neilb@suse.de>
Fri, 26 Jul 2024 02:21:34 +0000 (12:21 +1000)
committerChuck Lever <chuck.lever@oracle.com>
Fri, 20 Sep 2024 23:31:03 +0000 (19:31 -0400)
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>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfsfh.c
fs/nfsd/nfsfh.h
fs/nfsd/vfs.c

index fffeba0825400b6b63e7ff085a5bdae682297254..7abbd8b4a533deb79e673ebaba76f60517b0e0c5 100644 (file)
@@ -284,13 +284,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;
index 6ebdf7ea27bfdb55520dec0ba5939667768fa94e..8d46e203d139234abeae0fcca15ef006580b4b07 100644 (file)
@@ -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 */
index 0862f6ae86a9c6fd0c4963a9354bee231213f89a..bd6017510109f623c5270c9e3a7becd7ded38a13 100644 (file)
@@ -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);
@@ -2181,8 +2179,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);