Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Salvatore Bonaccorso <carnil@debian.org>
To: Julien Leclerc <julien.leclerc@saatchi.fr>,
	Jeff Layton <jlayton@kernel.org>
Cc: linux-nfs@vger.kernel.org, 1153524@bugs.debian.org,
	Chuck Lever <chuck.lever@oracle.com>,
	regressions@lists.linux.dev, stable@vger.kernel.org,
	Benjamin Coddington <bcodding@redhat.com>,
	Christian Brauner <brauner@kernel.org>,
	Salvatore Bonaccorso <carnil@debian.org>
Subject: [PATCH 1/4] fs: Introduce FOP_ASYNC_LOCK
Date: Fri,  4 Dec 2026 15:20:29 +0100	[thread overview]
Message-ID: <20261204142703.1100372-2-carnil@debian.org> (raw)
In-Reply-To: <20261204142703.1100372-1-carnil@debian.org>

From: Benjamin Coddington <bcodding@redhat.com>

commit 8cf9a01edc216b16b5839eb793ac544d2c97ce97 upstream.

Some lock managers (NLM, kNFSD) fastidiously avoid blocking their
kernel threads while servicing blocking locks.  If a filesystem supports
asynchronous lock requests those lock managers can use notifications to
quickly inform clients they have acquired a file lock.

Historically, only posix_lock_file() was capable of supporting asynchronous
locks so the check for support was simply file_operations->lock(), but with
recent changes in DLM, both GFS2 and OCFS2 also support asynchronous locks
and have started signalling their support with EXPORT_OP_ASYNC_LOCK.

We recently noticed that those changes dropped the checks for whether a
filesystem simply defaults to posix_lock_file(), so async lock
notifications have not been attempted for NLM and NFSv4.1+ for most
filesystems.  While trying to fix this it has become clear that testing
both the export flag combined with testing ->lock() creates quite a
layering mess.  It seems appropriate to signal support with a fop_flag.

Add FOP_ASYNC_LOCK so that filesystems with ->lock() can signal their
capability to handle lock requests asynchronously.  Add a helper for
lock managers to properly test that support.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
Link: https://lore.kernel.org/r/3330d5a324abe2ce9c1dafe89cacdc6db41945d1.1726083391.git.bcodding@redhat.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
[Salvatore Bonaccorso: Resolve conflict in include/linux/fs.h. v6.12
already defines FOP_UNSIGNED_OFFSET as bit 5, so FOP_ASYNC_LOCK goes in
as (1 << 6), its value in v6.13.]
Signed-off-by: Salvatore Bonaccorso <carnil@debian.org>
---
 include/linux/filelock.h | 5 +++++
 include/linux/fs.h       | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/filelock.h b/include/linux/filelock.h
index bb44224c6676..c412ded9171e 100644
--- a/include/linux/filelock.h
+++ b/include/linux/filelock.h
@@ -180,6 +180,11 @@ static inline void locks_wake_up(struct file_lock *fl)
 	wake_up(&fl->c.flc_wait);
 }
 
+static inline bool locks_can_async_lock(const struct file_operations *fops)
+{
+	return !fops->lock || fops->fop_flags & FOP_ASYNC_LOCK;
+}
+
 /* fs/locks.c */
 void locks_free_lock_context(struct inode *inode);
 void locks_free_lock(struct file_lock *fl);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index fc63611ac3c6..57a9f2e1e23c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2177,6 +2177,8 @@ struct file_operations {
 #define FOP_HUGE_PAGES		((__force fop_flags_t)(1 << 4))
 /* Treat loff_t as unsigned (e.g., /dev/mem) */
 #define FOP_UNSIGNED_OFFSET	((__force fop_flags_t)(1 << 5))
+/* Supports asynchronous lock callbacks */
+#define FOP_ASYNC_LOCK		((__force fop_flags_t)(1 << 6))
 
 /* Wrap a directory iterator that needs exclusive inode access */
 int wrap_directory_iterator(struct file *, struct dir_context *,
-- 
2.55.0


  reply	other threads:[~2026-12-04 14:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 14:20 [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Salvatore Bonaccorso
2026-12-04 14:20 ` Salvatore Bonaccorso [this message]
2026-12-04 14:20 ` [PATCH 2/4] gfs2/ocfs2: set FOP_ASYNC_LOCK Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 3/4] NLM/NFSD: Fix lock notifications for async-capable filesystems Salvatore Bonaccorso
2026-12-04 14:20 ` [PATCH 4/4] nfsd: fix FL_SLEEP being set unconditionally for all LOCK types Salvatore Bonaccorso
2026-12-04 14:37 ` [PATCH 6.12.y 0/4] Backport for "NLM/NFSD: Fix lock notifications for async-capable" Jeff Layton
2026-12-04 19:49 ` Sasha Levin

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=20261204142703.1100372-2-carnil@debian.org \
    --to=carnil@debian.org \
    --cc=1153524@bugs.debian.org \
    --cc=bcodding@redhat.com \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=julien.leclerc@saatchi.fr \
    --cc=linux-nfs@vger.kernel.org \
    --cc=regressions@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /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