* [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS
@ 2006-06-26 23:29 Trond Myklebust
2006-06-26 23:30 ` [PATCH 1/5] VFS: Allow caller to determine if BSD or posix locks were actually freed Trond Myklebust
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:29 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
Hi,
The following set of patches enables the NFS client to determine more
accurately whether or not it needs to send an NLM/NFSv4 unlock request
if the process has outstanding posix or flock locks:
The current heuristic just assumes that if inode->i_flock is non-null, then
we should always spam the server with an unlock request upon close().
The patchset introduces a new flag to the posix_lock_file()/flock_lock_file()
interfaces that tells them to return -ENOENT if an F_UNLCK request results in
no action.
Cheers,
Trond
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/5] VFS: Allow caller to determine if BSD or posix locks were actually freed
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
@ 2006-06-26 23:30 ` Trond Myklebust
2006-06-26 23:30 ` [PATCH 2/5] NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock Trond Myklebust
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:30 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
From: Trond Myklebust <Trond.Myklebust@netapp.com>
Change posix_lock_file_conf(), and flock_lock_file() so that if called
with an F_UNLCK argument, and the FL_EXISTS flag they will indicate
whether or not any locks were actually freed by returning 0 or -ENOENT.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/locks.c | 18 ++++++++++++++++--
include/linux/fs.h | 1 +
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index 1ad29c9..50cb0a2 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -725,6 +725,10 @@ next_task:
/* Try to create a FLOCK lock on filp. We always insert new FLOCK locks
* at the head of the list, but that's secret knowledge known only to
* flock_lock_file and posix_lock_file.
+ *
+ * Note that if called with an FL_EXISTS argument, the caller may determine
+ * whether or not a lock was successfully freed by testing the return
+ * value for -ENOENT.
*/
static int flock_lock_file(struct file *filp, struct file_lock *request)
{
@@ -750,8 +754,11 @@ static int flock_lock_file(struct file *
break;
}
- if (request->fl_type == F_UNLCK)
+ if (request->fl_type == F_UNLCK) {
+ if ((request->fl_flags & FL_EXISTS) && !found)
+ error = -ENOENT;
goto out;
+ }
error = -ENOMEM;
new_fl = locks_alloc_lock();
@@ -948,8 +955,11 @@ static int __posix_lock_file_conf(struct
error = 0;
if (!added) {
- if (request->fl_type == F_UNLCK)
+ if (request->fl_type == F_UNLCK) {
+ if (request->fl_flags & FL_EXISTS)
+ error = -ENOENT;
goto out;
+ }
if (!new_fl) {
error = -ENOLCK;
@@ -996,6 +1006,10 @@ static int __posix_lock_file_conf(struct
* Add a POSIX style lock to a file.
* We merge adjacent & overlapping locks whenever possible.
* POSIX locks are sorted by owner task, then by starting address
+ *
+ * Note that if called with an FL_EXISTS argument, the caller may determine
+ * whether or not a lock was successfully freed by testing the return
+ * value for -ENOENT.
*/
int posix_lock_file(struct file *filp, struct file_lock *fl)
{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 2d8b348..31b1f6f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -682,6 +682,7 @@ #endif
#define FL_POSIX 1
#define FL_FLOCK 2
#define FL_ACCESS 8 /* not trying to lock, just looking */
+#define FL_EXISTS 16 /* when unlocking, test for existence */
#define FL_LEASE 32 /* lease held on this file */
#define FL_CLOSE 64 /* unlock on close */
#define FL_SLEEP 128 /* A blocking lock */
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
2006-06-26 23:30 ` [PATCH 1/5] VFS: Allow caller to determine if BSD or posix locks were actually freed Trond Myklebust
@ 2006-06-26 23:30 ` Trond Myklebust
2006-06-26 23:30 ` [PATCH 3/5] NFSv4: Ensure nfs4_lock_expired() caches delegated locks Trond Myklebust
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:30 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
From: Trond Myklebust <Trond.Myklebust@netapp.com>
Use the new behaviour of {flock,posix}_file_lock(F_UNLCK) to determine if
we held a lock, and only send the RPC request to the server if this was the
case.
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/lockd/clntproc.c | 18 ++++++++++--------
fs/nfs/nfs4proc.c | 31 ++++++++++++-------------------
2 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 4db6209..e6dd725 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -455,7 +455,7 @@ static void nlmclnt_locks_init_private(s
fl->fl_ops = &nlmclnt_lock_ops;
}
-static void do_vfs_lock(struct file_lock *fl)
+static int do_vfs_lock(struct file_lock *fl)
{
int res = 0;
switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
@@ -468,9 +468,7 @@ static void do_vfs_lock(struct file_lock
default:
BUG();
}
- if (res < 0)
- printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
- __FUNCTION__);
+ return res;
}
/*
@@ -542,7 +540,8 @@ again:
}
fl->fl_flags |= FL_SLEEP;
/* Ensure the resulting lock will get added to granted list */
- do_vfs_lock(fl);
+ if (do_vfs_lock(fl) < 0)
+ printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
up_read(&host->h_rwsem);
}
status = nlm_stat_to_errno(resp->status);
@@ -607,15 +606,19 @@ nlmclnt_unlock(struct nlm_rqst *req, str
{
struct nlm_host *host = req->a_host;
struct nlm_res *resp = &req->a_res;
- int status;
+ int status = 0;
/*
* Note: the server is supposed to either grant us the unlock
* request, or to deny it with NLM_LCK_DENIED_GRACE_PERIOD. In either
* case, we want to unlock.
*/
+ fl->fl_flags |= FL_EXISTS;
down_read(&host->h_rwsem);
- do_vfs_lock(fl);
+ if (do_vfs_lock(fl) == -ENOENT) {
+ up_read(&host->h_rwsem);
+ goto out;
+ }
up_read(&host->h_rwsem);
if (req->a_flags & RPC_TASK_ASYNC)
@@ -625,7 +628,6 @@ nlmclnt_unlock(struct nlm_rqst *req, str
if (status < 0)
goto out;
- status = 0;
if (resp->status == NLM_LCK_GRANTED)
goto out;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index b4916b0..b8c6375 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3144,9 +3144,6 @@ static int do_vfs_lock(struct file *file
default:
BUG();
}
- if (res < 0)
- printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
- __FUNCTION__);
return res;
}
@@ -3258,8 +3255,6 @@ static struct rpc_task *nfs4_do_unlck(st
return ERR_PTR(-ENOMEM);
}
- /* Unlock _before_ we do the RPC call */
- do_vfs_lock(fl->fl_file, fl);
return rpc_run_task(NFS_CLIENT(lsp->ls_state->inode), RPC_TASK_ASYNC, &nfs4_locku_ops, data);
}
@@ -3270,30 +3265,28 @@ static int nfs4_proc_unlck(struct nfs4_s
struct rpc_task *task;
int status = 0;
- /* Is this a delegated lock? */
- if (test_bit(NFS_DELEGATED_STATE, &state->flags))
- goto out_unlock;
- /* Is this open_owner holding any locks on the server? */
- if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
- goto out_unlock;
-
status = nfs4_set_lock_state(state, request);
+ /* Unlock _before_ we do the RPC call */
+ request->fl_flags |= FL_EXISTS;
+ if (do_vfs_lock(request->fl_file, request) == -ENOENT)
+ goto out;
if (status != 0)
- goto out_unlock;
+ goto out;
+ /* Is this a delegated lock? */
+ if (test_bit(NFS_DELEGATED_STATE, &state->flags))
+ goto out;
lsp = request->fl_u.nfs4_fl.owner;
- status = -ENOMEM;
seqid = nfs_alloc_seqid(&lsp->ls_seqid);
+ status = -ENOMEM;
if (seqid == NULL)
- goto out_unlock;
+ goto out;
task = nfs4_do_unlck(request, request->fl_file->private_data, lsp, seqid);
status = PTR_ERR(task);
if (IS_ERR(task))
- goto out_unlock;
+ goto out;
status = nfs4_wait_for_completion_rpc_task(task);
rpc_release_task(task);
- return status;
-out_unlock:
- do_vfs_lock(request->fl_file, request);
+out:
return status;
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] NFSv4: Ensure nfs4_lock_expired() caches delegated locks
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
2006-06-26 23:30 ` [PATCH 1/5] VFS: Allow caller to determine if BSD or posix locks were actually freed Trond Myklebust
2006-06-26 23:30 ` [PATCH 2/5] NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock Trond Myklebust
@ 2006-06-26 23:30 ` Trond Myklebust
2006-06-26 23:30 ` [PATCH 4/5] VFS: Add support for the FL_ACCESS flag to flock_lock_file() Trond Myklebust
2006-06-26 23:30 ` [PATCH 5/5] NLM,NFSv4: Wait on local locks before we put RPC calls on the wire Trond Myklebust
4 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:30 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
From: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/nfs/nfs4proc.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index b8c6375..8bdfe3f 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3454,10 +3454,10 @@ static int nfs4_lock_reclaim(struct nfs4
struct nfs4_exception exception = { };
int err;
- /* Cache the lock if possible... */
- if (test_bit(NFS_DELEGATED_STATE, &state->flags))
- return 0;
do {
+ /* Cache the lock if possible... */
+ if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
+ return 0;
err = _nfs4_do_setlk(state, F_SETLK, request, 1);
if (err != -NFS4ERR_DELAY)
break;
@@ -3476,6 +3476,8 @@ static int nfs4_lock_expired(struct nfs4
if (err != 0)
return err;
do {
+ if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
+ return 0;
err = _nfs4_do_setlk(state, F_SETLK, request, 0);
if (err != -NFS4ERR_DELAY)
break;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] VFS: Add support for the FL_ACCESS flag to flock_lock_file()
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
` (2 preceding siblings ...)
2006-06-26 23:30 ` [PATCH 3/5] NFSv4: Ensure nfs4_lock_expired() caches delegated locks Trond Myklebust
@ 2006-06-26 23:30 ` Trond Myklebust
2006-06-26 23:30 ` [PATCH 5/5] NLM,NFSv4: Wait on local locks before we put RPC calls on the wire Trond Myklebust
4 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:30 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
From: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/locks.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/fs/locks.c b/fs/locks.c
index 50cb0a2..b0b41a6 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -739,6 +739,8 @@ static int flock_lock_file(struct file *
int found = 0;
lock_kernel();
+ if (request->fl_flags & FL_ACCESS)
+ goto find_conflict;
for_each_lock(inode, before) {
struct file_lock *fl = *before;
if (IS_POSIX(fl))
@@ -771,6 +773,7 @@ static int flock_lock_file(struct file *
if (found)
cond_resched();
+find_conflict:
for_each_lock(inode, before) {
struct file_lock *fl = *before;
if (IS_POSIX(fl))
@@ -784,6 +787,8 @@ static int flock_lock_file(struct file *
locks_insert_block(fl, request);
goto out;
}
+ if (request->fl_flags & FL_ACCESS)
+ goto out;
locks_copy_lock(new_fl, request);
locks_insert_lock(&inode->i_flock, new_fl);
new_fl = NULL;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] NLM,NFSv4: Wait on local locks before we put RPC calls on the wire
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
` (3 preceding siblings ...)
2006-06-26 23:30 ` [PATCH 4/5] VFS: Add support for the FL_ACCESS flag to flock_lock_file() Trond Myklebust
@ 2006-06-26 23:30 ` Trond Myklebust
4 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2006-06-26 23:30 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-fsdevel, nfs
From: Trond Myklebust <Trond.Myklebust@netapp.com>
Use FL_ACCESS flag to test and/or wait for local locks before we try
requesting a lock from the server
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
fs/lockd/clntproc.c | 8 +++++++-
fs/nfs/nfs4proc.c | 35 ++++++++++++++++++++++++-----------
2 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index e6dd725..ad089d0 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -497,6 +497,7 @@ nlmclnt_lock(struct nlm_rqst *req, struc
struct nlm_host *host = req->a_host;
struct nlm_res *resp = &req->a_res;
struct nlm_wait *block = NULL;
+ unsigned char fl_flags = fl->fl_flags;
int status = -ENOLCK;
if (!host->h_monitored && nsm_monitor(host) < 0) {
@@ -504,6 +505,10 @@ nlmclnt_lock(struct nlm_rqst *req, struc
host->h_name);
goto out;
}
+ fl->fl_flags |= FL_ACCESS;
+ status = do_vfs_lock(fl);
+ if (status < 0)
+ goto out;
block = nlmclnt_prepare_block(host, fl);
again:
@@ -538,8 +543,8 @@ again:
up_read(&host->h_rwsem);
goto again;
}
- fl->fl_flags |= FL_SLEEP;
/* Ensure the resulting lock will get added to granted list */
+ fl->fl_flags = fl_flags | FL_SLEEP;
if (do_vfs_lock(fl) < 0)
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
up_read(&host->h_rwsem);
@@ -552,6 +557,7 @@ out_unblock:
nlmclnt_cancel(host, req->a_args.block, fl);
out:
nlm_release_call(req);
+ fl->fl_flags = fl_flags;
return status;
}
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 8bdfe3f..e6ee97f 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -3489,29 +3489,42 @@ static int nfs4_lock_expired(struct nfs4
static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
{
struct nfs4_client *clp = state->owner->so_client;
+ unsigned char fl_flags = request->fl_flags;
int status;
/* Is this a delegated open? */
- if (NFS_I(state->inode)->delegation_state != 0) {
- /* Yes: cache locks! */
- status = do_vfs_lock(request->fl_file, request);
- /* ...but avoid races with delegation recall... */
- if (status < 0 || test_bit(NFS_DELEGATED_STATE, &state->flags))
- return status;
- }
- down_read(&clp->cl_sem);
status = nfs4_set_lock_state(state, request);
if (status != 0)
goto out;
+ request->fl_flags |= FL_ACCESS;
+ status = do_vfs_lock(request->fl_file, request);
+ if (status < 0)
+ goto out;
+ down_read(&clp->cl_sem);
+ if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
+ struct nfs_inode *nfsi = NFS_I(state->inode);
+ /* Yes: cache locks! */
+ down_read(&nfsi->rwsem);
+ /* ...but avoid races with delegation recall... */
+ if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
+ request->fl_flags = fl_flags & ~FL_SLEEP;
+ status = do_vfs_lock(request->fl_file, request);
+ up_read(&nfsi->rwsem);
+ goto out_unlock;
+ }
+ up_read(&nfsi->rwsem);
+ }
status = _nfs4_do_setlk(state, cmd, request, 0);
if (status != 0)
- goto out;
+ goto out_unlock;
/* Note: we always want to sleep here! */
- request->fl_flags |= FL_SLEEP;
+ request->fl_flags = fl_flags | FL_SLEEP;
if (do_vfs_lock(request->fl_file, request) < 0)
printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
-out:
+out_unlock:
up_read(&clp->cl_sem);
+out:
+ request->fl_flags = fl_flags;
return status;
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-06-26 23:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-26 23:29 [PATCH 0/5] Enable extra optimisations on fcntl(F_UNLCK) requests on NFS Trond Myklebust
2006-06-26 23:30 ` [PATCH 1/5] VFS: Allow caller to determine if BSD or posix locks were actually freed Trond Myklebust
2006-06-26 23:30 ` [PATCH 2/5] NLM,NFSv4: Don't put UNLOCK requests on the wire unless we hold a lock Trond Myklebust
2006-06-26 23:30 ` [PATCH 3/5] NFSv4: Ensure nfs4_lock_expired() caches delegated locks Trond Myklebust
2006-06-26 23:30 ` [PATCH 4/5] VFS: Add support for the FL_ACCESS flag to flock_lock_file() Trond Myklebust
2006-06-26 23:30 ` [PATCH 5/5] NLM,NFSv4: Wait on local locks before we put RPC calls on the wire Trond Myklebust
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).