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 <afs/param.h>
13 #include <sys/types.h>
19 #include <netinet/in.h>
23 #include <afs/afsint.h>
25 #include <afs/procmgmt.h>
26 #include <afs/assert.h>
27 #include <afs/prs_fs.h>
33 #include <afs/cellconfig.h>
36 #include <afs/tcdata.h>
37 #include "error_macros.h"
38 #include "butc_xbsa.h"
39 extern afs_int32 xbsaType;
46 struct rx_connection *tconn;
49 char name[MAXKTCNAMELEN];
50 char inst[MAXKTCNAMELEN];
51 char celn[MAXKTCREALMLEN];
57 /* before this code can be used, the rx connection, on the bucoord side, must */
58 /* be changed so that it will set up for token passing instead of using a */
59 /* simple rx connection that, below, returns a value of 0 from rx_SecurityClassOf */
63 /* -------------------------
64 * butc - interface routines - alphabetic order
65 * -------------------------
68 STC_LabelTape(acid, label, taskId)
70 struct tc_tapeLabel *label;
73 #ifdef AFS_PTHREAD_ENV
80 struct tc_tapeLabel *mylabel;
81 struct labelTapeIf *ptr;
85 extern int Labeller();
86 extern statusP createStatusNode();
87 extern afs_int32 allocTaskId();
90 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
93 if ( callPermitted(acid) == 0 )
94 return(TC_NOTPERMITTED);
96 ptr = (struct labelTapeIf *) malloc(sizeof(*ptr));
97 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
98 bcopy(label, &ptr->label, sizeof(ptr->label));
100 /* set up the status node */
101 *taskId = allocTaskId(); /* for bucoord */
102 ptr->taskId = *taskId;
104 statusPtr = createStatusNode();
105 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
108 statusPtr->taskId = *taskId;
109 statusPtr->lastPolled = time(0);
110 statusPtr->flags &= ~STARTING; /* ok to examine */
111 strncpy(statusPtr->taskName, "Labeltape", sizeof(statusPtr->taskName));
114 /* create the LWP to do the real work behind the scenes */
115 #ifdef AFS_PTHREAD_ENV
116 code = pthread_attr_init(&tattr);
117 if (code) ERROR_EXIT(code);
119 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
120 if (code) ERROR_EXIT(code);
123 code = pthread_create(&pid, &tattr, Labeller, ptr);
124 AFS_SIGSET_RESTORE();
126 code = LWP_CreateProcess(Labeller, 32768, 1, ptr ,"labeller process", &pid);
132 if (statusPtr) deleteStatusNode(statusPtr);
140 * Tape coordinator server routine to do a dump
143 STC_PerformDump(rxCallId, tcdiPtr, tc_dumpArrayPtr, taskId)
144 struct rx_call *rxCallId;
145 struct tc_dumpInterface *tcdiPtr;
146 tc_dumpArray *tc_dumpArrayPtr;
149 struct dumpNode *newNode = 0;
150 statusP statusPtr = 0;
151 #ifdef AFS_PTHREAD_ENV
153 pthread_attr_t tattr;
160 extern statusP createStatusNode();
163 if ( callPermitted(rxCallId) == 0 )
164 return(TC_NOTPERMITTED);
166 /* should be verifying parameter validity */
169 /* this creates a node in list, alots an id for it and prepares it for locking */
170 CreateNode(&newNode);
172 /*set up the parameters in the node, to be used by LWP */
173 strcpy(newNode->dumpSetName, tcdiPtr->dumpName);
175 newNode->dumpName = (char *) malloc(strlen(tcdiPtr->dumpPath)+1);
176 strcpy(newNode->dumpName, tcdiPtr->dumpPath);
178 newNode->volumeSetName = (char *) malloc(strlen(tcdiPtr->volumeSetName)+1);
179 strcpy(newNode->volumeSetName, tcdiPtr->volumeSetName);
181 CopyTapeSetDesc(&(newNode->tapeSetDesc), &tcdiPtr->tapeSet);
183 newNode->dumps = (struct tc_dumpDesc *)
184 malloc(sizeof(struct tc_dumpDesc) * tc_dumpArrayPtr->tc_dumpArray_len);
185 newNode->arraySize = tc_dumpArrayPtr->tc_dumpArray_len;
186 CopyDumpDesc(newNode->dumps, tc_dumpArrayPtr);
188 newNode->parent = tcdiPtr->parentDumpId;
189 newNode->level = tcdiPtr->dumpLevel;
190 newNode->doAppend = tcdiPtr->doAppend;
192 if (CONF_XBSA) newNode->doAppend = 0; /* Append flag is ignored if talking to XBSA */
195 /* create the status node */
196 statusPtr = createStatusNode();
197 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
200 statusPtr->taskId = newNode->taskID;
201 statusPtr->lastPolled = time(0);
202 statusPtr->flags &= ~STARTING; /* ok to examine */
203 strncpy(statusPtr->taskName, "Dump", sizeof(statusPtr->taskName));
206 newNode->statusNodePtr = statusPtr;
208 /* create the LWP to do the real work behind the scenes */
209 #ifdef AFS_PTHREAD_ENV
210 code = pthread_attr_init(&tattr);
211 if (code) ERROR_EXIT(code);
213 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
214 if (code) ERROR_EXIT(code);
217 code = pthread_create(&pid, &tattr, Dumper, newNode);
218 AFS_SIGSET_RESTORE();
220 code = LWP_CreateProcess(Dumper, 32768, 1, newNode, "dumper process", &pid);
222 if (code) ERROR_EXIT(code);
224 *taskId = newNode->taskID;
229 if (statusPtr) deleteStatusNode(statusPtr);
230 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
236 STC_PerformRestore(acid, dumpSetName, arestores, taskID)
237 struct rx_call *acid;
238 char *dumpSetName; /* not used */
239 tc_restoreArray *arestores;
242 struct dumpNode *newNode;
245 #ifdef AFS_PTHREAD_ENV
247 pthread_attr_t tattr;
253 extern int Restorer();
254 extern statusP createStatusNode();
256 if ( callPermitted(acid) == 0 )
257 return(TC_NOTPERMITTED);
259 /* should verify parameter validity */
261 /* this creates a node in list, alots an id for it and prepares it for locking */
262 CreateNode(&newNode);
264 newNode->restores = (struct tc_restoreDesc *)
265 malloc (sizeof(struct tc_restoreDesc) * arestores->tc_restoreArray_len);
266 newNode->arraySize = arestores->tc_restoreArray_len;
267 CopyRestoreDesc(newNode->restores,arestores);
268 *taskID = newNode->taskID;
270 /* should log the intent */
272 /* create the status node */
273 statusPtr = createStatusNode();
274 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
277 statusPtr->taskId = newNode->taskID;
278 statusPtr->flags &= ~STARTING; /* ok to examine */
279 statusPtr->lastPolled = time(0);
280 strncpy(statusPtr->taskName, "Restore", sizeof(statusPtr->taskName));
283 newNode->statusNodePtr = statusPtr;
285 /* create the LWP to do the real work behind the scenes */
286 #ifdef AFS_PTHREAD_ENV
287 code = pthread_attr_init(&tattr);
288 if (code) ERROR_EXIT(code);
290 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
291 if (code) ERROR_EXIT(code);
294 code = pthread_create(&pid, &tattr, Restorer, newNode);
295 AFS_SIGSET_RESTORE();
297 code = LWP_CreateProcess(Restorer, 65368, 1,newNode ,"restorer process", &pid);
303 if (statusPtr) deleteStatusNode(statusPtr);
304 FreeNode(newNode->taskID); /* failed to create LWP to do the dump. */
310 STC_ReadLabel(acid, label, taskId)
311 struct rx_call *acid;
312 struct tc_tapeLabel *label;
317 extern int ReadLabel();
320 if (CONF_XBSA) return(TC_BADTASK); /* ReadLabel does not apply if XBSA */
323 if ( callPermitted(acid) == 0 )
324 return(TC_NOTPERMITTED);
326 code = ReadLabel(label); /* Synchronous */
331 * restore the backup database from tape
334 STC_RestoreDb(rxCall, taskId)
335 struct rx_call *rxCall;
338 #ifdef AFS_PTHREAD_ENV
340 pthread_attr_t tattr;
348 extern afs_int32 restoreDbFromTape();
349 extern statusP createStatusNode();
350 extern afs_int32 allocTaskId();
353 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
356 if ( callPermitted(rxCall) == 0 )
357 return(TC_NOTPERMITTED);
359 *taskId = allocTaskId();
361 /* create the status node */
362 statusPtr = createStatusNode();
363 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
366 statusPtr->taskId = *taskId;
367 statusPtr->flags &= ~STARTING; /* ok to examine */
368 statusPtr->lastPolled = time(0);
369 strncpy(statusPtr->taskName, "RestoreDb", sizeof(statusPtr->taskName));
372 #ifdef AFS_PTHREAD_ENV
373 code = pthread_attr_init(&tattr);
374 if (code) ERROR_EXIT(code);
376 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
377 if (code) ERROR_EXIT(code);
380 code = pthread_create(&pid, &tattr, restoreDbFromTape, (void *)*taskId);
381 AFS_SIGSET_RESTORE();
383 code = LWP_CreateProcess(restoreDbFromTape, 32768, 1, *taskId, "Db restore", &pid);
389 if (statusPtr) deleteStatusNode(statusPtr);
396 * restore the backup database from tape
399 STC_SaveDb(rxCall, archiveTime, taskId)
400 struct rx_call *rxCall;
404 #ifdef AFS_PTHREAD_ENV
406 pthread_attr_t tattr;
413 struct saveDbIf *ptr;
415 extern afs_int32 saveDbToTape();
416 extern statusP createStatusNode();
417 extern afs_int32 allocTaskId();
420 if (CONF_XBSA) return(TC_BADTASK); /* LabelTape does not apply if XBSA */
423 if ( callPermitted(rxCall) == 0 )
424 return(TC_NOTPERMITTED);
426 *taskId = allocTaskId();
428 ptr = (struct saveDbIf *) malloc(sizeof(struct saveDbIf));
429 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
430 ptr->archiveTime = archiveTime;
431 ptr->taskId = *taskId;
433 /* create the status node */
434 statusPtr = createStatusNode();
435 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
438 statusPtr->taskId = *taskId;
439 statusPtr->lastPolled = time(0);
440 statusPtr->flags &= ~STARTING; /* ok to examine */
441 strncpy(statusPtr->taskName, "SaveDb", sizeof(statusPtr->taskName));
444 ptr->statusPtr = statusPtr;
446 #ifdef AFS_PTHREAD_ENV
447 code = pthread_attr_init(&tattr);
448 if (code) ERROR_EXIT(code);
450 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
451 if (code) ERROR_EXIT(code);
454 code = pthread_create(&pid, &tattr, saveDbToTape, ptr);
455 AFS_SIGSET_RESTORE();
457 code = LWP_CreateProcess(saveDbToTape, 32768, 1, ptr ,"Db save", &pid);
463 if (statusPtr) deleteStatusNode(statusPtr);
472 * read a dump (maybe more than one tape), and print out a summary
473 * of its contents. If the flag is set, add to the database.
475 * addDbFlag - if set, the information will be added to the database
478 STC_ScanDumps(acid, addDbFlag, taskId)
479 struct rx_call *acid;
483 #ifdef AFS_PTHREAD_ENV
485 pthread_attr_t tattr;
490 struct scanTapeIf *ptr;
494 extern afs_int32 ScanDumps();
495 extern afs_int32 allocTaskId();
496 extern statusP createStatusNode();
499 if (CONF_XBSA) return(TC_BADTASK); /* ScanDumps does not apply if XBSA */
502 if ( callPermitted(acid) == 0 )
503 return(TC_NOTPERMITTED);
505 *taskId = allocTaskId();
507 ptr = (struct scanTapeIf *) malloc(sizeof(*ptr));
508 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
509 ptr->addDbFlag = addDbFlag;
510 ptr->taskId = *taskId;
512 /* create the status node */
513 statusPtr = createStatusNode();
514 if ( !statusPtr ) ERROR_EXIT(TC_INTERNALERROR);
517 statusPtr->taskId = *taskId;
518 statusPtr->lastPolled = time(0);
519 statusPtr->flags &= ~STARTING; /* ok to examine */
520 strncpy(statusPtr->taskName, "Scantape", sizeof(statusPtr->taskName));
523 #ifdef AFS_PTHREAD_ENV
524 code = pthread_attr_init(&tattr);
525 if (code) ERROR_EXIT(code);
527 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
528 if (code) ERROR_EXIT(code);
531 code = pthread_create(&pid, &tattr, ScanDumps, ptr);
532 AFS_SIGSET_RESTORE();
534 code = LWP_CreateProcess(ScanDumps,32768, 1, ptr, "scandump process",&pid);
540 if (statusPtr) deleteStatusNode(statusPtr);
548 * return information about the tape coordinator. Currently this
549 * is just the version number of the interface
552 STC_TCInfo(acid, tciptr)
553 struct rx_call *acid;
554 struct tc_tcInfo *tciptr;
556 if ( callPermitted(acid) == 0 )
557 return(TC_NOTPERMITTED);
559 tciptr->tcVersion = CUR_BUTC_VERSION;
565 STC_DeleteDump(acid, dumpID, taskId)
566 struct rx_call *acid;
569 struct deleteDumpIf *ptr=0;
571 afs_int32 code = TC_BADTASK; /* If not compiled -Dxbsa then fail */
572 #ifdef AFS_PTHREAD_ENV
574 pthread_attr_t tattr;
579 extern afs_int32 DeleteDump();
580 extern statusP createStatusNode();
581 extern afs_int32 allocTaskId();
584 if (!CONF_XBSA) return(TC_BADTASK); /* Only do if butc is started as XBSA */
588 if ( callPermitted(acid) == 0 )
589 return(TC_NOTPERMITTED);
591 ptr = (struct deleteDumpIf *) malloc(sizeof(*ptr));
592 if (!ptr) ERROR_EXIT(TC_NOMEMORY);
594 *taskId = allocTaskId();
595 ptr->dumpID = dumpID;
596 ptr->taskId = *taskId;
598 statusPtr = createStatusNode();
599 if (!statusPtr) ERROR_EXIT(TC_INTERNALERROR);
602 statusPtr->taskId = *taskId;
603 statusPtr->lastPolled = time(0);
604 statusPtr->flags &= ~STARTING;
605 strncpy(statusPtr->taskName, "DeleteDump", sizeof(statusPtr->taskName));
608 #ifdef AFS_PTHREAD_ENV
609 code = pthread_attr_init(&tattr);
610 if (code) ERROR_EXIT(code);
612 code = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
613 if (code) ERROR_EXIT(code);
616 code = pthread_create(&pid, &tattr, DeleteDump, ptr);
617 AFS_SIGSET_RESTORE();
619 code = LWP_CreateProcess(DeleteDump, 32768, 1, ptr, "deletedump process", &pid);
624 if (statusPtr) deleteStatusNode(statusPtr);
632 /* -----------------------------
634 * -----------------------------
638 CopyDumpDesc(toDump, fromDump)
639 struct tc_dumpDesc *toDump;
640 tc_dumpArray *fromDump;
642 struct tc_dumpDesc *toPtr, *fromPtr;
646 fromPtr = fromDump->tc_dumpArray_val;
647 for(i = 0 ; i < fromDump->tc_dumpArray_len; i++)
649 toPtr->vid = fromPtr->vid;
650 toPtr->vtype = fromPtr->vtype;
651 toPtr->partition = fromPtr->partition;
652 toPtr->date = fromPtr->date;
653 toPtr->cloneDate = fromPtr->cloneDate;
654 toPtr->hostAddr = fromPtr->hostAddr;
655 strcpy(toPtr->name,fromPtr->name);
663 static CopyRestoreDesc(toRestore, fromRestore)
664 struct tc_restoreDesc *toRestore;
665 tc_restoreArray *fromRestore;
667 struct tc_restoreDesc *toPtr, *fromPtr;
671 fromPtr = fromRestore->tc_restoreArray_val;
672 for(i = 0 ; i < fromRestore->tc_restoreArray_len ; i++){
673 toPtr->flags = fromPtr->flags;
674 toPtr->position = fromPtr->position;
675 strcpy(toPtr->tapeName,fromPtr->tapeName);
676 toPtr->dbDumpId = fromPtr->dbDumpId;
677 toPtr->initialDumpId = fromPtr->initialDumpId;
678 toPtr->origVid = fromPtr->origVid;
679 toPtr->vid = fromPtr->vid;
680 toPtr->partition = fromPtr->partition;
681 toPtr->dumpLevel = fromPtr->dumpLevel;
682 toPtr->hostAddr = fromPtr->hostAddr;
683 strcpy(toPtr->newName,fromPtr->newName);
684 strcpy(toPtr->oldName, fromPtr->oldName);
692 static CopyTapeSetDesc(toPtr,fromPtr)
693 struct tc_tapeSet *toPtr,*fromPtr;
696 toPtr->id = fromPtr->id;
697 toPtr->maxTapes = fromPtr->maxTapes;
698 toPtr->a = fromPtr->a;
699 toPtr->b = fromPtr->b;
700 strcpy(toPtr->tapeServer,fromPtr->tapeServer);
701 strcpy(toPtr->format,fromPtr->format);
703 toPtr->expDate = fromPtr->expDate;
704 toPtr->expType = fromPtr->expType;