From 1812997720ab90d029548778c55d7315555e1fef Mon Sep 17 00:00:00 2001
From: Waiman Long <Waiman.Long@hp.com>
Date: Thu, 12 Sep 2013 10:55:35 -0400
Subject: dcache: get/release read lock in read_seqbegin_or_lock() & friend
Git-commit: 1812997720ab90d029548778c55d7315555e1fef (partial, skipped comment updates)
Patch-mainline: v3.12-rc1
References: FATE#317271

This patch modifies read_seqbegin_or_lock() and need_seqretry() to use
newly introduced read_seqlock_excl() and read_sequnlock_excl()
primitives so that they won't change the sequence number even if they
fall back to take the lock.  This is OK as no change to the protected
data structure is being made.

It will prevent one fallback to lock taking from cascading into a series
of lock taking reducing performance because of the sequence number
change.  It will also allow other sequence readers to go forward while
an exclusive reader lock is taken.

This patch also updates some of the inaccurate comments in the code.

Signed-off-by: Waiman Long <Waiman.Long@hp.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/dcache.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index 4d9df3c..f3dcc63 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -103,7 +103,7 @@ static inline void read_seqbegin_or_lock(seqlock_t *lock, int *seq)
 		*seq = read_seqbegin(lock);
 		rcu_read_lock();
 	} else			/* Odd */
-		write_seqlock(lock);
+		read_seqlock_excl(lock);
 }
 
 /**
@@ -121,7 +121,7 @@ static inline int read_seqretry_or_unlock(seqlock_t *lock, int *seq)
 			return 1;
 		}
 	} else			/* Odd */
-		write_sequnlock(lock);
+		read_sequnlock_excl(lock);
 	return 0;
 }
 
