]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nfs: don't atempt blocking locks on nfs reexports
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 20 Aug 2021 21:02:04 +0000 (17:02 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Thu, 26 Aug 2021 19:32:10 +0000 (15:32 -0400)
NFS implements blocking locks by blocking inside its lock method.  In
the reexport case, this blocks the nfs server thread, which could lead
to deadlocks since an nfs server thread might be required to unlock the
conflicting lock.  It also causes a crash, since the nfs server thread
assumes it can free the lock when its lm_notify lock callback is called.

Ideal would be to make the nfs lock method return without blocking in
this case, but for now it works just not to attempt blocking locks.  The
difference is just that the original client will have to poll (as it
does in the v4.0 case) instead of getting a callback when the lock's
available.

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/export.c
fs/nfsd/nfs4state.c
include/linux/exportfs.h

index 37a1a88df7717e155a6ee50a0108ea05f81ab8e3..d772c20bbfd153b6d060c5aea71e5344c3cbd089 100644 (file)
@@ -180,5 +180,5 @@ const struct export_operations nfs_export_ops = {
        .fetch_iversion = nfs_fetch_iversion,
        .flags = EXPORT_OP_NOWCC|EXPORT_OP_NOSUBTREECHK|
                EXPORT_OP_CLOSE_BEFORE_UNLINK|EXPORT_OP_REMOTE_FS|
-               EXPORT_OP_NOATOMIC_ATTR,
+               EXPORT_OP_NOATOMIC_ATTR|EXPORT_OP_SYNC_LOCKS,
 };
index 2bedc7839ec568edcfb18c6cf5261fb60eb7ef90..d0b2041c4d7597ab189aef18cbbd531bd0e62628 100644 (file)
@@ -6835,6 +6835,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        struct nfsd4_blocked_lock *nbl = NULL;
        struct file_lock *file_lock = NULL;
        struct file_lock *conflock = NULL;
+       struct super_block *sb;
        __be32 status = 0;
        int lkflg;
        int err;
@@ -6856,6 +6857,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                dprintk("NFSD: nfsd4_lock: permission denied!\n");
                return status;
        }
+       sb = cstate->current_fh.fh_dentry->d_sb;
 
        if (lock->lk_is_new) {
                if (nfsd4_has_session(cstate))
@@ -6904,7 +6906,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        fp = lock_stp->st_stid.sc_file;
        switch (lock->lk_type) {
                case NFS4_READW_LT:
-                       if (nfsd4_has_session(cstate))
+                       if (nfsd4_has_session(cstate) &&
+                           !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS))
                                fl_flags |= FL_SLEEP;
                        fallthrough;
                case NFS4_READ_LT:
@@ -6916,7 +6919,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                        fl_type = F_RDLCK;
                        break;
                case NFS4_WRITEW_LT:
-                       if (nfsd4_has_session(cstate))
+                       if (nfsd4_has_session(cstate) &&
+                           !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS))
                                fl_flags |= FL_SLEEP;
                        fallthrough;
                case NFS4_WRITE_LT:
index fe848901fcc3acb04a732b82df95c86fbad93ddc..3260fe7148462687d9c3d9a6e54e595deb678121 100644 (file)
@@ -221,6 +221,8 @@ struct export_operations {
 #define EXPORT_OP_NOATOMIC_ATTR                (0x10) /* Filesystem cannot supply
                                                  atomic attribute updates
                                                */
+#define EXPORT_OP_SYNC_LOCKS           (0x20) /* Filesystem can't do
+                                                 asychronous blocking locks */
        unsigned long   flags;
 };