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;
51 struct rx_connection *tconn;
54 char name[MAXKTCNAMELEN];
55 char inst[MAXKTCNAMELEN];
56 char celn[MAXKTCREALMLEN];
62 /* before this code can be used, the rx connection, on the bucoord side, must */
63 /* be changed so that it will set up for token passing instead of using a */
64 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
68 /* -------------------------
69 * butc - interface routines - alphabetic order
70 * -------------------------
74 STC_LabelTape(acid, label, taskId)
76 struct tc_tapeLabel *label;
79 #ifdef AFS_PTHREAD_ENV
86 struct tc_tapeLabel *mylabel;
87 struct labelTapeIf *ptr;
91 extern int Labeller();
92 extern statusP createStatusNode();
93 extern afs_int32 allocTaskId();
97 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
100 if (callPermitted(acid) == 0)
101 return (TC_NOTPERMITTED);
103 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
105 ERROR_EXIT(TC_NOMEMORY);
106 memcpy(&ptr->label, label, sizeof(ptr->label));
108 /* set up the status node */
109 *taskId = allocTaskId(); /* for bucoord */
110 ptr->taskId = *taskId;
112 statusPtr = createStatusNode();
114 ERROR_EXIT(TC_INTERNALERROR);
117 statusPtr->taskId = *taskId;
118 statusPtr->lastPolled = time(0);
119 statusPtr->flags &= ~STARTING; /* ok to examine */
120 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
123 /* create the LWP to do the real work behind the scenes */
124 #ifdef AFS_PTHREAD_ENV
125 code = pthread_attr_init(&tattr);
129 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
134 code = pthread_create(&pid, &tattr, Labeller, ptr);
135 AFS_SIGSET_RESTORE();
138 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
145 deleteStatusNode(statusPtr);
154 * Tape coordinator server routine to do a dump
158 STC_PerformDump(rxCallId, tcdiPtr, tc_dumpArrayPtr, taskId)
159 struct rx_call *rxCallId;
160 struct tc_dumpInterface *tcdiPtr;
161 tc_dumpArray *tc_dumpArrayPtr;
164 struct dumpNode *newNode = 0;
165 statusP statusPtr = 0;
166 #ifdef AFS_PTHREAD_ENV
168 pthread_attr_t tattr;
175 extern statusP createStatusNode();
178 if (callPermitted(rxCallId) == 0)
179 return (TC_NOTPERMITTED);
181 /* should be verifying parameter validity */
184 /* this creates a node in list, alots an id for it and prepares it for locking */
185 CreateNode(&newNode);
187 /*set up the parameters in the node, to be used by LWP */
188 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
190 newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
191 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
193 newNode->volumeSetName =
194 (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
195 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
197 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
199 newNode->dumps = (struct tc_dumpDesc *)
200 malloc(sizeof(struct tc_dumpDesc) *
201 tc_dumpArrayPtr->tc_dumpArray_len);
202 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
203 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
205 newNode->parent = tcdiPtr->parentDumpId;
206 newNode->level = tcdiPtr->dumpLevel;
207 newNode->doAppend = tcdiPtr->doAppend;
210 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
213 /* create the status node */
214 statusPtr = createStatusNode();
216 ERROR_EXIT(TC_INTERNALERROR);
219 statusPtr->taskId = newNode->taskID;
220 statusPtr->lastPolled = time(0);
221 statusPtr->flags &= ~STARTING; /* ok to examine */
222 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
225 newNode->statusNodePtr = statusPtr;
227 /* create the LWP to do the real work behind the scenes */
228 #ifdef AFS_PTHREAD_ENV
229 code = pthread_attr_init(&tattr);
233 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
238 code = pthread_create(&pid, &tattr, Dumper, newNode);
239 AFS_SIGSET_RESTORE();
242 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
248 *taskId = newNode->taskID;
253 deleteStatusNode(statusPtr);
254 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
261 STC_PerformRestore(acid, dumpSetName, arestores, taskID)
262 struct rx_call *acid;
263 char *dumpSetName; /* not used */
264 tc_restoreArray *arestores;
267 struct dumpNode *newNode;
270 #ifdef AFS_PTHREAD_ENV
272 pthread_attr_t tattr;
278 extern int Restorer();
279 extern statusP createStatusNode();
281 if (callPermitted(acid) == 0)
282 return (TC_NOTPERMITTED);
284 /* should verify parameter validity */
286 /* this creates a node in list, alots an id for it and prepares it for locking */
287 CreateNode(&newNode);
289 newNode->restores = (struct tc_restoreDesc *)
290 malloc(sizeof(struct tc_restoreDesc) *
291 arestores->tc_restoreArray_len);
292 newNode->arraySize = arestores->tc_restoreArray_len;
293 CopyRestoreDesc(newNode->restores, arestores);
294 *taskID = newNode->taskID;
296 /* should log the intent */
298 /* create the status node */
299 statusPtr = createStatusNode();
301 ERROR_EXIT(TC_INTERNALERROR);
304 statusPtr->taskId = newNode->taskID;
305 statusPtr->flags &= ~STARTING; /* ok to examine */
306 statusPtr->lastPolled = time(0);
307 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
310 newNode->statusNodePtr = statusPtr;
312 /* create the LWP to do the real work behind the scenes */
313 #ifdef AFS_PTHREAD_ENV
314 code = pthread_attr_init(&tattr);
318 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
323 code = pthread_create(&pid, &tattr, Restorer, newNode);
324 AFS_SIGSET_RESTORE();
327 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
328 "restorer process", &pid);
334 deleteStatusNode(statusPtr);
335 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
342 STC_ReadLabel(acid, label, taskId)
343 struct rx_call *acid;
344 struct tc_tapeLabel *label;
349 extern int ReadLabel();
353 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
356 if (callPermitted(acid) == 0)
357 return (TC_NOTPERMITTED);
359 code = ReadLabel(label); /* Synchronous */
364 * restore the backup database from tape
368 STC_RestoreDb(rxCall, taskId)
369 struct rx_call *rxCall;
372 #ifdef AFS_PTHREAD_ENV
374 pthread_attr_t tattr;
382 extern afs_int32 restoreDbFromTape();
383 extern statusP createStatusNode();
384 extern afs_int32 allocTaskId();
388 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
391 if (callPermitted(rxCall) == 0)
392 return (TC_NOTPERMITTED);
394 *taskId = allocTaskId();
396 /* create the status node */
397 statusPtr = createStatusNode();
399 ERROR_EXIT(TC_INTERNALERROR);
402 statusPtr->taskId = *taskId;
403 statusPtr->flags &= ~STARTING; /* ok to examine */
404 statusPtr->lastPolled = time(0);
405 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
408 #ifdef AFS_PTHREAD_ENV
409 code = pthread_attr_init(&tattr);
413 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
418 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
419 AFS_SIGSET_RESTORE();
422 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
429 deleteStatusNode(statusPtr);
436 * restore the backup database from tape
440 STC_SaveDb(rxCall, archiveTime, taskId)
441 struct rx_call *rxCall;
445 #ifdef AFS_PTHREAD_ENV
447 pthread_attr_t tattr;
454 struct saveDbIf *ptr;
456 extern afs_int32 saveDbToTape();
457 extern statusP createStatusNode();
458 extern afs_int32 allocTaskId();
462 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
465 if (callPermitted(rxCall) == 0)
466 return (TC_NOTPERMITTED);
468 *taskId = allocTaskId();
470 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
472 ERROR_EXIT(TC_NOMEMORY);
473 ptr->archiveTime = archiveTime;
474 ptr->taskId = *taskId;
476 /* create the status node */
477 statusPtr = createStatusNode();
479 ERROR_EXIT(TC_INTERNALERROR);
482 statusPtr->taskId = *taskId;
483 statusPtr->lastPolled = time(0);
484 statusPtr->flags &= ~STARTING; /* ok to examine */
485 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
488 ptr->statusPtr = statusPtr;
490 #ifdef AFS_PTHREAD_ENV
491 code = pthread_attr_init(&tattr);
495 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
500 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
501 AFS_SIGSET_RESTORE();
503 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
509 deleteStatusNode(statusPtr);
519 * read a dump (maybe more than one tape), and print out a summary
520 * of its contents. If the flag is set, add to the database.
522 * addDbFlag - if set, the information will be added to the database
526 STC_ScanDumps(acid, addDbFlag, taskId)
527 struct rx_call *acid;
531 #ifdef AFS_PTHREAD_ENV
533 pthread_attr_t tattr;
538 struct scanTapeIf *ptr;
542 extern afs_int32 ScanDumps();
543 extern afs_int32 allocTaskId();
544 extern statusP createStatusNode();
548 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
551 if (callPermitted(acid) == 0)
552 return (TC_NOTPERMITTED);
554 *taskId = allocTaskId();
556 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
558 ERROR_EXIT(TC_NOMEMORY);
559 ptr->addDbFlag = addDbFlag;
560 ptr->taskId = *taskId;
562 /* create the status node */
563 statusPtr = createStatusNode();
565 ERROR_EXIT(TC_INTERNALERROR);
568 statusPtr->taskId = *taskId;
569 statusPtr->lastPolled = time(0);
570 statusPtr->flags &= ~STARTING; /* ok to examine */
571 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
574 #ifdef AFS_PTHREAD_ENV
575 code = pthread_attr_init(&tattr);
579 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
584 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
585 AFS_SIGSET_RESTORE();
588 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
594 deleteStatusNode(statusPtr);
603 * return information about the tape coordinator. Currently this
604 * is just the version number of the interface
608 STC_TCInfo(acid, tciptr)
609 struct rx_call *acid;
610 struct tc_tcInfo *tciptr;
612 if (callPermitted(acid) == 0)
613 return (TC_NOTPERMITTED);
615 tciptr->tcVersion = CUR_BUTC_VERSION;
622 STC_DeleteDump(acid, dumpID, taskId)
623 struct rx_call *acid;
627 struct deleteDumpIf *ptr = 0;
628 statusP statusPtr = 0;
629 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
630 #ifdef AFS_PTHREAD_ENV
632 pthread_attr_t tattr;
637 extern afs_int32 DeleteDump();
638 extern statusP createStatusNode();
639 extern afs_int32 allocTaskId();
643 return (TC_BADTASK); /* Only do if butc is started as XBSA */
647 if (callPermitted(acid) == 0)
648 return (TC_NOTPERMITTED);
650 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
652 ERROR_EXIT(TC_NOMEMORY);
654 *taskId = allocTaskId();
655 ptr->dumpID = dumpID;
656 ptr->taskId = *taskId;
658 statusPtr = createStatusNode();
660 ERROR_EXIT(TC_INTERNALERROR);
663 statusPtr->taskId = *taskId;
664 statusPtr->lastPolled = time(0);
665 statusPtr->flags &= ~STARTING;
666 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
669 #ifdef AFS_PTHREAD_ENV
670 code = pthread_attr_init(&tattr);
674 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
679 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
680 AFS_SIGSET_RESTORE();
683 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
690 deleteStatusNode(statusPtr);
699 /* -----------------------------
701 * -----------------------------
705 CopyDumpDesc(toDump, fromDump)
706 struct tc_dumpDesc *toDump;
707 tc_dumpArray *fromDump;
709 struct tc_dumpDesc *toPtr, *fromPtr;
713 fromPtr = fromDump->tc_dumpArray_val;
714 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
715 toPtr->vid = fromPtr->vid;
716 toPtr->vtype = fromPtr->vtype;
717 toPtr->partition = fromPtr->partition;
718 toPtr->date = fromPtr->date;
719 toPtr->cloneDate = fromPtr->cloneDate;
720 toPtr->hostAddr = fromPtr->hostAddr;
721 strcpy(toPtr->name, fromPtr->name);
730 CopyRestoreDesc(toRestore, fromRestore)
731 struct tc_restoreDesc *toRestore;
732 tc_restoreArray *fromRestore;
734 struct tc_restoreDesc *toPtr, *fromPtr;
738 fromPtr = fromRestore->tc_restoreArray_val;
739 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
740 toPtr->flags = fromPtr->flags;
741 toPtr->position = fromPtr->position;
742 strcpy(toPtr->tapeName, fromPtr->tapeName);
743 toPtr->dbDumpId = fromPtr->dbDumpId;
744 toPtr->initialDumpId = fromPtr->initialDumpId;
745 toPtr->origVid = fromPtr->origVid;
746 toPtr->vid = fromPtr->vid;
747 toPtr->partition = fromPtr->partition;
748 toPtr->dumpLevel = fromPtr->dumpLevel;
749 toPtr->hostAddr = fromPtr->hostAddr;
750 strcpy(toPtr->newName, fromPtr->newName);
751 strcpy(toPtr->oldName, fromPtr->oldName);
760 CopyTapeSetDesc(toPtr, fromPtr)
761 struct tc_tapeSet *toPtr, *fromPtr;
764 toPtr->id = fromPtr->id;
765 toPtr->maxTapes = fromPtr->maxTapes;
766 toPtr->a = fromPtr->a;
767 toPtr->b = fromPtr->b;
768 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
769 strcpy(toPtr->format, fromPtr->format);
771 toPtr->expDate = fromPtr->expDate;
772 toPtr->expType = fromPtr->expType;