X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fldlm%2Fl_lock.c;h=024ec2675617ee94edb11345fdbf505b4c83339f;hb=33e5a4904d7d76a0bd4766e81c973b64966ce5e1;hp=25662809a40e1ca56d3d62b8e29651b8efd688ef;hpb=933ae24da26f871feb09bc739ba5a8a593eaacfb;p=fs%2Flustre-release.git diff --git a/lustre/ldlm/l_lock.c b/lustre/ldlm/l_lock.c index 2566280..024ec26 100644 --- a/lustre/ldlm/l_lock.c +++ b/lustre/ldlm/l_lock.c @@ -20,8 +20,8 @@ * */ - - +#define DEBUG_SUBSYSTEM S_LDLM +#ifdef __KERNEL__ #include #include #include @@ -41,10 +41,11 @@ #include #include #include +#else +#include +#endif -#define DEBUG_SUBSYSTEM S_LDLM - -#include +#include #include /* invariants: @@ -61,14 +62,19 @@ void l_lock_init(struct lustre_lock *lock) void l_lock(struct lustre_lock *lock) { int owner = 0; + spin_lock(&lock->l_spin); - if (lock->l_owner == current) { + if (lock->l_owner == current) owner = 1; - } spin_unlock(&lock->l_spin); - if (owner) - ++lock->l_depth; - else { + + /* This is safe to increment outside the spinlock because we + * can only have 1 CPU running on the current task + * (i.e. l_owner == current), regardless of the number of CPUs. + */ + if (owner) { + ++lock->l_depth; + } else { down(&lock->l_sem); spin_lock(&lock->l_spin); lock->l_owner = current; @@ -79,17 +85,54 @@ void l_lock(struct lustre_lock *lock) void l_unlock(struct lustre_lock *lock) { - if (lock->l_owner != current) - LBUG(); - if (lock->l_depth < 0) - LBUG(); + LASSERT(lock->l_owner == current); + LASSERT(lock->l_depth >= 0); - spin_lock(&lock->l_spin); - if (--lock->l_depth < 0) { + spin_lock(&lock->l_spin); + if (--lock->l_depth < 0) { lock->l_owner = NULL; spin_unlock(&lock->l_spin); up(&lock->l_sem); - return ; + return; } spin_unlock(&lock->l_spin); } + +int l_has_lock(struct lustre_lock *lock) +{ + int depth = -1, owner = 0; + + spin_lock(&lock->l_spin); + if (lock->l_owner == current) { + depth = lock->l_depth; + owner = 1; + } + spin_unlock(&lock->l_spin); + + if (depth >= 0) + CDEBUG(D_INFO, "lock_depth: %d\n", depth); + return owner; +} + +#ifdef __KERNEL__ +#include +void l_check_no_ns_lock(struct ldlm_namespace *ns) +{ + static unsigned long next_msg; + + if (l_has_lock(&ns->ns_lock) && time_after(jiffies, next_msg)) { + CERROR("namespace %s lock held illegally; tell phil\n", + ns->ns_name); + next_msg = jiffies + 60 * HZ; + } +} + +#else +void l_check_no_ns_lock(struct ldlm_namespace *ns) +{ + if (l_has_lock(&ns->ns_lock)) { + CERROR("namespace %s lock held illegally; tell phil\n", + ns->ns_name); + } +} +#endif /* __KERNEL__ */