1 /*===============================================================
2 * Copyright (C) 1998 Transarc Corporation - All rights reserved
3 *===============================================================*/
5 /* procedures invoked by the rpc stub */
14 #include <netinet/in.h>
18 #include <afs/afsint.h>
20 #include <afs/procmgmt.h>
21 #include <afs/assert.h>
22 #include <afs/prs_fs.h>
28 #include <afs/cellconfig.h>
31 #include <afs/tcdata.h>
32 #include "error_macros.h"
33 #include "butc_xbsa.h"
34 extern afs_int32 xbsaType;
41 struct rx_connection *tconn;
44 char name[MAXKTCNAMELEN];
45 char inst[MAXKTCNAMELEN];
46 char celn[MAXKTCREALMLEN];
52 /* before this code can be used, the rx connection, on the bucoord side, must */
53 /* be changed so that it will set up for token passing instead of using a */
54 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
58 /* -------------------------
59 * butc - interface routines - alphabetic order
60 * -------------------------
63 STC_LabelTape(acid, label, taskId)
65 struct tc_tapeLabel *label;
68 #ifdef AFS_PTHREAD_ENV
75 struct tc_tapeLabel *mylabel;
76 struct labelTapeIf *ptr;
80 extern int Labeller();
81 extern statusP createStatusNode();
82 extern afs_int32 allocTaskId();
85 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
88 if ( callPermitted(acid) == 0 )
89 return(TC_NOTPERMITTED);
91 ptr = (struct labelTapeIf *) malloc(sizeof(*ptr));
92 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
93 bcopy(label, &ptr->label, sizeof(ptr->label));
95 /* set up the status node */
96 *taskId = allocTaskId(); /* for bucoord */
97 ptr->taskId = *taskId;
99 statusPtr = createStatusNode();
100 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
103 statusPtr->taskId = *taskId;
104 statusPtr->lastPolled = time(0);
105 statusPtr->flags &= ~STARTING; /* ok to examine */
106 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
109 /* create the LWP to do the real work behind the scenes */
110 #ifdef AFS_PTHREAD_ENV
111 code = pthread_attr_init(&tattr);
112 if (code) ERROR_EXIT(code);
114 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
115 if (code) ERROR_EXIT(code);
118 code = pthread_create(&pid, &tattr, Labeller, ptr);
119 AFS_SIGSET_RESTORE();
121 code = LWP_CreateProcess(Labeller, 32768, 1, ptr ,"labeller process", &pid);
127 if (statusPtr) deleteStatusNode(statusPtr);
135 * Tape coordinator server routine to do a dump
138 STC_PerformDump(rxCallId, tcdiPtr, tc_dumpArrayPtr, taskId)
139 struct rx_call *rxCallId;
140 struct tc_dumpInterface *tcdiPtr;
141 tc_dumpArray *tc_dumpArrayPtr;
144 struct dumpNode *newNode = 0;
145 statusP statusPtr = 0;
146 #ifdef AFS_PTHREAD_ENV
148 pthread_attr_t tattr;
155 extern statusP createStatusNode();
158 if ( callPermitted(rxCallId) == 0 )
159 return(TC_NOTPERMITTED);
161 /* should be verifying parameter validity */
164 /* this creates a node in list, alots an id for it and prepares it for locking */
165 CreateNode(&newNode);
167 /*set up the parameters in the node, to be used by LWP */
168 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
170 newNode->dumpName = (char *) malloc(strlen(tcdiPtr->dumpPath)+1);
171 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
173 newNode->volumeSetName = (char *) malloc(strlen(tcdiPtr->volumeSetName)+1);
174 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
176 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
178 newNode->dumps = (struct tc_dumpDesc *)
179 malloc(sizeof(struct tc_dumpDesc) * tc_dumpArrayPtr->tc_dumpArray_len);
180 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
181 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
183 newNode->parent = tcdiPtr->parentDumpId;
184 newNode->level = tcdiPtr->dumpLevel;
185 newNode->doAppend = tcdiPtr->doAppend;
187 if (CONF_XBSA) newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
190 /* create the status node */
191 statusPtr = createStatusNode();
192 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
195 statusPtr->taskId = newNode->taskID;
196 statusPtr->lastPolled = time(0);
197 statusPtr->flags &= ~STARTING; /* ok to examine */
198 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
201 newNode->statusNodePtr = statusPtr;
203 /* create the LWP to do the real work behind the scenes */
204 #ifdef AFS_PTHREAD_ENV
205 code = pthread_attr_init(&tattr);
206 if (code) ERROR_EXIT(code);
208 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
209 if (code) ERROR_EXIT(code);
212 code = pthread_create(&pid, &tattr, Dumper, newNode);
213 AFS_SIGSET_RESTORE();
215 code = LWP_CreateProcess(Dumper, 32768, 1, newNode, "dumper process", &pid);
217 if (code) ERROR_EXIT(code);
219 *taskId = newNode->taskID;
224 if (statusPtr) deleteStatusNode(statusPtr);
225 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
231 STC_PerformRestore(acid, dumpSetName, arestores, taskID)
232 struct rx_call *acid;
233 char *dumpSetName; /* not used */
234 tc_restoreArray *arestores;
237 struct dumpNode *newNode;
240 #ifdef AFS_PTHREAD_ENV
242 pthread_attr_t tattr;
248 extern int Restorer();
249 extern statusP createStatusNode();
251 if ( callPermitted(acid) == 0 )
252 return(TC_NOTPERMITTED);
254 /* should verify parameter validity */
256 /* this creates a node in list, alots an id for it and prepares it for locking */
257 CreateNode(&newNode);
259 newNode->restores = (struct tc_restoreDesc *)
260 malloc (sizeof(struct tc_restoreDesc) * arestores->tc_restoreArray_len);
261 newNode->arraySize = arestores->tc_restoreArray_len;
262 CopyRestoreDesc(newNode->restores,arestores);
263 *taskID = newNode->taskID;
265 /* should log the intent */
267 /* create the status node */
268 statusPtr = createStatusNode();
269 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
272 statusPtr->taskId = newNode->taskID;
273 statusPtr->flags &= ~STARTING; /* ok to examine */
274 statusPtr->lastPolled = time(0);
275 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
278 newNode->statusNodePtr = statusPtr;
280 /* create the LWP to do the real work behind the scenes */
281 #ifdef AFS_PTHREAD_ENV
282 code = pthread_attr_init(&tattr);
283 if (code) ERROR_EXIT(code);
285 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
286 if (code) ERROR_EXIT(code);
289 code = pthread_create(&pid, &tattr, Restorer, newNode);
290 AFS_SIGSET_RESTORE();
292 code = LWP_CreateProcess(Restorer, 65368, 1,newNode ,"restorer process", &pid);
298 if (statusPtr) deleteStatusNode(statusPtr);
299 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
305 STC_ReadLabel(acid, label, taskId)
306 struct rx_call *acid;
307 struct tc_tapeLabel *label;
312 extern int ReadLabel();
315 if (CONF_XBSA) return(TC_BADTASK); /* ReadLabel does not apply if XBSA */
318 if ( callPermitted(acid) == 0 )
319 return(TC_NOTPERMITTED);
321 code = ReadLabel(label); /* Synchronous */
326 * restore the backup database from tape
329 STC_RestoreDb(rxCall, taskId)
330 struct rx_call *rxCall;
333 #ifdef AFS_PTHREAD_ENV
335 pthread_attr_t tattr;
343 extern afs_int32 restoreDbFromTape();
344 extern statusP createStatusNode();
345 extern afs_int32 allocTaskId();
348 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
351 if ( callPermitted(rxCall) == 0 )
352 return(TC_NOTPERMITTED);
354 *taskId = allocTaskId();
356 /* create the status node */
357 statusPtr = createStatusNode();
358 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
361 statusPtr->taskId = *taskId;
362 statusPtr->flags &= ~STARTING; /* ok to examine */
363 statusPtr->lastPolled = time(0);
364 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
367 #ifdef AFS_PTHREAD_ENV
368 code = pthread_attr_init(&tattr);
369 if (code) ERROR_EXIT(code);
371 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
372 if (code) ERROR_EXIT(code);
375 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
376 AFS_SIGSET_RESTORE();
378 code = LWP_CreateProcess(restoreDbFromTape, 32768, 1, *taskId, "Db restore", &pid);
384 if (statusPtr) deleteStatusNode(statusPtr);
391 * restore the backup database from tape
394 STC_SaveDb(rxCall, archiveTime, taskId)
395 struct rx_call *rxCall;
399 #ifdef AFS_PTHREAD_ENV
401 pthread_attr_t tattr;
408 struct saveDbIf *ptr;
410 extern afs_int32 saveDbToTape();
411 extern statusP createStatusNode();
412 extern afs_int32 allocTaskId();
415 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
418 if ( callPermitted(rxCall) == 0 )
419 return(TC_NOTPERMITTED);
421 *taskId = allocTaskId();
423 ptr = (struct saveDbIf *) malloc(sizeof(struct saveDbIf));
424 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
425 ptr->archiveTime = archiveTime;
426 ptr->taskId = *taskId;
428 /* create the status node */
429 statusPtr = createStatusNode();
430 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
433 statusPtr->taskId = *taskId;
434 statusPtr->lastPolled = time(0);
435 statusPtr->flags &= ~STARTING; /* ok to examine */
436 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
439 ptr->statusPtr = statusPtr;
441 #ifdef AFS_PTHREAD_ENV
442 code = pthread_attr_init(&tattr);
443 if (code) ERROR_EXIT(code);
445 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
446 if (code) ERROR_EXIT(code);
449 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
450 AFS_SIGSET_RESTORE();
452 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr ,"Db save", &pid);
458 if (statusPtr) deleteStatusNode(statusPtr);
467 * read a dump (maybe more than one tape), and print out a summary
468 * of its contents. If the flag is set, add to the database.
470 * addDbFlag - if set, the information will be added to the database
473 STC_ScanDumps(acid, addDbFlag, taskId)
474 struct rx_call *acid;
478 #ifdef AFS_PTHREAD_ENV
480 pthread_attr_t tattr;
485 struct scanTapeIf *ptr;
489 extern afs_int32 ScanDumps();
490 extern afs_int32 allocTaskId();
491 extern statusP createStatusNode();
494 if (CONF_XBSA) return(TC_BADTASK); /* ScanDumps does not apply if XBSA */
497 if ( callPermitted(acid) == 0 )
498 return(TC_NOTPERMITTED);
500 *taskId = allocTaskId();
502 ptr = (struct scanTapeIf *) malloc(sizeof(*ptr));
503 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
504 ptr->addDbFlag = addDbFlag;
505 ptr->taskId = *taskId;
507 /* create the status node */
508 statusPtr = createStatusNode();
509 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
512 statusPtr->taskId = *taskId;
513 statusPtr->lastPolled = time(0);
514 statusPtr->flags &= ~STARTING; /* ok to examine */
515 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
518 #ifdef AFS_PTHREAD_ENV
519 code = pthread_attr_init(&tattr);
520 if (code) ERROR_EXIT(code);
522 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
523 if (code) ERROR_EXIT(code);
526 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
527 AFS_SIGSET_RESTORE();
529 code = LWP_CreateProcess(ScanDumps,32768, 1, ptr, "scandump process",&pid);
535 if (statusPtr) deleteStatusNode(statusPtr);
543 * return information about the tape coordinator. Currently this
544 * is just the version number of the interface
547 STC_TCInfo(acid, tciptr)
548 struct rx_call *acid;
549 struct tc_tcInfo *tciptr;
551 if ( callPermitted(acid) == 0 )
552 return(TC_NOTPERMITTED);
554 tciptr->tcVersion = CUR_BUTC_VERSION;
560 STC_DeleteDump(acid, dumpID, taskId)
561 struct rx_call *acid;
564 struct deleteDumpIf *ptr=0;
566 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
567 #ifdef AFS_PTHREAD_ENV
569 pthread_attr_t tattr;
574 extern afs_int32 DeleteDump();
575 extern statusP createStatusNode();
576 extern afs_int32 allocTaskId();
579 if (!CONF_XBSA) return(TC_BADTASK); /* Only do if butc is started as XBSA */
583 if ( callPermitted(acid) == 0 )
584 return(TC_NOTPERMITTED);
586 ptr = (struct deleteDumpIf *) malloc(sizeof(*ptr));
587 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
589 *taskId = allocTaskId();
590 ptr->dumpID = dumpID;
591 ptr->taskId = *taskId;
593 statusPtr = createStatusNode();
594 if (!statusPtr) ERROR_EXIT(TC_INTERNALERROR);
597 statusPtr->taskId = *taskId;
598 statusPtr->lastPolled = time(0);
599 statusPtr->flags &= ~STARTING;
600 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
603 #ifdef AFS_PTHREAD_ENV
604 code = pthread_attr_init(&tattr);
605 if (code) ERROR_EXIT(code);
607 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
608 if (code) ERROR_EXIT(code);
611 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
612 AFS_SIGSET_RESTORE();
614 code = LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process", &pid);
619 if (statusPtr) deleteStatusNode(statusPtr);
627 /* -----------------------------
629 * -----------------------------
633 CopyDumpDesc(toDump, fromDump)
634 struct tc_dumpDesc *toDump;
635 tc_dumpArray *fromDump;
637 struct tc_dumpDesc *toPtr, *fromPtr;
641 fromPtr = fromDump->tc_dumpArray_val;
642 for(i = 0 ; i < fromDump->tc_dumpArray_len; i++)
644 toPtr->vid = fromPtr->vid;
645 toPtr->vtype = fromPtr->vtype;
646 toPtr->partition = fromPtr->partition;
647 toPtr->date = fromPtr->date;
648 toPtr->cloneDate = fromPtr->cloneDate;
649 toPtr->hostAddr = fromPtr->hostAddr;
650 strcpy(toPtr->name,fromPtr->name);
658 static CopyRestoreDesc(toRestore, fromRestore)
659 struct tc_restoreDesc *toRestore;
660 tc_restoreArray *fromRestore;
662 struct tc_restoreDesc *toPtr, *fromPtr;
666 fromPtr = fromRestore->tc_restoreArray_val;
667 for(i = 0 ; i < fromRestore->tc_restoreArray_len ; i++){
668 toPtr->flags = fromPtr->flags;
669 toPtr->position = fromPtr->position;
670 strcpy(toPtr->tapeName,fromPtr->tapeName);
671 toPtr->dbDumpId = fromPtr->dbDumpId;
672 toPtr->initialDumpId = fromPtr->initialDumpId;
673 toPtr->origVid = fromPtr->origVid;
674 toPtr->vid = fromPtr->vid;
675 toPtr->partition = fromPtr->partition;
676 toPtr->dumpLevel = fromPtr->dumpLevel;
677 toPtr->hostAddr = fromPtr->hostAddr;
678 strcpy(toPtr->newName,fromPtr->newName);
679 strcpy(toPtr->oldName, fromPtr->oldName);
687 static CopyTapeSetDesc(toPtr,fromPtr)
688 struct tc_tapeSet *toPtr,*fromPtr;
691 toPtr->id = fromPtr->id;
692 toPtr->maxTapes = fromPtr->maxTapes;
693 toPtr->a = fromPtr->a;
694 toPtr->b = fromPtr->b;
695 strcpy(toPtr->tapeServer,fromPtr->tapeServer);
696 strcpy(toPtr->format,fromPtr->format);
698 toPtr->expDate = fromPtr->expDate;
699 toPtr->expType = fromPtr->expType;