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"
45 static CopyDumpDesc();
46 static CopyRestoreDesc();
47 static CopyTapeSetDesc();
51 callPermitted(struct rx_call *call)
53 /* before this code can be used, the rx connection, on the bucoord side, must */
54 /* be changed so that it will set up for token passing instead of using a */
55 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
59 /* -----------------------------
61 * -----------------------------
65 CopyDumpDesc(struct tc_dumpDesc *toDump, tc_dumpArray *fromDump)
67 struct tc_dumpDesc *toPtr, *fromPtr;
71 fromPtr = fromDump->tc_dumpArray_val;
72 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
73 toPtr->vid = fromPtr->vid;
74 toPtr->vtype = fromPtr->vtype;
75 toPtr->partition = fromPtr->partition;
76 toPtr->date = fromPtr->date;
77 toPtr->cloneDate = fromPtr->cloneDate;
78 toPtr->hostAddr = fromPtr->hostAddr;
79 strcpy(toPtr->name, fromPtr->name);
88 CopyRestoreDesc(struct tc_restoreDesc *toRestore, tc_restoreArray *fromRestore)
90 struct tc_restoreDesc *toPtr, *fromPtr;
94 fromPtr = fromRestore->tc_restoreArray_val;
95 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
96 toPtr->flags = fromPtr->flags;
97 toPtr->position = fromPtr->position;
98 strcpy(toPtr->tapeName, fromPtr->tapeName);
99 toPtr->dbDumpId = fromPtr->dbDumpId;
100 toPtr->initialDumpId = fromPtr->initialDumpId;
101 toPtr->origVid = fromPtr->origVid;
102 toPtr->vid = fromPtr->vid;
103 toPtr->partition = fromPtr->partition;
104 toPtr->dumpLevel = fromPtr->dumpLevel;
105 toPtr->hostAddr = fromPtr->hostAddr;
106 strcpy(toPtr->newName, fromPtr->newName);
107 strcpy(toPtr->oldName, fromPtr->oldName);
116 CopyTapeSetDesc(struct tc_tapeSet *toPtr, struct tc_tapeSet *fromPtr)
119 toPtr->id = fromPtr->id;
120 toPtr->maxTapes = fromPtr->maxTapes;
121 toPtr->a = fromPtr->a;
122 toPtr->b = fromPtr->b;
123 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
124 strcpy(toPtr->format, fromPtr->format);
126 toPtr->expDate = fromPtr->expDate;
127 toPtr->expType = fromPtr->expType;
131 /* -------------------------
132 * butc - interface routines - alphabetic order
133 * -------------------------
137 STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
139 #ifdef AFS_PTHREAD_ENV
141 pthread_attr_t tattr;
146 struct labelTapeIf *ptr;
147 statusP statusPtr = NULL;
150 extern int Labeller();
151 extern statusP createStatusNode();
152 extern afs_int32 allocTaskId();
156 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
159 if (callPermitted(acid) == 0)
160 return (TC_NOTPERMITTED);
162 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
164 ERROR_EXIT(TC_NOMEMORY);
165 memcpy(&ptr->label, label, sizeof(ptr->label));
167 /* set up the status node */
168 *taskId = allocTaskId(); /* for bucoord */
169 ptr->taskId = *taskId;
171 statusPtr = createStatusNode();
173 ERROR_EXIT(TC_INTERNALERROR);
176 statusPtr->taskId = *taskId;
177 statusPtr->lastPolled = time(0);
178 statusPtr->flags &= ~STARTING; /* ok to examine */
179 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
182 /* create the LWP to do the real work behind the scenes */
183 #ifdef AFS_PTHREAD_ENV
184 code = pthread_attr_init(&tattr);
188 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
193 code = pthread_create(&pid, &tattr, Labeller, ptr);
194 AFS_SIGSET_RESTORE();
197 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
204 deleteStatusNode(statusPtr);
213 * Tape coordinator server routine to do a dump
217 STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_dumpArray *tc_dumpArrayPtr, afs_int32 *taskId)
219 struct dumpNode *newNode = 0;
220 statusP statusPtr = 0;
221 #ifdef AFS_PTHREAD_ENV
223 pthread_attr_t tattr;
230 extern statusP createStatusNode();
233 if (callPermitted(rxCallId) == 0)
234 return (TC_NOTPERMITTED);
236 /* should be verifying parameter validity */
239 /* this creates a node in list, alots an id for it and prepares it for locking */
240 CreateNode(&newNode);
242 /*set up the parameters in the node, to be used by LWP */
243 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
245 newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
246 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
248 newNode->volumeSetName =
249 (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
250 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
252 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
254 newNode->dumps = (struct tc_dumpDesc *)
255 malloc(sizeof(struct tc_dumpDesc) *
256 tc_dumpArrayPtr->tc_dumpArray_len);
257 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
258 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
260 newNode->parent = tcdiPtr->parentDumpId;
261 newNode->level = tcdiPtr->dumpLevel;
262 newNode->doAppend = tcdiPtr->doAppend;
265 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
268 /* create the status node */
269 statusPtr = createStatusNode();
271 ERROR_EXIT(TC_INTERNALERROR);
274 statusPtr->taskId = newNode->taskID;
275 statusPtr->lastPolled = time(0);
276 statusPtr->flags &= ~STARTING; /* ok to examine */
277 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
280 newNode->statusNodePtr = statusPtr;
282 /* create the LWP to do the real work behind the scenes */
283 #ifdef AFS_PTHREAD_ENV
284 code = pthread_attr_init(&tattr);
288 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
293 code = pthread_create(&pid, &tattr, Dumper, newNode);
294 AFS_SIGSET_RESTORE();
297 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
303 *taskId = newNode->taskID;
308 deleteStatusNode(statusPtr);
309 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
316 STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *arestores, afs_int32 *taskID)
318 struct dumpNode *newNode;
321 #ifdef AFS_PTHREAD_ENV
323 pthread_attr_t tattr;
329 extern int Restorer();
330 extern statusP createStatusNode();
332 if (callPermitted(acid) == 0)
333 return (TC_NOTPERMITTED);
335 /* should verify parameter validity */
337 /* this creates a node in list, alots an id for it and prepares it for locking */
338 CreateNode(&newNode);
340 newNode->restores = (struct tc_restoreDesc *)
341 malloc(sizeof(struct tc_restoreDesc) *
342 arestores->tc_restoreArray_len);
343 newNode->arraySize = arestores->tc_restoreArray_len;
344 CopyRestoreDesc(newNode->restores, arestores);
345 *taskID = newNode->taskID;
347 /* should log the intent */
349 /* create the status node */
350 statusPtr = createStatusNode();
352 ERROR_EXIT(TC_INTERNALERROR);
355 statusPtr->taskId = newNode->taskID;
356 statusPtr->flags &= ~STARTING; /* ok to examine */
357 statusPtr->lastPolled = time(0);
358 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
361 newNode->statusNodePtr = statusPtr;
363 /* create the LWP to do the real work behind the scenes */
364 #ifdef AFS_PTHREAD_ENV
365 code = pthread_attr_init(&tattr);
369 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
374 code = pthread_create(&pid, &tattr, Restorer, newNode);
375 AFS_SIGSET_RESTORE();
378 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
379 "restorer process", &pid);
385 deleteStatusNode(statusPtr);
386 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
393 STC_ReadLabel(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
397 extern int ReadLabel();
401 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
404 if (callPermitted(acid) == 0)
405 return (TC_NOTPERMITTED);
407 code = ReadLabel(label); /* Synchronous */
412 * restore the backup database from tape
416 STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
418 #ifdef AFS_PTHREAD_ENV
420 pthread_attr_t tattr;
428 extern afs_int32 restoreDbFromTape();
429 extern statusP createStatusNode();
430 extern afs_int32 allocTaskId();
434 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
437 if (callPermitted(rxCall) == 0)
438 return (TC_NOTPERMITTED);
440 *taskId = allocTaskId();
442 /* create the status node */
443 statusPtr = createStatusNode();
445 ERROR_EXIT(TC_INTERNALERROR);
448 statusPtr->taskId = *taskId;
449 statusPtr->flags &= ~STARTING; /* ok to examine */
450 statusPtr->lastPolled = time(0);
451 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
454 #ifdef AFS_PTHREAD_ENV
455 code = pthread_attr_init(&tattr);
459 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
464 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
465 AFS_SIGSET_RESTORE();
468 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
475 deleteStatusNode(statusPtr);
482 * restore the backup database from tape
486 STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
488 #ifdef AFS_PTHREAD_ENV
490 pthread_attr_t tattr;
495 statusP statusPtr = NULL;
497 struct saveDbIf *ptr;
499 extern afs_int32 saveDbToTape();
500 extern statusP createStatusNode();
501 extern afs_int32 allocTaskId();
505 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
508 if (callPermitted(rxCall) == 0)
509 return (TC_NOTPERMITTED);
511 *taskId = allocTaskId();
513 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
515 ERROR_EXIT(TC_NOMEMORY);
516 ptr->archiveTime = archiveTime;
517 ptr->taskId = *taskId;
519 /* create the status node */
520 statusPtr = createStatusNode();
522 ERROR_EXIT(TC_INTERNALERROR);
525 statusPtr->taskId = *taskId;
526 statusPtr->lastPolled = time(0);
527 statusPtr->flags &= ~STARTING; /* ok to examine */
528 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
531 ptr->statusPtr = statusPtr;
533 #ifdef AFS_PTHREAD_ENV
534 code = pthread_attr_init(&tattr);
538 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
543 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
544 AFS_SIGSET_RESTORE();
546 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
552 deleteStatusNode(statusPtr);
562 * read a dump (maybe more than one tape), and print out a summary
563 * of its contents. If the flag is set, add to the database.
565 * addDbFlag - if set, the information will be added to the database
569 STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
571 #ifdef AFS_PTHREAD_ENV
573 pthread_attr_t tattr;
578 struct scanTapeIf *ptr;
582 extern afs_int32 ScanDumps();
583 extern afs_int32 allocTaskId();
584 extern statusP createStatusNode();
588 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
591 if (callPermitted(acid) == 0)
592 return (TC_NOTPERMITTED);
594 *taskId = allocTaskId();
596 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
598 ERROR_EXIT(TC_NOMEMORY);
599 ptr->addDbFlag = addDbFlag;
600 ptr->taskId = *taskId;
602 /* create the status node */
603 statusPtr = createStatusNode();
605 ERROR_EXIT(TC_INTERNALERROR);
608 statusPtr->taskId = *taskId;
609 statusPtr->lastPolled = time(0);
610 statusPtr->flags &= ~STARTING; /* ok to examine */
611 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
614 #ifdef AFS_PTHREAD_ENV
615 code = pthread_attr_init(&tattr);
619 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
624 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
625 AFS_SIGSET_RESTORE();
628 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
634 deleteStatusNode(statusPtr);
643 * return information about the tape coordinator. Currently this
644 * is just the version number of the interface
648 STC_TCInfo(struct rx_call *acid, struct tc_tcInfo *tciptr)
650 if (callPermitted(acid) == 0)
651 return (TC_NOTPERMITTED);
653 tciptr->tcVersion = CUR_BUTC_VERSION;
660 STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
662 struct deleteDumpIf *ptr = 0;
663 statusP statusPtr = 0;
664 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
666 #ifdef AFS_PTHREAD_ENV
668 pthread_attr_t tattr;
674 extern afs_int32 DeleteDump();
675 extern statusP createStatusNode();
676 extern afs_int32 allocTaskId();
680 return (TC_BADTASK); /* Only do if butc is started as XBSA */
684 if (callPermitted(acid) == 0)
685 return (TC_NOTPERMITTED);
687 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
689 ERROR_EXIT(TC_NOMEMORY);
691 *taskId = allocTaskId();
692 ptr->dumpID = dumpID;
693 ptr->taskId = *taskId;
695 statusPtr = createStatusNode();
697 ERROR_EXIT(TC_INTERNALERROR);
700 statusPtr->taskId = *taskId;
701 statusPtr->lastPolled = time(0);
702 statusPtr->flags &= ~STARTING;
703 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
706 #ifdef AFS_PTHREAD_ENV
707 code = pthread_attr_init(&tattr);
711 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
716 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
717 AFS_SIGSET_RESTORE();
720 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
727 deleteStatusNode(statusPtr);