Skip to content

Commit 7e64c5b

Browse files
bcodding-rhbrauner
authored andcommitted
NLM/NFSD: Fix lock notifications for async-capable filesystems
Instead of checking just the exportfs flag, use the new locks_can_async_lock() helper which allows NLM and NFSD to once again support lock notifications for all filesystems which use posix_lock_file(). Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Link: https://lore.kernel.org/r/865c40da44af67939e8eb560d17a26c9c50f23e0.1726083391.git.bcodding@redhat.com Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 2253ab9 commit 7e64c5b

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

fs/lockd/svclock.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <linux/sunrpc/svc_xprt.h>
3131
#include <linux/lockd/nlm.h>
3232
#include <linux/lockd/lockd.h>
33-
#include <linux/exportfs.h>
3433

3534
#define NLMDBG_FACILITY NLMDBG_SVCLOCK
3635

@@ -481,7 +480,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
481480
struct nlm_host *host, struct nlm_lock *lock, int wait,
482481
struct nlm_cookie *cookie, int reclaim)
483482
{
484-
struct inode *inode = nlmsvc_file_inode(file);
483+
struct inode *inode __maybe_unused = nlmsvc_file_inode(file);
485484
struct nlm_block *block = NULL;
486485
int error;
487486
int mode;
@@ -496,7 +495,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
496495
(long long)lock->fl.fl_end,
497496
wait);
498497

499-
if (!exportfs_lock_op_is_async(inode->i_sb->s_export_op)) {
498+
if (!locks_can_async_lock(nlmsvc_file_file(file)->f_op)) {
500499
async_block = wait;
501500
wait = 0;
502501
}
@@ -550,7 +549,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
550549
* requests on the underlaying ->lock() implementation but
551550
* only one nlm_block to being granted by lm_grant().
552551
*/
553-
if (exportfs_lock_op_is_async(inode->i_sb->s_export_op) &&
552+
if (locks_can_async_lock(nlmsvc_file_file(file)->f_op) &&
554553
!list_empty(&block->b_list)) {
555554
spin_unlock(&nlm_blocked_lock);
556555
ret = nlm_lck_blocked;

fs/nfsd/nfs4state.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7953,9 +7953,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
79537953
fp = lock_stp->st_stid.sc_file;
79547954
switch (lock->lk_type) {
79557955
case NFS4_READW_LT:
7956-
if (nfsd4_has_session(cstate) ||
7957-
exportfs_lock_op_is_async(sb->s_export_op))
7958-
flags |= FL_SLEEP;
79597956
fallthrough;
79607957
case NFS4_READ_LT:
79617958
spin_lock(&fp->fi_lock);
@@ -7966,9 +7963,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
79667963
type = F_RDLCK;
79677964
break;
79687965
case NFS4_WRITEW_LT:
7969-
if (nfsd4_has_session(cstate) ||
7970-
exportfs_lock_op_is_async(sb->s_export_op))
7971-
flags |= FL_SLEEP;
79727966
fallthrough;
79737967
case NFS4_WRITE_LT:
79747968
spin_lock(&fp->fi_lock);
@@ -7988,15 +7982,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
79887982
goto out;
79897983
}
79907984

7991-
/*
7992-
* Most filesystems with their own ->lock operations will block
7993-
* the nfsd thread waiting to acquire the lock. That leads to
7994-
* deadlocks (we don't want every nfsd thread tied up waiting
7995-
* for file locks), so don't attempt blocking lock notifications
7996-
* on those filesystems:
7997-
*/
7998-
if (!exportfs_lock_op_is_async(sb->s_export_op))
7999-
flags &= ~FL_SLEEP;
7985+
if (lock->lk_type & (NFS4_READW_LT | NFS4_WRITEW_LT) &&
7986+
nfsd4_has_session(cstate) &&
7987+
locks_can_async_lock(nf->nf_file->f_op))
7988+
flags |= FL_SLEEP;
80007989

80017990
nbl = find_or_allocate_block(lock_sop, &fp->fi_fhandle, nn);
80027991
if (!nbl) {

0 commit comments

Comments
 (0)