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>
37 #include <afs/cellconfig.h>
40 #include <afs/tcdata.h>
41 #include "error_macros.h"
42 #include "butc_xbsa.h"
45 callPermitted(struct rx_call *call)
47 /* before this code can be used, the rx connection, on the bucoord side, must */
48 /* be changed so that it will set up for token passing instead of using a */
49 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
53 /* -----------------------------
55 * -----------------------------
59 CopyDumpDesc(struct tc_dumpDesc *toDump, tc_dumpArray *fromDump)
61 struct tc_dumpDesc *toPtr, *fromPtr;
65 fromPtr = fromDump->tc_dumpArray_val;
66 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
67 toPtr->vid = fromPtr->vid;
68 toPtr->vtype = fromPtr->vtype;
69 toPtr->partition = fromPtr->partition;
70 toPtr->date = fromPtr->date;
71 toPtr->cloneDate = fromPtr->cloneDate;
72 toPtr->hostAddr = fromPtr->hostAddr;
73 strcpy(toPtr->name, fromPtr->name);
82 CopyRestoreDesc(struct tc_restoreDesc *toRestore, tc_restoreArray *fromRestore)
84 struct tc_restoreDesc *toPtr, *fromPtr;
88 fromPtr = fromRestore->tc_restoreArray_val;
89 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
90 toPtr->flags = fromPtr->flags;
91 toPtr->position = fromPtr->position;
92 strcpy(toPtr->tapeName, fromPtr->tapeName);
93 toPtr->dbDumpId = fromPtr->dbDumpId;
94 toPtr->initialDumpId = fromPtr->initialDumpId;
95 toPtr->origVid = fromPtr->origVid;
96 toPtr->vid = fromPtr->vid;
97 toPtr->partition = fromPtr->partition;
98 toPtr->dumpLevel = fromPtr->dumpLevel;
99 toPtr->hostAddr = fromPtr->hostAddr;
100 strcpy(toPtr->newName, fromPtr->newName);
101 strcpy(toPtr->oldName, fromPtr->oldName);
110 CopyTapeSetDesc(struct tc_tapeSet *toPtr, struct tc_tapeSet *fromPtr)
113 toPtr->id = fromPtr->id;
114 toPtr->maxTapes = fromPtr->maxTapes;
115 toPtr->a = fromPtr->a;
116 toPtr->b = fromPtr->b;
117 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
118 strcpy(toPtr->format, fromPtr->format);
120 toPtr->expDate = fromPtr->expDate;
121 toPtr->expType = fromPtr->expType;
125 /* -------------------------
126 * butc - interface routines - alphabetic order
127 * -------------------------
131 STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
133 #ifdef AFS_PTHREAD_ENV
135 pthread_attr_t tattr;
140 struct labelTapeIf *ptr;
144 extern int Labeller();
145 extern statusP createStatusNode();
146 extern afs_int32 allocTaskId();
150 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
153 if (callPermitted(acid) == 0)
154 return (TC_NOTPERMITTED);
156 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
158 ERROR_EXIT(TC_NOMEMORY);
159 memcpy(&ptr->label, label, sizeof(ptr->label));
161 /* set up the status node */
162 *taskId = allocTaskId(); /* for bucoord */
163 ptr->taskId = *taskId;
165 statusPtr = createStatusNode();
167 ERROR_EXIT(TC_INTERNALERROR);
170 statusPtr->taskId = *taskId;
171 statusPtr->lastPolled = time(0);
172 statusPtr->flags &= ~STARTING; /* ok to examine */
173 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
176 /* create the LWP to do the real work behind the scenes */
177 #ifdef AFS_PTHREAD_ENV
178 code = pthread_attr_init(&tattr);
182 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
187 code = pthread_create(&pid, &tattr, Labeller, ptr);
188 AFS_SIGSET_RESTORE();
191 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
198 deleteStatusNode(statusPtr);
207 * Tape coordinator server routine to do a dump
211 STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_dumpArray *tc_dumpArrayPtr, afs_int32 *taskId)
213 struct dumpNode *newNode = 0;
214 statusP statusPtr = 0;
215 #ifdef AFS_PTHREAD_ENV
217 pthread_attr_t tattr;
224 extern statusP createStatusNode();
227 if (callPermitted(rxCallId) == 0)
228 return (TC_NOTPERMITTED);
230 /* should be verifying parameter validity */
233 /* this creates a node in list, alots an id for it and prepares it for locking */
234 CreateNode(&newNode);
236 /*set up the parameters in the node, to be used by LWP */
237 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
239 newNode->dumpName = (char *)malloc(strlen(tcdiPtr->dumpPath) + 1);
240 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
242 newNode->volumeSetName =
243 (char *)malloc(strlen(tcdiPtr->volumeSetName) + 1);
244 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
246 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
248 newNode->dumps = (struct tc_dumpDesc *)
249 malloc(sizeof(struct tc_dumpDesc) *
250 tc_dumpArrayPtr->tc_dumpArray_len);
251 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
252 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
254 newNode->parent = tcdiPtr->parentDumpId;
255 newNode->level = tcdiPtr->dumpLevel;
256 newNode->doAppend = tcdiPtr->doAppend;
259 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
262 /* create the status node */
263 statusPtr = createStatusNode();
265 ERROR_EXIT(TC_INTERNALERROR);
268 statusPtr->taskId = newNode->taskID;
269 statusPtr->lastPolled = time(0);
270 statusPtr->flags &= ~STARTING; /* ok to examine */
271 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
274 newNode->statusNodePtr = statusPtr;
276 /* create the LWP to do the real work behind the scenes */
277 #ifdef AFS_PTHREAD_ENV
278 code = pthread_attr_init(&tattr);
282 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
287 code = pthread_create(&pid, &tattr, Dumper, newNode);
288 AFS_SIGSET_RESTORE();
291 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
297 *taskId = newNode->taskID;
302 deleteStatusNode(statusPtr);
303 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
310 STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *arestores, afs_int32 *taskID)
312 struct dumpNode *newNode;
315 #ifdef AFS_PTHREAD_ENV
317 pthread_attr_t tattr;
323 extern int Restorer();
324 extern statusP createStatusNode();
326 if (callPermitted(acid) == 0)
327 return (TC_NOTPERMITTED);
329 /* should verify parameter validity */
331 /* this creates a node in list, alots an id for it and prepares it for locking */
332 CreateNode(&newNode);
334 newNode->restores = (struct tc_restoreDesc *)
335 malloc(sizeof(struct tc_restoreDesc) *
336 arestores->tc_restoreArray_len);
337 newNode->arraySize = arestores->tc_restoreArray_len;
338 CopyRestoreDesc(newNode->restores, arestores);
339 *taskID = newNode->taskID;
341 /* should log the intent */
343 /* create the status node */
344 statusPtr = createStatusNode();
346 ERROR_EXIT(TC_INTERNALERROR);
349 statusPtr->taskId = newNode->taskID;
350 statusPtr->flags &= ~STARTING; /* ok to examine */
351 statusPtr->lastPolled = time(0);
352 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
355 newNode->statusNodePtr = statusPtr;
357 /* create the LWP to do the real work behind the scenes */
358 #ifdef AFS_PTHREAD_ENV
359 code = pthread_attr_init(&tattr);
363 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
368 code = pthread_create(&pid, &tattr, Restorer, newNode);
369 AFS_SIGSET_RESTORE();
372 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
373 "restorer process", &pid);
379 deleteStatusNode(statusPtr);
380 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
387 STC_ReadLabel(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
391 extern int ReadLabel();
395 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
398 if (callPermitted(acid) == 0)
399 return (TC_NOTPERMITTED);
401 code = ReadLabel(label); /* Synchronous */
406 * restore the backup database from tape
410 STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
412 #ifdef AFS_PTHREAD_ENV
414 pthread_attr_t tattr;
422 extern afs_int32 restoreDbFromTape();
423 extern statusP createStatusNode();
424 extern afs_int32 allocTaskId();
428 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
431 if (callPermitted(rxCall) == 0)
432 return (TC_NOTPERMITTED);
434 *taskId = allocTaskId();
436 /* create the status node */
437 statusPtr = createStatusNode();
439 ERROR_EXIT(TC_INTERNALERROR);
442 statusPtr->taskId = *taskId;
443 statusPtr->flags &= ~STARTING; /* ok to examine */
444 statusPtr->lastPolled = time(0);
445 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
448 #ifdef AFS_PTHREAD_ENV
449 code = pthread_attr_init(&tattr);
453 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
458 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
459 AFS_SIGSET_RESTORE();
462 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)*taskId,
469 deleteStatusNode(statusPtr);
476 * restore the backup database from tape
480 STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
482 #ifdef AFS_PTHREAD_ENV
484 pthread_attr_t tattr;
491 struct saveDbIf *ptr;
493 extern afs_int32 saveDbToTape();
494 extern statusP createStatusNode();
495 extern afs_int32 allocTaskId();
499 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
502 if (callPermitted(rxCall) == 0)
503 return (TC_NOTPERMITTED);
505 *taskId = allocTaskId();
507 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
509 ERROR_EXIT(TC_NOMEMORY);
510 ptr->archiveTime = archiveTime;
511 ptr->taskId = *taskId;
513 /* create the status node */
514 statusPtr = createStatusNode();
516 ERROR_EXIT(TC_INTERNALERROR);
519 statusPtr->taskId = *taskId;
520 statusPtr->lastPolled = time(0);
521 statusPtr->flags &= ~STARTING; /* ok to examine */
522 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
525 ptr->statusPtr = statusPtr;
527 #ifdef AFS_PTHREAD_ENV
528 code = pthread_attr_init(&tattr);
532 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
537 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
538 AFS_SIGSET_RESTORE();
540 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
546 deleteStatusNode(statusPtr);
556 * read a dump (maybe more than one tape), and print out a summary
557 * of its contents. If the flag is set, add to the database.
559 * addDbFlag - if set, the information will be added to the database
563 STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
565 #ifdef AFS_PTHREAD_ENV
567 pthread_attr_t tattr;
572 struct scanTapeIf *ptr;
576 extern afs_int32 ScanDumps();
577 extern afs_int32 allocTaskId();
578 extern statusP createStatusNode();
582 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
585 if (callPermitted(acid) == 0)
586 return (TC_NOTPERMITTED);
588 *taskId = allocTaskId();
590 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
592 ERROR_EXIT(TC_NOMEMORY);
593 ptr->addDbFlag = addDbFlag;
594 ptr->taskId = *taskId;
596 /* create the status node */
597 statusPtr = createStatusNode();
599 ERROR_EXIT(TC_INTERNALERROR);
602 statusPtr->taskId = *taskId;
603 statusPtr->lastPolled = time(0);
604 statusPtr->flags &= ~STARTING; /* ok to examine */
605 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
608 #ifdef AFS_PTHREAD_ENV
609 code = pthread_attr_init(&tattr);
613 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
618 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
619 AFS_SIGSET_RESTORE();
622 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
628 deleteStatusNode(statusPtr);
637 * return information about the tape coordinator. Currently this
638 * is just the version number of the interface
642 STC_TCInfo(struct rx_call *acid, struct tc_tcInfo *tciptr)
644 if (callPermitted(acid) == 0)
645 return (TC_NOTPERMITTED);
647 tciptr->tcVersion = CUR_BUTC_VERSION;
654 STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
656 struct deleteDumpIf *ptr = 0;
657 statusP statusPtr = 0;
658 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
660 #ifdef AFS_PTHREAD_ENV
662 pthread_attr_t tattr;
668 extern afs_int32 DeleteDump();
669 extern statusP createStatusNode();
670 extern afs_int32 allocTaskId();
674 return (TC_BADTASK); /* Only do if butc is started as XBSA */
678 if (callPermitted(acid) == 0)
679 return (TC_NOTPERMITTED);
681 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
683 ERROR_EXIT(TC_NOMEMORY);
685 *taskId = allocTaskId();
686 ptr->dumpID = dumpID;
687 ptr->taskId = *taskId;
689 statusPtr = createStatusNode();
691 ERROR_EXIT(TC_INTERNALERROR);
694 statusPtr->taskId = *taskId;
695 statusPtr->lastPolled = time(0);
696 statusPtr->flags &= ~STARTING;
697 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
700 #ifdef AFS_PTHREAD_ENV
701 code = pthread_attr_init(&tattr);
705 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
710 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
711 AFS_SIGSET_RESTORE();
714 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
721 deleteStatusNode(statusPtr);