From 34767c6a0f914960c9a1efabe69dd9c312a2b400 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Sun, 17 Oct 2010 23:39:47 -0400 Subject: [PATCH] down with assert, up with osi_Assert because NDEBUG breaks things which happen inside an assert, be done with that. instead, call osi_Assert wherever possible. doesn't work for code which builds before rx; those cases we handle by ensuring no operations happen inside the assert(). side effect: move all pthread operations wrapped in asserts to MUTEX_mumble and CV_mumble calls where those exist, so the assertions happen all in one set of macroes. Change-Id: I9fd8a0fdfdaed5ed55de3e5c0c4673d4714e7441 Reviewed-on: http://gerrit.openafs.org/3001 Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: Derrick Brashear --- src/afsd/afsd.c | 13 +- src/afsd/afsd_kernel.c | 1 - src/audit/audit.c | 12 +- src/budb/db_dump.c | 18 +- src/budb/dbs_dump.c | 32 ++-- src/butc/tcmain.c | 4 - src/kauth/kalog.c | 1 - src/libafsrpc/afsrpc.def | 1 + src/log/unlog.c | 1 - src/lwp/iomgr.c | 6 +- src/lwp/lock.c | 47 +++-- src/lwp/lock.h | 8 +- src/lwp/lwp.c | 64 ++++--- src/lwp/lwp.h | 4 +- src/lwp/rw.c | 16 +- src/ptserver/utils.c | 13 +- src/rx/rx.c | 7 +- src/rx/rx_lwp.h | 4 + src/shlibafsrpc/libafsrpc.map | 3 + src/tsalvaged/Makefile.in | 7 +- src/ubik/disk.c | 4 +- src/ubik/recovery.c | 9 +- src/ubik/ubik.c | 34 ++-- src/ubik/ubik.p.h | 10 +- src/ubik/ubikclient.c | 15 +- src/util/Makefile.in | 8 +- src/util/netutils.c | 36 ++-- src/util/potpourri.h | 110 ----------- src/util/pthread_glock.h | 6 +- src/util/serverLog.c | 10 +- src/util/thread_pool.c | 55 +++--- src/util/work_queue.c | 216 +++++++++++----------- src/viced/afsfileprocs.c | 106 +++++------ src/viced/callback.c | 23 +-- src/viced/host.c | 92 +++++---- src/viced/host.h | 10 +- src/viced/viced.c | 68 ++++--- src/viced/viced.h | 22 +-- src/vol/Makefile.in | 5 +- src/vol/NTMakefile | 1 + src/vol/clone.c | 6 +- src/vol/daemon_com.c | 4 +- src/vol/fssync-client.c | 12 +- src/vol/fssync-debug.c | 4 +- src/vol/fssync-server.c | 46 +++-- src/vol/ihandle.c | 76 ++++---- src/vol/ihandle.h | 13 +- src/vol/listinodes.c | 8 +- src/vol/namei_ops.c | 14 +- src/vol/ntops.c | 2 +- src/vol/nuke.c | 4 - src/vol/partition.c | 34 ++-- src/vol/physio.c | 2 +- src/vol/salvaged.c | 62 +++---- src/vol/salvsync-client.c | 1 - src/vol/salvsync-server.c | 45 +++-- src/vol/vg_cache.c | 12 +- src/vol/vg_scan.c | 2 +- src/vol/vnode.c | 32 ++-- src/vol/vnode_inline.h | 22 +-- src/vol/vol-salvage.c | 158 ++++++++-------- src/vol/volume.c | 338 +++++++++++++++++----------------- src/vol/volume.h | 37 ++-- src/vol/volume_inline.h | 12 +- src/vol/vutil.c | 66 +++---- src/volser/Makefile.in | 3 +- src/volser/dumpstuff.c | 28 ++- src/volser/physio.c | 2 +- src/volser/vol_split.c | 4 - src/volser/volmain.c | 10 +- src/volser/volprocs.c | 12 +- src/volser/volser.p.h | 10 +- src/volser/voltrans.c | 4 - 73 files changed, 985 insertions(+), 1202 deletions(-) delete mode 100644 src/util/potpourri.h diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 84bbf0a03..d954ef8ff 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -68,8 +68,7 @@ #include "afsd.h" -#include -#include +#include #include #include #include @@ -270,7 +269,7 @@ static int sawBiod = 0; static int sawCacheStatEntries = 0; char afsd_cacheMountDir[1024]; /*Mount directory for AFS */ static char rootVolume[64] = "root.afs"; /*AFS root volume name */ -static afs_int32 cacheSetTime = FALSE; /*Keep checking time to avoid drift? */ +static afs_int32 cacheSetTime = 0; /*Keep checking time to avoid drift? */ #ifdef AFS_XBSD_ENV static int createAndTrunc = O_RDWR | O_CREAT | O_TRUNC; /*Create & truncate on open */ #else @@ -1726,7 +1725,7 @@ mainproc(struct cmd_syndesc *as, void *arock) } if (as->parms[8].items) { /* -nosettime */ - cacheSetTime = FALSE; + cacheSetTime = 0; } if (as->parms[9].items) { /* -verbose */ @@ -1858,7 +1857,7 @@ mainproc(struct cmd_syndesc *as, void *arock) } if (as->parms[32].items) { /* -settime */ - cacheSetTime = TRUE; + cacheSetTime = 1; } /* set rx_extraPackets */ @@ -1891,7 +1890,7 @@ mainproc(struct cmd_syndesc *as, void *arock) if (as->parms[35].items) { #ifdef AFS_MAXVCOUNT_ENV /* -disable-dynamic-vcaches */ - afsd_dynamic_vcaches = FALSE; + afsd_dynamic_vcaches = 0; #else printf("afsd: Error toggling flag, dynamically allocated vcaches not supported on your platform\n"); exit(1); @@ -1900,7 +1899,7 @@ mainproc(struct cmd_syndesc *as, void *arock) #ifdef AFS_MAXVCOUNT_ENV else { /* -dynamic-vcaches */ - afsd_dynamic_vcaches = TRUE; + afsd_dynamic_vcaches = 1; } if (afsd_verbose) diff --git a/src/afsd/afsd_kernel.c b/src/afsd/afsd_kernel.c index 35f3eaa1f..f68a76e60 100644 --- a/src/afsd/afsd_kernel.c +++ b/src/afsd/afsd_kernel.c @@ -17,7 +17,6 @@ #include "afsd.h" #include -#include #include #include #include diff --git a/src/audit/audit.c b/src/audit/audit.c index 3b42cde3f..dacbef7e8 100644 --- a/src/audit/audit.c +++ b/src/audit/audit.c @@ -292,7 +292,7 @@ static pthread_once_t audit_lock_once = PTHREAD_ONCE_INIT; static void osi_audit_init_lock(void) { - pthread_mutex_init(&audit_lock, NULL); + MUTEX_INIT(&audit_lock, "audit", MUTEX_DEFAULT, 0); audit_lock_initialized = 1; } #endif @@ -328,7 +328,7 @@ osi_audit_internal(char *audEvent, /* Event name (15 chars or less) */ /* i'm pretty sure all the server apps now call osi_audit_init(), * but to be extra careful we'll leave this assert in here for a * while to make sure */ - assert(audit_lock_initialized); + osi_Assert(audit_lock_initialized); #endif /* AFS_PTHREAD_ENV */ if ((osi_audit_all < 0) || (osi_echo_trail < 0)) @@ -362,9 +362,7 @@ osi_audit_internal(char *audEvent, /* Event name (15 chars or less) */ } #endif -#ifdef AFS_PTHREAD_ENV - pthread_mutex_lock(&audit_lock); -#endif + MUTEX_ENTER(&audit_lock); #ifdef AFS_AIX32_ENV bufferPtr = BUFFER; @@ -383,9 +381,7 @@ osi_audit_internal(char *audEvent, /* Event name (15 chars or less) */ printbuf(0, audEvent, afsName, hostId, errCode, vaList); } #endif -#ifdef AFS_PTHREAD_ENV - pthread_mutex_unlock(&audit_lock); -#endif + MUTEX_EXIT(&audit_lock); return 0; } diff --git a/src/budb/db_dump.c b/src/budb/db_dump.c index c7a1e1a95..dbecce45a 100644 --- a/src/budb/db_dump.c +++ b/src/budb/db_dump.c @@ -74,7 +74,7 @@ canWrite(int fid) if (dumpSyncPtr->ds_readerStatus == DS_WAITING) { dumpSyncPtr->ds_readerStatus = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dumpSyncPtr->ds_readerStatus_cond) == 0); + CV_BROADCAST(&dumpSyncPtr->ds_readerStatus_cond); #else code = LWP_SignalProcess(&dumpSyncPtr->ds_readerStatus); if (code) @@ -84,9 +84,9 @@ canWrite(int fid) dumpSyncPtr->ds_writerStatus = DS_WAITING; ReleaseWriteLock(&dumpSyncPtr->ds_lock); #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_lock(&dumpSyncPtr->ds_writerStatus_mutex) == 0); - assert(pthread_cond_wait(&dumpSyncPtr->ds_writerStatus_cond, &dumpSyncPtr->ds_writerStatus_mutex) == 0); - assert(pthread_mutex_unlock(&dumpSyncPtr->ds_writerStatus_mutex) == 0); + MUTEX_ENTER(&dumpSyncPtr->ds_writerStatus_mutex); + CV_WAIT(&dumpSyncPtr->ds_writerStatus_cond, &dumpSyncPtr->ds_writerStatus_mutex); + MUTEX_EXIT(&dumpSyncPtr->ds_writerStatus_mutex); #else LWP_WaitProcess(&dumpSyncPtr->ds_writerStatus); #endif @@ -115,7 +115,7 @@ haveWritten(afs_int32 nbytes) if (dumpSyncPtr->ds_readerStatus == DS_WAITING) { dumpSyncPtr->ds_readerStatus = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dumpSyncPtr->ds_readerStatus_cond) == 0); + CV_BROADCAST(&dumpSyncPtr->ds_readerStatus_cond); #else code = LWP_SignalProcess(&dumpSyncPtr->ds_readerStatus); if (code) @@ -144,9 +144,9 @@ doneWriting(afs_int32 error) dumpSyncPtr->ds_writerStatus = DS_WAITING; ReleaseWriteLock(&dumpSyncPtr->ds_lock); #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_lock(&dumpSyncPtr->ds_writerStatus_mutex) == 0); - assert(pthread_cond_wait(&dumpSyncPtr->ds_writerStatus_cond, &dumpSyncPtr->ds_writerStatus_mutex) == 0); - assert(pthread_mutex_unlock(&dumpSyncPtr->ds_writerStatus_mutex) == 0); + MUTEX_ENTER(&dumpSyncPtr->ds_writerStatus_mutex); + CV_WAIT(&dumpSyncPtr->ds_writerStatus_cond, &dumpSyncPtr->ds_writerStatus_mutex); + MUTEX_EXIT(&dumpSyncPtr->ds_writerStatus_mutex); #else LWP_WaitProcess(&dumpSyncPtr->ds_writerStatus); #endif @@ -162,7 +162,7 @@ doneWriting(afs_int32 error) dumpSyncPtr->ds_writerStatus = DS_DONE; dumpSyncPtr->ds_readerStatus = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dumpSyncPtr->ds_readerStatus_cond) == 0); + CV_BROADCAST(&dumpSyncPtr->ds_readerStatus_cond); #else code = LWP_NoYieldSignal(&dumpSyncPtr->ds_readerStatus); if (code) diff --git a/src/budb/dbs_dump.c b/src/budb/dbs_dump.c index 6007b6993..d980f26d3 100644 --- a/src/budb/dbs_dump.c +++ b/src/budb/dbs_dump.c @@ -162,16 +162,16 @@ DumpDB(struct rx_call *call, /* Initialize the condition variables and the mutexes we use * to signal and synchronize the reader and writer threads. */ - assert(pthread_cond_init(&dumpSyncPtr->ds_readerStatus_cond, (const pthread_condattr_t *)0) == 0); - assert(pthread_cond_init(&dumpSyncPtr->ds_writerStatus_cond, (const pthread_condattr_t *)0) == 0); - assert(pthread_mutex_init(&dumpSyncPtr->ds_readerStatus_mutex, (const pthread_mutexattr_t *)0) == 0); - assert(pthread_mutex_init(&dumpSyncPtr->ds_writerStatus_mutex, (const pthread_mutexattr_t *)0) == 0); + CV_INIT(&dumpSyncPtr->ds_readerStatus_cond, "reader cond", CV_DEFAULT, 0); + CV_INIT(&dumpSyncPtr->ds_writerStatus_cond, "writer cond", CV_DEFAULT, 0); + MUTEX_INIT(&dumpSyncPtr->ds_readerStatus_mutex, "reader", MUTEX_DEFAULT, 0); + MUTEX_INIT(&dumpSyncPtr->ds_writerStatus_mutex, "writer", MUTEX_DEFAULT, 0); /* Initialize the thread attributes and launch the thread */ - assert(pthread_attr_init(&dumperPid_tattr) == 0); - assert(pthread_attr_setdetachstate(&dumperPid_tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&dumperPid, &dumperPid_tattr, (void *)setupDbDump, NULL) == 0); + osi_Assert(pthread_attr_init(&dumperPid_tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&dumperPid_tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&dumperPid, &dumperPid_tattr, (void *)setupDbDump, NULL) == 0); #else code = @@ -188,9 +188,9 @@ DumpDB(struct rx_call *call, #ifdef AFS_PTHREAD_ENV /* Initialize the thread attributes and launch the thread */ - assert(pthread_attr_init(&watcherPid_tattr) == 0); - assert(pthread_attr_setdetachstate(&watcherPid_tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&watcherPid, &watcherPid_tattr, (void *)dumpWatcher, NULL) == 0); + osi_Assert(pthread_attr_init(&watcherPid_tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&watcherPid_tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&watcherPid, &watcherPid_tattr, (void *)dumpWatcher, NULL) == 0); #else /* now create the watcher thread */ code = @@ -214,7 +214,7 @@ DumpDB(struct rx_call *call, LogDebug(6, "wakup writer\n"); dumpSyncPtr->ds_writerStatus = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dumpSyncPtr->ds_writerStatus_cond) == 0); + CV_BROADCAST(&dumpSyncPtr->ds_writerStatus_cond); #else code = LWP_SignalProcess(&dumpSyncPtr->ds_writerStatus); if (code) @@ -225,9 +225,9 @@ DumpDB(struct rx_call *call, dumpSyncPtr->ds_readerStatus = DS_WAITING; ReleaseWriteLock(&dumpSyncPtr->ds_lock); #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_lock(&dumpSyncPtr->ds_readerStatus_mutex) == 0); - assert(pthread_cond_wait(&dumpSyncPtr->ds_readerStatus_cond, &dumpSyncPtr->ds_readerStatus_mutex) == 0); - assert(pthread_mutex_unlock(&dumpSyncPtr->ds_readerStatus_mutex) == 0); + MUTEX_ENTER(&dumpSyncPtr->ds_readerStatus_mutex); + CV_WAIT(&dumpSyncPtr->ds_readerStatus_cond, &dumpSyncPtr->ds_readerStatus_mutex); + MUTEX_EXIT(&dumpSyncPtr->ds_readerStatus_mutex); #else LWP_WaitProcess(&dumpSyncPtr->ds_readerStatus); #endif @@ -256,7 +256,7 @@ DumpDB(struct rx_call *call, if (dumpSyncPtr->ds_writerStatus == DS_WAITING) { dumpSyncPtr->ds_writerStatus = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dumpSyncPtr->ds_writerStatus_cond) == 0); + CV_BROADCAST(&dumpSyncPtr->ds_writerStatus_cond); #else code = LWP_SignalProcess(&dumpSyncPtr->ds_writerStatus); if (code) @@ -352,7 +352,7 @@ dumpWatcher(void *unused) close(dumpSyncPtr->pipeFid[0]); close(dumpSyncPtr->pipeFid[1]); #ifdef AFS_PTHREAD_ENV - assert(pthread_cancel(dumpSyncPtr->dumperPid) == 0); + osi_Assert(pthread_cancel(dumpSyncPtr->dumperPid) == 0); #else code = LWP_DestroyProcess(dumpSyncPtr->dumperPid); if (code) diff --git a/src/butc/tcmain.c b/src/butc/tcmain.c index e63209295..bdfb98039 100644 --- a/src/butc/tcmain.c +++ b/src/butc/tcmain.c @@ -27,11 +27,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else #include -#endif #include #include #include diff --git a/src/kauth/kalog.c b/src/kauth/kalog.c index 326cddf3c..6929b6f74 100644 --- a/src/kauth/kalog.c +++ b/src/kauth/kalog.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "kauth.h" #include "kalog.h" diff --git a/src/libafsrpc/afsrpc.def b/src/libafsrpc/afsrpc.def index 2a0a15a38..f87a057e3 100755 --- a/src/libafsrpc/afsrpc.def +++ b/src/libafsrpc/afsrpc.def @@ -267,6 +267,7 @@ EXPORTS rx_SetConnHardDeadTime @272 rx_SetConnIdleDeadTime @273 rx_InterruptCall @274 + osi_Panic @275 ; for performance testing rx_TSFPQGlobSize @2001 DATA diff --git a/src/log/unlog.c b/src/log/unlog.c index e807c0a9a..3542e7f24 100644 --- a/src/log/unlog.c +++ b/src/log/unlog.c @@ -31,7 +31,6 @@ #include -#include #ifdef AFS_AIX32_ENV #include #endif diff --git a/src/lwp/iomgr.c b/src/lwp/iomgr.c index ecc36d8d9..74df51754 100644 --- a/src/lwp/iomgr.c +++ b/src/lwp/iomgr.c @@ -73,9 +73,9 @@ void IOMGR_Sleep (seconds) itv.tv_sec = seconds; itv.tv_nsec = 0; - assert(pthread_mutex_unlock(&lwp_mutex) == 0); - assert(pthread_delay_np(&itv) == 0); - assert(pthread_mutex_lock(&lwp_mutex) == 0); + MUTEX_EXIT(&lwp_mutex); + osi_Assert(pthread_delay_np(&itv) == 0); + MUTEX_ENTER(&lwp_mutex); } #else diff --git a/src/lwp/lock.c b/src/lwp/lock.c index d2897f93b..ca8fc55a8 100644 --- a/src/lwp/lock.c +++ b/src/lwp/lock.c @@ -25,12 +25,14 @@ #include #include - -#ifndef AFS_PTHREAD_ENV +#ifdef AFS_PTHREAD_ENV #include -#else /* AFS_PTHREAD_ENV */ +/* can't include this in lwp, rx hasn't built yet */ +#include +#else #include -#endif /* AFS_PTHRED_ENV */ +#endif + #include "lwp.h" #include "lock.h" #include @@ -46,23 +48,20 @@ Lock_Init(struct Lock *lock) lock->wait_states = 0; lock->num_waiting = 0; #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&lock->mutex, (const pthread_mutexattr_t *)0) == - 0); - assert(pthread_cond_init(&lock->read_cv, (const pthread_condattr_t *)0) == - 0); - assert(pthread_cond_init(&lock->write_cv, (const pthread_condattr_t *)0) - == 0); -#endif /* AFS_PTHRED_ENV */ + MUTEX_INIT(&lock->mutex, "lock", MUTEX_DEFAULT, 0); + CV_INIT(&lock->read_cv, "read", CV_DEFAULT, 0); + CV_INIT(&lock->write_cv, "write", CV_DEFAULT, 0); +#endif /* AFS_PTHREAD_ENV */ } void Lock_Destroy(struct Lock *lock) { #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_destroy(&lock->mutex) == 0); - assert(pthread_cond_destroy(&lock->read_cv) == 0); - assert(pthread_cond_destroy(&lock->write_cv) == 0); -#endif /* AFS_PTHRED_ENV */ + MUTEX_DESTROY(&lock->mutex); + CV_DESTROY(&lock->read_cv); + CV_DESTROY(&lock->write_cv); +#endif /* AFS_PTHREAD_ENV */ } void @@ -75,7 +74,7 @@ Afs_Lock_Obtain(struct Lock *lock, int how) do { lock->wait_states |= READ_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&lock->read_cv, &lock->mutex) == 0); + CV_WAIT(&lock->read_cv, &lock->mutex); #else /* AFS_PTHREAD_ENV */ LWP_WaitProcess(&lock->readers_reading); #endif /* AFS_PTHREAD_ENV */ @@ -89,7 +88,7 @@ Afs_Lock_Obtain(struct Lock *lock, int how) do { lock->wait_states |= WRITE_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&lock->write_cv, &lock->mutex) == 0); + CV_WAIT(&lock->write_cv, &lock->mutex); #else /* AFS_PTHREAD_ENV */ LWP_WaitProcess(&lock->excl_locked); #endif /* AFS_PTHREAD_ENV */ @@ -103,7 +102,7 @@ Afs_Lock_Obtain(struct Lock *lock, int how) do { lock->wait_states |= SHARED_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&lock->write_cv, &lock->mutex) == 0); + CV_WAIT(&lock->write_cv, &lock->mutex); #else /* AFS_PTHREAD_ENV */ LWP_WaitProcess(&lock->excl_locked); #endif /* AFS_PTHREAD_ENV */ @@ -117,7 +116,7 @@ Afs_Lock_Obtain(struct Lock *lock, int how) do { lock->wait_states |= WRITE_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&lock->write_cv, &lock->mutex) == 0); + CV_WAIT(&lock->write_cv, &lock->mutex); #else /* AFS_PTHREAD_ENV */ LWP_WaitProcess(&lock->excl_locked); #endif /* AFS_PTHREAD_ENV */ @@ -139,7 +138,7 @@ Afs_Lock_WakeupR(struct Lock *lock) if (lock->wait_states & READ_LOCK) { lock->wait_states &= ~READ_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&lock->read_cv) == 0); + CV_BROADCAST(&lock->read_cv); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(&lock->readers_reading); #endif /* AFS_PTHREAD_ENV */ @@ -153,14 +152,14 @@ Afs_Lock_ReleaseR(struct Lock *lock) if (lock->wait_states & READ_LOCK) { lock->wait_states &= ~READ_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&lock->read_cv) == 0); + CV_BROADCAST(&lock->read_cv); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(&lock->readers_reading); #endif /* AFS_PTHREAD_ENV */ } else { lock->wait_states &= ~EXCL_LOCKS; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&lock->write_cv) == 0); + CV_BROADCAST(&lock->write_cv); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(&lock->excl_locked); #endif /* AFS_PTHREAD_ENV */ @@ -174,14 +173,14 @@ Afs_Lock_ReleaseW(struct Lock *lock) if (lock->wait_states & EXCL_LOCKS) { lock->wait_states &= ~EXCL_LOCKS; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&lock->write_cv) == 0); + CV_BROADCAST(&lock->write_cv); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(&lock->excl_locked); #endif /* AFS_PTHREAD_ENV */ } else { lock->wait_states &= ~READ_LOCK; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&lock->read_cv) == 0); + CV_BROADCAST(&lock->read_cv); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(&lock->readers_reading); #endif /* AFS_PTHREAD_ENV */ diff --git a/src/lwp/lock.h b/src/lwp/lock.h index cac86e101..7bda37588 100644 --- a/src/lwp/lock.h +++ b/src/lwp/lock.h @@ -43,10 +43,12 @@ #define ENDMAC } while (0) #ifdef AFS_PTHREAD_ENV -#include #include -#define LOCK_LOCK(A) assert(pthread_mutex_lock(&(A)->mutex) == 0) -#define LOCK_UNLOCK(A) assert(pthread_mutex_unlock(&(A)->mutex) == 0) +#include +/* can't include in non-lwp case; rx builds later */ +#include +#define LOCK_LOCK(A) MUTEX_ENTER(&(A)->mutex); +#define LOCK_UNLOCK(A) MUTEX_EXIT(&(A)->mutex); #else /* AFS_PTHREAD_ENV */ #define LOCK_LOCK(A) #define LOCK_UNLOCK(A) diff --git a/src/lwp/lwp.c b/src/lwp/lwp.c index 403e534c7..2e53d0dd2 100644 --- a/src/lwp/lwp.c +++ b/src/lwp/lwp.c @@ -1354,13 +1354,15 @@ static PROCESS lwp_alloc_process(char *name, pthread_startroutine_t ep, pthread_addr_t arg) { PROCESS lp; - assert(lp = (PROCESS) malloc(sizeof(*lp))); + lp = (PROCESS) malloc(sizeof(*lp)); + assert(lp); memset(lp, 0, sizeof(*lp)); if (!name) { char temp[100]; static procnum; sprintf(temp, "unnamed_process_%04d", ++procnum); - assert(name = (char *)malloc(strlen(temp) + 1)); + name = (char *)malloc(strlen(temp) + 1); + assert(name); strcpy(name, temp); } lp->name = name; @@ -1377,7 +1379,8 @@ lwp_thread_process(PROCESS lp) { lp->next = lwp_process_list; lwp_process_list = lp; - assert(!pthread_setspecific(lwp_process_key, (pthread_addr_t) lp)); + if (pthread_setspecific(lwp_process_key, (pthread_addr_t) lp) != 0) + assert(0); } /* The top-level routine used as entry point to explicitly created LWP @@ -1388,10 +1391,10 @@ lwp_top_level(pthread_addr_t argp) { PROCESS lp = (PROCESS) argp; - assert(!pthread_mutex_lock(&lwp_mutex)); + MUTEX_ENTER(&lwp_mutex); lwp_thread_process(lp); (lp->ep) (lp->arg); - assert(!pthread_mutex_unlock(&lwp_mutex)); + MUTEX_EXIT(&lwp_mutex); /* Should cleanup state */ } @@ -1408,10 +1411,13 @@ LWP_CreateProcess(pthread_startroutine_t ep, int stacksize, int priority, if (!cmalwp_pri_inrange(priority)) return LWP_EBADPRI; #endif - assert(!pthread_attr_create(&attr)); - assert(!pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)); + if (pthread_attr_create(&attr)) + assert(0); + if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) + assert(0); if (stacksize) - assert(!pthread_attr_setstacksize(&attr, stacksize)); + if (pthread_attr_setstacksize(&attr, stacksize)) + assert(0); #ifndef BDE_THREADS (void)pthread_attr_setinheritsched(&attr, PTHREAD_DEFAULT_SCHED); (void)pthread_attr_setsched(&attr, SCHED_FIFO); @@ -1423,14 +1429,16 @@ LWP_CreateProcess(pthread_startroutine_t ep, int stacksize, int priority, (pthread_addr_t) parm); /* allow new thread to run if higher priority */ - assert(!pthread_mutex_unlock(&lwp_mutex)); + MUTEX_EXIT(&lwp_mutex); /* process is only added to active list after first time it runs (it adds itself) */ status = pthread_create(&lp->handle, attr, (pthread_startroutine_t) lwp_top_level, (pthread_addr_t) lp); - assert(!pthread_attr_delete(&attr)); - assert(!pthread_mutex_lock(&lwp_mutex)); + if (pthread_attr_delete(&attr)) + assert(0); + if (pthread_mutex_lock(&lwp_mutex)) + assert(0); if (status != 0) { free(lp); return LWP_ENOMEM; @@ -1443,14 +1451,16 @@ PROCESS LWP_ActiveProcess(void) { /* returns pid of current process */ PROCESS pid; - assert(!pthread_getspecific(lwp_process_key, (pthread_addr_t *) & pid)); + if (pthread_getspecific(lwp_process_key, (pthread_addr_t *) & pid)) + assert(0); return pid; } int LWP_CurrentProcess(PROCESS * pid) { /* get pid of current process */ - assert(!pthread_getspecific(lwp_process_key, (pthread_addr_t *) pid)); + if (pthread_getspecific(lwp_process_key, (pthread_addr_t *) pid)) + assert(0); return LWP_SUCCESS; } @@ -1463,9 +1473,9 @@ LWP_DestroyProcess(PROCESS pid) int LWP_DispatchProcess(void) { /* explicit voluntary preemption */ - assert(!pthread_mutex_unlock(&lwp_mutex)); + MUTEX_EXIT(&lwp_mutex); pthread_yield(); - assert(!pthread_mutex_lock(&lwp_mutex)); + MUTEX_ENTER(&lwp_mutex); return LWP_SUCCESS; } @@ -1494,8 +1504,9 @@ LWP_InitializeProcessSupport(int priority, PROCESS * pid) /* Create pthread key to associate LWP process descriptor with each * LWP-created thread */ - assert(!pthread_keycreate(&lwp_process_key, (pthread_destructor_t) - lwp_process_key_destructor)); + if (pthread_keycreate(&lwp_process_key, (pthread_destructor_t) + lwp_process_key_destructor)) + assert(0); lp = lwp_alloc_process("main process", main, 0); lp->handle = pthread_self(); @@ -1505,8 +1516,8 @@ LWP_InitializeProcessSupport(int priority, PROCESS * pid) cmalwp_lwppri_to_cmapri(priority)); #endif - assert(pthread_mutex_init(&lwp_mutex, MUTEX_FAST_NP) == 0); - assert(pthread_mutex_lock(&lwp_mutex) == 0); + MUTEX_INIT(&lwp_mutex, "lwp", MUTEX_DEFAULT, 0); + MUTEX_ENTER(&lwp_mutex); initialized = 1; *pid = lp; return LWP_SUCCESS; @@ -1542,7 +1553,8 @@ getevent(void *event) assert(newp); newp->next = hashtable[hashcode]; hashtable[hashcode] = newp; - assert(!pthread_cond_init(&newp->cond, ((pthread_condattr_t) 0))); + if (pthread_cond_init(&newp->cond, ((pthread_condattr_t) 0))) + assert(0); newp->seq = 0; } newp->event = event; @@ -1564,7 +1576,8 @@ LWP_WaitProcess(void *event) ev = getevent(event); seq = ev->seq; while (seq == ev->seq) { - assert(pthread_cond_wait(&ev->cond, &lwp_mutex) == 0); + if (pthread_cond_wait(&ev->cond, &lwp_mutex)) + assert(0); } debugf(("%s: Woken up (%x)\n", lwp_process_string(), event)); relevent(ev); @@ -1587,7 +1600,8 @@ LWP_NoYieldSignal(void *event) ev = getevent(event); if (ev->refcount > 1) { ev->seq++; - assert(pthread_cond_broadcast(&ev->cond) == 0); + if (pthread_cond_broadcast(&ev->cond)) + assert(0); } relevent(ev); return LWP_SUCCESS; @@ -1603,10 +1617,10 @@ LWP_SignalProcess(void *event) ev = getevent(event); if (ev->refcount > 1) { ev->seq++; - assert(!pthread_mutex_unlock(&lwp_mutex)); - assert(!pthread_cond_broadcast(&ev->cond)); + MUTEX_EXIT(&lwp_mutex); + CV_BROADCAST(&ev->cond); pthread_yield(); - assert(!pthread_mutex_lock(&lwp_mutex)); + MUTEX_ENTER(&lwp_mutex); } relevent(ev); return LWP_SUCCESS; diff --git a/src/lwp/lwp.h b/src/lwp/lwp.h index 12923d1c1..81050b0d5 100644 --- a/src/lwp/lwp.h +++ b/src/lwp/lwp.h @@ -178,8 +178,8 @@ struct rock { /* to hide things associated with this LWP under */ * program. They simply acquire/release the global LWP mutex . */ extern pthread_mutex_t lwp_mutex; -#define LWP_EXIT_LWP_CONTEXT() pthread_mutex_unlock(&lwp_mutex) -#define LWP_ENTER_LWP_CONTEXT() pthread_mutex_lock(&lwp_mutex) +#define LWP_EXIT_LWP_CONTEXT() MUTEX_EXIT(&lwp_mutex) +#define LWP_ENTER_LWP_CONTEXT() MUTEX_ENTER(&lwp_mutex) #else #ifndef AFS_NT40_ENV #define lwp_abort() abort() diff --git a/src/lwp/rw.c b/src/lwp/rw.c index a416515cf..6fff9c75e 100644 --- a/src/lwp/rw.c +++ b/src/lwp/rw.c @@ -55,8 +55,7 @@ init() } char -empty(q) - queue *q; +empty(queue *q) { return (q->prev == q && q->next == q); } @@ -75,15 +74,14 @@ insert(queue * q, char *s) } char * -Remove(q) - queue *q; +Remove(queue *q) { queue *old; char *s; if (empty(q)) { printf("Remove from empty queue"); - assert(0); + osi_Assert(0); } old = q->next; @@ -100,8 +98,7 @@ int asleep; /* Number of processes sleeping -- used for * clean termination */ static int -read_process(id) - int *id; +read_process(int *id) { printf("\t[Reader %d]\n", *id); LWP_DispatchProcess(); /* Just relinquish control for now */ @@ -202,9 +199,8 @@ write_process() #include "AFS_component_version_number.c" -main(argc, argv) - int argc; - char **argv; +int +main(int argc, char **argv) { int nreaders, i; PROCESS pid; diff --git a/src/ptserver/utils.c b/src/ptserver/utils.c index 737c5732c..230e76041 100644 --- a/src/ptserver/utils.c +++ b/src/ptserver/utils.c @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -292,7 +291,7 @@ FindByID(struct ubik_trans *at, afs_int32 aid) return 0; if (aid == tentry.id) return entry; - assert(entry != tentry.nextID); + osi_Assert(entry != tentry.nextID); entry = tentry.nextID; while (entry != 0) { memset(&tentry, 0, sizeof(tentry)); @@ -301,7 +300,7 @@ FindByID(struct ubik_trans *at, afs_int32 aid) return 0; if (aid == tentry.id) return entry; - assert(entry != tentry.nextID); + osi_Assert(entry != tentry.nextID); entry = tentry.nextID; } return 0; @@ -325,7 +324,7 @@ FindByName(struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct prentry *ten return 0; if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0) return entry; - assert(entry != tentryp->nextName); + osi_Assert(entry != tentryp->nextName); entry = tentryp->nextName; while (entry != 0) { memset(tentryp, 0, sizeof(struct prentry)); @@ -334,7 +333,7 @@ FindByName(struct ubik_trans *at, char aname[PR_MAXNAMELEN], struct prentry *ten return 0; if ((strncmp(aname, tentryp->name, PR_MAXNAMELEN)) == 0) return entry; - assert(entry != tentryp->nextName); + osi_Assert(entry != tentryp->nextName); entry = tentryp->nextName; } return 0; @@ -464,7 +463,7 @@ RemoveFromIDHash(struct ubik_trans *tt, afs_int32 aid, afs_int32 *loc) /* ??? i if (code) return PRDBFAIL; while (aid != tentry.id) { - assert(trail != current); + osi_Assert(trail != current); trail = current; current = tentry.nextID; if (current == 0) @@ -542,7 +541,7 @@ RemoveFromNameHash(struct ubik_trans *tt, char *aname, afs_int32 *loc) if (code) return PRDBFAIL; while (strcmp(aname, tentry.name)) { - assert(trail != current); + osi_Assert(trail != current); trail = current; current = tentry.nextName; if (current == 0) diff --git a/src/rx/rx.c b/src/rx/rx.c index 773c75509..8f9438d16 100644 --- a/src/rx/rx.c +++ b/src/rx/rx.c @@ -229,10 +229,9 @@ rxi_InitPthread(void) MUTEX_INIT(&rxkad_random_mutex, "rxkad random", MUTEX_DEFAULT, 0); MUTEX_INIT(&rx_debug_mutex, "debug", MUTEX_DEFAULT, 0); - osi_Assert(pthread_cond_init - (&rx_event_handler_cond, (const pthread_condattr_t *)0) == 0); - osi_Assert(pthread_cond_init(&rx_listener_cond, (const pthread_condattr_t *)0) - == 0); + CV_INIT(&rx_event_handler_cond, "evhand", CV_DEFAULT, 0); + CV_INIT(&rx_listener_cond, "rxlisten", CV_DEFAULT, 0); + osi_Assert(pthread_key_create(&rx_thread_id_key, NULL) == 0); osi_Assert(pthread_key_create(&rx_ts_info_key, NULL) == 0); diff --git a/src/rx/rx_lwp.h b/src/rx/rx_lwp.h index d3feb0894..c77ad9ca4 100644 --- a/src/rx/rx_lwp.h +++ b/src/rx/rx_lwp.h @@ -28,6 +28,10 @@ #define MUTEX_ISMINE(a) #define CV_INIT(a,b,c,d) #define CV_DESTROY(a) +#define CV_WAIT(cv, l) +#define CV_SIGNAL(cv) +#define CV_BROADCAST(cv) +#define CV_TIMEDWAIT(cv, l, t) #define osirx_AssertMine(a, b) #endif /* KERNEL */ diff --git a/src/shlibafsrpc/libafsrpc.map b/src/shlibafsrpc/libafsrpc.map index adc68428b..0a3d9fe1c 100755 --- a/src/shlibafsrpc/libafsrpc.map +++ b/src/shlibafsrpc/libafsrpc.map @@ -19,6 +19,8 @@ des_pcbc_encrypt; ktohl; life_to_time; + osi_AssertFailU; + osi_Panic; rx_DestroyConnection; rx_EndCall; rx_Finalize; @@ -27,6 +29,7 @@ rx_GetIFInfo; rx_GetSpecific; rx_Init; + rx_InitHost; rx_KeyCreate; rx_NewCall; rx_NewConnection; diff --git a/src/tsalvaged/Makefile.in b/src/tsalvaged/Makefile.in index a8b7dcb34..01477fbb3 100644 --- a/src/tsalvaged/Makefile.in +++ b/src/tsalvaged/Makefile.in @@ -52,9 +52,10 @@ SSSDEBUG_OBJS = salvsync-debug.o physio.o common.o ${UTILOBJS} ${VLIBOBJS} ${DIR LIBS=${TOP_LIBDIR}/libafsauthent.a ${TOP_LIBDIR}/libafsrpc.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/libcmd.a -SLIBS=${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libdir.a \ - ${TOP_LIBDIR}/libvlib.a ${TOP_LIBDIR}/liblwp.a \ - ${TOP_LIBDIR}/libacl.a ${TOP_LIBDIR}/util.a +SLIBS=${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libdir.a \ + ${TOP_LIBDIR}/libvlib.a ${TOP_LIBDIR}/librx.a \ + ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libacl.a \ + ${TOP_LIBDIR}/util.a all: salvageserver dafssync-debug salvsync-debug dasalvager diff --git a/src/ubik/disk.c b/src/ubik/disk.c index 611402866..8b37195b9 100644 --- a/src/ubik/disk.c +++ b/src/ubik/disk.c @@ -899,7 +899,7 @@ udisk_commit(struct ubik_trans *atrans) dbase->version.counter++; /* bump commit count */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dbase->version_cond) == 0); + CV_BROADCAST(&dbase->version_cond); #else LWP_NoYieldSignal(&dbase->version); #endif @@ -1023,7 +1023,7 @@ udisk_end(struct ubik_trans *atrans) /* Wakeup any writers waiting in BeginTrans() */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&dbase->flags_cond) == 0); + CV_BROADCAST(&dbase->flags_cond); #else LWP_NoYieldSignal(&dbase->flags); #endif diff --git a/src/ubik/recovery.c b/src/ubik/recovery.c index 827f00603..e23d31c3e 100644 --- a/src/ubik/recovery.c +++ b/src/ubik/recovery.c @@ -15,7 +15,6 @@ #include #include #include -#include #ifdef AFS_NT40_ENV #include @@ -385,7 +384,7 @@ InitializeDB(struct ubik_dbase *adbase) (*adbase->setlabel) (adbase, 0, &adbase->version); } #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&adbase->version_cond) == 0); + CV_BROADCAST(&adbase->version_cond); #else LWP_NoYieldSignal(&adbase->version); #endif @@ -726,7 +725,7 @@ urecovery_Interact(void *dummy) } udisk_Invalidate(ubik_dbase, 0); /* data has changed */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&ubik_dbase->version_cond) == 0); + CV_BROADCAST(&ubik_dbase->version_cond); #else LWP_NoYieldSignal(&ubik_dbase->version); #endif @@ -754,7 +753,7 @@ urecovery_Interact(void *dummy) (*ubik_dbase->setlabel) (ubik_dbase, 0, &ubik_dbase->version); udisk_Invalidate(ubik_dbase, 0); /* data may have changed */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&ubik_dbase->version_cond) == 0); + CV_BROADCAST(&ubik_dbase->version_cond); #else LWP_NoYieldSignal(&ubik_dbase->version); #endif @@ -897,7 +896,7 @@ DoProbe(struct ubik_server *server) break; } } - assert(i); /* at least one interface address for this server */ + osi_Assert(i); /* at least one interface address for this server */ #ifdef AFS_PTHREAD_ENV DBRELE(ubik_dbase); diff --git a/src/ubik/ubik.c b/src/ubik/ubik.c index 4b608c9cd..aa9d62f41 100644 --- a/src/ubik/ubik.c +++ b/src/ubik/ubik.c @@ -491,7 +491,7 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, memset(&tdb->version, 0, sizeof(struct ubik_version)); memset(&tdb->cachedVersion, 0, sizeof(struct ubik_version)); #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&tdb->versionLock, NULL) == 0); + MUTEX_INIT(&tdb->versionLock, "version lock", MUTEX_DEFAULT, 0); #else Lock_Init(&tdb->versionLock); #endif @@ -512,8 +512,8 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, ubik_dbase = tdb; /* for now, only one db per server; can fix later when we have names for the other dbases */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_init(&tdb->version_cond, NULL) == 0); - assert(pthread_cond_init(&tdb->flags_cond, NULL) == 0); + CV_INIT(&tdb->version_cond, "version", CV_DEFAULT, 0); + CV_INIT(&tdb->flags_cond, "flags", CV_DEFAULT, 0); #endif /* AFS_PTHREAD_ENV */ /* initialize RX */ @@ -577,11 +577,11 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, */ #ifdef AFS_PTHREAD_ENV /* do assert stuff */ - assert(pthread_attr_init(&rxServer_tattr) == 0); - assert(pthread_attr_setdetachstate(&rxServer_tattr, PTHREAD_CREATE_DETACHED) == 0); -/* assert(pthread_attr_setstacksize(&rxServer_tattr, rx_stackSize) == 0); */ + osi_Assert(pthread_attr_init(&rxServer_tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&rxServer_tattr, PTHREAD_CREATE_DETACHED) == 0); +/* osi_Assert(pthread_attr_setstacksize(&rxServer_tattr, rx_stackSize) == 0); */ - assert(pthread_create(&rxServerThread, &rxServer_tattr, (void *)rx_ServerProc, NULL) == 0); + osi_Assert(pthread_create(&rxServerThread, &rxServer_tattr, (void *)rx_ServerProc, NULL) == 0); #else LWP_CreateProcess(rx_ServerProc, rx_stackSize, RX_PROCESS_PRIORITY, NULL, "rx_ServerProc", &junk); @@ -604,12 +604,12 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, /* now start up async processes */ #ifdef AFS_PTHREAD_ENV /* do assert stuff */ - assert(pthread_attr_init(&ubeacon_Interact_tattr) == 0); - assert(pthread_attr_setdetachstate(&ubeacon_Interact_tattr, PTHREAD_CREATE_DETACHED) == 0); -/* assert(pthread_attr_setstacksize(&ubeacon_Interact_tattr, 16384) == 0); */ + osi_Assert(pthread_attr_init(&ubeacon_Interact_tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&ubeacon_Interact_tattr, PTHREAD_CREATE_DETACHED) == 0); +/* osi_Assert(pthread_attr_setstacksize(&ubeacon_Interact_tattr, 16384) == 0); */ /* need another attr set here for priority??? - klm */ - assert(pthread_create(&ubeacon_InteractThread, &ubeacon_Interact_tattr, + osi_Assert(pthread_create(&ubeacon_InteractThread, &ubeacon_Interact_tattr, (void *)ubeacon_Interact, NULL) == 0); #else code = LWP_CreateProcess(ubeacon_Interact, 16384 /*8192 */ , @@ -621,12 +621,12 @@ ubik_ServerInitCommon(afs_uint32 myHost, short myPort, #ifdef AFS_PTHREAD_ENV /* do assert stuff */ - assert(pthread_attr_init(&urecovery_Interact_tattr) == 0); - assert(pthread_attr_setdetachstate(&urecovery_Interact_tattr, PTHREAD_CREATE_DETACHED) == 0); -/* assert(pthread_attr_setstacksize(&urecovery_Interact_tattr, 16384) == 0); */ + osi_Assert(pthread_attr_init(&urecovery_Interact_tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&urecovery_Interact_tattr, PTHREAD_CREATE_DETACHED) == 0); +/* osi_Assert(pthread_attr_setstacksize(&urecovery_Interact_tattr, 16384) == 0); */ /* need another attr set here for priority??? - klm */ - assert(pthread_create(&urecovery_InteractThread, &urecovery_Interact_tattr, + osi_Assert(pthread_create(&urecovery_InteractThread, &urecovery_Interact_tattr, (void *)urecovery_Interact, NULL) == 0); return 0; /* is this correct? - klm */ @@ -752,7 +752,7 @@ BeginTrans(struct ubik_dbase *dbase, afs_int32 transMode, /* if we're writing already, wait */ while (dbase->flags & DBWRITING) { #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&dbase->flags_cond, &dbase->versionLock) == 0); + CV_WAIT(&dbase->flags_cond, &dbase->versionLock); #else DBRELE(dbase); LWP_WaitProcess(&dbase->flags); @@ -1375,7 +1375,7 @@ ubik_WaitVersion(struct ubik_dbase *adatabase, return 0; } #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_wait(&adatabase->version_cond, &adatabase->versionLock) == 0); + CV_WAIT(&adatabase->version_cond, &adatabase->versionLock); #else DBRELE(adatabase); LWP_WaitProcess(&adatabase->version); /* same vers, just wait */ diff --git a/src/ubik/ubik.p.h b/src/ubik/ubik.p.h index 6e606a7df..ebe209af6 100644 --- a/src/ubik/ubik.p.h +++ b/src/ubik/ubik.p.h @@ -51,9 +51,9 @@ #define CFLastFailed 1 /*!< last call failed to this guy (to detect down hosts) */ /*\}*/ +#include #ifdef AFS_PTHREAD_ENV #include -#include #else #include #endif @@ -72,8 +72,8 @@ struct ubik_client { }; #ifdef AFS_PTHREAD_ENV -#define LOCK_UBIK_CLIENT(client) assert(pthread_mutex_lock(&client->cm)==0) -#define UNLOCK_UBIK_CLIENT(client) assert(pthread_mutex_unlock(&client->cm)==0) +#define LOCK_UBIK_CLIENT(client) MUTEX_ENTER(&client->cm) +#define UNLOCK_UBIK_CLIENT(client) MUTEX_EXIT(&client->cm) #else #define LOCK_UBIK_CLIENT(client) #define UNLOCK_UBIK_CLIENT(client) @@ -301,8 +301,8 @@ struct ubik_server { /*! \name hold and release functions on a database */ #ifdef AFS_PTHREAD_ENV -# define DBHOLD(a) assert(pthread_mutex_lock(&((a)->versionLock)) == 0) -# define DBRELE(a) assert(pthread_mutex_unlock(&((a)->versionLock)) == 0) +# define DBHOLD(a) MUTEX_ENTER(&((a)->versionLock)) +# define DBRELE(a) MUTEX_EXIT(&((a)->versionLock)) #else /* !AFS_PTHREAD_ENV */ # define DBHOLD(a) ObtainWriteLock(&((a)->versionLock)) # define DBRELE(a) ReleaseWriteLock(&((a)->versionLock)) diff --git a/src/ubik/ubikclient.c b/src/ubik/ubikclient.c index f649a2039..e6c9de665 100644 --- a/src/ubik/ubikclient.c +++ b/src/ubik/ubikclient.c @@ -94,9 +94,9 @@ ubik_ParseClientList(int argc, char **argv, afs_uint32 * aothers) return 0; } +#include #ifdef AFS_PTHREAD_ENV #include -#include static pthread_once_t random_once = PTHREAD_ONCE_INIT; static int called_afs_random_once; @@ -105,7 +105,7 @@ static pthread_key_t random_number_key; static void afs_random_once(void) { - assert(pthread_key_create(&random_number_key, NULL) == 0); + osi_Assert(pthread_key_create(&random_number_key, NULL) == 0); called_afs_random_once = 1; } @@ -333,15 +333,16 @@ ubik_RefreshConn(struct rx_connection *tc) pthread_once_t ubik_client_once = PTHREAD_ONCE_INIT; pthread_mutex_t ubik_client_mutex; -#define LOCK_UCLNT_CACHE \ - assert(pthread_once(&ubik_client_once, ubik_client_init_mutex) == 0 && \ - pthread_mutex_lock(&ubik_client_mutex)==0) -#define UNLOCK_UCLNT_CACHE assert(pthread_mutex_unlock(&ubik_client_mutex)==0) +#define LOCK_UCLNT_CACHE do { \ + osi_Assert(pthread_once(&ubik_client_once, ubik_client_init_mutex) == 0); \ + MUTEX_ENTER(&ubik_client_mutex); \ + } while (0) +#define UNLOCK_UCLNT_CACHE MUTEX_EXIT(&ubik_client_mutex) void ubik_client_init_mutex(void) { - assert(pthread_mutex_init(&ubik_client_mutex, NULL) == 0); + MUTEX_INIT(&ubik_client_mutex, "client init", MUTEX_DEFAULT, 0); } #else diff --git a/src/util/Makefile.in b/src/util/Makefile.in index 839c067b3..8f2da1f7c 100644 --- a/src/util/Makefile.in +++ b/src/util/Makefile.in @@ -43,8 +43,7 @@ includes = \ ${TOP_INCDIR}/afs/work_queue.h \ ${TOP_INCDIR}/afs/work_queue_types.h \ ${TOP_INCDIR}/afs/thread_pool.h \ - ${TOP_INCDIR}/afs/thread_pool_types.h \ - ${TOP_INCDIR}/potpourri.h + ${TOP_INCDIR}/afs/thread_pool_types.h all: ${includes} \ ${TOP_LIBDIR}/util.a \ @@ -116,9 +115,6 @@ ${TOP_INCDIR}/afs/thread_pool.h: ${srcdir}/thread_pool.h ${TOP_INCDIR}/afs/thread_pool_types.h: ${srcdir}/thread_pool_types.h ${INSTALL_DATA} $? $@ -${TOP_INCDIR}/potpourri.h: ${srcdir}/potpourri.h - ${INSTALL_DATA} $? $@ - ${TOP_LIBDIR}/util.a: util.a ${INSTALL_DATA} $? $@ @@ -193,7 +189,6 @@ install: dirpath.h util.a sys ${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DESTDIR}${includedir}/afs/work_queue_types.h ${INSTALL_DATA} ${srcdir}/thread_pool.h ${DESTDIR}${includedir}/afs/thread_pool.h ${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DESTDIR}${includedir}/afs/thread_pool_types.h - ${INSTALL_DATA} ${srcdir}/potpourri.h ${DESTDIR}${includedir}/potpourri.h ${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/util.a ${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/libafsutil.a ${INSTALL_PROGRAM} sys ${DESTDIR}${bindir}/sys @@ -222,7 +217,6 @@ dest: dirpath.h util.a sys ${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DEST}/include/afs/work_queue_types.h ${INSTALL_DATA} ${srcdir}/thread_pool.h ${DEST}/include/afs/thread_pool.h ${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DEST}/include/afs/thread_pool_types.h - ${INSTALL_DATA} ${srcdir}/potpourri.h ${DEST}/include/potpourri.h ${INSTALL_DATA} util.a ${DEST}/lib/afs/util.a ${INSTALL_DATA} util.a ${DEST}/lib/afs/libafsutil.a ${INSTALL_PROGRAM} sys ${DEST}/bin/sys diff --git a/src/util/netutils.c b/src/util/netutils.c index 7dc2ac9b3..4f47f456b 100644 --- a/src/util/netutils.c +++ b/src/util/netutils.c @@ -42,11 +42,7 @@ #include -#ifdef AFS_PTHREAD_ENV -#include -#else #include "afs_assert.h" -#endif #include "afsutil.h" #include @@ -144,12 +140,12 @@ parseNetRestrictFile_int(afs_uint32 outAddrs[], afs_uint32 * mask, afs_uint32 i, neaddrs, nOutaddrs; afs_uint32 addr, eAddrs[MAXIPADDRS], eMask[MAXIPADDRS], eMtu[MAXIPADDRS]; - assert(outAddrs); - assert(reason); - assert(fileName); - assert(nAddrs); + osi_Assert(outAddrs); + osi_Assert(reason); + osi_Assert(fileName); + osi_Assert(nAddrs); if (mask) - assert(mtu); + osi_Assert(mtu); /* Initialize */ *nAddrs = 0; @@ -265,11 +261,11 @@ ParseNetInfoFile_int(afs_uint32 * final, afs_uint32 * mask, afs_uint32 * mtu, int lineNo = 0; int l; - assert(fileName); - assert(final); - assert(mask); - assert(mtu); - assert(reason); + osi_Assert(fileName); + osi_Assert(final); + osi_Assert(mask); + osi_Assert(mtu); + osi_Assert(reason); /* get all network interfaces from the kernel */ existNu = @@ -395,12 +391,12 @@ filterAddrs(afs_uint32 addr1[], afs_uint32 addr2[], afs_uint32 mask1[], afs_uint32 tmtu[MAXIPADDRS]; int count = 0, i = 0, j = 0, found = 0; - assert(addr1); - assert(addr2); - assert(mask1); - assert(mask2); - assert(mtu1); - assert(mtu2); + osi_Assert(addr1); + osi_Assert(addr2); + osi_Assert(mask1); + osi_Assert(mask2); + osi_Assert(mtu1); + osi_Assert(mtu2); for (i = 0; i < n1; i++) { found = 0; diff --git a/src/util/potpourri.h b/src/util/potpourri.h deleted file mode 100644 index d60b5198a..000000000 --- a/src/util/potpourri.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2000, International Business Machines Corporation and others. - * All Rights Reserved. - * - * This software has been released under the terms of the IBM Public - * License. For details, see the LICENSE file in the top-level source - * directory or online at http://www.openafs.org/dl/license10.html - */ - -/* Standard Preamble for .h files - -Abstract: Contains miscellaneous general-purpose macros. - -*/ - -#define MAXSELECT 20 /* Max no. of file desc. to be checked in select() calls */ - -/*------------------------------------------------------------*/ -#define IN /* Input parameter */ -#define OUT /* Output parameter */ -#define INOUT /* Obvious */ -/*------------------------------------------------------------*/ - - -/* Ha, ha!! I did not realize C has a builtin XOR operator! */ -#define XOR(a,b) (unsigned char) (((a&~b)|(~a&b)) & 0377) /* NOTE: a and b should be unsigned char */ - - -/* Conditional debugging output macros */ - -#ifndef NOSAY -#define say(when, what, how)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf how;fflush(stdout);}\ - else -#else -#define say(when, what, how) /* null macro; BEWARE: avoid side effects in say() */ -#endif - -/* the ones below are obsolete and are here for upward compatibility only */ -#define say0(when, what, how)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how);fflush(stdout);} -#define say1(when, what, how, x1)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1); fflush(stdout);} -#define say2(when, what, how, x1, x2)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2); fflush(stdout);} -#define say3(when, what, how, x1, x2, x3)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3); fflush(stdout);} -#define say4(when, what, how, x1, x2, x3, x4)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4); fflush(stdout);} -#define say5(when, what, how, x1, x2, x3, x4, x5)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5); fflush(stdout);} -#define say6(when, what, how, x1, x2, x3, x4, x5, x6)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6); fflush(stdout);} -#define say7(when, what, how, x1, x2, x3, x4, x5, x6, x7)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7); fflush(stdout);} -#define say8(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7, x8); fflush(stdout);} -#define say9(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9); fflush(stdout);} -#define say10(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); fflush(stdout);} -#define say11(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11); fflush(stdout);} -#define say12(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)\ - if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\ - printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12); fflush(stdout);} - - -/* length-checked string routines: return 0 on success, -1 on length violation */ -#define SafeStrCat(dest,src,totalspace)\ - ((strlen(dest)+strlen(src) < totalspace) ? strcat(dest,src),0 : -1) - -#define SafeStrCpy(dest,src,totalspace)\ - ((strlen(src) < totalspace) ? strcpy(dest,src),0 : -1) - - -/* The following definition of assert is slightly modified from the standard 4.2BSD one. - This prints out the failing assertion, in addition to the file and line number. - BEWARE: avoid quotes in the assertion!! - Also beware: you cannot make the NOASSERT case a null macro, because of side effects */ - -#undef assert -#ifndef NOASSERT -#define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);fprintf(stderr, "\t%s\n", # ex); abort();}} -#else -#define assert(ex) {if (!(ex)) abort();} -#endif - - -#define TRUE 1 -#define FALSE 0 - -#ifdef LWP -#define SystemError(y) (fprintf(stderr, "%d(%s): ", getpid(), LWP_ActiveProcess->name), perror(y)) -#else -#define SystemError(y) (fprintf(stderr, "%d: ", getpid()), perror(y)) -#endif diff --git a/src/util/pthread_glock.h b/src/util/pthread_glock.h index 19d6891bf..c6414c96c 100644 --- a/src/util/pthread_glock.h +++ b/src/util/pthread_glock.h @@ -12,7 +12,7 @@ #ifdef AFS_PTHREAD_ENV #include -#include +#include typedef struct { pthread_mutex_t mut; @@ -35,10 +35,10 @@ extern int pthread_recursive_mutex_lock(pthread_recursive_mutex_p); extern int pthread_recursive_mutex_unlock(pthread_recursive_mutex_p); #define LOCK_GLOBAL_MUTEX \ - assert(pthread_recursive_mutex_lock(&grmutex)==0) + osi_Assert(pthread_recursive_mutex_lock(&grmutex)==0) #define UNLOCK_GLOBAL_MUTEX \ - assert(pthread_recursive_mutex_unlock(&grmutex)==0) + osi_Assert(pthread_recursive_mutex_unlock(&grmutex)==0) #else diff --git a/src/util/serverLog.c b/src/util/serverLog.c index 1fd7c9a5a..773080785 100644 --- a/src/util/serverLog.c +++ b/src/util/serverLog.c @@ -45,11 +45,13 @@ # include #endif #if defined(AFS_PTHREAD_ENV) -#include +#include +/* can't include rx when we are libutil; it's too early */ +#include #include static pthread_mutex_t serverLogMutex; -#define LOCK_SERVERLOG() assert(pthread_mutex_lock(&serverLogMutex)==0) -#define UNLOCK_SERVERLOG() assert(pthread_mutex_unlock(&serverLogMutex)==0) +#define LOCK_SERVERLOG() MUTEX_ENTER(&serverLogMutex) +#define UNLOCK_SERVERLOG() MUTEX_EXIT(&serverLogMutex) #ifdef AFS_NT40_ENV #define NULLDEV "NUL" @@ -353,7 +355,7 @@ OpenLog(const char *fileName) #endif #if defined(AFS_PTHREAD_ENV) - assert(pthread_mutex_init(&serverLogMutex, NULL) == 0); + MUTEX_INIT(&serverLogMutex, "serverlog", MUTEX_DEFAULT, 0); #endif /* AFS_PTHREAD_ENV */ serverLogFD = tempfd; diff --git a/src/util/thread_pool.c b/src/util/thread_pool.c index 070ec018f..ab16080b6 100644 --- a/src/util/thread_pool.c +++ b/src/util/thread_pool.c @@ -150,24 +150,24 @@ _afs_tp_worker_run(void * rock) struct afs_thread_pool * pool = worker->pool; /* register worker with pool */ - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); queue_Append(&pool->thread_list, worker); pool->nthreads++; - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); /* call high-level entry point */ worker->ret = (*pool->entry)(pool, worker, pool->work_queue, pool->rock); /* adjust pool live thread count */ - assert(pthread_mutex_lock(&pool->lock) == 0); - assert(pool->nthreads); + MUTEX_ENTER(&pool->lock); + osi_Assert(pool->nthreads); queue_Remove(worker); pool->nthreads--; if (!pool->nthreads) { - assert(pthread_cond_broadcast(&pool->shutdown_cv) == 0); + CV_BROADCAST(&pool->shutdown_cv); pool->state = AFS_TP_STATE_STOPPED; } - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); _afs_tp_worker_free(worker); @@ -220,8 +220,8 @@ _afs_tp_worker_start(struct afs_thread_pool * pool, worker->pool = pool; worker->req_shutdown = 0; - assert(pthread_attr_init(&attrs) == 0); - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_attr_init(&attrs) == 0); + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); ret = pthread_create(&worker->tid, &attrs, &_afs_tp_worker_run, worker); @@ -252,8 +252,8 @@ afs_tp_create(struct afs_thread_pool ** pool_out, } pool = *pool_out; - assert(pthread_mutex_init(&pool->lock, NULL) == 0); - assert(pthread_cond_init(&pool->shutdown_cv, NULL) == 0); + MUTEX_INIT(&pool->lock, "pool", MUTEX_DEFAULT, 0); + CV_INIT(&pool->shutdown_cv, "pool shutdown", CV_DEFAULT, 0); queue_Init(&pool->thread_list); pool->work_queue = queue; pool->entry = &_afs_tp_worker_default; @@ -280,7 +280,7 @@ afs_tp_destroy(struct afs_thread_pool * pool) { int ret = 0; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); switch (pool->state) { case AFS_TP_STATE_INIT: case AFS_TP_STATE_STOPPED: @@ -289,7 +289,7 @@ afs_tp_destroy(struct afs_thread_pool * pool) default: ret = AFS_TP_ERROR; - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); } return ret; @@ -311,13 +311,13 @@ afs_tp_set_threads(struct afs_thread_pool *pool, { int ret = 0; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); if (pool->state != AFS_TP_STATE_INIT) { ret = AFS_TP_ERROR; } else { pool->max_threads = threads; } - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); return ret; } @@ -340,14 +340,14 @@ afs_tp_set_entry(struct afs_thread_pool * pool, { int ret = 0; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); if (pool->state != AFS_TP_STATE_INIT) { ret = AFS_TP_ERROR; } else { pool->entry = entry; pool->rock = rock; } - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); return ret; } @@ -368,13 +368,13 @@ afs_tp_start(struct afs_thread_pool * pool) struct afs_thread_pool_worker * worker; afs_uint32 i; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); if (pool->state != AFS_TP_STATE_INIT) { ret = AFS_TP_ERROR; goto done_sync; } pool->state = AFS_TP_STATE_STARTING; - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); for (i = 0; i < pool->max_threads; i++) { code = _afs_tp_worker_start(pool, &worker); @@ -383,10 +383,10 @@ afs_tp_start(struct afs_thread_pool * pool) } } - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); pool->state = AFS_TP_STATE_RUNNING; done_sync: - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); return ret; } @@ -407,7 +407,7 @@ afs_tp_shutdown(struct afs_thread_pool * pool, int ret = 0; struct afs_thread_pool_worker * worker, *nn; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); if (pool->state == AFS_TP_STATE_STOPPED || pool->state == AFS_TP_STATE_STOPPING) { goto done_stopped; @@ -425,23 +425,22 @@ afs_tp_shutdown(struct afs_thread_pool * pool, pool->state = AFS_TP_STATE_STOPPED; } /* need to drop lock to get a membar here */ - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); ret = afs_wq_shutdown(pool->work_queue); if (ret) { goto error; } - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); done_stopped: if (block) { while (pool->nthreads) { - assert(pthread_cond_wait(&pool->shutdown_cv, - &pool->lock) == 0); + CV_WAIT(&pool->shutdown_cv, &pool->lock); } } done_sync: - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); error: return ret; @@ -461,9 +460,9 @@ afs_tp_is_online(struct afs_thread_pool * pool) { int ret; - assert(pthread_mutex_lock(&pool->lock) == 0); + MUTEX_ENTER(&pool->lock); ret = (pool->state == AFS_TP_STATE_RUNNING); - assert(pthread_mutex_unlock(&pool->lock) == 0); + MUTEX_EXIT(&pool->lock); return ret; } diff --git a/src/util/work_queue.c b/src/util/work_queue.c index 771b4dc75..cbda5cc0d 100644 --- a/src/util/work_queue.c +++ b/src/util/work_queue.c @@ -103,7 +103,7 @@ _afs_wq_node_state_change(struct afs_work_queue_node * node, old_state = node->state; node->state = new_state; - assert(pthread_cond_broadcast(&node->state_cv) == 0); + CV_BROADCAST(&node->state_cv); return old_state; } @@ -124,8 +124,7 @@ static int _afs_wq_node_state_wait_busy(struct afs_work_queue_node * node) { while (node->state == AFS_WQ_NODE_STATE_BUSY) { - assert(pthread_cond_wait(&node->state_cv, - &node->lock) == 0); + CV_WAIT(&node->state_cv, &node->lock); } return 0; @@ -192,14 +191,14 @@ _afs_wq_node_multilock(struct afs_work_queue_node_multilock * ml) } } - code = pthread_mutex_trylock(&ml->nodes[1].node->lock); - if (!code) { + code = MUTEX_TRYENTER(&ml->nodes[1].node->lock); + if (code) { /* success */ goto done; } /* setup for main loop */ - assert(pthread_mutex_unlock(&ml->nodes[0].node->lock) == 0); + MUTEX_EXIT(&ml->nodes[0].node->lock); } /* @@ -211,16 +210,16 @@ _afs_wq_node_multilock(struct afs_work_queue_node_multilock * ml) delay.tv_nsec = 500 + rand() % 500; while (1) { - assert(pthread_mutex_lock(&ml->nodes[first].node->lock) == 0); + MUTEX_ENTER(&ml->nodes[first].node->lock); if ((first != 0) || !ml->nodes[0].busy_held) { ret = _afs_wq_node_state_wait_busy(ml->nodes[first].node); if (ret) { /* cleanup */ if (!ml->nodes[0].lock_held || first) { - assert(pthread_mutex_unlock(&ml->nodes[first].node->lock) == 0); + MUTEX_EXIT(&ml->nodes[first].node->lock); if (ml->nodes[0].lock_held) { /* on error, return with locks in same state as before call */ - assert(pthread_mutex_lock(&ml->nodes[0].node->lock) == 0); + MUTEX_ENTER(&ml->nodes[0].node->lock); } } goto error; @@ -232,14 +231,14 @@ _afs_wq_node_multilock(struct afs_work_queue_node_multilock * ml) * a non-blocking state check. if we meet any contention, * we must drop back and start again. */ - code = pthread_mutex_trylock(&ml->nodes[second].node->lock); - if (!code) { + code = MUTEX_TRYENTER(&ml->nodes[second].node->lock); + if (code) { if (((second == 0) && (ml->nodes[0].busy_held)) || !_afs_wq_node_state_is_busy(ml->nodes[second].node)) { /* success */ break; } else { - assert(pthread_mutex_unlock(&ml->nodes[second].node->lock) == 0); + MUTEX_EXIT(&ml->nodes[second].node->lock); } } @@ -249,7 +248,7 @@ _afs_wq_node_multilock(struct afs_work_queue_node_multilock * ml) * drop locks, use exponential backoff, * try acquiring in the opposite order */ - assert(pthread_mutex_unlock(&ml->nodes[first].node->lock) == 0); + MUTEX_EXIT(&ml->nodes[first].node->lock); nanosleep(&delay, NULL); if (delay.tv_nsec <= 65536000) { /* max backoff delay of ~131ms */ delay.tv_nsec <<= 1; @@ -280,8 +279,8 @@ _afs_wq_node_list_init(struct afs_work_queue_node_list * list, afs_wq_node_list_id_t id) { queue_Init(&list->list); - assert(pthread_mutex_init(&list->lock, NULL) == 0); - assert(pthread_cond_init(&list->cv, NULL) == 0); + MUTEX_INIT(&list->lock, "list", MUTEX_DEFAULT, 0); + CV_INIT(&list->cv, "list", CV_DEFAULT, 0); list->qidx = id; list->shutdown = 0; @@ -309,8 +308,8 @@ _afs_wq_node_list_destroy(struct afs_work_queue_node_list * list) goto error; } - assert(pthread_mutex_destroy(&list->lock) == 0); - assert(pthread_cond_destroy(&list->cv) == 0); + MUTEX_DESTROY(&list->lock); + CV_DESTROY(&list->cv); error: return ret; @@ -332,7 +331,7 @@ _afs_wq_node_list_shutdown(struct afs_work_queue_node_list * list) int ret = 0; struct afs_work_queue_node *node, *nnode; - assert(pthread_mutex_lock(&list->lock) == 0); + MUTEX_ENTER(&list->lock); list->shutdown = 1; for (queue_Scan(&list->list, node, nnode, afs_work_queue_node)) { @@ -350,8 +349,8 @@ _afs_wq_node_list_shutdown(struct afs_work_queue_node_list * list) } } - assert(pthread_cond_broadcast(&list->cv) == 0); - assert(pthread_mutex_unlock(&list->lock) == 0); + CV_BROADCAST(&list->cv); + MUTEX_EXIT(&list->lock); return ret; } @@ -392,16 +391,16 @@ _afs_wq_node_list_enqueue(struct afs_work_queue_node_list * list, } /* deal with lock inversion */ - code = pthread_mutex_trylock(&list->lock); - if (code) { + code = MUTEX_TRYENTER(&list->lock); + if (!code) { /* contended */ _afs_wq_node_state_change(node, AFS_WQ_NODE_STATE_BUSY); - assert(pthread_mutex_unlock(&node->lock) == 0); - assert(pthread_mutex_lock(&list->lock) == 0); - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); + MUTEX_ENTER(&list->lock); + MUTEX_ENTER(&node->lock); /* assert state of the world (we set busy, so this should never happen) */ - assert(queue_IsNotOnQueue(node)); + osi_Assert(queue_IsNotOnQueue(node)); } if (list->shutdown) { @@ -409,18 +408,18 @@ _afs_wq_node_list_enqueue(struct afs_work_queue_node_list * list, goto error_unlock; } - assert(node->qidx == AFS_WQ_NODE_LIST_NONE); + osi_Assert(node->qidx == AFS_WQ_NODE_LIST_NONE); if (queue_IsEmpty(&list->list)) { /* wakeup a dequeue thread */ - assert(pthread_cond_signal(&list->cv) == 0); + CV_SIGNAL(&list->cv); } queue_Append(&list->list, node); node->qidx = list->qidx; _afs_wq_node_state_change(node, state); error_unlock: - assert(pthread_mutex_unlock(&node->lock) == 0); - assert(pthread_mutex_unlock(&list->lock) == 0); + MUTEX_EXIT(&node->lock); + MUTEX_EXIT(&list->lock); error: return ret; @@ -452,7 +451,7 @@ _afs_wq_node_list_dequeue(struct afs_work_queue_node_list * list, int ret = 0; struct afs_work_queue_node * node; - assert(pthread_mutex_lock(&list->lock) == 0); + MUTEX_ENTER(&list->lock); if (list->shutdown) { *node_out = NULL; @@ -472,19 +471,18 @@ _afs_wq_node_list_dequeue(struct afs_work_queue_node_list * list, ret = EINTR; goto done_sync; } - assert(pthread_cond_wait(&list->cv, - &list->lock) == 0); + CV_WAIT(&list->cv, &list->lock); } *node_out = node = queue_First(&list->list, afs_work_queue_node); - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); queue_Remove(node); node->qidx = AFS_WQ_NODE_LIST_NONE; _afs_wq_node_state_change(node, state); done_sync: - assert(pthread_mutex_unlock(&list->lock) == 0); + MUTEX_EXIT(&list->lock); return ret; } @@ -541,14 +539,14 @@ _afs_wq_node_list_remove(struct afs_work_queue_node * node, } if (list) { - code = pthread_mutex_trylock(&list->lock); - if (code) { + code = MUTEX_TRYENTER(&list->lock); + if (!code) { /* contended */ _afs_wq_node_state_change(node, AFS_WQ_NODE_STATE_BUSY); - assert(pthread_mutex_unlock(&node->lock) == 0); - assert(pthread_mutex_lock(&list->lock) == 0); - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); + MUTEX_ENTER(&list->lock); + MUTEX_ENTER(&node->lock); if (node->qidx == AFS_WQ_NODE_LIST_NONE) { /* raced */ @@ -562,7 +560,7 @@ _afs_wq_node_list_remove(struct afs_work_queue_node * node, _afs_wq_node_state_change(node, next_state); done_sync: - assert(pthread_mutex_unlock(&list->lock) == 0); + MUTEX_EXIT(&list->lock); } error: @@ -700,7 +698,7 @@ _afs_wq_node_free_deps(struct afs_work_queue_node *parent) nd, afs_work_queue_dep_node)) { - assert(pthread_mutex_lock(&dep->child->lock) == 0); + MUTEX_ENTER(&dep->child->lock); node_unlock = dep->child; /* We need to get a ref on child here, since _afs_wq_dep_unlink_r may @@ -719,7 +717,7 @@ _afs_wq_node_free_deps(struct afs_work_queue_node *parent) if (node_put) { _afs_wq_node_put_r(node_put, 1); } else if (node_unlock) { - assert(pthread_mutex_unlock(&node_unlock->lock) == 0); + MUTEX_EXIT(&node_unlock->lock); } node_put = node_unlock = NULL; @@ -803,7 +801,7 @@ _afs_wq_dep_propagate(struct afs_work_queue_node * parent, /* skip unscheduled nodes */ if (dep->child->queue == NULL) { - assert(pthread_mutex_unlock(&dep->child->lock) == 0); + MUTEX_EXIT(&dep->child->lock); continue; } @@ -830,7 +828,7 @@ _afs_wq_dep_propagate(struct afs_work_queue_node * parent, ret = _afs_wq_node_list_remove(dep->child, AFS_WQ_NODE_STATE_BUSY); if (ret) { - assert(pthread_mutex_unlock(&dep->child->lock) == 0); + MUTEX_EXIT(&dep->child->lock); goto error; } @@ -838,11 +836,11 @@ _afs_wq_dep_propagate(struct afs_work_queue_node * parent, dep->child, cns); if (ret) { - assert(pthread_mutex_unlock(&dep->child->lock) == 0); + MUTEX_EXIT(&dep->child->lock); goto error; } } - assert(pthread_mutex_unlock(&dep->child->lock) == 0); + MUTEX_EXIT(&dep->child->lock); } error: @@ -859,14 +857,14 @@ _afs_wq_dep_propagate(struct afs_work_queue_node * parent, static void _afs_wq_dec_running_count(struct afs_work_queue *queue) { - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); queue->running_count--; if (queue->shutdown && queue->running_count == 0) { /* if we've shut down, someone may be waiting for the running count * to drop to 0 */ - assert(pthread_cond_broadcast(&queue->running_cv) == 0); + CV_BROADCAST(&queue->running_cv); } - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); } /** @@ -901,13 +899,13 @@ _afs_wq_do(struct afs_work_queue * queue, * _afs_wq_node_list_dequeue should return immediately with EINTR, * in which case we'll dec running_count, so it's as if we never inc'd it * in the first place. */ - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); if (queue->shutdown) { - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); return EINTR; } queue->running_count++; - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); ret = _afs_wq_node_list_dequeue(&queue->ready_list, &node, @@ -923,9 +921,9 @@ _afs_wq_do(struct afs_work_queue * queue, detached = node->detached; if (cbf != NULL) { - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); code = (*cbf)(queue, node, queue->rock, node_rock, rock); - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); if (code == 0) { next_state = AFS_WQ_NODE_STATE_DONE; ql = &queue->done_list; @@ -957,23 +955,23 @@ _afs_wq_do(struct afs_work_queue * queue, if ((next_state == AFS_WQ_NODE_STATE_DONE) || (next_state == AFS_WQ_NODE_STATE_ERROR)) { - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); if (queue->drain && queue->pend_count == queue->opts.pend_lothresh) { /* signal other threads if we're about to below the low * pending-tasks threshold */ queue->drain = 0; - assert(pthread_cond_signal(&queue->pend_cv) == 0); + CV_SIGNAL(&queue->pend_cv); } if (queue->pend_count == 1) { /* signal other threads if we're about to become 'empty' */ - assert(pthread_cond_broadcast(&queue->empty_cv) == 0); + CV_BROADCAST(&queue->empty_cv); } queue->pend_count--; - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); } ret = _afs_wq_node_state_wait_busy(node); @@ -1084,10 +1082,10 @@ afs_wq_create(struct afs_work_queue ** queue_out, queue->pend_count = 0; queue->running_count = 0; - assert(pthread_mutex_init(&queue->lock, NULL) == 0); - assert(pthread_cond_init(&queue->pend_cv, NULL) == 0); - assert(pthread_cond_init(&queue->empty_cv, NULL) == 0); - assert(pthread_cond_init(&queue->running_cv, NULL) == 0); + MUTEX_INIT(&queue->lock, "queue", MUTEX_DEFAULT, 0); + CV_INIT(&queue->pend_cv, "queue pending", CV_DEFAULT, 0); + CV_INIT(&queue->empty_cv, "queue empty", CV_DEFAULT, 0); + CV_INIT(&queue->running_cv, "queue running", CV_DEFAULT, 0); error: return ret; @@ -1141,10 +1139,10 @@ afs_wq_shutdown(struct afs_work_queue * queue) { int ret = 0; - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); if (queue->shutdown) { /* already shutdown, do nothing */ - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); goto error; } queue->shutdown = 1; @@ -1167,9 +1165,9 @@ afs_wq_shutdown(struct afs_work_queue * queue) /* signal everyone that could be waiting, since these conditions will * generally fail to signal on their own if we're shutdown, since no * progress is being made */ - assert(pthread_cond_broadcast(&queue->pend_cv) == 0); - assert(pthread_cond_broadcast(&queue->empty_cv) == 0); - assert(pthread_mutex_unlock(&queue->lock) == 0); + CV_BROADCAST(&queue->pend_cv); + CV_BROADCAST(&queue->empty_cv); + MUTEX_EXIT(&queue->lock); error: return ret; @@ -1203,8 +1201,8 @@ afs_wq_node_alloc(struct afs_work_queue_node ** node_out) node->refcount = 1; node->block_count = 0; node->error_count = 0; - pthread_mutex_init(&node->lock, NULL); - pthread_cond_init(&node->state_cv, NULL); + MUTEX_INIT(&node->lock, "node", MUTEX_DEFAULT, 0); + CV_INIT(&node->state_cv, "node state", CV_DEFAULT, 0); node->state = AFS_WQ_NODE_STATE_INIT; queue_Init(&node->dep_children); @@ -1240,8 +1238,8 @@ _afs_wq_node_free(struct afs_work_queue_node * node) goto error; } - pthread_mutex_destroy(&node->lock); - pthread_cond_destroy(&node->state_cv); + MUTEX_DESTROY(&node->lock); + CV_DESTROY(&node->state_cv); if (node->rock_dtor) { (*node->rock_dtor) (node->rock); @@ -1264,9 +1262,9 @@ _afs_wq_node_free(struct afs_work_queue_node * node) int afs_wq_node_get(struct afs_work_queue_node * node) { - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); node->refcount++; - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return 0; } @@ -1292,13 +1290,13 @@ _afs_wq_node_put_r(struct afs_work_queue_node * node, { afs_uint32 refc; - assert(node->refcount > 0); + osi_Assert(node->refcount > 0); refc = --node->refcount; if (drop) { - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); } if (!refc) { - assert(node->qidx == AFS_WQ_NODE_LIST_NONE); + osi_Assert(node->qidx == AFS_WQ_NODE_LIST_NONE); _afs_wq_node_free(node); } @@ -1318,7 +1316,7 @@ _afs_wq_node_put_r(struct afs_work_queue_node * node, int afs_wq_node_put(struct afs_work_queue_node * node) { - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); return _afs_wq_node_put_r(node, 1); } @@ -1338,11 +1336,11 @@ afs_wq_node_set_callback(struct afs_work_queue_node * node, afs_wq_callback_func_t * cbf, void * rock, afs_wq_callback_dtor_t *dtor) { - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); node->cbf = cbf; node->rock = rock; node->rock_dtor = dtor; - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return 0; } @@ -1358,9 +1356,9 @@ afs_wq_node_set_callback(struct afs_work_queue_node * node, int afs_wq_node_set_detached(struct afs_work_queue_node * node) { - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); node->detached = 1; - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return 0; } @@ -1486,8 +1484,8 @@ afs_wq_node_dep_add(struct afs_work_queue_node * child, done: if (held) { - assert(pthread_mutex_unlock(&child->lock) == 0); - assert(pthread_mutex_unlock(&parent->lock) == 0); + MUTEX_EXIT(&child->lock); + MUTEX_EXIT(&parent->lock); } return ret; @@ -1560,8 +1558,8 @@ afs_wq_node_dep_del(struct afs_work_queue_node * child, error: if (held) { - assert(pthread_mutex_unlock(&child->lock) == 0); - assert(pthread_mutex_unlock(&parent->lock) == 0); + MUTEX_EXIT(&child->lock); + MUTEX_EXIT(&parent->lock); } return ret; } @@ -1584,7 +1582,7 @@ afs_wq_node_block(struct afs_work_queue_node * node) int ret = 0; int start; - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); ret = _afs_wq_node_state_wait_busy(node); if (ret) { goto error_sync; @@ -1607,7 +1605,7 @@ afs_wq_node_block(struct afs_work_queue_node * node) } error_sync: - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return ret; } @@ -1630,7 +1628,7 @@ afs_wq_node_unblock(struct afs_work_queue_node * node) int ret = 0; int end; - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); ret = _afs_wq_node_state_wait_busy(node); if (ret) { goto error_sync; @@ -1653,7 +1651,7 @@ afs_wq_node_unblock(struct afs_work_queue_node * node) } error_sync: - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return ret; } @@ -1706,7 +1704,7 @@ afs_wq_add(struct afs_work_queue *queue, force = opts->force; retry: - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); ret = _afs_wq_node_state_wait_busy(node); if (ret) { @@ -1726,12 +1724,12 @@ afs_wq_add(struct afs_work_queue *queue, ret = 0; - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); if (queue->shutdown) { ret = EINTR; - assert(pthread_mutex_unlock(&queue->lock) == 0); - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&queue->lock); + MUTEX_EXIT(&node->lock); goto error; } @@ -1745,27 +1743,22 @@ afs_wq_add(struct afs_work_queue *queue, if (queue->drain) { if (block) { - - assert(pthread_mutex_unlock(&node->lock) == 0); - - assert(pthread_cond_wait(&queue->pend_cv, &queue->lock) == 0); + MUTEX_EXIT(&node->lock); + CV_WAIT(&queue->pend_cv, &queue->lock); if (queue->shutdown) { ret = EINTR; - } else { - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); waited_for_drain = 1; goto retry; } - } else { ret = EWOULDBLOCK; } } - } if (ret == 0) { @@ -1773,10 +1766,10 @@ afs_wq_add(struct afs_work_queue *queue, } if (waited_for_drain) { /* signal another thread that may have been waiting for drain */ - assert(pthread_cond_signal(&queue->pend_cv) == 0); + CV_SIGNAL(&queue->pend_cv); } - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); if (ret) { goto error; @@ -1858,10 +1851,10 @@ afs_wq_wait_all(struct afs_work_queue *queue) { int ret = 0; - assert(pthread_mutex_lock(&queue->lock) == 0); + MUTEX_ENTER(&queue->lock); while (queue->pend_count > 0 && !queue->shutdown) { - assert(pthread_cond_wait(&queue->empty_cv, &queue->lock) == 0); + CV_WAIT(&queue->empty_cv, &queue->lock); } if (queue->shutdown) { @@ -1869,14 +1862,14 @@ afs_wq_wait_all(struct afs_work_queue *queue) * running e.g. in the middle of their callback. ensure they have * stopped before we return. */ while (queue->running_count > 0) { - assert(pthread_cond_wait(&queue->running_cv, &queue->lock) == 0); + CV_WAIT(&queue->running_cv, &queue->lock); } ret = EINTR; goto done; } done: - assert(pthread_mutex_unlock(&queue->lock) == 0); + MUTEX_EXIT(&queue->lock); /* technically this doesn't really guarantee that the work queue is empty * after we return, but we do guarantee that it was empty at some point */ @@ -1901,7 +1894,7 @@ afs_wq_node_wait(struct afs_work_queue_node * node, { int ret = 0; - assert(pthread_mutex_lock(&node->lock) == 0); + MUTEX_ENTER(&node->lock); if (node->state == AFS_WQ_NODE_STATE_INIT) { /* not sure what to do in this case */ goto done_sync; @@ -1909,8 +1902,7 @@ afs_wq_node_wait(struct afs_work_queue_node * node, while ((node->state != AFS_WQ_NODE_STATE_DONE) && (node->state != AFS_WQ_NODE_STATE_ERROR)) { - assert(pthread_cond_wait(&node->state_cv, - &node->lock) == 0); + CV_WAIT(&node->state_cv, &node->lock); } if (retcode) { *retcode = node->retcode; @@ -1925,7 +1917,7 @@ afs_wq_node_wait(struct afs_work_queue_node * node, AFS_WQ_NODE_STATE_INIT); done_sync: - assert(pthread_mutex_unlock(&node->lock) == 0); + MUTEX_EXIT(&node->lock); return ret; } diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index 0ed08bcab..c960b66ad 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -346,7 +346,7 @@ CallPreamble(struct rx_call *acall, int activecall, code = hpr_Initialize(&uclient); if (!code) - assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); + osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); H_LOCK; #else code = pr_Initialize(2, AFSDIR_SERVER_ETC_DIRPATH, 0); @@ -493,7 +493,7 @@ CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock) errorCode = 0; *volptr = VGetVolumeNoWait(&local_errorCode, &errorCode, (afs_int32) fid->Volume); if (!errorCode) { - assert(*volptr); + osi_Assert(*volptr); break; } if ((errorCode == VOFFLINE) && (VInit < 2)) { @@ -586,7 +586,7 @@ CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock) return (errorCode); } } - assert(*volptr); + osi_Assert(*volptr); /* get the vnode */ *vptr = VGetVnode(&errorCode, *volptr, fid->Vnode, lock); @@ -594,7 +594,7 @@ CheckVnode(AFSFid * fid, Volume ** volptr, Vnode ** vptr, int lock) return (errorCode); if ((*vptr)->disk.uniquifier != fid->Unique) { VPutVnode(&fileCode, *vptr); - assert(fileCode == 0); + osi_Assert(fileCode == 0); *vptr = 0; return (VNOVNODE); /* return the right error code, at least */ } @@ -618,7 +618,7 @@ SetAccessList(Vnode ** targetptr, Volume ** volume, *ACLSize = VAclSize(*targetptr); return (0); } else { - assert(Fid != 0); + osi_Assert(Fid != 0); while (1) { VnodeId parentvnode; Error errorCode = 0; @@ -702,7 +702,7 @@ GetRights(struct client *client, struct acl_accessList *ACL, while (client->host->hostFlags & HCPS_INPROGRESS) { client->host->hostFlags |= HCPS_WAITING; /* I am waiting */ #ifdef AFS_PTHREAD_ENV - pthread_cond_wait(&client->host->cond, &host_glock_mutex); + CV_WAIT(&client->host->cond, &host_glock_mutex); #else /* AFS_PTHREAD_ENV */ if ((code = LWP_WaitProcess(&(client->host->hostFlags))) != LWP_SUCCESS) @@ -776,7 +776,7 @@ GetVolumePackage(struct rx_connection *tcon, AFSFid * Fid, Volume ** volptr, (chkforDir == MustBeDIR ? 0 : locktype))) != 0) return (errorCode); if (chkforDir == MustBeDIR) - assert((*parent) == 0); + osi_Assert((*parent) == 0); if (!(*client)) { if ((errorCode = GetClient(tcon, client)) != 0) return (errorCode); @@ -814,15 +814,15 @@ PutVolumePackage(Vnode * parentwhentargetnotdir, Vnode * targetptr, if (parentwhentargetnotdir) { VPutVnode(&fileCode, parentwhentargetnotdir); - assert(!fileCode || (fileCode == VSALVAGE)); + osi_Assert(!fileCode || (fileCode == VSALVAGE)); } if (targetptr) { VPutVnode(&fileCode, targetptr); - assert(!fileCode || (fileCode == VSALVAGE)); + osi_Assert(!fileCode || (fileCode == VSALVAGE)); } if (parentptr) { VPutVnode(&fileCode, parentptr); - assert(!fileCode || (fileCode == VSALVAGE)); + osi_Assert(!fileCode || (fileCode == VSALVAGE)); } if (volptr) { VPutVolume(volptr); @@ -1174,7 +1174,7 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) } IH_INIT(newH, V_device(volptr), V_id(volptr), ino); newFdP = IH_OPEN(newH); - assert(newFdP != NULL); + osi_Assert(newFdP != NULL); done = off; while (size > 0) { @@ -1249,11 +1249,11 @@ CopyOnWrite(Vnode * targetptr, Volume * volptr, afs_foff_t off, afs_fsize_t len) FDH_REALLYCLOSE(targFdP); rc = IH_DEC(V_linkHandle(volptr), VN_GET_INO(targetptr), V_parentId(volptr)); - assert(!rc); + osi_Assert(!rc); IH_RELEASE(targetptr->handle); rc = FDH_SYNC(newFdP); - assert(rc == 0); + osi_Assert(rc == 0); FDH_CLOSE(newFdP); targetptr->handle = newH; VN_SET_INO(targetptr, ino); @@ -1354,7 +1354,7 @@ DeleteTarget(Vnode * parentptr, Volume * volptr, Vnode ** targetptr, } else if ((*targetptr)->disk.type == vDirectory) return (EISDIR); - /*assert((*targetptr)->disk.uniquifier == fileFid->Unique); */ + /*osi_Assert((*targetptr)->disk.uniquifier == fileFid->Unique); */ /** * If the uniquifiers dont match then instead of asserting * take the volume offline and return VSALVAGE @@ -1946,21 +1946,21 @@ RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg, *name = malloc(temp); if (!*name) { ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); - assert(0); + osi_Panic("Failed malloc in RXGetVolumeStatus\n"); } strcpy(*name, V_name(volptr)); temp = strlen(V_offlineMessage(volptr)) + 1; *offMsg = malloc(temp); if (!*offMsg) { ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); - assert(0); + osi_Panic("Failed malloc in RXGetVolumeStatus\n"); } strcpy(*offMsg, V_offlineMessage(volptr)); #if OPENAFS_VOL_STATS *motd = malloc(1); if (!*motd) { ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); - assert(0); + osi_Panic("Failed malloc in RXGetVolumeStatus\n"); } strcpy(*motd, nullString); #else @@ -1968,7 +1968,7 @@ RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg, *motd = malloc(temp); if (!*motd) { ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n")); - assert(0); + osi_Panic("Failed malloc in RXGetVolumeStatus\n"); } strcpy(*motd, V_motd(volptr)); #endif /* FS_STATS_DETAILED */ @@ -2058,7 +2058,7 @@ AllocSendBuffer(void) tmp = malloc(sendBufSize); if (!tmp) { ViceLog(0, ("Failed malloc in AllocSendBuffer\n")); - assert(0); + osi_Panic("Failed malloc in AllocSendBuffer\n"); } return tmp; } @@ -2217,7 +2217,7 @@ common_FetchData64(struct rx_call *acall, struct AFSFid *Fid, if (parentwhentargetnotdir != NULL) { tparentwhentargetnotdir = *parentwhentargetnotdir; VPutVnode(&fileCode, parentwhentargetnotdir); - assert(!fileCode || (fileCode == VSALVAGE)); + osi_Assert(!fileCode || (fileCode == VSALVAGE)); parentwhentargetnotdir = NULL; } #if FS_STATS_DETAILED @@ -2429,7 +2429,7 @@ SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid, AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX); if (!AccessList->AFSOpaque_val) { ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n")); - assert(0); + osi_Panic("Failed malloc in SRXAFS_FetchACL\n"); } /* @@ -2619,14 +2619,14 @@ SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids, malloc(nfiles * sizeof(struct AFSFetchStatus)); if (!OutStats->AFSBulkStats_val) { ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n")); - assert(0); + osi_Panic("Failed malloc in SRXAFS_BulkStatus\n"); } OutStats->AFSBulkStats_len = nfiles; CallBacks->AFSCBs_val = (struct AFSCallBack *) malloc(nfiles * sizeof(struct AFSCallBack)); if (!CallBacks->AFSCBs_val) { ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n")); - assert(0); + osi_Panic("Failed malloc in SRXAFS_BulkStatus\n"); } CallBacks->AFSCBs_len = nfiles; @@ -2770,14 +2770,14 @@ SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids, malloc(nfiles * sizeof(struct AFSFetchStatus)); if (!OutStats->AFSBulkStats_val) { ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n")); - assert(0); + osi_Panic("Failed malloc in SRXAFS_FetchStatus\n"); } OutStats->AFSBulkStats_len = nfiles; CallBacks->AFSCBs_val = (struct AFSCallBack *) malloc(nfiles * sizeof(struct AFSCallBack)); if (!CallBacks->AFSCBs_val) { ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n")); - assert(0); + osi_Panic("Failed malloc in SRXAFS_FetchStatus\n"); } CallBacks->AFSCBs_len = nfiles; @@ -3048,7 +3048,7 @@ common_StoreData64(struct rx_call *acall, struct AFSFid *Fid, if (parentwhentargetnotdir != NULL) { tparentwhentargetnotdir = *parentwhentargetnotdir; VPutVnode(&fileCode, parentwhentargetnotdir); - assert(!fileCode || (fileCode == VSALVAGE)); + osi_Assert(!fileCode || (fileCode == VSALVAGE)); parentwhentargetnotdir = NULL; } #if FS_STATS_DETAILED @@ -3289,7 +3289,7 @@ SRXAFS_StoreACL(struct rx_call * acall, struct AFSFid * Fid, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, targetptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call backs on the directory */ BreakCallBack(client->host, Fid, 0); @@ -3395,7 +3395,7 @@ SAFSS_StoreStatus(struct rx_call *acall, struct AFSFid *Fid, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, targetptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* Break call backs on Fid */ BreakCallBack(client->host, Fid, 0); @@ -3552,14 +3552,14 @@ SAFSS_RemoveFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name, DeleteFileCallBacks(&fileFid); /* convert the parent lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); } else { /* convert the parent lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* convert the target lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, targetptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* tell all the file has changed */ BreakCallBack(client->host, &fileFid, 1); } @@ -3724,7 +3724,7 @@ SAFSS_CreateFile(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call back on parent dir */ BreakCallBack(client->host, DirFid, 0); @@ -4072,7 +4072,7 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, } if (testnode == 1) top = 1; testvptr = VGetVnode(&errorCode, volptr, testnode, READ_LOCK); - assert(errorCode == 0); + osi_Assert(errorCode == 0); testnode = testvptr->disk.parent; VPutVnode(&errorCode, testvptr); if ((top == 1) && (testnode != 0)) { @@ -4083,7 +4083,7 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, errorCode = EIO; goto Bad_Rename; } - assert(errorCode == 0); + osi_Assert(errorCode == 0); } } @@ -4118,7 +4118,7 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, if (newfileptr) { /* Delete NewName from its directory */ code = Delete(&newdir, NewName); - assert(code == 0); + osi_Assert(code == 0); /* Drop the link count */ newfileptr->disk.linkCount--; @@ -4165,7 +4165,7 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, goto Bad_Rename; /* Delete the old name */ - assert(Delete(&olddir, (char *)OldName) == 0); + osi_Assert(Delete(&olddir, (char *)OldName) == 0); /* if the directory length changes, reflect it in the statistics */ #if FS_STATS_DETAILED @@ -4191,13 +4191,13 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, /* if we are dealing with a rename of a directory, and we need to * update the .. entry of that directory */ if (updatefile) { - assert(!fileptr->disk.cloned); + osi_Assert(!fileptr->disk.cloned); fileptr->changed_newTime = 1; /* status change of moved file */ /* fix .. to point to the correct place */ Delete(&filedir, ".."); /* No assert--some directories may be bad */ - assert(Create(&filedir, "..", NewDirFid) == 0); + osi_Assert(Create(&filedir, "..", NewDirFid) == 0); fileptr->disk.dataVersion++; /* if the parent directories are different the link counts have to be */ @@ -4219,15 +4219,15 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, /* convert the write locks to a read locks before breaking callbacks */ VVnodeWriteToRead(&errorCode, newvptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); if (oldvptr != newvptr) { VVnodeWriteToRead(&errorCode, oldvptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); } if (newfileptr && !doDelete) { /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, newfileptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); } /* break call back on NewDirFid, OldDirFid, NewDirFid and newFileFid */ @@ -4257,7 +4257,7 @@ SAFSS_Rename(struct rx_call *acall, struct AFSFid *OldDirFid, char *OldName, Bad_Rename: if (newfileptr) { VPutVnode(&fileCode, newfileptr); - assert(fileCode == 0); + osi_Assert(fileCode == 0); } (void)PutVolumePackage(fileptr, (newvptr && newvptr != oldvptr ? newvptr : 0), oldvptr, volptr, &client); @@ -4464,7 +4464,7 @@ SAFSS_Symlink(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call back on the parent dir */ BreakCallBack(client->host, DirFid, 0); @@ -4664,9 +4664,9 @@ SAFSS_Link(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* convert the write locks to read locks before breaking callbacks */ VVnodeWriteToRead(&errorCode, targetptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call back on DirFid */ BreakCallBack(client->host, DirFid, 0); @@ -4844,10 +4844,10 @@ SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name, #endif /* FS_STATS_DETAILED */ /* Point to target's ACL buffer and copy the parent's ACL contents to it */ - assert((SetAccessList + osi_Assert((SetAccessList (&targetptr, &volptr, &newACL, &newACLSize, &parentwhentargetnotdir, (AFSFid *) 0, 0)) == 0); - assert(parentwhentargetnotdir == 0); + osi_Assert(parentwhentargetnotdir == 0); memcpy((char *)newACL, (char *)VVnodeACL(parentptr), VAclSize(parentptr)); /* update the status for the target vnode */ @@ -4856,7 +4856,7 @@ SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* Actually create the New directory in the directory package */ SetDirHandle(&dir, targetptr); - assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid))); + osi_Assert(!(MakeDir(&dir, (afs_int32 *)OutFid, (afs_int32 *)DirFid))); DFlush(); VN_SET_LEN(targetptr, (afs_fsize_t) Length(&dir)); @@ -4866,7 +4866,7 @@ SAFSS_MakeDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call back on DirFid */ BreakCallBack(client->host, DirFid, 0); @@ -5032,7 +5032,7 @@ SAFSS_RemoveDir(struct rx_call *acall, struct AFSFid *DirFid, char *Name, /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, parentptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); /* break call back on DirFid and fileFid */ BreakCallBack(client->host, DirFid, 0); @@ -5417,7 +5417,7 @@ SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid, if (targetptr->disk.lock.lockCount <= 0) { /* convert the write lock to a read lock before breaking callbacks */ VVnodeWriteToRead(&errorCode, targetptr); - assert(!errorCode || errorCode == VSALVAGE); + osi_Assert(!errorCode || errorCode == VSALVAGE); BreakCallBack(client->host, Fid, 0); } @@ -7077,7 +7077,7 @@ FetchData_RXStyle(Volume * volptr, Vnode * targetptr, { afs_int32 high, low; SplitOffsetOrSize(Len, high, low); - assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0); + osi_Assert(Int64Mode || (Len >= 0 && high == 0) || Len < 0); if (Int64Mode) { high = htonl(high); rx_Write(Call, (char *)&high, sizeof(afs_int32)); /* High order bits */ @@ -7473,7 +7473,7 @@ StoreData_RXStyle(Volume * volptr, Vnode * targetptr, struct AFSFid * Fid, } if (errorCode) { afs_sfsize_t nfSize = FDH_SIZE(fdP); - assert(nfSize >= 0); + osi_Assert(nfSize >= 0); /* something went wrong: adjust size and return */ VN_SET_LEN(targetptr, nfSize); /* set new file size. */ /* changed_newTime is tested in StoreData to detemine if we diff --git a/src/viced/callback.c b/src/viced/callback.c index a9f52a0b6..1d52fc7a8 100644 --- a/src/viced/callback.c +++ b/src/viced/callback.c @@ -354,7 +354,8 @@ CDel(struct CallBack *cb, int deletefe) for (safety = 0, cbp = &fe->firstcb; *cbp && *cbp != cbi; cbp = &itocb(*cbp)->cnext, safety++) { if (safety > cbstuff.nblks + 10) { - assert(0); + osi_Panic("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n", + cbi, fe->firstcb, *cbp); ViceLog(0, ("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)); @@ -422,7 +423,7 @@ FDel(struct FileEntry *fe) while (*p && *p != fei) p = &itofe(*p)->fnext; - assert(*p); + osi_Assert(*p); *p = fe->fnext; FreeFE(fe); return 0; @@ -439,7 +440,7 @@ InitCallBack(int nblks) FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry)))); if (!FE) { ViceLog(0, ("Failed malloc in InitCallBack\n")); - assert(0); + osi_Panic("Failed malloc in InitCallBack\n"); } FE--; /* FE[0] is supposed to point to junk */ cbstuff.nFEs = nblks; @@ -448,7 +449,7 @@ InitCallBack(int nblks) CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack)))); if (!CB) { ViceLog(0, ("Failed malloc in InitCallBack\n")); - assert(0); + osi_Panic("Failed malloc in InitCallBack\n"); } CB--; /* CB[0] is supposed to point to junk */ cbstuff.nCBs = nblks; @@ -693,7 +694,7 @@ MultiBreakCallBack_r(struct cbstruct cba[], int ncbas, static struct AFSCBs tc = { 0, 0 }; int multi_to_cba_map[MAX_CB_HOSTS]; - assert(ncbas <= MAX_CB_HOSTS); + osi_Assert(ncbas <= MAX_CB_HOSTS); /* sort cba list to avoid makecall issues */ qsort(cba, ncbas, sizeof(struct cbstruct), CompareCBA); @@ -1146,7 +1147,7 @@ MultiBreakVolumeCallBack_r(struct host *host, int isheld, h_Unlock_r(host); return 0; /* parent will release hold */ } - assert(parms->ncbas <= MAX_CB_HOSTS); + osi_Assert(parms->ncbas <= MAX_CB_HOSTS); /* Do not call MultiBreakCallBack on the current host structure ** because it would prematurely release the hold on the host @@ -1239,7 +1240,7 @@ BreakVolumeCallBacksLater(afs_uint32 volume) ViceLog(25, ("Fsync thread wakeup\n")); #ifdef AFS_PTHREAD_ENV FSYNC_LOCK; - assert(pthread_cond_broadcast(&fsync_cond) == 0); + CV_BROADCAST(&fsync_cond); FSYNC_UNLOCK; #else LWP_NoYieldSignal(fsync_wait); @@ -2960,7 +2961,7 @@ MultiBreakCallBackAlternateAddress_r(struct host *host, if (!interfaces || !conns) { ViceLog(0, ("Failed malloc in MultiBreakCallBackAlternateAddress_r\n")); - assert(0); + osi_Panic("Failed malloc in MultiBreakCallBackAlternateAddress_r\n"); } /* initialize alternate rx connections */ @@ -2979,7 +2980,7 @@ MultiBreakCallBackAlternateAddress_r(struct host *host, j++; } - assert(j); /* at least one alternate address */ + osi_Assert(j); /* at least one alternate address */ ViceLog(125, ("Starting multibreakcall back on all addr for host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); @@ -3055,7 +3056,7 @@ MultiProbeAlternateAddress_r(struct host *host) conns = calloc(i, sizeof(struct rx_connection *)); if (!interfaces || !conns) { ViceLog(0, ("Failed malloc in MultiProbeAlternateAddress_r\n")); - assert(0); + osi_Panic("Failed malloc in MultiProbeAlternateAddress_r\n"); } /* initialize alternate rx connections */ @@ -3074,7 +3075,7 @@ MultiProbeAlternateAddress_r(struct host *host) j++; } - assert(j); /* at least one alternate address */ + osi_Assert(j); /* at least one alternate address */ ViceLog(125, ("Starting multiprobe on all addr for host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), diff --git a/src/viced/host.c b/src/viced/host.c index d9bf4077d..63502a141 100644 --- a/src/viced/host.c +++ b/src/viced/host.c @@ -218,7 +218,7 @@ GetHTBlock(void) } #ifdef AFS_PTHREAD_ENV for (i = 0; i < (h_HTSPERBLOCK); i++) - assert(pthread_cond_init(&block->entry[i].cond, NULL) == 0); + CV_INIT(&block->entry[i].cond, "block entry", CV_DEFAULT, 0); #endif /* AFS_PTHREAD_ENV */ for (i = 0; i < (h_HTSPERBLOCK); i++) Lock_Init(&block->entry[i].lock); @@ -241,7 +241,7 @@ GetHT(void) if (HTFree == NULL) GetHTBlock(); - assert(HTFree != NULL); + osi_Assert(HTFree != NULL); entry = HTFree; HTFree = entry->next; HTs++; @@ -356,7 +356,7 @@ hpr_GetHostCPS(afs_int32 host, prlist *CPS) if (!uclient) { code = hpr_Initialize(&uclient); if (!code) - assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); + osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); else return code; } @@ -390,7 +390,7 @@ hpr_NameToId(namelist *names, idlist *ids) if (!uclient) { code = hpr_Initialize(&uclient); if (!code) - assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); + osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); else return code; } @@ -415,7 +415,7 @@ hpr_IdToName(idlist *ids, namelist *names) if (!uclient) { code = hpr_Initialize(&uclient); if (!code) - assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); + osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); else return code; } @@ -439,7 +439,7 @@ hpr_GetCPS(afs_int32 id, prlist *CPS) if (!uclient) { code = hpr_Initialize(&uclient); if (!code) - assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); + osi_Assert(pthread_setspecific(viced_uclient_key, (void *)uclient) == 0); else return code; } @@ -590,7 +590,7 @@ h_gethostcps_r(struct host *host, afs_int32 now) slept = 1; /* I did sleep */ host->hostFlags |= HCPS_WAITING; /* I am sleeping now */ #ifdef AFS_PTHREAD_ENV - pthread_cond_wait(&host->cond, &host_glock_mutex); + CV_WAIT(&host->cond, &host_glock_mutex); #else /* AFS_PTHREAD_ENV */ if ((code = LWP_WaitProcess(&(host->hostFlags))) != LWP_SUCCESS) ViceLog(0, ("LWP_WaitProcess returned %d\n", code)); @@ -651,7 +651,7 @@ h_gethostcps_r(struct host *host, afs_int32 now) if (host->hostFlags & HCPS_WAITING) { /* somebody is waiting */ host->hostFlags &= ~HCPS_WAITING; #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&host->cond) == 0); + CV_BROADCAST(&host->cond); #else /* AFS_PTHREAD_ENV */ if ((code = LWP_NoYieldSignal(&(host->hostFlags))) != LWP_SUCCESS) ViceLog(0, ("LWP_NoYieldSignal returns %d\n", code)); @@ -773,7 +773,7 @@ h_Lookup_r(afs_uint32 haddr, afs_uint16 hport, struct host **hostp) restart: for (chain = hostAddrHashTable[index]; chain; chain = chain->next) { host = chain->hostPtr; - assert(host); + osi_Assert(host); if (!(host->hostFlags & HOSTDELETED) && chain->addr == haddr && chain->port == hport) { if ((host->hostFlags & HWHO_INPROGRESS) && @@ -820,7 +820,7 @@ h_LookupUuid_r(afsUUID * uuidp) for (chain = hostUuidHashTable[index]; chain; chain = chain->next) { host = chain->hostPtr; - assert(host); + osi_Assert(host); if (!(host->hostFlags & HOSTDELETED) && host->interface && afs_uuid_equal(&host->interface->uuid, uuidp)) { return host; @@ -988,12 +988,12 @@ h_Enumerate(int (*proc) (struct host*, int, void *), void *param) list = (struct host **)malloc(hostCount * sizeof(struct host *)); if (!list) { ViceLog(0, ("Failed malloc in h_Enumerate (list)\n")); - assert(0); + osi_Panic("Failed malloc in h_Enumerate (list)\n"); } flags = (int *)malloc(hostCount * sizeof(int)); if (!flags) { ViceLog(0, ("Failed malloc in h_Enumerate (flags)\n")); - assert(0); + osi_Panic("Failed malloc in h_Enumerate (flags)\n"); } for (totalCount = count = 0, host = hostList; host && totalCount < hostCount; @@ -1153,7 +1153,7 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host) chain = (struct h_UuidHashChain *)malloc(sizeof(struct h_UuidHashChain)); if (!chain) { ViceLog(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n")); - assert(0); + osi_Panic("Failed malloc in h_AddHostToUuidHashTable_r\n"); } chain->hostPtr = host; chain->next = hostUuidHashTable[index]; @@ -1185,7 +1185,7 @@ h_DeleteHostFromUuidHashTable_r(struct host *host) if (LogLevel >= 125) afsUUID_to_string(&host->interface->uuid, uuid1, 127); for (uhp = &hostUuidHashTable[index]; (uth = *uhp); uhp = &uth->next) { - assert(uth->hostPtr); + osi_Assert(uth->hostPtr); if (uth->hostPtr == host) { ViceLog(125, ("h_DeleteHostFromUuidHashTable_r: host %" AFS_PTR_FMT " (uuid %s %s:%d)\n", @@ -1216,8 +1216,8 @@ invalidateInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port) struct Interface *interface; char hoststr[16], hoststr2[16]; - assert(host); - assert(host->interface); + osi_Assert(host); + osi_Assert(host->interface); ViceLog(125, ("invalidateInterfaceAddr : host %" AFS_PTR_FMT " (%s:%d) addr %s:%d\n", host, afs_inet_ntoa_r(host->host, hoststr), @@ -1340,7 +1340,7 @@ createHostAddrHashChain_r(int index, afs_uint32 addr, afs_uint16 port, struct ho chain = (struct h_AddrHashChain *)malloc(sizeof(struct h_AddrHashChain)); if (!chain) { ViceLog(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n")); - assert(0); + osi_Panic("Failed malloc in h_AddHostToAddrHashTable_r\n"); } chain->hostPtr = host; chain->next = hostAddrHashTable[index]; @@ -1376,7 +1376,7 @@ reconcileHosts_r(afs_uint32 addr, afs_uint16 port, struct host *newHost, AFS_PTR_FMT, afs_inet_ntoa_r(addr, hoststr), ntohs(port), newHost, oldHost)); - assert(oldHost != newHost); + osi_Assert(oldHost != newHost); caps.Capabilities_val = NULL; if (!sc) { @@ -1526,8 +1526,8 @@ addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port) struct Interface *interface; char hoststr[16], hoststr2[16]; - assert(host); - assert(host->interface); + osi_Assert(host); + osi_Assert(host->interface); /* * Make sure this address is on the list of known addresses @@ -1561,7 +1561,7 @@ addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port) malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * number)); if (!interface) { ViceLog(0, ("Failed malloc in addInterfaceAddr_r\n")); - assert(0); + osi_Panic("Failed malloc in addInterfaceAddr_r\n"); } interface->numberOfInterfaces = number + 1; interface->uuid = host->interface->uuid; @@ -1593,8 +1593,8 @@ removeInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port) struct Interface *interface; char hoststr[16], hoststr2[16]; - assert(host); - assert(host->interface); + osi_Assert(host); + osi_Assert(host->interface); ViceLog(125, ("removeInterfaceAddr : host %" AFS_PTR_FMT " (%s:%d) addr %s:%d\n", host, afs_inet_ntoa_r(host->host, hoststr), @@ -1754,7 +1754,7 @@ h_GetHost_r(struct rx_connection *tcon) identP = (struct Identity *)malloc(sizeof(struct Identity)); if (!identP) { ViceLog(0, ("Failed malloc in h_GetHost_r\n")); - assert(0); + osi_Panic("Failed malloc in h_GetHost_r\n"); } identP->valid = 0; rx_SetSpecific(tcon, rxcon_ident_key, identP); @@ -1796,7 +1796,7 @@ h_GetHost_r(struct rx_connection *tcon) identP = (struct Identity *)malloc(sizeof(struct Identity)); if (!identP) { ViceLog(0, ("Failed malloc in h_GetHost_r\n")); - assert(0); + osi_Panic("Failed malloc in h_GetHost_r\n"); } identP->valid = 1; identP->uuid = interf.uuid; @@ -1985,7 +1985,7 @@ h_GetHost_r(struct rx_connection *tcon) if (!identP) { ViceLog(0, ("Failed malloc in h_GetHost_r\n")); - assert(0); + osi_Panic("Failed malloc in h_GetHost_r\n"); } identP->valid = 0; if (!pident) @@ -2004,7 +2004,7 @@ h_GetHost_r(struct rx_connection *tcon) if (!identP) { ViceLog(0, ("Failed malloc in h_GetHost_r\n")); - assert(0); + osi_Panic("Failed malloc in h_GetHost_r\n"); } identP->valid = 1; interfValid = 1; @@ -2156,7 +2156,7 @@ h_GetHost_r(struct rx_connection *tcon) ("InitCallBackState3 success on host %" AFS_PTR_FMT " (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port))); - assert(interfValid == 1); + osi_Assert(interfValid == 1); initInterfaceAddr_r(host, &interf); } } @@ -2230,9 +2230,7 @@ h_InitHostPackage(void) } rxcon_ident_key = rx_KeyCreate((rx_destructor_t) free); rxcon_client_key = rx_KeyCreate((rx_destructor_t) 0); -#ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&host_glock_mutex, NULL) == 0); -#endif /* AFS_PTHREAD_ENV */ + MUTEX_INIT(&host_glock_mutex, "host glock", MUTEX_DEFAULT, 0); } static int @@ -2271,7 +2269,7 @@ MapName_r(char *aname, char *acell, afs_int32 * aval) tname = (char *)malloc(PR_MAXNAMELEN); if (!tname) { ViceLog(0, ("Failed malloc in MapName_r\n")); - assert(0); + osi_Panic("Failed malloc in MapName_r\n"); } strcpy(tname, aname); tname[anamelen] = '@'; @@ -2541,7 +2539,7 @@ h_FindClient_r(struct rx_connection *tcon) * possible failure modes that we will disable it again */ /* Turn off System:Administrator for safety * if (AL_IsAMember(SystemId, client->CPS) == 0) - * assert(AL_DisableGroup(SystemId, client->CPS) == 0); */ + * osi_Assert(AL_DisableGroup(SystemId, client->CPS) == 0); */ } /* Now, tcon may already be set to a rock, since we blocked with no host @@ -2626,7 +2624,7 @@ h_FindClient_r(struct rx_connection *tcon) int h_ReleaseClient_r(struct client *client) { - assert(client->refCount > 0); + osi_Assert(client->refCount > 0); client->refCount--; return 0; } @@ -2704,7 +2702,7 @@ h_UserName(struct client *client) lids.idlist_val = (afs_int32 *) malloc(1 * sizeof(afs_int32)); if (!lids.idlist_val) { ViceLog(0, ("Failed malloc in h_UserName\n")); - assert(0); + osi_Panic("Failed malloc in h_UserName\n"); } lnames.namelist_len = 0; lnames.namelist_val = (prname *) 0; @@ -3239,7 +3237,7 @@ h_stateSaveHost(struct host * host, int flags, void* rock) if_len = sizeof(struct Interface) + ((host->interface->numberOfInterfaces-1) * sizeof(struct AddrPort)); ifp = (struct Interface *) malloc(if_len); - assert(ifp != NULL); + osi_Assert(ifp != NULL); memcpy(ifp, host->interface, if_len); hdr.interfaces = host->interface->numberOfInterfaces; iov[iovcnt].iov_base = (char *) ifp; @@ -3250,7 +3248,7 @@ h_stateSaveHost(struct host * host, int flags, void* rock) hdr.hcps = host->hcps.prlist_len; hcps_len = hdr.hcps * sizeof(afs_int32); hcps = (afs_int32 *) malloc(hcps_len); - assert(hcps != NULL); + osi_Assert(hcps != NULL); memcpy(hcps, host->hcps.prlist_val, hcps_len); iov[iovcnt].iov_base = (char *) hcps; iov[iovcnt].iov_len = hcps_len; @@ -3322,7 +3320,7 @@ h_stateRestoreHost(struct fs_dump_state * state) ifp_len = sizeof(struct Interface) + ((hdr.interfaces-1) * sizeof(struct AddrPort)); ifp = (struct Interface *) malloc(ifp_len); - assert(ifp != NULL); + osi_Assert(ifp != NULL); iov[iovcnt].iov_base = (char *) ifp; iov[iovcnt].iov_len = ifp_len; iovcnt++; @@ -3330,7 +3328,7 @@ h_stateRestoreHost(struct fs_dump_state * state) if (hdr.hcps) { hcps_len = hdr.hcps * sizeof(afs_int32); hcps = (afs_int32 *) malloc(hcps_len); - assert(hcps != NULL); + osi_Assert(hcps != NULL); iov[iovcnt].iov_base = (char *) hcps; iov[iovcnt].iov_len = hcps_len; iovcnt++; @@ -3351,11 +3349,11 @@ h_stateRestoreHost(struct fs_dump_state * state) if (!hdr.hcps && hdsk.hcps_valid) { /* valid, zero-length host cps ; does this ever happen? */ hcps = (afs_int32 *) malloc(sizeof(afs_int32)); - assert(hcps != NULL); + osi_Assert(hcps != NULL); } host = GetHT(); - assert(host != NULL); + osi_Assert(host != NULL); if (ifp) { host->interface = ifp; @@ -3958,8 +3956,8 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf) char uuidstr[128]; afs_uint16 port7001 = htons(7001); - assert(host); - assert(interf); + osi_Assert(host); + osi_Assert(interf); number = interf->numberOfInterfaces; myAddr = host->host; /* current interface address */ @@ -4035,7 +4033,7 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf) (sizeof(struct AddrPort) * (count - 1))); if (!interface) { ViceLog(0, ("Failed malloc in initInterfaceAddr_r 1\n")); - assert(0); + osi_Panic("Failed malloc in initInterfaceAddr_r 1\n"); } interface->numberOfInterfaces = count; } else { @@ -4043,7 +4041,7 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf) malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * count)); if (!interface) { ViceLog(0, ("Failed malloc in initInterfaceAddr_r 2\n")); - assert(0); + osi_Panic("Failed malloc in initInterfaceAddr_r 2\n"); } interface->numberOfInterfaces = count + 1; interface->interface[count].addr = myAddr; @@ -4065,7 +4063,7 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf) interface->uuid = interf->uuid; - assert(!host->interface); + osi_Assert(!host->interface); host->interface = interface; if (LogLevel >= 125) { @@ -4096,7 +4094,7 @@ h_DeleteHostFromAddrHashTable_r(afs_uint32 addr, afs_uint16 port, for (hp = &hostAddrHashTable[h_HashIndex(addr)]; (th = *hp); hp = &th->next) { - assert(th->hostPtr); + osi_Assert(th->hostPtr); if (th->hostPtr == host && th->addr == addr && th->port == port) { ViceLog(125, ("h_DeleteHostFromAddrHashTable_r: host %" AFS_PTR_FMT " (%s:%d)\n", host, afs_inet_ntoa_r(host->host, hoststr), diff --git a/src/viced/host.h b/src/viced/host.h index 3e7b3c06a..e02e4426b 100644 --- a/src/viced/host.h +++ b/src/viced/host.h @@ -23,13 +23,11 @@ * precedence is host_listlock_mutex, host->mutex, host_glock_mutex. */ #include -#include +#include #include extern pthread_mutex_t host_glock_mutex; -#define H_LOCK \ - assert(pthread_mutex_lock(&host_glock_mutex) == 0) -#define H_UNLOCK \ - assert(pthread_mutex_unlock(&host_glock_mutex) == 0) +#define H_LOCK MUTEX_ENTER(&host_glock_mutex); +#define H_UNLOCK MUTEX_EXIT(&host_glock_mutex); extern pthread_key_t viced_uclient_key; #else /* AFS_PTHREAD_ENV */ #define H_LOCK @@ -193,7 +191,7 @@ do { \ hostList ? (hostList->prev = (h)):0; \ hostList = (h); \ hostCount++; -#define h_DeleteList_r(h) assert(hostCount>0); \ +#define h_DeleteList_r(h) osi_Assert(hostCount>0); \ hostCount--; \ (h)->next ? ((h)->next->prev = (h)->prev):0;\ (h)->prev ? ((h)->prev->next = (h)->next):0;\ diff --git a/src/viced/viced.c b/src/viced/viced.c index 0e9d2a9c8..d1fcb18ae 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -52,11 +52,7 @@ #undef SHARED #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -269,8 +265,8 @@ static int fs_stateInit(void) fs_state.options.fs_state_verify_before_save = 1; fs_state.options.fs_state_verify_after_restore = 1; - assert(pthread_cond_init(&fs_state.worker_done_cv, NULL) == 0); - assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0); + CV_INIT(&fs_state.worker_done_cv, "worker done", CV_DEFAULT, 0); + osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0); } #endif /* AFS_NT40_ENV */ #endif /* AFS_DEMAND_ATTACH_FS */ @@ -509,7 +505,7 @@ FiveMinuteCheckLWP(void *unused) #ifdef AFS_DEMAND_ATTACH_FS fs_state.FiveMinuteLWP_tranquil = 1; FS_LOCK; - assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0); + CV_BROADCAST(&fs_state.worker_done_cv); FS_UNLOCK; FS_STATE_UNLOCK; #endif @@ -561,7 +557,7 @@ HostCheckLWP(void *unused) #ifdef AFS_DEMAND_ATTACH_FS fs_state.HostCheckLWP_tranquil = 1; FS_LOCK; - assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0); + CV_BROADCAST(&fs_state.worker_done_cv); FS_UNLOCK; FS_STATE_UNLOCK; #endif @@ -597,9 +593,8 @@ FsyncCheckLWP(void *unused) fsync_next.tv_nsec = 0; fsync_next.tv_sec = time(0) + fiveminutes; - code = - pthread_cond_timedwait(&fsync_cond, &fsync_glock_mutex, - &fsync_next); + code = CV_TIMEDWAIT(&fsync_cond, &fsync_glock_mutex, + &fsync_next); if (code != 0 && code != ETIMEDOUT) ViceLog(0, ("pthread_cond_timedwait returned %d\n", code)); #else /* AFS_PTHREAD_ENV */ @@ -628,7 +623,7 @@ FsyncCheckLWP(void *unused) #ifdef AFS_DEMAND_ATTACH_FS fs_state.FsyncCheckLWP_tranquil = 1; FS_LOCK; - assert(pthread_cond_broadcast(&fs_state.worker_done_cv)==0); + CV_BROADCAST(&fs_state.worker_done_cv); FS_UNLOCK; FS_STATE_UNLOCK; #endif /* AFS_DEMAND_ATTACH_FS */ @@ -788,7 +783,8 @@ ShutdownWatchdogLWP(void *unused) sleep(panic_timeout); ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic " "within %d seconds; forcing panic\n", panic_timeout)); - assert(0); + osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic " + "within %d seconds; forcing panic\n", panic_timeout); return NULL; } @@ -802,11 +798,11 @@ ShutDownAndCore(int dopanic) #ifdef AFS_PTHREAD_ENV pthread_t watchdogPid; pthread_attr_t tattr; - assert(pthread_attr_init(&tattr) == 0); - assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0); + osi_Assert(pthread_attr_init(&tattr) == 0); + osi_Assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0); #else PROCESS watchdogPid; - assert(LWP_CreateProcess + osi_Assert(LWP_CreateProcess (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2, NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS); #endif @@ -864,7 +860,7 @@ ShutDownAndCore(int dopanic) FS_LOCK; FS_STATE_UNLOCK; ViceLog(0, ("waiting for background host/callback threads to quiesce before saving fileserver state...\n")); - assert(pthread_cond_wait(&fs_state.worker_done_cv, &fileproc_glock_mutex) == 0); + CV_WAIT(&fs_state.worker_done_cv, &fileproc_glock_mutex); FS_UNLOCK; FS_STATE_RDLOCK; } @@ -893,8 +889,8 @@ ShutDownAndCore(int dopanic) afs_ctime(&now, tbuffer, sizeof(tbuffer)))); } - if (dopanic) - assert(0); + if (dopanic) /* XXX pass in file and line? */ + osi_Panic("Panic requested\n"); exit(0); } @@ -1571,7 +1567,7 @@ void Die(char *msg) { ViceLog(0, ("%s\n", msg)); - assert(0); + osi_Panic("%s\n", msg); } /*Die */ @@ -1593,7 +1589,7 @@ InitPR(void) } #ifdef AFS_PTHREAD_ENV - assert(pthread_key_create(&viced_uclient_key, NULL) == 0); + osi_Assert(pthread_key_create(&viced_uclient_key, NULL) == 0); #endif SystemId = SYSADMINID; @@ -1985,7 +1981,7 @@ main(int argc, char *argv[]) exit(-1); } #ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&fileproc_glock_mutex, NULL) == 0); + MUTEX_INIT(&fileproc_glock_mutex, "fileproc", MUTEX_DEFAULT, 0); #endif /* AFS_PTHREAD_ENV */ #ifdef AFS_SGI_VNODE_GLUE @@ -2036,7 +2032,7 @@ main(int argc, char *argv[]) nice(-5); /* TODO: */ #endif #endif - assert(DInit(buffs) == 0); + osi_Assert(DInit(buffs) == 0); #ifdef AFS_DEMAND_ATTACH_FS FS_STATE_INIT; #endif @@ -2089,7 +2085,7 @@ main(int argc, char *argv[]) curLimit, lwps, vol_io_params.fd_max_cachesize)); } #ifndef AFS_PTHREAD_ENV - assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) == + osi_Assert(LWP_InitializeProcessSupport(LWP_MAX_PRIORITY - 2, &parentPid) == LWP_SUCCESS); #endif /* !AFS_PTHREAD_ENV */ @@ -2211,10 +2207,8 @@ main(int argc, char *argv[]) /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(fs_rxstat_userok); -#ifdef AFS_PTHREAD_ENV - assert(pthread_cond_init(&fsync_cond, NULL) == 0); - assert(pthread_mutex_init(&fsync_glock_mutex, NULL) == 0); -#endif + CV_INIT(&fsync_cond, "fsync", CV_DEFAULT, 0); + MUTEX_INIT(&fsync_glock_mutex, "fsync", MUTEX_DEFAULT, 0); #if !defined(AFS_DEMAND_ATTACH_FS) /* @@ -2300,27 +2294,27 @@ main(int argc, char *argv[]) #ifdef AFS_PTHREAD_ENV ViceLog(5, ("Starting pthreads\n")); - assert(pthread_attr_init(&tattr) == 0); - assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_attr_init(&tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create + osi_Assert(pthread_create (&serverPid, &tattr, FiveMinuteCheckLWP, &fiveminutes) == 0); - assert(pthread_create + osi_Assert(pthread_create (&serverPid, &tattr, HostCheckLWP, &fiveminutes) == 0); - assert(pthread_create + osi_Assert(pthread_create (&serverPid, &tattr, FsyncCheckLWP, &fiveminutes) == 0); #else /* AFS_PTHREAD_ENV */ ViceLog(5, ("Starting LWP\n")); - assert(LWP_CreateProcess + osi_Assert(LWP_CreateProcess (FiveMinuteCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, (void *)&fiveminutes, "FiveMinuteChecks", &serverPid) == LWP_SUCCESS); - assert(LWP_CreateProcess + osi_Assert(LWP_CreateProcess (HostCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, (void *)&fiveminutes, "HostCheck", &serverPid) == LWP_SUCCESS); - assert(LWP_CreateProcess + osi_Assert(LWP_CreateProcess (FsyncCheckLWP, stack * 1024, LWP_MAX_PRIORITY - 2, (void *)&fiveminutes, "FsyncCheck", &serverPid) == LWP_SUCCESS); #endif /* AFS_PTHREAD_ENV */ @@ -2366,7 +2360,7 @@ main(int argc, char *argv[]) sleep(1000); /* long time */ } #else /* AFS_PTHREAD_ENV */ - assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS); + osi_Assert(LWP_WaitProcess(&parentPid) == LWP_SUCCESS); #endif /* AFS_PTHREAD_ENV */ return 0; } diff --git a/src/viced/viced.h b/src/viced/viced.h index a2e64dbb5..09e2bf395 100644 --- a/src/viced/viced.h +++ b/src/viced/viced.h @@ -195,17 +195,13 @@ extern int saneacls; * HostCheck, Signal, min 2 for RXSTATS */ #ifdef AFS_PTHREAD_ENV #include -#include +#include extern pthread_mutex_t fileproc_glock_mutex; -#define FS_LOCK \ - assert(pthread_mutex_lock(&fileproc_glock_mutex) == 0) -#define FS_UNLOCK \ - assert(pthread_mutex_unlock(&fileproc_glock_mutex) == 0) +#define FS_LOCK MUTEX_ENTER(&fileproc_glock_mutex); +#define FS_UNLOCK MUTEX_EXIT(&fileproc_glock_mutex); extern pthread_mutex_t fsync_glock_mutex; -#define FSYNC_LOCK \ - assert(pthread_mutex_lock(&fsync_glock_mutex) == 0) -#define FSYNC_UNLOCK \ - assert(pthread_mutex_unlock(&fsync_glock_mutex) == 0) +#define FSYNC_LOCK MUTEX_ENTER(&fsync_glock_mutex); +#define FSYNC_UNLOCK MUTEX_EXIT(&fsync_glock_mutex); #else /* AFS_PTHREAD_ENV */ #define FS_LOCK #define FS_UNLOCK @@ -248,11 +244,11 @@ extern struct fs_state fs_state; #ifdef AFS_NT40_ENV #define FS_STATE_INIT fs_stateInit() #else -#define FS_STATE_INIT assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0) +#define FS_STATE_INIT osi_Assert(pthread_rwlock_init(&fs_state.state_lock, NULL) == 0) #endif -#define FS_STATE_RDLOCK assert(pthread_rwlock_rdlock(&fs_state.state_lock) == 0) -#define FS_STATE_WRLOCK assert(pthread_rwlock_wrlock(&fs_state.state_lock) == 0) -#define FS_STATE_UNLOCK assert(pthread_rwlock_unlock(&fs_state.state_lock) == 0) +#define FS_STATE_RDLOCK osi_Assert(pthread_rwlock_rdlock(&fs_state.state_lock) == 0) +#define FS_STATE_WRLOCK osi_Assert(pthread_rwlock_wrlock(&fs_state.state_lock) == 0) +#define FS_STATE_UNLOCK osi_Assert(pthread_rwlock_unlock(&fs_state.state_lock) == 0) #define FS_MODE_NORMAL 0 #define FS_MODE_SHUTDOWN 1 diff --git a/src/vol/Makefile.in b/src/vol/Makefile.in index 739f07c93..3a4a99386 100644 --- a/src/vol/Makefile.in +++ b/src/vol/Makefile.in @@ -18,8 +18,9 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ HELPER_SPLINT=@HELPER_SPLINT@ LIBS=${TOP_LIBDIR}/libcmd.a vlib.a ${TOP_LIBDIR}/util.a \ - ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/libdir.a \ - ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libacl.a + ${TOP_LIBDIR}/libdir.a ${TOP_LIBDIR}/librx.a \ + ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libsys.a \ + ${TOP_LIBDIR}/libacl.a MODULE_CFLAGS= -D${SYS_NAME} ${FSINCLUDES} \ -DFSSYNC_BUILD_SERVER -DFSSYNC_BUILD_CLIENT diff --git a/src/vol/NTMakefile b/src/vol/NTMakefile index 2eb0fe00e..cba51dd59 100644 --- a/src/vol/NTMakefile +++ b/src/vol/NTMakefile @@ -173,6 +173,7 @@ EXEC_LIBS = \ $(DESTDIR)\lib\afs\afsvol.lib \ $(DESTDIR)\lib\afs\afsutil.lib \ $(DESTDIR)\lib\afs\afsdir.lib \ + $(DESTDIR)\lib\afsrx.lib \ $(DESTDIR)\lib\afslwp.lib \ $(DESTDIR)\lib\afs\afsacl.lib \ $(DESTDIR)\lib\afs\afsreg.lib \ diff --git a/src/vol/clone.c b/src/vol/clone.c index e6076b419..7dbd3ec61 100644 --- a/src/vol/clone.c +++ b/src/vol/clone.c @@ -21,11 +21,7 @@ #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_NT40_ENV #include #include @@ -91,7 +87,7 @@ ci_AddItem(struct clone_head *ah, Inode aino) ti = (struct clone_items *)malloc(sizeof(struct clone_items)); if (!ti) { Log("ci_AddItem: malloc failed\n"); - assert(0); + osi_Panic("ci_AddItem: malloc failed\n"); } ti->nitems = 0; ti->next = (struct clone_items *)0; diff --git a/src/vol/daemon_com.c b/src/vol/daemon_com.c index a530c2133..c532b8623 100644 --- a/src/vol/daemon_com.c +++ b/src/vol/daemon_com.c @@ -36,7 +36,7 @@ #include #endif #include -#include +#include #include #include @@ -131,7 +131,7 @@ osi_socket SYNC_getSock(SYNC_endpoint_t * endpoint) { osi_socket sd; - assert((sd = socket(endpoint->domain, SOCK_STREAM, 0)) >= 0); + osi_Assert((sd = socket(endpoint->domain, SOCK_STREAM, 0)) >= 0); return sd; } diff --git a/src/vol/fssync-client.c b/src/vol/fssync-client.c index 10c05a0f6..8a7f35d3a 100644 --- a/src/vol/fssync-client.c +++ b/src/vol/fssync-client.c @@ -49,11 +49,7 @@ #include #endif #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include @@ -88,10 +84,8 @@ static SYNC_client_state fssync_state = #ifdef AFS_PTHREAD_ENV static pthread_mutex_t vol_fsync_mutex; static volatile int vol_fsync_mutex_init = 0; -#define VFSYNC_LOCK \ - assert(pthread_mutex_lock(&vol_fsync_mutex) == 0) -#define VFSYNC_UNLOCK \ - assert(pthread_mutex_unlock(&vol_fsync_mutex) == 0) +#define VFSYNC_LOCK MUTEX_ENTER(&vol_fsync_mutex) +#define VFSYNC_UNLOCK MUTEX_EXIT(&vol_fsync_mutex) #else #define VFSYNC_LOCK #define VFSYNC_UNLOCK @@ -103,7 +97,7 @@ FSYNC_clientInit(void) #ifdef AFS_PTHREAD_ENV /* this is safe since it gets called with VOL_LOCK held, or before we go multithreaded */ if (!vol_fsync_mutex_init) { - assert(pthread_mutex_init(&vol_fsync_mutex, NULL) == 0); + MUTEX_INIT(&vol_fsync_mutex, "vol fsync", MUTEX_DEFAULT, 0); vol_fsync_mutex_init = 1; } #endif diff --git a/src/vol/fssync-debug.c b/src/vol/fssync-debug.c index 993e4065b..096e6e3c2 100644 --- a/src/vol/fssync-debug.c +++ b/src/vol/fssync-debug.c @@ -362,7 +362,7 @@ common_volop_prolog(struct cmd_syndesc * as, struct state * state) struct cmd_item *ti; state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state)); - assert(state->vop != NULL); + osi_Assert(state->vop != NULL); if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */ state->vop->volume = atoi(ti->data); @@ -957,7 +957,7 @@ vn_prolog(struct cmd_syndesc * as, struct state * state) struct cmd_item *ti; state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state)); - assert(state->vop != NULL); + osi_Assert(state->vop != NULL); if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */ state->vop->volume = atoi(ti->data); diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index c08470ccd..d08791006 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -61,11 +61,7 @@ #include #endif #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include @@ -222,19 +218,19 @@ FSYNC_fsInit(void) Lock_Init(&FSYNC_handler_lock); #ifdef AFS_PTHREAD_ENV - assert(pthread_attr_init(&tattr) == 0); - assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0); + osi_Assert(pthread_attr_init(&tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0); #else /* AFS_PTHREAD_ENV */ - assert(LWP_CreateProcess + osi_Assert(LWP_CreateProcess (FSYNC_sync, USUAL_STACK_SIZE, USUAL_PRIORITY, (void *)0, "FSYNC_sync", &pid) == LWP_SUCCESS); #endif /* AFS_PTHREAD_ENV */ #ifdef AFS_DEMAND_ATTACH_FS queue_Init(&fsync_salv.head); - assert(pthread_cond_init(&fsync_salv.cv, NULL) == 0); - assert(pthread_create(&tid, &tattr, FSYNC_salvageThread, NULL) == 0); + CV_INIT(&fsync_salv.cv, "fsync salv", CV_DEFAULT, 0); + osi_Assert(pthread_create(&tid, &tattr, FSYNC_salvageThread, NULL) == 0); #endif /* AFS_DEMAND_ATTACH_FS */ } @@ -268,7 +264,7 @@ FSYNC_sync(void * args) /* we must not be called before vol package initialization, since we use * vol package mutexes and conds etc */ - assert(VInit); + osi_Assert(VInit); SYNC_getAddr(&state->endpoint, &state->addr); SYNC_cleanupSock(state); @@ -302,7 +298,7 @@ FSYNC_sync(void * args) state->fd = SYNC_getSock(&state->endpoint); code = SYNC_bindSock(state); - assert(!code); + osi_Assert(!code); #ifdef AFS_DEMAND_ATTACH_FS /* @@ -317,10 +313,10 @@ FSYNC_sync(void * args) } memcpy(thread_opts, &VThread_defaults, sizeof(VThread_defaults)); thread_opts->disallow_salvsync = 1; - assert(pthread_setspecific(VThread_key, thread_opts) == 0); + osi_Assert(pthread_setspecific(VThread_key, thread_opts) == 0); code = VVGCache_PkgInit(); - assert(code == 0); + osi_Assert(code == 0); #endif InitHandler(); @@ -430,7 +426,7 @@ FSYNC_backgroundSalvage(Volume *vp) } queue_Append(&fsync_salv.head, node); - assert(pthread_cond_broadcast(&fsync_salv.cv) == 0); + CV_BROADCAST(&fsync_salv.cv); } #endif /* AFS_DEMAND_ATTACH_FS */ @@ -448,10 +444,10 @@ FSYNC_newconnection(osi_socket afd) fd = accept(afd, (struct sockaddr *)&other, &junk); if (fd == -1) { Log("FSYNC_newconnection: accept failed, errno==%d\n", errno); - assert(1 == 2); + osi_Assert(1 == 2); } else if (!AddHandler(fd, FSYNC_com)) { AcceptOff(); - assert(AddHandler(fd, FSYNC_com)); + osi_Assert(AddHandler(fd, FSYNC_com)); } } @@ -1054,7 +1050,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res) #ifdef AFS_DEMAND_ATTACH_FS VOfflineForVolOp_r(&error, vp, "A volume utility is running."); if (error==0) { - assert(vp->nUsers==0); + osi_Assert(vp->nUsers==0); vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOffline; } else { @@ -1506,7 +1502,7 @@ FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res) vp = VLookupVolume_r(&error, vcom->vop->volume, NULL); if (vp && vp->pending_vol_op) { - assert(sizeof(FSSYNC_VolOp_info) <= res->payload.len); + osi_Assert(sizeof(FSSYNC_VolOp_info) <= res->payload.len); memcpy(res->payload.buf, vp->pending_vol_op, sizeof(FSSYNC_VolOp_info)); res->hdr.response_len += sizeof(FSSYNC_VolOp_info); } else { @@ -1538,7 +1534,7 @@ FSYNC_com_VGQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res) goto done; } - assert(sizeof(FSSYNC_VGQry_response_t) <= res->payload.len); + osi_Assert(sizeof(FSSYNC_VGQry_response_t) <= res->payload.len); rc = VVGCache_query_r(dp, vcom->vop->volume, res->payload.buf); switch (rc) { @@ -1950,7 +1946,7 @@ static void AcceptOn(void) { if (AcceptHandler == -1) { - assert(AddHandler(fssync_server_state.fd, FSYNC_newconnection)); + osi_Assert(AddHandler(fssync_server_state.fd, FSYNC_newconnection)); AcceptHandler = FindHandler(fssync_server_state.fd); } } @@ -1959,7 +1955,7 @@ static void AcceptOff(void) { if (AcceptHandler != -1) { - assert(RemoveHandler(fssync_server_state.fd)); + osi_Assert(RemoveHandler(fssync_server_state.fd)); AcceptHandler = -1; } } @@ -2044,7 +2040,7 @@ FindHandler(osi_socket afd) return i; } ReleaseReadLock(&FSYNC_handler_lock); /* just in case */ - assert(1 == 2); + osi_Assert(1 == 2); return -1; /* satisfy compiler */ } @@ -2056,7 +2052,7 @@ FindHandler_r(osi_socket afd) if (HandlerFD[i] == afd) { return i; } - assert(1 == 2); + osi_Assert(1 == 2); return -1; /* satisfy compiler */ } @@ -2078,7 +2074,7 @@ GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds) ObtainReadLock(&FSYNC_handler_lock); for (i = 0; i < MAXHANDLERS; i++) if (HandlerFD[i] != -1) { - assert(fdi -#else /* AFS_PTHREAD_ENV */ #include "afs/afs_assert.h" -#endif /* AFS_PTHREAD_ENV */ #include #ifndef AFS_NT40_ENV @@ -125,7 +121,7 @@ void ih_PkgDefaults(void) void ih_glock_init(void) { - assert(pthread_mutex_init(&ih_glock_mutex, NULL) == 0); + MUTEX_INIT(&ih_glock_mutex, "ih glock", MUTEX_DEFAULT, 0); } #endif /* AFS_PTHREAD_ENV */ @@ -134,7 +130,7 @@ void ih_Initialize(void) { int i; - assert(!ih_Inited); + osi_Assert(!ih_Inited); ih_Inited = 1; DLL_INIT_LIST(ihAvailHead, ihAvailTail); DLL_INIT_LIST(fdAvailHead, fdAvailTail); @@ -147,9 +143,9 @@ ih_Initialize(void) #elif defined(AFS_SUN5_ENV) || defined(AFS_NBSD_ENV) { struct rlimit rlim; - assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0); + osi_Assert(getrlimit(RLIMIT_NOFILE, &rlim) == 0); rlim.rlim_cur = rlim.rlim_max; - assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0); + osi_Assert(setrlimit(RLIMIT_NOFILE, &rlim) == 0); fdMaxCacheSize = rlim.rlim_cur - vol_io_params.fd_handle_setaside; #ifdef AFS_NBSD_ENV /* XXX this is to avoid using up all system fd netbsd is @@ -163,7 +159,7 @@ ih_Initialize(void) fdMaxCacheSize /= 4; #endif fdMaxCacheSize = MIN(fdMaxCacheSize, vol_io_params.fd_max_cachesize); - assert(fdMaxCacheSize > 0); + osi_Assert(fdMaxCacheSize > 0); } #elif defined(AFS_HPUX_ENV) /* Avoid problems with "UFSOpen: igetinode failed" panics on HPUX 11.0 */ @@ -225,9 +221,9 @@ iHandleAllocateChunk(void) int i; IHandle_t *ihP; - assert(ihAvailHead == NULL); + osi_Assert(ihAvailHead == NULL); ihP = (IHandle_t *) malloc(I_HANDLE_MALLOCSIZE * sizeof(IHandle_t)); - assert(ihP != NULL); + osi_Assert(ihP != NULL); for (i = 0; i < I_HANDLE_MALLOCSIZE; i++) { ihP[i].ih_refcnt = 0; DLL_INSERT_TAIL(&ihP[i], ihAvailHead, ihAvailTail, ih_next, ih_prev); @@ -264,7 +260,7 @@ ih_init(int dev, int vid, Inode ino) iHandleAllocateChunk(); } ihP = ihAvailHead; - assert(ihP->ih_refcnt == 0); + osi_Assert(ihP->ih_refcnt == 0); DLL_DELETE(ihP, ihAvailHead, ihAvailTail, ih_next, ih_prev); ihP->ih_dev = dev; ihP->ih_vid = vid; @@ -284,8 +280,8 @@ IHandle_t * ih_copy(IHandle_t * ihP) { IH_LOCK; - assert(ih_Inited); - assert(ihP->ih_refcnt > 0); + osi_Assert(ih_Inited); + osi_Assert(ihP->ih_refcnt > 0); ihP->ih_refcnt++; IH_UNLOCK; return ihP; @@ -298,9 +294,9 @@ fdHandleAllocateChunk(void) int i; FdHandle_t *fdP; - assert(fdAvailHead == NULL); + osi_Assert(fdAvailHead == NULL); fdP = (FdHandle_t *) malloc(FD_HANDLE_MALLOCSIZE * sizeof(FdHandle_t)); - assert(fdP != NULL); + osi_Assert(fdP != NULL); for (i = 0; i < FD_HANDLE_MALLOCSIZE; i++) { fdP[i].fd_status = FD_HANDLE_AVAIL; fdP[i].fd_refcnt = 0; @@ -317,10 +313,10 @@ streamHandleAllocateChunk(void) int i; StreamHandle_t *streamP; - assert(streamAvailHead == NULL); + osi_Assert(streamAvailHead == NULL); streamP = (StreamHandle_t *) malloc(STREAM_HANDLE_MALLOCSIZE * sizeof(StreamHandle_t)); - assert(streamP != NULL); + osi_Assert(streamP != NULL); for (i = 0; i < STREAM_HANDLE_MALLOCSIZE; i++) { streamP[i].str_fd = INVALID_FD; DLL_INSERT_TAIL(&streamP[i], streamAvailHead, streamAvailTail, @@ -351,7 +347,7 @@ ih_open(IHandle_t * ihP) * we can't do so in a threadsafe way. */ if (fdP->fd_status != FD_HANDLE_INUSE) { - assert(fdP->fd_status == FD_HANDLE_OPEN); + osi_Assert(fdP->fd_status == FD_HANDLE_OPEN); #else /* HAVE_PIO */ if (fdP->fd_status != FD_HANDLE_AVAIL) { #endif /* HAVE_PIO */ @@ -386,7 +382,7 @@ ih_open_retry: * of open files reaches the size of the cache */ if ((fdInUseCount > fdCacheSize || fd == INVALID_FD) && fdLruHead != NULL) { fdP = fdLruHead; - assert(fdP->fd_status == FD_HANDLE_OPEN); + osi_Assert(fdP->fd_status == FD_HANDLE_OPEN); DLL_DELETE(fdP, fdLruHead, fdLruTail, fd_next, fd_prev); DLL_DELETE(fdP, fdP->fd_ih->ih_fdhead, fdP->fd_ih->ih_fdtail, fd_ihnext, fd_ihprev); @@ -406,7 +402,7 @@ ih_open_retry: fdHandleAllocateChunk(); } fdP = fdAvailHead; - assert(fdP->fd_status == FD_HANDLE_AVAIL); + osi_Assert(fdP->fd_status == FD_HANDLE_AVAIL); DLL_DELETE(fdP, fdAvailHead, fdAvailTail, fd_next, fd_prev); closeFd = INVALID_FD; } @@ -445,9 +441,9 @@ fd_close(FdHandle_t * fdP) return 0; IH_LOCK; - assert(ih_Inited); - assert(fdInUseCount > 0); - assert(fdP->fd_status == FD_HANDLE_INUSE); + osi_Assert(ih_Inited); + osi_Assert(fdInUseCount > 0); + osi_Assert(fdP->fd_status == FD_HANDLE_INUSE); ihP = fdP->fd_ih; @@ -496,9 +492,9 @@ fd_reallyclose(FdHandle_t * fdP) return 0; IH_LOCK; - assert(ih_Inited); - assert(fdInUseCount > 0); - assert(fdP->fd_status == FD_HANDLE_INUSE); + osi_Assert(ih_Inited); + osi_Assert(fdInUseCount > 0); + osi_Assert(fdP->fd_status == FD_HANDLE_INUSE); ihP = fdP->fd_ih; closeFd = fdP->fd_fd; @@ -584,7 +580,7 @@ stream_open(const char *filename, const char *mode) } else if (strcmp(mode, "a+") == 0) { fd = OS_OPEN(filename, O_RDWR | O_APPEND | O_CREAT, 0); } else { - assert(FALSE); /* not implemented */ + osi_Assert(FALSE); /* not implemented */ } if (fd == INVALID_FD) { @@ -607,7 +603,7 @@ stream_read(void *ptr, afs_fsize_t size, afs_fsize_t nitems, streamP->str_bufoff = 0; streamP->str_buflen = 0; } else { - assert(streamP->str_direction == STREAM_DIRECTION_READ); + osi_Assert(streamP->str_direction == STREAM_DIRECTION_READ); } bytesRead = 0; @@ -661,7 +657,7 @@ stream_write(void *ptr, afs_fsize_t size, afs_fsize_t nitems, streamP->str_bufoff = 0; streamP->str_buflen = STREAM_HANDLE_BUFSIZE; } else { - assert(streamP->str_direction == STREAM_DIRECTION_WRITE); + osi_Assert(streamP->str_direction == STREAM_DIRECTION_WRITE); } nbytes = size * nitems; @@ -751,7 +747,7 @@ stream_close(StreamHandle_t * streamP, int reallyClose) ssize_t rc; int retval = 0; - assert(streamP != NULL); + osi_Assert(streamP != NULL); if (streamP->str_direction == STREAM_DIRECTION_WRITE && streamP->str_bufoff > 0) { rc = OS_PWRITE(streamP->str_fd, streamP->str_buffer, @@ -788,7 +784,7 @@ ih_fdclose(IHandle_t * ihP) int closeCount, closedAll; FdHandle_t *fdP, *head, *tail, *next; - assert(ihP->ih_refcnt > 0); + osi_Assert(ihP->ih_refcnt > 0); closedAll = 1; DLL_INIT_LIST(head, tail); @@ -801,8 +797,8 @@ ih_fdclose(IHandle_t * ihP) */ for (fdP = ihP->ih_fdhead; fdP != NULL; fdP = next) { next = fdP->fd_ihnext; - assert(fdP->fd_ih == ihP); - assert(fdP->fd_status == FD_HANDLE_OPEN + osi_Assert(fdP->fd_ih == ihP); + osi_Assert(fdP->fd_status == FD_HANDLE_OPEN || fdP->fd_status == FD_HANDLE_INUSE); if (fdP->fd_status == FD_HANDLE_OPEN) { DLL_DELETE(fdP, ihP->ih_fdhead, ihP->ih_fdtail, fd_ihnext, @@ -819,9 +815,9 @@ ih_fdclose(IHandle_t * ihP) * closed all file descriptors. */ if (ihP->ih_refcnt == 1 || closedAll) { - assert(closedAll); - assert(!ihP->ih_fdhead); - assert(!ihP->ih_fdtail); + osi_Assert(closedAll); + osi_Assert(!ihP->ih_fdhead); + osi_Assert(!ihP->ih_fdtail); } if (head == NULL) { @@ -843,7 +839,7 @@ ih_fdclose(IHandle_t * ihP) } IH_LOCK; - assert(fdInUseCount >= closeCount); + osi_Assert(fdInUseCount >= closeCount); fdInUseCount -= closeCount; /* @@ -883,7 +879,7 @@ ih_reallyclose(IHandle_t * ihP) IH_LOCK; } - assert(ihP->ih_refcnt > 0); + osi_Assert(ihP->ih_refcnt > 0); ihP->ih_synced = 0; ih_fdclose(ihP); @@ -910,7 +906,7 @@ ih_release(IHandle_t * ihP) return 0; IH_LOCK; - assert(ihP->ih_refcnt > 0); + osi_Assert(ihP->ih_refcnt > 0); if (ihP->ih_refcnt > 1) { ihP->ih_refcnt--; diff --git a/src/vol/ihandle.h b/src/vol/ihandle.h index fc19fee56..6df2dffe7 100644 --- a/src/vol/ihandle.h +++ b/src/vol/ihandle.h @@ -69,16 +69,15 @@ #define _IHANDLE_H_ #ifdef AFS_PTHREAD_ENV -#include #include extern pthread_once_t ih_glock_once; extern pthread_mutex_t ih_glock_mutex; extern void ih_glock_init(void); #define IH_LOCK \ - assert(pthread_once(&ih_glock_once, ih_glock_init) == 0 && \ - pthread_mutex_lock(&ih_glock_mutex) == 0) -#define IH_UNLOCK \ - assert(pthread_mutex_unlock(&ih_glock_mutex) == 0) + do { osi_Assert(pthread_once(&ih_glock_once, ih_glock_init) == 0); \ + MUTEX_ENTER(&ih_glock_mutex); \ + } while (0) +#define IH_UNLOCK MUTEX_EXIT(&ih_glock_mutex) #else /* AFS_PTHREAD_ENV */ #define IH_LOCK #define IH_UNLOCK @@ -108,7 +107,7 @@ extern void ih_glock_init(void); else \ (head) = (ptr)->next; \ (ptr)->next = (ptr)->prev = NULL; \ - assert(!(head) || !((head)->prev)); \ + osi_Assert(!(head) || !((head)->prev)); \ } while(0) /* @@ -123,7 +122,7 @@ extern void ih_glock_init(void); (ptr)->prev->next = (ptr); \ else \ (head) = (ptr); \ - assert((head) && ((head)->prev == NULL)); \ + osi_Assert((head) && ((head)->prev == NULL)); \ } while(0) #endif /* DLL_INIT_LIST */ diff --git a/src/vol/listinodes.c b/src/vol/listinodes.c index cbff9723e..326f264ea 100644 --- a/src/vol/listinodes.c +++ b/src/vol/listinodes.c @@ -99,11 +99,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, #if defined (AFS_AIX_ENV) || defined (AFS_HPUX_ENV) #include #endif -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #if defined(AFS_HPUX101_ENV) #include #endif @@ -299,7 +295,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, * LAST_RSVD_I is a vice inode, with dead beef, and * di_nlink == 2 to indicate the FORCE. */ - assert(p = ginode(LAST_RSVD_I)); + osi_Assert(p = ginode(LAST_RSVD_I)); if (p->di_vicemagic == VICEMAGIC && p->di_vicep1 == 0xdeadbeef && p->di_nlink == 2) { @@ -1171,7 +1167,7 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, goto out; } #else - assert(0); /* define AFS_3DISPARES in param.h */ + osi_Panic("Tru64 needs AFS_3DISPARES\n"); #endif #endif #if defined(AFS_SUN56_ENV) diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index aa5c307f5..726203720 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -984,8 +984,8 @@ namei_GetLCOffsetAndIndexFromIno(Inode ino, afs_foff_t * offset, int *index) #ifdef AFS_PTHREAD_ENV /* XXX do static initializers work for WINNT/pthread? */ pthread_mutex_t _namei_glc_lock = PTHREAD_MUTEX_INITIALIZER; -#define NAMEI_GLC_LOCK assert(pthread_mutex_lock(&_namei_glc_lock) == 0) -#define NAMEI_GLC_UNLOCK assert(pthread_mutex_unlock(&_namei_glc_lock) == 0) +#define NAMEI_GLC_LOCK MUTEX_ENTER(&_namei_glc_lock) +#define NAMEI_GLC_UNLOCK MUTEX_EXIT(&_namei_glc_lock) #else /* !AFS_PTHREAD_ENV */ #define NAMEI_GLC_LOCK #define NAMEI_GLC_UNLOCK @@ -1756,7 +1756,7 @@ static pthread_key_t wq_key; static void _namei_wq_keycreate(void) { - assert(pthread_key_create(&wq_key, NULL) == 0); + osi_Assert(pthread_key_create(&wq_key, NULL) == 0); } /** @@ -1770,9 +1770,9 @@ _namei_wq_keycreate(void) void namei_SetWorkQueue(struct afs_work_queue *wq) { - assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0); + osi_Assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0); - assert(pthread_setspecific(wq_key, wq) == 0); + osi_Assert(pthread_setspecific(wq_key, wq) == 0); } /** @@ -1948,7 +1948,7 @@ namei_ListAFSSubDirs(IHandle_t * dirIH, linkHandle.fd_fd = -1; #ifdef AFS_SALSRV_ENV - assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0); + osi_Assert(pthread_once(&wq_once, _namei_wq_keycreate) == 0); wq = pthread_getspecific(wq_key); if (!wq) { @@ -2497,7 +2497,7 @@ static zlcList_t *zlcCur = NULL; static void AddToZLCDeleteList(char dir, char *name) { - assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); + osi_Assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); if (!zlcCur || zlcCur->zlc_n >= MAX_ZLC_NAMES) { if (zlcCur && zlcCur->zlc_next) diff --git a/src/vol/ntops.c b/src/vol/ntops.c index 056aeba20..a36b4ea24 100644 --- a/src/vol/ntops.c +++ b/src/vol/ntops.c @@ -1286,7 +1286,7 @@ static zlcList_t *zlcCur = NULL; static void AddToZLCDeleteList(char dir, char *name) { - assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); + osi_Assert(strlen(name) <= MAX_ZLC_NAMELEN - 3); if (!zlcCur || zlcCur->zlc_n >= MAX_ZLC_NAMES) { if (zlcCur && zlcCur->zlc_next) diff --git a/src/vol/nuke.c b/src/vol/nuke.c index 151f0bd62..f1add7bcf 100644 --- a/src/vol/nuke.c +++ b/src/vol/nuke.c @@ -14,11 +14,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include diff --git a/src/vol/partition.c b/src/vol/partition.c index 3ec83b656..6f304bb4c 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -127,11 +127,7 @@ #include "vnode.h" #include "volume.h" #include "partition.h" -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #if defined(AFS_HPUX_ENV) #include @@ -284,7 +280,7 @@ VInitPartition_r(char *path, char *devname, Device dev) #ifdef AFS_DEMAND_ATTACH_FS AddPartitionToTable_r(dp); queue_Init(&dp->vol_list.head); - assert(pthread_cond_init(&dp->vol_list.cv, NULL) == 0); + CV_INIT(&dp->vol_list.cv, "vol list", CV_DEFAULT, 0); dp->vol_list.len = 0; dp->vol_list.busy = 0; { @@ -362,7 +358,7 @@ VCheckPartition(char *part, char *devname) struct dirent *dp; dirp = opendir(part); - assert(dirp); + osi_Assert(dirp); while ((dp = readdir(dirp))) { if (dp->d_name[0] == 'V') { Log("This program is compiled with AFS_NAMEI_ENV, but partition %s seems to contain volumes which don't use the namei-interface; aborting\n", part); @@ -924,7 +920,7 @@ VGetPartition_r(char *name, int abortp) } #endif /* AFS_DEMAND_ATTACH_FS */ if (abortp) - assert(dp != NULL); + osi_Assert(dp != NULL); return dp; } @@ -1172,12 +1168,12 @@ VLockPartition_r(char *name) (FD_t)CreateFile(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_HIDDEN, NULL); - assert(dp->lock_fd != INVALID_FD); + osi_Assert(dp->lock_fd != INVALID_FD); memset(&lap, 0, sizeof(lap)); rc = LockFileEx((HANDLE) dp->lock_fd, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &lap); - assert(rc); + osi_Assert(rc); } } @@ -1262,11 +1258,11 @@ VLockPartition_r(char *name) pausing.tv_usec = 500000; select(0, NULL, NULL, NULL, &pausing); } - assert(retries != 0); + osi_Assert(retries != 0); #if defined (AFS_HPUX_ENV) - assert(getprivgrp(privGrpList) == 0); + osi_Assert(getprivgrp(privGrpList) == 0); /* * In general, it will difficult and time-consuming ,if not impossible, @@ -1287,26 +1283,26 @@ VLockPartition_r(char *name) if (((*globalMask) & privmask(PRIV_LOCKRDONLY)) == 0) { /* allow everybody to set a lock on a read-only file descriptor */ (*globalMask) |= privmask(PRIV_LOCKRDONLY); - assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) + osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) == 0); lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); /* remove the privilege granted to everybody to lock a read-only fd */ (*globalMask) &= ~(privmask(PRIV_LOCKRDONLY)); - assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) + osi_Assert(setprivgrp(PRIV_GLOBAL, privGrpList[globalMaskIndex].priv_mask) == 0); } else { /* in this case, we should be able to do this with impunity, anyway */ lockfRtn = lockf(dp->lock_fd, F_LOCK, 0); } - assert(lockfRtn != -1); + osi_Assert(lockfRtn != -1); #else #if defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) - assert(lockf(dp->lock_fd, F_LOCK, 0) != -1); + osi_Assert(lockf(dp->lock_fd, F_LOCK, 0) != -1); #else - assert(flock(dp->lock_fd, LOCK_EX) == 0); + osi_Assert(flock(dp->lock_fd, LOCK_EX) == 0); #endif /* defined(AFS_AIX_ENV) || defined(AFS_SUN5_ENV) */ #endif } @@ -1413,7 +1409,7 @@ VGetPartitionById_r(afs_int32 id, int abortp) } if (abortp) { - assert(dp != NULL); + osi_Assert(dp != NULL); } return dp; } @@ -1457,7 +1453,7 @@ VLookupPartition_r(char * path) static void AddPartitionToTable_r(struct DiskPartition64 *dp) { - assert(dp->index >= 0 && dp->index <= VOLMAXPARTS); + osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS); DiskPartitionTable[dp->index] = dp; } @@ -1465,7 +1461,7 @@ AddPartitionToTable_r(struct DiskPartition64 *dp) static void DeletePartitionFromTable_r(struct DiskPartition64 *dp) { - assert(dp->index >= 0 && dp->index <= VOLMAXPARTS); + osi_Assert(dp->index >= 0 && dp->index <= VOLMAXPARTS); DiskPartitionTable[dp->index] = NULL; } #endif diff --git a/src/vol/physio.c b/src/vol/physio.c index e5ef1925d..673b611af 100644 --- a/src/vol/physio.c +++ b/src/vol/physio.c @@ -165,5 +165,5 @@ void Die(char *msg) { printf("%s\n", msg); - assert(1 == 2); + osi_Panic("%s\n", msg); } diff --git a/src/vol/salvaged.c b/src/vol/salvaged.c index 563222ff5..087325888 100644 --- a/src/vol/salvaged.c +++ b/src/vol/salvaged.c @@ -508,7 +508,7 @@ SalvageServer(int argc, char **argv) ObtainSharedSalvageLock(); child_slot = (int *) malloc(Parallel * sizeof(int)); - assert(child_slot != NULL); + osi_Assert(child_slot != NULL); memset(child_slot, 0, Parallel * sizeof(int)); /* initialize things */ @@ -520,22 +520,22 @@ SalvageServer(int argc, char **argv) DInit(10); queue_Init(&pending_q); queue_Init(&log_cleanup_queue); - assert(pthread_mutex_init(&worker_lock, NULL) == 0); - assert(pthread_cond_init(&worker_cv, NULL) == 0); - assert(pthread_cond_init(&log_cleanup_queue.queue_change_cv, NULL) == 0); - assert(pthread_attr_init(&attrs) == 0); + MUTEX_INIT(&worker_lock, "worker", MUTEX_DEFAULT, 0); + CV_INIT(&worker_cv, "worker", CV_DEFAULT, 0); + CV_INIT(&log_cleanup_queue.queue_change_cv, "queuechange", CV_DEFAULT, 0); + osi_Assert(pthread_attr_init(&attrs) == 0); /* start up the reaper and log cleaner threads */ - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&tid, + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&tid, &attrs, &SalvageChildReaperThread, NULL) == 0); - assert(pthread_create(&tid, + osi_Assert(pthread_create(&tid, &attrs, &SalvageLogCleanupThread, NULL) == 0); - assert(pthread_create(&tid, + osi_Assert(pthread_create(&tid, &attrs, &SalvageLogScanningThread, NULL) == 0); @@ -543,7 +543,7 @@ SalvageServer(int argc, char **argv) /* loop forever serving requests */ while (1) { node = SALVSYNC_getWork(); - assert(node != NULL); + osi_Assert(node != NULL); Log("dispatching child to salvage volume %u...\n", node->command.sop.parent); @@ -554,7 +554,7 @@ SalvageServer(int argc, char **argv) if (!child_slot[slot]) break; } - assert (slot < Parallel); + osi_Assert (slot < Parallel); do_fork: pid = Fork(); @@ -571,17 +571,17 @@ SalvageServer(int argc, char **argv) node->pid = pid; VOL_UNLOCK; - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); current_workers++; /* let the reaper thread know another worker was spawned */ - assert(pthread_cond_broadcast(&worker_cv) == 0); + CV_BROADCAST(&worker_cv); /* if we're overquota, wait for the reaper */ while (current_workers >= Parallel) { - assert(pthread_cond_wait(&worker_cv, &worker_lock) == 0); + CV_WAIT(&worker_cv, &worker_lock); } - assert(pthread_mutex_unlock(&worker_lock) == 0); + MUTEX_EXIT(&worker_lock); } } } @@ -639,17 +639,17 @@ SalvageChildReaperThread(void * args) int slot, pid, status; struct log_cleanup_node * cleanup; - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); /* loop reaping our children */ while (1) { /* wait() won't block unless we have children, so * block on the cond var if we're childless */ while (current_workers == 0) { - assert(pthread_cond_wait(&worker_cv, &worker_lock) == 0); + CV_WAIT(&worker_cv, &worker_lock); } - assert(pthread_mutex_unlock(&worker_lock) == 0); + MUTEX_EXIT(&worker_lock); cleanup = (struct log_cleanup_node *) malloc(sizeof(struct log_cleanup_node)); @@ -663,23 +663,23 @@ SalvageChildReaperThread(void * args) if (child_slot[slot] == pid) break; } - assert(slot < Parallel); + osi_Assert(slot < Parallel); child_slot[slot] = 0; VOL_UNLOCK; SALVSYNC_doneWorkByPid(pid, status); - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); if (cleanup) { cleanup->pid = pid; queue_Append(&log_cleanup_queue, cleanup); - assert(pthread_cond_signal(&log_cleanup_queue.queue_change_cv) == 0); + CV_SIGNAL(&log_cleanup_queue.queue_change_cv); } /* ok, we've reaped a child */ current_workers--; - assert(pthread_cond_broadcast(&worker_cv) == 0); + CV_BROADCAST(&worker_cv); } return NULL; @@ -714,24 +714,24 @@ SalvageLogCleanupThread(void * arg) { struct log_cleanup_node * cleanup; - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); while (1) { while (queue_IsEmpty(&log_cleanup_queue)) { - assert(pthread_cond_wait(&log_cleanup_queue.queue_change_cv, &worker_lock) == 0); + CV_WAIT(&log_cleanup_queue.queue_change_cv, &worker_lock); } while (queue_IsNotEmpty(&log_cleanup_queue)) { cleanup = queue_First(&log_cleanup_queue, log_cleanup_node); queue_Remove(cleanup); - assert(pthread_mutex_unlock(&worker_lock) == 0); + MUTEX_EXIT(&worker_lock); SalvageLogCleanup(cleanup->pid); free(cleanup); - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); } } - assert(pthread_mutex_unlock(&worker_lock) == 0); + MUTEX_EXIT(&worker_lock); return NULL; } @@ -793,7 +793,7 @@ SalvageLogScanningThread(void * arg) prefix_len = strlen(prefix); dp = opendir(AFSDIR_LOGS_DIR); - assert(dp); + osi_Assert(dp); while ((dirp = readdir(dp)) != NULL) { pid_t pid; @@ -859,7 +859,7 @@ ScanLogs(struct rx_queue *log_watch_queue) { struct log_cleanup_node *cleanup, *next; - assert(pthread_mutex_lock(&worker_lock) == 0); + MUTEX_ENTER(&worker_lock); for (queue_Scan(log_watch_queue, cleanup, next, log_cleanup_node)) { /* if a process is still running, assume it's the salvage process @@ -867,9 +867,9 @@ ScanLogs(struct rx_queue *log_watch_queue) if (kill(cleanup->pid, 0) < 0 && errno == ESRCH) { queue_Remove(cleanup); queue_Append(&log_cleanup_queue, cleanup); - assert(pthread_cond_signal(&log_cleanup_queue.queue_change_cv) == 0); + CV_SIGNAL(&log_cleanup_queue.queue_change_cv); } } - assert(pthread_mutex_unlock(&worker_lock) == 0); + MUTEX_EXIT(&worker_lock); } diff --git a/src/vol/salvsync-client.c b/src/vol/salvsync-client.c index 814cbcaf6..84d65ed43 100644 --- a/src/vol/salvsync-client.c +++ b/src/vol/salvsync-client.c @@ -31,7 +31,6 @@ #include #endif #include -#include #include #include diff --git a/src/vol/salvsync-server.c b/src/vol/salvsync-server.c index db5848a02..348eba4d2 100644 --- a/src/vol/salvsync-server.c +++ b/src/vol/salvsync-server.c @@ -40,7 +40,7 @@ #include #endif #include -#include +#include #include #include @@ -274,27 +274,27 @@ SALVSYNC_salvInit(void) /* initialize the queues */ Lock_Init(&SALVSYNC_handler_lock); - assert(pthread_cond_init(&salvageQueue.cv, NULL) == 0); + CV_INIT(&salvageQueue.cv, "sq", CV_DEFAULT, 0); for (i = 0; i <= VOLMAXPARTS; i++) { queue_Init(&salvageQueue.part[i]); salvageQueue.len[i] = 0; } - assert(pthread_cond_init(&pendingQueue.queue_change_cv, NULL) == 0); + CV_INIT(&pendingQueue.queue_change_cv, "queuechange", CV_DEFAULT, 0); queue_Init(&pendingQueue); salvageQueue.total_len = pendingQueue.len = 0; salvageQueue.last_insert = -1; memset(partition_salvaging, 0, sizeof(partition_salvaging)); for (i = 0; i < VSHASH_SIZE; i++) { - assert(pthread_cond_init(&SalvageHashTable[i].queue_change_cv, NULL) == 0); + CV_INIT(&SalvageHashTable[i].queue_change_cv, "queuechange", CV_DEFAULT, 0); SalvageHashTable[i].len = 0; queue_Init(&SalvageHashTable[i]); } /* start the salvsync thread */ - assert(pthread_attr_init(&tattr) == 0); - assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&tid, &tattr, SALVSYNC_syncThread, NULL) == 0); + osi_Assert(pthread_attr_init(&tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&tid, &tattr, SALVSYNC_syncThread, NULL) == 0); } static void @@ -324,7 +324,7 @@ SALVSYNC_syncThread(void * args) /* when we fork, the child needs to close the salvsync server sockets, * otherwise, it may get salvsync requests, instead of the parent * salvageserver */ - assert(pthread_atfork(NULL, NULL, CleanFDs) == 0); + osi_Assert(pthread_atfork(NULL, NULL, CleanFDs) == 0); SYNC_getAddr(&state->endpoint, &state->addr); SYNC_cleanupSock(state); @@ -335,7 +335,7 @@ SALVSYNC_syncThread(void * args) state->fd = SYNC_getSock(&state->endpoint); code = SYNC_bindSock(state); - assert(!code); + osi_Assert(!code); InitHandler(); AcceptOn(); @@ -367,11 +367,10 @@ SALVSYNC_newconnection(int afd) junk = sizeof(other); fd = accept(afd, (struct sockaddr *)&other, &junk); if (fd == -1) { - Log("SALVSYNC_newconnection: accept failed, errno==%d\n", errno); - assert(1 == 2); + osi_Panic("SALVSYNC_newconnection: accept failed, errno==%d\n", errno); } else if (!AddHandler(fd, SALVSYNC_com)) { AcceptOff(); - assert(AddHandler(fd, SALVSYNC_com)); + osi_Assert(AddHandler(fd, SALVSYNC_com)); } } @@ -777,7 +776,7 @@ static void AcceptOn(void) { if (AcceptHandler == -1) { - assert(AddHandler(salvsync_server_state.fd, SALVSYNC_newconnection)); + osi_Assert(AddHandler(salvsync_server_state.fd, SALVSYNC_newconnection)); AcceptHandler = FindHandler(salvsync_server_state.fd); } } @@ -786,7 +785,7 @@ static void AcceptOff(void) { if (AcceptHandler != -1) { - assert(RemoveHandler(salvsync_server_state.fd)); + osi_Assert(RemoveHandler(salvsync_server_state.fd)); AcceptHandler = -1; } } @@ -849,7 +848,7 @@ FindHandler(osi_socket afd) return i; } ReleaseReadLock(&SALVSYNC_handler_lock); /* just in case */ - assert(1 == 2); + osi_Panic("Failed to find handler\n"); return -1; /* satisfy compiler */ } @@ -861,7 +860,7 @@ FindHandler_r(osi_socket afd) if (HandlerFD[i] == afd) { return i; } - assert(1 == 2); + osi_Panic("Failed to find handler\n"); return -1; /* satisfy compiler */ } @@ -1066,7 +1065,7 @@ AddToSalvageQueue(struct SalvageQueueNode * node) UpdateCommandPrio(node); } - assert(pthread_cond_broadcast(&salvageQueue.cv) == 0); + CV_BROADCAST(&salvageQueue.cv); return 0; } @@ -1078,7 +1077,7 @@ DeleteFromSalvageQueue(struct SalvageQueueNode * node) salvageQueue.len[node->partition_id]--; salvageQueue.total_len--; node->state = SALVSYNC_STATE_UNKNOWN; - assert(pthread_cond_broadcast(&salvageQueue.cv) == 0); + CV_BROADCAST(&salvageQueue.cv); } } @@ -1088,7 +1087,7 @@ AddToPendingQueue(struct SalvageQueueNode * node) queue_Append(&pendingQueue, node); pendingQueue.len++; node->state = SALVSYNC_STATE_SALVAGING; - assert(pthread_cond_broadcast(&pendingQueue.queue_change_cv) == 0); + CV_BROADCAST(&pendingQueue.queue_change_cv); } static void @@ -1098,7 +1097,7 @@ DeleteFromPendingQueue(struct SalvageQueueNode * node) queue_Remove(node); pendingQueue.len--; node->state = SALVSYNC_STATE_UNKNOWN; - assert(pthread_cond_broadcast(&pendingQueue.queue_change_cv) == 0); + CV_BROADCAST(&pendingQueue.queue_change_cv); } } @@ -1145,7 +1144,7 @@ UpdateCommandPrio(struct SalvageQueueNode * node) afs_int32 id; afs_uint32 prio; - assert(queue_IsOnQueue(node)); + osi_Assert(queue_IsOnQueue(node)); prio = node->command.sop.prio; id = node->partition_id; @@ -1234,10 +1233,10 @@ SALVSYNC_getWork(void) } /* we should never reach this line */ - assert(1==2); + osi_Panic("Node not found\n"); have_node: - assert(node != NULL); + osi_Assert(node != NULL); node->pid = 0; partition_salvaging[node->partition_id]++; DeleteFromSalvageQueue(node); diff --git a/src/vol/vg_cache.c b/src/vol/vg_cache.c index ce6376da5..17d3fa352 100644 --- a/src/vol/vg_cache.c +++ b/src/vol/vg_cache.c @@ -110,7 +110,7 @@ VVGCache_PkgInit(void) for (i = 0; i <= VOLMAXPARTS; i++) { VVGCache.part[i].state = VVGC_PART_STATE_INVALID; VVGCache.part[i].dlist_hash_buckets = NULL; - code = pthread_cond_init(&VVGCache.part[i].cv, NULL); + CV_INIT(&VVGCache.part[i].cv, "cache part", CV_DEFAULT, 0); if (code) { goto error; } @@ -142,7 +142,7 @@ VVGCache_PkgShutdown(void) /* destroy per-partition VVGC state */ for (i = 0; i <= VOLMAXPARTS; i++) { VVGCache.part[i].state = VVGC_PART_STATE_INVALID; - pthread_cond_destroy(&VVGCache.part[i].cv); + CV_DESTROY(&VVGCache.part[i].cv); } return EOPNOTSUPP; @@ -191,7 +191,7 @@ _VVGC_entry_free(VVGCache_entry_t * entry) { int code = 0; - assert(entry->refcnt == 0); + osi_Assert(entry->refcnt == 0); free(entry); return code; @@ -380,7 +380,7 @@ _VVGC_entry_put(struct DiskPartition64 * dp, VVGCache_entry_t * entry) { int code = 0; - assert(entry->refcnt > 0); + osi_Assert(entry->refcnt > 0); if (--entry->refcnt == 0) { VVGCache_entry_t *nentry; @@ -772,7 +772,7 @@ VVGCache_entry_add_r(struct DiskPartition64 * dp, } } - assert(!child_ent); + osi_Assert(!child_ent); child_ent = parent_ent; code = _VVGC_hash_entry_add(dp, child, @@ -1185,7 +1185,7 @@ _VVGC_state_change(struct DiskPartition64 * part, VVGCache.part[part->index].state = state; if (old_state != state) { - pthread_cond_broadcast(&VVGCache.part[part->index].cv); + CV_BROADCAST(&VVGCache.part[part->index].cv); } return old_state; diff --git a/src/vol/vg_scan.c b/src/vol/vg_scan.c index df8759121..752187822 100644 --- a/src/vol/vg_scan.c +++ b/src/vol/vg_scan.c @@ -431,7 +431,7 @@ _VVGC_scan_start(struct DiskPartition64 * dp) ViceLog(0, ("_VVGC_scan_start: pthread_create failed with %d\n", code)); old_state = _VVGC_state_change(dp, VVGC_PART_STATE_INVALID); - assert(old_state == VVGC_PART_STATE_UPDATING); + osi_Assert(old_state == VVGC_PART_STATE_UPDATING); } error: diff --git a/src/vol/vnode.c b/src/vol/vnode.c index 086d639e1..a111cc7a6 100644 --- a/src/vol/vnode.c +++ b/src/vol/vnode.c @@ -24,11 +24,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include "rx/rx_queue.h" @@ -381,7 +377,7 @@ VInitVnodes(VnodeClass class, int nVnodes) vcp->cacheSize = nVnodes; switch (class) { case vSmall: - assert(CHECKSIZE_SMALLVNODE); + osi_Assert(CHECKSIZE_SMALLVNODE); vcp->lruHead = NULL; vcp->residentSize = SIZEOF_SMALLVNODE; vcp->diskSize = SIZEOF_SMALLDISKVNODE; @@ -406,13 +402,13 @@ VInitVnodes(VnodeClass class, int nVnodes) return 0; va = (byte *) calloc(nVnodes, vcp->residentSize); - assert(va != NULL); + osi_Assert(va != NULL); while (nVnodes--) { Vnode *vnp = (Vnode *) va; Vn_refcount(vnp) = 0; /* no context switches */ Vn_stateFlags(vnp) |= VN_ON_LRU; #ifdef AFS_DEMAND_ATTACH_FS - assert(pthread_cond_init(&Vn_stateCV(vnp), NULL) == 0); + CV_INIT(&Vn_stateCV(vnp), "vnode state", CV_DEFAULT, 0); Vn_state(vnp) = VN_STATE_INVALID; Vn_readers(vnp) = 0; #else /* !AFS_DEMAND_ATTACH_FS */ @@ -1065,7 +1061,7 @@ VnStore(Error * ec, Volume * vp, Vnode * vnp, VnChangeState_r(vnp, VN_STATE_ERROR); VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0); #else - assert(1 == 2); + osi_Assert(1 == 2); #endif } @@ -1313,10 +1309,10 @@ VPutVnode_r(Error * ec, Vnode * vnp) struct VnodeClassInfo *vcp; *ec = 0; - assert(Vn_refcount(vnp) != 0); + osi_Assert(Vn_refcount(vnp) != 0); class = vnodeIdToClass(Vn_id(vnp)); vcp = &VnodeClassInfo[class]; - assert(vnp->disk.vnodeMagic == vcp->magic); + osi_Assert(vnp->disk.vnodeMagic == vcp->magic); VNLog(200, 2, Vn_id(vnp), (intptr_t) vnp, 0, 0); #ifdef AFS_DEMAND_ATTACH_FS @@ -1345,7 +1341,7 @@ VPutVnode_r(Error * ec, Vnode * vnp) if (vnp->changed_oldTime || vnp->changed_newTime || vnp->delete) { Volume *vp = Vn_volume(vnp); afs_uint32 now = FT_ApproxTime(); - assert(Vn_cacheCheck(vnp) == vp->cacheCheck); + osi_Assert(Vn_cacheCheck(vnp) == vp->cacheCheck); if (vnp->delete) { /* No longer any directory entries for this vnode. Free the Vnode */ @@ -1367,7 +1363,7 @@ VPutVnode_r(Error * ec, Vnode * vnp) #ifdef AFS_DEMAND_ATTACH_FS VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0); #else - assert(V_needsSalvaged(vp)); + osi_Assert(V_needsSalvaged(vp)); *ec = VSALVAGE; #endif } else { @@ -1454,10 +1450,10 @@ VVnodeWriteToRead_r(Error * ec, Vnode * vnp) #endif /* AFS_PTHREAD_ENV */ *ec = 0; - assert(Vn_refcount(vnp) != 0); + osi_Assert(Vn_refcount(vnp) != 0); class = vnodeIdToClass(Vn_id(vnp)); vcp = &VnodeClassInfo[class]; - assert(vnp->disk.vnodeMagic == vcp->magic); + osi_Assert(vnp->disk.vnodeMagic == vcp->magic); VNLog(300, 2, Vn_id(vnp), (intptr_t) vnp, 0, 0); #ifdef AFS_DEMAND_ATTACH_FS @@ -1491,7 +1487,7 @@ VVnodeWriteToRead_r(Error * ec, Vnode * vnp) if (vnp->changed_oldTime || vnp->changed_newTime) { Volume *vp = Vn_volume(vnp); afs_uint32 now = FT_ApproxTime(); - assert(Vn_cacheCheck(vnp) == vp->cacheCheck); + osi_Assert(Vn_cacheCheck(vnp) == vp->cacheCheck); if (vnp->changed_newTime) vnp->disk.serverModifyTime = now; if (vnp->changed_newTime) @@ -1502,7 +1498,7 @@ VVnodeWriteToRead_r(Error * ec, Vnode * vnp) #ifdef AFS_DEMAND_ATTACH_FS VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0); #else - assert(V_needsSalvaged(vp)); + osi_Assert(V_needsSalvaged(vp)); *ec = VSALVAGE; #endif } else { @@ -1646,7 +1642,7 @@ VCloseVnodeFiles_r(Volume * vp) #endif /* AFS_DEMAND_ATTACH_FS */ /* XXX need better error handling here */ - assert(VInvalidateVnodesByVolume_r(vp, + osi_Assert(VInvalidateVnodesByVolume_r(vp, &ih_vec, &vec_len) == 0); @@ -1710,7 +1706,7 @@ VReleaseVnodeFiles_r(Volume * vp) #endif /* AFS_DEMAND_ATTACH_FS */ /* XXX need better error handling here */ - assert(VInvalidateVnodesByVolume_r(vp, + osi_Assert(VInvalidateVnodesByVolume_r(vp, &ih_vec, &vec_len) == 0); diff --git a/src/vol/vnode_inline.h b/src/vol/vnode_inline.h index 506922d60..f31c5ca29 100644 --- a/src/vol/vnode_inline.h +++ b/src/vol/vnode_inline.h @@ -168,7 +168,7 @@ VnChangeState_r(Vnode * vnp, VnState new_state) VnState old_state = Vn_state(vnp); Vn_state(vnp) = new_state; - assert(pthread_cond_broadcast(&Vn_stateCV(vnp)) == 0); + CV_BROADCAST(&Vn_stateCV(vnp)); return old_state; } @@ -259,11 +259,11 @@ VnWaitStateChange_r(Vnode * vnp) { VnState state_save = Vn_state(vnp); - assert(Vn_refcount(vnp)); + osi_Assert(Vn_refcount(vnp)); do { VOL_CV_WAIT(&Vn_stateCV(vnp)); } while (Vn_state(vnp) == state_save); - assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); + osi_Assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); } /** @@ -280,11 +280,11 @@ VnWaitStateChange_r(Vnode * vnp) static_inline void VnWaitExclusiveState_r(Vnode * vnp) { - assert(Vn_refcount(vnp)); + osi_Assert(Vn_refcount(vnp)); while (VnIsExclusiveState(Vn_state(vnp))) { VOL_CV_WAIT(&Vn_stateCV(vnp)); } - assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); + osi_Assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); } /** @@ -301,12 +301,12 @@ VnWaitExclusiveState_r(Vnode * vnp) static_inline void VnWaitQuiescent_r(Vnode * vnp) { - assert(Vn_refcount(vnp)); + osi_Assert(Vn_refcount(vnp)); while (VnIsExclusiveState(Vn_state(vnp)) || Vn_readers(vnp)) { VOL_CV_WAIT(&Vn_stateCV(vnp)); } - assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); + osi_Assert(!(Vn_stateFlags(vnp) & VN_ON_LRU)); } /** @@ -329,11 +329,11 @@ static_inline void VnBeginRead_r(Vnode * vnp) { if (!Vn_readers(vnp)) { - assert(Vn_state(vnp) == VN_STATE_ONLINE); + osi_Assert(Vn_state(vnp) == VN_STATE_ONLINE); VnChangeState_r(vnp, VN_STATE_READ); } Vn_readers(vnp)++; - assert(Vn_state(vnp) == VN_STATE_READ); + osi_Assert(Vn_state(vnp) == VN_STATE_READ); } /** @@ -356,10 +356,10 @@ VnBeginRead_r(Vnode * vnp) static_inline void VnEndRead_r(Vnode * vnp) { - assert(Vn_readers(vnp) > 0); + osi_Assert(Vn_readers(vnp) > 0); Vn_readers(vnp)--; if (!Vn_readers(vnp)) { - assert(pthread_cond_broadcast(&Vn_stateCV(vnp)) == 0); + CV_BROADCAST(&Vn_stateCV(vnp)); VnChangeState_r(vnp, VN_STATE_ONLINE); } } diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index ccb1ae5eb..97f00e97c 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -402,7 +402,7 @@ IsPartitionMounted(char *part) FILE *mntfp; struct mntent *mntent; - assert(mntfp = setmntent(MOUNTED, "r")); + osi_Assert(mntfp = setmntent(MOUNTED, "r")); while (mntent = getmntent(mntfp)) { if (!strcmp(part, mntent->mnt_dir)) break; @@ -581,12 +581,12 @@ SalvageFileSysParallel(struct DiskPartition64 *partP) * job to finish. When it's done, clean up after it. */ pid = wait(&wstatus); - assert(pid != -1); + osi_Assert(pid != -1); for (j = 0; j < numjobs; j++) { /* Find which job it is */ if (pid == jobs[j]->pid) break; } - assert(j < numjobs); + osi_Assert(j < numjobs); if (WCOREDUMP(wstatus)) { /* Say if the job core dumped */ Log("Salvage of %s core dumped!\n", jobs[j]->partP->name); } @@ -820,7 +820,7 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) DIR *dirp; struct dirent *dp; - assert((dirp = opendir(salvinfo->fileSysPath)) != NULL); + osi_Assert((dirp = opendir(salvinfo->fileSysPath)) != NULL); while ((dp = readdir(dirp))) { if (!strncmp(dp->d_name, "salvage.inodes.", 15) || !strncmp(dp->d_name, "salvage.temp.", 13)) { @@ -1255,16 +1255,16 @@ GetInodeSummary(struct SalvInfo *salvinfo, FILE *inodeFile, VolumeId singleVolum Exit(1); /* salvage of this partition aborted */ } } - assert(afs_fstat(fileno(summaryFile), &status) != -1); + osi_Assert(afs_fstat(fileno(summaryFile), &status) != -1); if (status.st_size != 0) { int ret; unsigned long st_status=(unsigned long)status.st_size; salvinfo->inodeSummary = (struct InodeSummary *)malloc(st_status); - assert(salvinfo->inodeSummary != NULL); + osi_Assert(salvinfo->inodeSummary != NULL); /* For GNU we need to do lseek to get the file pointer moved. */ - assert(afs_lseek(fileno(summaryFile), 0, SEEK_SET) == 0); + osi_Assert(afs_lseek(fileno(summaryFile), 0, SEEK_SET) == 0); ret = read(fileno(summaryFile), salvinfo->inodeSummary, st_status); - assert(ret == st_status); + osi_Assert(ret == st_status); } salvinfo->nVolumesInInodeFile =(unsigned long)(status.st_size) / sizeof(struct InodeSummary); for (i = 0; i < salvinfo->nVolumesInInodeFile; i++) { @@ -1389,7 +1389,7 @@ AskVolumeSummary(struct SalvInfo *salvinfo, VolumeId singleVolumeNumber) } salvinfo->volumeSummaryp = malloc(VOL_VG_MAX_VOLS * sizeof(struct VolumeSummary)); - assert(salvinfo->volumeSummaryp != NULL); + osi_Assert(salvinfo->volumeSummaryp != NULL); salvinfo->nVolumes = 0; vsp = salvinfo->volumeSummaryp; @@ -1705,7 +1705,7 @@ GetVolumeSummary(struct SalvInfo *salvinfo, VolumeId singleVolumeNumber) } salvinfo->volumeSummaryp = malloc(nvols * sizeof(struct VolumeSummary)); - assert(salvinfo->volumeSummaryp != NULL); + osi_Assert(salvinfo->volumeSummaryp != NULL); params.singleVolumeNumber = singleVolumeNumber; params.vsp = salvinfo->volumeSummaryp; @@ -1875,10 +1875,10 @@ DoSalvageVolumeGroup(struct SalvInfo *salvinfo, struct InodeSummary *isp, int nV allInodes = inodes - isp->index; /* this would the base of all the inodes * for the partition, if all the inodes * had been read into memory */ - assert(afs_lseek + osi_Assert(afs_lseek (salvinfo->inodeFd, isp->index * sizeof(struct ViceInodeInfo), SEEK_SET) != -1); - assert(read(salvinfo->inodeFd, inodes, size) == size); + osi_Assert(read(salvinfo->inodeFd, inodes, size) == size); /* Don't try to salvage a read write volume if there isn't one on this * partition */ @@ -2537,16 +2537,16 @@ SalvageIndex(struct SalvInfo *salvinfo, Inode ino, VnodeClass class, int RW, IH_INIT(handle, salvinfo->fileSysDevice, volSummary->header.parent, ino); fdP = IH_OPEN(handle); - assert(fdP != NULL); + osi_Assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r+"); - assert(file != NULL); + osi_Assert(file != NULL); vcp = &VnodeClassInfo[class]; size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - assert((nVnodes + 1) * vcp->diskSize == size); - assert(STREAM_ASEEK(file, vcp->diskSize) == 0); + osi_Assert((nVnodes + 1) * vcp->diskSize == size); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else { nVnodes = 0; } @@ -2754,9 +2754,9 @@ SalvageIndex(struct SalvInfo *salvinfo, Inode ino, VnodeClass class, int RW, } } /* VNDISK_GET_INO(vnode) != 0 */ vnodeDone: - assert(!(vnodeChanged && check)); + osi_Assert(!(vnodeChanged && check)); if (vnodeChanged && !Testing) { - assert(IH_IWRITE + osi_Assert(IH_IWRITE (handle, vnodeIndexOffset(vcp, vnodeNumber), (char *)vnode, vcp->diskSize) == vcp->diskSize); @@ -2803,7 +2803,7 @@ CopyOnWrite(struct SalvInfo *salvinfo, struct DirSummary *dir) IH_IREAD(salvinfo->vnodeInfo[vLarge].handle, vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(code == sizeof(vnode)); + osi_Assert(code == sizeof(vnode)); oldinode = VNDISK_GET_INO(&vnode); /* Increment the version number by a whole lot to avoid problems with * clients that were promised new version numbers--but the file server @@ -2813,15 +2813,15 @@ CopyOnWrite(struct SalvInfo *salvinfo, struct DirSummary *dir) IH_CREATE(dir->ds_linkH, salvinfo->fileSysDevice, salvinfo->fileSysPath, 0, dir->rwVid, dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion += 200); - assert(VALID_INO(newinode)); - assert(CopyInode(salvinfo->fileSysDevice, oldinode, newinode, dir->rwVid) == 0); + osi_Assert(VALID_INO(newinode)); + osi_Assert(CopyInode(salvinfo->fileSysDevice, oldinode, newinode, dir->rwVid) == 0); vnode.cloned = 0; VNDISK_SET_INO(&vnode, newinode); code = IH_IWRITE(salvinfo->vnodeInfo[vLarge].handle, vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(code == sizeof(vnode)); + osi_Assert(code == sizeof(vnode)); SetSalvageDirHandle(&dir->dirHandle, dir->dirHandle.dirh_handle->ih_vid, salvinfo->fileSysDevice, newinode, @@ -2859,7 +2859,7 @@ CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir) IH_IREAD(salvinfo->vnodeInfo[vLarge].handle, vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(lcode == sizeof(vnode)); + osi_Assert(lcode == sizeof(vnode)); oldinode = VNDISK_GET_INO(&vnode); /* Increment the version number by a whole lot to avoid problems with * clients that were promised new version numbers--but the file server @@ -2869,7 +2869,7 @@ CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir) IH_CREATE(dir->ds_linkH, salvinfo->fileSysDevice, salvinfo->fileSysPath, 0, dir->rwVid, dir->vnodeNumber, vnode.uniquifier, vnode.dataVersion += 200); - assert(VALID_INO(newinode)); + osi_Assert(VALID_INO(newinode)); SetSalvageDirHandle(&newdir, dir->rwVid, salvinfo->fileSysDevice, newinode, &salvinfo->VolumeChanged); @@ -2895,14 +2895,14 @@ CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir) if (code) { Log("also failed to decrement link count on new inode"); } - assert(1 == 2); + osi_Assert(1 == 2); } Log("Checking the results of the directory salvage...\n"); if (!DirOK(&newdir)) { Log("Directory salvage failed!!!; restoring old version of the directory.\n"); code = IH_DEC(dir->ds_linkH, newinode, dir->rwVid); - assert(code == 0); - assert(1 == 2); + osi_Assert(code == 0); + osi_Assert(1 == 2); } vnode.cloned = 0; VNDISK_SET_INO(&vnode, newinode); @@ -2912,7 +2912,7 @@ CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir) IH_IWRITE(salvinfo->vnodeInfo[vLarge].handle, vnodeIndexOffset(vcp, dir->vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(lcode == sizeof(vnode)); + osi_Assert(lcode == sizeof(vnode)); #if 0 #ifdef AFS_NT40_ENV nt_sync(salvinfo->fileSysDevice); @@ -2929,7 +2929,7 @@ CopyAndSalvage(struct SalvInfo *salvinfo, struct DirSummary *dir) FDH_REALLYCLOSE(fdP); code = IH_DEC(dir->ds_linkH, oldinode, dir->rwVid); - assert(code == 0); + osi_Assert(code == 0); dir->dirHandle = newdir; } @@ -2960,7 +2960,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, } if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); } return 0; } @@ -2974,7 +2974,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, Log("dir vnode %d: invalid entry: %s/%s has no inode (vnode %d, unique %d)%s\n", dir->vnodeNumber, (dir->name ? dir->name : "??"), name, vnodeNumber, unique, (Testing ? "-- would have deleted" : " -- deleted")); if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); } return 0; } @@ -2992,7 +2992,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, if (!unique) { if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); } return 0; } @@ -3022,9 +3022,9 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, fid.Vnode = vnodeNumber; fid.Unique = vnodeEssence->unique; CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); if (!todelete) - assert(Create(&dir->dirHandle, name, &fid) == 0); + osi_Assert(Create(&dir->dirHandle, name, &fid) == 0); } if (todelete) return 0; /* no need to continue */ @@ -3037,10 +3037,10 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, Log("directory vnode %u.%u: bad '.' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique); if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, ".") == 0); + osi_Assert(Delete(&dir->dirHandle, ".") == 0); fid.Vnode = dir->vnodeNumber; fid.Unique = dir->unique; - assert(Create(&dir->dirHandle, ".", &fid) == 0); + osi_Assert(Create(&dir->dirHandle, ".", &fid) == 0); } vnodeNumber = fid.Vnode; /* Get the new Essence */ @@ -3054,7 +3054,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, struct VnodeEssence *dotdot; pa.Vnode = dir->parent; dotdot = CheckVnodeNumber(salvinfo, pa.Vnode); - assert(dotdot != NULL); /* XXX Should not be assert */ + osi_Assert(dotdot != NULL); /* XXX Should not be assert */ pa.Unique = dotdot->unique; } else { pa.Vnode = dir->vnodeNumber; @@ -3065,8 +3065,8 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, Log("directory vnode %u.%u: bad '..' entry (was %u.%u); fixed\n", dir->vnodeNumber, dir->unique, vnodeNumber, unique); if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, "..") == 0); - assert(Create(&dir->dirHandle, "..", &pa) == 0); + osi_Assert(Delete(&dir->dirHandle, "..") == 0); + osi_Assert(Create(&dir->dirHandle, "..", &pa) == 0); } vnodeNumber = pa.Vnode; /* Get the new Essence */ @@ -3080,7 +3080,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, } if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); } vnodeEssence->claimed = 0; /* Not claimed: Orphaned */ vnodeEssence->todelete = 1; /* Will later delete vnode and decr inode */ @@ -3174,7 +3174,7 @@ JudgeEntry(void *arock, char *name, afs_int32 vnodeNumber, } if (!Testing) { CopyOnWrite(salvinfo, dir); - assert(Delete(&dir->dirHandle, name) == 0); + osi_Assert(Delete(&dir->dirHandle, name) == 0); } return 0; } @@ -3202,19 +3202,19 @@ DistilVnodeEssence(struct SalvInfo *salvinfo, VolumeId rwVId, IH_INIT(vip->handle, salvinfo->fileSysDevice, rwVId, ino); fdP = IH_OPEN(vip->handle); - assert(fdP != NULL); + osi_Assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r+"); - assert(file != NULL); + osi_Assert(file != NULL); size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); vip->nVnodes = (size / vcp->diskSize) - 1; if (vip->nVnodes > 0) { - assert((vip->nVnodes + 1) * vcp->diskSize == size); - assert(STREAM_ASEEK(file, vcp->diskSize) == 0); - assert((vip->vnodes = (struct VnodeEssence *) + osi_Assert((vip->nVnodes + 1) * vcp->diskSize == size); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); + osi_Assert((vip->vnodes = (struct VnodeEssence *) calloc(vip->nVnodes, sizeof(struct VnodeEssence))) != NULL); if (class == vLarge) { - assert((vip->inodes = (Inode *) + osi_Assert((vip->inodes = (Inode *) calloc(vip->nVnodes, sizeof(Inode))) != NULL); } else { vip->inodes = NULL; @@ -3373,7 +3373,7 @@ SalvageDir(struct SalvInfo *salvinfo, char *name, VolumeId rwVid, judge_params.salvinfo = salvinfo; judge_params.dir = &dir; - assert(EnumerateDir(&dirHandle, JudgeEntry, &judge_params) == 0); + osi_Assert(EnumerateDir(&dirHandle, JudgeEntry, &judge_params) == 0); } /* Delete the old directory if it was copied in order to salvage. @@ -3384,7 +3384,7 @@ SalvageDir(struct SalvInfo *salvinfo, char *name, VolumeId rwVid, DFlush(); if (dir.copied && !Testing) { code = IH_DEC(dir.ds_linkH, dirHandle.dirh_handle->ih_ino, rwVid); - assert(code == 0); + osi_Assert(code == 0); dirVnodeInfo->inodes[i] = dir.dirHandle.dirh_inode; } @@ -3626,8 +3626,8 @@ CreateRootDir(struct SalvInfo *salvinfo, VolumeDiskData *volHeader, salvinfo->vnodeInfo[vLarge].vnodes = calloc(1, sizeof(struct VnodeEssence)); salvinfo->vnodeInfo[vLarge].inodes = calloc(1, sizeof(Inode)); - assert(salvinfo->vnodeInfo[vLarge].vnodes); - assert(salvinfo->vnodeInfo[vLarge].inodes); + osi_Assert(salvinfo->vnodeInfo[vLarge].vnodes); + osi_Assert(salvinfo->vnodeInfo[vLarge].inodes); } vep = &salvinfo->vnodeInfo[vLarge].vnodes[vnodeIdToBitNumber(1)]; @@ -3809,9 +3809,9 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * vid = rwIsp->volSummary->header.id; IH_INIT(h, salvinfo->fileSysDevice, vid, rwIsp->volSummary->header.volumeInfo); nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)); - assert(nBytes == sizeof(volHeader)); - assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); - assert(volHeader.destroyMe != DESTROY_ME); + osi_Assert(nBytes == sizeof(volHeader)); + osi_Assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); + osi_Assert(volHeader.destroyMe != DESTROY_ME); /* (should not have gotten this far with DESTROY_ME flag still set!) */ DistilVnodeEssence(salvinfo, vid, vLarge, @@ -3920,8 +3920,8 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * &salvinfo->VolumeChanged); pa.Vnode = LFVnode; pa.Unique = LFUnique; - assert(Delete(&dh, "..") == 0); - assert(Create(&dh, "..", &pa) == 0); + osi_Assert(Delete(&dh, "..") == 0); + osi_Assert(Create(&dh, "..", &pa) == 0); /* The original parent's link count was decremented above. * Here we increment the new parent's link count. @@ -3951,7 +3951,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * ThisUnique += 50; /* Try creating a different file */ } - assert(code == 0); + osi_Assert(code == 0); Log("Attaching orphaned %s to volume's root dir as %s\n", ((class == vLarge) ? "directory" : "file"), npath); } @@ -3964,7 +3964,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * code = IH_DEC(oldrootdir.ds_linkH, oldrootdir.dirHandle.dirh_inode, oldrootdir.rwVid); - assert(code == 0); + osi_Assert(code == 0); /* dirVnodeInfo->inodes[?] is not updated with new inode number */ } @@ -4002,7 +4002,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * IH_IREAD(salvinfo->vnodeInfo[class].handle, vnodeIndexOffset(vcp, vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(nBytes == sizeof(vnode)); + osi_Assert(nBytes == sizeof(vnode)); vnode.parent = vnp->parent; oldCount = vnode.linkCount; @@ -4013,7 +4013,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * if (orphaned) { if (!vnp->todelete) { /* Orphans should have already been attached (if requested) */ - assert(orphans != ORPH_ATTACH); + osi_Assert(orphans != ORPH_ATTACH); oblocks += vnp->blockCount; ofiles++; } @@ -4024,7 +4024,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * if (VNDISK_GET_INO(&vnode)) { code = IH_DEC(alinkH, VNDISK_GET_INO(&vnode), vid); - assert(code == 0); + osi_Assert(code == 0); } memset(&vnode, 0, sizeof(vnode)); } @@ -4042,7 +4042,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * IH_IWRITE(salvinfo->vnodeInfo[class].handle, vnodeIndexOffset(vcp, vnodeNumber), (char *)&vnode, sizeof(vnode)); - assert(nBytes == sizeof(vnode)); + osi_Assert(nBytes == sizeof(vnode)); } salvinfo->VolumeChanged = 1; } @@ -4112,7 +4112,7 @@ SalvageVolume(struct SalvInfo *salvinfo, struct InodeSummary *rwIsp, IHandle_t * salvinfo->VolumeChanged = 0; if (!Testing) { nBytes = IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader)); - assert(nBytes == sizeof(volHeader)); + osi_Assert(nBytes == sizeof(volHeader)); } if (!Showmode) { Log("%sSalvaged %s (%u): %d files, %d blocks\n", @@ -4135,15 +4135,15 @@ ClearROInUseBit(struct VolumeSummary *summary) VolumeDiskData volHeader; nBytes = IH_IREAD(h, 0, (char *)&volHeader, sizeof(volHeader)); - assert(nBytes == sizeof(volHeader)); - assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); + osi_Assert(nBytes == sizeof(volHeader)); + osi_Assert(volHeader.stamp.magic == VOLUMEINFOMAGIC); volHeader.inUse = 0; volHeader.needsSalvaged = 0; volHeader.inService = 1; volHeader.dontSalvage = DONT_SALVAGE; if (!Testing) { nBytes = IH_IWRITE(h, 0, (char *)&volHeader, sizeof(volHeader)); - assert(nBytes == sizeof(volHeader)); + osi_Assert(nBytes == sizeof(volHeader)); } } @@ -4275,7 +4275,7 @@ LockVolume(struct SalvInfo *salvinfo, VolumeId volumeId) * case). But if it's there enough that we can read it, but * somehow we cannot write to it to signify we're salvaging it, * we've got a big problem and we cannot continue. */ - assert(IH_IWRITE(h, 0, (char*)&volHeader, sizeof(volHeader)) == sizeof(volHeader)); + osi_Assert(IH_IWRITE(h, 0, (char*)&volHeader, sizeof(volHeader)) == sizeof(volHeader)); IH_RELEASE(h); } @@ -4372,14 +4372,14 @@ CopyInode(Device device, Inode inode1, Inode inode2, int rwvolume) IH_INIT(srcH, device, rwvolume, inode1); srcFdP = IH_OPEN(srcH); - assert(srcFdP != NULL); + osi_Assert(srcFdP != NULL); IH_INIT(destH, device, rwvolume, inode2); destFdP = IH_OPEN(destH); while ((nBytes = FDH_PREAD(srcFdP, buf, sizeof(buf), size)) > 0) { - assert(FDH_PWRITE(destFdP, buf, nBytes, size) == nBytes); + osi_Assert(FDH_PWRITE(destFdP, buf, nBytes, size) == nBytes); size += nBytes; } - assert(nBytes == 0); + osi_Assert(nBytes == 0); FDH_REALLYCLOSE(srcFdP); FDH_REALLYCLOSE(destFdP); IH_RELEASE(srcH); @@ -4396,11 +4396,11 @@ PrintInodeList(struct SalvInfo *salvinfo) int nInodes; afs_ino_str_t stmp; - assert(afs_fstat(salvinfo->inodeFd, &status) == 0); + osi_Assert(afs_fstat(salvinfo->inodeFd, &status) == 0); buf = (struct ViceInodeInfo *)malloc(status.st_size); - assert(buf != NULL); + osi_Assert(buf != NULL); nInodes = status.st_size / sizeof(struct ViceInodeInfo); - assert(read(salvinfo->inodeFd, buf, status.st_size) == status.st_size); + osi_Assert(read(salvinfo->inodeFd, buf, status.st_size) == status.st_size); for (ip = buf; nInodes--; ip++) { Log("Inode:%s, linkCount=%d, size=%#llx, p=(%u,%u,%u,%u)\n", PrintInode(stmp, ip->inodeNumber), ip->linkCount, @@ -4439,10 +4439,10 @@ Fork(void) int f; #ifdef AFS_NT40_ENV f = 0; - assert(0); /* Fork is never executed in the NT code path */ + osi_Assert(0); /* Fork is never executed in the NT code path */ #else f = fork(); - assert(f >= 0); + osi_Assert(f >= 0); #ifdef AFS_DEMAND_ATTACH_FS if ((f == 0) && (programType == salvageServer)) { /* we are a salvageserver child */ @@ -4491,7 +4491,7 @@ Wait(char *prog) int status; int pid; pid = wait(&status); - assert(pid != -1); + osi_Assert(pid != -1); if (WCOREDUMP(status)) Log("\"%s\" core dumped!\n", prog); if (WIFSIGNALED(status) != 0 || WEXITSTATUS(status) != 0) @@ -4645,7 +4645,7 @@ ToString(const char *s) { char *p; p = (char *)malloc(strlen(s) + 1); - assert(p != NULL); + osi_Assert(p != NULL); strcpy(p, s); return p; } diff --git a/src/vol/volume.c b/src/vol/volume.c index 77f31d349..1b0588824 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -124,12 +124,7 @@ #include "partition.h" #include "volume_inline.h" #include "common.h" - -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include "afs/afs_assert.h" -#endif /* AFS_PTHREAD_ENV */ #include "vutils.h" #ifndef AFS_NT40_ENV #include @@ -556,9 +551,7 @@ static void VSetVInit_r(int value) { VInit = value; -#ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&vol_vinit_cond) == 0); -#endif + CV_BROADCAST(&vol_vinit_cond); } int @@ -580,17 +573,16 @@ VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts) } else { VLRU_SetOptions(VLRU_SET_ENABLED, 0); } - assert(pthread_key_create(&VThread_key, NULL) == 0); + osi_Assert(pthread_key_create(&VThread_key, NULL) == 0); #endif -#ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&vol_glock_mutex, NULL) == 0); - assert(pthread_mutex_init(&vol_trans_mutex, NULL) == 0); - assert(pthread_cond_init(&vol_put_volume_cond, NULL) == 0); - assert(pthread_cond_init(&vol_sleep_cond, NULL) == 0); - assert(pthread_cond_init(&vol_init_attach_cond, NULL) == 0); - assert(pthread_cond_init(&vol_vinit_cond, NULL) == 0); -#else /* AFS_PTHREAD_ENV */ + MUTEX_INIT(&vol_glock_mutex, "vol glock", MUTEX_DEFAULT, 0); + MUTEX_INIT(&vol_trans_mutex, "vol trans", MUTEX_DEFAULT, 0); + CV_INIT(&vol_put_volume_cond, "vol put", CV_DEFAULT, 0); + CV_INIT(&vol_sleep_cond, "vol sleep", CV_DEFAULT, 0); + CV_INIT(&vol_init_attach_cond, "vol init attach", CV_DEFAULT, 0); + CV_INIT(&vol_vinit_cond, "vol init", CV_DEFAULT, 0); +#ifndef AFS_PTHREAD_ENV IOMGR_Initialize(); #endif /* AFS_PTHREAD_ENV */ Lock_Init(&vol_listLock); @@ -598,7 +590,7 @@ VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts) srandom(time(0)); /* For VGetVolumeInfo */ #ifdef AFS_DEMAND_ATTACH_FS - assert(pthread_mutex_init(&vol_salvsync_mutex, NULL) == 0); + MUTEX_INIT(&vol_salvsync_mutex, "salvsync", MUTEX_DEFAULT, 0); #endif /* AFS_DEMAND_ATTACH_FS */ /* Ok, we have done enough initialization that fileserver can @@ -620,7 +612,7 @@ VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts) #if defined(AFS_DEMAND_ATTACH_FS) && defined(SALVSYNC_BUILD_CLIENT) if (VCanUseSALVSYNC()) { /* establish a connection to the salvager at this point */ - assert(VConnectSALV() != 0); + osi_Assert(VConnectSALV() != 0); } #endif /* AFS_DEMAND_ATTACH_FS */ @@ -674,13 +666,13 @@ VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts) int VInitAttachVolumes(ProgramType pt) { - assert(VInit==1); + osi_Assert(VInit==1); if (pt == fileServer) { struct DiskPartition64 *diskP; /* Attach all the volumes in this partition */ for (diskP = DiskPartitionList; diskP; diskP = diskP->next) { int nAttached = 0, nUnattached = 0; - assert(VAttachVolumesByPartition(diskP, &nAttached, &nUnattached) == 0); + osi_Assert(VAttachVolumesByPartition(diskP, &nAttached, &nUnattached) == 0); } } VOL_LOCK; @@ -705,7 +697,7 @@ VInitAttachVolumes(ProgramType pt) int VInitAttachVolumes(ProgramType pt) { - assert(VInit==1); + osi_Assert(VInit==1); if (pt == fileServer) { struct DiskPartition64 *diskP; struct vinitvolumepackage_thread_t params; @@ -714,14 +706,14 @@ VInitAttachVolumes(ProgramType pt) pthread_t tid; pthread_attr_t attrs; - assert(pthread_cond_init(¶ms.thread_done_cv,NULL) == 0); + CV_INIT(¶ms.thread_done_cv, "thread done", CV_DEFAULT, 0); queue_Init(¶ms); params.n_threads_complete = 0; /* create partition work queue */ for (parts=0, diskP = DiskPartitionList; diskP; diskP = diskP->next, parts++) { dpq = (diskpartition_queue_t *) malloc(sizeof(struct diskpartition_queue_t)); - assert(dpq != NULL); + osi_Assert(dpq != NULL); dpq->diskP = diskP; queue_Append(¶ms,dpq); } @@ -730,8 +722,8 @@ VInitAttachVolumes(ProgramType pt) if (threads > 1) { /* spawn off a bunch of initialization threads */ - assert(pthread_attr_init(&attrs) == 0); - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_attr_init(&attrs) == 0); + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); Log("VInitVolumePackage: beginning parallel fileserver startup\n"); Log("VInitVolumePackage: using %d threads to attach volumes on %d partitions\n", @@ -741,7 +733,7 @@ VInitAttachVolumes(ProgramType pt) for (i=0; i < threads; i++) { AFS_SIGSET_DECL; AFS_SIGSET_CLEAR(); - assert(pthread_create + osi_Assert(pthread_create (&tid, &attrs, &VInitVolumePackageThread, ¶ms) == 0); AFS_SIGSET_RESTORE(); @@ -752,7 +744,7 @@ VInitAttachVolumes(ProgramType pt) } VOL_UNLOCK; - assert(pthread_attr_destroy(&attrs) == 0); + osi_Assert(pthread_attr_destroy(&attrs) == 0); } else { /* if we're only going to run one init thread, don't bother creating * another LWP */ @@ -763,11 +755,11 @@ VInitAttachVolumes(ProgramType pt) VInitVolumePackageThread(¶ms); } - assert(pthread_cond_destroy(¶ms.thread_done_cv) == 0); + CV_DESTROY(¶ms.thread_done_cv); } VOL_LOCK; VSetVInit_r(2); /* Initialized, and all volumes have been attached */ - assert(pthread_cond_broadcast(&vol_init_attach_cond) == 0); + CV_BROADCAST(&vol_init_attach_cond); VOL_UNLOCK; return 0; } @@ -798,14 +790,14 @@ VInitVolumePackageThread(void * args) { diskP = dpq->diskP; free(dpq); - assert(VAttachVolumesByPartition(diskP, &nAttached, &nUnattached) == 0); + osi_Assert(VAttachVolumesByPartition(diskP, &nAttached, &nUnattached) == 0); VOL_LOCK; } done: params->n_threads_complete++; - pthread_cond_signal(¶ms->thread_done_cv); + CV_SIGNAL(¶ms->thread_done_cv); VOL_UNLOCK; return NULL; } @@ -825,7 +817,7 @@ done: int VInitAttachVolumes(ProgramType pt) { - assert(VInit==1); + osi_Assert(VInit==1); if (pt == fileServer) { struct DiskPartition64 *diskP; @@ -838,12 +830,12 @@ VInitAttachVolumes(ProgramType pt) /* create partition work queue */ queue_Init(&pq); - assert(pthread_cond_init(&(pq.cv), NULL) == 0); - assert(pthread_mutex_init(&(pq.mutex), NULL) == 0); + CV_INIT(&(pq.cv), "partq", CV_DEFAULT, 0); + MUTEX_INIT(&(pq.mutex), "partq", MUTEX_DEFAULT, 0); for (parts = 0, diskP = DiskPartitionList; diskP; diskP = diskP->next, parts++) { struct diskpartition_queue_t *dp; dp = (struct diskpartition_queue_t*)malloc(sizeof(struct diskpartition_queue_t)); - assert(dp != NULL); + osi_Assert(dp != NULL); dp->diskP = diskP; queue_Append(&pq, dp); } @@ -853,11 +845,11 @@ VInitAttachVolumes(ProgramType pt) /* create volume work queue */ queue_Init(&vq); - assert(pthread_cond_init(&(vq.cv), NULL) == 0); - assert(pthread_mutex_init(&(vq.mutex), NULL) == 0); + CV_INIT(&(vq.cv), "volq", CV_DEFAULT, 0); + MUTEX_INIT(&(vq.mutex), "volq", MUTEX_DEFAULT, 0); - assert(pthread_attr_init(&attrs) == 0); - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_attr_init(&attrs) == 0); + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); Log("VInitVolumePackage: beginning parallel fileserver startup\n"); Log("VInitVolumePackage: using %d threads to pre-attach volumes on %d partitions\n", @@ -869,29 +861,29 @@ VInitAttachVolumes(ProgramType pt) AFS_SIGSET_DECL; params = (struct vinitvolumepackage_thread_param *)malloc(sizeof(struct vinitvolumepackage_thread_param)); - assert(params); + osi_Assert(params); params->pq = &pq; params->vq = &vq; params->nthreads = threads; params->thread = i+1; AFS_SIGSET_CLEAR(); - assert(pthread_create (&tid, &attrs, &VInitVolumePackageThread, (void*)params) == 0); + osi_Assert(pthread_create (&tid, &attrs, &VInitVolumePackageThread, (void*)params) == 0); AFS_SIGSET_RESTORE(); } VInitPreAttachVolumes(threads, &vq); - assert(pthread_attr_destroy(&attrs) == 0); - assert(pthread_cond_destroy(&pq.cv) == 0); - assert(pthread_mutex_destroy(&pq.mutex) == 0); - assert(pthread_cond_destroy(&vq.cv) == 0); - assert(pthread_mutex_destroy(&vq.mutex) == 0); + osi_Assert(pthread_attr_destroy(&attrs) == 0); + CV_DESTROY(&pq.cv); + MUTEX_DESTROY(&pq.mutex); + CV_DESTROY(&vq.cv); + MUTEX_DESTROY(&vq.mutex); } VOL_LOCK; VSetVInit_r(2); /* Initialized, and all volumes have been attached */ - assert(pthread_cond_broadcast(&vol_init_attach_cond) == 0); + CV_BROADCAST(&vol_init_attach_cond); VOL_UNLOCK; return 0; @@ -912,15 +904,15 @@ VInitVolumePackageThread(void *args) struct volume_init_queue *vq; struct volume_init_batch *vb; - assert(args); + osi_Assert(args); params = (struct vinitvolumepackage_thread_param *)args; pq = params->pq; vq = params->vq; - assert(pq); - assert(vq); + osi_Assert(pq); + osi_Assert(vq); vb = (struct volume_init_batch*)malloc(sizeof(struct volume_init_batch)); - assert(vb); + osi_Assert(vb); vb->thread = params->thread; vb->last = 0; vb->size = 0; @@ -938,23 +930,23 @@ VInitVolumePackageThread(void *args) } while ((vid = VInitNextVolumeId(dirp))) { Volume *vp = (Volume*)malloc(sizeof(Volume)); - assert(vp); + osi_Assert(vp); memset(vp, 0, sizeof(Volume)); vp->device = partition->device; vp->partition = partition; vp->hashid = vid; queue_Init(&vp->vnode_list); - assert(pthread_cond_init(&V_attachCV(vp), NULL) == 0); + CV_INIT(&V_attachCV(vp), "partattach", CV_DEFAULT, 0); vb->batch[vb->size++] = vp; if (vb->size == VINIT_BATCH_MAX_SIZE) { - assert(pthread_mutex_lock(&vq->mutex) == 0); + MUTEX_ENTER(&vq->mutex); queue_Append(vq, vb); - assert(pthread_cond_broadcast(&vq->cv) == 0); - assert(pthread_mutex_unlock(&vq->mutex) == 0); + CV_BROADCAST(&vq->cv); + MUTEX_EXIT(&vq->mutex); vb = (struct volume_init_batch*)malloc(sizeof(struct volume_init_batch)); - assert(vb); + osi_Assert(vb); vb->thread = params->thread; vb->size = 0; vb->last = 0; @@ -964,10 +956,10 @@ VInitVolumePackageThread(void *args) } vb->last = 1; - assert(pthread_mutex_lock(&vq->mutex) == 0); + MUTEX_ENTER(&vq->mutex); queue_Append(vq, vb); - assert(pthread_cond_broadcast(&vq->cv) == 0); - assert(pthread_mutex_unlock(&vq->mutex) == 0); + CV_BROADCAST(&vq->cv); + MUTEX_EXIT(&vq->mutex); Log("Partition scan thread %d of %d ended\n", params->thread, params->nthreads); free(params); @@ -989,17 +981,17 @@ VInitNextPartition(struct partition_queue *pq) } /* get next partition to scan */ - assert(pthread_mutex_lock(&pq->mutex) == 0); + MUTEX_ENTER(&pq->mutex); if (queue_IsEmpty(pq)) { - assert(pthread_mutex_unlock(&pq->mutex) == 0); + MUTEX_EXIT(&pq->mutex); return NULL; } dp = queue_First(pq, diskpartition_queue_t); queue_Remove(dp); - assert(pthread_mutex_unlock(&pq->mutex) == 0); + MUTEX_EXIT(&pq->mutex); - assert(dp); - assert(dp->diskP); + osi_Assert(dp); + osi_Assert(dp->diskP); partition = dp->diskP; free(dp); @@ -1044,13 +1036,13 @@ VInitPreAttachVolumes(int nthreads, struct volume_init_queue *vq) while (nthreads) { /* dequeue next volume */ - pthread_mutex_lock(&vq->mutex); + MUTEX_ENTER(&vq->mutex); if (queue_IsEmpty(vq)) { - pthread_cond_wait(&vq->cv, &vq->mutex); + CV_WAIT(&vq->cv, &vq->mutex); } vb = queue_First(vq, volume_init_batch); queue_Remove(vb); - pthread_mutex_unlock(&vq->mutex); + MUTEX_EXIT(&vq->mutex); if (vb->size) { VOL_LOCK; @@ -1227,11 +1219,11 @@ VShutdown_r(void) if (vol_attach_threads > 1) { /* prepare for parallel shutdown */ params.n_threads = vol_attach_threads; - assert(pthread_mutex_init(¶ms.lock, NULL) == 0); - assert(pthread_cond_init(¶ms.cv, NULL) == 0); - assert(pthread_cond_init(¶ms.master_cv, NULL) == 0); - assert(pthread_attr_init(&attrs) == 0); - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + MUTEX_INIT(¶ms.lock, "params", MUTEX_DEFAULT, 0); + CV_INIT(¶ms.cv, "params", CV_DEFAULT, 0); + CV_INIT(¶ms.master_cv, "params master", CV_DEFAULT, 0); + osi_Assert(pthread_attr_init(&attrs) == 0); + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); queue_Init(¶ms); /* setup the basic partition information structures for @@ -1257,7 +1249,7 @@ VShutdown_r(void) /* build up the pass 0 shutdown work queue */ dpq = (struct diskpartition_queue_t *) malloc(sizeof(struct diskpartition_queue_t)); - assert(dpq != NULL); + osi_Assert(dpq != NULL); dpq->diskP = diskP; queue_Prepend(¶ms, dpq); @@ -1269,21 +1261,21 @@ VShutdown_r(void) vol_attach_threads, params.n_parts, params.n_parts > 1 ? "s" : "" ); /* do pass 0 shutdown */ - assert(pthread_mutex_lock(¶ms.lock) == 0); + MUTEX_ENTER(¶ms.lock); for (i=0; i < params.n_threads; i++) { - assert(pthread_create + osi_Assert(pthread_create (&tid, &attrs, &VShutdownThread, ¶ms) == 0); } /* wait for all the pass 0 shutdowns to complete */ while (params.n_threads_complete < params.n_threads) { - assert(pthread_cond_wait(¶ms.master_cv, ¶ms.lock) == 0); + CV_WAIT(¶ms.master_cv, ¶ms.lock); } params.n_threads_complete = 0; params.pass = 1; - assert(pthread_cond_broadcast(¶ms.cv) == 0); - assert(pthread_mutex_unlock(¶ms.lock) == 0); + CV_BROADCAST(¶ms.cv); + MUTEX_EXIT(¶ms.lock); Log("VShutdown: pass 0 completed using the 1 thread per partition algorithm\n"); Log("VShutdown: starting passes 1 through 3 using finely-granular mp-fast algorithm\n"); @@ -1296,10 +1288,10 @@ VShutdown_r(void) VOL_CV_WAIT(¶ms.cv); } - assert(pthread_attr_destroy(&attrs) == 0); - assert(pthread_cond_destroy(¶ms.cv) == 0); - assert(pthread_cond_destroy(¶ms.master_cv) == 0); - assert(pthread_mutex_destroy(¶ms.lock) == 0); + osi_Assert(pthread_attr_destroy(&attrs) == 0); + CV_DESTROY(¶ms.cv); + CV_DESTROY(¶ms.master_cv); + MUTEX_DESTROY(¶ms.lock); /* drop the VByPList exclusive reservations */ for (diskP = DiskPartitionList; diskP; diskP = diskP->next) { @@ -1368,7 +1360,7 @@ VShutdown_r(void) void VShutdown(void) { - assert(VInit>0); + osi_Assert(VInit>0); VOL_LOCK; VShutdown_r(); VOL_UNLOCK; @@ -1575,14 +1567,14 @@ VShutdownThread(void * args) params = (vshutdown_thread_t *) args; /* acquire the shutdown pass 0 lock */ - assert(pthread_mutex_lock(¶ms->lock) == 0); + MUTEX_ENTER(¶ms->lock); /* if there's still pass 0 work to be done, * get a work entry, and do a pass 0 shutdown */ if (queue_IsNotEmpty(params)) { dpq = queue_First(params, diskpartition_queue_t); queue_Remove(dpq); - assert(pthread_mutex_unlock(¶ms->lock) == 0); + MUTEX_EXIT(¶ms->lock); diskP = dpq->diskP; free(dpq); id = diskP->index; @@ -1591,24 +1583,24 @@ VShutdownThread(void * args) while (ShutdownVolumeWalk_r(diskP, 0, ¶ms->part_pass_head[id])) count++; params->stats[0][diskP->index] = count; - assert(pthread_mutex_lock(¶ms->lock) == 0); + MUTEX_ENTER(¶ms->lock); } params->n_threads_complete++; if (params->n_threads_complete == params->n_threads) { - /* notify control thread that all workers have completed pass 0 */ - assert(pthread_cond_signal(¶ms->master_cv) == 0); + /* notify control thread that all workers have completed pass 0 */ + CV_SIGNAL(¶ms->master_cv); } while (params->pass == 0) { - assert(pthread_cond_wait(¶ms->cv, ¶ms->lock) == 0); + CV_WAIT(¶ms->cv, ¶ms->lock); } /* switch locks */ - assert(pthread_mutex_unlock(¶ms->lock) == 0); + MUTEX_EXIT(¶ms->lock); VOL_LOCK; pass = params->pass; - assert(pass > 0); + osi_Assert(pass > 0); /* now escalate through the more complicated shutdowns */ while (pass <= 3) { @@ -1688,7 +1680,7 @@ VShutdownThread(void * args) ShutdownCreateSchedule(params); /* wake up all the workers */ - assert(pthread_cond_broadcast(¶ms->cv) == 0); + CV_BROADCAST(¶ms->cv); VOL_UNLOCK; Log("VShutdown: pass %d completed using %d threads on %d partitions\n", @@ -1842,7 +1834,7 @@ VShutdownVolume_r(Volume * vp) /* wait for other blocking ops to finish */ VWaitExclusiveState_r(vp); - assert(VIsValidState(V_attachState(vp))); + osi_Assert(VIsValidState(V_attachState(vp))); switch(V_attachState(vp)) { case VOL_STATE_SALVAGING: @@ -2089,7 +2081,7 @@ VPreAttachVolumeById_r(Error * ec, *ec = 0; - assert(programType == fileServer); + osi_Assert(programType == fileServer); if (!(partp = VGetPartition_r(partition, 0))) { *ec = VNOVOL; @@ -2173,10 +2165,10 @@ VPreAttachVolumeByVp_r(Error * ec, /* allocate the volume structure */ vp = nvp = (Volume *) malloc(sizeof(Volume)); - assert(vp != NULL); + osi_Assert(vp != NULL); memset(vp, 0, sizeof(Volume)); queue_Init(&vp->vnode_list); - assert(pthread_cond_init(&V_attachCV(vp), NULL) == 0); + CV_INIT(&V_attachCV(vp), "vp attach", CV_DEFAULT, 0); } /* link the volume with its associated vice partition */ @@ -2263,7 +2255,7 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode) } if (VRequiresPartLock()) { - assert(VInit == 3); + osi_Assert(VInit == 3); VLockPartition_r(partition); } else if (programType == fileServer) { #ifdef AFS_DEMAND_ATTACH_FS @@ -2338,7 +2330,7 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode) } } - assert(vp != NULL); + osi_Assert(vp != NULL); /* handle pre-attach races * @@ -2399,13 +2391,13 @@ VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode) if (!vp) { vp = (Volume *) calloc(1, sizeof(Volume)); - assert(vp != NULL); + osi_Assert(vp != NULL); vp->hashid = volumeId; vp->device = partp->device; vp->partition = partp; queue_Init(&vp->vnode_list); #ifdef AFS_DEMAND_ATTACH_FS - assert(pthread_cond_init(&V_attachCV(vp), NULL) == 0); + CV_INIT(&V_attachCV(vp), "vp attach", CV_DEFAULT, 0); #endif /* AFS_DEMAND_ATTACH_FS */ } @@ -2543,7 +2535,7 @@ VAttachVolumeByVp_r(Error * ec, Volume * vp, int mode) *ec = 0; /* volume utility should never call AttachByVp */ - assert(programType == fileServer); + osi_Assert(programType == fileServer); volumeId = vp->hashid; partp = vp->partition; @@ -2587,7 +2579,7 @@ VAttachVolumeByVp_r(Error * ec, Volume * vp, int mode) } } - assert(vp != NULL); + osi_Assert(vp != NULL); VChangeState_r(vp, VOL_STATE_ATTACHING); /* restore monotonically increasing stats */ @@ -2685,8 +2677,8 @@ VLockVolumeNB(Volume *vp, int locktype) { int code; - assert(programType != fileServer || VIsExclusiveState(V_attachState(vp))); - assert(!(V_attachFlags(vp) & VOL_LOCKED)); + osi_Assert(programType != fileServer || VIsExclusiveState(V_attachState(vp))); + osi_Assert(!(V_attachFlags(vp) & VOL_LOCKED)); code = VLockVolumeByIdNB(vp->hashid, vp->partition, locktype); if (code == 0) { @@ -2708,8 +2700,8 @@ VLockVolumeNB(Volume *vp, int locktype) static void VUnlockVolume(Volume *vp) { - assert(programType != fileServer || VIsExclusiveState(V_attachState(vp))); - assert((V_attachFlags(vp) & VOL_LOCKED)); + osi_Assert(programType != fileServer || VIsExclusiveState(V_attachState(vp))); + osi_Assert((V_attachFlags(vp) & VOL_LOCKED)); VUnlockVolumeById(vp->hashid, vp->partition); @@ -3018,12 +3010,12 @@ attach_check_vop(Error *ec, VolumeId volid, struct DiskPartition64 *partp, switch (vp->pending_vol_op->vol_op_state) { case FSSYNC_VolOpPending: /* this should never happen */ - assert(vp->pending_vol_op->vol_op_state != FSSYNC_VolOpPending); + osi_Assert(vp->pending_vol_op->vol_op_state != FSSYNC_VolOpPending); break; case FSSYNC_VolOpRunningUnknown: /* this should never happen; we resolved 'unknown' above */ - assert(vp->pending_vol_op->vol_op_state != FSSYNC_VolOpRunningUnknown); + osi_Assert(vp->pending_vol_op->vol_op_state != FSSYNC_VolOpRunningUnknown); break; case FSSYNC_VolOpRunningOffline: @@ -3451,7 +3443,7 @@ VAttachVolume_r(Error * ec, VolumeId volumeId, int mode) Error error; vp = VGetVolume_r(&error, volumeId); if (vp) { - assert(V_inUse(vp) == 0); + osi_Assert(V_inUse(vp) == 0); VDetachVolume_r(ec, vp); } return NULL; @@ -3534,7 +3526,7 @@ VHold(Volume * vp) void VPutVolume_r(Volume * vp) { - assert(--vp->nUsers >= 0); + osi_Assert(--vp->nUsers >= 0); if (vp->nUsers == 0) { VCheckOffline(vp); ReleaseVolumeHeader(vp->header); @@ -3801,7 +3793,7 @@ GetVolume(Error * ec, Error * client_ec, VolId volumeId, Volume * hint, int nowa */ /* only valid before/during demand attachment */ - assert(!vp->pending_vol_op || vp->pending_vol_op->vol_op_state != FSSYNC_VolOpRunningUnknown); + osi_Assert(!vp->pending_vol_op || vp->pending_vol_op->vol_op_state != FSSYNC_VolOpRunningUnknown); /* deny getvolume due to running mutually exclusive vol op */ if (vp->pending_vol_op && vp->pending_vol_op->vol_op_state==FSSYNC_VolOpRunningOffline) { @@ -3924,7 +3916,7 @@ GetVolume(Error * ec, Error * client_ec, VolId volumeId, Volume * hint, int nowa #endif /* AFS_DEMAND_ATTACH_FS */ not_inited: - assert(vp || *ec); + osi_Assert(vp || *ec); return vp; } @@ -3940,8 +3932,8 @@ VTakeOffline_r(Volume * vp) { Error error; - assert(vp->nUsers > 0); - assert(programType == fileServer); + osi_Assert(vp->nUsers > 0); + osi_Assert(programType == fileServer); VCreateReservation_r(vp); VWaitExclusiveState_r(vp); @@ -3956,8 +3948,8 @@ VTakeOffline_r(Volume * vp) void VTakeOffline_r(Volume * vp) { - assert(vp->nUsers > 0); - assert(programType == fileServer); + osi_Assert(vp->nUsers > 0); + osi_Assert(programType == fileServer); vp->goingOffline = 1; V_needsSalvaged(vp) = 1; @@ -4029,7 +4021,7 @@ VForceOffline_r(Volume * vp, int flags) #endif /* AFS_DEMAND_ATTACH_FS */ #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0); + CV_BROADCAST(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(VPutVolume); #endif /* AFS_PTHREAD_ENV */ @@ -4064,7 +4056,7 @@ VOffline_r(Volume * vp, char *message) VolumeId vid = V_id(vp); #endif - assert(programType != volumeUtility && programType != volumeServer); + osi_Assert(programType != volumeUtility && programType != volumeServer); if (!V_inUse(vp)) { VPutVolume_r(vp); return; @@ -4123,7 +4115,7 @@ VOffline_r(Volume * vp, char *message) void VOfflineForVolOp_r(Error *ec, Volume *vp, char *message) { - assert(vp->pending_vol_op); + osi_Assert(vp->pending_vol_op); if (!V_inUse(vp)) { VPutVolume_r(vp); *ec = 1; @@ -4423,9 +4415,9 @@ VSyncVolume_r(Error * ec, Volume * vp, int flags) VOL_UNLOCK; #endif fdP = IH_OPEN(V_diskDataHandle(vp)); - assert(fdP != NULL); + osi_Assert(fdP != NULL); code = FDH_SYNC(fdP); - assert(code == 0); + osi_Assert(code == 0); FDH_CLOSE(fdP); #ifdef AFS_DEMAND_ATTACH_FS VOL_LOCK; @@ -4517,7 +4509,7 @@ VCheckDetach(Volume * vp) VCheckSalvage(vp); ReallyFreeVolume(vp); if (programType == fileServer) { - assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0); + CV_BROADCAST(&vol_put_volume_cond); } } return ret; @@ -4551,7 +4543,7 @@ VCheckDetach(Volume * vp) ReallyFreeVolume(vp); if (programType == fileServer) { #if defined(AFS_PTHREAD_ENV) - assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0); + CV_BROADCAST(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(VPutVolume); #endif /* AFS_PTHREAD_ENV */ @@ -4571,8 +4563,8 @@ VCheckOffline(Volume * vp) if (vp->goingOffline && !vp->nUsers) { Error error; - assert(programType == fileServer); - assert((V_attachState(vp) != VOL_STATE_ATTACHED) && + osi_Assert(programType == fileServer); + osi_Assert((V_attachState(vp) != VOL_STATE_ATTACHED) && (V_attachState(vp) != VOL_STATE_FREED) && (V_attachState(vp) != VOL_STATE_PREATTACHED) && (V_attachState(vp) != VOL_STATE_UNATTACHED) && @@ -4632,7 +4624,7 @@ VCheckOffline(Volume * vp) if (vp->goingOffline && !vp->nUsers) { Error error; - assert(programType == fileServer); + osi_Assert(programType == fileServer); ret = 1; vp->goingOffline = 0; @@ -4648,7 +4640,7 @@ VCheckOffline(Volume * vp) } FreeVolumeHeader(vp); #ifdef AFS_PTHREAD_ENV - assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0); + CV_BROADCAST(&vol_put_volume_cond); #else /* AFS_PTHREAD_ENV */ LWP_NoYieldSignal(VPutVolume); #endif /* AFS_PTHREAD_ENV */ @@ -4699,7 +4691,7 @@ VCheckOffline(Volume * vp) void VCancelReservation_r(Volume * vp) { - assert(--vp->nWaiters >= 0); + osi_Assert(--vp->nWaiters >= 0); if (vp->nWaiters == 0) { VCheckOffline(vp); if (!VCheckDetach(vp)) { @@ -4756,7 +4748,7 @@ VRegisterVolOp_r(Volume * vp, FSSYNC_VolOp_info * vopinfo) /* attach a vol op info node to the volume struct */ info = (FSSYNC_VolOp_info *) malloc(sizeof(FSSYNC_VolOp_info)); - assert(info != NULL); + osi_Assert(info != NULL); memcpy(info, vopinfo, sizeof(FSSYNC_VolOp_info)); vp->pending_vol_op = info; @@ -5157,7 +5149,7 @@ VScheduleSalvage_r(Volume * vp) VThreadOptions_t * thread_opts; char partName[16]; - assert(VCanUseSALVSYNC() || VCanUseFSSYNC()); + osi_Assert(VCanUseSALVSYNC() || VCanUseFSSYNC()); if (vp->nWaiters || vp->nUsers) { return 1; @@ -5195,7 +5187,7 @@ VScheduleSalvage_r(Volume * vp) state_save = VChangeState_r(vp, VOL_STATE_SALVSYNC_REQ); VOL_UNLOCK; - assert(try_SALVSYNC(vp, partName, &code) || + osi_Assert(try_SALVSYNC(vp, partName, &code) || try_FSSYNC(vp, partName, &code)); VOL_LOCK; @@ -5447,7 +5439,7 @@ int VConnectFS_r(void) { int rc; - assert((VInit == 2) && + osi_Assert((VInit == 2) && (programType != fileServer) && (programType != salvager)); rc = FSYNC_clientInit(); @@ -5476,7 +5468,7 @@ VConnectFS_r(void) void VDisconnectFS_r(void) { - assert((programType != fileServer) && + osi_Assert((programType != fileServer) && (programType != salvager)); FSYNC_clientFinis(); VSetVInit_r(2); @@ -5684,7 +5676,7 @@ VAllocBitmapEntry_r(Error * ec, Volume * vp, /* No bit map entry--must grow bitmap */ bp = (byte *) realloc(index->bitmap, index->bitmapSize + VOLUME_BITMAP_GROWSIZE); - assert(bp != NULL); + osi_Assert(bp != NULL); index->bitmap = bp; bp += index->bitmapSize; memset(bp, 0, VOLUME_BITMAP_GROWSIZE); @@ -5776,13 +5768,13 @@ VGetBitmap_r(Error * ec, Volume * vp, VnodeClass class) VOL_UNLOCK; fdP = IH_OPEN(vip->handle); - assert(fdP != NULL); + osi_Assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r"); - assert(file != NULL); + osi_Assert(file != NULL); vnode = (VnodeDiskObject *) malloc(vcp->diskSize); - assert(vnode != NULL); + osi_Assert(vnode != NULL); size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); nVnodes = (size <= vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize; vip->bitmapSize = ((nVnodes / 8) + 10) / 4 * 4; /* The 10 is a little extra so @@ -5792,10 +5784,10 @@ VGetBitmap_r(Error * ec, Volume * vp, VnodeClass class) * it that way */ #ifdef BITMAP_LATER BitMap = (byte *) calloc(1, vip->bitmapSize); - assert(BitMap != NULL); + osi_Assert(BitMap != NULL); #else /* BITMAP_LATER */ vip->bitmap = (byte *) calloc(1, vip->bitmapSize); - assert(vip->bitmap != NULL); + osi_Assert(vip->bitmap != NULL); vip->bitmapOffset = 0; #endif /* BITMAP_LATER */ if (STREAM_ASEEK(file, vcp->diskSize) != -1) { @@ -6192,7 +6184,7 @@ VAddToVolumeUpdateList_r(Error * ec, Volume * vp) sizeof(VolumeId) * updateSize); } } - assert(UpdateList != NULL); + osi_Assert(UpdateList != NULL); UpdateList[nUpdatedVolumes++] = V_id(vp); #endif /* !AFS_DEMAND_ATTACH_FS */ } @@ -6448,7 +6440,7 @@ VInitVLRU(void) queue_Init(&volume_LRU.q[i]); volume_LRU.q[i].len = 0; volume_LRU.q[i].busy = 0; - assert(pthread_cond_init(&volume_LRU.q[i].cv, NULL) == 0); + CV_INIT(&volume_LRU.q[i].cv, "vol lru", CV_DEFAULT, 0); } /* setup the timing constants */ @@ -6466,10 +6458,10 @@ VInitVLRU(void) /* start up the VLRU scanner */ volume_LRU.scanner_state = VLRU_SCANNER_STATE_OFFLINE; if (programType == fileServer) { - assert(pthread_cond_init(&volume_LRU.cv, NULL) == 0); - assert(pthread_attr_init(&attrs) == 0); - assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&tid, &attrs, &VLRU_ScannerThread, NULL) == 0); + CV_INIT(&volume_LRU.cv, "vol lru", CV_DEFAULT, 0); + osi_Assert(pthread_attr_init(&attrs) == 0); + osi_Assert(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_create(&tid, &attrs, &VLRU_ScannerThread, NULL) == 0); } } @@ -6495,7 +6487,7 @@ VLRU_Init_Node_r(Volume * vp) if (!VLRU_enabled) return; - assert(queue_IsNotOnQueue(&vp->vlru)); + osi_Assert(queue_IsNotOnQueue(&vp->vlru)); vp->vlru.idx = VLRU_QUEUE_INVALID; } @@ -6639,7 +6631,7 @@ VLRU_UpdateAccess_r(Volume * vp) if (queue_IsNotOnQueue(&vp->vlru)) return; - assert(V_attachFlags(vp) & VOL_ON_VLRU); + osi_Assert(V_attachFlags(vp) & VOL_ON_VLRU); /* update the access timestamp */ vp->stats.last_get = FT_ApproxTime(); @@ -6772,7 +6764,7 @@ VLRU_ScannerThread(void * args) /* check to see if we've been asked to pause */ if (volume_LRU.scanner_state == VLRU_SCANNER_STATE_PAUSING) { volume_LRU.scanner_state = VLRU_SCANNER_STATE_PAUSED; - assert(pthread_cond_broadcast(&volume_LRU.cv) == 0); + CV_BROADCAST(&volume_LRU.cv); do { VOL_CV_WAIT(&volume_LRU.cv); } while (volume_LRU.scanner_state == VLRU_SCANNER_STATE_PAUSED); @@ -6848,7 +6840,7 @@ VLRU_ScannerThread(void * args) /* signal that scanner is down */ volume_LRU.scanner_state = VLRU_SCANNER_STATE_OFFLINE; - assert(pthread_cond_broadcast(&volume_LRU.cv) == 0); + CV_BROADCAST(&volume_LRU.cv); VOL_UNLOCK; return NULL; } @@ -6951,7 +6943,7 @@ VLRU_Demote_r(int idx) Volume ** salv_flag_vec = NULL; int salv_vec_offset = 0; - assert(idx == VLRU_QUEUE_MID || idx == VLRU_QUEUE_OLD); + osi_Assert(idx == VLRU_QUEUE_MID || idx == VLRU_QUEUE_OLD); /* get exclusive access to two chains, and drop the glock */ VLRU_Wait_r(&volume_LRU.q[idx-1]); @@ -7050,7 +7042,7 @@ VLRU_Scan_r(int idx) Volume * vp; int i, locked = 1; - assert(idx == VLRU_QUEUE_NEW || idx == VLRU_QUEUE_CANDIDATE); + osi_Assert(idx == VLRU_QUEUE_NEW || idx == VLRU_QUEUE_CANDIDATE); /* gain exclusive access to the idx VLRU */ VLRU_Wait_r(&volume_LRU.q[idx]); @@ -7141,7 +7133,7 @@ VCheckSoftDetachCandidate(Volume * vp, afs_uint32 thresh) idx = vp->vlru.idx; - assert(idx == VLRU_QUEUE_NEW); + osi_Assert(idx == VLRU_QUEUE_NEW); if (vp->stats.last_get <= thresh) { /* move to candidate pool */ @@ -7161,7 +7153,7 @@ VCheckSoftDetachCandidate(Volume * vp, afs_uint32 thresh) static void VLRU_BeginExclusive_r(struct VLRU_q * q) { - assert(q->busy == 0); + osi_Assert(q->busy == 0); q->busy = 1; } @@ -7169,9 +7161,9 @@ VLRU_BeginExclusive_r(struct VLRU_q * q) static void VLRU_EndExclusive_r(struct VLRU_q * q) { - assert(q->busy); + osi_Assert(q->busy); q->busy = 0; - assert(pthread_cond_broadcast(&q->cv) == 0); + CV_BROADCAST(&q->cv); } /* wait for another thread to end exclusive access on VLRU */ @@ -7193,7 +7185,7 @@ VSoftDetachVolume_r(Volume * vp, afs_uint32 thresh) afs_uint32 ts_save; int ret = 0; - assert(vp->vlru.idx == VLRU_QUEUE_CANDIDATE); + osi_Assert(vp->vlru.idx == VLRU_QUEUE_CANDIDATE); ts_save = vp->stats.last_get; if (ts_save > thresh) @@ -7248,7 +7240,7 @@ VSoftDetachVolume_r(Volume * vp, afs_uint32 thresh) vp = NULL; } else { /* pull it off the VLRU */ - assert(vp->vlru.idx == VLRU_QUEUE_CANDIDATE); + osi_Assert(vp->vlru.idx == VLRU_QUEUE_CANDIDATE); volume_LRU.q[VLRU_QUEUE_CANDIDATE].len--; queue_Remove(&vp->vlru); vp->vlru.idx = VLRU_QUEUE_INVALID; @@ -7310,7 +7302,7 @@ VInitVolumeHeaderCache(afs_uint32 howMany) volume_hdr_LRU.stats.used = howMany; volume_hdr_LRU.stats.attached = 0; hp = (struct volHeader *)(calloc(howMany, sizeof(struct volHeader))); - assert(hp != NULL); + osi_Assert(hp != NULL); while (howMany--) /* We are using ReleaseVolumeHeader to initialize the values on the header list @@ -7368,7 +7360,7 @@ GetVolumeHeader(Volume * vp) /* for volume utilities, we allocate volHeaders as needed */ if (!vp->header) { hd = (struct volHeader *)calloc(1, sizeof(*vp->header)); - assert(hd != NULL); + osi_Assert(hd != NULL); vp->header = hd; hd->back = vp; #ifdef AFS_DEMAND_ATTACH_FS @@ -7382,7 +7374,7 @@ GetVolumeHeader(Volume * vp) * still available. pull it off the lru and return */ hd = vp->header; queue_Remove(hd); - assert(hd->back == vp); + osi_Assert(hd->back == vp); #ifdef AFS_DEMAND_ATTACH_FS V_attachFlags(vp) &= ~(VOL_HDR_IN_LRU); #endif @@ -7396,7 +7388,7 @@ GetVolumeHeader(Volume * vp) /* LRU is empty, so allocate a new volHeader * this is probably indicative of a leak, so let the user know */ hd = (struct volHeader *)calloc(1, sizeof(struct volHeader)); - assert(hd != NULL); + osi_Assert(hd != NULL); if (!everLogged) { Log("****Allocated more volume headers, probably leak****\n"); everLogged = 1; @@ -7411,7 +7403,7 @@ GetVolumeHeader(Volume * vp) #ifdef AFS_DEMAND_ATTACH_FS /* if hd->back were in an exclusive state, then * its volHeader would not be on the LRU... */ - assert(!VIsExclusiveState(V_attachState(hd->back))); + osi_Assert(!VIsExclusiveState(V_attachState(hd->back))); #endif if (hd->diskstuff.inUse) { @@ -7641,12 +7633,12 @@ VInitVolumeHash(void) VolumeHashTable.Table = (VolumeHashChainHead *) calloc(VolumeHashTable.Size, sizeof(VolumeHashChainHead)); - assert(VolumeHashTable.Table != NULL); + osi_Assert(VolumeHashTable.Table != NULL); for (i=0; i < VolumeHashTable.Size; i++) { queue_Init(&VolumeHashTable.Table[i]); #ifdef AFS_DEMAND_ATTACH_FS - assert(pthread_cond_init(&VolumeHashTable.Table[i].chain_busy_cv, NULL) == 0); + CV_INIT(&VolumeHashTable.Table[i].chain_busy_cv, "vhash busy", CV_DEFAULT, 0); #endif /* AFS_DEMAND_ATTACH_FS */ } } @@ -7915,7 +7907,7 @@ VReorderHash_r(VolumeHashChainHead * head, Volume * pp, Volume * vp) static void VHashBeginExclusive_r(VolumeHashChainHead * head) { - assert(head->busy == 0); + osi_Assert(head->busy == 0); head->busy = 1; } @@ -7939,9 +7931,9 @@ VHashBeginExclusive_r(VolumeHashChainHead * head) static void VHashEndExclusive_r(VolumeHashChainHead * head) { - assert(head->busy); + osi_Assert(head->busy); head->busy = 0; - assert(pthread_cond_broadcast(&head->chain_busy_cv) == 0); + CV_BROADCAST(&head->chain_busy_cv); } /** @@ -8079,7 +8071,7 @@ DeleteVolumeFromVByPList_r(Volume * vp) static void VVByPListBeginExclusive_r(struct DiskPartition64 * dp) { - assert(dp->vol_list.busy == 0); + osi_Assert(dp->vol_list.busy == 0); dp->vol_list.busy = 1; } @@ -8103,9 +8095,9 @@ VVByPListBeginExclusive_r(struct DiskPartition64 * dp) static void VVByPListEndExclusive_r(struct DiskPartition64 * dp) { - assert(dp->vol_list.busy); + osi_Assert(dp->vol_list.busy); dp->vol_list.busy = 0; - assert(pthread_cond_broadcast(&dp->vol_list.cv) == 0); + CV_BROADCAST(&dp->vol_list.cv); } /** diff --git a/src/vol/volume.h b/src/vol/volume.h index 9341e7dfb..76c3f334f 100644 --- a/src/vol/volume.h +++ b/src/vol/volume.h @@ -36,9 +36,9 @@ typedef bit32 FileOffset; /* Offset in this file */ #ifdef VOL_LOCK_DEBUG #define VOL_LOCK_ASSERT_HELD \ - assert(vol_glock_holder == pthread_self()) + osi_Assert(vol_glock_holder == pthread_self()) #define VOL_LOCK_ASSERT_UNHELD \ - assert(vol_glock_holder == 0) + osi_Assert(vol_glock_holder == 0) #define _VOL_LOCK_SET_HELD \ vol_glock_holder = pthread_self() #define _VOL_LOCK_SET_UNHELD \ @@ -62,7 +62,6 @@ typedef bit32 FileOffset; /* Offset in this file */ #ifdef AFS_PTHREAD_ENV -#include #include extern pthread_mutex_t vol_glock_mutex; extern pthread_mutex_t vol_trans_mutex; @@ -75,37 +74,31 @@ extern int vol_attach_threads; extern pthread_t vol_glock_holder; #define VOL_LOCK \ do { \ - assert(pthread_mutex_lock(&vol_glock_mutex) == 0); \ - assert(vol_glock_holder == 0); \ - vol_glock_holder = pthread_self(); \ + MUTEX_ENTER(&vol_glock_mutex); \ + VOL_LOCK_ASSERT_UNHELD; \ + _VOL_LOCK_SET_HELD; \ } while (0) #define VOL_UNLOCK \ do { \ VOL_LOCK_ASSERT_HELD; \ - vol_glock_holder = 0; \ - assert(pthread_mutex_unlock(&vol_glock_mutex) == 0); \ + _VOL_LOCK_SET_UNHELD; \ + MUTEX_EXIT(&vol_glock_mutex); \ } while (0) #define VOL_CV_WAIT(cv) \ do { \ VOL_LOCK_DBG_CV_WAIT_BEGIN; \ - assert(pthread_cond_wait((cv), &vol_glock_mutex) == 0); \ + CV_WAIT((cv), &vol_glock_mutex); \ VOL_LOCK_DBG_CV_WAIT_END; \ } while (0) #else /* !VOL_LOCK_DEBUG */ -#define VOL_LOCK \ - assert(pthread_mutex_lock(&vol_glock_mutex) == 0) -#define VOL_UNLOCK \ - assert(pthread_mutex_unlock(&vol_glock_mutex) == 0) -#define VOL_CV_WAIT(cv) assert(pthread_cond_wait((cv), &vol_glock_mutex) == 0) +#define VOL_LOCK MUTEX_ENTER(&vol_glock_mutex) +#define VOL_UNLOCK MUTEX_EXIT(&vol_glock_mutex) +#define VOL_CV_WAIT(cv) CV_WAIT((cv), &vol_glock_mutex) #endif /* !VOL_LOCK_DEBUG */ -#define VSALVSYNC_LOCK \ - assert(pthread_mutex_lock(&vol_salvsync_mutex) == 0) -#define VSALVSYNC_UNLOCK \ - assert(pthread_mutex_unlock(&vol_salvsync_mutex) == 0) -#define VTRANS_LOCK \ - assert(pthread_mutex_lock(&vol_trans_mutex) == 0) -#define VTRANS_UNLOCK \ - assert(pthread_mutex_unlock(&vol_trans_mutex) == 0) +#define VSALVSYNC_LOCK MUTEX_ENTER(&vol_salvsync_mutex) +#define VSALVSYNC_UNLOCK MUTEX_EXIT(&vol_salvsync_mutex) +#define VTRANS_LOCK MUTEX_ENTER(&vol_trans_mutex) +#define VTRANS_UNLOCK MUTEX_EXIT(&vol_trans_mutex) #else /* AFS_PTHREAD_ENV */ #define VOL_LOCK #define VOL_UNLOCK diff --git a/src/vol/volume_inline.h b/src/vol/volume_inline.h index acdc21dad..1c717aeb8 100644 --- a/src/vol/volume_inline.h +++ b/src/vol/volume_inline.h @@ -233,7 +233,7 @@ VVolLockType(int mode, int writeable) return 0; default: - assert(0 /* unknown checkout mode */); + osi_Assert(0 /* unknown checkout mode */); return 0; } } @@ -382,11 +382,11 @@ VWaitStateChange_r(Volume * vp) { VolState state_save = V_attachState(vp); - assert(vp->nWaiters || vp->nUsers); + osi_Assert(vp->nWaiters || vp->nUsers); do { VOL_CV_WAIT(&V_attachCV(vp)); } while (V_attachState(vp) == state_save); - assert(V_attachState(vp) != VOL_STATE_FREED); + osi_Assert(V_attachState(vp) != VOL_STATE_FREED); } /** @@ -403,11 +403,11 @@ VWaitStateChange_r(Volume * vp) static_inline void VWaitExclusiveState_r(Volume * vp) { - assert(vp->nWaiters || vp->nUsers); + osi_Assert(vp->nWaiters || vp->nUsers); while (VIsExclusiveState(V_attachState(vp))) { VOL_CV_WAIT(&V_attachCV(vp)); } - assert(V_attachState(vp) != VOL_STATE_FREED); + osi_Assert(V_attachState(vp) != VOL_STATE_FREED); } /** @@ -435,7 +435,7 @@ VChangeState_r(Volume * vp, VolState new_state) VStats.state_levels[new_state]++; V_attachState(vp) = new_state; - assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0); + CV_BROADCAST(&V_attachCV(vp)); return old_state; } diff --git a/src/vol/vutil.c b/src/vol/vutil.c index 8c6719a67..fdd2b7ae0 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -31,11 +31,7 @@ #endif #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include @@ -863,14 +859,6 @@ VWalkVolumeHeaders(struct DiskPartition64 *dp, const char *partpath, return code; } -#ifdef AFS_PTHREAD_ENV -# define AFS_LF_LOCK(lf) assert(pthread_mutex_lock(&((lf)->mutex)) == 0) -# define AFS_LF_UNLOCK(lf) assert(pthread_mutex_unlock(&((lf)->mutex)) == 0) -#else -# define AFS_LF_LOCK(lf) -# define AFS_LF_UNLOCK(lf) -#endif /* AFS_PTHREAD_ENV */ - /** * initialize a struct VLockFile. * @@ -884,9 +872,7 @@ VLockFileInit(struct VLockFile *lf, const char *path) memset(lf, 0, sizeof(*lf)); lf->path = strdup(path); lf->fd = INVALID_FD; -#ifdef AFS_PTHREAD_ENV - assert(pthread_mutex_init(&lf->mutex, NULL) == 0); -#endif /* AFS_PTHREAD_ENV */ + MUTEX_INIT(&lf->mutex, "vlockfile", MUTEX_DEFAULT, 0); } #ifdef AFS_NT40_ENV @@ -1087,7 +1073,7 @@ _VUnlockFd(int fd, afs_uint32 offset) void VLockFileReinit(struct VLockFile *lf) { - AFS_LF_LOCK(lf); + MUTEX_ENTER(&lf->mutex); if (lf->fd != INVALID_FD) { _VCloseFd(lf->fd); @@ -1096,7 +1082,7 @@ VLockFileReinit(struct VLockFile *lf) lf->refcount = 0; - AFS_LF_UNLOCK(lf); + MUTEX_EXIT(&lf->mutex); } /** @@ -1126,31 +1112,31 @@ VLockFileLock(struct VLockFile *lf, afs_uint32 offset, int locktype, int nonbloc { int code; - assert(locktype == READ_LOCK || locktype == WRITE_LOCK); + osi_Assert(locktype == READ_LOCK || locktype == WRITE_LOCK); - AFS_LF_LOCK(lf); + MUTEX_ENTER(&lf->mutex); if (lf->fd == INVALID_FD) { lf->fd = _VOpenPath(lf->path); if (lf->fd == INVALID_FD) { - AFS_LF_UNLOCK(lf); + MUTEX_EXIT(&lf->mutex); return EIO; } } lf->refcount++; - AFS_LF_UNLOCK(lf); + MUTEX_EXIT(&lf->mutex); code = _VLockFd(lf->fd, offset, locktype, nonblock); if (code) { - AFS_LF_LOCK(lf); + MUTEX_ENTER(&lf->mutex); if (--lf->refcount < 1) { _VCloseFd(lf->fd); lf->fd = INVALID_FD; } - AFS_LF_UNLOCK(lf); + MUTEX_EXIT(&lf->mutex); } return code; @@ -1159,9 +1145,9 @@ VLockFileLock(struct VLockFile *lf, afs_uint32 offset, int locktype, int nonbloc void VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset) { - AFS_LF_LOCK(lf); + MUTEX_ENTER(&lf->mutex); - assert(lf->fd != INVALID_FD); + osi_Assert(lf->fd != INVALID_FD); if (--lf->refcount < 1) { _VCloseFd(lf->fd); @@ -1170,7 +1156,7 @@ VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset) _VUnlockFd(lf->fd, offset); } - AFS_LF_UNLOCK(lf); + MUTEX_EXIT(&lf->mutex); } #ifdef AFS_DEMAND_ATTACH_FS @@ -1184,11 +1170,11 @@ VLockFileUnlock(struct VLockFile *lf, afs_uint32 offset) void VDiskLockInit(struct VDiskLock *dl, struct VLockFile *lf, afs_uint32 offset) { - assert(lf); + osi_Assert(lf); memset(dl, 0, sizeof(*dl)); Lock_Init(&dl->rwlock); - assert(pthread_mutex_init(&dl->mutex, NULL) == 0); - assert(pthread_cond_init(&dl->cv, NULL) == 0); + MUTEX_INIT(&dl->mutex, "disklock", MUTEX_DEFAULT, 0); + CV_INIT(&dl->cv, "disklock cv", CV_DEFAULT, 0); dl->lockfile = lf; dl->offset = offset; } @@ -1219,7 +1205,7 @@ int VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) { int code = 0; - assert(locktype == READ_LOCK || locktype == WRITE_LOCK); + osi_Assert(locktype == READ_LOCK || locktype == WRITE_LOCK); if (nonblock) { if (locktype == READ_LOCK) { @@ -1238,7 +1224,7 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) ObtainWriteLock(&dl->rwlock); } - assert(pthread_mutex_lock(&dl->mutex) == 0); + MUTEX_ENTER(&dl->mutex); if ((dl->flags & VDISKLOCK_ACQUIRING)) { /* Some other thread is waiting to acquire an fs lock. If nonblock=1, @@ -1249,7 +1235,7 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) code = EBUSY; } else { while ((dl->flags & VDISKLOCK_ACQUIRING)) { - assert(pthread_cond_wait(&dl->cv, &dl->mutex) == 0); + CV_WAIT(&dl->cv, &dl->mutex); } } } @@ -1266,9 +1252,9 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) /* mark that we are waiting on the fs lock */ dl->flags |= VDISKLOCK_ACQUIRING; - assert(pthread_mutex_unlock(&dl->mutex) == 0); + MUTEX_EXIT(&dl->mutex); code = VLockFileLock(dl->lockfile, dl->offset, locktype, nonblock); - assert(pthread_mutex_lock(&dl->mutex) == 0); + MUTEX_ENTER(&dl->mutex); dl->flags &= ~VDISKLOCK_ACQUIRING; @@ -1276,7 +1262,7 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) dl->flags |= VDISKLOCK_ACQUIRED; } - assert(pthread_cond_broadcast(&dl->cv) == 0); + CV_BROADCAST(&dl->cv); } } @@ -1292,7 +1278,7 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) ++dl->lockers; } - assert(pthread_mutex_unlock(&dl->mutex) == 0); + MUTEX_EXIT(&dl->mutex); return code; } @@ -1310,10 +1296,10 @@ VGetDiskLock(struct VDiskLock *dl, int locktype, int nonblock) void VReleaseDiskLock(struct VDiskLock *dl, int locktype) { - assert(locktype == READ_LOCK || locktype == WRITE_LOCK); + osi_Assert(locktype == READ_LOCK || locktype == WRITE_LOCK); - assert(pthread_mutex_lock(&dl->mutex) == 0); - assert(dl->lockers > 0); + MUTEX_ENTER(&dl->mutex); + osi_Assert(dl->lockers > 0); if (--dl->lockers < 1) { /* no threads are holding this lock anymore, so we can release the @@ -1322,7 +1308,7 @@ VReleaseDiskLock(struct VDiskLock *dl, int locktype) dl->flags &= ~VDISKLOCK_ACQUIRED; } - assert(pthread_mutex_unlock(&dl->mutex) == 0); + MUTEX_EXIT(&dl->mutex); if (locktype == READ_LOCK) { ReleaseReadLock(&dl->rwlock); diff --git a/src/volser/Makefile.in b/src/volser/Makefile.in index cc45af96d..50709c74b 100644 --- a/src/volser/Makefile.in +++ b/src/volser/Makefile.in @@ -52,10 +52,11 @@ VOLDUMP_LIBS = \ ../vol/vlib.a \ ${TOP_LIBDIR}/libcmd.a \ ${TOP_LIBDIR}/util.a \ - ${TOP_LIBDIR}/libsys.a \ ${TOP_LIBDIR}/libcom_err.a \ ${TOP_LIBDIR}/libdir.a \ + ${TOP_LIBDIR}/librx.a \ ${TOP_LIBDIR}/liblwp.a \ + ${TOP_LIBDIR}/libsys.a \ ${TOP_LIBDIR}/libacl.a VSOBJS=vsprocs.o vsutils.o lockprocs.o volint.xdr.o volerr.o diff --git a/src/volser/dumpstuff.c b/src/volser/dumpstuff.c index 2ea2117bc..4297d7075 100644 --- a/src/volser/dumpstuff.c +++ b/src/volser/dumpstuff.c @@ -26,11 +26,7 @@ #include #endif #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -177,7 +173,7 @@ iod_Write(struct iod *iodp, char *buf, int nbytes) int code, i; int one_success = 0; - assert((iodp->call && iodp->ncalls == 1 && !iodp->calls) + osi_Assert((iodp->call && iodp->ncalls == 1 && !iodp->calls) || (!iodp->call && iodp->ncalls >= 1 && iodp->calls)); if (iodp->call) { @@ -991,15 +987,15 @@ DumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class, int vnodeIndex; fdP = IH_OPEN(vp->vnodeIndex[class].handle); - assert(fdP != NULL); + osi_Assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r+"); - assert(file != NULL); + osi_Assert(file != NULL); size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - assert((nVnodes + 1) * vcp->diskSize == size); - assert(STREAM_ASEEK(file, vcp->diskSize) == 0); + osi_Assert((nVnodes + 1) * vcp->diskSize == size); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else nVnodes = 0; for (vnodeIndex = 0; @@ -1158,7 +1154,7 @@ ProcessIndex(Volume * vp, VnodeClass class, afs_int32 ** Bufp, int *sizep, OS_SYNC(afile->str_fd); } else { size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); nVnodes = (size <= vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize; @@ -1858,15 +1854,15 @@ SizeDumpVnodeIndex(struct iod *iodp, Volume * vp, VnodeClass class, int vnodeIndex; fdP = IH_OPEN(vp->vnodeIndex[class].handle); - assert(fdP != NULL); + osi_Assert(fdP != NULL); file = FDH_FDOPEN(fdP, "r+"); - assert(file != NULL); + osi_Assert(file != NULL); size = OS_SIZE(fdP->fd_fd); - assert(size != -1); + osi_Assert(size != -1); nVnodes = (size / vcp->diskSize) - 1; if (nVnodes > 0) { - assert((nVnodes + 1) * vcp->diskSize == size); - assert(STREAM_ASEEK(file, vcp->diskSize) == 0); + osi_Assert((nVnodes + 1) * vcp->diskSize == size); + osi_Assert(STREAM_ASEEK(file, vcp->diskSize) == 0); } else nVnodes = 0; for (vnodeIndex = 0; diff --git a/src/volser/physio.c b/src/volser/physio.c index 776d23429..e431a3649 100644 --- a/src/volser/physio.c +++ b/src/volser/physio.c @@ -157,5 +157,5 @@ void Die(char *msg) { printf("%s\n", msg); - assert(1 == 2); + osi_Panic("%s\n", msg); } diff --git a/src/volser/vol_split.c b/src/volser/vol_split.c index 300912969..c5587745f 100644 --- a/src/volser/vol_split.c +++ b/src/volser/vol_split.c @@ -11,11 +11,7 @@ #if defined(AFS_NAMEI_ENV) && !defined(AFS_NT40_ENV) #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #ifdef AFS_NT40_ENV #include #include diff --git a/src/volser/volmain.c b/src/volser/volmain.c index cbe53fa1b..4d837d481 100644 --- a/src/volser/volmain.c +++ b/src/volser/volmain.c @@ -31,11 +31,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -478,10 +474,10 @@ main(int argc, char **argv) #ifdef AFS_PTHREAD_ENV pthread_t tid; pthread_attr_t tattr; - assert(pthread_attr_init(&tattr) == 0); - assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); + osi_Assert(pthread_attr_init(&tattr) == 0); + osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0); - assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0); + osi_Assert(pthread_create(&tid, &tattr, BKGLoop, NULL) == 0); #else PROCESS pid; LWP_CreateProcess(BKGLoop, 16*1024, 3, 0, "vol bkg daemon", &pid); diff --git a/src/volser/volprocs.c b/src/volser/volprocs.c index 44d737530..f212dd905 100644 --- a/src/volser/volprocs.c +++ b/src/volser/volprocs.c @@ -34,11 +34,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include @@ -348,14 +344,14 @@ ViceCreateRoot(Volume *vp) IH_CREATE(V_linkHandle(vp), V_device(vp), VPartitionPath(V_partition(vp)), nearInode, V_parentId(vp), 1, 1, 0); - assert(VALID_INO(inodeNumber)); + osi_Assert(VALID_INO(inodeNumber)); SetSalvageDirHandle(&dir, V_parentId(vp), vp->device, inodeNumber); did.Volume = V_id(vp); did.Vnode = (VnodeId) 1; did.Unique = 1; - assert(!(MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did))); + osi_Assert(!(MakeDir(&dir, (afs_int32 *)&did, (afs_int32 *)&did))); DFlush(); /* flush all modified dir buffers out */ DZap((afs_int32 *)&dir); /* Remove all buffers for this dir */ length = Length(&dir); /* Remember size of this directory */ @@ -395,9 +391,9 @@ ViceCreateRoot(Volume *vp) IH_INIT(h, vp->device, V_parentId(vp), vp->vnodeIndex[vLarge].handle->ih_ino); fdP = IH_OPEN(h); - assert(fdP != NULL); + osi_Assert(fdP != NULL); nBytes = FDH_PWRITE(fdP, vnode, SIZEOF_LARGEDISKVNODE, vnodeIndexOffset(vcp, 1)); - assert(nBytes == SIZEOF_LARGEDISKVNODE); + osi_Assert(nBytes == SIZEOF_LARGEDISKVNODE); FDH_REALLYCLOSE(fdP); IH_RELEASE(h); VNDISK_GET_LEN(length, vnode); diff --git a/src/volser/volser.p.h b/src/volser/volser.p.h index 3b39c9e4d..75ffce41a 100644 --- a/src/volser/volser.p.h +++ b/src/volser/volser.p.h @@ -10,8 +10,8 @@ #ifndef _VOLSER_ #define _VOLSER_ 1 +#include #ifdef AFS_PTHREAD_ENV -#include #include #endif @@ -71,13 +71,13 @@ struct volser_trans { #ifdef AFS_PTHREAD_ENV #define VTRANS_OBJ_LOCK_INIT(tt) \ - assert(pthread_mutex_init(&((tt)->lock),NULL) == 0) + MUTEX_INIT(&((tt)->lock), "vtrans obj", MUTEX_DEFAULT, 0); #define VTRANS_OBJ_LOCK_DESTROY(tt) \ - assert(pthread_mutex_destroy(&((tt)->lock)) == 0) + MUTEX_DESTROY(&((tt)->lock)) #define VTRANS_OBJ_LOCK(tt) \ - assert(pthread_mutex_lock(&((tt)->lock)) == 0) + MUTEX_ENTER(&((tt)->lock)) #define VTRANS_OBJ_UNLOCK(tt) \ - assert(pthread_mutex_unlock(&((tt)->lock)) == 0) + MUTEX_EXIT(&((tt)->lock)) #else #define VTRANS_OBJ_LOCK_INIT(tt) #define VTRANS_OBJ_LOCK_DESTROY(tt) diff --git a/src/volser/voltrans.c b/src/volser/voltrans.c index 3fe499d8c..6a0f365e8 100644 --- a/src/volser/voltrans.c +++ b/src/volser/voltrans.c @@ -40,11 +40,7 @@ #include #include #include -#ifdef AFS_PTHREAD_ENV -#include -#else /* AFS_PTHREAD_ENV */ #include -#endif /* AFS_PTHREAD_ENV */ #include #include #include -- 2.39.5