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 /* procedures invoked by the rpc stub */
12 #include <afsconfig.h>
13 #include <afs/param.h>
18 #include <sys/types.h>
24 #include <netinet/in.h>
28 #include <afs/afsint.h>
30 #include <afs/procmgmt.h>
31 #include <afs/assert.h>
32 #include <afs/prs_fs.h>
38 #include <afs/cellconfig.h>
41 #include <afs/tcdata.h>
42 #include "error_macros.h"
43 #include "butc_xbsa.h"
44 extern afs_int32 xbsaType;
49 /* before this code can be used, the rx connection, on the bucoord side, must */
50 /* be changed so that it will set up for token passing instead of using a */
51 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
55 /* -------------------------
56 * butc - interface routines - alphabetic order
57 * -------------------------
61 STC_LabelTape(acid, label, taskId)
63 struct tc_tapeLabel *label;
66 #ifdef AFS_PTHREAD_ENV
73 struct labelTapeIf *ptr;
77 extern int Labeller();
78 extern statusP createStatusNode();
79 extern afs_int32 allocTaskId();
83 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
86 if (callPermitted(acid) == 0)
87 return (TC_NOTPERMITTED);
89 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
91 ERROR_EXIT(TC_NOMEMORY);
92 memcpy(&ptr->label, label, sizeof(ptr->label));
94 /* set up the status node */
95 *taskId = allocTaskId(); /* for bucoord */
96 ptr->taskId = *taskId;
98 statusPtr = createStatusNode();
100 ERROR_EXIT(TC_INTERNALERROR);
103 statusPtr->taskId = *taskId;
104 statusPtr->lastPolled = time(0);
105 statusPtr->flags &= ~STARTING; /* ok to examine */
106 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
109 /* create the LWP to do the real work behind the scenes */
110 #ifdef AFS_PTHREAD_ENV
111 code = pthread_attr_init(&tattr);
115 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
120 code = pthread_create(&pid, &tattr, Labeller, ptr);
121 AFS_SIGSET_RESTORE();
124 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
131 deleteStatusNode(statusPtr);
140 * Tape coordinator server routine to do a dump
144 STC_PerformDump(rxCallId, tcdiPtr, tc_dumpArrayPtr, taskId)
145 struct rx_call *rxCallId;
146 struct tc_dumpInterface *tcdiPtr;
147 tc_dumpArray *tc_dumpArrayPtr;
150 struct dumpNode *newNode = 0;
151 statusP statusPtr = 0;
152 #ifdef AFS_PTHREAD_ENV
154 pthread_attr_t tattr;
161 extern statusP createStatusNode();
164 if (callPermitted(rxCallId) == 0)
165 return (TC_NOTPERMITTED);
167 /* should be verifying parameter validity */
170 /* this creates a node in list, alots an id for it and prepares it for locking */
171 CreateNode(&newNode);
173 /*set up the parameters in the node, to be used by LWP */
174 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
176 newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
177 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
179 newNode->volumeSetName =
180 (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
181 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
183 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
185 newNode->dumps = (struct tc_dumpDesc *)
186 malloc(sizeof(struct tc_dumpDesc) *
187 tc_dumpArrayPtr->tc_dumpArray_len);
188 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
189 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
191 newNode->parent = tcdiPtr->parentDumpId;
192 newNode->level = tcdiPtr->dumpLevel;
193 newNode->doAppend = tcdiPtr->doAppend;
196 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
199 /* create the status node */
200 statusPtr = createStatusNode();
202 ERROR_EXIT(TC_INTERNALERROR);
205 statusPtr->taskId = newNode->taskID;
206 statusPtr->lastPolled = time(0);
207 statusPtr->flags &= ~STARTING; /* ok to examine */
208 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
211 newNode->statusNodePtr = statusPtr;
213 /* create the LWP to do the real work behind the scenes */
214 #ifdef AFS_PTHREAD_ENV
215 code = pthread_attr_init(&tattr);
219 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
224 code = pthread_create(&pid, &tattr, Dumper, newNode);
225 AFS_SIGSET_RESTORE();
228 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
234 *taskId = newNode->taskID;
239 deleteStatusNode(statusPtr);
240 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
247 STC_PerformRestore(acid, dumpSetName, arestores, taskID)
248 struct rx_call *acid;
249 char *dumpSetName; /* not used */
250 tc_restoreArray *arestores;
253 struct dumpNode *newNode;
256 #ifdef AFS_PTHREAD_ENV
258 pthread_attr_t tattr;
264 extern int Restorer();
265 extern statusP createStatusNode();
267 if (callPermitted(acid) == 0)
268 return (TC_NOTPERMITTED);
270 /* should verify parameter validity */
272 /* this creates a node in list, alots an id for it and prepares it for locking */
273 CreateNode(&newNode);
275 newNode->restores = (struct tc_restoreDesc *)
276 malloc(sizeof(struct tc_restoreDesc) *
277 arestores->tc_restoreArray_len);
278 newNode->arraySize = arestores->tc_restoreArray_len;
279 CopyRestoreDesc(newNode->restores, arestores);
280 *taskID = newNode->taskID;
282 /* should log the intent */
284 /* create the status node */
285 statusPtr = createStatusNode();
287 ERROR_EXIT(TC_INTERNALERROR);
290 statusPtr->taskId = newNode->taskID;
291 statusPtr->flags &= ~STARTING; /* ok to examine */
292 statusPtr->lastPolled = time(0);
293 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
296 newNode->statusNodePtr = statusPtr;
298 /* create the LWP to do the real work behind the scenes */
299 #ifdef AFS_PTHREAD_ENV
300 code = pthread_attr_init(&tattr);
304 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
309 code = pthread_create(&pid, &tattr, Restorer, newNode);
310 AFS_SIGSET_RESTORE();
313 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
314 "restorer process", &pid);
320 deleteStatusNode(statusPtr);
321 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
328 STC_ReadLabel(acid, label, taskId)
329 struct rx_call *acid;
330 struct tc_tapeLabel *label;
335 extern int ReadLabel();
339 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
342 if (callPermitted(acid) == 0)
343 return (TC_NOTPERMITTED);
345 code = ReadLabel(label); /* Synchronous */
350 * restore the backup database from tape
354 STC_RestoreDb(rxCall, taskId)
355 struct rx_call *rxCall;
358 #ifdef AFS_PTHREAD_ENV
360 pthread_attr_t tattr;
368 extern afs_int32 restoreDbFromTape();
369 extern statusP createStatusNode();
370 extern afs_int32 allocTaskId();
374 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
377 if (callPermitted(rxCall) == 0)
378 return (TC_NOTPERMITTED);
380 *taskId = allocTaskId();
382 /* create the status node */
383 statusPtr = createStatusNode();
385 ERROR_EXIT(TC_INTERNALERROR);
388 statusPtr->taskId = *taskId;
389 statusPtr->flags &= ~STARTING; /* ok to examine */
390 statusPtr->lastPolled = time(0);
391 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
394 #ifdef AFS_PTHREAD_ENV
395 code = pthread_attr_init(&tattr);
399 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
404 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
405 AFS_SIGSET_RESTORE();
408 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
415 deleteStatusNode(statusPtr);
422 * restore the backup database from tape
426 STC_SaveDb(rxCall, archiveTime, taskId)
427 struct rx_call *rxCall;
431 #ifdef AFS_PTHREAD_ENV
433 pthread_attr_t tattr;
440 struct saveDbIf *ptr;
442 extern afs_int32 saveDbToTape();
443 extern statusP createStatusNode();
444 extern afs_int32 allocTaskId();
448 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
451 if (callPermitted(rxCall) == 0)
452 return (TC_NOTPERMITTED);
454 *taskId = allocTaskId();
456 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
458 ERROR_EXIT(TC_NOMEMORY);
459 ptr->archiveTime = archiveTime;
460 ptr->taskId = *taskId;
462 /* create the status node */
463 statusPtr = createStatusNode();
465 ERROR_EXIT(TC_INTERNALERROR);
468 statusPtr->taskId = *taskId;
469 statusPtr->lastPolled = time(0);
470 statusPtr->flags &= ~STARTING; /* ok to examine */
471 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
474 ptr->statusPtr = statusPtr;
476 #ifdef AFS_PTHREAD_ENV
477 code = pthread_attr_init(&tattr);
481 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
486 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
487 AFS_SIGSET_RESTORE();
489 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
495 deleteStatusNode(statusPtr);
505 * read a dump (maybe more than one tape), and print out a summary
506 * of its contents. If the flag is set, add to the database.
508 * addDbFlag - if set, the information will be added to the database
512 STC_ScanDumps(acid, addDbFlag, taskId)
513 struct rx_call *acid;
517 #ifdef AFS_PTHREAD_ENV
519 pthread_attr_t tattr;
524 struct scanTapeIf *ptr;
528 extern afs_int32 ScanDumps();
529 extern afs_int32 allocTaskId();
530 extern statusP createStatusNode();
534 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
537 if (callPermitted(acid) == 0)
538 return (TC_NOTPERMITTED);
540 *taskId = allocTaskId();
542 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
544 ERROR_EXIT(TC_NOMEMORY);
545 ptr->addDbFlag = addDbFlag;
546 ptr->taskId = *taskId;
548 /* create the status node */
549 statusPtr = createStatusNode();
551 ERROR_EXIT(TC_INTERNALERROR);
554 statusPtr->taskId = *taskId;
555 statusPtr->lastPolled = time(0);
556 statusPtr->flags &= ~STARTING; /* ok to examine */
557 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
560 #ifdef AFS_PTHREAD_ENV
561 code = pthread_attr_init(&tattr);
565 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
570 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
571 AFS_SIGSET_RESTORE();
574 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
580 deleteStatusNode(statusPtr);
589 * return information about the tape coordinator. Currently this
590 * is just the version number of the interface
594 STC_TCInfo(acid, tciptr)
595 struct rx_call *acid;
596 struct tc_tcInfo *tciptr;
598 if (callPermitted(acid) == 0)
599 return (TC_NOTPERMITTED);
601 tciptr->tcVersion = CUR_BUTC_VERSION;
608 STC_DeleteDump(acid, dumpID, taskId)
609 struct rx_call *acid;
613 struct deleteDumpIf *ptr = 0;
614 statusP statusPtr = 0;
615 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
617 #ifdef AFS_PTHREAD_ENV
619 pthread_attr_t tattr;
625 extern afs_int32 DeleteDump();
626 extern statusP createStatusNode();
627 extern afs_int32 allocTaskId();
631 return (TC_BADTASK); /* Only do if butc is started as XBSA */
635 if (callPermitted(acid) == 0)
636 return (TC_NOTPERMITTED);
638 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
640 ERROR_EXIT(TC_NOMEMORY);
642 *taskId = allocTaskId();
643 ptr->dumpID = dumpID;
644 ptr->taskId = *taskId;
646 statusPtr = createStatusNode();
648 ERROR_EXIT(TC_INTERNALERROR);
651 statusPtr->taskId = *taskId;
652 statusPtr->lastPolled = time(0);
653 statusPtr->flags &= ~STARTING;
654 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
657 #ifdef AFS_PTHREAD_ENV
658 code = pthread_attr_init(&tattr);
662 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
667 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
668 AFS_SIGSET_RESTORE();
671 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
678 deleteStatusNode(statusPtr);
687 /* -----------------------------
689 * -----------------------------
693 CopyDumpDesc(toDump, fromDump)
694 struct tc_dumpDesc *toDump;
695 tc_dumpArray *fromDump;
697 struct tc_dumpDesc *toPtr, *fromPtr;
701 fromPtr = fromDump->tc_dumpArray_val;
702 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
703 toPtr->vid = fromPtr->vid;
704 toPtr->vtype = fromPtr->vtype;
705 toPtr->partition = fromPtr->partition;
706 toPtr->date = fromPtr->date;
707 toPtr->cloneDate = fromPtr->cloneDate;
708 toPtr->hostAddr = fromPtr->hostAddr;
709 strcpy(toPtr->name, fromPtr->name);
718 CopyRestoreDesc(toRestore, fromRestore)
719 struct tc_restoreDesc *toRestore;
720 tc_restoreArray *fromRestore;
722 struct tc_restoreDesc *toPtr, *fromPtr;
726 fromPtr = fromRestore->tc_restoreArray_val;
727 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
728 toPtr->flags = fromPtr->flags;
729 toPtr->position = fromPtr->position;
730 strcpy(toPtr->tapeName, fromPtr->tapeName);
731 toPtr->dbDumpId = fromPtr->dbDumpId;
732 toPtr->initialDumpId = fromPtr->initialDumpId;
733 toPtr->origVid = fromPtr->origVid;
734 toPtr->vid = fromPtr->vid;
735 toPtr->partition = fromPtr->partition;
736 toPtr->dumpLevel = fromPtr->dumpLevel;
737 toPtr->hostAddr = fromPtr->hostAddr;
738 strcpy(toPtr->newName, fromPtr->newName);
739 strcpy(toPtr->oldName, fromPtr->oldName);
748 CopyTapeSetDesc(toPtr, fromPtr)
749 struct tc_tapeSet *toPtr, *fromPtr;
752 toPtr->id = fromPtr->id;
753 toPtr->maxTapes = fromPtr->maxTapes;
754 toPtr->a = fromPtr->a;
755 toPtr->b = fromPtr->b;
756 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
757 strcpy(toPtr->format, fromPtr->format);
759 toPtr->expDate = fromPtr->expDate;
760 toPtr->expType = fromPtr->expType;