From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: linux-fsdevel@vger.kernel.org
Cc: nfs@lists.sourceforge.net, Marc Eshel <eshel@almaden.ibm.com>
Subject: [PATCH 5/14] locks: add fl_notify arguments for asynchronous lock return
Date: Sat, 3 Feb 2007 00:34:01 -0500 [thread overview]
Message-ID: <31453.3895849765$1170480879@news.gmane.org> (raw)
Message-ID: <a4ecb8974d61a5077d24cf42ed2c564b4fa7aadf.1170479265.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <1170480851972-git-send-email->
In-Reply-To: <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>
From: Marc Eshel <eshel@almaden.ibm.com> - unquoted
Acquiring a lock on a cluster filesystem may require communication with remote
hosts, and to avoid blocking lockd or nfsd threads during such communication,
we allow the results to be returned asynchronously.
When a ->lock() call needs to block, the file system will return -EINPROGRESS,
and then later return the results with a call to the routine in the fl_notify
field of the lock_manager_operations struct.
Note that this is different from the ->lock() call discovering that there is a
conflict which would cause the caller to block; this is still handled in the
same way as before. In fact, we don't currently handle "blocking" locks at
all; those are less urgent, because the filesystem can always just return an
immediate -EAGAIN without denying the lock.
So this asynchronous interface is only used in the case of a non-blocking lock,
where we must know whether to allow or deny the lock now.
We're using fl_notify to asynchronously return the result of a lock
request. So we want fl_notify to be able to return a status and, if
appropriate, a conflicting lock.
This only current caller of fl_notify is in the blocked case, in which case
we don't use these extra arguments.
We also allow fl_notify to return an error. (Also ignored for now.)
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/svclock.c | 7 ++++---
fs/locks.c | 21 ++++++++++++++++++++-
include/linux/fs.h | 2 +-
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index c7db0a5..d2c8020 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -506,12 +506,13 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
* This function doesn't grant the blocked lock instantly, but rather moves
* the block to the head of nlm_blocked where it can be picked up by lockd.
*/
-static void
-nlmsvc_notify_blocked(struct file_lock *fl)
+static int
+nlmsvc_notify_blocked(struct file_lock *fl, struct file_lock *conf, int result)
{
struct nlm_block *block;
- dprintk("lockd: VFS unblock notification for block %p\n", fl);
+ dprintk("lockd: nlmsvc_notify_blocked lock %p conf %p result %d\n",
+ fl, conf, result);
list_for_each_entry(block, &nlm_blocked, b_list) {
if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
nlmsvc_insert_block(block, 0);
diff --git a/fs/locks.c b/fs/locks.c
index 1bd6418..819dc28 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -544,7 +544,7 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
struct file_lock, fl_block);
__locks_delete_block(waiter);
if (waiter->fl_lmops && waiter->fl_lmops->fl_notify)
- waiter->fl_lmops->fl_notify(waiter);
+ waiter->fl_lmops->fl_notify(waiter, NULL, -EAGAIN);
else
wake_up(&waiter->fl_wait);
}
@@ -1696,6 +1696,25 @@ out:
* @filp: The file to apply the lock to
* @cmd: type of locking operation (F_SETLK, F_GETLK, etc.)
* @fl: The lock to be applied
+ *
+ * To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX
+ * locks, the ->lock() interface may return asynchronously, before the lock has
+ * been granted or denied by the underlying filesystem, if (and only if)
+ * fl_notify is set. Callers expecting ->lock() to return asynchronously
+ * will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if)
+ * the request is for a blocking lock. When ->lock() does return asynchronously,
+ * it must return -EINPROGRESS, and call ->fl_notify() when the lock
+ * request completes.
+ * If the request is for non-blocking lock the file system should return
+ * -EINPROGRESS then try to get the lock and call the callback routine with
+ * the result. If the request timed out the callback routine will return a
+ * nonzero return code and the file system should release the lock. The file
+ * system is also responsible to keep a corresponding posix lock when it
+ * grants a lock so the VFS can find out which locks are locally held and do
+ * the correct lock cleanup when required.
+ * The underlying filesystem must not drop the kernel lock or call
+ * ->fl_notify() before returning to the caller with a -EINPROGRESS
+ * return code.
*/
int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1410e53..5d44d25 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -783,7 +783,7 @@ struct file_lock_operations {
struct lock_manager_operations {
int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
- void (*fl_notify)(struct file_lock *); /* unblock callback */
+ int (*fl_notify)(struct file_lock *, struct file_lock *, int);
void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
void (*fl_release_private)(struct file_lock *);
void (*fl_break)(struct file_lock *);
--
1.5.0.rc1.g72fe
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
NFS maillist - NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs
WARNING: multiple messages have this Message-ID (diff)
From: "J. Bruce Fields" <bfields@citi.umich.edu>
To: linux-fsdevel@vger.kernel.org
Cc: nfs@lists.sourceforge.net, Marc Eshel <eshel@almaden.ibm.com>
Subject: [PATCH 5/14] locks: add fl_notify arguments for asynchronous lock return
Date: Sat, 3 Feb 2007 00:34:01 -0500 [thread overview]
Message-ID: <43483.1035360277$1170484082@news.gmane.org> (raw)
Message-ID: <a4ecb8974d61a5077d24cf42ed2c564b4fa7aadf.1170479265.git.bfields@citi.umich.edu> (raw)
In-Reply-To: <1170480851972-git-send-email->
In-Reply-To: <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>
From: Marc Eshel <eshel@almaden.ibm.com> - unquoted
Acquiring a lock on a cluster filesystem may require communication with remote
hosts, and to avoid blocking lockd or nfsd threads during such communication,
we allow the results to be returned asynchronously.
When a ->lock() call needs to block, the file system will return -EINPROGRESS,
and then later return the results with a call to the routine in the fl_notify
field of the lock_manager_operations struct.
Note that this is different from the ->lock() call discovering that there is a
conflict which would cause the caller to block; this is still handled in the
same way as before. In fact, we don't currently handle "blocking" locks at
all; those are less urgent, because the filesystem can always just return an
immediate -EAGAIN without denying the lock.
So this asynchronous interface is only used in the case of a non-blocking lock,
where we must know whether to allow or deny the lock now.
We're using fl_notify to asynchronously return the result of a lock
request. So we want fl_notify to be able to return a status and, if
appropriate, a conflicting lock.
This only current caller of fl_notify is in the blocked case, in which case
we don't use these extra arguments.
We also allow fl_notify to return an error. (Also ignored for now.)
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
---
fs/lockd/svclock.c | 7 ++++---
fs/locks.c | 21 ++++++++++++++++++++-
include/linux/fs.h | 2 +-
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index c7db0a5..d2c8020 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -506,12 +506,13 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
* This function doesn't grant the blocked lock instantly, but rather moves
* the block to the head of nlm_blocked where it can be picked up by lockd.
*/
-static void
-nlmsvc_notify_blocked(struct file_lock *fl)
+static int
+nlmsvc_notify_blocked(struct file_lock *fl, struct file_lock *conf, int result)
{
struct nlm_block *block;
- dprintk("lockd: VFS unblock notification for block %p\n", fl);
+ dprintk("lockd: nlmsvc_notify_blocked lock %p conf %p result %d\n",
+ fl, conf, result);
list_for_each_entry(block, &nlm_blocked, b_list) {
if (nlm_compare_locks(&block->b_call->a_args.lock.fl, fl)) {
nlmsvc_insert_block(block, 0);
diff --git a/fs/locks.c b/fs/locks.c
index 1bd6418..819dc28 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -544,7 +544,7 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
struct file_lock, fl_block);
__locks_delete_block(waiter);
if (waiter->fl_lmops && waiter->fl_lmops->fl_notify)
- waiter->fl_lmops->fl_notify(waiter);
+ waiter->fl_lmops->fl_notify(waiter, NULL, -EAGAIN);
else
wake_up(&waiter->fl_wait);
}
@@ -1696,6 +1696,25 @@ out:
* @filp: The file to apply the lock to
* @cmd: type of locking operation (F_SETLK, F_GETLK, etc.)
* @fl: The lock to be applied
+ *
+ * To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX
+ * locks, the ->lock() interface may return asynchronously, before the lock has
+ * been granted or denied by the underlying filesystem, if (and only if)
+ * fl_notify is set. Callers expecting ->lock() to return asynchronously
+ * will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if)
+ * the request is for a blocking lock. When ->lock() does return asynchronously,
+ * it must return -EINPROGRESS, and call ->fl_notify() when the lock
+ * request completes.
+ * If the request is for non-blocking lock the file system should return
+ * -EINPROGRESS then try to get the lock and call the callback routine with
+ * the result. If the request timed out the callback routine will return a
+ * nonzero return code and the file system should release the lock. The file
+ * system is also responsible to keep a corresponding posix lock when it
+ * grants a lock so the VFS can find out which locks are locally held and do
+ * the correct lock cleanup when required.
+ * The underlying filesystem must not drop the kernel lock or call
+ * ->fl_notify() before returning to the caller with a -EINPROGRESS
+ * return code.
*/
int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1410e53..5d44d25 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -783,7 +783,7 @@ struct file_lock_operations {
struct lock_manager_operations {
int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
- void (*fl_notify)(struct file_lock *); /* unblock callback */
+ int (*fl_notify)(struct file_lock *, struct file_lock *, int);
void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
void (*fl_release_private)(struct file_lock *);
void (*fl_break)(struct file_lock *);
--
1.5.0.rc1.g72fe
next prev parent reply other threads:[~2007-02-03 5:34 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <11704808501171-git-send-email->
[not found] ` <11704808502512-git-send-email->
[not found] ` <11704808513862-git-send-email->
[not found] ` <1170480851972-git-send-email->
[not found] ` <11704808513070-git-send-email->
[not found] ` <117048085185-git-send-email->
[not found] ` <11704808513263-git-send-email->
[not found] ` <11704808513185-git-send-email->
[not found] ` <11704808511238-git-send-email->
[not found] ` <11704808513085-git-send-email->
[not found] ` <11704808521765-git-send-email->
[not found] ` <11704808523686-git-send-email->
[not found] ` <ad8373acbb12f165b625f6065bc0ca86f3982b7f.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:33 ` [PATCH 1/14] locks: always unlock on close J. Bruce Fields
2007-02-03 5:33 ` J. Bruce Fields
[not found] ` <1dd47bf9aeb6f19c82a59efb2f4236f23f73019d.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:33 ` [PATCH 3/14] locks: factor out generic/filesystem switch from setlock code J. Bruce Fields
2007-02-03 5:33 ` J. Bruce Fields
2007-02-03 8:51 ` Christoph Hellwig
2007-02-03 5:16 ` Brad Boyer
2007-02-04 2:27 ` J. Bruce Fields
2007-02-04 8:37 ` Christoph Hellwig
2007-02-03 21:27 ` Brad Boyer
2007-02-04 1:58 ` J. Bruce Fields
[not found] ` <96a0abaf64b433a7e7450e7e35d0baf2c44103db.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 4/14] locks: add locking function that returns conflicting lock J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
2007-02-03 8:54 ` Christoph Hellwig
2007-02-04 2:02 ` J. Bruce Fields
[not found] ` <a4ecb8974d61a5077d24cf42ed2c564b4fa7aadf.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` J. Bruce Fields [this message]
2007-02-03 5:34 ` [PATCH 5/14] locks: add fl_notify arguments for asynchronous lock return J. Bruce Fields
[not found] ` <fdf19cb6a33a08dd9220cdf2379d712d3c15e66f.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 6/14] locks: add lock cancel command J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <d1c313156428c533721d67f938ca72759b192156.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 7/14] nfsd4: Convert NFSv4 to new lock interface J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <8096fc4eb11f5c5678197fdee8afe0e2780357fc.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 8/14] lockd: save lock state on deferral J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <6f2a40ca33ea2b58e3f515bea9be1e0fa8cda6aa.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 9/14] lockd: handle fl_notify callbacks J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
2007-02-04 0:40 ` [NFS] " Trond Myklebust
2007-02-04 2:10 ` J. Bruce Fields
[not found] ` <19e4ad761534f2afd8045321c950a9336c6b1fc2.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 10/14] lockd: pass cookie in nlmsvc_testlock J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <ecc19d4bdf659f8cd1bbe4783625af5040f0b83a.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 11/14] lockd: handle test_lock deferrals J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <ed8e1981069ef91a62c19a16b37d51c819a5196f.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 12/14] lockd: always preallocate block in nlmsvc_lock() J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <b18934dedc3dd49bd1578256944c8fb756db2a6c.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 13/14] lockd: add code to handle deferred lock requests J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <6d1e339108dad3e204a1eb53e736a2a0f73dda22.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:34 ` [PATCH 14/14] gfs2: nfs lock support for gfs2 J. Bruce Fields
2007-02-03 5:34 ` J. Bruce Fields
[not found] ` <5cdd83858bf5c75e14742bbd03b462f5ec4997fe.1170479265.git.bfields@citi.umich.edu>
2007-02-03 5:33 ` [PATCH 2/14] locks: factor out generic/filesystem switch from test_lock J. Bruce Fields
2007-02-03 5:33 ` J. Bruce Fields
2007-02-03 8:50 ` Christoph Hellwig
2007-02-04 1:48 ` J. Bruce Fields
2007-02-04 8:41 ` Christoph Hellwig
2007-02-04 0:32 ` [NFS] " Trond Myklebust
2007-02-04 1:52 ` 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='31453.3895849765$1170480879@news.gmane.org' \
--to=bfields@citi.umich.edu \
--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 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).