From: Dai Ngo <dai.ngo@oracle.com>
To: chuck.lever@oracle.com, bfields@fieldses.org
Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk,
linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH RFC v13 2/4] fs/lock: add new callback, lm_lock_expired, to lock_manager_operations
Date: Sat, 12 Feb 2022 10:12:53 -0800 [thread overview]
Message-ID: <1644689575-1235-3-git-send-email-dai.ngo@oracle.com> (raw)
In-Reply-To: <1644689575-1235-1-git-send-email-dai.ngo@oracle.com>
Add new callback, lm_lock_expired, to lock_manager_operations to allow
the lock manager to take appropriate action to resolve the lock conflict
if possible. The callback takes 1 argument, the file_lock of the blocker
and returns true if the conflict was resolved else returns false. Note
that the lock manager has to be able to resolve the conflict while
the spinlock flc_lock is held.
Lock manager, such as NFSv4 courteous server, uses this callback to
resolve conflict by destroying lock owner, or the NFSv4 courtesy client
(client that has expired but allowed to maintains its states) that owns
the lock.
Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
---
Documentation/filesystems/locking.rst | 2 ++
fs/locks.c | 14 ++++++++++----
include/linux/fs.h | 1 +
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst
index aaca0b601819..ebd73e76cb7e 100644
--- a/Documentation/filesystems/locking.rst
+++ b/Documentation/filesystems/locking.rst
@@ -434,6 +434,7 @@ prototypes::
void (*lm_break)(struct file_lock *); /* break_lease callback */
int (*lm_change)(struct file_lock **, int);
bool (*lm_breaker_owns_lease)(struct file_lock *);
+ bool (*lm_lock_expired)(struct file_lock *);
locking rules:
@@ -445,6 +446,7 @@ lm_grant: no no no
lm_break: yes no no
lm_change yes no no
lm_breaker_owns_lease: yes no no
+lm_lock_expired yes no no
====================== ============= ================= =========
buffer_head
diff --git a/fs/locks.c b/fs/locks.c
index 8c6df10cd9ed..52ede42651df 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -883,10 +883,13 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
spin_lock(&ctx->flc_lock);
list_for_each_entry(cfl, &ctx->flc_posix, fl_list) {
- if (posix_locks_conflict(fl, cfl)) {
- locks_copy_conflock(fl, cfl);
- goto out;
- }
+ if (!posix_locks_conflict(fl, cfl))
+ continue;
+ if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expired &&
+ cfl->fl_lmops->lm_lock_expired(cfl))
+ continue;
+ locks_copy_conflock(fl, cfl);
+ goto out;
}
fl->fl_type = F_UNLCK;
out:
@@ -1089,6 +1092,9 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
if (!posix_locks_conflict(request, fl))
continue;
+ if (fl->fl_lmops && fl->fl_lmops->lm_lock_expired &&
+ fl->fl_lmops->lm_lock_expired(fl))
+ continue;
if (conflock)
locks_copy_conflock(conflock, fl);
error = -EAGAIN;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e2d892b201b0..831b20430d6e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1062,6 +1062,7 @@ struct lock_manager_operations {
int (*lm_change)(struct file_lock *, int, struct list_head *);
void (*lm_setup)(struct file_lock *, void **);
bool (*lm_breaker_owns_lease)(struct file_lock *);
+ bool (*lm_lock_expired)(struct file_lock *cfl);
};
struct lock_manager {
--
2.9.5
next prev parent reply other threads:[~2022-02-12 18:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-12 18:12 [PATCH RFC v13 0/4] nfsd: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-02-12 18:12 ` [PATCH RFC v13 1/4] fs/lock: documentation cleanup. Replace inode->i_lock with flc_lock Dai Ngo
2022-02-14 17:03 ` Chuck Lever III
2022-02-14 17:24 ` Jeff Layton
2022-02-12 18:12 ` Dai Ngo [this message]
2022-02-12 18:12 ` [PATCH RFC v13 3/4] fs/lock: only call lm_breaker_owns_lease if there is conflict Dai Ngo
2022-02-12 18:12 ` [PATCH RFC v13 4/4] nfsd: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-02-15 17:17 ` Chuck Lever III
2022-02-16 9:56 ` dai.ngo
2022-02-16 16:15 ` Chuck Lever III
2022-02-18 18:03 ` dai.ngo
2022-02-18 18:28 ` Chuck Lever III
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=1644689575-1235-3-git-send-email-dai.ngo@oracle.com \
--to=dai.ngo@oracle.com \
--cc=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=jlayton@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).