From: NeilBrown <neilb@ownmail.net>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
linux-nfs@vger.kernel.org
Subject: [PATCH v2 2/2] locks: ensure vfs_test_lock() never returns FILE_LOCK_DEFERRED
Date: Sat, 22 Nov 2025 12:00:37 +1100 [thread overview]
Message-ID: <20251122010253.3445570-3-neilb@ownmail.net> (raw)
In-Reply-To: <20251122010253.3445570-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
FILE_LOCK_DEFERRED can be returned when creating or removing a lock, but
not when testing for a lock. This support was explicitly removed in
Commit 09802fd2a8ca ("lockd: rip out deferred lock handling from testlock codepath")
However the test in nlmsvc_testlock() suggests that it *can* be returned,
only nlm cannot handle it.
To aid clarity, remove the test and instead put a similar test and
warning in vfs_test_lock(). If the impossible happens, convert
FILE_LOCK_DEFERRED to -EIO.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/lockd/svclock.c | 4 ----
fs/locks.c | 17 ++++++++++++++---
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index d66e82851599..dfd1a12b7887 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -635,10 +635,6 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
conflock->fl.c.flc_owner = lock->fl.c.flc_owner;
error = vfs_test_lock(file->f_file[mode], &conflock->fl);
if (error) {
- /* We can't currently deal with deferred test requests */
- if (error == FILE_LOCK_DEFERRED)
- WARN_ON_ONCE(1);
-
ret = nlm_lck_denied_nolocks;
goto out;
}
diff --git a/fs/locks.c b/fs/locks.c
index bf5e0d05a026..b5a3bb8790f3 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2199,12 +2199,23 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd)
*/
int vfs_test_lock(struct file *filp, struct file_lock *fl)
{
+ int error = 0;
+
WARN_ON_ONCE(fl->fl_ops || fl->fl_lmops);
WARN_ON_ONCE(filp != fl->c.flc_file);
if (filp->f_op->lock)
- return filp->f_op->lock(filp, F_GETLK, fl);
- posix_test_lock(filp, fl);
- return 0;
+ error = filp->f_op->lock(filp, F_GETLK, fl);
+ else
+ posix_test_lock(filp, fl);
+
+ /*
+ * We don't expect FILE_LOCK_DEFERRED and callers cannot
+ * handle it.
+ */
+ if (WARN_ON_ONCE(error == FILE_LOCK_DEFERRED))
+ error = -EIO;
+
+ return error;
}
EXPORT_SYMBOL_GPL(vfs_test_lock);
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2025-11-22 1:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 1:00 [PATCH v2 0/2] lockd/locks: address issues with vfs_test_lock() NeilBrown
2025-11-22 1:00 ` [PATCH v2 1/2] lockd: fix vfs_test_lock() calls NeilBrown
2025-11-22 16:10 ` Chuck Lever
2025-11-22 20:48 ` NeilBrown
2025-11-23 12:15 ` Jeff Layton
2025-11-22 1:00 ` NeilBrown [this message]
2025-11-22 16:29 ` [PATCH v2 0/2] lockd/locks: address issues with vfs_test_lock() Chuck Lever
2025-11-23 12:16 ` Jeff Layton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251122010253.3445570-3-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox