ocfs2: dlm: fix race between purge and get lock resource
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / ocfs2 / dlm / dlmmaster.c
index 2b941113e42332b3e914f386e5318f690c69e6d6..2c119d5d04c9b342747207d8730a5813ec0fcd48 100644 (file)
@@ -729,6 +729,19 @@ lookup:
        if (tmpres) {
                spin_unlock(&dlm->spinlock);
                spin_lock(&tmpres->spinlock);
+
+               /*
+                * Right after dlm spinlock was released, dlm_thread could have
+                * purged the lockres. Check if lockres got unhashed. If so
+                * start over.
+                */
+               if (hlist_unhashed(&tmpres->hash_node)) {
+                       spin_unlock(&tmpres->spinlock);
+                       dlm_lockres_put(tmpres);
+                       tmpres = NULL;
+                       goto lookup;
+               }
+
                /* Wait on the thread that is mastering the resource */
                if (tmpres->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
                        __dlm_wait_on_lockres(tmpres);