diff --git a/src/afs/afs_lock.c b/src/afs/afs_lock.c index 7d380b264c..8410292a83 100644 --- a/src/afs/afs_lock.c +++ b/src/afs/afs_lock.c @@ -362,3 +362,34 @@ struct afs_bozoLock *alock; { return 0; } #endif + +Afs_Lock_Trace(op, alock, type, file, line) + int op; + struct afs_lock *alock; + int type; + char *file; + int line; +{ + int traceok; + struct afs_icl_log *tlp; + struct afs_icl_set *tsp; + + if (!afs_trclock) return 1; + if ((alock) == &afs_icl_lock) return 1; + + ObtainReadLock(&afs_icl_lock); + traceok = 1; + for (tlp = afs_icl_allLogs; tlp; tlp = tlp->nextp) + if ((alock) == &tlp->lock) traceok = 0; + for (tsp = afs_icl_allSets; tsp; tsp = tsp->nextp) + if ((alock) == &tsp->lock) traceok = 0; + ReleaseReadLock(&afs_icl_lock); + if (!traceok) return 1; + + afs_Trace4(afs_iclSetp, op, + ICL_TYPE_STRING, (long)file, + ICL_TYPE_INT32, (long)line, + ICL_TYPE_POINTER, (long)alock, + ICL_TYPE_LONG, (long)type); + return 0; +} diff --git a/src/afs/afs_trace.et b/src/afs/afs_trace.et index 0b6286c257..01f779b310 100644 --- a/src/afs/afs_trace.et +++ b/src/afs/afs_trace.et @@ -99,10 +99,10 @@ error_table 2 ZCM ec CM_TRACE_READLINK, "readlink 0x%lx" ec CM_TRACE_FSYNC, "fsync 0x%lx" - ec CM_TRACE_LOCKDONE, "Released lock 0x%lx level %d" - ec CM_TRACE_LOCKDOWN, "Downgraded lock 0x%lx to %d" - ec CM_TRACE_LOCKOBTAIN,"Obtained lock 0x%lx level %d" - ec CM_TRACE_LOCKSLEPT, "Slept for lock 0x%lx level %d" + ec CM_TRACE_LOCKDONE, "%s line %d: Released lock 0x%lx level %d" + ec CM_TRACE_LOCKDOWN, "%s line %d: Downgraded lock 0x%lx to %d" + ec CM_TRACE_LOCKOBTAIN,"%s line %d: Obtained lock 0x%lx level %d" + ec CM_TRACE_LOCKSLEPT, "%s line %d: Slept for lock 0x%lx level %d" ec CM_TRACE_PAGE_READ, "0x%lx called page_read (returned %d) states 0x%x" ec CM_TRACE_PAGE_WRITE, "0x%lx called page_write (returned %d) states 0x%x" diff --git a/src/afs/lock.h b/src/afs/lock.h index f7a84ac3f2..774b23726e 100644 --- a/src/afs/lock.h +++ b/src/afs/lock.h @@ -152,11 +152,20 @@ typedef struct afs_lock afs_rwlock_t; #include "icl.h" extern int afs_trclock; + +#define AFS_LOCK_TRACE_ENABLE 0 +#if AFS_LOCK_TRACE_ENABLE +#define AFS_LOCK_TRACE(op, lock, type) \ + if (afs_trclock) Afs_Lock_Trace(op, lock, type, __FILE__, __LINE__); +#else +#define AFS_LOCK_TRACE(op, lock, type) +#endif + #if defined(INSTRUMENT_LOCKS) #define ObtainReadLock(lock)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, READ_LOCK);\ if (!((lock)->excl_locked & WRITE_LOCK)) \ ((lock)->readers_reading)++; \ else \ @@ -166,7 +175,7 @@ extern int afs_trclock; #define ObtainWriteLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, WRITE_LOCK);\ if (!(lock)->excl_locked && !(lock)->readers_reading)\ (lock) -> excl_locked = WRITE_LOCK;\ else\ @@ -179,7 +188,7 @@ extern int afs_trclock; #define ObtainSharedLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, SHARED_LOCK);\ if (!(lock)->excl_locked)\ (lock) -> excl_locked = SHARED_LOCK;\ else\ @@ -192,7 +201,7 @@ extern int afs_trclock; #define UpgradeSToWLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)BOOSTED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, BOOSTED_LOCK);\ if (!(lock)->readers_reading)\ (lock)->excl_locked = WRITE_LOCK;\ else\ @@ -204,7 +213,7 @@ extern int afs_trclock; /* this must only be called with a WRITE or boosted SHARED lock! */ #define ConvertWToSLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, SHARED_LOCK);\ (lock)->excl_locked = SHARED_LOCK; \ if((lock)->wait_states) \ Afs_Lock_ReleaseR(lock); \ @@ -212,7 +221,7 @@ extern int afs_trclock; #define ConvertWToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ (lock)->pid_last_reader = MyPidxx ; \ @@ -222,7 +231,7 @@ extern int afs_trclock; #define ConvertSToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ (lock)->pid_last_reader = MyPidxx ; \ @@ -232,7 +241,7 @@ extern int afs_trclock; #define ReleaseReadLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, READ_LOCK);\ if (!(--((lock)->readers_reading)) && (lock)->wait_states)\ Afs_Lock_ReleaseW(lock) ; \ if ( (lock)->pid_last_reader == MyPidxx ) \ @@ -241,7 +250,7 @@ extern int afs_trclock; #define ReleaseWriteLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, WRITE_LOCK);\ (lock)->excl_locked &= ~WRITE_LOCK;\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ (lock)->pid_writer=0; \ @@ -250,7 +259,7 @@ extern int afs_trclock; /* can be used on shared or boosted (write) locks */ #define ReleaseSharedLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, SHARED_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ (lock)->pid_writer=0; \ @@ -260,7 +269,7 @@ extern int afs_trclock; #define ObtainReadLock(lock)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, READ_LOCK);\ if (!((lock)->excl_locked & WRITE_LOCK)) \ ((lock)->readers_reading)++; \ else \ @@ -269,7 +278,7 @@ extern int afs_trclock; #define ObtainWriteLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, WRITE_LOCK);\ if (!(lock)->excl_locked && !(lock)->readers_reading)\ (lock) -> excl_locked = WRITE_LOCK;\ else\ @@ -280,7 +289,7 @@ extern int afs_trclock; #define ObtainSharedLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, SHARED_LOCK);\ if (!(lock)->excl_locked)\ (lock) -> excl_locked = SHARED_LOCK;\ else\ @@ -291,7 +300,7 @@ extern int afs_trclock; #define UpgradeSToWLock(lock, src)\ BEGINMAC \ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKOBTAIN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)BOOSTED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKOBTAIN, lock, BOOSTED_LOCK);\ if (!(lock)->readers_reading)\ (lock)->excl_locked = WRITE_LOCK;\ else\ @@ -301,7 +310,7 @@ extern int afs_trclock; /* this must only be called with a WRITE or boosted SHARED lock! */ #define ConvertWToSLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, SHARED_LOCK);\ (lock)->excl_locked = SHARED_LOCK; \ if((lock)->wait_states) \ Afs_Lock_ReleaseR(lock); \ @@ -309,7 +318,7 @@ extern int afs_trclock; #define ConvertWToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ Afs_Lock_ReleaseR(lock);\ @@ -317,7 +326,7 @@ extern int afs_trclock; #define ConvertSToRLock(lock) \ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDOWN, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDOWN, lock, READ_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ ((lock)->readers_reading)++;\ Afs_Lock_ReleaseR(lock);\ @@ -325,14 +334,14 @@ extern int afs_trclock; #define ReleaseReadLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)READ_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, READ_LOCK);\ if (!(--((lock)->readers_reading)) && (lock)->wait_states)\ Afs_Lock_ReleaseW(lock) ; \ ENDMAC #define ReleaseWriteLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)WRITE_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, WRITE_LOCK);\ (lock)->excl_locked &= ~WRITE_LOCK;\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ ENDMAC @@ -340,7 +349,7 @@ extern int afs_trclock; /* can be used on shared or boosted (write) locks */ #define ReleaseSharedLock(lock)\ BEGINMAC\ -/* if (afs_trclock) {icl_Trace2(cm_iclSetp, CM_TRACE_LOCKDONE, ICL_TYPE_POINTER, (long)lock, ICL_TYPE_LONG, (long)SHARED_LOCK);} */ \ + AFS_LOCK_TRACE(CM_TRACE_LOCKDONE, lock, SHARED_LOCK);\ (lock)->excl_locked &= ~(SHARED_LOCK | WRITE_LOCK);\ if ((lock)->wait_states) Afs_Lock_ReleaseR(lock);\ ENDMAC