All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dai Ngo <dai.ngo@oracle.com>
To: bfields@fieldses.org
Cc: chuck.lever@oracle.com, linux-nfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH RFC v5 1/2] fs/lock: add new callback, lm_expire_lock, to lock_manager_operations
Date: Tue, 28 Sep 2021 20:56:40 -0400	[thread overview]
Message-ID: <20210929005641.60861-2-dai.ngo@oracle.com> (raw)
In-Reply-To: <20210929005641.60861-1-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 2 arguments, file_lock of the blocker
and a testonly flag:

testonly = 1  check and return true if lock conflict can be resolved
              else return false.
testonly = 0  resolve the conflict if possible, return true if conflict
              was resolved esle return false.

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         | 28 +++++++++++++++++++++++++---
 include/linux/fs.h |  1 +
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 3d6fb4ae847b..0fef0a6322c7 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -954,6 +954,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
 	struct file_lock *cfl;
 	struct file_lock_context *ctx;
 	struct inode *inode = locks_inode(filp);
+	bool ret;
 
 	ctx = smp_load_acquire(&inode->i_flctx);
 	if (!ctx || list_empty_careful(&ctx->flc_posix)) {
@@ -962,11 +963,20 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
 	}
 
 	spin_lock(&ctx->flc_lock);
+retry:
 	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, 1)) {
+			spin_unlock(&ctx->flc_lock);
+			ret = cfl->fl_lmops->lm_expire_lock(cfl, 0);
+			spin_lock(&ctx->flc_lock);
+			if (ret)
+				goto retry;
 		}
+		locks_copy_conflock(fl, cfl);
+		goto out;
 	}
 	fl->fl_type = F_UNLCK;
 out:
@@ -1140,6 +1150,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
 	int error;
 	bool added = false;
 	LIST_HEAD(dispose);
+	bool ret;
 
 	ctx = locks_get_lock_context(inode, request->fl_type);
 	if (!ctx)
@@ -1166,9 +1177,20 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,
 	 * blocker's list of waiters and the global blocked_hash.
 	 */
 	if (request->fl_type != F_UNLCK) {
+retry:
 		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, 1)) {
+				spin_unlock(&ctx->flc_lock);
+				percpu_up_read(&file_rwsem);
+				ret = fl->fl_lmops->lm_expire_lock(fl, 0);
+				percpu_down_read(&file_rwsem);
+				spin_lock(&ctx->flc_lock);
+				if (ret)
+					goto retry;
+			}
 			if (conflock)
 				locks_copy_conflock(conflock, fl);
 			error = -EAGAIN;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7a633353fd2..1a76b6451398 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 *fl, bool testonly);
 };
 
 struct lock_manager {
-- 
2.9.5


  reply	other threads:[~2021-09-29  0:56 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  0:56 [PATCH RFC v5 0/2] nfsd: Initial implementation of NFSv4 Courteous Server Dai Ngo
2021-09-29  0:56 ` Dai Ngo [this message]
2021-09-29  0:56 ` [PATCH RFC v5 2/2] " Dai Ngo
2021-10-01 20:53 ` [PATCH RFC v5 0/2] " J. Bruce Fields
2021-10-01 21:41   ` dai.ngo
2021-10-01 23:03     ` J. Bruce Fields
2021-11-16 23:06     ` dai.ngo
2021-11-17 14:14       ` J. Bruce Fields
2021-11-17 17:59         ` dai.ngo
2021-11-17 21:46           ` dai.ngo
2021-11-18  0:34             ` J. Bruce Fields
2021-11-22  3:04               ` dai.ngo
2021-11-29 17:13                 ` dai.ngo
2021-11-29 17:30                   ` J. Bruce Fields
2021-11-29 18:32                     ` dai.ngo
2021-11-29 19:03                       ` Chuck Lever III
2021-11-29 19:13                         ` Bruce Fields
2021-11-29 19:39                           ` dai.ngo
2021-11-29 19:36                         ` dai.ngo
2021-11-29 21:01                           ` dai.ngo
2021-11-29 21:10                           ` Chuck Lever III
2021-11-30  0:11                             ` dai.ngo
2021-11-30  1:42                               ` Chuck Lever III
2021-11-30  4:08                                 ` Trond Myklebust
2021-11-30  4:47                                   ` Chuck Lever III
2021-11-30  4:57                                     ` Trond Myklebust
2021-11-30  7:22                                       ` dai.ngo
2021-11-30 13:37                                         ` Trond Myklebust
2021-12-01  3:52                                           ` dai.ngo
2021-12-01 14:19                                             ` bfields
2021-11-30 15:36                                         ` Chuck Lever III
2021-11-30 16:05                                           ` Bruce Fields
2021-11-30 16:14                                             ` Trond Myklebust
2021-11-30 19:01                                               ` bfields
2021-11-30  7:13                                 ` dai.ngo
2021-11-30 15:32                                   ` Bruce Fields
2021-12-01  3:50                                     ` dai.ngo
2021-12-01 14:36                                       ` Bruce Fields
2021-12-01 14:51                                         ` Bruce Fields
2021-12-01 18:47                                           ` dai.ngo
2021-12-01 19:25                                             ` Bruce Fields
2021-12-02 17:53                                           ` Chuck Lever III
2021-12-01 17:42                                         ` Bruce Fields
2021-12-01 18:03                                           ` Bruce Fields
2021-12-01 19:50                                             ` Bruce Fields
2021-12-03 21:22                                               ` Bruce Fields
2021-12-03 21:55                                                 ` [PATCH] nfsdcld: use WAL journal for faster commits Bruce Fields
2021-12-03 22:07                                                   ` Chuck Lever III
2021-12-03 22:39                                                     ` Bruce Fields
2021-12-04  0:35                                                       ` Chuck Lever III
2021-12-04  1:24                                                         ` Bruce Fields
2021-12-06 15:46                                                           ` Chuck Lever III
2022-01-04 22:24                                                             ` Bruce Fields

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=20210929005641.60861-2-dai.ngo@oracle.com \
    --to=dai.ngo@oracle.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-nfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.