2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include <sys/types.h>
22 #include <netinet/in.h>
23 #include <sys/socket.h>
33 #include <afs/tcdata.h>
34 #include <afs/bubasics.h>
35 #include <afs/budb_client.h>
36 #include <afs/vldbint.h>
37 #include <afs/ktime.h>
38 #include <afs/vlserver.h>
39 #include <afs/volser.h>
40 #include <afs/volint.h>
41 #include <afs/cellconfig.h>
43 #include "error_macros.h"
44 #include "butc_xbsa.h"
48 /* GLOBAL CONFIGURATION PARAMETERS */
49 extern int dump_namecheck;
50 extern int queryoperator;
52 extern int forcemultiple;
54 extern struct ubik_client *cstruct;
55 dlqlinkT savedEntries;
56 dlqlinkT entries_to_flush;
58 afs_int32 flushSavedEntries(), finishDump(), finishTape(), useTape(),
61 extern struct rx_connection *UV_Bind();
63 extern afs_int32 groupId;
64 extern afs_int32 BufferSize;
65 extern afs_int32 statusSize;
66 extern FILE *centralLogIO;
67 afs_int32 lastPass = 0;
69 extern afs_int32 xbsaType;
70 char *butcdumpIdStr = "/backup_afs_volume_dumps";
71 extern struct butx_transactionInfo butxInfo;
72 extern char *xbsaObjectOwner;
73 extern char *appObjectOwner;
74 extern char *xbsaSecToken;
75 extern char *xbsalGName;
76 extern char *globalButcLog;
79 afs_int32 dataSize; /* Size of data to read on each rx_Read() call */
80 afs_int32 tapeblocks; /* Number of 16K tape datablocks in buffer (!CONF_XBSA) */
84 * Done 1) dump id generation
85 * Done xx) volume fragment number accounting !! I think.
86 * 2) check abort - check after subroutine calls
87 * Done 3) trailer anomaly
88 * 4) trailer damage indicator after partial dumps ( affects scandump )
89 * Done 5) Ensure mount failure logged
90 * 6) Ensure bucoord status calls work
94 * keep token timeout. If no user reponse (idle time > some period)
95 * and tokens about to time out, terminate dump. This provides at
96 * least something usable.
99 #define DUMPNAME(dumpname, name, dbDumpId) \
101 sprintf(dumpname, "%s", name); \
103 sprintf(dumpname, "%s (DumpId %u)", name, dbDumpId);
105 #if defined(AFS_NT40_ENV) || (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV)) || defined(AFS_SUN4_ENV)
107 localtime_r(time_t * t, struct tm *tm)
109 memcpy(tm, localtime(t), sizeof(struct tm));
117 int curVolume; /* index in dumpNode of volume */
118 int curVolumeStatus; /* more explicit dump state */
119 afs_uint32 curVolStartPos; /* Starting position of the current volume */
120 afs_uint32 databaseDumpId; /* real dump id, for db */
121 afs_uint32 initialDumpId; /* the initial dump, for appended dumps */
122 afs_int32 volumesDumped; /* # volumes successfully dumped */
123 afs_int32 volumesFailed; /* # volumes that failed to dump */
124 afs_int32 volumesNotDumped; /* # volumes that were not dumped (didn't fail) */
126 /* tape management */
127 char tapeName[TC_MAXTAPENAMELEN];
128 struct butm_tapeInfo *tapeInfoPtr;
129 struct butm_tapeLabel tapeLabel;
130 int wroteLabel; /* If the tape label is written */
132 /* database information */
133 struct budb_dumpEntry lastDump; /* the last dump of this volset */
134 struct budb_dumpEntry dump; /* current dump */
135 struct budb_tapeEntry tape; /* current tape, not used -VA */
137 /* links to existing info */
138 struct dumpNode *node;
141 /* configuration variables */
142 #define HITEOT(code) ((code == BUTM_IO) || (code == BUTM_EOT) || (code == BUTM_IOCTL))
143 extern int autoQuery;
146 afs_int32 tc_EndMargin;
147 afs_int32 tc_KEndMargin;
148 static char *bufferBlock;
150 /* compute the absolute expiration date */
152 calcExpirationDate(afs_int32 expType, afs_int32 expDate, afs_int32 createTime)
154 struct ktime_date kd;
155 afs_int32 Add_RelDate_to_Time();
159 /* expiration date is relative to the creation time of the dump.
160 * This is the only case that requires any work
162 Int32To_ktimeRelDate(expDate, &kd);
163 return (Add_RelDate_to_Time(&kd, createTime));
176 afs_int32 curr_bserver = 0;
177 struct rx_connection *curr_fromconn = (struct rx_connection *)0;
179 struct rx_connection *
180 Bind(afs_int32 server)
183 if (curr_bserver == server) /* Keep connection if have it */
184 return (curr_fromconn);
186 rx_DestroyConnection(curr_fromconn); /* Otherwise get rid of it */
187 curr_fromconn = (struct rx_connection *)0;
192 curr_fromconn = UV_Bind(server, AFSCONF_VOLUMEPORT); /* Establish new connection */
194 curr_bserver = server;
197 return (curr_fromconn);
201 * 1) save the chunksize or otherwise ensure tape space remaining is
202 * check frequently enough
203 * 2) This is called once. For partial dumps, need to
204 * ensure that the tape device is left in the correct state for
208 #define BIGCHUNK 102400
211 dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
213 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
214 struct dumpNode *nodePtr = dparamsPtr->node;
215 afs_int32 taskId = nodePtr->taskID;
218 afs_int32 volumeFlags;
219 afs_int32 kRemaining;
220 afs_int32 rc, code = 0;
222 afs_uint32 volBytesRead;
223 afs_uint32 chunkSize;
224 afs_int32 bytesread; /* rx reads */
225 int endofvolume = 0; /* Have we read all volume data */
228 struct volumeHeader hostVolumeHeader;
230 struct rx_call *fromcall = (struct rx_call *)0;
231 struct rx_connection *fromconn;
232 afs_int32 updatedate, fromtid = 0;
233 volEntries volumeInfo;
234 afs_int32 bytesWritten;
235 afs_uint32 statuscount = statusSize, tsize = 0;
237 dparamsPtr->curVolumeStatus = DUMP_NOTHING;
239 fromconn = Bind(htonl(curDump->hostAddr)); /* get connection to the server */
241 /* Determine when the volume was last cloned and updated */
242 volumeInfo.volEntries_val = (volintInfo *) 0;
243 volumeInfo.volEntries_len = 0;
244 rc = AFSVolListOneVolume(fromconn, curDump->partition, curDump->vid,
248 updatedate = volumeInfo.volEntries_val[0].updateDate;
251 RWVOL) ? time(0) : volumeInfo.volEntries_val[0].creationDate);
253 if (curDump->date >= curDump->cloneDate)
254 ERROR_EXIT(0); /* not recloned since last dump */
255 if (curDump->date > updatedate) {
256 dparamsPtr->curVolumeStatus = DUMP_NODUMP; /* not modified since last dump */
260 /* Start the volserver transaction and dump */
261 rc = AFSVolTransCreate(fromconn, curDump->vid, curDump->partition, ITBusy,
265 fromcall = rx_NewCall(fromconn);
267 rc = StartAFSVolDump(fromcall, fromtid, curDump->date);
271 dparamsPtr->curVolumeStatus = DUMP_PARTIAL;
272 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
274 /* buffer is place in bufferBlock to write volume data.
275 * butm_writeFileData() assumes the previous BUTM_HDRSIZE bytes
276 * is available to write the tape block header.
278 buffer = bufferBlock + BUTM_HDRSIZE;
280 /* Dump one volume fragment at a time until we dump the full volume.
281 * A volume with more than 1 fragment means the volume will 'span'
284 for (fragmentNumber = 1; !endofvolume; fragmentNumber++) { /*frag */
285 rc = butm_WriteFileBegin(tapeInfoPtr);
287 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
288 "Can't write FileBegin on tape\n");
291 indump = 1; /* first write to tape */
293 /* Create and Write the volume header */
294 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, fragmentNumber);
295 hostVolumeHeader.contd = ((fragmentNumber == 1) ? 0 : TC_VOLCONTD);
296 volumeHeader_hton(&hostVolumeHeader, buffer);
298 rc = butm_WriteFileData(tapeInfoPtr, buffer, 1,
299 sizeof(hostVolumeHeader));
301 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
302 "Can't write VolumeHeader on tape\n");
306 bytesWritten = BUTM_BLOCKSIZE; /* Wrote one tapeblock */
307 tsize += bytesWritten;
309 /* Start reading volume data, rx_Read(), and dumping to the tape
310 * until we've dumped the entire volume (endofvolume == 1). We can
311 * exit this loop early if we find we are close to the end of the
312 * tape; in which case we dump the next fragment on the next tape.
317 while (!endofvolume && !fragmentvolume) { /*w */
320 /* Check for abort in the middle of writing data */
321 if (volBytesRead >= chunkSize) {
322 chunkSize += BIGCHUNK;
323 if (checkAbortByTaskId(taskId))
324 ABORT_EXIT(TC_ABORTEDBYREQUEST);
326 /* set bytes dumped for backup */
328 nodePtr->statusNodePtr->nKBytes = tapeInfoPtr->kBytes;
332 /* Determine how much data to read in upcoming RX_Read() call */
334 /* Check if we are close to the EOT. There should at least be some
335 * data on the tape before it is switched. HACK: we have to split a
336 * volume across tapes because the volume trailer says the dump
337 * continues on the next tape (and not the filemark). This could
338 * result in a volume starting on one tape (no volume data dumped) and
339 * continued on the next tape. It'll work, just requires restore to
340 * switch tapes. This allows many small volumes (<16K) to be dumped.
342 kRemaining = butm_remainingKSpace(tapeInfoPtr);
343 if ((kRemaining < tc_KEndMargin)
345 || (tapeInfoPtr->position > (isafile ? 3 : 2)))) {
350 /* Guess at how much data to read. So we don't write off end of tape */
351 if (kRemaining < (tapeblocks * 16)) {
352 if (kRemaining < 0) {
353 toread = BUTM_BLKSIZE;
355 toread = ((kRemaining / 16) + 1) * BUTM_BLKSIZE;
356 if (toread > dataSize)
361 /* Read some volume data. */
362 if (fragmentvolume) {
365 bytesread = rx_Read(fromcall, buffer, toread);
366 volBytesRead += bytesread;
367 if (bytesread != toread) {
368 /* Make sure were at end of volume and not a communication error */
369 rc = rx_Error(fromcall);
376 if (fragmentvolume || endofvolume) {
377 /* Create a volume trailer appending it to this data block */
378 makeVolumeHeader(&hostVolumeHeader, dparamsPtr,
380 hostVolumeHeader.contd = (endofvolume ? 0 : TC_VOLCONTD);
381 hostVolumeHeader.magic = TC_VOLENDMAGIC;
382 hostVolumeHeader.endTime = (endofvolume ? time(0) : 0);
383 volumeHeader_hton(&hostVolumeHeader, &buffer[bytesread]);
384 bytesread += sizeof(hostVolumeHeader);
387 /* Write the datablock out */
388 /* full data buffer - write it to tape */
389 rc = butm_WriteFileData(tapeInfoPtr, buffer, tapeblocks,
392 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
393 "Can't write VolumeData on tape\n");
396 bytesWritten = tapeblocks * BUTM_BLOCKSIZE;
397 tsize += bytesWritten;
399 /* Display a status line every statusSize or at end of volume */
401 && ((tsize >= statuscount) || endofvolume
402 || fragmentvolume)) {
405 localtime_r(&t, &tm);
406 printf("%02d:%02d:%02d: Task %u: %u KB: %s: %u B\n",
407 tm.tm_hour, tm.tm_min, tm.tm_sec, taskId,
408 tapeInfoPtr->kBytes, hostVolumeHeader.volumeName,
410 statuscount = tsize + statusSize;
414 /* End the dump before recording it in BUDB as successfully dumped */
415 rc = butm_WriteFileEnd(tapeInfoPtr);
418 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
419 "Can't write FileEnd on tape\n");
423 /* Record in BUDB the volume fragment as succcessfully dumped */
424 volumeFlags = ((fragmentNumber == 1) ? BUDB_VOL_FIRSTFRAG : 0);
426 volumeFlags |= BUDB_VOL_LASTFRAG;
427 rc = addVolume(0, dparamsPtr->databaseDumpId, dparamsPtr->tapeName,
428 nodePtr->dumps[dparamsPtr->curVolume].name,
429 nodePtr->dumps[dparamsPtr->curVolume].vid,
430 nodePtr->dumps[dparamsPtr->curVolume].cloneDate,
431 dparamsPtr->curVolStartPos, volBytesRead,
432 (fragmentNumber - 1), volumeFlags);
436 /* If haven't finished dumping the volume, end this
437 * tape and get the next tape.
440 /* Write an EOT marker.
441 * Log the error but ignore it since the dump is effectively done.
442 * Scantape will detect continued volume and not read the EOT.
444 rc = butm_WriteEOT(tapeInfoPtr);
446 TapeLog(1, taskId, rc, tapeInfoPtr->error,
447 "Warning: Can't write End-Of-Dump on tape\n");
449 /* Unmount the tape */
450 unmountTape(taskId, tapeInfoPtr);
452 /* Tell the database the tape is complete (and ok) */
453 rc = finishTape(&dparamsPtr->tape,
454 dparamsPtr->tapeInfoPtr->kBytes +
455 (dparamsPtr->tapeInfoPtr->nBytes ? 1 : 0));
459 /* get the next tape. Prompt, mount, and add it into the database */
460 dparamsPtr->tapeSeq++;
461 rc = getDumpTape(dparamsPtr, 1, 0); /* interactive - no append */
465 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
469 dparamsPtr->curVolumeStatus = DUMP_SUCCESS;
473 * If we hit the end, see if this is the first volume on the tape or not.
474 * Also, mark the tape as finished if the tape contains other dumps.
479 ErrorLog(2, taskId, code, tapeInfoPtr->error,
480 "Warning: Dump (%s) hit end-of-tape inferred\n",
481 nodePtr->dumpSetName);
483 if (tapeInfoPtr->position == 2) {
484 dparamsPtr->curVolumeStatus = DUMP_NORETRYEOT;
486 dparamsPtr->curVolumeStatus = DUMP_RETRY;
487 rc = finishTape(&dparamsPtr->tape,
488 dparamsPtr->tapeInfoPtr->kBytes +
489 (dparamsPtr->tapeInfoPtr->nBytes ? 1 : 0));
496 * This is used when an error occurs part way into a volume dump. Clean
497 * the tape state by writing an FileEnd mark. Forgo this action if we hit
501 rc = butm_WriteFileEnd(tapeInfoPtr);
504 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
505 "Can't write FileEnd on tape\n");
510 rc = rx_EndCall(fromcall, 0);
517 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
519 code = (rc ? rc : rcode);
525 dparamsPtr->curVolumeStatus = DUMP_FAILED;
530 xbsaDumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
533 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
534 struct dumpNode *nodePtr = dparamsPtr->node;
535 char *buffer = bufferBlock;
536 afs_int32 taskId = nodePtr->taskID;
537 afs_int32 rc, code = 0;
539 afs_uint32 volBytesRead;
540 afs_uint32 chunkSize;
541 afs_int32 bytesread; /* rx reads */
542 int endofvolume = 0; /* Have we read all volume data */
543 int begindump = 0, indump = 0; /* if dump transaction started; if dumping data */
544 struct volumeHeader hostVolumeHeader;
546 struct rx_call *fromcall = (struct rx_call *)0;
547 struct rx_connection *fromconn;
548 afs_int32 updatedate, fromtid = 0;
549 volEntries volumeInfo;
550 afs_int32 bytesWritten;
551 afs_uint32 statuscount = statusSize, tsize = 0, esize;
554 char dumpIdStr[XBSA_MAX_OSNAME];
555 char volumeNameStr[XBSA_MAX_PATHNAME];
556 static char *dumpDescription = "AFS volume dump";
557 static char *objectDescription = "XBSA - butc";
559 dparamsPtr->curVolumeStatus = DUMP_NOTHING;
561 fromconn = Bind(htonl(curDump->hostAddr)); /* get connection to the server */
563 /* Determine when the volume was last cloned and updated */
564 volumeInfo.volEntries_val = (volintInfo *) 0;
565 volumeInfo.volEntries_len = 0;
566 rc = AFSVolListOneVolume(fromconn, curDump->partition, curDump->vid,
570 updatedate = volumeInfo.volEntries_val[0].updateDate;
573 RWVOL) ? time(0) : volumeInfo.volEntries_val[0].creationDate);
575 /* Get the volume size (in KB) and increase by 25%. Then set as a hyper */
576 esize = volumeInfo.volEntries_val[0].size;
577 esize += (esize / 4) + 1;
579 if (curDump->date >= curDump->cloneDate)
580 ERROR_EXIT(0); /* not recloned since last dump */
581 if (curDump->date > updatedate) {
582 dparamsPtr->curVolumeStatus = DUMP_NODUMP; /* not modified since last dump */
586 /* Start a new XBSA Transaction */
587 rc = xbsa_BeginTrans(&butxInfo);
588 if (rc != XBSA_SUCCESS) {
589 ErrorLog(1, taskId, rc, 0, "Unable to create a new transaction\n");
592 begindump = 1; /* Will need to do an xbsa_EndTrans */
594 /* Start the volserver transaction and dump. Once started, the
595 * volume status is "partial dump". Also, the transaction with
596 * the volserver is idle until the first read. An idle transaction
597 * will time out in 600 seconds. After the first rx_Read,
598 * the transaction is not idle. See GCTrans().
600 rc = AFSVolTransCreate(fromconn, curDump->vid, curDump->partition, ITBusy,
604 fromcall = rx_NewCall(fromconn);
606 rc = StartAFSVolDump(fromcall, fromtid, curDump->date);
610 dparamsPtr->curVolumeStatus = DUMP_PARTIAL;
611 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
613 /* Tell XBSA what the name and size of volume to write */
614 strcpy(dumpIdStr, butcdumpIdStr); /* "backup_afs_volume_dumps" */
615 sprintf(volumeNameStr, "/%d", dparamsPtr->databaseDumpId);
616 strcat(volumeNameStr, "/");
617 strcat(volumeNameStr, curDump->name); /* <dumpid>/<volname> */
618 hset32(estSize, esize);
619 hshlft(estSize, 10); /* Multiply by 1024 so its in KB */
621 rc = xbsa_WriteObjectBegin(&butxInfo, dumpIdStr, volumeNameStr,
622 xbsalGName, estSize, dumpDescription,
624 if (rc != XBSA_SUCCESS) {
625 ErrorLog(1, taskId, rc, 0,
626 "Unable to begin writing of the fileset data to the server\n");
629 indump = 1; /* Will need to do an xbsa_WriteObjectEnd */
631 /* Create and Write the volume header */
632 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, 1);
633 hostVolumeHeader.contd = 0;
634 volumeHeader_hton(&hostVolumeHeader, buffer);
636 rc = xbsa_WriteObjectData(&butxInfo, buffer, sizeof(struct volumeHeader),
638 if (rc != XBSA_SUCCESS) {
639 ErrorLog(1, taskId, rc, 0,
640 "Unable to write VolumeHeader data to the server\n");
643 /* There is a bug in the ADSM library where the bytesWritten is
644 * not filled in, so we set it as correct anyway.
646 bytesWritten = sizeof(struct volumeHeader);
647 if (bytesWritten != sizeof(struct volumeHeader)) {
648 ErrorLog(1, taskId, rc, 0,
649 "The size of VolumeHeader written (%d) does not equal its actual size (%d)\n",
650 bytesWritten, sizeof(struct volumeHeader));
651 ERROR_EXIT(TC_INTERNALERROR);
654 incSize(tapeInfoPtr, sizeof(struct volumeHeader)); /* Increment amount we've written */
655 tsize += bytesWritten;
657 /* Start reading volume data, rx_Read(), and dumping to the tape
658 * until we've dumped the entire volume (endofvolume == 1).
662 while (!endofvolume) { /*w */
665 /* Check for abort in the middle of writing data */
666 if (volBytesRead >= chunkSize) {
667 chunkSize += BIGCHUNK;
668 if (checkAbortByTaskId(taskId))
669 ABORT_EXIT(TC_ABORTEDBYREQUEST);
671 /* set bytes dumped for backup */
673 nodePtr->statusNodePtr->nKBytes = tapeInfoPtr->kBytes;
677 /* Determine how much data to read in upcoming RX_Read() call */
680 /* Read some volume data. */
681 bytesread = rx_Read(fromcall, buffer, toread);
682 volBytesRead += bytesread;
683 if (bytesread != toread) {
686 /* Make sure were at end of volume and not a communication error */
687 rc = rx_Error(fromcall);
693 /* Create a volume trailer appending it to this data block (if not XBSA) */
694 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, 1);
695 hostVolumeHeader.contd = 0;
696 hostVolumeHeader.magic = TC_VOLENDMAGIC;
697 hostVolumeHeader.endTime = time(0);
698 volumeHeader_hton(&hostVolumeHeader, &buffer[bytesread]);
699 bytesread += sizeof(hostVolumeHeader);
701 /* End the dump and transaction with the volserver. We end it now, before
702 * we make the XBSA call because if XBSA blocks, we could time out on the
703 * volserver (After last read, the transaction with the volserver is idle).
705 rc = rx_EndCall(fromcall, 0);
710 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
716 /* Write the datablock out */
717 rc = xbsa_WriteObjectData(&butxInfo, buffer, bytesread,
719 if (rc != XBSA_SUCCESS) {
720 ErrorLog(1, taskId, rc, 0,
721 "Unable to write data to the server\n");
724 /* There is a bug in the ADSM library where the bytesWritten is
725 * not filled in, so we set it as correct anyway.
727 bytesWritten = bytesread;
728 if (bytesWritten != bytesread) {
729 ErrorLog(1, taskId, rc, 0,
730 "The size of data written (%d) does not equal size read (%d)\n",
731 bytesWritten, bytesread);
732 ERROR_EXIT(TC_INTERNALERROR);
735 incSize(tapeInfoPtr, bytesread); /* Increment amount we've written */
736 tsize += bytesWritten;
738 /* Display a status line every statusSize or at end of volume */
739 if (statusSize && ((tsize >= statuscount) || endofvolume)) {
742 localtime_r(&t, &tm);
743 printf("%02d:%02d:%02d: Task %u: %u KB: %s: %u B\n", tm.tm_hour,
744 tm.tm_min, tm.tm_sec, taskId, tapeInfoPtr->kBytes,
745 hostVolumeHeader.volumeName, tsize);
746 statuscount = tsize + statusSize;
750 /* End the XBSA transaction before recording it in BUDB as successfully dumped */
751 rc = xbsa_WriteObjectEnd(&butxInfo);
753 if (rc != XBSA_SUCCESS) {
754 ErrorLog(1, taskId, rc, 0,
755 "Unable to terminate writing of the volume data to the server");
758 rc = xbsa_EndTrans(&butxInfo);
760 tapeInfoPtr->position++;
761 if (rc != XBSA_SUCCESS) {
762 ErrorLog(1, taskId, rc, 0,
763 "Unable to terminate the current transaction");
767 /* Record in BUDB the volume fragment as succcessfully dumped */
768 rc = addVolume(0, dparamsPtr->databaseDumpId, dparamsPtr->tapeName,
769 nodePtr->dumps[dparamsPtr->curVolume].name,
770 nodePtr->dumps[dparamsPtr->curVolume].vid,
771 nodePtr->dumps[dparamsPtr->curVolume].cloneDate,
772 dparamsPtr->curVolStartPos, volBytesRead, 0 /*frag0 */ ,
773 (BUDB_VOL_FIRSTFRAG | BUDB_VOL_LASTFRAG));
777 dparamsPtr->curVolumeStatus = DUMP_SUCCESS;
780 /* Cleanup after an error occurs part way into a volume dump */
782 rc = rx_EndCall(fromcall, 0);
789 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
791 code = (rc ? rc : rcode);
794 /* If this dump failed, what happens to successive retries
795 * of the volume? How do they get recorded in the XBSA database
796 * (overwritten)? If not, we don't record this in the BUDB database
797 * so it will not be removed when we delete the dump. What to do?
798 * Also if the volume was never recorded in the DB (partial dump).
802 rc = xbsa_WriteObjectEnd(&butxInfo);
804 if (rc != XBSA_SUCCESS) {
805 ErrorLog(1, taskId, rc, 0,
806 "Unable to terminate writing of the volume data to the server");
808 tapeInfoPtr->position++;
812 /* End the XBSA Transaction */
813 rc = xbsa_EndTrans(&butxInfo);
815 if (rc != XBSA_SUCCESS) {
816 ErrorLog(1, taskId, rc, 0,
817 "Unable to terminate the current transaction");
824 dparamsPtr->curVolumeStatus = DUMP_FAILED;
831 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
834 * Go through the list of volumes to dump, dumping each one. The action
835 * taken when a volume dump fails, depends on the passNumber. At minimum,
836 * the failed volume is remembered.
838 * flushSavedEntries - inconsistent treatment for errors. What should
839 * be done for user aborts?
843 dumpPass(struct dumpRock * dparamsPtr, int passNumber)
845 struct dumpNode *nodePtr = dparamsPtr->node;
846 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
847 afs_int32 taskId = nodePtr->taskID;
848 struct tc_dumpDesc *curDump;
850 afs_int32 code = 0, tcode, dvcode;
853 struct vldbentry vldbEntry;
854 struct sockaddr_in server;
857 TapeLog(2, taskId, 0, 0, "Starting pass %d\n", passNumber);
859 /* while there are more volumes to dump */
860 for (dparamsPtr->curVolume = 0; dparamsPtr->curVolume < nodePtr->arraySize; dparamsPtr->curVolume++) { /*w */
861 curDump = &nodePtr->dumps[dparamsPtr->curVolume];
862 if (curDump->hostAddr == 0)
865 /* set name of current volume being dumped */
867 strcpy(nodePtr->statusNodePtr->volumeName, curDump->name);
870 /* Determine location of the volume.
871 * In case the volume moved has moved.
873 if (passNumber > 1) { /*pass */
875 bc_GetEntryByID(cstruct, curDump->vid, curDump->vtype,
878 ErrorLog(0, taskId, tcode, 0,
879 "Volume %s (%u) failed - Can't find volume in VLDB\n",
880 curDump->name, curDump->vid);
881 curDump->hostAddr = 0;
882 dparamsPtr->volumesFailed++;
886 switch (curDump->vtype) {
888 if (!(vldbEntry.flags & BACK_EXISTS)) {
889 ErrorLog(0, taskId, 0, 0,
890 "Volume %s (%u) failed - Backup volume no longer exists\n",
891 curDump->name, curDump->vid);
892 curDump->hostAddr = 0;
893 dparamsPtr->volumesFailed++;
896 /* Fall into RWVOL case */
899 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the RW volume */
900 if (vldbEntry.serverFlags[e] & ITSRWVOL)
906 /* Try to use the server and partition we found the volume on
907 * Otherwise, use the first RO volume.
909 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the RO volume */
910 if ((curDump->hostAddr == vldbEntry.serverNumber[e])
911 && (curDump->partition ==
912 vldbEntry.serverPartition[e]))
916 if (e >= vldbEntry.nServers) { /* Didn't find RO volume */
917 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the first RO volume */
918 if (vldbEntry.serverFlags[e] & ITSROVOL)
925 ErrorLog(0, taskId, 0, 0,
926 "Volume %s (%u) failed - Unknown volume type\n",
927 curDump->name, curDump->vid);
928 curDump->hostAddr = 0;
933 if (e >= vldbEntry.nServers) {
934 ErrorLog(0, taskId, 0, 0,
935 "Volume %s (%u) failed - Can't find volume entry in VLDB\n",
936 curDump->name, curDump->vid);
937 curDump->hostAddr = 0;
938 dparamsPtr->volumesFailed++;
942 /* Remember the server and partition the volume exists on */
943 memset(&server, 0, sizeof(server));
944 server.sin_addr.s_addr = vldbEntry.serverNumber[e];
946 server.sin_family = AF_INET;
947 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
948 server.sin_len = sizeof(struct sockaddr_in);
950 curDump->hostAddr = HOSTADDR(&server);
951 curDump->partition = vldbEntry.serverPartition[e];
953 /* Determine date from which to do an incremental dump
955 if (nodePtr->parent) {
957 bcdb_FindClone(nodePtr->parent, curDump->name,
962 curDump->date = 0; /* do a full dump */
966 if (checkAbortByTaskId(taskId))
967 ERROR_EXIT(TC_ABORTEDBYREQUEST);
969 /* Establish connection to volume - UV_ routine expects
970 * host address in network order
973 dvcode = xbsaDumpVolume(curDump, dparamsPtr);
975 dvcode = dumpVolume(curDump, dparamsPtr);
977 action = dparamsPtr->curVolumeStatus;
979 /* Flush volume and tape entries to the database */
980 tcode = flushSavedEntries(action);
986 TapeLog(1, taskId, 0, 0, "Volume %s (%u) successfully dumped\n",
987 curDump->name, curDump->vid);
989 ErrorLog(1, taskId, dvcode, 0,
990 "Warning: Termination processing error on volume %s (%u)\n",
991 curDump->name, curDump->vid);
993 curDump->hostAddr = 0;
994 dparamsPtr->volumesDumped++;
999 if (action == DUMP_PARTIAL) {
1000 ErrorLog(1, taskId, dvcode, 0,
1001 "Volume %s (%u) failed - partially dumped\n",
1002 curDump->name, curDump->vid);
1003 } else if (dvcode) {
1004 ErrorLog(0, taskId, dvcode, 0, "Volume %s (%u) failed\n",
1005 curDump->name, curDump->vid);
1007 ErrorLog(0, taskId, dvcode, 0,
1008 "Volume %s (%u) not dumped - has not been re-cloned since last dump\n",
1009 curDump->name, curDump->vid);
1012 if (passNumber == maxpass) {
1016 ch = retryPrompt(curDump->name, curDump->vid, taskId);
1019 case 'r': /* retry */
1020 dparamsPtr->curVolume--; /* redump this volume */
1023 case 'o': /* omit */
1024 ErrorLog(1, taskId, 0, 0, "Volume %s (%u) omitted\n",
1025 curDump->name, curDump->vid);
1026 dparamsPtr->volumesFailed++;
1028 case 'a': /* abort */
1029 TapeLog(1, taskId, 0, 0, "Dump aborted\n");
1030 ERROR_EXIT(TC_ABORTEDBYREQUEST);
1033 ERROR_EXIT(TC_INTERNALERROR);
1040 TapeLog(1, taskId, dvcode, 0,
1041 "Volume %s (%u) hit end-of-tape inferred - will retry on next tape\n",
1042 curDump->name, curDump->vid);
1044 /* Get the next tape */
1045 unmountTape(taskId, tapeInfoPtr);
1047 dparamsPtr->tapeSeq++;
1048 tcode = getDumpTape(dparamsPtr, 1, 0); /* interactive - no appends */
1052 dparamsPtr->curVolume--; /* redump this volume */
1056 case DUMP_NORETRYEOT:
1057 ErrorLog(1, taskId, 0, 0,
1058 "Volume %s (%u) failed - volume larger than tape\n",
1059 curDump->name, curDump->vid);
1061 /* rewrite the label on the tape - rewind - no need to switch tapes */
1062 tcode = butm_Create(tapeInfoPtr, &dparamsPtr->tapeLabel, 1);
1064 ErrorLog(0, taskId, tcode, tapeInfoPtr->error,
1065 "Can't relabel tape\n");
1067 unmountTape(taskId, tapeInfoPtr);
1068 tcode = getDumpTape(dparamsPtr, 1, 0); /* interactive - no appends */
1071 } else { /* Record the tape in database */
1072 tapepos = tapeInfoPtr->position;
1074 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1075 dparamsPtr->tapeName,
1076 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1077 dparamsPtr->tapeLabel.useCount,
1078 dparamsPtr->tapeLabel.creationTime,
1079 dparamsPtr->tapeLabel.expirationDate, tapepos);
1082 curDump->hostAddr = 0;
1083 dparamsPtr->volumesFailed++;
1087 TapeLog(1, taskId, dvcode, 0,
1088 "Volume %s (%u) not dumped - has not been modified since last dump\n",
1089 curDump->name, curDump->vid);
1091 curDump->hostAddr = 0;
1092 dparamsPtr->volumesNotDumped++;
1096 ErrorLog(1, taskId, dvcode, 0, "Volume %s (%u) failed\n",
1097 curDump->name, curDump->vid);
1104 /* check if we terminated while processing a volume */
1105 if (dparamsPtr->curVolume < nodePtr->arraySize) {
1106 TapeLog(2, taskId, 0, 0,
1107 "Terminated while processing Volume %s (%u)\n", curDump->name,
1111 /* print a summary of this pass */
1112 TapeLog(2, taskId, 0, 0, "End of pass %d: Volumes remaining = %d\n",
1114 nodePtr->arraySize - (dparamsPtr->volumesDumped +
1115 dparamsPtr->volumesFailed +
1116 dparamsPtr->volumesNotDumped));
1121 Dumper(struct dumpNode *nodePtr)
1123 struct dumpRock dparams;
1124 struct butm_tapeInfo tapeInfo;
1130 /* for volume setup */
1132 int failedvolumes = 0;
1133 int dumpedvolumes = 0;
1134 int nodumpvolumes = 0;
1137 char finishedMsg1[50];
1138 char finishedMsg2[50];
1139 time_t startTime = 0;
1141 afs_int32 allocbufferSize;
1143 extern struct deviceSyncNode *deviceLatch;
1144 extern struct tapeConfig globalTapeConfig;
1145 extern afs_int32 createDump();
1147 taskId = nodePtr->taskID; /* Get task Id */
1148 setStatus(taskId, DRIVE_WAIT);
1149 EnterDeviceQueue(deviceLatch);
1150 clearStatus(taskId, DRIVE_WAIT);
1153 TapeLog(2, taskId, 0, 0, "Dump %s\n", nodePtr->dumpSetName);
1155 /* setup the dump parameters */
1156 memset(&dparams, 0, sizeof(dparams));
1157 dparams.node = nodePtr;
1158 dparams.tapeInfoPtr = &tapeInfo;
1159 dlqInit(&savedEntries);
1162 /* Instantiate the tape module */
1163 tapeInfo.structVersion = BUTM_MAJORVERSION;
1164 code = butm_file_Instantiate(&tapeInfo, &globalTapeConfig);
1166 ErrorLog(0, taskId, code, tapeInfo.error,
1167 "Can't initialize the tape module\n");
1172 /* check if abort requested while waiting on device latch */
1173 if (checkAbortByTaskId(taskId))
1174 ERROR_EXIT(TC_ABORTEDBYREQUEST);
1176 /* Are there volumes to dump */
1177 if (nodePtr->arraySize == 0) {
1178 TLog(taskId, "Dump (%s), no volumes to dump\n", nodePtr->dumpSetName);
1182 /* Allocate a buffer for the dumps. Leave room for header and vol-trailer.
1183 * dataSize is amount of data to read in each rx_Read() call.
1186 /* XBSA dumps have not header */
1187 dataSize = BufferSize;
1188 allocbufferSize = dataSize + sizeof(struct volumeHeader);
1190 tapeblocks = BufferSize / BUTM_BLOCKSIZE; /* # of 16K tapeblocks */
1191 dataSize = (tapeblocks * BUTM_BLKSIZE);
1193 BUTM_HDRSIZE + dataSize + sizeof(struct volumeHeader);
1196 bufferBlock = malloc(allocbufferSize);
1198 ErrorLog(0, taskId, TC_NOMEMORY, 0,
1199 "Can't allocate BUFFERSIZE for dumps\n");
1200 ERROR_EXIT(TC_NOMEMORY);
1203 /* Determine the dumpid of the most recent dump of this volumeset and dumplevel
1204 * Used when requesting a tape. Done now because once we create the dump, the
1205 * routine will then find the newly created dump.
1207 sprintf(strlevel, "%d", nodePtr->level);
1209 bcdb_FindLatestDump(nodePtr->volumeSetName, strlevel,
1212 if (code != BUDB_NODUMPNAME) {
1213 ErrorLog(0, taskId, code, 0, "Can't read backup database\n");
1216 memset(&dparams.lastDump, 0, sizeof(dparams.lastDump));
1219 code = createDump(&dparams); /* enter dump into database */
1221 ErrorLog(0, taskId, code, 0, "Can't create dump in database\n");
1225 TLog(taskId, "Dump %s (DumpID %u)\n", nodePtr->dumpSetName,
1226 dparams.databaseDumpId);
1229 /* mount the tape and write its label */
1230 code = getDumpTape(&dparams, autoQuery, nodePtr->doAppend);
1232 /* Create a dummy tape to satisfy backup databae */
1233 code = getXBSATape(&dparams);
1234 tapeInfo.position = 1;
1237 /* If didn't write the label, remove dump from the database */
1238 if (!dparams.wroteLabel) {
1239 i = bcdb_deleteDump(dparams.databaseDumpId, 0, 0, 0);
1240 if (i && (i != BUDB_NOENT))
1241 ErrorLog(1, taskId, i, 0,
1242 "Warning: Can't delete dump %u from database\n",
1243 dparams.databaseDumpId);
1245 dparams.databaseDumpId = 0;
1247 ERROR_EXIT(code); /* exit with code from getTape */
1250 startTime = time(0);
1251 for (pass = 1; pass <= maxpass; pass++) {
1252 lastPass = (pass == maxpass);
1253 code = dumpPass(&dparams, pass);
1257 /* if no failed volumes, we're done */
1258 if ((dparams.volumesDumped + dparams.volumesFailed +
1259 dparams.volumesNotDumped) == nodePtr->arraySize)
1264 * Log the error but ignore it since the dump is effectively done.
1265 * Scantape may assume another volume and ask for next tape.
1268 code = butm_WriteEOT(&tapeInfo);
1270 TapeLog(taskId, code, tapeInfo.error,
1271 "Warning: Can't write end-of-dump on tape\n");
1275 finishTape(&dparams.tape,
1276 dparams.tapeInfoPtr->kBytes +
1277 (dparams.tapeInfoPtr->nBytes ? 1 : 0));
1281 code = finishDump(&dparams.dump);
1285 action = dparams.curVolumeStatus;
1286 code = flushSavedEntries(action);
1297 unmountTape(taskId, &tapeInfo);
1301 dumpedvolumes = dparams.volumesDumped;
1302 nodumpvolumes = dparams.volumesNotDumped;
1303 failedvolumes = nodePtr->arraySize - (dumpedvolumes + nodumpvolumes);
1305 /* pass back the number of volumes we failed to dump */
1307 nodePtr->statusNodePtr->volsFailed = failedvolumes;
1310 lastPass = 1; /* In case we aborted */
1312 DUMPNAME(finishedMsg1, nodePtr->dumpSetName, dparams.databaseDumpId);
1313 sprintf(finishedMsg2, "%d volumes dumped", dumpedvolumes);
1314 if (failedvolumes) {
1315 sprintf(msg, ", %d failed", failedvolumes);
1316 strcat(finishedMsg2, msg);
1318 if (nodumpvolumes) {
1319 sprintf(msg, ", %d unchanged", nodumpvolumes);
1320 strcat(finishedMsg2, msg);
1323 if (code == TC_ABORTEDBYREQUEST) {
1324 ErrorLog(0, taskId, 0, 0, "%s: Aborted by request. %s\n",
1325 finishedMsg1, finishedMsg2);
1326 clearStatus(taskId, ABORT_REQUEST);
1327 setStatus(taskId, ABORT_DONE);
1329 ErrorLog(0, taskId, code, 0, "%s: Finished with errors. %s\n",
1330 finishedMsg1, finishedMsg2);
1331 setStatus(taskId, TASK_ERROR);
1333 TLog(taskId, "%s: Finished. %s\n", finishedMsg1, finishedMsg2);
1337 /* Record how long the dump took */
1338 if (centralLogIO && startTime) {
1340 afs_int32 hrs, min, sec, tmp;
1342 struct tm tmstart, tmend;
1344 localtime_r(&startTime, &tmstart);
1345 localtime_r(&endTime, &tmend);
1346 timediff = (int)endTime - (int)startTime;
1347 hrs = timediff / 3600;
1348 tmp = timediff % 3600;
1353 "%-5d %02d/%02d/%04d %02d:%02d:%02d "
1354 "%02d/%02d/%04d %02d:%02d:%02d " "%02d:%02d:%02d "
1355 "%s %d of %d volumes dumped (%ld KB)\n", taskId,
1356 tmstart.tm_mon + 1, tmstart.tm_mday, tmstart.tm_year + 1900,
1357 tmstart.tm_hour, tmstart.tm_min, tmstart.tm_sec,
1358 tmend.tm_mon + 1, tmend.tm_mday, tmend.tm_year + 1900,
1359 tmend.tm_hour, tmend.tm_min, tmend.tm_sec, hrs, min, sec,
1360 nodePtr->volumeSetName, dumpedvolumes,
1361 dumpedvolumes + failedvolumes,
1362 dparams.tapeInfoPtr->kBytes + 1);
1364 fwrite(line, strlen(line), 1, centralLogIO);
1365 fflush(centralLogIO);
1368 setStatus(taskId, TASK_DONE);
1370 FreeNode(taskId); /* free the dump node */
1371 LeaveDeviceQueue(deviceLatch);
1375 #define BELLTIME 60 /* 60 seconds before a bell rings */
1376 #define BELLCHAR 7 /* ascii for bell */
1379 * prompt the user to decide how to handle a failed volume dump. The
1380 * volume parameters describe the volume that failed
1382 * volumeName - name of volume
1383 * volumeId - volume id
1384 * taskId - for job contrl
1386 * character typed by user, one of r, o or a
1390 retryPrompt(char *volumeName, afs_int32 volumeId, afs_uint32 taskId)
1396 setStatus(taskId, OPR_WAIT);
1397 printf("\nDump of volume %s (%u) failed\n\n", volumeName, volumeId);
1399 printf("Please select action to be taken for this volume\n");
1402 printf("r - retry, try dumping this volume again\n");
1403 printf("o - omit, this volume from this dump\n");
1404 printf("a - abort, the entire dump\n");
1413 #ifdef AFS_PTHREAD_ENV
1414 code = GetResponseKey(5, &ch); /* ch stores key pressed */
1416 code = LWP_GetResponseKey(5, &ch); /* ch stores key pressed */
1419 break; /* input is available */
1421 if (checkAbortByTaskId(taskId)) {
1422 clearStatus(taskId, OPR_WAIT);
1424 ("This tape operation has been aborted by the coordinator\n");
1428 if (time(0) > start + BELLTIME)
1431 /* otherwise, we should beep again, check for abort and go back,
1432 * since the GetResponseKey() timed out.
1435 break; /* input is available */
1437 clearStatus(taskId, OPR_WAIT);
1438 if (ch != 'r' && ch != 'o' && ch != 'a') {
1439 printf("Please select one of the 3 options, r, o or a\n");
1446 /* For testing: it prints the tape label */
1448 printTapeLabel(struct butm_tapeLabel *tl)
1450 printf("Tape Label\n");
1451 printf(" structVersion = %d\n", tl->structVersion);
1452 printf(" creationTime = %u\n", tl->creationTime);
1453 printf(" expirationDate = %u\n", tl->expirationDate);
1454 printf(" AFSName = %s\n", tl->AFSName);
1455 printf(" cell = %s\n", tl->cell);
1456 printf(" dumpid = %d\n", tl->dumpid);
1457 printf(" useCount = %d\n", tl->useCount);
1458 printf(" comment = %s\n", tl->comment);
1459 printf(" pName = %s\n", tl->pName);
1460 printf(" size = %u\n", tl->size);
1461 printf(" dumpPath = %s\n", tl->dumpPath);
1466 * Create a tape structure to be satisfy the backup database
1467 * even though we don't really use a tape with XBSA.
1470 getXBSATape(struct dumpRock *dparamsPtr)
1472 struct dumpNode *nodePtr = dparamsPtr->node;
1473 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
1474 struct butm_tapeLabel *tapeLabelPtr = &dparamsPtr->tapeLabel;
1477 tc_MakeTapeName(dparamsPtr->tapeName, &nodePtr->tapeSetDesc,
1478 dparamsPtr->tapeSeq);
1480 GetNewLabel(tapeInfoPtr, "" /*pName */ , dparamsPtr->tapeName,
1482 strcpy(tapeLabelPtr->dumpPath, nodePtr->dumpName);
1483 tapeLabelPtr->dumpid = dparamsPtr->databaseDumpId;
1484 tapeLabelPtr->expirationDate =
1485 calcExpirationDate(nodePtr->tapeSetDesc.expType,
1486 nodePtr->tapeSetDesc.expDate, time(0));
1488 /* printTapeLabel(tapeLabelPtr); For testing */
1491 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1492 dparamsPtr->tapeName,
1493 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1494 tapeLabelPtr->useCount, tapeLabelPtr->creationTime,
1495 tapeLabelPtr->expirationDate, 0 /*tape position */ );
1500 * iterate until the desired tape (as specified by the dump structures)
1504 * 0 - assume the tape is there. Prompt if assumption false
1505 * 1 - prompt regardless
1509 getDumpTape(struct dumpRock *dparamsPtr, int interactiveFlag,
1512 struct dumpNode *nodePtr = dparamsPtr->node;
1513 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
1514 struct butm_tapeLabel *newTapeLabelPtr = &dparamsPtr->tapeLabel;
1515 char AFSTapeName[TC_MAXTAPENAMELEN];
1516 afs_int32 taskId = nodePtr->taskID;
1517 struct butm_tapeLabel oldTapeLabel;
1518 struct budb_dumpEntry dumpEntry;
1519 struct budb_tapeEntry tapeEntry;
1520 struct budb_volumeEntry volEntry;
1527 afs_int32 tapepos, lastpos;
1529 extern struct tapeConfig globalTapeConfig;
1530 extern struct udbHandleS udbHandle;
1532 askForTape = interactiveFlag;
1533 dparamsPtr->wroteLabel = 0;
1535 /* Keep prompting for a tape until we get it right */
1537 /* What the name of the tape would be if not appending to it */
1538 tc_MakeTapeName(AFSTapeName, &nodePtr->tapeSetDesc,
1539 dparamsPtr->tapeSeq);
1545 PromptForTape((doAppend ? APPENDOPCODE : WRITEOPCODE),
1546 AFSTapeName, dparamsPtr->databaseDumpId, taskId,
1554 /* open the tape device */
1555 code = butm_Mount(tapeInfoPtr, AFSTapeName);
1557 TapeLog(0, taskId, code, tapeInfoPtr->error, "Can't open tape\n");
1561 /* Read the tape label */
1562 code = butm_ReadLabel(tapeInfoPtr, &oldTapeLabel, 1); /* rewind */
1564 if (tapeInfoPtr->error) {
1565 ErrorLog(0, taskId, code, tapeInfoPtr->error,
1566 "Warning: Tape error while reading label (will proceed with dump)\n");
1568 memset(&oldTapeLabel, 0, sizeof(oldTapeLabel));
1571 /* Check if null tape. Prior 3.3, backup tapes have no dump id */
1572 if ((strcmp(oldTapeLabel.AFSName, "") == 0)
1573 && (oldTapeLabel.dumpid == 0)) {
1576 "Dump not found on tape. Proceeding with initial dump\n");
1579 } else if (doAppend) { /* appending */
1580 /* Check that we don't have a database dump tape */
1581 if (databaseTape(oldTapeLabel.AFSName)) {
1582 char gotName[BU_MAXTAPELEN + 32];
1584 /* label does not match */
1585 LABELNAME(gotName, &oldTapeLabel);
1586 TLog(taskId, "Can't append to database tape %s\n", gotName);
1590 /* Verify that the tape is of version 4 (AFS 3.3) or greater */
1591 if (oldTapeLabel.structVersion < TAPE_VERSION_4) {
1593 "Can't append: requires tape version %d or greater\n",
1598 /* Verify that the last tape of the dump set is in the drive.
1599 * volEntry will be zeroed if last dump has no volume entries.
1602 bcdb_FindLastTape(oldTapeLabel.dumpid, &dumpEntry, &tapeEntry,
1605 ErrorLog(0, taskId, code, 0,
1606 "Can't append: Can't find last volume of dumpId %u in database\n",
1607 oldTapeLabel.dumpid);
1608 printf("Please scan the dump in or choose another tape\n");
1612 (volEntry.position ? volEntry.position : tapeEntry.labelpos);
1614 if (strcmp(TNAME(&oldTapeLabel), tapeEntry.name)) {
1615 char expName[BU_MAXTAPELEN + 32], gotName[BU_MAXTAPELEN + 32];
1617 TAPENAME(expName, tapeEntry.name, oldTapeLabel.dumpid);
1618 LABELNAME(gotName, &oldTapeLabel);
1621 "Can't append: Last tape in dump-set is %s, label seen %s\n",
1626 /* After reading the tape label, we now know what it is */
1627 strcpy(AFSTapeName, oldTapeLabel.AFSName); /* the real name */
1628 strcpy(tapeInfoPtr->name, oldTapeLabel.AFSName); /* the real name */
1630 /* Position after last volume on the tape */
1631 code = butm_SeekEODump(tapeInfoPtr, lastpos);
1633 ErrorLog(0, taskId, code, tapeInfoPtr->error,
1634 "Can't append: Can't position to end of dump on tape %s\n",
1639 /* Track size of tape - set after seek since seek changes the value */
1640 tapeInfoPtr->kBytes = tapeEntry.useKBytes;
1641 } else { /* not appending */
1645 struct budb_dumpEntry de, de2;
1647 /* Check if tape name is not what expected - null tapes are acceptable
1648 * Don't do check if the tape has a user defined label.
1650 if (dump_namecheck && (strcmp(oldTapeLabel.pName, "") == 0)) {
1651 if (strcmp(oldTapeLabel.AFSName, "") && /* not null tape */
1652 strcmp(oldTapeLabel.AFSName, AFSTapeName)) { /* not expected name */
1653 TLog(taskId, "Tape label expected %s, label seen %s\n",
1654 AFSTapeName, oldTapeLabel.AFSName);
1658 /* Check that we don't have a database dump tape */
1659 if (databaseTape(oldTapeLabel.AFSName)) {
1660 /* label does not match */
1662 "Tape label expected %s, can't dump to database tape %s\n",
1663 AFSTapeName, oldTapeLabel.AFSName);
1668 /* Verify the tape has not expired - only check if not appending */
1669 if (!tapeExpired(&oldTapeLabel)) {
1670 TLog(taskId, "This tape has not expired\n");
1674 /* Given a tape dump with good data, verify we don't overwrite recent dumps
1675 * and also verify that the volume will be restorable - if not print warnings
1677 if (oldTapeLabel.dumpid) {
1678 /* Do not overwrite a tape that belongs to the dump's dumpset */
1680 (dparamsPtr->initialDumpId ? dparamsPtr->
1681 initialDumpId : dparamsPtr->databaseDumpId);
1682 if (oldTapeLabel.dumpid == tapeid) {
1683 ErrorLog(0, taskId, 0, 0,
1684 "Can't overwrite tape containing the dump in progress\n");
1688 /* Since the dumpset on this tape will be deleted from database, check if
1689 * any of the dump's parent-dumps are on this tape.
1691 for (dmp = nodePtr->parent; dmp; dmp = de.parent) {
1692 code = bcdb_FindDumpByID(dmp, &de);
1694 ErrorLog(0, taskId, 0, 0,
1695 "Warning: Can't find parent dump %u in backup database\n",
1700 tapeid = (de.initialDumpID ? de.initialDumpID : de.id);
1701 if (oldTapeLabel.dumpid == tapeid) {
1702 ErrorLog(0, taskId, 0, 0,
1703 "Can't overwrite the parent dump %s (DumpID %u)\n",
1709 /* Since the dumpset on this tape will be deleted from database, check if
1710 * any of the dumps in this dumpset are most-recent-dumps.
1712 for (dmp = oldTapeLabel.dumpid; dmp; dmp = de.appendedDumpID) {
1713 if (dmp == dparamsPtr->lastDump.id) {
1714 memcpy(&de, &dparamsPtr->lastDump, sizeof(de));
1715 memcpy(&de2, &dparamsPtr->lastDump, sizeof(de2));
1717 code = bcdb_FindDumpByID(dmp, &de);
1720 sprintf(strlevel, "%d", de.level);
1722 bcdb_FindLatestDump(de.volumeSetName, strlevel,
1728 /* If dump on the tape is the latest dump at this level */
1729 if (de.id == de2.id) {
1730 if (strcmp(DUMP_TAPE_NAME, de2.name) == 0) {
1731 ErrorLog(0, taskId, 0, 0,
1732 "Warning: Overwriting most recent dump %s (DumpID %u)\n",
1735 ErrorLog(0, taskId, 0, 0,
1736 "Warning: Overwriting most recent dump of the '%s' volumeset: %s (DumpID %u)\n",
1737 de.volumeSetName, de.name, de.id);
1741 } /* if (oldTapeLabel.dumpid) */
1742 } /* else not appending */
1745 * Now have the right tape. Create a new label for the tape
1746 * Appended labels have the dump's dumpId - labels at beginnings of
1747 * tape have the initial dump's dumpId.
1748 * Appended labels do not increment the useCount.
1749 * Labels at beginnings of tape use the most future expiration of the dump set.
1751 GetNewLabel(tapeInfoPtr, oldTapeLabel.pName, AFSTapeName,
1753 strcpy(newTapeLabelPtr->dumpPath, nodePtr->dumpName);
1754 newTapeLabelPtr->expirationDate =
1755 calcExpirationDate(nodePtr->tapeSetDesc.expType,
1756 nodePtr->tapeSetDesc.expDate, time(0));
1757 newTapeLabelPtr->dumpid = dparamsPtr->databaseDumpId;
1758 newTapeLabelPtr->useCount = oldTapeLabel.useCount;
1761 newTapeLabelPtr->useCount++;
1762 if (dparamsPtr->initialDumpId) {
1763 newTapeLabelPtr->dumpid = dparamsPtr->initialDumpId;
1764 expir = ExpirationDate(dparamsPtr->initialDumpId);
1765 if (expir > newTapeLabelPtr->expirationDate)
1766 newTapeLabelPtr->expirationDate = expir;
1770 /* write the label on the tape - rewind if not appending and vice-versa */
1771 code = butm_Create(tapeInfoPtr, newTapeLabelPtr, !doAppend);
1773 char gotName[BU_MAXTAPELEN + 32];
1775 LABELNAME(gotName, newTapeLabelPtr);
1776 TapeLog(0, taskId, code, tapeInfoPtr->error,
1777 "Can't label tape as %s\n", gotName);
1780 dparamsPtr->wroteLabel = 1; /* Remember we wrote the label */
1781 tapepos = tapeInfoPtr->position - 1;
1783 strcpy(dparamsPtr->tapeName, TNAME(newTapeLabelPtr));
1785 /* If appending, set dumpentry in the database as appended. */
1787 char gotName[BU_MAXTAPELEN + 32];
1789 nodePtr->tapeSetDesc.b = extractTapeSeq(AFSTapeName);
1790 dparamsPtr->dump.tapes.b = nodePtr->tapeSetDesc.b;
1791 dparamsPtr->initialDumpId = oldTapeLabel.dumpid;
1792 strcpy(nodePtr->tapeSetDesc.format, dumpEntry.tapes.format);
1795 bcdb_MakeDumpAppended(dparamsPtr->databaseDumpId,
1796 dparamsPtr->initialDumpId,
1797 nodePtr->tapeSetDesc.b);
1799 ErrorLog(2, taskId, code, 0,
1800 "Warning: Can't append dump %u to dump %u in database\n",
1801 dparamsPtr->databaseDumpId,
1802 dparamsPtr->initialDumpId);
1804 LABELNAME(gotName, &oldTapeLabel);
1805 TLog(taskId, "Appending dump %s (DumpID %u) to tape %s\n",
1806 nodePtr->dumpSetName, dparamsPtr->databaseDumpId, gotName);
1809 /* If not appending, delete overwritten dump from the database */
1811 if ((oldTapeLabel.structVersion >= TAPE_VERSION_3)
1812 && oldTapeLabel.dumpid) {
1813 code = bcdb_deleteDump(oldTapeLabel.dumpid, 0, 0, 0);
1814 if (code && (code != BUDB_NOENT))
1815 ErrorLog(0, taskId, code, 0,
1816 "Warning: Can't delete old dump %u from database\n",
1817 oldTapeLabel.dumpid);
1822 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1823 dparamsPtr->tapeName,
1824 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1825 newTapeLabelPtr->useCount, newTapeLabelPtr->creationTime,
1826 newTapeLabelPtr->expirationDate, tapepos);
1829 * The margin of space to check for end of tape is set to the
1830 * amount of space used to write an end-of-tape multiplied by 2.
1831 * The amount of space is size of a 16K volume trailer, a 16K File
1832 * End mark, its EOF marker, a 16K EODump marker, its EOF marker,
1833 * and up to two EOF markers done on close (3 16K blocks + 4 EOF
1836 tc_EndMargin = (3 * 16384 + 4 * globalTapeConfig.fileMarkSize) * 2;
1837 tc_KEndMargin = tc_EndMargin / 1024;
1841 unmountTape(taskId, tapeInfoPtr);
1849 makeVolumeHeader(struct volumeHeader *vhptr, struct dumpRock *dparamsPtr,
1852 struct dumpNode *nodePtr = dparamsPtr->node;
1853 struct tc_dumpDesc *curDump;
1856 curDump = &nodePtr->dumps[dparamsPtr->curVolume];
1858 memset(vhptr, 0, sizeof(*vhptr));
1859 strcpy(vhptr->volumeName, curDump->name);
1860 vhptr->volumeID = curDump->vid;
1861 vhptr->cloneDate = curDump->cloneDate;
1862 vhptr->server = curDump->hostAddr;
1863 vhptr->part = curDump->partition;
1864 vhptr->from = curDump->date;
1865 vhptr->frag = fragmentNumber;
1867 vhptr->magic = TC_VOLBEGINMAGIC;
1868 vhptr->dumpID = dparamsPtr->databaseDumpId; /* real dump id */
1869 vhptr->level = nodePtr->level;
1870 vhptr->parentID = nodePtr->parent;
1872 vhptr->versionflags = CUR_TAPE_VERSION;
1873 strcpy(vhptr->dumpSetName, nodePtr->dumpSetName);
1874 strcpy(vhptr->preamble, "H++NAME#");
1875 strcpy(vhptr->postamble, "T--NAME#");
1881 volumeHeader_hton(struct volumeHeader *hostPtr, struct volumeHeader *netPtr)
1883 struct volumeHeader volHdr;
1885 strcpy(volHdr.preamble, hostPtr->preamble);
1886 strcpy(volHdr.postamble, hostPtr->postamble);
1887 strcpy(volHdr.volumeName, hostPtr->volumeName);
1888 strcpy(volHdr.dumpSetName, hostPtr->dumpSetName);
1889 volHdr.volumeID = htonl(hostPtr->volumeID);
1890 volHdr.server = htonl(hostPtr->server);
1891 volHdr.part = htonl(hostPtr->part);
1892 volHdr.from = htonl(hostPtr->from);
1893 volHdr.frag = htonl(hostPtr->frag);
1894 volHdr.magic = htonl(hostPtr->magic);
1895 volHdr.contd = htonl(hostPtr->contd);
1896 volHdr.dumpID = htonl(hostPtr->dumpID);
1897 volHdr.level = htonl(hostPtr->level);
1898 volHdr.parentID = htonl(hostPtr->parentID);
1899 volHdr.endTime = htonl(hostPtr->endTime);
1900 volHdr.versionflags = htonl(hostPtr->versionflags);
1901 volHdr.cloneDate = htonl(hostPtr->cloneDate);
1903 memcpy(netPtr, &volHdr, sizeof(struct volumeHeader));
1907 /* database related routines */
1910 createDump(struct dumpRock *dparamsPtr)
1912 struct dumpNode *nodePtr = dparamsPtr->node;
1913 struct budb_dumpEntry *dumpPtr;
1916 dumpPtr = &dparamsPtr->dump;
1917 memset(dumpPtr, 0, sizeof(*dumpPtr));
1919 /* id filled in by database */
1920 dumpPtr->parent = nodePtr->parent;
1921 dumpPtr->level = nodePtr->level;
1925 if (xbsaType == XBSA_SERVER_TYPE_ADSM) {
1926 strcpy(dumpPtr->tapes.tapeServer, butxInfo.serverName);
1927 dumpPtr->flags = BUDB_DUMP_ADSM;
1929 if (!(butxInfo.serverType & XBSA_SERVER_FLAG_MULTIPLE)) {
1930 /* The current server (API) doesn't provide the function required
1931 * to specify a server at startup time. For that reason, we can't
1932 * be sure that the server name supplied by the user in the user-
1933 * defined configuration file is correct. We set a flag here so
1934 * we know at restore time that the servername info in the backup
1935 * database may be incorrect. We will not allow a server switch
1936 * at that time, even if the server at restore time supports
1939 dumpPtr->flags |= BUDB_DUMP_XBSA_NSS;
1943 strcpy(dumpPtr->volumeSetName, nodePtr->volumeSetName);
1944 strcpy(dumpPtr->dumpPath, nodePtr->dumpName);
1945 strcpy(dumpPtr->name, nodePtr->dumpSetName);
1946 dumpPtr->created = 0; /* let database assign it */
1947 dumpPtr->incTime = 0; /* not really used */
1948 dumpPtr->nVolumes = 0;
1949 dumpPtr->initialDumpID = 0;
1951 dumpPtr->tapes.id = groupId;
1952 dumpPtr->tapes.b = 1;
1953 dumpPtr->tapes.maxTapes = 0;
1954 strcpy(dumpPtr->tapes.format, nodePtr->tapeSetDesc.format);
1956 /* principal filled in by database */
1958 /* now call the database to create the entry */
1959 code = bcdb_CreateDump(dumpPtr);
1961 dparamsPtr->databaseDumpId = dumpPtr->id;
1968 * Initialize to a specific server. The first time, we remember the
1969 * server as the original server and go back to it each time we pass 0
1973 InitToServer(afs_int32 taskId, struct butx_transactionInfo * butxInfoP,
1976 static char origserver[BSA_MAX_DESC];
1977 static int init = 0;
1978 afs_int32 rc, code = 0;
1981 strcpy(origserver, "");
1986 server = origserver; /* return to original server */
1987 if (strcmp(server, "") == 0)
1988 return 0; /* No server, do nothing */
1989 if (strcmp(butxInfoP->serverName, server) == 0)
1990 return 0; /* same server, do nothing */
1991 if (strcmp(origserver, "") == 0)
1992 strcpy(origserver, server); /* remember original server */
1994 if (strcmp(butxInfoP->serverName, "") != 0) {
1995 /* If already connected to a server, disconnect from it.
1996 * Check to see if our server does not support switching.
1998 if (!(butxInfo.serverType & XBSA_SERVER_FLAG_MULTIPLE)) {
1999 ErrorLog(0, taskId, TC_BADTASK, 0,
2000 "This version of XBSA libraries does not support switching "
2001 "from server %s to server %s\n", butxInfoP->serverName,
2003 return (TC_BADTASK);
2006 rc = xbsa_Finalize(&butxInfo);
2007 if (rc != XBSA_SUCCESS) {
2008 ErrorLog(0, taskId, rc, 0,
2009 "InitToServer: Unable to terminate the connection to server %s\n",
2010 butxInfoP->serverName);
2015 /* initialize to the new server */
2016 rc = xbsa_Initialize(&butxInfo, xbsaObjectOwner, appObjectOwner,
2017 xbsaSecToken, server);
2018 if (rc != XBSA_SUCCESS) {
2019 ErrorLog(0, taskId, rc, 0,
2020 "InitToServer: Unable to initialize the XBSA library to server %s\n",
2034 DeleteDump(struct deleteDumpIf *ptr)
2037 afs_int32 rc, code = 0;
2039 afs_int32 index, next, dbTime;
2041 struct budb_dumpEntry dumpEntry;
2042 char tapeName[BU_MAXTAPELEN];
2043 char dumpIdStr[XBSA_MAX_OSNAME];
2044 char volumeNameStr[XBSA_MAX_PATHNAME];
2047 int allnotfound = 1, onenotfound = 0;
2048 extern struct udbHandleS udbHandle;
2049 extern struct deviceSyncNode *deviceLatch;
2051 setStatus(taskId, DRIVE_WAIT);
2052 EnterDeviceQueue(deviceLatch);
2053 clearStatus(taskId, DRIVE_WAIT);
2055 dumpid = ptr->dumpID;
2056 taskId = ptr->taskId; /* Get task Id */
2059 TapeLog(2, taskId, 0, 0, "Delete Dump %u\n", dumpid);
2061 vl.budb_volumeList_len = 0;
2062 vl.budb_volumeList_val = 0;
2065 /* Get the dump info for the dump we are deleting */
2066 rc = bcdb_FindDumpByID(dumpid, &dumpEntry);
2068 ErrorLog(0, taskId, rc, 0,
2069 "Unable to locate dump ID %u in database\n", dumpid);
2070 setStatus(taskId, TASK_ERROR);
2074 /* we must make sure that we are configured with the correct type of
2075 * XBSA server for this dump delete! Only those dumped to an ADSM server.
2077 if ((xbsaType == XBSA_SERVER_TYPE_ADSM)
2078 && !((dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA)))) {
2079 ErrorLog(0, taskId, TC_BADTASK, 0,
2080 "The dump %u requested for deletion is incompatible with this instance of butc\n",
2082 setStatus(taskId, TASK_ERROR);
2083 ERROR_EXIT(TC_BADTASK);
2086 /* Make sure we are connected to the correct server. If not, switch to it if appropriate */
2087 if ((strlen((char *)dumpEntry.tapes.tapeServer) != 0)
2088 && (strcmp((char *)dumpEntry.tapes.tapeServer, butxInfo.serverName) !=
2091 /* Check to see if the tapeServer name is trustworthy */
2092 if ((dumpEntry.flags & (BUDB_DUMP_XBSA_NSS | BUDB_DUMP_BUTA))
2093 && !forcemultiple) {
2094 /* The dump was made with a version of the XBSA interface
2095 * that didn't allow switching of servers, we can't be sure
2096 * that the servername in the backup database is correct. So,
2097 * we will check the servername and log it if they don't match;
2098 * but we will try to do the delete without switching servers.
2101 "The dump %d requested for deletion is on server %s "
2102 "but butc is connected to server %s "
2103 "(Attempting to delete the dump anyway)\n", dumpid,
2104 (char *)dumpEntry.tapes.tapeServer, butxInfo.serverName);
2107 "The dump %u requested for deletion is on server %s "
2108 "but butc is connected to server %s "
2109 "(switching servers)\n", dumpid,
2110 (char *)dumpEntry.tapes.tapeServer, butxInfo.serverName);
2112 rc = InitToServer(taskId, &butxInfo,
2113 (char *)dumpEntry.tapes.tapeServer);
2114 if (rc != XBSA_SUCCESS) {
2115 setStatus(taskId, TASK_ERROR);
2121 /* Start a new Transaction */
2122 rc = xbsa_BeginTrans(&butxInfo);
2123 if (rc != XBSA_SUCCESS) {
2124 ErrorLog(0, taskId, rc, 0, "Unable to create a new transaction\n");
2125 setStatus(taskId, TASK_ERROR);
2130 /* Query the backup database for list of volumes to delete */
2131 for (index = next = 0; index != -1; index = next) {
2132 rc = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client,
2133 UF_SINGLESERVER, BUDB_MAJORVERSION,
2134 BUDB_OP_DUMPID, tapeName, dumpid, 0,
2135 index, &next, &dbTime, &vl);
2137 if (rc == BUDB_ENDOFLIST)
2139 ErrorLog(0, taskId, rc, 0, "Can't find volume info for dump %d\n",
2141 setStatus(taskId, TASK_ERROR);
2145 /* Delete all volumes on the list */
2146 for (i = 0; i < vl.budb_volumeList_len; i++) {
2147 if (dumpEntry.flags & BUDB_DUMP_BUTA) {
2148 /* dump was from buta, use old buta style names */
2149 sprintf(dumpIdStr, "/%d", dumpid);
2150 strcpy(volumeNameStr, "/");
2151 strcat(volumeNameStr, (char *)vl.budb_volumeList_val[i].name);
2152 } else { /* BUDB_DUMP_ADSM */
2153 /* dump was from butc to ADSM, use butc names */
2154 strcpy(dumpIdStr, butcdumpIdStr);
2155 sprintf(volumeNameStr, "/%d", dumpid);
2156 strcat(volumeNameStr, "/");
2157 strcat(volumeNameStr, (char *)vl.budb_volumeList_val[i].name);
2160 rc = xbsa_DeleteObject(&butxInfo, dumpIdStr, volumeNameStr);
2161 if (rc != XBSA_SUCCESS) {
2162 ErrorLog(0, taskId, rc, 0,
2163 "Unable to delete the object %s of dump %s from the server\n",
2164 volumeNameStr, dumpIdStr);
2165 /* Don't exit if volume was not found */
2166 if (rc != BUTX_DELETENOVOL) {
2174 "Deleted volume %s (%u) in dumpID %u from the backup server\n",
2175 vl.budb_volumeList_val[i].name,
2176 vl.budb_volumeList_val[i].id, dumpid);
2180 /* free the memory allocated by RPC for this list */
2181 if (vl.budb_volumeList_val)
2182 free(vl.budb_volumeList_val);
2183 vl.budb_volumeList_len = 0;
2184 vl.budb_volumeList_val = 0;
2189 rc = xbsa_EndTrans(&butxInfo);
2190 if (rc != XBSA_SUCCESS) {
2191 ErrorLog(0, taskId, rc, 0,
2192 "Unable to terminate the current transaction\n");
2193 setStatus(taskId, TASK_ERROR);
2198 /* Switch back to the original server */
2199 rc = InitToServer(taskId, &butxInfo, NULL);
2201 if (vl.budb_volumeList_val)
2202 free(vl.budb_volumeList_val);
2204 setStatus(taskId, TASK_DONE);
2205 FreeNode(taskId); /* free the dump node */
2206 LeaveDeviceQueue(deviceLatch);
2208 /* If we don't find any dumps on the server, rather than returning
2209 * a success, return a failure.
2211 if (!code && onenotfound && allnotfound) {
2212 code = BUTX_DELETENOVOL;
2213 setStatus(taskId, TASK_ERROR);