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 5/10] lockd: handle fl_notify callbacks
Date: Wed,  6 Dec 2006 00:34:15 -0500	[thread overview]
Message-ID: <1165383260424-git-send-email-bfields@fieldses.org> (raw)
Message-ID: <e9e7fa0047137e5c988edaacc3dc70a84eb02efb.1165380893.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <11653832601635-git-send-email-bfields@fieldses.org>
In-Reply-To: <8eb625184e6025f7f3d081dfe0a805abdd62a068.1165380892.git.bfields@citi.umich.edu>

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

Add code to handle file system callback when the lock is finally granted.

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

diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 32f4cc4..90aa4a5 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -367,6 +367,8 @@ static void nlmsvc_free_block(struct kref *kref)
 	nlmsvc_freegrantargs(block->b_call);
 	nlm_release_call(block->b_call);
 	nlm_release_file(block->b_file);
+	if (block->b_fl)
+		kfree(block->b_fl);
 	kfree(block);
 }
 
@@ -631,6 +633,32 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
 }
 
 /*
+ * This is a callback from the filesystem for VFS file lock requests.
+ * It will be used if fl_notify is defined and the filesystem can not
+ * respond to the request immediately.
+ * For GETLK request it will copy the reply to the nlm_block.
+ * For SETLK or SETLKW request it will get the local posix lock.
+ * In all cases it will move the block to the head of nlm_blocked q where
+ * nlmsvc_retry_blocked() can send back a reply for SETLKW or revisit the
+ * deferred rpc for GETLK and SETLK.
+ */
+static void
+nlmsvc_update_deferred_block(struct nlm_block *block, struct file_lock *conf,
+			     int result)
+{
+	block->b_flags |= B_GOT_CALLBACK;
+	if (result == 0)
+		block->b_granted = 1;
+	else
+		block->b_flags |= B_TOO_LATE;
+	if (conf) {
+		block->b_fl = kmalloc(sizeof(struct file_lock), GFP_KERNEL);
+		if (block->b_fl)
+			locks_copy_lock(block->b_fl, conf);
+	}
+}
+
+/*
  * Unblock a blocked lock request. This is a callback invoked from the
  * VFS layer when a lock on which we blocked is removed.
  *
@@ -641,18 +669,33 @@ static int
 nlmsvc_notify_blocked(struct file_lock *fl, struct file_lock *conf, int result)
 {
 	struct nlm_block	*block;
+	int rc = -ENOENT;
 
 	dprintk("lockd: nlmsvc_notify_blocked lock %p conf %p result %d\n",
 							fl, conf, result);
+	lock_kernel();
 	list_for_each_entry(block, &nlm_blocked, b_list) {
 		if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
+			dprintk("lockd: nlmsvc_notify_blocked block %p flags %d\n",
+							block, block->b_flags);
+			if (block->b_flags & B_QUEUED) {
+				if (block->b_flags & B_TOO_LATE) {
+					rc = -ENOLCK;
+					break;
+				}
+				nlmsvc_update_deferred_block(block, conf, result);
+			}
 			nlmsvc_insert_block(block, 0);
 			svc_wake_up(block->b_daemon);
-			return;
+			rc = 0;
+			break;
 		}
 	}
+	unlock_kernel();
 
-	printk(KERN_WARNING "lockd: notification for unknown block!\n");
+	if (rc == -ENOENT)
+		printk(KERN_WARNING "lockd: notification for unknown block!\n");
+	return rc;
 }
 
 static int nlmsvc_same_owner(struct file_lock *fl1, struct file_lock *fl2)
@@ -685,6 +728,8 @@ nlmsvc_grant_blocked(struct nlm_block *block)
 
 	dprintk("lockd: grant blocked lock %p\n", block);
 
+	kref_get(&block->b_count);
+
 	/* Unlink block request from list */
 	nlmsvc_unlink_block(block);
 
@@ -707,11 +752,13 @@ nlmsvc_grant_blocked(struct nlm_block *block)
 	case -EAGAIN:
 		dprintk("lockd: lock still blocked\n");
 		nlmsvc_insert_block(block, NLM_NEVER);
+		nlmsvc_release_block(block);
 		return;
 	default:
 		printk(KERN_WARNING "lockd: unexpected error %d in %s!\n",
 				-error, __FUNCTION__);
 		nlmsvc_insert_block(block, 10 * HZ);
+		nlmsvc_release_block(block);
 		return;
 	}
 
@@ -724,7 +771,6 @@ callback:
 	nlmsvc_insert_block(block, 30 * HZ);
 
 	/* Call the client */
-	kref_get(&block->b_count);
 	if (nlm_async_call(block->b_call, NLMPROC_GRANTED_MSG,
 						&nlmsvc_grant_ops) < 0)
 		nlmsvc_release_block(block);
@@ -799,6 +845,23 @@ nlmsvc_grant_reply(struct nlm_cookie *cookie, u32 status)
 	nlmsvc_release_block(block);
 }
 
+/* Helper function to handle retry of a deferred block.
+ * If it is a blocking lock, call grant_blocked.
+ * For a non-blocking lock or test lock, revisit the request.
+ */
+static void
+retry_deferred_block(struct nlm_block *block)
+{
+	if (!(block->b_flags & B_GOT_CALLBACK))
+		block->b_flags |= B_TOO_LATE;
+	nlmsvc_insert_block(block, NLM_TIMEOUT);
+	dprintk("revisit block %p flags %d\n",	block, block->b_flags);
+	if (block->b_deferred_req) {
+		block->b_deferred_req->revisit(block->b_deferred_req, 0);
+		block->b_deferred_req = NULL;
+	}
+}
+
 /*
  * Retry all blocked locks that have been notified. This is where lockd
  * picks up locks that can be granted, or grant notifications that must
@@ -822,9 +885,12 @@ nlmsvc_retry_blocked(void)
 
 		dprintk("nlmsvc_retry_blocked(%p, when=%ld)\n",
 			block, block->b_when);
-		kref_get(&block->b_count);
-		nlmsvc_grant_blocked(block);
-		nlmsvc_release_block(block);
+		if (block->b_flags & B_QUEUED) {
+			dprintk("nlmsvc_retry_blocked delete block (%p, granted=%d, flags=%d)\n",
+				block, block->b_granted, block->b_flags);
+			retry_deferred_block(block);
+		} else
+			nlmsvc_grant_blocked(block);
 	}
 
 	return timeout;
-- 
1.4.4.1


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

  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-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   ` [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   ` J. Bruce Fields [this message]
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   ` [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   ` [PATCH 7/10] lockd: handle test_lock deferrals 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 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=1165383260424-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.