Skip to content

Commit 244cc19

Browse files
jtlaytonchucklever
authored andcommitted
lockd: server should unlock lock if client rejects the grant
Currently lockd just dequeues the block and ignores it if the client sends a GRANT_RES with a status of nlm_lck_denied. That status is an indicator that the client has rejected the lock, so the right thing to do is to unlock the lock we were trying to grant. Reported-by: Yongcheng Yang <[email protected]> Link: https://bugzilla.redhat.com/show_bug.cgi?id=2063818 Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 2005f5b commit 244cc19

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

fs/lockd/svclock.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,19 +954,32 @@ void
954954
nlmsvc_grant_reply(struct nlm_cookie *cookie, __be32 status)
955955
{
956956
struct nlm_block *block;
957+
struct file_lock *fl;
958+
int error;
957959

958960
dprintk("grant_reply: looking for cookie %x, s=%d \n",
959961
*(unsigned int *)(cookie->data), status);
960962
if (!(block = nlmsvc_find_block(cookie)))
961963
return;
962964

963-
if (status == nlm_lck_denied_grace_period) {
965+
switch (status) {
966+
case nlm_lck_denied_grace_period:
964967
/* Try again in a couple of seconds */
965968
nlmsvc_insert_block(block, 10 * HZ);
966-
} else {
969+
break;
970+
case nlm_lck_denied:
971+
/* Client doesn't want it, just unlock it */
972+
nlmsvc_unlink_block(block);
973+
fl = &block->b_call->a_args.lock.fl;
974+
fl->fl_type = F_UNLCK;
975+
error = vfs_lock_file(fl->fl_file, F_SETLK, fl, NULL);
976+
if (error)
977+
pr_warn("lockd: unable to unlock lock rejected by client!\n");
978+
break;
979+
default:
967980
/*
968-
* Lock is now held by client, or has been rejected.
969-
* In both cases, the block should be removed.
981+
* Either it was accepted or the status makes no sense
982+
* just unlink it either way.
970983
*/
971984
nlmsvc_unlink_block(block);
972985
}

0 commit comments

Comments
 (0)