Skip to content

Commit 797bfd0

Browse files
jtlaytongregkh
authored andcommitted
nfsd: remove blocked locks on client teardown
commit 68ef3bc upstream. We had some reports of panics in nfsd4_lm_notify, and that showed a nfs4_lockowner that had outlived its so_client. Ensure that we walk any leftover lockowners after tearing down all of the stateids, and remove any blocked locks that they hold. With this change, we also don't need to walk the nbl_lru on nfsd_net shutdown, as that will happen naturally when we tear down the clients. Fixes: 76d348f (nfsd: have nfsd4_lock use blocking locks for v4.1+ locks) Reported-by: Frank Sorenson <fsorenso@redhat.com> Signed-off-by: Jeff Layton <jlayton@redhat.com> Cc: stable@vger.kernel.org # 4.9 Signed-off-by: J. Bruce Fields <bfields@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aa0533f commit 797bfd0

1 file changed

Lines changed: 43 additions & 19 deletions

File tree

‎fs/nfsd/nfs4state.c‎

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,35 @@ free_blocked_lock(struct nfsd4_blocked_lock *nbl)
263263
kfree(nbl);
264264
}
265265

266+
static void
267+
remove_blocked_locks(struct nfs4_lockowner *lo)
268+
{
269+
struct nfs4_client *clp = lo->lo_owner.so_client;
270+
struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
271+
struct nfsd4_blocked_lock *nbl;
272+
LIST_HEAD(reaplist);
273+
274+
/* Dequeue all blocked locks */
275+
spin_lock(&nn->blocked_locks_lock);
276+
while (!list_empty(&lo->lo_blocked)) {
277+
nbl = list_first_entry(&lo->lo_blocked,
278+
struct nfsd4_blocked_lock,
279+
nbl_list);
280+
list_del_init(&nbl->nbl_list);
281+
list_move(&nbl->nbl_lru, &reaplist);
282+
}
283+
spin_unlock(&nn->blocked_locks_lock);
284+
285+
/* Now free them */
286+
while (!list_empty(&reaplist)) {
287+
nbl = list_first_entry(&reaplist, struct nfsd4_blocked_lock,
288+
nbl_lru);
289+
list_del_init(&nbl->nbl_lru);
290+
posix_unblock_lock(&nbl->nbl_lock);
291+
free_blocked_lock(nbl);
292+
}
293+
}
294+
266295
static int
267296
nfsd4_cb_notify_lock_done(struct nfsd4_callback *cb, struct rpc_task *task)
268297
{
@@ -1854,6 +1883,7 @@ static __be32 mark_client_expired_locked(struct nfs4_client *clp)
18541883
static void
18551884
__destroy_client(struct nfs4_client *clp)
18561885
{
1886+
int i;
18571887
struct nfs4_openowner *oo;
18581888
struct nfs4_delegation *dp;
18591889
struct list_head reaplist;
@@ -1883,6 +1913,16 @@ __destroy_client(struct nfs4_client *clp)
18831913
nfs4_get_stateowner(&oo->oo_owner);
18841914
release_openowner(oo);
18851915
}
1916+
for (i = 0; i < OWNER_HASH_SIZE; i++) {
1917+
struct nfs4_stateowner *so, *tmp;
1918+
1919+
list_for_each_entry_safe(so, tmp, &clp->cl_ownerstr_hashtbl[i],
1920+
so_strhash) {
1921+
/* Should be no openowners at this point */
1922+
WARN_ON_ONCE(so->so_is_open_owner);
1923+
remove_blocked_locks(lockowner(so));
1924+
}
1925+
}
18861926
nfsd4_return_all_client_layouts(clp);
18871927
nfsd4_shutdown_callback(clp);
18881928
if (clp->cl_cb_conn.cb_xprt)
@@ -6275,6 +6315,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
62756315
}
62766316
spin_unlock(&clp->cl_lock);
62776317
free_ol_stateid_reaplist(&reaplist);
6318+
remove_blocked_locks(lo);
62786319
nfs4_put_stateowner(&lo->lo_owner);
62796320

62806321
return status;
@@ -7060,6 +7101,8 @@ nfs4_state_destroy_net(struct net *net)
70607101
}
70617102
}
70627103

7104+
WARN_ON(!list_empty(&nn->blocked_locks_lru));
7105+
70637106
for (i = 0; i < CLIENT_HASH_SIZE; i++) {
70647107
while (!list_empty(&nn->unconf_id_hashtbl[i])) {
70657108
clp = list_entry(nn->unconf_id_hashtbl[i].next, struct nfs4_client, cl_idhash);
@@ -7126,7 +7169,6 @@ nfs4_state_shutdown_net(struct net *net)
71267169
struct nfs4_delegation *dp = NULL;
71277170
struct list_head *pos, *next, reaplist;
71287171
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
7129-
struct nfsd4_blocked_lock *nbl;
71307172

71317173
cancel_delayed_work_sync(&nn->laundromat_work);
71327174
locks_end_grace(&nn->nfsd4_manager);
@@ -7147,24 +7189,6 @@ nfs4_state_shutdown_net(struct net *net)
71477189
nfs4_put_stid(&dp->dl_stid);
71487190
}
71497191

7150-
BUG_ON(!list_empty(&reaplist));
7151-
spin_lock(&nn->blocked_locks_lock);
7152-
while (!list_empty(&nn->blocked_locks_lru)) {
7153-
nbl = list_first_entry(&nn->blocked_locks_lru,
7154-
struct nfsd4_blocked_lock, nbl_lru);
7155-
list_move(&nbl->nbl_lru, &reaplist);
7156-
list_del_init(&nbl->nbl_list);
7157-
}
7158-
spin_unlock(&nn->blocked_locks_lock);
7159-
7160-
while (!list_empty(&reaplist)) {
7161-
nbl = list_first_entry(&reaplist,
7162-
struct nfsd4_blocked_lock, nbl_lru);
7163-
list_del_init(&nbl->nbl_lru);
7164-
posix_unblock_lock(&nbl->nbl_lock);
7165-
free_blocked_lock(nbl);
7166-
}
7167-
71687192
nfsd4_client_tracking_exit(net);
71697193
nfs4_state_destroy_net(net);
71707194
}

0 commit comments

Comments
 (0)