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>
31 #include <afs/procmgmt.h>
32 #include <afs/assert.h>
33 #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"
46 callPermitted(struct rx_call *call)
48 /* before this code can be used, the rx connection, on the bucoord side, must */
49 /* be changed so that it will set up for token passing instead of using a */
50 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
54 /* -----------------------------
56 * -----------------------------
60 CopyDumpDesc(struct tc_dumpDesc *toDump, tc_dumpArray *fromDump)
62 struct tc_dumpDesc *toPtr, *fromPtr;
66 fromPtr = fromDump->tc_dumpArray_val;
67 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
68 toPtr->vid = fromPtr->vid;
69 toPtr->vtype = fromPtr->vtype;
70 toPtr->partition = fromPtr->partition;
71 toPtr->date = fromPtr->date;
72 toPtr->cloneDate = fromPtr->cloneDate;
73 toPtr->hostAddr = fromPtr->hostAddr;
74 strcpy(toPtr->name, fromPtr->name);
83 CopyRestoreDesc(struct tc_restoreDesc *toRestore, tc_restoreArray *fromRestore)
85 struct tc_restoreDesc *toPtr, *fromPtr;
89 fromPtr = fromRestore->tc_restoreArray_val;
90 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
91 toPtr->flags = fromPtr->flags;
92 toPtr->position = fromPtr->position;
93 strcpy(toPtr->tapeName, fromPtr->tapeName);
94 toPtr->dbDumpId = fromPtr->dbDumpId;
95 toPtr->initialDumpId = fromPtr->initialDumpId;
96 toPtr->origVid = fromPtr->origVid;
97 toPtr->vid = fromPtr->vid;
98 toPtr->partition = fromPtr->partition;
99 toPtr->dumpLevel = fromPtr->dumpLevel;
100 toPtr->hostAddr = fromPtr->hostAddr;
101 strcpy(toPtr->newName, fromPtr->newName);
102 strcpy(toPtr->oldName, fromPtr->oldName);
111 CopyTapeSetDesc(struct tc_tapeSet *toPtr, struct tc_tapeSet *fromPtr)
114 toPtr->id = fromPtr->id;
115 toPtr->maxTapes = fromPtr->maxTapes;
116 toPtr->a = fromPtr->a;
117 toPtr->b = fromPtr->b;
118 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
119 strcpy(toPtr->format, fromPtr->format);
121 toPtr->expDate = fromPtr->expDate;
122 toPtr->expType = fromPtr->expType;
126 /* -------------------------
127 * butc - interface routines - alphabetic order
128 * -------------------------
132 STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
134 #ifdef AFS_PTHREAD_ENV
136 pthread_attr_t tattr;
141 struct labelTapeIf *ptr;
145 extern int Labeller();
146 extern statusP createStatusNode();
147 extern afs_int32 allocTaskId();
151 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
154 if (callPermitted(acid) == 0)
155 return (TC_NOTPERMITTED);
157 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
159 ERROR_EXIT(TC_NOMEMORY);
160 memcpy(&ptr->label, label, sizeof(ptr->label));
162 /* set up the status node */
163 *taskId = allocTaskId(); /* for bucoord */
164 ptr->taskId = *taskId;
166 statusPtr = createStatusNode();
168 ERROR_EXIT(TC_INTERNALERROR);
171 statusPtr->taskId = *taskId;
172 statusPtr->lastPolled = time(0);
173 statusPtr->flags &= ~STARTING; /* ok to examine */
174 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
177 /* create the LWP to do the real work behind the scenes */
178 #ifdef AFS_PTHREAD_ENV
179 code = pthread_attr_init(&tattr);
183 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
188 code = pthread_create(&pid, &tattr, Labeller, ptr);
189 AFS_SIGSET_RESTORE();
192 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
199 deleteStatusNode(statusPtr);
208 * Tape coordinator server routine to do a dump
212 STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_dumpArray *tc_dumpArrayPtr, afs_int32 *taskId)
214 struct dumpNode *newNode = 0;
215 statusP statusPtr = 0;
216 #ifdef AFS_PTHREAD_ENV
218 pthread_attr_t tattr;
225 extern statusP createStatusNode();
228 if (callPermitted(rxCallId) == 0)
229 return (TC_NOTPERMITTED);
231 /* should be verifying parameter validity */
234 /* this creates a node in list, alots an id for it and prepares it for locking */
235 CreateNode(&newNode);
237 /*set up the parameters in the node, to be used by LWP */
238 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
240 newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
241 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
243 newNode->volumeSetName =
244 (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
245 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
247 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
249 newNode->dumps = (struct tc_dumpDesc *)
250 malloc(sizeof(struct tc_dumpDesc) *
251 tc_dumpArrayPtr->tc_dumpArray_len);
252 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
253 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
255 newNode->parent = tcdiPtr->parentDumpId;
256 newNode->level = tcdiPtr->dumpLevel;
257 newNode->doAppend = tcdiPtr->doAppend;
260 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
263 /* create the status node */
264 statusPtr = createStatusNode();
266 ERROR_EXIT(TC_INTERNALERROR);
269 statusPtr->taskId = newNode->taskID;
270 statusPtr->lastPolled = time(0);
271 statusPtr->flags &= ~STARTING; /* ok to examine */
272 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
275 newNode->statusNodePtr = statusPtr;
277 /* create the LWP to do the real work behind the scenes */
278 #ifdef AFS_PTHREAD_ENV
279 code = pthread_attr_init(&tattr);
283 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
288 code = pthread_create(&pid, &tattr, Dumper, newNode);
289 AFS_SIGSET_RESTORE();
292 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
298 *taskId = newNode->taskID;
303 deleteStatusNode(statusPtr);
304 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
311 STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *arestores, afs_int32 *taskID)
313 struct dumpNode *newNode;
316 #ifdef AFS_PTHREAD_ENV
318 pthread_attr_t tattr;
324 extern int Restorer();
325 extern statusP createStatusNode();
327 if (callPermitted(acid) == 0)
328 return (TC_NOTPERMITTED);
330 /* should verify parameter validity */
332 /* this creates a node in list, alots an id for it and prepares it for locking */
333 CreateNode(&newNode);
335 newNode->restores = (struct tc_restoreDesc *)
336 malloc(sizeof(struct tc_restoreDesc) *
337 arestores->tc_restoreArray_len);
338 newNode->arraySize = arestores->tc_restoreArray_len;
339 CopyRestoreDesc(newNode->restores, arestores);
340 *taskID = newNode->taskID;
342 /* should log the intent */
344 /* create the status node */
345 statusPtr = createStatusNode();
347 ERROR_EXIT(TC_INTERNALERROR);
350 statusPtr->taskId = newNode->taskID;
351 statusPtr->flags &= ~STARTING; /* ok to examine */
352 statusPtr->lastPolled = time(0);
353 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
356 newNode->statusNodePtr = statusPtr;
358 /* create the LWP to do the real work behind the scenes */
359 #ifdef AFS_PTHREAD_ENV
360 code = pthread_attr_init(&tattr);
364 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
369 code = pthread_create(&pid, &tattr, Restorer, newNode);
370 AFS_SIGSET_RESTORE();
373 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
374 "restorer process", &pid);
380 deleteStatusNode(statusPtr);
381 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
388 STC_ReadLabel(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
392 extern int ReadLabel();
396 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
399 if (callPermitted(acid) == 0)
400 return (TC_NOTPERMITTED);
402 code = ReadLabel(label); /* Synchronous */
407 * restore the backup database from tape
411 STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
413 #ifdef AFS_PTHREAD_ENV
415 pthread_attr_t tattr;
423 extern afs_int32 restoreDbFromTape();
424 extern statusP createStatusNode();
425 extern afs_int32 allocTaskId();
429 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
432 if (callPermitted(rxCall) == 0)
433 return (TC_NOTPERMITTED);
435 *taskId = allocTaskId();
437 /* create the status node */
438 statusPtr = createStatusNode();
440 ERROR_EXIT(TC_INTERNALERROR);
443 statusPtr->taskId = *taskId;
444 statusPtr->flags &= ~STARTING; /* ok to examine */
445 statusPtr->lastPolled = time(0);
446 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
449 #ifdef AFS_PTHREAD_ENV
450 code = pthread_attr_init(&tattr);
454 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
459 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
460 AFS_SIGSET_RESTORE();
463 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
470 deleteStatusNode(statusPtr);
477 * restore the backup database from tape
481 STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
483 #ifdef AFS_PTHREAD_ENV
485 pthread_attr_t tattr;
492 struct saveDbIf *ptr;
494 extern afs_int32 saveDbToTape();
495 extern statusP createStatusNode();
496 extern afs_int32 allocTaskId();
500 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
503 if (callPermitted(rxCall) == 0)
504 return (TC_NOTPERMITTED);
506 *taskId = allocTaskId();
508 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
510 ERROR_EXIT(TC_NOMEMORY);
511 ptr->archiveTime = archiveTime;
512 ptr->taskId = *taskId;
514 /* create the status node */
515 statusPtr = createStatusNode();
517 ERROR_EXIT(TC_INTERNALERROR);
520 statusPtr->taskId = *taskId;
521 statusPtr->lastPolled = time(0);
522 statusPtr->flags &= ~STARTING; /* ok to examine */
523 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
526 ptr->statusPtr = statusPtr;
528 #ifdef AFS_PTHREAD_ENV
529 code = pthread_attr_init(&tattr);
533 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
538 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
539 AFS_SIGSET_RESTORE();
541 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
547 deleteStatusNode(statusPtr);
557 * read a dump (maybe more than one tape), and print out a summary
558 * of its contents. If the flag is set, add to the database.
560 * addDbFlag - if set, the information will be added to the database
564 STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
566 #ifdef AFS_PTHREAD_ENV
568 pthread_attr_t tattr;
573 struct scanTapeIf *ptr;
577 extern afs_int32 ScanDumps();
578 extern afs_int32 allocTaskId();
579 extern statusP createStatusNode();
583 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
586 if (callPermitted(acid) == 0)
587 return (TC_NOTPERMITTED);
589 *taskId = allocTaskId();
591 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
593 ERROR_EXIT(TC_NOMEMORY);
594 ptr->addDbFlag = addDbFlag;
595 ptr->taskId = *taskId;
597 /* create the status node */
598 statusPtr = createStatusNode();
600 ERROR_EXIT(TC_INTERNALERROR);
603 statusPtr->taskId = *taskId;
604 statusPtr->lastPolled = time(0);
605 statusPtr->flags &= ~STARTING; /* ok to examine */
606 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
609 #ifdef AFS_PTHREAD_ENV
610 code = pthread_attr_init(&tattr);
614 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
619 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
620 AFS_SIGSET_RESTORE();
623 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
629 deleteStatusNode(statusPtr);
638 * return information about the tape coordinator. Currently this
639 * is just the version number of the interface
643 STC_TCInfo(struct rx_call *acid, struct tc_tcInfo *tciptr)
645 if (callPermitted(acid) == 0)
646 return (TC_NOTPERMITTED);
648 tciptr->tcVersion = CUR_BUTC_VERSION;
655 STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
657 struct deleteDumpIf *ptr = 0;
658 statusP statusPtr = 0;
659 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
661 #ifdef AFS_PTHREAD_ENV
663 pthread_attr_t tattr;
669 extern afs_int32 DeleteDump();
670 extern statusP createStatusNode();
671 extern afs_int32 allocTaskId();
675 return (TC_BADTASK); /* Only do if butc is started as XBSA */
679 if (callPermitted(acid) == 0)
680 return (TC_NOTPERMITTED);
682 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
684 ERROR_EXIT(TC_NOMEMORY);
686 *taskId = allocTaskId();
687 ptr->dumpID = dumpID;
688 ptr->taskId = *taskId;
690 statusPtr = createStatusNode();
692 ERROR_EXIT(TC_INTERNALERROR);
695 statusPtr->taskId = *taskId;
696 statusPtr->lastPolled = time(0);
697 statusPtr->flags &= ~STARTING;
698 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
701 #ifdef AFS_PTHREAD_ENV
702 code = pthread_attr_init(&tattr);
706 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
711 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
712 AFS_SIGSET_RESTORE();
715 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
722 deleteStatusNode(statusPtr);