Print this page
6253 F_GETLK doesn't always return lock owner
The F_GETLK fcntl doesn't return the offending lock if there is a read lock
on the file, a waiting write lock, and a read lock is requested.
The write lock blocks the locking request, but without this patch isn't
returned by GETLK.

@@ -2097,10 +2097,29 @@
                         }
                         lock = lock->l_next;
                 } while (lock->l_vnode == vp);
         }
 
+        if (blocker == NULL && request->l_flock.l_type == F_RDLCK) {
+                /*
+                 * No active lock is blocking this request, but if a read
+                 * lock is requested, it may also get blocked by a waiting
+                 * writer. So search all sleeping locks and see if there is
+                 * a writer waiting.
+                 */
+                SET_LOCK_TO_FIRST_SLEEP_VP(gp, lock, vp);
+                if (lock) {
+                        do {
+                                if (BLOCKS(lock, request)) {
+                                        blocker = lock;
+                                        break;
+                                }
+                                lock = lock->l_next;
+                        } while (lock->l_vnode == vp);
+                }
+        }
+
         if (blocker) {
                 report_blocker(blocker, request);
         } else
                 request->l_flock.l_type = F_UNLCK;
 }