Replace down_trylock() with down_nowait(), reverse return values.

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".

Rename it to down_nowait() (which makes more sense anyway), and reverse
it.  Fortunately there aren't a huge number of callers left.

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

diff -r f705d2595c1c include/linux/semaphore.h
--- a/include/linux/semaphore.h	Tue May 06 10:13:52 2008 +1000
+++ b/include/linux/semaphore.h	Tue May 06 10:17:31 2008 +1000
@@ -44,7 +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 int __must_check down_nowait(struct semaphore *sem);
+/* Old down_trylock() returned the opposite of what was expected. */
+static inline int __deprecated down_trylock(struct semaphore *sem)
+{
+	return !down_nowait(sem);
+}
 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
 extern void up(struct semaphore *sem);
 
diff -r f705d2595c1c kernel/semaphore.c
--- a/kernel/semaphore.c	Tue May 06 10:13:52 2008 +1000
+++ b/kernel/semaphore.c	Tue May 06 10:17:31 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_nowait() 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_nowait - 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)
+int down_nowait(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_nowait);
 
 /**
  * down_timeout - acquire the semaphore within a specified time
