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>
15 #include <afs/procmgmt.h>
20 #include <afs/afsint.h>
21 #include <afs/prs_fs.h>
25 #include <afs/cellconfig.h>
28 #include <afs/tcdata.h>
29 #include <afs/budb_client.h>
30 #include <afs/bucoord_prototypes.h>
32 #include "error_macros.h"
33 #include "butc_xbsa.h"
34 #include "butc_prototypes.h"
35 #include "butc_internal.h"
37 static int CopyDumpDesc(struct tc_dumpDesc *, tc_dumpArray *);
38 static int CopyRestoreDesc(struct tc_restoreDesc *, tc_restoreArray *);
39 static int CopyTapeSetDesc(struct tc_tapeSet *, struct tc_tapeSet *);
42 callPermitted(struct rx_call *call)
44 /* before this code can be used, the rx connection, on the bucoord side, must */
45 /* be changed so that it will set up for token passing instead of using a */
46 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
50 /* -----------------------------
52 * -----------------------------
56 CopyDumpDesc(struct tc_dumpDesc *toDump, tc_dumpArray *fromDump)
58 struct tc_dumpDesc *toPtr, *fromPtr;
62 fromPtr = fromDump->tc_dumpArray_val;
63 for (i = 0; i < fromDump->tc_dumpArray_len; i++) {
64 toPtr->vid = fromPtr->vid;
65 toPtr->vtype = fromPtr->vtype;
66 toPtr->partition = fromPtr->partition;
67 toPtr->date = fromPtr->date;
68 toPtr->cloneDate = fromPtr->cloneDate;
69 toPtr->hostAddr = fromPtr->hostAddr;
70 strcpy(toPtr->name, fromPtr->name);
79 CopyRestoreDesc(struct tc_restoreDesc *toRestore, tc_restoreArray *fromRestore)
81 struct tc_restoreDesc *toPtr, *fromPtr;
85 fromPtr = fromRestore->tc_restoreArray_val;
86 for (i = 0; i < fromRestore->tc_restoreArray_len; i++) {
87 toPtr->flags = fromPtr->flags;
88 toPtr->position = fromPtr->position;
89 strcpy(toPtr->tapeName, fromPtr->tapeName);
90 toPtr->dbDumpId = fromPtr->dbDumpId;
91 toPtr->initialDumpId = fromPtr->initialDumpId;
92 toPtr->origVid = fromPtr->origVid;
93 toPtr->vid = fromPtr->vid;
94 toPtr->partition = fromPtr->partition;
95 toPtr->dumpLevel = fromPtr->dumpLevel;
96 toPtr->hostAddr = fromPtr->hostAddr;
97 strcpy(toPtr->newName, fromPtr->newName);
98 strcpy(toPtr->oldName, fromPtr->oldName);
107 CopyTapeSetDesc(struct tc_tapeSet *toPtr, struct tc_tapeSet *fromPtr)
110 toPtr->id = fromPtr->id;
111 toPtr->maxTapes = fromPtr->maxTapes;
112 toPtr->a = fromPtr->a;
113 toPtr->b = fromPtr->b;
114 strcpy(toPtr->tapeServer, fromPtr->tapeServer);
115 strcpy(toPtr->format, fromPtr->format);
117 toPtr->expDate = fromPtr->expDate;
118 toPtr->expType = fromPtr->expType;
122 /* -------------------------
123 * butc - interface routines - alphabetic order
124 * -------------------------
128 STC_LabelTape(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
130 #ifdef AFS_PTHREAD_ENV
132 pthread_attr_t tattr;
137 struct labelTapeIf *ptr;
138 statusP statusPtr = NULL;
143 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
146 if (callPermitted(acid) == 0)
147 return (TC_NOTPERMITTED);
149 ptr = (struct labelTapeIf *)malloc(sizeof(*ptr));
151 ERROR_EXIT(TC_NOMEMORY);
152 memcpy(&ptr->label, label, sizeof(ptr->label));
154 /* set up the status node */
155 *taskId = allocTaskId(); /* for bucoord */
156 ptr->taskId = *taskId;
158 statusPtr = createStatusNode();
160 ERROR_EXIT(TC_INTERNALERROR);
163 statusPtr->taskId = *taskId;
164 statusPtr->lastPolled = time(0);
165 statusPtr->flags &= ~STARTING; /* ok to examine */
166 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
169 /* create the LWP to do the real work behind the scenes */
170 #ifdef AFS_PTHREAD_ENV
171 code = pthread_attr_init(&tattr);
175 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
180 code = pthread_create(&pid, &tattr, Labeller, ptr);
181 AFS_SIGSET_RESTORE();
184 LWP_CreateProcess(Labeller, 32768, 1, (void *)ptr, "labeller process",
191 deleteStatusNode(statusPtr);
200 * Tape coordinator server routine to do a dump
204 STC_PerformDump(struct rx_call *rxCallId, struct tc_dumpInterface *tcdiPtr, tc_dumpArray *tc_dumpArrayPtr, afs_int32 *taskId)
206 struct dumpNode *newNode = 0;
207 statusP statusPtr = 0;
208 #ifdef AFS_PTHREAD_ENV
210 pthread_attr_t tattr;
217 if (callPermitted(rxCallId) == 0)
218 return (TC_NOTPERMITTED);
220 /* should be verifying parameter validity */
223 /* this creates a node in list, alots an id for it and prepares it for locking */
224 CreateNode(&newNode);
226 /*set up the parameters in the node, to be used by LWP */
227 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
229 newNode->dumpName = strdup(tcdiPtr->dumpPath);
230 newNode->volumeSetName = strdup(tcdiPtr->volumeSetName);
232 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
234 newNode->dumps = (struct tc_dumpDesc *)
235 malloc(sizeof(struct tc_dumpDesc) *
236 tc_dumpArrayPtr->tc_dumpArray_len);
237 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
238 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
240 newNode->parent = tcdiPtr->parentDumpId;
241 newNode->level = tcdiPtr->dumpLevel;
242 newNode->doAppend = tcdiPtr->doAppend;
245 newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
248 /* create the status node */
249 statusPtr = createStatusNode();
251 ERROR_EXIT(TC_INTERNALERROR);
254 statusPtr->taskId = newNode->taskID;
255 statusPtr->lastPolled = time(0);
256 statusPtr->flags &= ~STARTING; /* ok to examine */
257 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
260 newNode->statusNodePtr = statusPtr;
262 /* create the LWP to do the real work behind the scenes */
263 #ifdef AFS_PTHREAD_ENV
264 code = pthread_attr_init(&tattr);
268 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
273 code = pthread_create(&pid, &tattr, Dumper, newNode);
274 AFS_SIGSET_RESTORE();
277 LWP_CreateProcess(Dumper, 32768, 1, (void *)newNode, "dumper process",
283 *taskId = newNode->taskID;
288 deleteStatusNode(statusPtr);
289 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
296 STC_PerformRestore(struct rx_call *acid, char *dumpSetName, tc_restoreArray *arestores, afs_int32 *taskID)
298 struct dumpNode *newNode;
301 #ifdef AFS_PTHREAD_ENV
303 pthread_attr_t tattr;
309 if (callPermitted(acid) == 0)
310 return (TC_NOTPERMITTED);
312 /* should verify parameter validity */
314 /* this creates a node in list, alots an id for it and prepares it for locking */
315 CreateNode(&newNode);
317 newNode->restores = (struct tc_restoreDesc *)
318 malloc(sizeof(struct tc_restoreDesc) *
319 arestores->tc_restoreArray_len);
320 newNode->arraySize = arestores->tc_restoreArray_len;
321 CopyRestoreDesc(newNode->restores, arestores);
322 *taskID = newNode->taskID;
324 /* should log the intent */
326 /* create the status node */
327 statusPtr = createStatusNode();
329 ERROR_EXIT(TC_INTERNALERROR);
332 statusPtr->taskId = newNode->taskID;
333 statusPtr->flags &= ~STARTING; /* ok to examine */
334 statusPtr->lastPolled = time(0);
335 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
338 newNode->statusNodePtr = statusPtr;
340 /* create the LWP to do the real work behind the scenes */
341 #ifdef AFS_PTHREAD_ENV
342 code = pthread_attr_init(&tattr);
346 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
351 code = pthread_create(&pid, &tattr, Restorer, newNode);
352 AFS_SIGSET_RESTORE();
355 LWP_CreateProcess(Restorer, 65368, 1, (void *)newNode,
356 "restorer process", &pid);
362 deleteStatusNode(statusPtr);
363 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
370 STC_ReadLabel(struct rx_call *acid, struct tc_tapeLabel *label, afs_uint32 *taskId)
376 return (TC_BADTASK); /* ReadLabel does not apply if XBSA */
379 if (callPermitted(acid) == 0)
380 return (TC_NOTPERMITTED);
382 code = ReadLabel(label); /* Synchronous */
387 * restore the backup database from tape
391 STC_RestoreDb(struct rx_call *rxCall, afs_uint32 *taskId)
393 #ifdef AFS_PTHREAD_ENV
395 pthread_attr_t tattr;
405 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
408 if (callPermitted(rxCall) == 0)
409 return (TC_NOTPERMITTED);
411 *taskId = allocTaskId();
413 /* create the status node */
414 statusPtr = createStatusNode();
416 ERROR_EXIT(TC_INTERNALERROR);
419 statusPtr->taskId = *taskId;
420 statusPtr->flags &= ~STARTING; /* ok to examine */
421 statusPtr->lastPolled = time(0);
422 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
425 #ifdef AFS_PTHREAD_ENV
426 code = pthread_attr_init(&tattr);
430 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
435 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)(intptr_t)*taskId);
436 AFS_SIGSET_RESTORE();
439 LWP_CreateProcess(restoreDbFromTape, 32768, 1, (void *)(intptr_t)*taskId,
446 deleteStatusNode(statusPtr);
453 * restore the backup database from tape
457 STC_SaveDb(struct rx_call *rxCall, Date archiveTime, afs_uint32 *taskId)
459 #ifdef AFS_PTHREAD_ENV
461 pthread_attr_t tattr;
466 statusP statusPtr = NULL;
468 struct saveDbIf *ptr;
472 return (TC_BADTASK); /* LabelTape does not apply if XBSA */
475 if (callPermitted(rxCall) == 0)
476 return (TC_NOTPERMITTED);
478 *taskId = allocTaskId();
480 ptr = (struct saveDbIf *)malloc(sizeof(struct saveDbIf));
482 ERROR_EXIT(TC_NOMEMORY);
483 ptr->archiveTime = archiveTime;
484 ptr->taskId = *taskId;
486 /* create the status node */
487 statusPtr = createStatusNode();
489 ERROR_EXIT(TC_INTERNALERROR);
492 statusPtr->taskId = *taskId;
493 statusPtr->lastPolled = time(0);
494 statusPtr->flags &= ~STARTING; /* ok to examine */
495 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
498 ptr->statusPtr = statusPtr;
500 #ifdef AFS_PTHREAD_ENV
501 code = pthread_attr_init(&tattr);
505 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
510 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
511 AFS_SIGSET_RESTORE();
513 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr, "Db save", &pid);
519 deleteStatusNode(statusPtr);
529 * read a dump (maybe more than one tape), and print out a summary
530 * of its contents. If the flag is set, add to the database.
532 * addDbFlag - if set, the information will be added to the database
536 STC_ScanDumps(struct rx_call *acid, afs_int32 addDbFlag, afs_uint32 *taskId)
538 #ifdef AFS_PTHREAD_ENV
540 pthread_attr_t tattr;
545 struct scanTapeIf *ptr;
546 statusP statusPtr = NULL;
551 return (TC_BADTASK); /* ScanDumps does not apply if XBSA */
554 if (callPermitted(acid) == 0)
555 return (TC_NOTPERMITTED);
557 *taskId = allocTaskId();
559 ptr = (struct scanTapeIf *)malloc(sizeof(*ptr));
561 ERROR_EXIT(TC_NOMEMORY);
562 ptr->addDbFlag = addDbFlag;
563 ptr->taskId = *taskId;
565 /* create the status node */
566 statusPtr = createStatusNode();
568 ERROR_EXIT(TC_INTERNALERROR);
571 statusPtr->taskId = *taskId;
572 statusPtr->lastPolled = time(0);
573 statusPtr->flags &= ~STARTING; /* ok to examine */
574 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
577 #ifdef AFS_PTHREAD_ENV
578 code = pthread_attr_init(&tattr);
582 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
587 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
588 AFS_SIGSET_RESTORE();
591 LWP_CreateProcess(ScanDumps, 32768, 1, ptr, "scandump process", &pid);
597 deleteStatusNode(statusPtr);
606 * return information about the tape coordinator. Currently this
607 * is just the version number of the interface
611 STC_TCInfo(struct rx_call *acid, struct tc_tcInfo *tciptr)
613 if (callPermitted(acid) == 0)
614 return (TC_NOTPERMITTED);
616 tciptr->tcVersion = CUR_BUTC_VERSION;
623 STC_DeleteDump(struct rx_call *acid, afs_uint32 dumpID, afs_uint32 *taskId)
625 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
627 struct deleteDumpIf *ptr = 0;
628 statusP statusPtr = 0;
629 #ifdef AFS_PTHREAD_ENV
631 pthread_attr_t tattr;
640 return (TC_BADTASK); /* Only do if butc is started as XBSA */
644 if (callPermitted(acid) == 0)
645 return (TC_NOTPERMITTED);
647 ptr = (struct deleteDumpIf *)malloc(sizeof(*ptr));
649 ERROR_EXIT(TC_NOMEMORY);
651 *taskId = allocTaskId();
652 ptr->dumpID = dumpID;
653 ptr->taskId = *taskId;
655 statusPtr = createStatusNode();
657 ERROR_EXIT(TC_INTERNALERROR);
660 statusPtr->taskId = *taskId;
661 statusPtr->lastPolled = time(0);
662 statusPtr->flags &= ~STARTING;
663 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
666 #ifdef AFS_PTHREAD_ENV
667 code = pthread_attr_init(&tattr);
671 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
676 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
677 AFS_SIGSET_RESTORE();
680 LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process",
687 deleteStatusNode(statusPtr);