Deprecate down_trylock()

down_trylock() returns 1 on failure, 0 on success.  This differs from
spin_trylock(), mutex_trylock() and common sense.  Or as ocfs2 put it
"kernel 1, world 0".

Deprecate it and make down_try() the primary function.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
 include/linux/semaphore.h |   22 ++++++----------------
 kernel/semaphore.c        |   17 ++++++++---------
 2 files changed, 14 insertions(+), 25 deletions(-)

diff -r 46ea57469bc7 include/linux/semaphore.h
--- a/include/linux/semaphore.h	Wed May 21 15:07:32 2008 +1000
+++ b/include/linux/semaphore.h	Wed May 21 15:24:42 2008 +1000
@@ -44,22 +44,12 @@ extern void down(struct semaphore *sem);
 extern void down(struct semaphore *sem);
 extern int __must_check down_interruptible(struct semaphore *sem);
 extern int __must_check down_killable(struct semaphore *sem);
-extern int __must_check down_trylock(struct semaphore *sem);
+extern bool __must_check down_try(struct semaphore *sem);
+/* Old down_trylock() returned the opposite of what was expected. */
+static inline int __deprecated down_trylock(struct semaphore *sem)
+{
+	return !down_try(sem);
+}
 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
 extern void up(struct semaphore *sem);
-
-/**
- * down_try - try to down a semaphore, but don't block
- * @sem: the semaphore
- *
- * This is equivalent to down_trylock(), but has the same return codes as
- * spin_trylock and mutex_trylock: 1 if semaphore acquired, 0 if not.
- *
- * down_trylock() with its confusing return codes will be deprecated
- * soon.  It will not be missed.
- */
-static inline bool __must_check down_try(struct semaphore *sem)
-{
-	return !down_trylock(sem);
-}
 #endif /* __LINUX_SEMAPHORE_H */
diff -r 46ea57469bc7 kernel/semaphore.c
--- a/kernel/semaphore.c	Wed May 21 15:07:32 2008 +1000
+++ b/kernel/semaphore.c	Wed May 21 15:24:42 2008 +1000
@@ -14,7 +14,7 @@
  * Some notes on the implementation:
  *
  * The spinlock controls access to the other members of the semaphore.
- * down_trylock() and up() can be called from interrupt context, so we
+ * down_try() and up() can be called from interrupt context, so we
  * have to disable interrupts when taking the lock.  It turns out various
  * parts of the kernel expect to be able to use down() on a semaphore in
  * interrupt context when they know it will succeed, so we have to use
@@ -114,19 +114,18 @@ EXPORT_SYMBOL(down_killable);
 EXPORT_SYMBOL(down_killable);
 
 /**
- * down_trylock - try to acquire the semaphore, without waiting
+ * down_try - try to acquire the semaphore, without waiting
  * @sem: the semaphore to be acquired
  *
- * Try to acquire the semaphore atomically.  Returns 0 if the mutex has
- * been acquired successfully or 1 if it it cannot be acquired.
+ * Try to acquire the semaphore atomically.  Returns true if the mutex has
+ * been acquired successfully or 0 if it it cannot be acquired.
  *
- * NOTE: This return value is inverted from both spin_trylock and
- * mutex_trylock!  Be careful about this when converting code.
+ * NOTE: This replaces down_trylock() which returned the reverse.
  *
  * Unlike mutex_trylock, this function can be used from interrupt context,
  * and the semaphore can be released by any task or interrupt.
  */
-int down_trylock(struct semaphore *sem)
+bool down_try(struct semaphore *sem)
 {
 	unsigned long flags;
 	int count;
@@ -137,9 +136,9 @@ int down_trylock(struct semaphore *sem)
 		sem->count = count;
 	spin_unlock_irqrestore(&sem->lock, flags);
 
-	return (count < 0);
+	return (count >= 0);
 }
-EXPORT_SYMBOL(down_trylock);
+EXPORT_SYMBOL(down_try);
 
 /**
  * down_timeout - acquire the semaphore within a specified time
