Skip to content

Commit b1432a2

Browse files
biger410torvalds
authored andcommitted
ocfs2: dlm: fix race between purge and get lock resource
There is a race window in dlm_get_lock_resource(), which may return a lock resource which has been purged. This will cause the process to hang forever in dlmlock() as the ast msg can't be handled due to its lock resource not existing. dlm_get_lock_resource { ... spin_lock(&dlm->spinlock); tmpres = __dlm_lookup_lockres_full(dlm, lockid, namelen, hash); if (tmpres) { spin_unlock(&dlm->spinlock); >>>>>>>> race window, dlm_run_purge_list() may run and purge the lock resource spin_lock(&tmpres->spinlock); ... spin_unlock(&tmpres->spinlock); } } Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com> Cc: Joseph Qi <joseph.qi@huawei.com> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d8fd150 commit b1432a2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/ocfs2/dlm/dlmmaster.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,19 @@ struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm,
757757
if (tmpres) {
758758
spin_unlock(&dlm->spinlock);
759759
spin_lock(&tmpres->spinlock);
760+
761+
/*
762+
* Right after dlm spinlock was released, dlm_thread could have
763+
* purged the lockres. Check if lockres got unhashed. If so
764+
* start over.
765+
*/
766+
if (hlist_unhashed(&tmpres->hash_node)) {
767+
spin_unlock(&tmpres->spinlock);
768+
dlm_lockres_put(tmpres);
769+
tmpres = NULL;
770+
goto lookup;
771+
}
772+
760773
/* Wait on the thread that is mastering the resource */
761774
if (tmpres->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
762775
__dlm_wait_on_lockres(tmpres);

0 commit comments

Comments
 (0)