Skip to content

Commit ef8d98f

Browse files
neilbrownTrond Myklebust
authored andcommitted
NFS: avoid spurious warning of lost lock that is being unlocked.
When the NFSv4 state manager recovers state after a server restart, it reports that locks have been lost if it finds any lock state for which recovery hasn't been successful. i.e. any for which NFS_LOCK_INITIALIZED is not set. However it only tries to recover locks that are still linked to inode->i_flctx. So if a lock has been removed from inode->i_flctx, but the state for that lock has not yet been destroyed, then a spurious warning results. nfs4_proc_unlck() calls locks_lock_inode_wait() - which removes the lock from ->i_flctx - before sending the unlock request to the server and before the final nfs4_put_lock_state() is called. This allows a window in which a spurious warning can be produced. So add a new flag NFS_LOCK_UNLOCKING which is set once the decision has been made to unlock the lock. This will prevent it from triggering any warning. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 5559405 commit ef8d98f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

fs/nfs/nfs4_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct nfs4_lock_state {
149149
struct nfs4_state * ls_state; /* Pointer to open state */
150150
#define NFS_LOCK_INITIALIZED 0
151151
#define NFS_LOCK_LOST 1
152+
#define NFS_LOCK_UNLOCKING 2
152153
unsigned long ls_flags;
153154
struct nfs_seqid_counter ls_seqid;
154155
nfs4_stateid ls_stateid;

fs/nfs/nfs4proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7023,12 +7023,13 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
70237023
mutex_unlock(&sp->so_delegreturn_mutex);
70247024
goto out;
70257025
}
7026+
lsp = request->fl_u.nfs4_fl.owner;
7027+
set_bit(NFS_LOCK_UNLOCKING, &lsp->ls_flags);
70267028
up_read(&nfsi->rwsem);
70277029
mutex_unlock(&sp->so_delegreturn_mutex);
70287030
if (status != 0)
70297031
goto out;
70307032
/* Is this a delegated lock? */
7031-
lsp = request->fl_u.nfs4_fl.owner;
70327033
if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0)
70337034
goto out;
70347035
alloc_seqid = NFS_SERVER(inode)->nfs_client->cl_mvops->alloc_seqid;

fs/nfs/nfs4state.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,8 @@ static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_st
16191619
spin_lock(&state->state_lock);
16201620
list_for_each_entry(lock, &state->lock_states, ls_locks) {
16211621
trace_nfs4_state_lock_reclaim(state, lock);
1622-
if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1622+
if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags) &&
1623+
!test_bit(NFS_LOCK_UNLOCKING, &lock->ls_flags))
16231624
*lost_locks += 1;
16241625
}
16251626
spin_unlock(&state->state_lock);

0 commit comments

Comments
 (0)