Skip to content

Commit 3e2910c

Browse files
neilbrownamschuma-ntap
authored andcommitted
NFS: Improve warning message when locks are lost.
NFSv4 can lose locks if, for example there is a network partition for longer than the lease period. When this happens a warning message NFS: __nfs4_reclaim_open_state: Lock reclaim failed! is generated, possibly once for each lock (though rate limited). This is potentially misleading as is can be read as suggesting that lock reclaim was attempted. However the default behaviour is to not attempt to recover locks (except due to server report). This patch changes the reporting to produce at most one message for each attempt to recover all state from a given server. The message reports the server name and the number of locks lost if that number is non-zero. It reports that locks were lost and give no suggestion as to whether there was an attempt or not. Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 71342db commit 3e2910c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

fs/nfs/nfs4state.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,8 @@ static inline void nfs42_complete_copies(struct nfs4_state_owner *sp,
16021602
#endif /* CONFIG_NFS_V4_2 */
16031603

16041604
static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
1605-
const struct nfs4_state_recovery_ops *ops)
1605+
const struct nfs4_state_recovery_ops *ops,
1606+
int *lost_locks)
16061607
{
16071608
struct nfs4_lock_state *lock;
16081609
int status;
@@ -1620,7 +1621,7 @@ static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_st
16201621
list_for_each_entry(lock, &state->lock_states, ls_locks) {
16211622
trace_nfs4_state_lock_reclaim(state, lock);
16221623
if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1623-
pr_warn_ratelimited("NFS: %s: Lock reclaim failed!\n", __func__);
1624+
*lost_locks += 1;
16241625
}
16251626
spin_unlock(&state->state_lock);
16261627
}
@@ -1630,7 +1631,9 @@ static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_st
16301631
return status;
16311632
}
16321633

1633-
static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
1634+
static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp,
1635+
const struct nfs4_state_recovery_ops *ops,
1636+
int *lost_locks)
16341637
{
16351638
struct nfs4_state *state;
16361639
unsigned int loop = 0;
@@ -1666,7 +1669,7 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
16661669
#endif /* CONFIG_NFS_V4_2 */
16671670
refcount_inc(&state->count);
16681671
spin_unlock(&sp->so_lock);
1669-
status = __nfs4_reclaim_open_state(sp, state, ops);
1672+
status = __nfs4_reclaim_open_state(sp, state, ops, lost_locks);
16701673

16711674
switch (status) {
16721675
default:
@@ -1909,6 +1912,7 @@ static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recov
19091912
struct rb_node *pos;
19101913
LIST_HEAD(freeme);
19111914
int status = 0;
1915+
int lost_locks = 0;
19121916

19131917
restart:
19141918
rcu_read_lock();
@@ -1928,8 +1932,11 @@ static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recov
19281932
spin_unlock(&clp->cl_lock);
19291933
rcu_read_unlock();
19301934

1931-
status = nfs4_reclaim_open_state(sp, ops);
1935+
status = nfs4_reclaim_open_state(sp, ops, &lost_locks);
19321936
if (status < 0) {
1937+
if (lost_locks)
1938+
pr_warn("NFS: %s: lost %d locks\n",
1939+
clp->cl_hostname, lost_locks);
19331940
set_bit(ops->owner_flag_bit, &sp->so_flags);
19341941
nfs4_put_state_owner(sp);
19351942
status = nfs4_recovery_handle_error(clp, status);
@@ -1943,6 +1950,9 @@ static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recov
19431950
}
19441951
rcu_read_unlock();
19451952
nfs4_free_state_owners(&freeme);
1953+
if (lost_locks)
1954+
pr_warn("NFS: %s: lost %d locks\n",
1955+
clp->cl_hostname, lost_locks);
19461956
return 0;
19471957
}
19481958

0 commit comments

Comments
 (0)