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