]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nfs: block notification on fs with its own ->lock
authorJ. Bruce Fields <bfields@redhat.com>
Thu, 16 Dec 2021 17:20:13 +0000 (12:20 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Sat, 8 Jan 2022 19:42:01 +0000 (14:42 -0500)
NFSv4.1 supports an optional lock notification feature which notifies
the client when a lock comes available.  (Normally NFSv4 clients just
poll for locks if necessary.)  To make that work, we need to request a
blocking lock from the filesystem.

We turned that off for NFS in commit 33fde4889ec0 ("nfs: don't atempt
blocking locks on nfs reexports") [sic] because it actually blocks the
nfsd thread while waiting for the lock.

Thanks to Vasily Averin for pointing out that NFS isn't the only
filesystem with that problem.

Any filesystem that leaves ->lock NULL will use posix_lock_file(), which
does the right thing.  Simplest is just to assume that any filesystem
that defines its own ->lock is not safe to request a blocking lock from.

So, this patch mostly reverts commit 33fde4889ec0 ("nfs: don't atempt
blocking locks on nfs reexports") [sic] and commit 0efa031db862 ("lockd:
don't attempt blocking locks on nfs reexports"), and instead uses a
check of ->lock (Vasily's suggestion) to decide whether to support
blocking lock notifications on a given filesystem.  Also add a little
documentation.

Perhaps someday we could add back an export flag later to allow
filesystems with "good" ->lock methods to support blocking lock
notifications.

Reported-by: Vasily Averin <vvs@virtuozzo.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
[ cel: Description rewritten to address checkpatch nits ]
[ cel: Fixed warning when SUNRPC debugging is disabled ]
[ cel: Fixed NULL check ]
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Vasily Averin <vvs@virtuozzo.com>
fs/lockd/svclock.c
fs/nfs/export.c
fs/nfsd/nfs4state.c
include/linux/exportfs.h
include/linux/lockd/lockd.h

index e9b85d8fd5fe756acd55934b7e619fa0ea9c1a50..cb3658ab9b7aed37baaef3183590d52dbed91c10 100644 (file)
@@ -470,8 +470,10 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
            struct nlm_host *host, struct nlm_lock *lock, int wait,
            struct nlm_cookie *cookie, int reclaim)
 {
-       struct nlm_block        *block = NULL;
+#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
        struct inode            *inode = nlmsvc_file_inode(file);
+#endif
+       struct nlm_block        *block = NULL;
        int                     error;
        int                     mode;
        int                     async_block = 0;
@@ -484,7 +486,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
                                (long long)lock->fl.fl_end,
                                wait);
 
-       if (inode->i_sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS) {
+       if (nlmsvc_file_file(file)->f_op->lock) {
                async_block = wait;
                wait = 0;
        }
index 171c424cb6d53027f8edb109e64296a8e8db04c8..01596f2d0a1ed6127afd006d93b1abedd4cf0f7f 100644 (file)
@@ -158,5 +158,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_SYNC_LOCKS,
+               EXPORT_OP_NOATOMIC_ATTR,
 };
index 72e3833c30349f8a3e47d181f9dbe7c97626c989..d8faccc5547988e8b6bc3760d63c302fc249cc31 100644 (file)
@@ -6842,7 +6842,6 @@ 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;
@@ -6864,7 +6863,6 @@ 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))
@@ -6916,8 +6914,7 @@ 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) &&
-                           !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS))
+                       if (nfsd4_has_session(cstate))
                                fl_flags |= FL_SLEEP;
                        fallthrough;
                case NFS4_READ_LT:
@@ -6929,8 +6926,7 @@ 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) &&
-                           !(sb->s_export_op->flags & EXPORT_OP_SYNC_LOCKS))
+                       if (nfsd4_has_session(cstate))
                                fl_flags |= FL_SLEEP;
                        fallthrough;
                case NFS4_WRITE_LT:
@@ -6951,6 +6947,16 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
+       /*
+        * Most filesystems with their own ->lock operations will block
+        * the nfsd thread waiting to acquire the lock.  That leads to
+        * deadlocks (we don't want every nfsd thread tied up waiting
+        * for file locks), so don't attempt blocking lock notifications
+        * on those filesystems:
+        */
+       if (nf->nf_file->f_op->lock)
+               fl_flags &= ~FL_SLEEP;
+
        nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn);
        if (!nbl) {
                dprintk("NFSD: %s: unable to allocate block!\n", __func__);
index 3260fe7148462687d9c3d9a6e54e595deb678121..fe848901fcc3acb04a732b82df95c86fbad93ddc 100644 (file)
@@ -221,8 +221,6 @@ 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;
 };
 
index c4ae6506b8b3607c2b1cc04376558daefce9eacf..fcef192e5e45ed4c3f5b87fa3c6f0d316c43b9db 100644 (file)
@@ -303,10 +303,15 @@ void                nlmsvc_invalidate_all(void);
 int           nlmsvc_unlock_all_by_sb(struct super_block *sb);
 int           nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr);
 
+static inline struct file *nlmsvc_file_file(struct nlm_file *file)
+{
+       return file->f_file[O_RDONLY] ?
+              file->f_file[O_RDONLY] : file->f_file[O_WRONLY];
+}
+
 static inline struct inode *nlmsvc_file_inode(struct nlm_file *file)
 {
-       return locks_inode(file->f_file[O_RDONLY] ?
-                          file->f_file[O_RDONLY] : file->f_file[O_WRONLY]);
+       return locks_inode(nlmsvc_file_file(file));
 }
 
 static inline int __nlm_privileged_request4(const struct sockaddr *sap)