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>
32 #include <afs/tcdata.h>
33 #include <afs/bubasics.h>
34 #include <afs/budb_client.h>
35 #include <afs/vldbint.h>
36 #include <afs/ktime.h>
37 #include <afs/vlserver.h>
38 #include <afs/volser.h>
39 #include <afs/volint.h>
40 #include <afs/cellconfig.h>
42 #include "error_macros.h"
43 #include "butc_xbsa.h"
47 /* GLOBAL CONFIGURATION PARAMETERS */
48 extern int dump_namecheck;
49 extern int queryoperator;
51 extern int forcemultiple;
53 extern struct ubik_client *cstruct;
54 dlqlinkT savedEntries;
55 dlqlinkT entries_to_flush;
57 afs_int32 flushSavedEntries(), finishDump(), finishTape(), useTape(),
60 extern struct rx_connection *UV_Bind();
62 extern afs_int32 groupId;
63 extern afs_int32 BufferSize;
64 extern afs_int32 statusSize;
65 extern FILE *centralLogIO;
66 afs_int32 lastPass = 0;
68 extern afs_int32 xbsaType;
69 char *butcdumpIdStr = "/backup_afs_volume_dumps";
70 extern struct butx_transactionInfo butxInfo;
71 extern char *xbsaObjectOwner;
72 extern char *appObjectOwner;
73 extern char *xbsaSecToken;
74 extern char *xbsalGName;
75 extern char *globalButcLog;
78 afs_int32 dataSize; /* Size of data to read on each rx_Read() call */
79 afs_int32 tapeblocks; /* Number of 16K tape datablocks in buffer (!CONF_XBSA) */
83 * Done 1) dump id generation
84 * Done xx) volume fragment number accounting !! I think.
85 * 2) check abort - check after subroutine calls
86 * Done 3) trailer anomaly
87 * 4) trailer damage indicator after partial dumps ( affects scandump )
88 * Done 5) Ensure mount failure logged
89 * 6) Ensure bucoord status calls work
93 * keep token timeout. If no user reponse (idle time > some period)
94 * and tokens about to time out, terminate dump. This provides at
95 * least something usable.
98 #define DUMPNAME(dumpname, name, dbDumpId) \
100 sprintf(dumpname, "%s", name); \
102 sprintf(dumpname, "%s (DumpId %u)", name, dbDumpId);
104 #if defined(AFS_NT40_ENV) || (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN60_ENV)) || defined(AFS_SUN4_ENV)
106 localtime_r(time_t * t, struct tm *tm)
108 memcpy(tm, localtime(t), sizeof(struct tm));
116 int curVolume; /* index in dumpNode of volume */
117 int curVolumeStatus; /* more explicit dump state */
118 afs_uint32 curVolStartPos; /* Starting position of the current volume */
119 afs_uint32 databaseDumpId; /* real dump id, for db */
120 afs_uint32 initialDumpId; /* the initial dump, for appended dumps */
121 afs_int32 volumesDumped; /* # volumes successfully dumped */
122 afs_int32 volumesFailed; /* # volumes that failed to dump */
123 afs_int32 volumesNotDumped; /* # volumes that were not dumped (didn't fail) */
125 /* tape management */
126 char tapeName[TC_MAXTAPENAMELEN];
127 struct butm_tapeInfo *tapeInfoPtr;
128 struct butm_tapeLabel tapeLabel;
129 int wroteLabel; /* If the tape label is written */
131 /* database information */
132 struct budb_dumpEntry lastDump; /* the last dump of this volset */
133 struct budb_dumpEntry dump; /* current dump */
134 struct budb_tapeEntry tape; /* current tape, not used -VA */
136 /* links to existing info */
137 struct dumpNode *node;
140 /* configuration variables */
141 #define HITEOT(code) ((code == BUTM_IO) || (code == BUTM_EOT) || (code == BUTM_IOCTL))
142 extern int autoQuery;
145 afs_int32 tc_EndMargin;
146 afs_int32 tc_KEndMargin;
147 static char *bufferBlock;
149 /* compute the absolute expiration date */
151 calcExpirationDate(afs_int32 expType, afs_int32 expDate, afs_int32 createTime)
153 struct ktime_date kd;
154 afs_int32 Add_RelDate_to_Time();
158 /* expiration date is relative to the creation time of the dump.
159 * This is the only case that requires any work
161 Int32To_ktimeRelDate(expDate, &kd);
162 return (Add_RelDate_to_Time(&kd, createTime));
175 afs_int32 curr_bserver = 0;
176 struct rx_connection *curr_fromconn = (struct rx_connection *)0;
178 struct rx_connection *
179 Bind(afs_int32 server)
182 if (curr_bserver == server) /* Keep connection if have it */
183 return (curr_fromconn);
185 rx_DestroyConnection(curr_fromconn); /* Otherwise get rid of it */
186 curr_fromconn = (struct rx_connection *)0;
191 curr_fromconn = UV_Bind(server, AFSCONF_VOLUMEPORT); /* Establish new connection */
193 curr_bserver = server;
196 return (curr_fromconn);
200 * 1) save the chunksize or otherwise ensure tape space remaining is
201 * check frequently enough
202 * 2) This is called once. For partial dumps, need to
203 * ensure that the tape device is left in the correct state for
207 #define BIGCHUNK 102400
210 dumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
212 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
213 struct dumpNode *nodePtr = dparamsPtr->node;
214 afs_int32 taskId = nodePtr->taskID;
217 afs_int32 volumeFlags;
218 afs_int32 kRemaining;
219 afs_int32 rc, code = 0;
221 afs_uint32 volBytesRead;
222 afs_uint32 chunkSize;
223 afs_int32 bytesread; /* rx reads */
224 int endofvolume = 0; /* Have we read all volume data */
227 struct volumeHeader hostVolumeHeader;
229 struct rx_call *fromcall = (struct rx_call *)0;
230 struct rx_connection *fromconn;
231 afs_int32 updatedate, fromtid = 0;
232 volEntries volumeInfo;
233 afs_int32 bytesWritten;
234 afs_uint32 statuscount = statusSize, tsize = 0;
236 dparamsPtr->curVolumeStatus = DUMP_NOTHING;
238 fromconn = Bind(htonl(curDump->hostAddr)); /* get connection to the server */
240 /* Determine when the volume was last cloned and updated */
241 volumeInfo.volEntries_val = (volintInfo *) 0;
242 volumeInfo.volEntries_len = 0;
243 rc = AFSVolListOneVolume(fromconn, curDump->partition, curDump->vid,
247 updatedate = volumeInfo.volEntries_val[0].updateDate;
250 RWVOL) ? time(0) : volumeInfo.volEntries_val[0].creationDate);
252 if (curDump->date >= curDump->cloneDate)
253 ERROR_EXIT(0); /* not recloned since last dump */
254 if (curDump->date > updatedate) {
255 dparamsPtr->curVolumeStatus = DUMP_NODUMP; /* not modified since last dump */
259 /* Start the volserver transaction and dump */
260 rc = AFSVolTransCreate(fromconn, curDump->vid, curDump->partition, ITBusy,
264 fromcall = rx_NewCall(fromconn);
266 rc = StartAFSVolDump(fromcall, fromtid, curDump->date);
270 dparamsPtr->curVolumeStatus = DUMP_PARTIAL;
271 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
273 /* buffer is place in bufferBlock to write volume data.
274 * butm_writeFileData() assumes the previous BUTM_HDRSIZE bytes
275 * is available to write the tape block header.
277 buffer = bufferBlock + BUTM_HDRSIZE;
279 /* Dump one volume fragment at a time until we dump the full volume.
280 * A volume with more than 1 fragment means the volume will 'span'
283 for (fragmentNumber = 1; !endofvolume; fragmentNumber++) { /*frag */
284 rc = butm_WriteFileBegin(tapeInfoPtr);
286 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
287 "Can't write FileBegin on tape\n");
290 indump = 1; /* first write to tape */
292 /* Create and Write the volume header */
293 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, fragmentNumber);
294 hostVolumeHeader.contd = ((fragmentNumber == 1) ? 0 : TC_VOLCONTD);
295 volumeHeader_hton(&hostVolumeHeader, buffer);
297 rc = butm_WriteFileData(tapeInfoPtr, buffer, 1,
298 sizeof(hostVolumeHeader));
300 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
301 "Can't write VolumeHeader on tape\n");
305 bytesWritten = BUTM_BLOCKSIZE; /* Wrote one tapeblock */
306 tsize += bytesWritten;
308 /* Start reading volume data, rx_Read(), and dumping to the tape
309 * until we've dumped the entire volume (endofvolume == 1). We can
310 * exit this loop early if we find we are close to the end of the
311 * tape; in which case we dump the next fragment on the next tape.
316 while (!endofvolume && !fragmentvolume) { /*w */
319 /* Check for abort in the middle of writing data */
320 if (volBytesRead >= chunkSize) {
321 chunkSize += BIGCHUNK;
322 if (checkAbortByTaskId(taskId))
323 ABORT_EXIT(TC_ABORTEDBYREQUEST);
325 /* set bytes dumped for backup */
327 nodePtr->statusNodePtr->nKBytes = tapeInfoPtr->kBytes;
331 /* Determine how much data to read in upcoming RX_Read() call */
333 /* Check if we are close to the EOT. There should at least be some
334 * data on the tape before it is switched. HACK: we have to split a
335 * volume across tapes because the volume trailer says the dump
336 * continues on the next tape (and not the filemark). This could
337 * result in a volume starting on one tape (no volume data dumped) and
338 * continued on the next tape. It'll work, just requires restore to
339 * switch tapes. This allows many small volumes (<16K) to be dumped.
341 kRemaining = butm_remainingKSpace(tapeInfoPtr);
342 if ((kRemaining < tc_KEndMargin)
344 || (tapeInfoPtr->position > (isafile ? 3 : 2)))) {
349 /* Guess at how much data to read. So we don't write off end of tape */
350 if (kRemaining < (tapeblocks * 16)) {
351 if (kRemaining < 0) {
352 toread = BUTM_BLKSIZE;
354 toread = ((kRemaining / 16) + 1) * BUTM_BLKSIZE;
355 if (toread > dataSize)
360 /* Read some volume data. */
361 if (fragmentvolume) {
364 bytesread = rx_Read(fromcall, buffer, toread);
365 volBytesRead += bytesread;
366 if (bytesread != toread) {
367 /* Make sure were at end of volume and not a communication error */
368 rc = rx_Error(fromcall);
375 if (fragmentvolume || endofvolume) {
376 /* Create a volume trailer appending it to this data block */
377 makeVolumeHeader(&hostVolumeHeader, dparamsPtr,
379 hostVolumeHeader.contd = (endofvolume ? 0 : TC_VOLCONTD);
380 hostVolumeHeader.magic = TC_VOLENDMAGIC;
381 hostVolumeHeader.endTime = (endofvolume ? time(0) : 0);
382 volumeHeader_hton(&hostVolumeHeader, &buffer[bytesread]);
383 bytesread += sizeof(hostVolumeHeader);
386 /* Write the datablock out */
387 /* full data buffer - write it to tape */
388 rc = butm_WriteFileData(tapeInfoPtr, buffer, tapeblocks,
391 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
392 "Can't write VolumeData on tape\n");
395 bytesWritten = tapeblocks * BUTM_BLOCKSIZE;
396 tsize += bytesWritten;
398 /* Display a status line every statusSize or at end of volume */
400 && ((tsize >= statuscount) || endofvolume
401 || fragmentvolume)) {
404 localtime_r(&t, &tm);
405 printf("%02d:%02d:%02d: Task %u: %u KB: %s: %u B\n",
406 tm.tm_hour, tm.tm_min, tm.tm_sec, taskId,
407 tapeInfoPtr->kBytes, hostVolumeHeader.volumeName,
409 statuscount = tsize + statusSize;
413 /* End the dump before recording it in BUDB as successfully dumped */
414 rc = butm_WriteFileEnd(tapeInfoPtr);
417 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
418 "Can't write FileEnd on tape\n");
422 /* Record in BUDB the volume fragment as succcessfully dumped */
423 volumeFlags = ((fragmentNumber == 1) ? BUDB_VOL_FIRSTFRAG : 0);
425 volumeFlags |= BUDB_VOL_LASTFRAG;
426 rc = addVolume(0, dparamsPtr->databaseDumpId, dparamsPtr->tapeName,
427 nodePtr->dumps[dparamsPtr->curVolume].name,
428 nodePtr->dumps[dparamsPtr->curVolume].vid,
429 nodePtr->dumps[dparamsPtr->curVolume].cloneDate,
430 dparamsPtr->curVolStartPos, volBytesRead,
431 (fragmentNumber - 1), volumeFlags);
435 /* If haven't finished dumping the volume, end this
436 * tape and get the next tape.
439 /* Write an EOT marker.
440 * Log the error but ignore it since the dump is effectively done.
441 * Scantape will detect continued volume and not read the EOT.
443 rc = butm_WriteEOT(tapeInfoPtr);
445 TapeLog(1, taskId, rc, tapeInfoPtr->error,
446 "Warning: Can't write End-Of-Dump on tape\n");
448 /* Unmount the tape */
449 unmountTape(taskId, tapeInfoPtr);
451 /* Tell the database the tape is complete (and ok) */
452 rc = finishTape(&dparamsPtr->tape,
453 dparamsPtr->tapeInfoPtr->kBytes +
454 (dparamsPtr->tapeInfoPtr->nBytes ? 1 : 0));
458 /* get the next tape. Prompt, mount, and add it into the database */
459 dparamsPtr->tapeSeq++;
460 rc = getDumpTape(dparamsPtr, 1, 0); /* interactive - no append */
464 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
468 dparamsPtr->curVolumeStatus = DUMP_SUCCESS;
472 * If we hit the end, see if this is the first volume on the tape or not.
473 * Also, mark the tape as finished if the tape contains other dumps.
478 ErrorLog(2, taskId, code, tapeInfoPtr->error,
479 "Warning: Dump (%s) hit end-of-tape inferred\n",
480 nodePtr->dumpSetName);
482 if (tapeInfoPtr->position == 2) {
483 dparamsPtr->curVolumeStatus = DUMP_NORETRYEOT;
485 dparamsPtr->curVolumeStatus = DUMP_RETRY;
486 rc = finishTape(&dparamsPtr->tape,
487 dparamsPtr->tapeInfoPtr->kBytes +
488 (dparamsPtr->tapeInfoPtr->nBytes ? 1 : 0));
495 * This is used when an error occurs part way into a volume dump. Clean
496 * the tape state by writing an FileEnd mark. Forgo this action if we hit
500 rc = butm_WriteFileEnd(tapeInfoPtr);
503 ErrorLog(1, taskId, rc, tapeInfoPtr->error,
504 "Can't write FileEnd on tape\n");
509 rc = rx_EndCall(fromcall, 0);
516 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
518 code = (rc ? rc : rcode);
524 dparamsPtr->curVolumeStatus = DUMP_FAILED;
529 xbsaDumpVolume(struct tc_dumpDesc * curDump, struct dumpRock * dparamsPtr)
532 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
533 struct dumpNode *nodePtr = dparamsPtr->node;
534 char *buffer = bufferBlock;
535 afs_int32 taskId = nodePtr->taskID;
536 afs_int32 rc, code = 0;
538 afs_uint32 volBytesRead;
539 afs_uint32 chunkSize;
540 afs_int32 bytesread; /* rx reads */
541 int endofvolume = 0; /* Have we read all volume data */
542 int begindump = 0, indump = 0; /* if dump transaction started; if dumping data */
543 struct volumeHeader hostVolumeHeader;
545 struct rx_call *fromcall = (struct rx_call *)0;
546 struct rx_connection *fromconn;
547 afs_int32 updatedate, fromtid = 0;
548 volEntries volumeInfo;
549 afs_int32 bytesWritten;
550 afs_uint32 statuscount = statusSize, tsize = 0, esize;
553 char dumpIdStr[XBSA_MAX_OSNAME];
554 char volumeNameStr[XBSA_MAX_PATHNAME];
555 static char *dumpDescription = "AFS volume dump";
556 static char *objectDescription = "XBSA - butc";
558 dparamsPtr->curVolumeStatus = DUMP_NOTHING;
560 fromconn = Bind(htonl(curDump->hostAddr)); /* get connection to the server */
562 /* Determine when the volume was last cloned and updated */
563 volumeInfo.volEntries_val = (volintInfo *) 0;
564 volumeInfo.volEntries_len = 0;
565 rc = AFSVolListOneVolume(fromconn, curDump->partition, curDump->vid,
569 updatedate = volumeInfo.volEntries_val[0].updateDate;
572 RWVOL) ? time(0) : volumeInfo.volEntries_val[0].creationDate);
574 /* Get the volume size (in KB) and increase by 25%. Then set as a hyper */
575 esize = volumeInfo.volEntries_val[0].size;
576 esize += (esize / 4) + 1;
578 if (curDump->date >= curDump->cloneDate)
579 ERROR_EXIT(0); /* not recloned since last dump */
580 if (curDump->date > updatedate) {
581 dparamsPtr->curVolumeStatus = DUMP_NODUMP; /* not modified since last dump */
585 /* Start a new XBSA Transaction */
586 rc = xbsa_BeginTrans(&butxInfo);
587 if (rc != XBSA_SUCCESS) {
588 ErrorLog(1, taskId, rc, 0, "Unable to create a new transaction\n");
591 begindump = 1; /* Will need to do an xbsa_EndTrans */
593 /* Start the volserver transaction and dump. Once started, the
594 * volume status is "partial dump". Also, the transaction with
595 * the volserver is idle until the first read. An idle transaction
596 * will time out in 600 seconds. After the first rx_Read,
597 * the transaction is not idle. See GCTrans().
599 rc = AFSVolTransCreate(fromconn, curDump->vid, curDump->partition, ITBusy,
603 fromcall = rx_NewCall(fromconn);
605 rc = StartAFSVolDump(fromcall, fromtid, curDump->date);
609 dparamsPtr->curVolumeStatus = DUMP_PARTIAL;
610 dparamsPtr->curVolStartPos = tapeInfoPtr->position;
612 /* Tell XBSA what the name and size of volume to write */
613 strcpy(dumpIdStr, butcdumpIdStr); /* "backup_afs_volume_dumps" */
614 sprintf(volumeNameStr, "/%d", dparamsPtr->databaseDumpId);
615 strcat(volumeNameStr, "/");
616 strcat(volumeNameStr, curDump->name); /* <dumpid>/<volname> */
617 hset32(estSize, esize);
618 hshlft(estSize, 10); /* Multiply by 1024 so its in KB */
620 rc = xbsa_WriteObjectBegin(&butxInfo, dumpIdStr, volumeNameStr,
621 xbsalGName, estSize, dumpDescription,
623 if (rc != XBSA_SUCCESS) {
624 ErrorLog(1, taskId, rc, 0,
625 "Unable to begin writing of the fileset data to the server\n");
628 indump = 1; /* Will need to do an xbsa_WriteObjectEnd */
630 /* Create and Write the volume header */
631 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, 1);
632 hostVolumeHeader.contd = 0;
633 volumeHeader_hton(&hostVolumeHeader, buffer);
635 rc = xbsa_WriteObjectData(&butxInfo, buffer, sizeof(struct volumeHeader),
637 if (rc != XBSA_SUCCESS) {
638 ErrorLog(1, taskId, rc, 0,
639 "Unable to write VolumeHeader data to the server\n");
642 /* There is a bug in the ADSM library where the bytesWritten is
643 * not filled in, so we set it as correct anyway.
645 bytesWritten = sizeof(struct volumeHeader);
646 if (bytesWritten != sizeof(struct volumeHeader)) {
647 ErrorLog(1, taskId, rc, 0,
648 "The size of VolumeHeader written (%d) does not equal its actual size (%d)\n",
649 bytesWritten, sizeof(struct volumeHeader));
650 ERROR_EXIT(TC_INTERNALERROR);
653 incSize(tapeInfoPtr, sizeof(struct volumeHeader)); /* Increment amount we've written */
654 tsize += bytesWritten;
656 /* Start reading volume data, rx_Read(), and dumping to the tape
657 * until we've dumped the entire volume (endofvolume == 1).
661 while (!endofvolume) { /*w */
664 /* Check for abort in the middle of writing data */
665 if (volBytesRead >= chunkSize) {
666 chunkSize += BIGCHUNK;
667 if (checkAbortByTaskId(taskId))
668 ABORT_EXIT(TC_ABORTEDBYREQUEST);
670 /* set bytes dumped for backup */
672 nodePtr->statusNodePtr->nKBytes = tapeInfoPtr->kBytes;
676 /* Determine how much data to read in upcoming RX_Read() call */
679 /* Read some volume data. */
680 bytesread = rx_Read(fromcall, buffer, toread);
681 volBytesRead += bytesread;
682 if (bytesread != toread) {
685 /* Make sure were at end of volume and not a communication error */
686 rc = rx_Error(fromcall);
692 /* Create a volume trailer appending it to this data block (if not XBSA) */
693 makeVolumeHeader(&hostVolumeHeader, dparamsPtr, 1);
694 hostVolumeHeader.contd = 0;
695 hostVolumeHeader.magic = TC_VOLENDMAGIC;
696 hostVolumeHeader.endTime = time(0);
697 volumeHeader_hton(&hostVolumeHeader, &buffer[bytesread]);
698 bytesread += sizeof(hostVolumeHeader);
700 /* End the dump and transaction with the volserver. We end it now, before
701 * we make the XBSA call because if XBSA blocks, we could time out on the
702 * volserver (After last read, the transaction with the volserver is idle).
704 rc = rx_EndCall(fromcall, 0);
709 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
715 /* Write the datablock out */
716 rc = xbsa_WriteObjectData(&butxInfo, buffer, bytesread,
718 if (rc != XBSA_SUCCESS) {
719 ErrorLog(1, taskId, rc, 0,
720 "Unable to write data to the server\n");
723 /* There is a bug in the ADSM library where the bytesWritten is
724 * not filled in, so we set it as correct anyway.
726 bytesWritten = bytesread;
727 if (bytesWritten != bytesread) {
728 ErrorLog(1, taskId, rc, 0,
729 "The size of data written (%d) does not equal size read (%d)\n",
730 bytesWritten, bytesread);
731 ERROR_EXIT(TC_INTERNALERROR);
734 incSize(tapeInfoPtr, bytesread); /* Increment amount we've written */
735 tsize += bytesWritten;
737 /* Display a status line every statusSize or at end of volume */
738 if (statusSize && ((tsize >= statuscount) || endofvolume)) {
741 localtime_r(&t, &tm);
742 printf("%02d:%02d:%02d: Task %u: %u KB: %s: %u B\n", tm.tm_hour,
743 tm.tm_min, tm.tm_sec, taskId, tapeInfoPtr->kBytes,
744 hostVolumeHeader.volumeName, tsize);
745 statuscount = tsize + statusSize;
749 /* End the XBSA transaction before recording it in BUDB as successfully dumped */
750 rc = xbsa_WriteObjectEnd(&butxInfo);
752 if (rc != XBSA_SUCCESS) {
753 ErrorLog(1, taskId, rc, 0,
754 "Unable to terminate writing of the volume data to the server");
757 rc = xbsa_EndTrans(&butxInfo);
759 tapeInfoPtr->position++;
760 if (rc != XBSA_SUCCESS) {
761 ErrorLog(1, taskId, rc, 0,
762 "Unable to terminate the current transaction");
766 /* Record in BUDB the volume fragment as succcessfully dumped */
767 rc = addVolume(0, dparamsPtr->databaseDumpId, dparamsPtr->tapeName,
768 nodePtr->dumps[dparamsPtr->curVolume].name,
769 nodePtr->dumps[dparamsPtr->curVolume].vid,
770 nodePtr->dumps[dparamsPtr->curVolume].cloneDate,
771 dparamsPtr->curVolStartPos, volBytesRead, 0 /*frag0 */ ,
772 (BUDB_VOL_FIRSTFRAG | BUDB_VOL_LASTFRAG));
776 dparamsPtr->curVolumeStatus = DUMP_SUCCESS;
779 /* Cleanup after an error occurs part way into a volume dump */
781 rc = rx_EndCall(fromcall, 0);
788 rc = AFSVolEndTrans(fromconn, fromtid, &rcode);
790 code = (rc ? rc : rcode);
793 /* If this dump failed, what happens to successive retries
794 * of the volume? How do they get recorded in the XBSA database
795 * (overwritten)? If not, we don't record this in the BUDB database
796 * so it will not be removed when we delete the dump. What to do?
797 * Also if the volume was never recorded in the DB (partial dump).
801 rc = xbsa_WriteObjectEnd(&butxInfo);
803 if (rc != XBSA_SUCCESS) {
804 ErrorLog(1, taskId, rc, 0,
805 "Unable to terminate writing of the volume data to the server");
807 tapeInfoPtr->position++;
811 /* End the XBSA Transaction */
812 rc = xbsa_EndTrans(&butxInfo);
814 if (rc != XBSA_SUCCESS) {
815 ErrorLog(1, taskId, rc, 0,
816 "Unable to terminate the current transaction");
823 dparamsPtr->curVolumeStatus = DUMP_FAILED;
830 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
833 * Go through the list of volumes to dump, dumping each one. The action
834 * taken when a volume dump fails, depends on the passNumber. At minimum,
835 * the failed volume is remembered.
837 * flushSavedEntries - inconsistent treatment for errors. What should
838 * be done for user aborts?
842 dumpPass(struct dumpRock * dparamsPtr, int passNumber)
844 struct dumpNode *nodePtr = dparamsPtr->node;
845 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
846 afs_int32 taskId = nodePtr->taskID;
847 struct tc_dumpDesc *curDump;
849 afs_int32 code = 0, tcode, dvcode;
852 struct vldbentry vldbEntry;
853 struct sockaddr_in server;
856 TapeLog(2, taskId, 0, 0, "Starting pass %d\n", passNumber);
858 /* while there are more volumes to dump */
859 for (dparamsPtr->curVolume = 0; dparamsPtr->curVolume < nodePtr->arraySize; dparamsPtr->curVolume++) { /*w */
860 curDump = &nodePtr->dumps[dparamsPtr->curVolume];
861 if (curDump->hostAddr == 0)
864 /* set name of current volume being dumped */
866 strcpy(nodePtr->statusNodePtr->volumeName, curDump->name);
869 /* Determine location of the volume.
870 * In case the volume moved has moved.
872 if (passNumber > 1) { /*pass */
874 bc_GetEntryByID(cstruct, curDump->vid, curDump->vtype,
877 ErrorLog(0, taskId, tcode, 0,
878 "Volume %s (%u) failed - Can't find volume in VLDB\n",
879 curDump->name, curDump->vid);
880 curDump->hostAddr = 0;
881 dparamsPtr->volumesFailed++;
885 switch (curDump->vtype) {
887 if (!(vldbEntry.flags & BACK_EXISTS)) {
888 ErrorLog(0, taskId, 0, 0,
889 "Volume %s (%u) failed - Backup volume no longer exists\n",
890 curDump->name, curDump->vid);
891 curDump->hostAddr = 0;
892 dparamsPtr->volumesFailed++;
895 /* Fall into RWVOL case */
898 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the RW volume */
899 if (vldbEntry.serverFlags[e] & ITSRWVOL)
905 /* Try to use the server and partition we found the volume on
906 * Otherwise, use the first RO volume.
908 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the RO volume */
909 if ((curDump->hostAddr == vldbEntry.serverNumber[e])
910 && (curDump->partition ==
911 vldbEntry.serverPartition[e]))
915 if (e >= vldbEntry.nServers) { /* Didn't find RO volume */
916 for (e = 0; e < vldbEntry.nServers; e++) { /* Find the first RO volume */
917 if (vldbEntry.serverFlags[e] & ITSROVOL)
924 ErrorLog(0, taskId, 0, 0,
925 "Volume %s (%u) failed - Unknown volume type\n",
926 curDump->name, curDump->vid);
927 curDump->hostAddr = 0;
932 if (e >= vldbEntry.nServers) {
933 ErrorLog(0, taskId, 0, 0,
934 "Volume %s (%u) failed - Can't find volume entry in VLDB\n",
935 curDump->name, curDump->vid);
936 curDump->hostAddr = 0;
937 dparamsPtr->volumesFailed++;
941 /* Remember the server and partition the volume exists on */
942 memset(&server, 0, sizeof(server));
943 server.sin_addr.s_addr = vldbEntry.serverNumber[e];
945 server.sin_family = AF_INET;
946 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
947 server.sin_len = sizeof(struct sockaddr_in);
949 curDump->hostAddr = HOSTADDR(&server);
950 curDump->partition = vldbEntry.serverPartition[e];
952 /* Determine date from which to do an incremental dump
954 if (nodePtr->parent) {
956 bcdb_FindClone(nodePtr->parent, curDump->name,
961 curDump->date = 0; /* do a full dump */
965 if (checkAbortByTaskId(taskId))
966 ERROR_EXIT(TC_ABORTEDBYREQUEST);
968 /* Establish connection to volume - UV_ routine expects
969 * host address in network order
972 dvcode = xbsaDumpVolume(curDump, dparamsPtr);
974 dvcode = dumpVolume(curDump, dparamsPtr);
976 action = dparamsPtr->curVolumeStatus;
978 /* Flush volume and tape entries to the database */
979 tcode = flushSavedEntries(action);
985 TapeLog(1, taskId, 0, 0, "Volume %s (%u) successfully dumped\n",
986 curDump->name, curDump->vid);
988 ErrorLog(1, taskId, dvcode, 0,
989 "Warning: Termination processing error on volume %s (%u)\n",
990 curDump->name, curDump->vid);
992 curDump->hostAddr = 0;
993 dparamsPtr->volumesDumped++;
998 if (action == DUMP_PARTIAL) {
999 ErrorLog(1, taskId, dvcode, 0,
1000 "Volume %s (%u) failed - partially dumped\n",
1001 curDump->name, curDump->vid);
1002 } else if (dvcode) {
1003 ErrorLog(0, taskId, dvcode, 0, "Volume %s (%u) failed\n",
1004 curDump->name, curDump->vid);
1006 ErrorLog(0, taskId, dvcode, 0,
1007 "Volume %s (%u) not dumped - has not been re-cloned since last dump\n",
1008 curDump->name, curDump->vid);
1011 if (passNumber == maxpass) {
1015 ch = retryPrompt(curDump->name, curDump->vid, taskId);
1018 case 'r': /* retry */
1019 dparamsPtr->curVolume--; /* redump this volume */
1022 case 'o': /* omit */
1023 ErrorLog(1, taskId, 0, 0, "Volume %s (%u) omitted\n",
1024 curDump->name, curDump->vid);
1025 dparamsPtr->volumesFailed++;
1027 case 'a': /* abort */
1028 TapeLog(1, taskId, 0, 0, "Dump aborted\n");
1029 ERROR_EXIT(TC_ABORTEDBYREQUEST);
1032 ERROR_EXIT(TC_INTERNALERROR);
1039 TapeLog(1, taskId, dvcode, 0,
1040 "Volume %s (%u) hit end-of-tape inferred - will retry on next tape\n",
1041 curDump->name, curDump->vid);
1043 /* Get the next tape */
1044 unmountTape(taskId, tapeInfoPtr);
1046 dparamsPtr->tapeSeq++;
1047 tcode = getDumpTape(dparamsPtr, 1, 0); /* interactive - no appends */
1051 dparamsPtr->curVolume--; /* redump this volume */
1055 case DUMP_NORETRYEOT:
1056 ErrorLog(1, taskId, 0, 0,
1057 "Volume %s (%u) failed - volume larger than tape\n",
1058 curDump->name, curDump->vid);
1060 /* rewrite the label on the tape - rewind - no need to switch tapes */
1061 tcode = butm_Create(tapeInfoPtr, &dparamsPtr->tapeLabel, 1);
1063 ErrorLog(0, taskId, tcode, tapeInfoPtr->error,
1064 "Can't relabel tape\n");
1066 unmountTape(taskId, tapeInfoPtr);
1067 tcode = getDumpTape(dparamsPtr, 1, 0); /* interactive - no appends */
1070 } else { /* Record the tape in database */
1071 tapepos = tapeInfoPtr->position;
1073 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1074 dparamsPtr->tapeName,
1075 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1076 dparamsPtr->tapeLabel.useCount,
1077 dparamsPtr->tapeLabel.creationTime,
1078 dparamsPtr->tapeLabel.expirationDate, tapepos);
1081 curDump->hostAddr = 0;
1082 dparamsPtr->volumesFailed++;
1086 TapeLog(1, taskId, dvcode, 0,
1087 "Volume %s (%u) not dumped - has not been modified since last dump\n",
1088 curDump->name, curDump->vid);
1090 curDump->hostAddr = 0;
1091 dparamsPtr->volumesNotDumped++;
1095 ErrorLog(1, taskId, dvcode, 0, "Volume %s (%u) failed\n",
1096 curDump->name, curDump->vid);
1103 /* check if we terminated while processing a volume */
1104 if (dparamsPtr->curVolume < nodePtr->arraySize) {
1105 TapeLog(2, taskId, 0, 0,
1106 "Terminated while processing Volume %s (%u)\n", curDump->name,
1110 /* print a summary of this pass */
1111 TapeLog(2, taskId, 0, 0, "End of pass %d: Volumes remaining = %d\n",
1113 nodePtr->arraySize - (dparamsPtr->volumesDumped +
1114 dparamsPtr->volumesFailed +
1115 dparamsPtr->volumesNotDumped));
1120 Dumper(struct dumpNode *nodePtr)
1122 struct dumpRock dparams;
1123 struct butm_tapeInfo tapeInfo;
1129 /* for volume setup */
1131 int failedvolumes = 0;
1132 int dumpedvolumes = 0;
1133 int nodumpvolumes = 0;
1136 char finishedMsg1[50];
1137 char finishedMsg2[50];
1138 time_t startTime = 0;
1140 afs_int32 allocbufferSize;
1142 extern struct deviceSyncNode *deviceLatch;
1143 extern struct tapeConfig globalTapeConfig;
1144 extern afs_int32 createDump();
1146 taskId = nodePtr->taskID; /* Get task Id */
1147 setStatus(taskId, DRIVE_WAIT);
1148 EnterDeviceQueue(deviceLatch);
1149 clearStatus(taskId, DRIVE_WAIT);
1152 TapeLog(2, taskId, 0, 0, "Dump %s\n", nodePtr->dumpSetName);
1154 /* setup the dump parameters */
1155 memset(&dparams, 0, sizeof(dparams));
1156 dparams.node = nodePtr;
1157 dparams.tapeInfoPtr = &tapeInfo;
1158 dlqInit(&savedEntries);
1161 /* Instantiate the tape module */
1162 tapeInfo.structVersion = BUTM_MAJORVERSION;
1163 code = butm_file_Instantiate(&tapeInfo, &globalTapeConfig);
1165 ErrorLog(0, taskId, code, tapeInfo.error,
1166 "Can't initialize the tape module\n");
1171 /* check if abort requested while waiting on device latch */
1172 if (checkAbortByTaskId(taskId))
1173 ERROR_EXIT(TC_ABORTEDBYREQUEST);
1175 /* Are there volumes to dump */
1176 if (nodePtr->arraySize == 0) {
1177 TLog(taskId, "Dump (%s), no volumes to dump\n", nodePtr->dumpSetName);
1181 /* Allocate a buffer for the dumps. Leave room for header and vol-trailer.
1182 * dataSize is amount of data to read in each rx_Read() call.
1185 /* XBSA dumps have not header */
1186 dataSize = BufferSize;
1187 allocbufferSize = dataSize + sizeof(struct volumeHeader);
1189 tapeblocks = BufferSize / BUTM_BLOCKSIZE; /* # of 16K tapeblocks */
1190 dataSize = (tapeblocks * BUTM_BLKSIZE);
1192 BUTM_HDRSIZE + dataSize + sizeof(struct volumeHeader);
1195 bufferBlock = malloc(allocbufferSize);
1197 ErrorLog(0, taskId, TC_NOMEMORY, 0,
1198 "Can't allocate BUFFERSIZE for dumps\n");
1199 ERROR_EXIT(TC_NOMEMORY);
1202 /* Determine the dumpid of the most recent dump of this volumeset and dumplevel
1203 * Used when requesting a tape. Done now because once we create the dump, the
1204 * routine will then find the newly created dump.
1206 sprintf(strlevel, "%d", nodePtr->level);
1208 bcdb_FindLatestDump(nodePtr->volumeSetName, strlevel,
1211 if (code != BUDB_NODUMPNAME) {
1212 ErrorLog(0, taskId, code, 0, "Can't read backup database\n");
1215 memset(&dparams.lastDump, 0, sizeof(dparams.lastDump));
1218 code = createDump(&dparams); /* enter dump into database */
1220 ErrorLog(0, taskId, code, 0, "Can't create dump in database\n");
1224 TLog(taskId, "Dump %s (DumpID %u)\n", nodePtr->dumpSetName,
1225 dparams.databaseDumpId);
1228 /* mount the tape and write its label */
1229 code = getDumpTape(&dparams, autoQuery, nodePtr->doAppend);
1231 /* Create a dummy tape to satisfy backup databae */
1232 code = getXBSATape(&dparams);
1233 tapeInfo.position = 1;
1236 /* If didn't write the label, remove dump from the database */
1237 if (!dparams.wroteLabel) {
1238 i = bcdb_deleteDump(dparams.databaseDumpId, 0, 0, 0);
1239 if (i && (i != BUDB_NOENT))
1240 ErrorLog(1, taskId, i, 0,
1241 "Warning: Can't delete dump %u from database\n",
1242 dparams.databaseDumpId);
1244 dparams.databaseDumpId = 0;
1246 ERROR_EXIT(code); /* exit with code from getTape */
1249 startTime = time(0);
1250 for (pass = 1; pass <= maxpass; pass++) {
1251 lastPass = (pass == maxpass);
1252 code = dumpPass(&dparams, pass);
1256 /* if no failed volumes, we're done */
1257 if ((dparams.volumesDumped + dparams.volumesFailed +
1258 dparams.volumesNotDumped) == nodePtr->arraySize)
1263 * Log the error but ignore it since the dump is effectively done.
1264 * Scantape may assume another volume and ask for next tape.
1267 code = butm_WriteEOT(&tapeInfo);
1269 TapeLog(taskId, code, tapeInfo.error,
1270 "Warning: Can't write end-of-dump on tape\n");
1274 finishTape(&dparams.tape,
1275 dparams.tapeInfoPtr->kBytes +
1276 (dparams.tapeInfoPtr->nBytes ? 1 : 0));
1280 code = finishDump(&dparams.dump);
1284 action = dparams.curVolumeStatus;
1285 code = flushSavedEntries(action);
1296 unmountTape(taskId, &tapeInfo);
1300 dumpedvolumes = dparams.volumesDumped;
1301 nodumpvolumes = dparams.volumesNotDumped;
1302 failedvolumes = nodePtr->arraySize - (dumpedvolumes + nodumpvolumes);
1304 /* pass back the number of volumes we failed to dump */
1306 nodePtr->statusNodePtr->volsFailed = failedvolumes;
1309 lastPass = 1; /* In case we aborted */
1311 DUMPNAME(finishedMsg1, nodePtr->dumpSetName, dparams.databaseDumpId);
1312 sprintf(finishedMsg2, "%d volumes dumped", dumpedvolumes);
1313 if (failedvolumes) {
1314 sprintf(msg, ", %d failed", failedvolumes);
1315 strcat(finishedMsg2, msg);
1317 if (nodumpvolumes) {
1318 sprintf(msg, ", %d unchanged", nodumpvolumes);
1319 strcat(finishedMsg2, msg);
1322 if (code == TC_ABORTEDBYREQUEST) {
1323 ErrorLog(0, taskId, 0, 0, "%s: Aborted by request. %s\n",
1324 finishedMsg1, finishedMsg2);
1325 clearStatus(taskId, ABORT_REQUEST);
1326 setStatus(taskId, ABORT_DONE);
1328 ErrorLog(0, taskId, code, 0, "%s: Finished with errors. %s\n",
1329 finishedMsg1, finishedMsg2);
1330 setStatus(taskId, TASK_ERROR);
1332 TLog(taskId, "%s: Finished. %s\n", finishedMsg1, finishedMsg2);
1336 /* Record how long the dump took */
1337 if (centralLogIO && startTime) {
1339 afs_int32 hrs, min, sec, tmp;
1341 struct tm tmstart, tmend;
1343 localtime_r(&startTime, &tmstart);
1344 localtime_r(&endTime, &tmend);
1345 timediff = (int)endTime - (int)startTime;
1346 hrs = timediff / 3600;
1347 tmp = timediff % 3600;
1352 "%-5d %02d/%02d/%04d %02d:%02d:%02d "
1353 "%02d/%02d/%04d %02d:%02d:%02d " "%02d:%02d:%02d "
1354 "%s %d of %d volumes dumped (%ld KB)\n", taskId,
1355 tmstart.tm_mon + 1, tmstart.tm_mday, tmstart.tm_year + 1900,
1356 tmstart.tm_hour, tmstart.tm_min, tmstart.tm_sec,
1357 tmend.tm_mon + 1, tmend.tm_mday, tmend.tm_year + 1900,
1358 tmend.tm_hour, tmend.tm_min, tmend.tm_sec, hrs, min, sec,
1359 nodePtr->volumeSetName, dumpedvolumes,
1360 dumpedvolumes + failedvolumes,
1361 dparams.tapeInfoPtr->kBytes + 1);
1363 fwrite(line, strlen(line), 1, centralLogIO);
1364 fflush(centralLogIO);
1367 setStatus(taskId, TASK_DONE);
1369 FreeNode(taskId); /* free the dump node */
1370 LeaveDeviceQueue(deviceLatch);
1374 #define BELLTIME 60 /* 60 seconds before a bell rings */
1375 #define BELLCHAR 7 /* ascii for bell */
1378 * prompt the user to decide how to handle a failed volume dump. The
1379 * volume parameters describe the volume that failed
1381 * volumeName - name of volume
1382 * volumeId - volume id
1383 * taskId - for job contrl
1385 * character typed by user, one of r, o or a
1389 retryPrompt(char *volumeName, afs_int32 volumeId, afs_uint32 taskId)
1395 setStatus(taskId, OPR_WAIT);
1396 printf("\nDump of volume %s (%u) failed\n\n", volumeName, volumeId);
1398 printf("Please select action to be taken for this volume\n");
1401 printf("r - retry, try dumping this volume again\n");
1402 printf("o - omit, this volume from this dump\n");
1403 printf("a - abort, the entire dump\n");
1412 #ifdef AFS_PTHREAD_ENV
1413 code = GetResponseKey(5, &ch); /* ch stores key pressed */
1415 code = LWP_GetResponseKey(5, &ch); /* ch stores key pressed */
1418 break; /* input is available */
1420 if (checkAbortByTaskId(taskId)) {
1421 clearStatus(taskId, OPR_WAIT);
1423 ("This tape operation has been aborted by the coordinator\n");
1427 if (time(0) > start + BELLTIME)
1430 /* otherwise, we should beep again, check for abort and go back,
1431 * since the GetResponseKey() timed out.
1434 break; /* input is available */
1436 clearStatus(taskId, OPR_WAIT);
1437 if (ch != 'r' && ch != 'o' && ch != 'a') {
1438 printf("Please select one of the 3 options, r, o or a\n");
1445 /* For testing: it prints the tape label */
1447 printTapeLabel(struct butm_tapeLabel *tl)
1449 printf("Tape Label\n");
1450 printf(" structVersion = %d\n", tl->structVersion);
1451 printf(" creationTime = %u\n", tl->creationTime);
1452 printf(" expirationDate = %u\n", tl->expirationDate);
1453 printf(" AFSName = %s\n", tl->AFSName);
1454 printf(" cell = %s\n", tl->cell);
1455 printf(" dumpid = %d\n", tl->dumpid);
1456 printf(" useCount = %d\n", tl->useCount);
1457 printf(" comment = %s\n", tl->comment);
1458 printf(" pName = %s\n", tl->pName);
1459 printf(" size = %u\n", tl->size);
1460 printf(" dumpPath = %s\n", tl->dumpPath);
1465 * Create a tape structure to be satisfy the backup database
1466 * even though we don't really use a tape with XBSA.
1469 getXBSATape(struct dumpRock *dparamsPtr)
1471 struct dumpNode *nodePtr = dparamsPtr->node;
1472 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
1473 struct butm_tapeLabel *tapeLabelPtr = &dparamsPtr->tapeLabel;
1476 tc_MakeTapeName(dparamsPtr->tapeName, &nodePtr->tapeSetDesc,
1477 dparamsPtr->tapeSeq);
1479 GetNewLabel(tapeInfoPtr, "" /*pName */ , dparamsPtr->tapeName,
1481 strcpy(tapeLabelPtr->dumpPath, nodePtr->dumpName);
1482 tapeLabelPtr->dumpid = dparamsPtr->databaseDumpId;
1483 tapeLabelPtr->expirationDate =
1484 calcExpirationDate(nodePtr->tapeSetDesc.expType,
1485 nodePtr->tapeSetDesc.expDate, time(0));
1487 /* printTapeLabel(tapeLabelPtr); For testing */
1490 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1491 dparamsPtr->tapeName,
1492 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1493 tapeLabelPtr->useCount, tapeLabelPtr->creationTime,
1494 tapeLabelPtr->expirationDate, 0 /*tape position */ );
1499 * iterate until the desired tape (as specified by the dump structures)
1503 * 0 - assume the tape is there. Prompt if assumption false
1504 * 1 - prompt regardless
1508 getDumpTape(struct dumpRock *dparamsPtr, int interactiveFlag,
1511 struct dumpNode *nodePtr = dparamsPtr->node;
1512 struct butm_tapeInfo *tapeInfoPtr = dparamsPtr->tapeInfoPtr;
1513 struct butm_tapeLabel *newTapeLabelPtr = &dparamsPtr->tapeLabel;
1514 char AFSTapeName[TC_MAXTAPENAMELEN];
1515 afs_int32 taskId = nodePtr->taskID;
1516 struct butm_tapeLabel oldTapeLabel;
1517 struct budb_dumpEntry dumpEntry;
1518 struct budb_tapeEntry tapeEntry;
1519 struct budb_volumeEntry volEntry;
1526 afs_int32 tapepos, lastpos;
1528 extern struct tapeConfig globalTapeConfig;
1529 extern struct udbHandleS udbHandle;
1531 askForTape = interactiveFlag;
1532 dparamsPtr->wroteLabel = 0;
1534 /* Keep prompting for a tape until we get it right */
1536 /* What the name of the tape would be if not appending to it */
1537 tc_MakeTapeName(AFSTapeName, &nodePtr->tapeSetDesc,
1538 dparamsPtr->tapeSeq);
1544 PromptForTape((doAppend ? APPENDOPCODE : WRITEOPCODE),
1545 AFSTapeName, dparamsPtr->databaseDumpId, taskId,
1553 /* open the tape device */
1554 code = butm_Mount(tapeInfoPtr, AFSTapeName);
1556 TapeLog(0, taskId, code, tapeInfoPtr->error, "Can't open tape\n");
1560 /* Read the tape label */
1561 code = butm_ReadLabel(tapeInfoPtr, &oldTapeLabel, 1); /* rewind */
1563 if (tapeInfoPtr->error) {
1564 ErrorLog(0, taskId, code, tapeInfoPtr->error,
1565 "Warning: Tape error while reading label (will proceed with dump)\n");
1567 memset(&oldTapeLabel, 0, sizeof(oldTapeLabel));
1570 /* Check if null tape. Prior 3.3, backup tapes have no dump id */
1571 if ((strcmp(oldTapeLabel.AFSName, "") == 0)
1572 && (oldTapeLabel.dumpid == 0)) {
1575 "Dump not found on tape. Proceeding with initial dump\n");
1578 } else if (doAppend) { /* appending */
1579 /* Check that we don't have a database dump tape */
1580 if (databaseTape(oldTapeLabel.AFSName)) {
1581 char gotName[BU_MAXTAPELEN + 32];
1583 /* label does not match */
1584 LABELNAME(gotName, &oldTapeLabel);
1585 TLog(taskId, "Can't append to database tape %s\n", gotName);
1589 /* Verify that the tape is of version 4 (AFS 3.3) or greater */
1590 if (oldTapeLabel.structVersion < TAPE_VERSION_4) {
1592 "Can't append: requires tape version %d or greater\n",
1597 /* Verify that the last tape of the dump set is in the drive.
1598 * volEntry will be zeroed if last dump has no volume entries.
1601 bcdb_FindLastTape(oldTapeLabel.dumpid, &dumpEntry, &tapeEntry,
1604 ErrorLog(0, taskId, code, 0,
1605 "Can't append: Can't find last volume of dumpId %u in database\n",
1606 oldTapeLabel.dumpid);
1607 printf("Please scan the dump in or choose another tape\n");
1611 (volEntry.position ? volEntry.position : tapeEntry.labelpos);
1613 if (strcmp(TNAME(&oldTapeLabel), tapeEntry.name)) {
1614 char expName[BU_MAXTAPELEN + 32], gotName[BU_MAXTAPELEN + 32];
1616 TAPENAME(expName, tapeEntry.name, oldTapeLabel.dumpid);
1617 LABELNAME(gotName, &oldTapeLabel);
1620 "Can't append: Last tape in dump-set is %s, label seen %s\n",
1625 /* After reading the tape label, we now know what it is */
1626 strcpy(AFSTapeName, oldTapeLabel.AFSName); /* the real name */
1627 strcpy(tapeInfoPtr->name, oldTapeLabel.AFSName); /* the real name */
1629 /* Position after last volume on the tape */
1630 code = butm_SeekEODump(tapeInfoPtr, lastpos);
1632 ErrorLog(0, taskId, code, tapeInfoPtr->error,
1633 "Can't append: Can't position to end of dump on tape %s\n",
1638 /* Track size of tape - set after seek since seek changes the value */
1639 tapeInfoPtr->kBytes = tapeEntry.useKBytes;
1640 } else { /* not appending */
1644 struct budb_dumpEntry de, de2;
1646 /* Check if tape name is not what expected - null tapes are acceptable
1647 * Don't do check if the tape has a user defined label.
1649 if (dump_namecheck && (strcmp(oldTapeLabel.pName, "") == 0)) {
1650 if (strcmp(oldTapeLabel.AFSName, "") && /* not null tape */
1651 strcmp(oldTapeLabel.AFSName, AFSTapeName)) { /* not expected name */
1652 TLog(taskId, "Tape label expected %s, label seen %s\n",
1653 AFSTapeName, oldTapeLabel.AFSName);
1657 /* Check that we don't have a database dump tape */
1658 if (databaseTape(oldTapeLabel.AFSName)) {
1659 /* label does not match */
1661 "Tape label expected %s, can't dump to database tape %s\n",
1662 AFSTapeName, oldTapeLabel.AFSName);
1667 /* Verify the tape has not expired - only check if not appending */
1668 if (!tapeExpired(&oldTapeLabel)) {
1669 TLog(taskId, "This tape has not expired\n");
1673 /* Given a tape dump with good data, verify we don't overwrite recent dumps
1674 * and also verify that the volume will be restorable - if not print warnings
1676 if (oldTapeLabel.dumpid) {
1677 /* Do not overwrite a tape that belongs to the dump's dumpset */
1679 (dparamsPtr->initialDumpId ? dparamsPtr->
1680 initialDumpId : dparamsPtr->databaseDumpId);
1681 if (oldTapeLabel.dumpid == tapeid) {
1682 ErrorLog(0, taskId, 0, 0,
1683 "Can't overwrite tape containing the dump in progress\n");
1687 /* Since the dumpset on this tape will be deleted from database, check if
1688 * any of the dump's parent-dumps are on this tape.
1690 for (dmp = nodePtr->parent; dmp; dmp = de.parent) {
1691 code = bcdb_FindDumpByID(dmp, &de);
1693 ErrorLog(0, taskId, 0, 0,
1694 "Warning: Can't find parent dump %u in backup database\n",
1699 tapeid = (de.initialDumpID ? de.initialDumpID : de.id);
1700 if (oldTapeLabel.dumpid == tapeid) {
1701 ErrorLog(0, taskId, 0, 0,
1702 "Can't overwrite the parent dump %s (DumpID %u)\n",
1708 /* Since the dumpset on this tape will be deleted from database, check if
1709 * any of the dumps in this dumpset are most-recent-dumps.
1711 for (dmp = oldTapeLabel.dumpid; dmp; dmp = de.appendedDumpID) {
1712 if (dmp == dparamsPtr->lastDump.id) {
1713 memcpy(&de, &dparamsPtr->lastDump, sizeof(de));
1714 memcpy(&de2, &dparamsPtr->lastDump, sizeof(de2));
1716 code = bcdb_FindDumpByID(dmp, &de);
1719 sprintf(strlevel, "%d", de.level);
1721 bcdb_FindLatestDump(de.volumeSetName, strlevel,
1727 /* If dump on the tape is the latest dump at this level */
1728 if (de.id == de2.id) {
1729 if (strcmp(DUMP_TAPE_NAME, de2.name) == 0) {
1730 ErrorLog(0, taskId, 0, 0,
1731 "Warning: Overwriting most recent dump %s (DumpID %u)\n",
1734 ErrorLog(0, taskId, 0, 0,
1735 "Warning: Overwriting most recent dump of the '%s' volumeset: %s (DumpID %u)\n",
1736 de.volumeSetName, de.name, de.id);
1740 } /* if (oldTapeLabel.dumpid) */
1741 } /* else not appending */
1744 * Now have the right tape. Create a new label for the tape
1745 * Appended labels have the dump's dumpId - labels at beginnings of
1746 * tape have the initial dump's dumpId.
1747 * Appended labels do not increment the useCount.
1748 * Labels at beginnings of tape use the most future expiration of the dump set.
1750 GetNewLabel(tapeInfoPtr, oldTapeLabel.pName, AFSTapeName,
1752 strcpy(newTapeLabelPtr->dumpPath, nodePtr->dumpName);
1753 newTapeLabelPtr->expirationDate =
1754 calcExpirationDate(nodePtr->tapeSetDesc.expType,
1755 nodePtr->tapeSetDesc.expDate, time(0));
1756 newTapeLabelPtr->dumpid = dparamsPtr->databaseDumpId;
1757 newTapeLabelPtr->useCount = oldTapeLabel.useCount;
1760 newTapeLabelPtr->useCount++;
1761 if (dparamsPtr->initialDumpId) {
1762 newTapeLabelPtr->dumpid = dparamsPtr->initialDumpId;
1763 expir = ExpirationDate(dparamsPtr->initialDumpId);
1764 if (expir > newTapeLabelPtr->expirationDate)
1765 newTapeLabelPtr->expirationDate = expir;
1769 /* write the label on the tape - rewind if not appending and vice-versa */
1770 code = butm_Create(tapeInfoPtr, newTapeLabelPtr, !doAppend);
1772 char gotName[BU_MAXTAPELEN + 32];
1774 LABELNAME(gotName, newTapeLabelPtr);
1775 TapeLog(0, taskId, code, tapeInfoPtr->error,
1776 "Can't label tape as %s\n", gotName);
1779 dparamsPtr->wroteLabel = 1; /* Remember we wrote the label */
1780 tapepos = tapeInfoPtr->position - 1;
1782 strcpy(dparamsPtr->tapeName, TNAME(newTapeLabelPtr));
1784 /* If appending, set dumpentry in the database as appended. */
1786 char gotName[BU_MAXTAPELEN + 32];
1788 nodePtr->tapeSetDesc.b = extractTapeSeq(AFSTapeName);
1789 dparamsPtr->dump.tapes.b = nodePtr->tapeSetDesc.b;
1790 dparamsPtr->initialDumpId = oldTapeLabel.dumpid;
1791 strcpy(nodePtr->tapeSetDesc.format, dumpEntry.tapes.format);
1794 bcdb_MakeDumpAppended(dparamsPtr->databaseDumpId,
1795 dparamsPtr->initialDumpId,
1796 nodePtr->tapeSetDesc.b);
1798 ErrorLog(2, taskId, code, 0,
1799 "Warning: Can't append dump %u to dump %u in database\n",
1800 dparamsPtr->databaseDumpId,
1801 dparamsPtr->initialDumpId);
1803 LABELNAME(gotName, &oldTapeLabel);
1804 TLog(taskId, "Appending dump %s (DumpID %u) to tape %s\n",
1805 nodePtr->dumpSetName, dparamsPtr->databaseDumpId, gotName);
1808 /* If not appending, delete overwritten dump from the database */
1810 if ((oldTapeLabel.structVersion >= TAPE_VERSION_3)
1811 && oldTapeLabel.dumpid) {
1812 code = bcdb_deleteDump(oldTapeLabel.dumpid, 0, 0, 0);
1813 if (code && (code != BUDB_NOENT))
1814 ErrorLog(0, taskId, code, 0,
1815 "Warning: Can't delete old dump %u from database\n",
1816 oldTapeLabel.dumpid);
1821 useTape(&dparamsPtr->tape, dparamsPtr->databaseDumpId,
1822 dparamsPtr->tapeName,
1823 (dparamsPtr->tapeSeq + dparamsPtr->dump.tapes.b),
1824 newTapeLabelPtr->useCount, newTapeLabelPtr->creationTime,
1825 newTapeLabelPtr->expirationDate, tapepos);
1828 * The margin of space to check for end of tape is set to the
1829 * amount of space used to write an end-of-tape multiplied by 2.
1830 * The amount of space is size of a 16K volume trailer, a 16K File
1831 * End mark, its EOF marker, a 16K EODump marker, its EOF marker,
1832 * and up to two EOF markers done on close (3 16K blocks + 4 EOF
1835 tc_EndMargin = (3 * 16384 + 4 * globalTapeConfig.fileMarkSize) * 2;
1836 tc_KEndMargin = tc_EndMargin / 1024;
1840 unmountTape(taskId, tapeInfoPtr);
1848 makeVolumeHeader(struct volumeHeader *vhptr, struct dumpRock *dparamsPtr,
1851 struct dumpNode *nodePtr = dparamsPtr->node;
1852 struct tc_dumpDesc *curDump;
1855 curDump = &nodePtr->dumps[dparamsPtr->curVolume];
1857 memset(vhptr, 0, sizeof(*vhptr));
1858 strcpy(vhptr->volumeName, curDump->name);
1859 vhptr->volumeID = curDump->vid;
1860 vhptr->cloneDate = curDump->cloneDate;
1861 vhptr->server = curDump->hostAddr;
1862 vhptr->part = curDump->partition;
1863 vhptr->from = curDump->date;
1864 vhptr->frag = fragmentNumber;
1866 vhptr->magic = TC_VOLBEGINMAGIC;
1867 vhptr->dumpID = dparamsPtr->databaseDumpId; /* real dump id */
1868 vhptr->level = nodePtr->level;
1869 vhptr->parentID = nodePtr->parent;
1871 vhptr->versionflags = CUR_TAPE_VERSION;
1872 strcpy(vhptr->dumpSetName, nodePtr->dumpSetName);
1873 strcpy(vhptr->preamble, "H++NAME#");
1874 strcpy(vhptr->postamble, "T--NAME#");
1880 volumeHeader_hton(struct volumeHeader *hostPtr, struct volumeHeader *netPtr)
1882 struct volumeHeader volHdr;
1884 strcpy(volHdr.preamble, hostPtr->preamble);
1885 strcpy(volHdr.postamble, hostPtr->postamble);
1886 strcpy(volHdr.volumeName, hostPtr->volumeName);
1887 strcpy(volHdr.dumpSetName, hostPtr->dumpSetName);
1888 volHdr.volumeID = htonl(hostPtr->volumeID);
1889 volHdr.server = htonl(hostPtr->server);
1890 volHdr.part = htonl(hostPtr->part);
1891 volHdr.from = htonl(hostPtr->from);
1892 volHdr.frag = htonl(hostPtr->frag);
1893 volHdr.magic = htonl(hostPtr->magic);
1894 volHdr.contd = htonl(hostPtr->contd);
1895 volHdr.dumpID = htonl(hostPtr->dumpID);
1896 volHdr.level = htonl(hostPtr->level);
1897 volHdr.parentID = htonl(hostPtr->parentID);
1898 volHdr.endTime = htonl(hostPtr->endTime);
1899 volHdr.versionflags = htonl(hostPtr->versionflags);
1900 volHdr.cloneDate = htonl(hostPtr->cloneDate);
1902 memcpy(netPtr, &volHdr, sizeof(struct volumeHeader));
1906 /* database related routines */
1909 createDump(struct dumpRock *dparamsPtr)
1911 struct dumpNode *nodePtr = dparamsPtr->node;
1912 struct budb_dumpEntry *dumpPtr;
1915 dumpPtr = &dparamsPtr->dump;
1916 memset(dumpPtr, 0, sizeof(*dumpPtr));
1918 /* id filled in by database */
1919 dumpPtr->parent = nodePtr->parent;
1920 dumpPtr->level = nodePtr->level;
1924 if (xbsaType == XBSA_SERVER_TYPE_ADSM) {
1925 strcpy(dumpPtr->tapes.tapeServer, butxInfo.serverName);
1926 dumpPtr->flags = BUDB_DUMP_ADSM;
1928 if (!(butxInfo.serverType & XBSA_SERVER_FLAG_MULTIPLE)) {
1929 /* The current server (API) doesn't provide the function required
1930 * to specify a server at startup time. For that reason, we can't
1931 * be sure that the server name supplied by the user in the user-
1932 * defined configuration file is correct. We set a flag here so
1933 * we know at restore time that the servername info in the backup
1934 * database may be incorrect. We will not allow a server switch
1935 * at that time, even if the server at restore time supports
1938 dumpPtr->flags |= BUDB_DUMP_XBSA_NSS;
1942 strcpy(dumpPtr->volumeSetName, nodePtr->volumeSetName);
1943 strcpy(dumpPtr->dumpPath, nodePtr->dumpName);
1944 strcpy(dumpPtr->name, nodePtr->dumpSetName);
1945 dumpPtr->created = 0; /* let database assign it */
1946 dumpPtr->incTime = 0; /* not really used */
1947 dumpPtr->nVolumes = 0;
1948 dumpPtr->initialDumpID = 0;
1950 dumpPtr->tapes.id = groupId;
1951 dumpPtr->tapes.b = 1;
1952 dumpPtr->tapes.maxTapes = 0;
1953 strcpy(dumpPtr->tapes.format, nodePtr->tapeSetDesc.format);
1955 /* principal filled in by database */
1957 /* now call the database to create the entry */
1958 code = bcdb_CreateDump(dumpPtr);
1960 dparamsPtr->databaseDumpId = dumpPtr->id;
1967 * Initialize to a specific server. The first time, we remember the
1968 * server as the original server and go back to it each time we pass 0
1972 InitToServer(afs_int32 taskId, struct butx_transactionInfo * butxInfoP,
1975 static char origserver[BSA_MAX_DESC];
1976 static int init = 0;
1977 afs_int32 rc, code = 0;
1980 strcpy(origserver, "");
1985 server = origserver; /* return to original server */
1986 if (strcmp(server, "") == 0)
1987 return 0; /* No server, do nothing */
1988 if (strcmp(butxInfoP->serverName, server) == 0)
1989 return 0; /* same server, do nothing */
1990 if (strcmp(origserver, "") == 0)
1991 strcpy(origserver, server); /* remember original server */
1993 if (strcmp(butxInfoP->serverName, "") != 0) {
1994 /* If already connected to a server, disconnect from it.
1995 * Check to see if our server does not support switching.
1997 if (!(butxInfo.serverType & XBSA_SERVER_FLAG_MULTIPLE)) {
1998 ErrorLog(0, taskId, TC_BADTASK, 0,
1999 "This version of XBSA libraries does not support switching "
2000 "from server %s to server %s\n", butxInfoP->serverName,
2002 return (TC_BADTASK);
2005 rc = xbsa_Finalize(&butxInfo);
2006 if (rc != XBSA_SUCCESS) {
2007 ErrorLog(0, taskId, rc, 0,
2008 "InitToServer: Unable to terminate the connection to server %s\n",
2009 butxInfoP->serverName);
2014 /* initialize to the new server */
2015 rc = xbsa_Initialize(&butxInfo, xbsaObjectOwner, appObjectOwner,
2016 xbsaSecToken, server);
2017 if (rc != XBSA_SUCCESS) {
2018 ErrorLog(0, taskId, rc, 0,
2019 "InitToServer: Unable to initialize the XBSA library to server %s\n",
2033 DeleteDump(struct deleteDumpIf *ptr)
2036 afs_int32 rc, code = 0;
2038 afs_int32 index, next, dbTime;
2040 struct budb_dumpEntry dumpEntry;
2041 char tapeName[BU_MAXTAPELEN];
2042 char dumpIdStr[XBSA_MAX_OSNAME];
2043 char volumeNameStr[XBSA_MAX_PATHNAME];
2046 int allnotfound = 1, onenotfound = 0;
2047 extern struct udbHandleS udbHandle;
2048 extern struct deviceSyncNode *deviceLatch;
2050 setStatus(taskId, DRIVE_WAIT);
2051 EnterDeviceQueue(deviceLatch);
2052 clearStatus(taskId, DRIVE_WAIT);
2054 dumpid = ptr->dumpID;
2055 taskId = ptr->taskId; /* Get task Id */
2058 TapeLog(2, taskId, 0, 0, "Delete Dump %u\n", dumpid);
2060 vl.budb_volumeList_len = 0;
2061 vl.budb_volumeList_val = 0;
2064 /* Get the dump info for the dump we are deleting */
2065 rc = bcdb_FindDumpByID(dumpid, &dumpEntry);
2067 ErrorLog(0, taskId, rc, 0,
2068 "Unable to locate dump ID %u in database\n", dumpid);
2069 setStatus(taskId, TASK_ERROR);
2073 /* we must make sure that we are configured with the correct type of
2074 * XBSA server for this dump delete! Only those dumped to an ADSM server.
2076 if ((xbsaType == XBSA_SERVER_TYPE_ADSM)
2077 && !((dumpEntry.flags & (BUDB_DUMP_ADSM | BUDB_DUMP_BUTA)))) {
2078 ErrorLog(0, taskId, TC_BADTASK, 0,
2079 "The dump %u requested for deletion is incompatible with this instance of butc\n",
2081 setStatus(taskId, TASK_ERROR);
2082 ERROR_EXIT(TC_BADTASK);
2085 /* Make sure we are connected to the correct server. If not, switch to it if appropriate */
2086 if ((strlen((char *)dumpEntry.tapes.tapeServer) != 0)
2087 && (strcmp((char *)dumpEntry.tapes.tapeServer, butxInfo.serverName) !=
2090 /* Check to see if the tapeServer name is trustworthy */
2091 if ((dumpEntry.flags & (BUDB_DUMP_XBSA_NSS | BUDB_DUMP_BUTA))
2092 && !forcemultiple) {
2093 /* The dump was made with a version of the XBSA interface
2094 * that didn't allow switching of servers, we can't be sure
2095 * that the servername in the backup database is correct. So,
2096 * we will check the servername and log it if they don't match;
2097 * but we will try to do the delete without switching servers.
2100 "The dump %d requested for deletion is on server %s "
2101 "but butc is connected to server %s "
2102 "(Attempting to delete the dump anyway)\n", dumpid,
2103 (char *)dumpEntry.tapes.tapeServer, butxInfo.serverName);
2106 "The dump %u requested for deletion is on server %s "
2107 "but butc is connected to server %s "
2108 "(switching servers)\n", dumpid,
2109 (char *)dumpEntry.tapes.tapeServer, butxInfo.serverName);
2111 rc = InitToServer(taskId, &butxInfo,
2112 (char *)dumpEntry.tapes.tapeServer);
2113 if (rc != XBSA_SUCCESS) {
2114 setStatus(taskId, TASK_ERROR);
2120 /* Start a new Transaction */
2121 rc = xbsa_BeginTrans(&butxInfo);
2122 if (rc != XBSA_SUCCESS) {
2123 ErrorLog(0, taskId, rc, 0, "Unable to create a new transaction\n");
2124 setStatus(taskId, TASK_ERROR);
2129 /* Query the backup database for list of volumes to delete */
2130 for (index = next = 0; index != -1; index = next) {
2131 rc = ubik_Call_SingleServer(BUDB_GetVolumes, udbHandle.uh_client,
2132 UF_SINGLESERVER, BUDB_MAJORVERSION,
2133 BUDB_OP_DUMPID, tapeName, dumpid, 0,
2134 index, &next, &dbTime, &vl);
2136 if (rc == BUDB_ENDOFLIST)
2138 ErrorLog(0, taskId, rc, 0, "Can't find volume info for dump %d\n",
2140 setStatus(taskId, TASK_ERROR);
2144 /* Delete all volumes on the list */
2145 for (i = 0; i < vl.budb_volumeList_len; i++) {
2146 if (dumpEntry.flags & BUDB_DUMP_BUTA) {
2147 /* dump was from buta, use old buta style names */
2148 sprintf(dumpIdStr, "/%d", dumpid);
2149 strcpy(volumeNameStr, "/");
2150 strcat(volumeNameStr, (char *)vl.budb_volumeList_val[i].name);
2151 } else { /* BUDB_DUMP_ADSM */
2152 /* dump was from butc to ADSM, use butc names */
2153 strcpy(dumpIdStr, butcdumpIdStr);
2154 sprintf(volumeNameStr, "/%d", dumpid);
2155 strcat(volumeNameStr, "/");
2156 strcat(volumeNameStr, (char *)vl.budb_volumeList_val[i].name);
2159 rc = xbsa_DeleteObject(&butxInfo, dumpIdStr, volumeNameStr);
2160 if (rc != XBSA_SUCCESS) {
2161 ErrorLog(0, taskId, rc, 0,
2162 "Unable to delete the object %s of dump %s from the server\n",
2163 volumeNameStr, dumpIdStr);
2164 /* Don't exit if volume was not found */
2165 if (rc != BUTX_DELETENOVOL) {
2173 "Deleted volume %s (%u) in dumpID %u from the backup server\n",
2174 vl.budb_volumeList_val[i].name,
2175 vl.budb_volumeList_val[i].id, dumpid);
2179 /* free the memory allocated by RPC for this list */
2180 if (vl.budb_volumeList_val)
2181 free(vl.budb_volumeList_val);
2182 vl.budb_volumeList_len = 0;
2183 vl.budb_volumeList_val = 0;
2188 rc = xbsa_EndTrans(&butxInfo);
2189 if (rc != XBSA_SUCCESS) {
2190 ErrorLog(0, taskId, rc, 0,
2191 "Unable to terminate the current transaction\n");
2192 setStatus(taskId, TASK_ERROR);
2197 /* Switch back to the original server */
2198 rc = InitToServer(taskId, &butxInfo, NULL);
2200 if (vl.budb_volumeList_val)
2201 free(vl.budb_volumeList_val);
2203 setStatus(taskId, TASK_DONE);
2204 FreeNode(taskId); /* free the dump node */
2205 LeaveDeviceQueue(deviceLatch);
2207 /* If we don't find any dumps on the server, rather than returning
2208 * a success, return a failure.
2210 if (!code && onenotfound && allnotfound) {
2211 code = BUTX_DELETENOVOL;
2212 setStatus(taskId, TASK_ERROR);