butc: Remove dead initialisation
[openafs.git] / src / butc / dump.c
index 4788f15..c0d9695 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
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
 
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/time.h>
-#include <sys/file.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <lwp.h>
 #include <lock.h>
-#include <errno.h>
 #include <afs/tcdata.h>
 #include <afs/bubasics.h>
 #include <afs/budb_client.h>
+#include <afs/butm_prototypes.h>
 #include <afs/vldbint.h>
 #include <afs/ktime.h>
 #include <afs/vlserver.h>
+#include <afs/afsint.h>
 #include <afs/volser.h>
+#include <afs/volser_prototypes.h>
 #include <afs/volint.h>
 #include <afs/cellconfig.h>
+#include <afs/bucoord_prototypes.h>
 
+#include "butc_internal.h"
 #include "error_macros.h"
 #include "butc_xbsa.h"
 #include "afs/butx.h"
 
-
 /* GLOBAL CONFIGURATION PARAMETERS */
 extern int dump_namecheck;
 extern int queryoperator;
@@ -55,11 +45,6 @@ extern struct ubik_client *cstruct;
 dlqlinkT savedEntries;
 dlqlinkT entries_to_flush;
 
-afs_int32 flushSavedEntries(), finishDump(), finishTape(), useTape(),
-addVolume();
-
-extern struct rx_connection *UV_Bind();
-
 extern afs_int32 groupId;
 extern afs_int32 BufferSize;
 extern afs_int32 statusSize;
@@ -90,7 +75,7 @@ afs_int32 tapeblocks;         /* Number of 16K tape datablocks in buffer (!CONF_XBSA) *
  * 6) Ensure bucoord status calls work
  *
  * notes
- * pass 3: 
+ * pass 3:
  *     keep token timeout. If no user reponse (idle time > some period)
  *     and tokens about to time out, terminate dump. This provides at
  *     least something usable.
@@ -102,15 +87,6 @@ afs_int32 tapeblocks;               /* Number of 16K tape datablocks in buffer (!CONF_XBSA) *
    else \
      sprintf(dumpname, "%s (DumpId %u)", name, dbDumpId);
 
-#if defined(AFS_NT40_ENV) || (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV)) || defined(AFS_SUN4_ENV)
-int
-localtime_r(time_t * t, struct tm *tm)
-{
-    memcpy(tm, localtime(t), sizeof(struct tm));
-    return 0;
-}
-#endif
-
 struct dumpRock {
     /* status only */
     int tapeSeq;
@@ -138,6 +114,15 @@ struct dumpRock {
     struct dumpNode *node;
 };
 
+/* Forward declarations */
+
+int makeVolumeHeader(struct volumeHeader *, struct dumpRock *, int);
+int volumeHeader_hton(struct volumeHeader *, struct volumeHeader *);
+char retryPrompt(char *, afs_int32, afs_uint32);
+int getDumpTape(struct dumpRock *, int, afs_int32);
+int getXBSATape(struct dumpRock *);
+afs_int32 createDump(struct dumpRock *);
+
 /* configuration variables */
 #define HITEOT(code) ((code == BUTM_IO) || (code == BUTM_EOT) || (code == BUTM_IOCTL))
 extern int autoQuery;
@@ -152,7 +137,6 @@ afs_int32
 calcExpirationDate(afs_int32 expType, afs_int32 expDate, afs_int32 createTime)
 {
     struct ktime_date kd;
-    afs_int32 Add_RelDate_to_Time();
 
     switch (expType) {
     case BC_REL_EXPDATE:
@@ -161,11 +145,9 @@ calcExpirationDate(afs_int32 expType, afs_int32 expDate, afs_int32 createTime)
         */
        Int32To_ktimeRelDate(expDate, &kd);
        return (Add_RelDate_to_Time(&kd, createTime));
-       break;
 
     case BC_ABS_EXPDATE:
        return (expDate);
-       break;
 
     case BC_NO_EXPDATE:
     default:
@@ -173,11 +155,11 @@ calcExpirationDate(afs_int32 expType, afs_int32 expDate, afs_int32 createTime)
     }
 }
 
-afs_int32 curr_bserver = 0;
+afs_uint32 curr_bserver = 0;
 struct rx_connection *curr_fromconn = (struct rx_connection *)0;
 
 struct rx_connection *
-Bind(afs_int32 server)
+Bind(afs_uint32 server)
 {
     if (curr_fromconn) {
        if (curr_bserver == server)     /* Keep connection if have it */
@@ -200,10 +182,10 @@ Bind(afs_int32 server)
 /* notes
  * 1) save the chunksize or otherwise ensure tape space remaining is
  *     check frequently enough
- * 2) This is called once. For partial dumps, need to 
+ * 2) This is called once. For partial dumps, need to
  *     ensure that the tape device is left in the correct state for
  *     further dumps.
- * 
+ *
  */
 #define BIGCHUNK 102400
 
@@ -278,7 +260,7 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
     buffer = bufferBlock + BUTM_HDRSIZE;
 
     /* Dump one volume fragment at a time until we dump the full volume.
-     * A volume with more than 1 fragment means the volume will 'span' 
+     * A volume with more than 1 fragment means the volume will 'span'
      * 2 or more tapes.
      */
     for (fragmentNumber = 1; !endofvolume; fragmentNumber++) { /*frag */
@@ -293,7 +275,7 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
        /* Create and Write the volume header */
        makeVolumeHeader(&hostVolumeHeader, dparamsPtr, fragmentNumber);
        hostVolumeHeader.contd = ((fragmentNumber == 1) ? 0 : TC_VOLCONTD);
-       volumeHeader_hton(&hostVolumeHeader, buffer);
+       volumeHeader_hton(&hostVolumeHeader, (struct volumeHeader *)buffer);
 
        rc = butm_WriteFileData(tapeInfoPtr, buffer, 1,
                                sizeof(hostVolumeHeader));
@@ -315,8 +297,6 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
        chunkSize = 0;
        fragmentvolume = 0;
        while (!endofvolume && !fragmentvolume) {       /*w */
-           bytesread = 0;
-
            /* Check for abort in the middle of writing data */
            if (volBytesRead >= chunkSize) {
                chunkSize += BIGCHUNK;
@@ -332,11 +312,11 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
            /* Determine how much data to read in upcoming RX_Read() call */
            toread = dataSize;
            /* Check if we are close to the EOT. There should at least be some
-            * data on the tape before it is switched. HACK: we have to split a 
-            * volume across tapes because the volume trailer says the dump 
-            * continues on the next tape (and not the filemark). This could 
-            * result in a volume starting on one tape (no volume data dumped) and 
-            * continued on the next tape. It'll work, just requires restore to 
+            * data on the tape before it is switched. HACK: we have to split a
+            * volume across tapes because the volume trailer says the dump
+            * continues on the next tape (and not the filemark). This could
+            * result in a volume starting on one tape (no volume data dumped) and
+            * continued on the next tape. It'll work, just requires restore to
             * switch tapes. This allows many small volumes (<16K) to be dumped.
             */
            kRemaining = butm_remainingKSpace(tapeInfoPtr);
@@ -358,6 +338,13 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
                }
            }
 
+#ifdef xbsa
+           /* Set aside space for the trailing volume header when using large buffers. */
+           if (XBSAMAXBUFFER < toread + sizeof(hostVolumeHeader)) {
+               toread = XBSAMAXBUFFER - sizeof(hostVolumeHeader);
+           }
+#endif
+
            /* Read some volume data. */
            if (fragmentvolume) {
                bytesread = 0;
@@ -380,7 +367,7 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
                hostVolumeHeader.contd = (endofvolume ? 0 : TC_VOLCONTD);
                hostVolumeHeader.magic = TC_VOLENDMAGIC;
                hostVolumeHeader.endTime = (endofvolume ? time(0) : 0);
-               volumeHeader_hton(&hostVolumeHeader, &buffer[bytesread]);
+               volumeHeader_hton(&hostVolumeHeader, (struct volumeHeader *)&buffer[bytesread]);
                bytesread += sizeof(hostVolumeHeader);
            }
 
@@ -469,7 +456,7 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
     dparamsPtr->curVolumeStatus = DUMP_SUCCESS;
 
   error_exit:
-    /* 
+    /*
      * If we hit the end, see if this is the first volume on the tape or not.
      * Also, mark the tape as finished if the tape contains other dumps.
      */
@@ -492,7 +479,7 @@ dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
        }
     }
 
-    /* 
+    /*
      * This is used when an error occurs part way into a volume dump. Clean
      * the tape state by writing an FileEnd mark. Forgo this action if we hit
      * the end of tape.
@@ -631,10 +618,10 @@ xbsaDumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
     /* Create and Write the volume header */
     makeVolumeHeader(&hostVolumeHeader, dparamsPtr, 1);
     hostVolumeHeader.contd = 0;
-    volumeHeader_hton(&hostVolumeHeader, buffer);
+    volumeHeader_hton(&hostVolumeHeader, (struct volumeHeader *)buffer);
 
-    rc = xbsa_WriteObjectData(&butxInfo, buffer, sizeof(struct volumeHeader),
-                             &bytesWritten);
+    rc = xbsa_WriteObjectData(&butxInfo, (struct volumeHeader *)buffer,
+                             sizeof(struct volumeHeader), &bytesWritten);
     if (rc != XBSA_SUCCESS) {
        ErrorLog(1, taskId, rc, 0,
                 "Unable to write VolumeHeader data to the server\n");
@@ -660,8 +647,6 @@ xbsaDumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
     volBytesRead = 0;
     chunkSize = 0;
     while (!endofvolume) {     /*w */
-       bytesread = 0;
-
        /* Check for abort in the middle of writing data */
        if (volBytesRead >= chunkSize) {
            chunkSize += BIGCHUNK;
@@ -699,7 +684,7 @@ xbsaDumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
            bytesread += sizeof(hostVolumeHeader);
 
            /* End the dump and transaction with the volserver. We end it now, before
-            * we make the XBSA call because if XBSA blocks, we could time out on the 
+            * we make the XBSA call because if XBSA blocks, we could time out on the
             * volserver (After last read, the transaction with the volserver is idle).
             */
            rc = rx_EndCall(fromcall, 0);
@@ -849,7 +834,6 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
     int action, e;
     afs_int32 code = 0, tcode, dvcode;
     char ch;
-    char retryPrompt();
     struct vldbentry vldbEntry;
     struct sockaddr_in server;
     afs_int32 tapepos;
@@ -927,7 +911,6 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
                         curDump->name, curDump->vid);
                curDump->hostAddr = 0;
                continue;
-               break;
            }
 
            if (e >= vldbEntry.nServers) {
@@ -966,8 +949,8 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
        if (checkAbortByTaskId(taskId))
            ERROR_EXIT(TC_ABORTEDBYREQUEST);
 
-       /* Establish connection to volume - UV_ routine expects 
-        * host address in network order 
+       /* Establish connection to volume - UV_ routine expects
+        * host address in network order
         */
        if (CONF_XBSA) {
            dvcode = xbsaDumpVolume(curDump, dparamsPtr);
@@ -1019,7 +1002,6 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
                case 'r':       /* retry */
                    dparamsPtr->curVolume--;    /* redump this volume */
                    continue;
-                   break;
                case 'o':       /* omit */
                    ErrorLog(1, taskId, 0, 0, "Volume %s (%u) omitted\n",
                             curDump->name, curDump->vid);
@@ -1051,7 +1033,6 @@ dumpPass(struct dumpRock * dparamsPtr, int passNumber)
 
            dparamsPtr->curVolume--;    /* redump this volume */
            continue;
-           break;
 
        case DUMP_NORETRYEOT:
            ErrorLog(1, taskId, 0, 0,
@@ -1143,8 +1124,8 @@ Dumper(void *param)
 
     extern struct deviceSyncNode *deviceLatch;
     extern struct tapeConfig globalTapeConfig;
-    extern afs_int32 createDump();
 
+    afs_pthread_setname_self("dumper");
     taskId = nodePtr->taskID;  /* Get task Id */
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
@@ -1261,14 +1242,14 @@ Dumper(void *param)
            break;
     }
 
-    /* 
+    /*
      * Log the error but ignore it since the dump is effectively done.
      * Scantape may assume another volume and ask for next tape.
      */
     if (!CONF_XBSA) {
        code = butm_WriteEOT(&tapeInfo);
        if (code)
-           TapeLog(taskId, code, tapeInfo.error,
+           TapeLog(0, taskId, code, tapeInfo.error,
                    "Warning: Can't write end-of-dump on tape\n");
     }
 
@@ -1353,14 +1334,14 @@ Dumper(void *param)
        sprintf(line,
                "%-5d  %02d/%02d/%04d %02d:%02d:%02d  "
                "%02d/%02d/%04d %02d:%02d:%02d  " "%02d:%02d:%02d  "
-               "%s %d of %d volumes dumped (%ld KB)\n", taskId,
+               "%s %d of %d volumes dumped (%lu KB)\n", taskId,
                tmstart.tm_mon + 1, tmstart.tm_mday, tmstart.tm_year + 1900,
                tmstart.tm_hour, tmstart.tm_min, tmstart.tm_sec,
                tmend.tm_mon + 1, tmend.tm_mday, tmend.tm_year + 1900,
                tmend.tm_hour, tmend.tm_min, tmend.tm_sec, hrs, min, sec,
                nodePtr->volumeSetName, dumpedvolumes,
                dumpedvolumes + failedvolumes,
-               dparams.tapeInfoPtr->kBytes + 1);
+               afs_printable_uint32_lu(dparams.tapeInfoPtr->kBytes + 1));
 
        fwrite(line, strlen(line), 1, centralLogIO);
        fflush(centralLogIO);
@@ -1370,7 +1351,7 @@ Dumper(void *param)
 
     FreeNode(taskId);          /* free the dump node */
     LeaveDeviceQueue(deviceLatch);
-    return (void *)(code);
+    return (void *)(intptr_t)(code);
 }
 
 #define BELLTIME 60            /* 60 seconds before a bell rings */
@@ -1381,7 +1362,7 @@ Dumper(void *param)
  *     volume parameters describe the volume that failed
  * entry:
  *     volumeName - name of volume
- *     volumeId - volume id 
+ *     volumeId - volume id
  *     taskId - for job contrl
  * fn return:
  *     character typed by user, one of r, o or a
@@ -1405,17 +1386,13 @@ retryPrompt(char *volumeName, afs_int32 volumeId, afs_uint32 taskId)
     printf("a - abort, the entire dump\n");
 
     while (1) {
-       FFlushInput(stdin);
+       FFlushInput();
        putchar(BELLCHAR);
        fflush(stdout);
 
        start = time(0);
        while (1) {
-#ifdef AFS_PTHREAD_ENV
-           code = GetResponseKey(5, &ch);      /* ch stores key pressed */
-#else
            code = LWP_GetResponseKey(5, &ch);  /* ch stores key pressed */
-#endif
            if (code == 1)
                break;          /* input is available */
 
@@ -1528,7 +1505,6 @@ getDumpTape(struct dumpRock *dparamsPtr, int interactiveFlag,
     afs_int32 tapepos, lastpos;
 
     extern struct tapeConfig globalTapeConfig;
-    extern struct udbHandleS udbHandle;
 
     askForTape = interactiveFlag;
     dparamsPtr->wroteLabel = 0;
@@ -1744,7 +1720,7 @@ getDumpTape(struct dumpRock *dparamsPtr, int interactiveFlag,
 
        /*
         * Now have the right tape. Create a new label for the tape
-        * Appended labels have the dump's dumpId - labels at beginnings of 
+        * Appended labels have the dump's dumpId - labels at beginnings of
         *     tape have the initial dump's dumpId.
         * Appended labels do not increment the useCount.
         * Labels at beginnings of tape use the most future expiration of the dump set.
@@ -1874,7 +1850,7 @@ makeVolumeHeader(struct volumeHeader *vhptr, struct dumpRock *dparamsPtr,
     strcpy(vhptr->dumpSetName, nodePtr->dumpSetName);
     strcpy(vhptr->preamble, "H++NAME#");
     strcpy(vhptr->postamble, "T--NAME#");
-  
+
     return (code);
 }
 
@@ -2051,6 +2027,7 @@ DeleteDump(void *param)
     extern struct udbHandleS udbHandle;
     extern struct deviceSyncNode *deviceLatch;
 
+    afs_pthread_setname_self("deletedump");
     setStatus(taskId, DRIVE_WAIT);
     EnterDeviceQueue(deviceLatch);
     clearStatus(taskId, DRIVE_WAIT);
@@ -2215,6 +2192,6 @@ DeleteDump(void *param)
        code = BUTX_DELETENOVOL;
        setStatus(taskId, TASK_ERROR);
     }
-    return (code);
+    return (void *)(code);
 }
 #endif