nfsd: move fsid_type choice out of fh_compose
[safe/jmp/linux-2.6] / lib / spinlock_debug.c
index 3de2ccf..9c4b025 100644 (file)
@@ -7,11 +7,48 @@
  */
 
 #include <linux/spinlock.h>
+#include <linux/nmi.h>
 #include <linux/interrupt.h>
 #include <linux/debug_locks.h>
 #include <linux/delay.h>
 #include <linux/module.h>
 
+void __spin_lock_init(spinlock_t *lock, const char *name,
+                     struct lock_class_key *key)
+{
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+       /*
+        * Make sure we are not reinitializing a held lock:
+        */
+       debug_check_no_locks_freed((void *)lock, sizeof(*lock));
+       lockdep_init_map(&lock->dep_map, name, key, 0);
+#endif
+       lock->raw_lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
+       lock->magic = SPINLOCK_MAGIC;
+       lock->owner = SPINLOCK_OWNER_INIT;
+       lock->owner_cpu = -1;
+}
+
+EXPORT_SYMBOL(__spin_lock_init);
+
+void __rwlock_init(rwlock_t *lock, const char *name,
+                  struct lock_class_key *key)
+{
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+       /*
+        * Make sure we are not reinitializing a held lock:
+        */
+       debug_check_no_locks_freed((void *)lock, sizeof(*lock));
+       lockdep_init_map(&lock->dep_map, name, key, 0);
+#endif
+       lock->raw_lock = (raw_rwlock_t) __RAW_RW_LOCK_UNLOCKED;
+       lock->magic = RWLOCK_MAGIC;
+       lock->owner = SPINLOCK_OWNER_INIT;
+       lock->owner_cpu = -1;
+}
+
+EXPORT_SYMBOL(__rwlock_init);
+
 static void spin_bug(spinlock_t *lock, const char *msg)
 {
        struct task_struct *owner = NULL;
@@ -23,12 +60,12 @@ static void spin_bug(spinlock_t *lock, const char *msg)
                owner = lock->owner;
        printk(KERN_EMERG "BUG: spinlock %s on CPU#%d, %s/%d\n",
                msg, raw_smp_processor_id(),
-               current->comm, current->pid);
+               current->comm, task_pid_nr(current));
        printk(KERN_EMERG " lock: %p, .magic: %08x, .owner: %s/%d, "
                        ".owner_cpu: %d\n",
                lock, lock->magic,
                owner ? owner->comm : "<none>",
-               owner ? owner->pid : -1,
+               owner ? task_pid_nr(owner) : -1,
                lock->owner_cpu);
        dump_stack();
 }
@@ -63,11 +100,12 @@ static inline void debug_spin_unlock(spinlock_t *lock)
 
 static void __spin_lock_debug(spinlock_t *lock)
 {
-       int print_once = 1;
        u64 i;
+       u64 loops = loops_per_jiffy * HZ;
+       int print_once = 1;
 
        for (;;) {
-               for (i = 0; i < loops_per_jiffy * HZ; i++) {
+               for (i = 0; i < loops; i++) {
                        if (__raw_spin_trylock(&lock->raw_lock))
                                return;
                        __delay(1);
@@ -78,8 +116,11 @@ static void __spin_lock_debug(spinlock_t *lock)
                        printk(KERN_EMERG "BUG: spinlock lockup on CPU#%d, "
                                        "%s/%d, %p\n",
                                raw_smp_processor_id(), current->comm,
-                               current->pid, lock);
+                               task_pid_nr(current), lock);
                        dump_stack();
+#ifdef CONFIG_SMP
+                       trigger_all_cpu_backtrace();
+#endif
                }
        }
 }
@@ -120,19 +161,21 @@ static void rwlock_bug(rwlock_t *lock, const char *msg)
 
        printk(KERN_EMERG "BUG: rwlock %s on CPU#%d, %s/%d, %p\n",
                msg, raw_smp_processor_id(), current->comm,
-               current->pid, lock);
+               task_pid_nr(current), lock);
        dump_stack();
 }
 
 #define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg)
 
+#if 0          /* __write_lock_debug() can lock up - maybe this can too? */
 static void __read_lock_debug(rwlock_t *lock)
 {
-       int print_once = 1;
        u64 i;
+       u64 loops = loops_per_jiffy * HZ;
+       int print_once = 1;
 
        for (;;) {
-               for (i = 0; i < loops_per_jiffy * HZ; i++) {
+               for (i = 0; i < loops; i++) {
                        if (__raw_read_trylock(&lock->raw_lock))
                                return;
                        __delay(1);
@@ -148,12 +191,12 @@ static void __read_lock_debug(rwlock_t *lock)
                }
        }
 }
+#endif
 
 void _raw_read_lock(rwlock_t *lock)
 {
        RWLOCK_BUG_ON(lock->magic != RWLOCK_MAGIC, lock, "bad magic");
-       if (unlikely(!__raw_read_trylock(&lock->raw_lock)))
-               __read_lock_debug(lock);
+       __raw_read_lock(&lock->raw_lock);
 }
 
 int _raw_read_trylock(rwlock_t *lock)
@@ -199,13 +242,15 @@ static inline void debug_write_unlock(rwlock_t *lock)
        lock->owner_cpu = -1;
 }
 
+#if 0          /* This can cause lockups */
 static void __write_lock_debug(rwlock_t *lock)
 {
-       int print_once = 1;
        u64 i;
+       u64 loops = loops_per_jiffy * HZ;
+       int print_once = 1;
 
        for (;;) {
-               for (i = 0; i < loops_per_jiffy * HZ; i++) {
+               for (i = 0; i < loops; i++) {
                        if (__raw_write_trylock(&lock->raw_lock))
                                return;
                        __delay(1);
@@ -221,12 +266,12 @@ static void __write_lock_debug(rwlock_t *lock)
                }
        }
 }
+#endif
 
 void _raw_write_lock(rwlock_t *lock)
 {
        debug_write_lock_before(lock);
-       if (unlikely(!__raw_write_trylock(&lock->raw_lock)))
-               __write_lock_debug(lock);
+       __raw_write_lock(&lock->raw_lock);
        debug_write_lock_after(lock);
 }