autofs-5.0.6 - dont use pthread_rwlock_tryrdlock()

From: Ian Kent <ikent@redhat.com>

Occasionally we might not be able to get the master source read lock
when a write lock is held. Currently we wait a little while to see if
it gets released and try again. But using the pthreads function
pthread_rwlock_tryrdlock() introduces scheduling inconsistencies and
makes the wakeup order somewhat random causing some threads to sometimes
wait much longer than others. Unsing the pthread_rwlock_rdlock() resolves
the inconsistencies.
---

 CHANGELOG    |    1 +
 lib/master.c |   10 ++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index aafc69c..04f4ff6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -66,6 +66,7 @@
 - fix get_nfs_info() can incorrectly fail.
 - fix offset directory removal.
 - check negative cache much earlier.
+- dont use pthread_rwlock_tryrdlock().
 
 28/06/2011 autofs-5.0.6
 -----------------------
diff --git a/lib/master.c b/lib/master.c
index c6ae9f2..904b13d 100644
--- a/lib/master.c
+++ b/lib/master.c
@@ -551,16 +551,22 @@ void master_source_writelock(struct master_mapent *entry)
 
 void master_source_readlock(struct master_mapent *entry)
 {
-	int retries = 25; /* 5 second maximum */
+	int retries = 25;
 	int status;
 
 	while (retries--) {
-		status = pthread_rwlock_tryrdlock(&entry->source_lock);
+		status = pthread_rwlock_rdlock(&entry->source_lock);
 		if (status != EAGAIN && status != EBUSY)
 			break;
 		else {
                 	struct timespec t = { 0, 200000000 };
 	                struct timespec r;
+
+			if (status == EAGAIN)
+				logmsg("master_mapent source too many readers");
+			else
+				logmsg("master_mapent source write lock held");
+
                 	while (nanosleep(&t, &r) == -1 && errno == EINTR)
                         	memcpy(&t, &r, sizeof(struct timespec));
 		}
