All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: linux-fsdevel@vger.kernel.org
To: me <bfields@umich.edu>
Cc: nfs@lists.sourceforge.net, Marc Eshel <eshel@almaden.ibm.com>
Subject: [PATCH 7/10] lockd: handle test_lock deferrals
Date: Wed,  6 Dec 2006 00:34:17 -0500	[thread overview]
Message-ID: <1165383260548-git-send-email-bfields@fieldses.org> (raw)
Message-ID: <c214e0a0062abdbb72f0810c25ab7688e51b4dbd.1165380893.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <11653832601925-git-send-email-bfields@fieldses.org>
In-Reply-To: <8eb625184e6025f7f3d081dfe0a805abdd62a068.1165380892.git.bfields@citi.umich.edu>

From: Marc Eshel <eshel@almaden.ibm.com>

Rewrite nlmsvc_testlock() to use the new asynchronous interface: instead of
immediately doing a posix_test_lock(), we first look for a matching block.
If the subsequent test_lock returns anything other than -EINPROGRESS, we
then remove the block we've found and return the results.

If it returns -EINPROGRESS, then we defer the lock request.

In the case where the block we find in the first step has B_QUEUED set,
we bypass the vfs_test_lock entirely, instead using the block to decide how
to respond:
	with nlm_lck_denied if B_TOO_LATE is set.
	with nlm_granted if B_GOT_CALLBACK is set.
	by dropping if neither B_TOO_LATE nor B_GOT_CALLBACK is set

Signed-off-by: Marc Eshel <eshel@almaden.ibm.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
 fs/lockd/svclock.c |   59 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index e342046..21185a7 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -553,6 +553,9 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 		struct nlm_lock *lock, struct nlm_lock *conflock,
 		struct nlm_cookie *cookie)
 {
+	struct nlm_block *block = NULL;
+	int error;
+
 	dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
 				file->f_file->f_dentry->d_inode->i_sb->s_id,
 				file->f_file->f_dentry->d_inode->i_ino,
@@ -560,19 +563,53 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 				(long long)lock->fl.fl_start,
 				(long long)lock->fl.fl_end);
 
-	if (posix_test_lock(file->f_file, &lock->fl, &conflock->fl)) {
-		dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
-				conflock->fl.fl_type,
-				(long long)conflock->fl.fl_start,
-				(long long)conflock->fl.fl_end);
-		conflock->caller = "somehost";	/* FIXME */
-		conflock->len = strlen(conflock->caller);
-		conflock->oh.len = 0;		/* don't return OH info */
-		conflock->svid = conflock->fl.fl_pid;
-		return nlm_lck_denied;
+	/* Get existing block (in case client is busy-waiting) */
+	block = nlmsvc_lookup_block(file, lock);
+
+	if (block == NULL) {
+		block = nlmsvc_create_block(rqstp, file, lock, cookie);
+		if (block == NULL)
+			return nlm_granted;
 	}
+	if (block->b_flags & B_QUEUED) {
+		dprintk("lockd: nlmsvc_testlock deferred block %p flags %d fl %p\n",
+			block, block->b_flags, block->b_fl);
+		if (block->b_flags & B_TOO_LATE) {
+			nlmsvc_unlink_block(block);
+			return nlm_lck_denied;
+		}
+		if (block->b_flags & B_GOT_CALLBACK) {
+			if (block->b_fl != NULL) {
+				conflock->fl = *block->b_fl;
+				goto conf_lock;
+			}
+			else {
+				nlmsvc_unlink_block(block);
+				return nlm_granted;
+			}
+		}
+		return nlm_drop_reply;
+ 	}
 
-	return nlm_granted;
+	error = vfs_test_lock(file->f_file, &lock->fl, &conflock->fl);
+	if (!error) {
+		nlmsvc_unlink_block(block);
+		return nlm_granted;
+        }
+	if (error == -EINPROGRESS)
+		return nlmsvc_defer_lock_rqst(rqstp, block);
+
+conf_lock:
+	dprintk("lockd: conflicting lock(ty=%d, %Ld-%Ld)\n",
+		conflock->fl.fl_type, (long long)conflock->fl.fl_start,
+		(long long)conflock->fl.fl_end);
+	conflock->caller = "somehost";	/* FIXME */
+	conflock->len = strlen(conflock->caller);
+	conflock->oh.len = 0;		/* don't return OH info */
+	conflock->svid = conflock->fl.fl_pid;
+	if (block)
+		nlmsvc_unlink_block(block);
+	return nlm_lck_denied;
 }
 
 /*
-- 
1.4.4.1


  parent reply	other threads:[~2006-12-06  5:34 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  5:34 asynchronous locks for cluster exports J. Bruce Fields
2006-12-06  5:34 ` [PATCH 1/10] lockd: add new export operation for nfsv4/lockd locking J. Bruce Fields
2006-12-06  5:34   ` J. Bruce Fields
2006-12-09  5:53     ` Wendy Cheng
2006-12-10 18:31       ` J. Bruce Fields
2006-12-06  5:34   ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 2/10] nfsd4: Convert NFSv4 to new lock interface J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 3/10] lockd: request deferral routine J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 4/10] locks: add fl_notify arguments J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 5/10] lockd: handle fl_notify callbacks J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 6/10] lockd: pass cookie in nlmsvc_testlock J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` J. Bruce Fields [this message]
2006-12-06  5:34     ` [PATCH 7/10] lockd: handle test_lock deferrals J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 8/10] lockd: always preallocate block in nlmsvc_lock() J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 9/10] lockd: add code to handle deferred lock requests J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34   ` [PATCH 10/10] gfs2: nfs lock support for gfs2 J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  5:34     ` J. Bruce Fields
2006-12-06  6:00       ` [NFS] " Wendy Cheng
2006-12-06 13:26         ` Wendy Cheng
2006-12-06 12:02     ` [Cluster-devel] " Steven Whitehouse
2006-12-06 12:02       ` Steven Whitehouse
2006-12-06 15:49     ` David Teigland
2006-12-06 19:57       ` J. Bruce Fields
2006-12-06 20:08         ` [NFS] " J. Bruce Fields
2006-12-06 20:58         ` David Teigland
2006-12-06 21:23           ` J. Bruce Fields
2006-12-06 21:42             ` David Teigland
2006-12-06 22:00               ` [NFS] " J. Bruce Fields
2006-12-07 15:30                 ` David Teigland
2006-12-08 17:35                   ` [NFS] " J. Bruce Fields
2006-12-07  6:47           ` Marc Eshel
2006-12-07 15:23             ` J. Bruce Fields
2006-12-07 15:43               ` [NFS] " Marc Eshel
2006-12-07 16:21                 ` J. Bruce Fields
2006-12-07 18:52                   ` [NFS] " Trond Myklebust
2006-12-14 23:04   ` [PATCH 1/10] lockd: add new export operation for nfsv4/lockd locking J. Bruce Fields
2006-12-15  5:52     ` Marc Eshel
2006-12-15  7:40     ` Christoph Hellwig
2006-12-07 16:51 ` asynchronous locks for cluster exports Christoph Hellwig
2006-12-14 22:51   ` J. Bruce Fields
2006-12-15 19:51 ` J. 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=1165383260548-git-send-email-bfields@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=eshel@almaden.ibm.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=nfs@lists.sourceforge.net \
    /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.