Commit 64a318ee authored by J. Bruce Fields's avatar J. Bruce Fields Committed by Trond Myklebust

NLM: Further cancel fixes

 If the server receives an NLM cancel call and finds no waiting lock to
 cancel, then chances are the lock has already been applied, and the client
 just hadn't yet processed the NLM granted callback before it sent the

 The Open Group text, for example, perimts a server to return either success
 (LCK_GRANTED) or failure (LCK_DENIED) in this case.  But returning an error
 seems more helpful; the client may be able to use it to recognize that a
 race has occurred and to recover from the race.

 So, modify the relevant functions to return an error in this case.
Signed-off-by: default avatarJ. Bruce Fields <>
Signed-off-by: default avatarTrond Myklebust <>
parent 2c5acd2e
......@@ -227,25 +227,27 @@ nlmsvc_create_block(struct svc_rqst *rqstp, struct nlm_file *file,
* It is the caller's responsibility to check whether the file
* can be closed hereafter.
static void
static int
nlmsvc_delete_block(struct nlm_block *block, int unlock)
struct file_lock *fl = &block->b_call.a_args.lock.fl;
struct nlm_file *file = block->b_file;
struct nlm_block **bp;
int status = 0;
dprintk("lockd: deleting block %p...\n", block);
/* Remove block from list */
posix_unblock_lock(file->f_file, fl);
if (unlock)
status = posix_unblock_lock(file->f_file, fl);
/* If the block is in the middle of a GRANT callback,
* don't kill it yet. */
if (block->b_incall) {
nlmsvc_insert_block(block, NLM_NEVER);
block->b_done = 1;
return status;
/* Remove block from file's list of blocks */
......@@ -260,6 +262,7 @@ nlmsvc_delete_block(struct nlm_block *block, int unlock)
return status;
......@@ -270,6 +273,7 @@ int
nlmsvc_traverse_blocks(struct nlm_host *host, struct nlm_file *file, int action)
struct nlm_block *block, *next;
/* XXX: Will everything get cleaned up if we don't unlock here? */
for (block = file->f_blocks; block; block = next) {
......@@ -439,6 +443,7 @@ u32
nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
struct nlm_block *block;
int status = 0;
dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n",
......@@ -449,9 +454,9 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
if ((block = nlmsvc_lookup_block(file, lock, 1)) != NULL)
nlmsvc_delete_block(block, 1);
status = nlmsvc_delete_block(block, 1);
return nlm_granted;
return status ? nlm_lck_denied : nlm_granted;
......@@ -1958,13 +1958,18 @@ EXPORT_SYMBOL(posix_block_lock);
* lockd needs to block waiting for locks.
posix_unblock_lock(struct file *filp, struct file_lock *waiter)
int status = 0;
if (waiter->fl_next)
status = -ENOENT;
return status;
......@@ -760,7 +760,7 @@ extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
extern int posix_lock_file(struct file *, struct file_lock *);
extern int posix_lock_file_wait(struct file *, struct file_lock *);
extern void posix_block_lock(struct file_lock *, struct file_lock *);
extern void posix_unblock_lock(struct file *, struct file_lock *);
extern int posix_unblock_lock(struct file *, struct file_lock *);
extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
extern int __break_lease(struct inode *inode, unsigned int flags);
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment