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>
17 #include <sys/types.h>
23 #include <netinet/in.h>
27 #include <afs/afsint.h>
29 #include <afs/procmgmt.h>
30 #include <afs/assert.h>
31 #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"
43 extern afs_int32 xbsaType;
50 struct rx_connection *tconn;
53 char name[MAXKTCNAMELEN];
54 char inst[MAXKTCNAMELEN];
55 char celn[MAXKTCREALMLEN];
61 /* before this code can be used, the rx connection, on the bucoord side, must */
62 /* be changed so that it will set up for token passing instead of using a */
63 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
67 /* -------------------------
68 * butc - interface routines - alphabetic order
69 * -------------------------
72 afs_int32 STC_LabelTape(acid, label, taskId)
74 struct tc_tapeLabel *label;
77 #ifdef AFS_PTHREAD_ENV
84 struct tc_tapeLabel *mylabel;
85 struct labelTapeIf *ptr;
89 extern int Labeller();
90 extern statusP createStatusNode();
91 extern afs_int32 allocTaskId();
94 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
97 if ( callPermitted(acid) == 0 )
98 return(TC_NOTPERMITTED);
100 ptr = (struct labelTapeIf *) malloc(sizeof(*ptr));
101 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
102 memcpy(&ptr->label, label, sizeof(ptr->label));
104 /* set up the status node */
105 *taskId = allocTaskId(); /* for bucoord */
106 ptr->taskId = *taskId;
108 statusPtr = createStatusNode();
109 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
112 statusPtr->taskId = *taskId;
113 statusPtr->lastPolled = time(0);
114 statusPtr->flags &= ~STARTING; /* ok to examine */
115 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
118 /* create the LWP to do the real work behind the scenes */
119 #ifdef AFS_PTHREAD_ENV
120 code = pthread_attr_init(&tattr);
121 if (code) ERROR_EXIT(code);
123 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
124 if (code) ERROR_EXIT(code);
127 code = pthread_create(&pid, &tattr, Labeller, ptr);
128 AFS_SIGSET_RESTORE();
130 code = LWP_CreateProcess(Labeller, 32768, 1, ptr ,"labeller process", &pid);
136 if (statusPtr) deleteStatusNode(statusPtr);
144 * Tape coordinator server routine to do a dump
147 afs_int32 STC_PerformDump(rxCallId, tcdiPtr, tc_dumpArrayPtr, taskId)
148 struct rx_call *rxCallId;
149 struct tc_dumpInterface *tcdiPtr;
150 tc_dumpArray *tc_dumpArrayPtr;
153 struct dumpNode *newNode = 0;
154 statusP statusPtr = 0;
155 #ifdef AFS_PTHREAD_ENV
157 pthread_attr_t tattr;
164 extern statusP createStatusNode();
167 if ( callPermitted(rxCallId) == 0 )
168 return(TC_NOTPERMITTED);
170 /* should be verifying parameter validity */
173 /* this creates a node in list, alots an id for it and prepares it for locking */
174 CreateNode(&newNode);
176 /*set up the parameters in the node, to be used by LWP */
177 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
179 newNode->dumpName = (char *) malloc(strlen(tcdiPtr->dumpPath)+1);
180 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
182 newNode->volumeSetName = (char *) malloc(strlen(tcdiPtr->volumeSetName)+1);
183 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
185 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
187 newNode->dumps = (struct tc_dumpDesc *)
188 malloc(sizeof(struct tc_dumpDesc) * tc_dumpArrayPtr->tc_dumpArray_len);
189 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
190 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
192 newNode->parent = tcdiPtr->parentDumpId;
193 newNode->level = tcdiPtr->dumpLevel;
194 newNode->doAppend = tcdiPtr->doAppend;
196 if (CONF_XBSA) newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
199 /* create the status node */
200 statusPtr = createStatusNode();
201 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
204 statusPtr->taskId = newNode->taskID;
205 statusPtr->lastPolled = time(0);
206 statusPtr->flags &= ~STARTING; /* ok to examine */
207 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
210 newNode->statusNodePtr = statusPtr;
212 /* create the LWP to do the real work behind the scenes */
213 #ifdef AFS_PTHREAD_ENV
214 code = pthread_attr_init(&tattr);
215 if (code) ERROR_EXIT(code);
217 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
218 if (code) ERROR_EXIT(code);
221 code = pthread_create(&pid, &tattr, Dumper, newNode);
222 AFS_SIGSET_RESTORE();
224 code = LWP_CreateProcess(Dumper, 32768, 1, newNode, "dumper process", &pid);
226 if (code) ERROR_EXIT(code);
228 *taskId = newNode->taskID;
233 if (statusPtr) deleteStatusNode(statusPtr);
234 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
240 afs_int32 STC_PerformRestore(acid, dumpSetName, arestores, taskID)
241 struct rx_call *acid;
242 char *dumpSetName; /* not used */
243 tc_restoreArray *arestores;
246 struct dumpNode *newNode;
249 #ifdef AFS_PTHREAD_ENV
251 pthread_attr_t tattr;
257 extern int Restorer();
258 extern statusP createStatusNode();
260 if ( callPermitted(acid) == 0 )
261 return(TC_NOTPERMITTED);
263 /* should verify parameter validity */
265 /* this creates a node in list, alots an id for it and prepares it for locking */
266 CreateNode(&newNode);
268 newNode->restores = (struct tc_restoreDesc *)
269 malloc (sizeof(struct tc_restoreDesc) * arestores->tc_restoreArray_len);
270 newNode->arraySize = arestores->tc_restoreArray_len;
271 CopyRestoreDesc(newNode->restores,arestores);
272 *taskID = newNode->taskID;
274 /* should log the intent */
276 /* create the status node */
277 statusPtr = createStatusNode();
278 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
281 statusPtr->taskId = newNode->taskID;
282 statusPtr->flags &= ~STARTING; /* ok to examine */
283 statusPtr->lastPolled = time(0);
284 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
287 newNode->statusNodePtr = statusPtr;
289 /* create the LWP to do the real work behind the scenes */
290 #ifdef AFS_PTHREAD_ENV
291 code = pthread_attr_init(&tattr);
292 if (code) ERROR_EXIT(code);
294 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
295 if (code) ERROR_EXIT(code);
298 code = pthread_create(&pid, &tattr, Restorer, newNode);
299 AFS_SIGSET_RESTORE();
301 code = LWP_CreateProcess(Restorer, 65368, 1,newNode ,"restorer process", &pid);
307 if (statusPtr) deleteStatusNode(statusPtr);
308 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
314 afs_int32 STC_ReadLabel(acid, label, taskId)
315 struct rx_call *acid;
316 struct tc_tapeLabel *label;
321 extern int ReadLabel();
324 if (CONF_XBSA) return(TC_BADTASK); /* ReadLabel does not apply if XBSA */
327 if ( callPermitted(acid) == 0 )
328 return(TC_NOTPERMITTED);
330 code = ReadLabel(label); /* Synchronous */
335 * restore the backup database from tape
338 afs_int32 STC_RestoreDb(rxCall, taskId)
339 struct rx_call *rxCall;
342 #ifdef AFS_PTHREAD_ENV
344 pthread_attr_t tattr;
352 extern afs_int32 restoreDbFromTape();
353 extern statusP createStatusNode();
354 extern afs_int32 allocTaskId();
357 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
360 if ( callPermitted(rxCall) == 0 )
361 return(TC_NOTPERMITTED);
363 *taskId = allocTaskId();
365 /* create the status node */
366 statusPtr = createStatusNode();
367 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
370 statusPtr->taskId = *taskId;
371 statusPtr->flags &= ~STARTING; /* ok to examine */
372 statusPtr->lastPolled = time(0);
373 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
376 #ifdef AFS_PTHREAD_ENV
377 code = pthread_attr_init(&tattr);
378 if (code) ERROR_EXIT(code);
380 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
381 if (code) ERROR_EXIT(code);
384 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
385 AFS_SIGSET_RESTORE();
387 code = LWP_CreateProcess(restoreDbFromTape, 32768, 1, *taskId, "Db restore", &pid);
393 if (statusPtr) deleteStatusNode(statusPtr);
400 * restore the backup database from tape
403 afs_int32 STC_SaveDb(rxCall, archiveTime, taskId)
404 struct rx_call *rxCall;
408 #ifdef AFS_PTHREAD_ENV
410 pthread_attr_t tattr;
417 struct saveDbIf *ptr;
419 extern afs_int32 saveDbToTape();
420 extern statusP createStatusNode();
421 extern afs_int32 allocTaskId();
424 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
427 if ( callPermitted(rxCall) == 0 )
428 return(TC_NOTPERMITTED);
430 *taskId = allocTaskId();
432 ptr = (struct saveDbIf *) malloc(sizeof(struct saveDbIf));
433 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
434 ptr->archiveTime = archiveTime;
435 ptr->taskId = *taskId;
437 /* create the status node */
438 statusPtr = createStatusNode();
439 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
442 statusPtr->taskId = *taskId;
443 statusPtr->lastPolled = time(0);
444 statusPtr->flags &= ~STARTING; /* ok to examine */
445 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
448 ptr->statusPtr = statusPtr;
450 #ifdef AFS_PTHREAD_ENV
451 code = pthread_attr_init(&tattr);
452 if (code) ERROR_EXIT(code);
454 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
455 if (code) ERROR_EXIT(code);
458 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
459 AFS_SIGSET_RESTORE();
461 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr ,"Db save", &pid);
467 if (statusPtr) deleteStatusNode(statusPtr);
476 * read a dump (maybe more than one tape), and print out a summary
477 * of its contents. If the flag is set, add to the database.
479 * addDbFlag - if set, the information will be added to the database
482 afs_int32 STC_ScanDumps(acid, addDbFlag, taskId)
483 struct rx_call *acid;
487 #ifdef AFS_PTHREAD_ENV
489 pthread_attr_t tattr;
494 struct scanTapeIf *ptr;
498 extern afs_int32 ScanDumps();
499 extern afs_int32 allocTaskId();
500 extern statusP createStatusNode();
503 if (CONF_XBSA) return(TC_BADTASK); /* ScanDumps does not apply if XBSA */
506 if ( callPermitted(acid) == 0 )
507 return(TC_NOTPERMITTED);
509 *taskId = allocTaskId();
511 ptr = (struct scanTapeIf *) malloc(sizeof(*ptr));
512 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
513 ptr->addDbFlag = addDbFlag;
514 ptr->taskId = *taskId;
516 /* create the status node */
517 statusPtr = createStatusNode();
518 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
521 statusPtr->taskId = *taskId;
522 statusPtr->lastPolled = time(0);
523 statusPtr->flags &= ~STARTING; /* ok to examine */
524 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
527 #ifdef AFS_PTHREAD_ENV
528 code = pthread_attr_init(&tattr);
529 if (code) ERROR_EXIT(code);
531 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
532 if (code) ERROR_EXIT(code);
535 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
536 AFS_SIGSET_RESTORE();
538 code = LWP_CreateProcess(ScanDumps,32768, 1, ptr, "scandump process",&pid);
544 if (statusPtr) deleteStatusNode(statusPtr);
552 * return information about the tape coordinator. Currently this
553 * is just the version number of the interface
556 afs_int32 STC_TCInfo(acid, tciptr)
557 struct rx_call *acid;
558 struct tc_tcInfo *tciptr;
560 if ( callPermitted(acid) == 0 )
561 return(TC_NOTPERMITTED);
563 tciptr->tcVersion = CUR_BUTC_VERSION;
569 afs_int32 STC_DeleteDump(acid, dumpID, taskId)
570 struct rx_call *acid;
574 struct deleteDumpIf *ptr=0;
576 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
577 #ifdef AFS_PTHREAD_ENV
579 pthread_attr_t tattr;
584 extern afs_int32 DeleteDump();
585 extern statusP createStatusNode();
586 extern afs_int32 allocTaskId();
589 if (!CONF_XBSA) return(TC_BADTASK); /* Only do if butc is started as XBSA */
593 if ( callPermitted(acid) == 0 )
594 return(TC_NOTPERMITTED);
596 ptr = (struct deleteDumpIf *) malloc(sizeof(*ptr));
597 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
599 *taskId = allocTaskId();
600 ptr->dumpID = dumpID;
601 ptr->taskId = *taskId;
603 statusPtr = createStatusNode();
604 if (!statusPtr) ERROR_EXIT(TC_INTERNALERROR);
607 statusPtr->taskId = *taskId;
608 statusPtr->lastPolled = time(0);
609 statusPtr->flags &= ~STARTING;
610 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
613 #ifdef AFS_PTHREAD_ENV
614 code = pthread_attr_init(&tattr);
615 if (code) ERROR_EXIT(code);
617 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
618 if (code) ERROR_EXIT(code);
621 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
622 AFS_SIGSET_RESTORE();
624 code = LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process", &pid);
629 if (statusPtr) deleteStatusNode(statusPtr);
637 /* -----------------------------
639 * -----------------------------
643 CopyDumpDesc(toDump, fromDump)
644 struct tc_dumpDesc *toDump;
645 tc_dumpArray *fromDump;
647 struct tc_dumpDesc *toPtr, *fromPtr;
651 fromPtr = fromDump->tc_dumpArray_val;
652 for(i = 0 ; i < fromDump->tc_dumpArray_len; i++)
654 toPtr->vid = fromPtr->vid;
655 toPtr->vtype = fromPtr->vtype;
656 toPtr->partition = fromPtr->partition;
657 toPtr->date = fromPtr->date;
658 toPtr->cloneDate = fromPtr->cloneDate;
659 toPtr->hostAddr = fromPtr->hostAddr;
660 strcpy(toPtr->name,fromPtr->name);
668 static CopyRestoreDesc(toRestore, fromRestore)
669 struct tc_restoreDesc *toRestore;
670 tc_restoreArray *fromRestore;
672 struct tc_restoreDesc *toPtr, *fromPtr;
676 fromPtr = fromRestore->tc_restoreArray_val;
677 for(i = 0 ; i < fromRestore->tc_restoreArray_len ; i++){
678 toPtr->flags = fromPtr->flags;
679 toPtr->position = fromPtr->position;
680 strcpy(toPtr->tapeName,fromPtr->tapeName);
681 toPtr->dbDumpId = fromPtr->dbDumpId;
682 toPtr->initialDumpId = fromPtr->initialDumpId;
683 toPtr->origVid = fromPtr->origVid;
684 toPtr->vid = fromPtr->vid;
685 toPtr->partition = fromPtr->partition;
686 toPtr->dumpLevel = fromPtr->dumpLevel;
687 toPtr->hostAddr = fromPtr->hostAddr;
688 strcpy(toPtr->newName,fromPtr->newName);
689 strcpy(toPtr->oldName, fromPtr->oldName);
697 static CopyTapeSetDesc(toPtr,fromPtr)
698 struct tc_tapeSet *toPtr,*fromPtr;
701 toPtr->id = fromPtr->id;
702 toPtr->maxTapes = fromPtr->maxTapes;
703 toPtr->a = fromPtr->a;
704 toPtr->b = fromPtr->b;
705 strcpy(toPtr->tapeServer,fromPtr->tapeServer);
706 strcpy(toPtr->format,fromPtr->format);
708 toPtr->expDate = fromPtr->expDate;
709 toPtr->expType = fromPtr->expType;