budb: Only have one build rule for budb_errs.c
[openafs.git] / src / budb / dbs_dump.c
index 2b94325..17db2bd 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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
@@ -10,8 +10,7 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
@@ -27,6 +26,9 @@ RCSID
 #include <sys/types.h>
 #include <afs/stds.h>
 #include <stdio.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
 #include <lock.h>
 #include <ubik.h>
 #include <lwp.h>
@@ -34,16 +36,18 @@ RCSID
 #include <rx/rx.h>
 #include <rx/rxkad.h>
 #include <string.h>
-#include <des.h>
 #include <afs/cellconfig.h>
 #include <errno.h>
 #include "budb.h"
 #include "budb_errs.h"
 #include "database.h"
+#include "budb_internal.h"
 #include "error_macros.h"
 #include "globals.h"
 #include "afs/audit.h"
 
+afs_int32 DumpDB(struct rx_call *, int, afs_int32, charListT *, afs_int32 *);
+afs_int32 RestoreDbHeader(struct rx_call *, struct DbHeader *);
 void *dumpWatcher(void *);
 
 /* dump ubik database - interface routines */
@@ -53,8 +57,7 @@ void *dumpWatcher(void *);
  */
 
 afs_int32
-badEntry(dbAddr)
-     afs_uint32 dbAddr;
+badEntry(afs_uint32 dbAddr)
 {
     /* return entry ok */
     return (0);
@@ -67,7 +70,7 @@ badEntry(dbAddr)
 void *
 setupDbDump(void *param)
 {
-    int writeFid = (int)param;
+    int writeFid = (intptr_t)param;
     afs_int32 code = 0;
 
     code = InitRPC(&dumpSyncPtr->ut, LOCKREAD, 1);
@@ -87,18 +90,13 @@ setupDbDump(void *param)
   error_exit:
     if (dumpSyncPtr->ut)
        ubik_EndTrans(dumpSyncPtr->ut);
-    return (void *)(code);
+    return (void *)(intptr_t)(code);
 }
 
 
-afs_int32 DumpDB(), RestoreDbHeader();
 afs_int32
-SBUDB_DumpDB(call, firstcall, maxLength, charListPtr, done)
-     struct rx_call *call;
-     int firstcall;
-     afs_int32 maxLength;
-     charListT *charListPtr;
-     afs_int32 *done;
+SBUDB_DumpDB(struct rx_call *call, int firstcall, afs_int32 maxLength,
+            charListT *charListPtr, afs_int32 *done)
 {
     afs_int32 code;
 
@@ -108,12 +106,11 @@ SBUDB_DumpDB(call, firstcall, maxLength, charListPtr, done)
 }
 
 afs_int32
-DumpDB(call, firstcall, maxLength, charListPtr, done)
-     struct rx_call *call;
-     int firstcall;            /* 1 - init.  0 - no init */
-     afs_int32 maxLength;
-     charListT *charListPtr;
-     afs_int32 *done;
+DumpDB(struct rx_call *call,
+       int firstcall,          /* 1 - init.  0 - no init */
+       afs_int32 maxLength,
+       charListT *charListPtr,
+       afs_int32 *done)
 {
 #ifdef AFS_PTHREAD_ENV
     pthread_t dumperPid, watcherPid;
@@ -131,7 +128,7 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
     ObtainWriteLock(&dumpSyncPtr->ds_lock);
 
     /* If asking for zero bytes, then this is a call to reset the timeToLive
-     * timer. Reset it if there is a dump in progress. 
+     * timer. Reset it if there is a dump in progress.
      */
     if (maxLength == 0) {
        charListPtr->charListT_val = NULL;
@@ -165,21 +162,21 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
        /* 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 =
            LWP_CreateProcess(setupDbDump, 16384, 1,
-                             (void *)dumpSyncPtr->pipeFid[1],
+                             (void *)(intptr_t)dumpSyncPtr->pipeFid[1],
                              "Database Dumper", &dumperPid);
        if (code)
            goto error_exit;
@@ -191,9 +188,9 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
 #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 =
@@ -217,7 +214,7 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
            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)
@@ -228,9 +225,9 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
        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
@@ -259,7 +256,7 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
     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)
@@ -275,9 +272,7 @@ DumpDB(call, firstcall, maxLength, charListPtr, done)
 }
 
 afs_int32
-SBUDB_RestoreDbHeader(call, header)
-     struct rx_call *call;
-     struct DbHeader *header;
+SBUDB_RestoreDbHeader(struct rx_call *call, struct DbHeader *header)
 {
     afs_int32 code;
 
@@ -287,9 +282,7 @@ SBUDB_RestoreDbHeader(call, header)
 }
 
 afs_int32
-RestoreDbHeader(call, header)
-     struct rx_call *call;
-     struct DbHeader *header;
+RestoreDbHeader(struct rx_call *call, struct DbHeader *header)
 {
     struct ubik_trans *ut = 0;
     afs_int32 code = 0;
@@ -327,9 +320,9 @@ RestoreDbHeader(call, header)
 }
 
 /* dumpWatcher
- *     monitors the state of a database dump. If the dump calls do not 
+ *     monitors the state of a database dump. If the dump calls do not
  *     reset the time to live value, the dump times out. In that case,
- *     we kill the database traversal thread and clean up all the other 
+ *     we kill the database traversal thread and clean up all the other
  *     state. Most importantly, the database is unlocked so that other
  *     transactions can proceed.
  */
@@ -359,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)