00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <SUM.h>
00012 #include <rpc/pmap_clnt.h>
00013 #include <sum_rpc.h>
00014 #include <soi_error.h>
00015 #include <tape.h>
00016 #include <printk.h>
00017 #include <sys/types.h>
00018 #include <sys/stat.h>
00019 #include <unistd.h>
00020 #include "serverdefs.h"
00021
00022 #define REBOOT "/usr/local/logs/SUM/RESTART_AFTER_REBOOT"
00023
00024 #define ALRMSECTO 50 //30 will give average 60sec t.o. on rd drive
00025
00026 SLOT slots[MAX_SLOTS];
00027 DRIVE drives[MAX_DRIVES];
00028 #ifdef SUMDC
00029 int drive_order[MAX_DRIVES];
00030 #else
00031 int drive_order_rd[MAX_DRIVES];
00032 int drive_order_wt[MAX_DRIVES];
00033 int nxtscanrd;
00034 int nxtscanwt;
00035 int max_drives_rd = 0;
00036 int max_drives_wt = 0;
00037 #endif
00038 int noalrm = 0;
00039 int Empty_Slot_Cnt;
00040
00041 void logkey();
00042 extern void write_time();
00043 extern int tape_inventory();
00044 extern int tape_free_drives();
00045 extern int kick_next_entry_rd();
00046 extern int kick_next_entry_wt();
00047 extern int errno;
00048 extern TQ *q_rd_front;
00049 extern TQ *q_wrt_front;
00050 extern TQ *q_need_front;
00051 extern SUMOFFCNT *offcnt_hdr;
00052 static void tapeprog_1();
00053
00054
00055 static struct timeval TIMEOUT = { 40, 0 };
00056 uint32_t rinfo, rinfox;
00057 uint32_t procnum;
00058 uint32_t sumprog, sumvers;
00059
00060 TQ *poff, *poffrd, *poffwt;
00061 FILE *logfp;
00062 CLIENT *current_client, *clntsum, *clntdrv0;
00063 CLIENT *clntrobot0;
00064 CLIENT *clntdrv[MAX_DRIVES];
00065 CLIENT *clntsums[SUM_MAXNUMSUM+1];
00066 SVCXPRT *glb_transp;
00067 int debugflg = 0;
00068 int sim = 0;
00069 int tapeoffline = 0;
00070 int robotoffline = 0;
00071 int driveonoffstatus = 0;
00072 int pactive = 0;
00073 int current_client_destroy;
00074 int alrm_sec;
00075 char *dbname;
00076 char *timetag;
00077 char thishost[MAX_STR];
00078 char sumhost[MAX_STR];
00079 char hostn[MAX_STR];
00080 char datestr[32];
00081 char libdevname[32];
00082 char heaplow[32];
00083 char heaphigh[32];
00084 char heapcln[32];
00085 static int numSUM;
00086
00087 int soi_errno = NO_ERROR;
00088
00089
00090 void open_log(char *filename)
00091 {
00092 char cmd[80];
00093
00094
00095 sprintf(cmd, "/bin/rm -f %s", filename);
00096 system(cmd);
00097 if((logfp=fopen(filename, "a+")) == NULL) {
00098 fprintf(stderr, "Can't open the log file %s\n", filename);
00099 }
00100 }
00101
00102
00103
00104
00105 static char *datestring()
00106 {
00107 struct timeval tvalr;
00108 struct tm *t_ptr;
00109
00110 gettimeofday(&tvalr, NULL);
00111 t_ptr = localtime((const time_t *)&tvalr);
00112 sprintf(datestr, "%s", asctime(t_ptr));
00113 datestr[19] = (char)NULL;
00114 return(&datestr[4]);
00115 }
00116
00117
00118
00119
00120 int write_log(const char *fmt, ...)
00121 {
00122 va_list args;
00123 char string[4096];
00124
00125 va_start(args, fmt);
00126 vsprintf(string, fmt, args);
00127 if(logfp) {
00128 fprintf(logfp, string);
00129 fflush(logfp);
00130 }
00131 else
00132 fprintf(stderr, string);
00133 va_end(args);
00134 return(0);
00135 }
00136
00137
00138 void sighandler(sig)
00139 int sig;
00140 {
00141 if(sig == SIGTERM) {
00142 write_log("*** %s tape_svc got SIGTERM. Exiting.\n", datestring());
00143 exit(1);
00144 }
00145 if(sig == SIGINT) {
00146 write_log("*** %s tape_svc got SIGINT. Exiting.\n", datestring());
00147 DS_DisConnectDB();
00148 exit(1);
00149 }
00150 write_log("*** %s tape_svc got an illegal signal %d, ignoring...\n",
00151 datestring(), sig);
00152 if (signal(SIGINT, SIG_IGN) != SIG_IGN)
00153 signal(SIGINT, sighandler);
00154 }
00155
00156
00157
00158
00159 void alrm_sig(int sig)
00160 {
00161 int d, e, tocheck, offcnt, kstatus;
00162 uint32_t ssprog;
00163 enum clnt_stat clnt_stat;
00164 SUMID_t uid;
00165 char *call_err;
00166 TQ *p;
00167 SUMOFFCNT *offptr;
00168 bool_t (*xdr_argument)(), (*xdr_result)();
00169
00170
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 if(noalrm) {
00187 signal(SIGALRM, &alrm_sig);
00188 alarm(alrm_sec);
00189 return;
00190 }
00191 tocheck = 0;
00192 for(e=0; e < max_drives_rd; e++) {
00193 d = drive_order_rd[e];
00194 if(drives[d].to) {
00195 --drives[d].tocnt;
00196 if(drives[d].tocnt == 0) {
00197 drives[d].to = 0;
00198 tocheck = 1;
00199 }
00200 }
00201 }
00202
00203 if(tocheck) {
00204
00205 if(!pactive) {
00206
00207 if((p = q_rd_front) != NULL) {
00208 write_log("Attempt to kick next rd from alrm_sig()\n");
00209 kstatus = kick_next_entry_rd();
00210 poffrd = poff;
00211
00212
00213
00214 switch(kstatus) {
00215 case 0:
00216 break;
00217 case 1:
00218 break;
00219 case 2:
00220 setkey_int(&poff->list, "STATUS", 1);
00221 uid = getkey_uint64(poff->list, "uid");
00222 offptr = getsumoffcnt(offcnt_hdr, uid);
00223 offptr->offcnt++;
00224 offcnt = getkey_int(poff->list, "offcnt");
00225 if(offcnt == offptr->offcnt) {
00226 ssprog = getkey_uint32(poff->list, "SPROG");
00227 if(offptr->sprog != ssprog) {
00228 write_log("**ERROR: Bug at alrm_sig. tape rd sprog != ssprog\n");
00229
00230 }
00231
00232 remsumoffcnt(&offcnt_hdr, uid);
00233
00234
00235
00236 switch(ssprog) {
00237 case SUMPROG:
00238 clntsum = clntsums[0];
00239 break;
00240 case SUMGET:
00241 clntsum = clntsums[1];
00242 break;
00243 case SUMGET1:
00244 clntsum = clntsums[2];
00245 break;
00246 case SUMGET2:
00247 clntsum = clntsums[3];
00248 break;
00249 case SUMGET3:
00250 clntsum = clntsums[4];
00251 break;
00252 case SUMGET4:
00253 clntsum = clntsums[5];
00254 break;
00255 case SUMGET5:
00256 clntsum = clntsums[6];
00257 break;
00258 case SUMGET6:
00259 clntsum = clntsums[7];
00260 break;
00261 case SUMGET7:
00262 clntsum = clntsums[8];
00263 break;
00264 default:
00265 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
00266 break;
00267 }
00268 clnt_stat=clnt_call(clntsum, SUMRESPDO, (xdrproc_t)xdr_result,
00269 (char *)poff->list, (xdrproc_t)xdr_void, 0, TIMEOUT);
00270 if(clnt_stat != 0) {
00271 clnt_perrno(clnt_stat);
00272 write_log("***Error in tape_svc on clnt_call() back to sum_svc SUMRESPDO\n");
00273 call_err = clnt_sperror(current_client, "Err");
00274 write_log("%s\n", call_err);
00275 }
00276 }
00277 break;
00278 }
00279 }
00280 }
00281 }
00282 signal(SIGALRM, &alrm_sig);
00283 alarm(alrm_sec);
00284 }
00285
00286
00287 void get_cmd(int argc, char *argv[])
00288 {
00289 int c;
00290
00291 while(--argc > 0 && (*++argv)[0] == '-') {
00292 while((c = *++argv[0]))
00293 switch(c) {
00294 case 'd':
00295 debugflg=1;
00296 break;
00297 case 's':
00298 sim=1;
00299 break;
00300 case 'o':
00301 tapeoffline=1;
00302 break;
00303 default:
00304 break;
00305 }
00306 }
00307 if(argc != 2) {
00308 printf("\nERROR: tape_svc must be call with dbname and timestamp\n");
00309 exit(1);
00310 }
00311 else {
00312 dbname = argv[0];
00313 timetag = argv[1];
00314 }
00315 }
00316
00317
00318 void setoffline()
00319 {
00320 FILE *drfp;
00321 int order0;
00322 char logname[MAX_STR], line[256];
00323
00324 sprintf(logname, "/usr/local/logs/SUM/drive_offline.txt");
00325 if((drfp=fopen(logname, "r")) == NULL) {
00326 fprintf(stderr, "Can't open the file %s. Proceed anyway.\n", logname);
00327 }
00328 else {
00329 while(fgets(line, 256, drfp)) {
00330 if(!strncmp(line, "#", 1)) {
00331 continue;
00332 }
00333 sscanf(line, "%d", &order0);
00334 if(order0 >= MAX_DRIVES) {
00335 write_log("Error drivenum >= MAX_DRIVES (%d)\n", MAX_DRIVES);
00336 write_log("Can't take drive %d offline.\n", order0);
00337 fclose(drfp);
00338 return;
00339 }
00340 sprintf(line, "take drive %d offline", order0);
00341 printf("%s\n", line);
00342 write_log("%s\n", line);
00343 drives[order0].offline = 1;
00344
00345 }
00346 }
00347 fclose(drfp);
00348 }
00349
00350
00351 void setup()
00352 {
00353 FILE *sgfp, *drfp;
00354 int pid, ppid, order0, neworder, i;
00355 char *cptr, *token;
00356 char logname[MAX_STR], line[256], rwchars[32];
00357
00358 numSUM = SUM_NUMSUM;
00359
00360
00361
00362 sprintf(thishost, "localhost");
00363 gethostname(hostn, MAX_STR);
00364 cptr = index(hostn, '.');
00365 if(cptr) *cptr = (char)NULL;
00366 cptr = datestring();
00367 ppid = getppid();
00368 pid = getpid();
00369 sprintf(logname, "/usr/local/logs/SUM/xtape_svc_%s.log", timetag);
00370
00371 open_log(logname);
00372 printk_set(write_log, write_log);
00373 write_log("\n## %s xtape_svc on %s for pid = %d ##\n",
00374 datestring(), thishost, pid);
00375 write_log("Database to connect to is %s\n", dbname);
00376 #ifdef SUMDC
00377 sprintf(logname, "/usr/local/logs/SUM/drive_order.txt");
00378 if((drfp=fopen(logname, "r")) == NULL) {
00379 fprintf(stderr, "Can't open the file file %s\n", logname);
00380 order0 = 0;
00381 }
00382 else {
00383 fgets(line, 256, drfp);
00384 sscanf(line, "%d", &order0);
00385 }
00386 fclose(drfp);
00387 neworder = order0 + 1;
00388 if(neworder >= MAX_DRIVES) neworder = 0;
00389 drfp=fopen(logname, "w");
00390 fprintf(drfp, "%d", neworder);
00391 fclose(drfp);
00392 for(i=0; i < MAX_DRIVES; i++) {
00393 drive_order[i] = order0;
00394
00395 order0++;
00396 if(order0 >= MAX_DRIVES) order0 = 0;
00397 }
00398 #else
00399 sprintf(logname, "/usr/local/logs/SUM/drive_order_rw.txt");
00400 if((drfp=fopen(logname, "r")) == NULL) {
00401 fprintf(stderr, "Can't open the file file %s\n", logname);
00402 exit(1);
00403 }
00404 else {
00405 i = 0;
00406
00407 while(fgets(line, 256, drfp)) {
00408 if(!strncmp(line, "#", 1)) {
00409 continue;
00410 }
00411 sscanf(line, "%d %s", &order0, rwchars);
00412 write_log("rw = %s drive# = %d\n", rwchars, order0);
00413 if(!strcmp(rwchars, "rd")) {
00414 drive_order_rd[i] = order0;
00415 max_drives_rd++;
00416 }
00417 else if(!strcmp(rwchars, "wt")) {
00418 drive_order_wt[i] = order0;
00419 max_drives_wt++;
00420 }
00421 else {
00422 printf("%s is incorrect format\n", logname);
00423 exit(1);
00424 }
00425 i++;
00426 }
00427 nxtscanrd = 0;
00428 nxtscanwt = max_drives_rd;
00429 write_log("max_drives_rd = %d, max_drives_wt = %d\n",
00430 max_drives_rd, max_drives_wt);
00431 }
00432 fclose(drfp);
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 #endif
00460 alrm_sec = ALRMSECTO;
00461
00462 signal(SIGINT, sighandler);
00463 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
00464 signal(SIGTERM, sighandler);
00465 signal(SIGALRM, &alrm_sig);
00466 alarm(180);
00467
00468 sprintf(libdevname, "%s", LIBDEV);
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 }
00486
00487
00488 int main(int argc, char *argv[])
00489 {
00490 register SVCXPRT *transp;
00491 struct stat sbuf;
00492 char cmd[80];
00493 int retry, istat, i;
00494
00495 get_cmd(argc, argv);
00496 setup();
00497
00498
00499 (void) pmap_unset(TAPEPROG, TAPEVERS);
00500
00501 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
00502 if (transp == NULL) {
00503 write_log("***cannot create tcp service\n");
00504 exit(1);
00505 }
00506 if (!svc_register(transp, TAPEPROG, TAPEVERS, tapeprog_1, IPPROTO_TCP)) {
00507 write_log("***unable to register (TAPEPROG, TAPEVERS, tcp)\n");
00508 exit(1);
00509 }
00510
00511 if(strcmp(hostn, TAPEHOST)) {
00512 sprintf(sumhost, TAPEHOST);
00513 }
00514 else {
00515 sprintf(sumhost, SUMSVCHOST);
00516 }
00517
00518 sprintf(sumhost, "xim");
00519
00520
00521
00522
00523 sleep(30);
00524
00525
00526 for(i=0; i < MAX_DRIVES; i++) {
00527
00528 clntdrv0 = clnt_create(thishost, DRIVE0PROG+i, DRIVE0VERS, "tcp");
00529 if(!clntdrv0) {
00530 clnt_pcreateerror("Can't get client handle to driven_svc in tape_svc");
00531 write_log("***tape_svc can't get drive%d_svc on %s for %u\n",
00532 i, thishost, DRIVE0PROG+i);
00533
00534
00535 }
00536 else { write_log("##tape_svc gets handle for drive%d_svc for %u\n",
00537 i, DRIVE0PROG+i); }
00538 clntdrv[i] = clntdrv0;
00539 }
00540 clntrobot0 = clnt_create(thishost, ROBOT0PROG, ROBOT0VERS, "tcp");
00541 if(!clntrobot0) {
00542 clnt_pcreateerror("Can't get client handle to xrobot0_svc in tape_svc");
00543 write_log("***xtape_svc can't get xrobot0_svc on %s\n", thishost);
00544 exit(1);
00545 }
00546
00547
00548
00549
00550 clntsum = clnt_create(sumhost, SUMPROG, SUMVERS, "tcp");
00551 if(!clntsum) {
00552 clnt_pcreateerror("Can't get client handle to SUMPROG in tape_svc");
00553 write_log("***tape_svc can't get handle to SUMPROG on %s\n", sumhost);
00554 exit(1);
00555 }
00556 clntsums[0] = clntsum;
00557
00558 if(numSUM >= 2) {
00559 clntsum = clnt_create(sumhost, SUMGET, SUMGETV, "tcp");
00560 if(!clntsum) {
00561 clnt_pcreateerror("Can't get client handle to SUMGET in tape_svc");
00562 write_log("***tape_svc can't get handle to SUMGET on %s\n", sumhost);
00563 exit(1);
00564 }
00565 clntsums[1] = clntsum;
00566 clntsum = clnt_create(sumhost, SUMGET1, SUMGETV, "tcp");
00567 if(!clntsum) {
00568 clnt_pcreateerror("Can't get client handle to SUMGET1 in tape_svc");
00569 write_log("***tape_svc can't get handle to SUMGET1 on %s\n", sumhost);
00570 exit(1);
00571 }
00572 clntsums[2] = clntsum;
00573 }
00574 if(numSUM >= 3) {
00575 clntsum = clnt_create(sumhost, SUMGET2, SUMGETV, "tcp");
00576 if(!clntsum) {
00577 clnt_pcreateerror("Can't get client handle to SUMGET2 in tape_svc");
00578 write_log("***tape_svc can't get handle to SUMGET2 on %s\n", sumhost);
00579 exit(1);
00580 }
00581 clntsums[3] = clntsum;
00582 }
00583 if(numSUM >= 4) {
00584 clntsum = clnt_create(sumhost, SUMGET3, SUMGETV, "tcp");
00585 if(!clntsum) {
00586 clnt_pcreateerror("Can't get client handle to SUMGET3 in tape_svc");
00587 write_log("***tape_svc can't get handle to SUMGET3 on %s\n", sumhost);
00588 exit(1);
00589 }
00590 clntsums[4] = clntsum;
00591 }
00592 if(numSUM >= 5) {
00593 clntsum = clnt_create(sumhost, SUMGET4, SUMGETV, "tcp");
00594 if(!clntsum) {
00595 clnt_pcreateerror("Can't get client handle to SUMGET4 in tape_svc");
00596 write_log("***tape_svc can't get handle to SUMGET4 on %s\n", sumhost);
00597 exit(1);
00598 }
00599 clntsums[5] = clntsum;
00600 }
00601 if(numSUM >= 6) {
00602 clntsum = clnt_create(sumhost, SUMGET5, SUMGETV, "tcp");
00603 if(!clntsum) {
00604 clnt_pcreateerror("Can't get client handle to SUMGET5 in tape_svc");
00605 write_log("***tape_svc can't get handle to SUMGET5 on %s\n", sumhost);
00606 exit(1);
00607 }
00608 clntsums[6] = clntsum;
00609 }
00610 if(numSUM >= 7) {
00611 clntsum = clnt_create(sumhost, SUMGET6, SUMGETV, "tcp");
00612 if(!clntsum) {
00613 clnt_pcreateerror("Can't get client handle to SUMGET6 in tape_svc");
00614 write_log("***tape_svc can't get handle to SUMGET6 on %s\n", sumhost);
00615 exit(1);
00616 }
00617 clntsums[7] = clntsum;
00618 }
00619 if(numSUM >= 8) {
00620 clntsum = clnt_create(sumhost, SUMGET7, SUMGETV, "tcp");
00621 if(!clntsum) {
00622 clnt_pcreateerror("Can't get client handle to SUMGET7 in tape_svc");
00623 write_log("***tape_svc can't get handle to SUMGET7 on %s\n", sumhost);
00624 exit(1);
00625 }
00626 clntsums[8] = clntsum;
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638 DS_ConnectDB(dbname);
00639
00640
00641
00642
00643
00644
00645
00646
00647 if(tapeoffline == 0) {
00648 retry = 6;
00649
00650 while(retry) {
00651 #ifdef SUMDC
00652 if((istat = tape_inventory(sim, 1)) == 0) {
00653 #else
00654 if((istat = tape_inventory(sim, 0)) == 0) {
00655 #endif
00656 write_log("***Error: Can't do tape inventory. Will retry...\n");
00657 --retry;
00658 if(retry == 0) {
00659 write_log("***Fatal error: Can't do tape inventory\n");
00660 (void) pmap_unset(TAPEPROG, TAPEVERS);
00661 exit(1);
00662 }
00663 continue;
00664 }
00665 if(istat == -1) {
00666 --retry;
00667 if(retry == 0) {
00668 write_log("***Fatal error: Can't do tape inventory\n");
00669 (void) pmap_unset(TAPEPROG, TAPEVERS);
00670 exit(1);
00671 }
00672 }
00673 else { retry = 0; }
00674 }
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 }
00695
00696
00697
00698
00699
00700 svc_run();
00701 write_log("!!!Fatal Error: svc_run() returned in tape_svc\n");
00702 exit(1);
00703 }
00704
00705
00706
00707
00708 static void
00709 tapeprog_1(rqstp, transp)
00710 struct svc_req *rqstp;
00711 SVCXPRT *transp;
00712 {
00713 char *result, *call_err;
00714 int force = 0;
00715 int rdflg = 0;
00716 uint32_t sprog;
00717 enum clnt_stat clnt_stat;
00718 SUMOFFCNT *offptr;
00719 SUMID_t uid;
00720 int kstatus, offcnt, errorcase;
00721 TQ *p;
00722 union __svcargun {
00723 Rkey tapedo_1_arg;
00724 } argument;
00725 uint32_t spare;
00726
00727 bool_t (*xdr_argument)(), (*xdr_result)();
00728 char *(*local)();
00729 pactive = 1;
00730 rinfox = 1;
00731 switch (rqstp->rq_proc) {
00732 case NULLPROC:
00733 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00734 pactive = 0;
00735 return;
00736 case READDO:
00737 if(tapeoffline) rinfox = SUM_TAPE_SVC_OFF;
00738 xdr_argument = xdr_Rkey;
00739 xdr_result = xdr_Rkey;;
00740 local = (char *(*)()) readdo_1;
00741 break;
00742 case WRITEDO:
00743 if(tapeoffline) rinfox = SUM_TAPE_SVC_OFF;
00744 xdr_argument = xdr_Rkey;
00745 xdr_result = xdr_Rkey;
00746 local = (char *(*)()) writedo_1;
00747 break;
00748 case TAPERESPREADDO:
00749 rdflg = 1;
00750 xdr_argument = xdr_Rkey;
00751 xdr_result = xdr_Rkey;
00752 local = (char *(*)()) taperespreaddo_1;
00753 break;
00754 case TAPERESPWRITEDO:
00755 xdr_argument = xdr_Rkey;
00756 xdr_result = xdr_Rkey;
00757 local = (char *(*)()) taperespwritedo_1;
00758 break;
00759 case TAPERESPROBOTDO:
00760 force = 1;
00761 xdr_argument = xdr_Rkey;
00762 xdr_result = xdr_Rkey;
00763 local = (char *(*)()) taperesprobotdo_1;
00764 break;
00765 case TAPERESPROBOTDOORDO:
00766 xdr_argument = xdr_Rkey;
00767 xdr_result = xdr_Rkey;
00768 local = (char *(*)()) taperesprobotdoordo_1;
00769 break;
00770 case IMPEXPDO:
00771 xdr_argument = xdr_Rkey;
00772 xdr_result = xdr_uint32_t;
00773 local = (char *(*)()) impexpdo_1;
00774 break;
00775 case EXPCLOSEDO:
00776 force = 1;
00777 xdr_argument = xdr_Rkey;
00778 xdr_result = xdr_uint32_t;
00779 local = (char *(*)()) expclosedo_1;
00780 break;
00781 case TAPETESTDO:
00782 xdr_argument = xdr_Rkey;
00783 xdr_result = xdr_Rkey;
00784 local = (char *(*)()) tapetestdo_1;
00785 break;
00786 case ONOFFDO:
00787 force = 1;
00788 xdr_argument = xdr_Rkey;
00789 xdr_result = xdr_uint32_t;
00790 local = (char *(*)()) onoffdo_1;
00791 break;
00792 case ROBOTONOFFDO:
00793 force = 1;
00794 xdr_argument = xdr_Rkey;
00795 xdr_result = xdr_uint32_t;
00796 local = (char *(*)()) robotonoffdo_1;
00797 break;
00798 case DRONOFFDO:
00799 force = 1;
00800 xdr_argument = xdr_Rkey;
00801 xdr_result = xdr_uint32_t;
00802 local = (char *(*)()) dronoffdo_1;
00803 break;
00804 case JMTXTAPEDO:
00805 force = 1;
00806 xdr_argument = xdr_Rkey;
00807 xdr_result = xdr_Rkey;
00808 local = (char *(*)()) jmtxtapedo_1;
00809 break;
00810 case TAPENOPDO:
00811 force = 1;
00812 xdr_argument = xdr_Rkey;
00813 xdr_result = xdr_uint32_t;
00814 local = (char *(*)()) tapenopdo_1;
00815 break;
00816 case CLNTGONE:
00817 xdr_argument = xdr_Rkey;
00818 xdr_result = xdr_Rkey;
00819 local = (char *(*)()) clntgone_1;
00820 break;
00821 default:
00822 write_log("**tapeprog_1() dispatch default procedure %d,ignore\n", rqstp->rq_proc);
00823 svcerr_noproc(transp);
00824 pactive = 0;
00825 return;
00826 }
00827 bzero((char *)&argument, sizeof(argument));
00828 if (!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00829 write_log("***Error on svc_getargs()\n");
00830 svcerr_decode(transp);
00831 svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
00832 pactive = 0;
00833 return;
00834 }
00835 glb_transp = transp;
00836 poff = NULL;
00837 current_client_destroy = 0;
00838 if((tapeoffline) && (!force)) {
00839 rinfo = rinfox;
00840 send_ack();
00841 result = (KEY *)1;
00842 }
00843 else {
00844
00845 result = (*local)(&argument, rqstp);
00846 }
00847 if(result) {
00848 if(result == (char *)1) {
00849
00850 }
00851 else {
00852 if(debugflg) {
00853 write_log("\nKEYS in tape_svc response are:\n");
00854 keyiterate(logkey, (KEY *)result);
00855 }
00856 if(current_client == 0) {
00857 write_log("***Error on clnt_call() back to orig tape_svc caller\n");
00858 write_log(" current_client was NULL\n");
00859 }
00860 else {
00861 sprintf(heapcln, "%lx", current_client);
00862 write_log("current_client = %s\n", heapcln);
00863
00864
00865
00866
00867
00868
00869 write_log("!!TEMP return ans to xtape_svc caller. uid=%lu\n",
00870 getkey_uint64(result, "uid"));
00871 clnt_stat=clnt_call(current_client, procnum, (xdrproc_t)xdr_result,
00872 result, (xdrproc_t)xdr_void, 0, TIMEOUT);
00873 if(clnt_stat != 0) {
00874 clnt_perrno(clnt_stat);
00875 write_log("***Error in tape_svc on clnt_call() back to %ld procedure\n", procnum);
00876 call_err = clnt_sperror(current_client, "Err");
00877 write_log("%s %s\n", datestring(), call_err);
00878 }
00879 if(current_client_destroy) clnt_destroy(current_client);
00880
00881 }
00882 freekeylist((KEY **)&result);
00883 }
00884 if(poff) {
00885
00886 free(poff->tapeid);
00887 free(poff->username);
00888 freekeylist((KEY **)&poff->list);
00889 free(poff);
00890 poff = NULL;
00891 }
00892 }
00893 if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
00894 write_log("***unable to free arguments\n");
00895
00896 }
00897
00898 if((p = q_rd_front) != NULL) {
00899 kstatus = kick_next_entry_rd();
00900 poffrd = poff;
00901
00902
00903
00904 switch(kstatus) {
00905 case 0:
00906 break;
00907 case 1:
00908 break;
00909 case 2:
00910 setkey_int(&poff->list, "STATUS", 1);
00911 uid = getkey_uint64(poff->list, "uid");
00912 offptr = getsumoffcnt(offcnt_hdr, uid);
00913 offptr->offcnt++;
00914 offcnt = getkey_int(poff->list, "offcnt");
00915 if(offcnt == offptr->offcnt) {
00916 remsumoffcnt(&offcnt_hdr, uid);
00917
00918 sprog = getkey_uint32(poff->list, "SPROG");
00919 if(offptr->sprog != sprog) {
00920 write_log("**ERROR: Bug. In tape rd sprog != sumprog\n");
00921 sprog = offptr->sprog;
00922 }
00923
00924
00925
00926 switch(sprog) {
00927 case SUMPROG:
00928 clntsum = clntsums[0];
00929 break;
00930 case SUMGET:
00931 clntsum = clntsums[1];
00932 break;
00933 case SUMGET1:
00934 clntsum = clntsums[2];
00935 break;
00936 case SUMGET2:
00937 clntsum = clntsums[3];
00938 break;
00939 case SUMGET3:
00940 clntsum = clntsums[4];
00941 break;
00942 case SUMGET4:
00943 clntsum = clntsums[5];
00944 break;
00945 case SUMGET5:
00946 clntsum = clntsums[6];
00947 break;
00948 case SUMGET6:
00949 clntsum = clntsums[7];
00950 break;
00951 case SUMGET7:
00952 clntsum = clntsums[8];
00953 break;
00954 default:
00955 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
00956 break;
00957 }
00958 clnt_stat=clnt_call(clntsum, SUMRESPDO, (xdrproc_t)xdr_result,
00959 (char *)poff->list, (xdrproc_t)xdr_void, 0, TIMEOUT);
00960 if(clnt_stat != 0) {
00961 clnt_perrno(clnt_stat);
00962 write_log("***Error in tape_svc on clnt_call() back to sum_svc SUMRESPDO\n");
00963 call_err = clnt_sperror(current_client, "Err");
00964 write_log("%s\n", call_err);
00965 }
00966 }
00967 break;
00968 }
00969 }
00970 while((p = q_wrt_front) != NULL) {
00971 errorcase = 0;
00972 kstatus = kick_next_entry_wt();
00973 poffwt = poff;
00974
00975
00976
00977 switch(kstatus) {
00978 case 0:
00979 break;
00980 case 1:
00981 break;
00982 case 2: case 3:
00983 setkey_int(&poff->list, "STATUS", 1);
00984 uid = getkey_uint64(poff->list, "uid");
00985 errorcase = 1;
00986
00987
00988
00989
00990
00991
00992 sumprog = getkey_uint32(poff->list, "SPROG");
00993
00994
00995 switch(sumprog) {
00996 case SUMPROG:
00997 clntsum = clntsums[0];
00998 break;
00999 case SUMGET:
01000 clntsum = clntsums[1];
01001 break;
01002 case SUMGET1:
01003 clntsum = clntsums[2];
01004 break;
01005 case SUMGET2:
01006 clntsum = clntsums[3];
01007 break;
01008 case SUMGET3:
01009 clntsum = clntsums[4];
01010 break;
01011 case SUMGET4:
01012 clntsum = clntsums[5];
01013 break;
01014 case SUMGET5:
01015 clntsum = clntsums[6];
01016 break;
01017 case SUMGET6:
01018 clntsum = clntsums[7];
01019 break;
01020 case SUMGET7:
01021 clntsum = clntsums[8];
01022 break;
01023 default:
01024 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
01025 break;
01026 }
01027 clnt_stat=clnt_call(clntsum, SUMRESPDO, (xdrproc_t)xdr_result,
01028 (char *)poff->list, (xdrproc_t)xdr_void, 0, TIMEOUT);
01029 if(clnt_stat != 0) {
01030 clnt_perrno(clnt_stat);
01031 write_log("***Error in tape_svc on clnt_call() back to sum_svc SUMRESPDO\n");
01032 call_err = clnt_sperror(current_client, "Err");
01033 write_log("%s\n", call_err);
01034 }
01035
01036
01037 break;
01038 }
01039 if(errorcase == 0) break;
01040 }
01041 if(poffrd) {
01042
01043 free(poffrd->tapeid);
01044 free(poffrd->username);
01045 freekeylist((KEY **)&poffrd->list);
01046 free(poffrd);
01047 poffrd = NULL;
01048 }
01049 if(poffwt) {
01050
01051 free(poffwt->tapeid);
01052 free(poffwt->username);
01053 freekeylist((KEY **)&poffwt->list);
01054 free(poffwt);
01055 poffwt = NULL;
01056 }
01057 poff = NULL;
01058 pactive = 0;
01059 return;
01060 }