From: Dai Ngo <dai.ngo@oracle.com>
To: bfields@fieldses.org, chuck.lever@oracle.com
Cc: jlayton@redhat.com, viro@zeniv.linux.org.uk,
linux-nfs@vger.kernel, linux-fsdevel@vger.kernel.org
Subject: [PATCH RFC v9 1/2] fs/lock: add new callback, lm_expire_lock, to lock_manager_operations
Date: Mon, 10 Jan 2022 10:40:28 -0800 [thread overview]
Message-ID: <1641840029-20972-2-git-send-email-dai.ngo@oracle.com> (raw)
In-Reply-To: <1641840029-20972-1-git-send-email-dai.ngo@oracle.com>
Add new callback, lm_expire_lock, 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>
---
fs/locks.c | 14 ++++++++++----
include/linux/fs.h | 1 +
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index 3d6fb4ae847b..5844fd29560d 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -963,10 +963,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_expire_lock &&
+ cfl->fl_lmops->lm_expire_lock(cfl))
+ continue;
+ locks_copy_conflock(fl, cfl);
+ goto out;
}
fl->fl_type = F_UNLCK;
out:
@@ -1169,6 +1172,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_expire_lock &&
+ fl->fl_lmops->lm_expire_lock(fl))
+ continue;
if (conflock)
locks_copy_conflock(conflock, fl);
error = -EAGAIN;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7a633353fd2..0f70e0b39834 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1071,6 +1071,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_expire_lock)(struct file_lock *cfl);
};
struct lock_manager {
--
2.9.5
next prev parent reply other threads:[~2022-01-10 18:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-10 18:40 [PATCH RFC v9 0/2] nfsd: Initial implementation of NFSv4 Courteous Server Dai Ngo
2022-01-10 18:40 ` Dai Ngo [this message]
2022-01-10 18:40 ` [PATCH RFC v9 2/2] " Dai Ngo
-- strict thread matches above, loose matches on Subject: below --
2022-01-10 18:50 [PATCH RFC v9 0/2] " Dai Ngo
2022-01-10 18:50 ` [PATCH RFC v9 1/2] fs/lock: add new callback, lm_expire_lock, to lock_manager_operations Dai Ngo
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=1641840029-20972-2-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 \
--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).