nfsd: don't return an unhashed lock stateid after taking mutex
authorJeff Layton <jlayton@redhat.com>
Thu, 11 Aug 2016 14:37:39 +0000 (10:37 -0400)
committerJ. Bruce Fields <bfields@redhat.com>
Fri, 12 Aug 2016 20:10:25 +0000 (16:10 -0400)
commitdd257933fa4b9fea66a1195f8a15111029810abc
treef00c7fb74c9eb3ab557ce1cda54eb9a6f5c0c20c
parent42691398be08bd1fe99326911a0aa31f2c041d53
nfsd: don't return an unhashed lock stateid after taking mutex

nfsd4_lock will take the st_mutex before working with the stateid it
gets, but between the time when we drop the cl_lock and take the mutex,
the stateid could become unhashed (a'la FREE_STATEID). If that happens
the lock stateid returned to the client will be forgotten.

Fix this by first moving the st_mutex acquisition into
lookup_or_create_lock_state. Then, have it check to see if the lock
stateid is still hashed after taking the mutex. If it's not, then put
the stateid and try the find/create again.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Tested-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: stable@vger.kernel.org # feb9dad5 nfsd: Always lock state exclusively.
Cc: stable@vger.kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4state.c