nfs: don't allow reexport reclaims
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 20 Aug 2021 21:02:06 +0000 (17:02 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Thu, 26 Aug 2021 19:32:28 +0000 (15:32 -0400)
In the reexport case, nfsd is currently passing along locks with the
reclaim bit set.  The client sends a new lock request, which is granted
if there's currently no conflict--even if it's possible a conflicting
lock could have been briefly held in the interim.

We don't currently have any way to safely grant reclaim, so for now
let's just deny them all.

I'm doing this by passing the reclaim bit to nfs and letting it fail the
call, with the idea that eventually the client might be able to do
something more forgiving here.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Acked-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfs/file.c
fs/nfsd/nfs4state.c
fs/nfsd/nfsproc.c
include/linux/errno.h
include/linux/fs.h

index 1fef107961bc4a4ca624796de35d33c400179a2f..7411658f8b05743dfe81f5e4137b2f517339cd10 100644 (file)
@@ -806,6 +806,9 @@ int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
 
        nfs_inc_stats(inode, NFSIOS_VFSLOCK);
 
+       if (fl->fl_flags & FL_RECLAIM)
+               return -ENOGRACE;
+
        /* No mandatory locks over NFS */
        if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
                goto out_err;
index d0b2041c4d7597ab189aef18cbbd531bd0e62628..1b6a7f48982ed411e7921ee2c1f0acebdce904fa 100644 (file)
@@ -6903,6 +6903,9 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (!locks_in_grace(net) && lock->lk_reclaim)
                goto out;
 
+       if (lock->lk_reclaim)
+               fl_flags |= FL_RECLAIM;
+
        fp = lock_stp->st_stid.sc_file;
        switch (lock->lk_type) {
                case NFS4_READW_LT:
index 60d7c59e7935cc7424be1e6efb8f0360b2e669a8..90fcd6178823b42890c8673ab8a06d95bdfbe74f 100644 (file)
@@ -881,6 +881,7 @@ nfserrno (int errno)
                { nfserr_serverfault, -ENFILE },
                { nfserr_io, -EUCLEAN },
                { nfserr_perm, -ENOKEY },
+               { nfserr_no_grace, -ENOGRACE},
        };
        int     i;
 
index d73f597a248491aa7cb180b78f9b7ecca0060969..8b0c754bab02562b28ac7e7a539c7652764cdbb7 100644 (file)
@@ -31,5 +31,6 @@
 #define EJUKEBOX       528     /* Request initiated, but will not complete before timeout */
 #define EIOCBQUEUED    529     /* iocb queued, will get completion event */
 #define ERECALLCONFLICT        530     /* conflict with recalled state */
+#define ENOGRACE       531     /* NFS file lock reclaim refused */
 
 #endif
index 640574294216c03fb68876e0f3aa8cd7ee98e13a..1f5c3dbce1da8eb2ee6dec98a5234f5cc6f584f2 100644 (file)
@@ -997,6 +997,7 @@ static inline struct file *get_file(struct file *f)
 #define FL_UNLOCK_PENDING      512 /* Lease is being broken */
 #define FL_OFDLCK      1024    /* lock is "owned" by struct file */
 #define FL_LAYOUT      2048    /* outstanding pNFS layout */
+#define FL_RECLAIM     4096    /* reclaiming from a reboot server */
 
 #define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)