00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <SUM.h>
00011 #include <sys/time.h>
00012 #include <rpc/pmap_clnt.h>
00013 #include <soi_error.h>
00014 #include <sum_rpc.h>
00015 #include <tape.h>
00016 #include <printk.h>
00017
00018 extern int write_log();
00019 extern int tapeindrive();
00020 extern int tapeinslot();
00021 extern void rd_q_print();
00022 extern void tq_entry_rd_dump2();
00023 extern void insert_tq_entry_rd_sort();
00024 extern void insert_tq_entry_rd_need();
00025 extern void insert_tq_entry_wrt_need();
00026 extern int find_empty_impexp_slot();
00027 extern TQ *delete_q_rd_need_front();
00028 extern TQ *delete_q_wrt_need_front();
00029 extern CLIENT *current_client, *clntsum, *clntdrv0, *clntdrv1;
00030 extern CLIENT *clntdrv2, *clntdrv3;
00031 extern CLIENT *clntdrv[];
00032 extern CLIENT *clntsums[];
00033 extern CLIENT *clntrobot0;
00034 extern SVCXPRT *glb_transp;
00035 #ifdef SUMDC
00036 extern int drive_order[];
00037 int nxtscanrd = 0;
00038 int nxtscanwt = 0;
00039 #else
00040 extern int drive_order_rd[];
00041 extern int drive_order_wt[];
00042 extern int nxtscanrd;
00043 extern int nxtscanwt;
00044 extern int max_drives_rd;
00045 extern int max_drives_wt;
00046 #endif
00047
00048 extern uint32_t rinfo;
00049 extern uint32_t procnum;
00050 extern uint32_t sumprog;
00051 extern uint32_t sumvers;
00052 extern int debugflg;
00053 extern int current_client_destroy;
00054 extern int sim;
00055 extern int tapeoffline;
00056 extern int robotoffline;
00057 extern int driveonoffstatus;
00058 extern int noalrm;
00059 extern char libdevname[];
00060 extern char hostn[];
00061 extern char sumhost[];
00062 extern SLOT slots[];
00063 extern DRIVE drives[];
00064 extern TQ *poff;
00065
00066 SUMOPENED *rdexitopened_hdr = NULL;
00067
00068 TQ *q_rd_front = NULL;
00069 TQ *q_rd_rear = NULL;
00070 TQ *q_wrt_front = NULL;
00071 TQ *q_wrt_rear = NULL;
00072 TQ *q_rd_need_front = NULL;
00073 TQ *q_rd_need_rear = NULL;
00074 TQ *q_wrt_need_front = NULL;
00075 TQ *q_wrt_need_rear = NULL;
00076 SUMOFFCNT *offcnt_hdr = NULL;
00077
00078 int robotbusy = 0;
00079 int robotcmdseq = 0;
00080 int eeactive = 0;
00081 int full_impexp_slotnum_internal[NUM_IMP_EXP_SLOTS];
00082 int empty_slotnum_internal[NUM_IMP_EXP_SLOTS];
00083 char dstring[32];
00084 char datestr[32];
00085 void write_time();
00086 int send_mail(char *fmt, ...);
00087 void logkey ();
00088 char *find_tape_from_group();
00089 KEY *taperesprobotdo_1_rd(KEY *params);
00090 KEY *taperesprobotdo_1_wt(KEY *params);
00091 static struct timeval TIMEOUT = { 120, 0 };
00092
00093 static struct timeval first[5], second[5];
00094 float ftmp;
00095
00096
00097 void StartTimer(int n)
00098 {
00099 gettimeofday (&first[n], NULL);
00100 }
00101
00102 float StopTimer(int n)
00103 {
00104 gettimeofday (&second[n], NULL);
00105 if (first[n].tv_usec > second[n].tv_usec) {
00106 second[n].tv_usec += 1000000;
00107 second[n].tv_sec--;
00108 }
00109 return (float) (second[n].tv_sec-first[n].tv_sec) +
00110 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00111 }
00112
00113
00114
00115
00116 char *datestring()
00117 {
00118 struct timeval tvalr;
00119 struct tm *t_ptr;
00120
00121 gettimeofday(&tvalr, NULL);
00122 t_ptr = localtime((const time_t *)&tvalr);
00123 sprintf(datestr, "%s", asctime(t_ptr));
00124 datestr[19] = (char)NULL;
00125 return(&datestr[4]);
00126 }
00127
00128
00129
00130 CLIENT *set_client_handle(uint32_t prognum, uint32_t versnum)
00131 {
00132 static CLIENT *client;
00133 struct sockaddr_in *sock_in;
00134 int sock = RPC_ANYSOCK;
00135
00136
00137
00138
00139
00140 sock_in = svc_getcaller(glb_transp);
00141 sock_in->sin_port = 0;
00142 client = clnttcp_create(sock_in,prognum,versnum,&sock,0,0);
00143 if(!client) {
00144 clnt_pcreateerror("Can't do a clnttcp_create to send a response");
00145 write_time();
00146 write_log("**** Can't do a clnttcp_create to send a response ****\n");
00147 write_log("**** prognum=0x%x versnum=%d ****\n", prognum, versnum);
00148 write_log("**** Did someone remove us from the portmapper? ****\n");
00149 return(0);
00150 }
00151
00152 current_client = client;
00153 return(client);
00154 }
00155
00156
00157
00158
00159
00160
00161 void send_ack()
00162 {
00163
00164 if (!svc_sendreply(glb_transp, (xdrproc_t)xdr_uint32_t, (char *)&rinfo)) {
00165 write_log("***Error on immed ack back to client. FATAL???\n");
00166 svcerr_systemerr(glb_transp);
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 int kick_next_entry_rd() {
00183 TQ *p, *ptmp;
00184 uint32_t driveback, robotback;
00185 int d, e, snum, sback;
00186 char cmd[80];
00187 char *call_err, *tapeid;
00188 enum clnt_stat status;
00189
00190 noalrm = 1;
00191 poff = NULL;
00192 sback = 0;
00193 robotback = 0;
00194 p = q_rd_front;
00195
00196 while(p) {
00197 if((d=tapeindrive(p->tapeid)) != -1) {
00198 if(drives[d].busy || drives[d].offline) {
00199 p = p->next;
00200 continue;
00201 }
00202
00203 if(drives[d].to && (drives[d].sumid != p->uid)) {
00204 p = p->next;
00205 continue;
00206 }
00207 else {
00208 if(poff) {
00209 free(poff->tapeid);
00210 free(poff->username);
00211 freekeylist((KEY **)&poff->list);
00212 free(poff);
00213 }
00214 setkey_int(&p->list, "dnum", d);
00215 poff = delete_q_rd(p);
00216 write_log("*Tp:RdQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00217 drives[d].busy = 1;
00218 drives[d].sumid = p->uid;
00219 write_log("*Tp:DrBusy: drv=%d\n", d);
00220 drives[d].tapemode = TAPE_RD_CONT;
00221 if(drives[d].filenum == -1)
00222 setkey_int(&poff->list, "tapemode", TAPE_RD_INIT);
00223 else
00224 setkey_int(&poff->list, "tapemode", TAPE_RD_CONT);
00225 setkey_int(&poff->list, "filenum", drives[d].filenum);
00226
00227 write_log("kick_next_entry_rd(): clnt_call( READDRVDO ): drv=%d uid=%lu \n", d, p->uid);
00228 status = clnt_call(clntdrv[d], READDRVDO, (xdrproc_t)xdr_Rkey,
00229 (char *)poff->list, (xdrproc_t)xdr_uint32_t,(char *)&driveback,TIMEOUT);
00230 if(status != RPC_SUCCESS) {
00231 if(status != RPC_TIMEDOUT) {
00232 call_err = clnt_sperror(clntdrv[d], "Err clnt_call for READDRVDO");
00233 drives[d].busy = 0;
00234 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00235 write_log("%s %s\n", datestring(), call_err);
00236 noalrm = 0;
00237 return(2);
00238 } else {
00239 write_log("%s timeout occured for READDRVDO drv#%d in kick_next_entry_rd()\n", datestring(), d);
00240 }
00241 }
00242 if(driveback == 1) {
00243 drives[d].busy = 0;
00244 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00245 write_log("**Error in kick_next_entry_rd() in tape_svc_proc.c\n");
00246 noalrm = 0;
00247 return(2);
00248 }
00249 sback = 1;
00250 p = poff->next;
00251 continue;
00252 }
00253 }
00254 p = p->next;
00255 }
00256
00257
00258 p = q_rd_front;
00259 while(p) {
00260 if(eeactive) {
00261 sback = 0;
00262 break;
00263 }
00264 if((d=tapeindrive(p->tapeid)) != -1) {
00265 if(drives[d].busy || drives[d].offline) {
00266 p = p->next;
00267 continue;
00268 }
00269
00270 if(drives[d].to && (drives[d].sumid != p->uid)) {
00271 p = p->next;
00272 continue;
00273 }
00274 }
00275
00276 if(((snum=tapeinslot(p->tapeid)) == -1) && (d == -1)) {
00277 #ifdef SUMDC
00278
00279 write_log("*Tp:Need:Rd tapeid=%s is not in live slots\n", p->tapeid);
00280 #else
00281 write_log("*Tp:Need: tapeid=%s is not in live slots\n", p->tapeid);
00282 #endif
00283 send_mail("tapeid=%s is not in live slot\n", p->tapeid);
00284 ptmp = delete_q_rd(p);
00285 p = p->next;
00286 ptmp->next = NULL;
00287 write_log("*Tp:RdQdel: dsix=%lu drv=**WRN:tape_not_in_robot\n",
00288 ptmp->ds_index);
00289 insert_tq_entry_rd_need(ptmp);
00290 write_log("NEED RD Q:\n");
00291
00292 sback = 0;
00293 continue;
00294 }
00295
00296 #ifdef SUMDC
00298 for(e=0; e < MAX_DRIVES; e++) {
00299 d = drive_order[e];
00300 if((!drives[d].tapeid) && (!drives[d].offline)) break;
00301 }
00302 if(e == MAX_DRIVES) {
00303 for(e=0; e < MAX_DRIVES; e++) {
00304 d = drive_order[nxtscanrd++];
00305 if(nxtscanrd >= MAX_DRIVES) nxtscanrd = 0;
00306 if((!drives[d].busy) && (!drives[d].offline)) break;
00307 }
00308 }
00309 if(e == MAX_DRIVES) {
00310 sback = 0;
00311 break;
00312 }
00313 #else
00314 for(e=0; e < max_drives_rd; e++) {
00315 d = drive_order_rd[e];
00316
00317 if(drives[d].to && (drives[d].sumid != p->uid)) continue;
00318 if(drives[d].busy) continue;
00319 if((!drives[d].tapeid) && (!drives[d].offline)) break;
00320 }
00321 if(e == max_drives_rd) {
00322 for(e=0; e < max_drives_rd; e++) {
00323 d = drive_order_rd[nxtscanrd++];
00324 if(nxtscanrd >= max_drives_rd) nxtscanrd = 0;
00325 if(drives[d].to && (drives[d].sumid != p->uid)) continue;
00326 if((!drives[d].busy) && (!drives[d].offline)) break;
00327 }
00328 }
00329 if(e == max_drives_rd) {
00330 sback = 0;
00331 break;
00332 }
00333 #endif
00334
00335 if(robotbusy) {
00336 sback = 0;
00337 break;
00338 }
00339 write_log("Dr%d found for Rd at index=%d\n", d, e);
00340 robotbusy = 1;
00341 drives[d].busy = 1;
00342 drives[d].sumid = p->uid;
00343 write_log("*Tp:DrBusy: drv=%d\n", d);
00344 setkey_int(&p->list, "dnum", d);
00345 setkey_int(&p->list, "snum", snum);
00346 if(tapeid = drives[d].tapeid) {
00347 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00348 libdevname, (drives[d].slotnum)+1, d, robotcmdseq++);
00349 setkey_str(&p->list, "cmd1", cmd);
00350 sprintf(cmd,"mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00351 libdevname, snum+1, d, robotcmdseq++);
00352 setkey_str(&p->list, "cmd2", cmd);
00353 }
00354 else {
00355 sprintf(cmd,"mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00356 libdevname, snum+1, d, robotcmdseq++);
00357 setkey_str(&p->list, "cmd1", cmd);
00358 }
00359
00360
00361 StartTimer(3);
00362 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)p->list,
00363 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
00364 ftmp = StopTimer(3);
00365 write_log("Time 3 for ROBOTDO in tape_svc = %f sec\n", ftmp);
00366 if(status != RPC_SUCCESS) {
00367 if(status != RPC_TIMEDOUT) {
00368 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
00369 write_log("%s %s\n", datestring(), call_err);
00370 robotbusy = 0;
00371 drives[d].busy = 0;
00372 drives[d].sumid = 0;
00373 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00374 poff = delete_q_rd(p);
00375 write_log("*Tp:RdQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00376 sback = 2;
00377 break;
00378 } else {
00379
00380 write_log("%s timeout occured for ROBOTDO in kick_next_entry_rd() \n",
00381 datestring());
00382 }
00383 }
00384 if(robotback == 1) {
00385 write_log("**Error in ROBOTDO call in tape_svc_proc.c\n");
00386 robotbusy = 0;
00387 drives[d].busy = 0;
00388 drives[d].sumid = 0;
00389 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00390 poff = delete_q_rd(p);
00391 write_log("*Tp:RdQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00392 sback = 2;
00393 break;
00394 }
00395 poff = delete_q_rd(p);
00396 write_log("*Tp:RdQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00397 sback = 1;
00398 break;
00399 }
00400 noalrm = 0;
00401 return(sback);
00402 }
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 int kick_next_entry_wt() {
00414 TQ *p, *ptmp;
00415 TAPE tapeinfo;
00416 uint64_t driveback, robotback;
00417 int d, e, snum, sback, tape_closed, group_id, nxtwrtfn;
00418 double total_bytes;
00419 char cmd[80];
00420 char *call_err, *tapeid;
00421 enum clnt_stat status;
00422
00423 poff = NULL;
00424 sback = 0;
00425 robotback = 0;
00426 p = q_wrt_front;
00427
00428 while(p) {
00429 if((d=tapeindrive(p->tapeid)) != -1) {
00430 if(drives[d].busy || drives[d].offline) {
00431 p = p->next;
00432 continue;
00433 }
00434 else {
00435 if(poff) {
00436 free(poff->tapeid);
00437 free(poff->username);
00438 freekeylist((KEY **)&poff->list);
00439 free(poff);
00440 poff = NULL;
00441 }
00442 setkey_int(&p->list, "dnum", d);
00443 tape_closed = SUMLIB_TapeState(p->tapeid);
00444 if(tape_closed == TAPECLOSED) {
00445 group_id = getkey_int(p->list, "group_id_0");
00446 total_bytes = getkey_double(p->list, "total_bytes");
00447 if(SUMLIB_TapeFindGroup(group_id, total_bytes, &tapeinfo)) {
00448 write_log("Error: no tape in group %d\n", group_id);
00449 send_mail("Error: no tape in group %d\n", group_id);
00450 write_log("*Tp:Need: tapeid=%s\n", "NOGROUP");
00451 poff = delete_q_wrt(p);
00452 write_log("*Tp:WtQdel: dsix=%lu drv=**WRN:tape_not_in_robot\n",
00453 poff->ds_index);
00454 return(2);
00455 }
00456
00457 p->tapeid = tapeinfo.tapeid;
00458 setkey_str(&p->list, "tapeid", tapeinfo.tapeid);
00459 setkey_uint64(&p->list, "availblocks", tapeinfo.availblocks);
00460 continue;
00461 }
00462 poff = delete_q_wrt(p);
00463 write_log("*Tp:WtQdel: dsix=%lu drv=%d\n", p->ds_index, d);
00464 setkey_int(&poff->list, "tape_closed", tape_closed);
00465
00466 if((nxtwrtfn = SUMLIB_TapeFilenumber(poff->tapeid)) == 0) {
00467 write_log("Error: can't get next file# to write for tape=%s\n",
00468 poff->tapeid);
00469 return(2);
00470 }
00471 setkey_int(&poff->list, "nxtwrtfn", nxtwrtfn);
00472 drives[d].busy = 1;
00473
00474 write_log("*Tp:DrBusy: drv=%d\n", d);
00475
00476
00477
00478 StartTimer(1);
00479 status = clnt_call(clntdrv[d], WRITEDRVDO, (xdrproc_t)xdr_Rkey,
00480 (char *)poff->list, (xdrproc_t)xdr_uint32_t,(char *)&driveback,TIMEOUT);
00481 ftmp = StopTimer(1);
00482 write_log("Time 1 for WRITEDRVDO in tape_svc = %f sec\n", ftmp);
00483
00484 if(status != RPC_SUCCESS) {
00485 if(status != RPC_TIMEDOUT) {
00486 call_err = clnt_sperror(clntdrv[d], "Err clnt_call for WRITEDRVDO");
00487 drives[d].busy = 0;
00488
00489 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00490
00491 write_log("%s %s\n", datestring(), call_err);
00492 return(2);
00493 }
00494 }
00495 if(driveback == 1) {
00496 drives[d].busy = 0;
00497
00498 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00499
00500 write_log("**Error in kick_next_entry_wt() in tape_svc_proc.c\n");
00501 return(2);
00502 }
00503
00504 sback = 1;
00505 p = poff->next;
00506 continue;
00507 }
00508 }
00509 p = p->next;
00510 }
00511
00512
00513 p = q_wrt_front;
00514 while(p) {
00515 if(eeactive) {
00516 sback = 0;
00517 break;
00518 }
00519 tape_closed = SUMLIB_TapeState(p->tapeid);
00520 if(tape_closed == TAPECLOSED) {
00521 group_id = getkey_int(p->list, "group_id_0");
00522 total_bytes = getkey_double(p->list, "total_bytes");
00523 if(SUMLIB_TapeFindGroup(group_id, total_bytes, &tapeinfo)) {
00524 write_log("Error: no tape in group %d\n", group_id);
00525 send_mail("Error: no tape in group %d\n", group_id);
00526 write_log("*Tp:Need: tapeid=%s\n", "NOGROUP");
00527 poff = delete_q_wrt(p);
00528 write_log("*Tp:WtQdel: dsix=%lu drv=**WRN:tape_not_in_robot\n",
00529 poff->ds_index);
00530 return(2);
00531 }
00532 p->tapeid = tapeinfo.tapeid;
00533 setkey_str(&p->list, "tapeid", tapeinfo.tapeid);
00534 setkey_uint64(&p->list, "availblocks", tapeinfo.availblocks);
00535 }
00536
00537 if((d=tapeindrive(p->tapeid)) != -1) {
00538 if(drives[d].busy || drives[d].offline) {
00539 p = p->next;
00540 continue;
00541 }
00542 }
00543
00544 if(((snum=tapeinslot(p->tapeid)) == -1) && (d == -1)) {
00545 write_log("*Tp:Need: tapeid=%s is not in live slots\n", p->tapeid);
00546 send_mail("tapeid=%s is not in live slot\n", p->tapeid);
00547 #ifdef SUMDC
00548
00549 poff = delete_q_wrt(p);
00550 write_log("*Tp:WtQdel: dsix=%lu drv=**WRN:tape_not_in_robot\n",
00551 poff->ds_index);
00552 return(2);
00553 #endif
00554 ptmp = delete_q_wrt(p);
00555 p = p->next;
00556 ptmp->next = NULL;
00557 write_log("*Tp:WtQdel: dsix=%lu drv=**WRN:tape_not_in_robot\n",
00558 ptmp->ds_index);
00559 insert_tq_entry_wrt_need(ptmp);
00560 sback = 0;
00561 continue;
00562 }
00563
00564 #ifdef SUMDC
00565 for(e=0; e < MAX_DRIVES; e++) {
00566 d = drive_order[e];
00567 if((!drives[d].tapeid) && (!drives[d].offline)) break;
00568 }
00569 if(e == MAX_DRIVES) {
00570 for(e=0; e < MAX_DRIVES; e++) {
00571 d = drive_order[nxtscanwt++];
00572 if(nxtscanwt >= MAX_DRIVES) nxtscanwt = 0;
00573
00574 if((!drives[d].busy) && (!drives[d].offline)) break;
00575 }
00576 }
00577 #else
00578 for(e=max_drives_rd; e < MAX_DRIVES; e++) {
00579 d = drive_order_wt[e];
00580 if((!drives[d].tapeid) && (!drives[d].offline)) break;
00581 }
00582 if(e == MAX_DRIVES) {
00583 for(e=max_drives_rd; e < MAX_DRIVES; e++) {
00584 d = drive_order_wt[nxtscanwt++];
00585 if(nxtscanwt >= MAX_DRIVES) nxtscanwt = max_drives_rd;
00586
00587 if((!drives[d].busy) && (!drives[d].offline)) break;
00588 }
00589 }
00590 #endif
00591 if(e == MAX_DRIVES) {
00592 sback = 0;
00593 break;
00594 }
00595
00596 if(robotbusy) {
00597 sback = 0;
00598 break;
00599 }
00600 write_log("Dr%d found for Wt at index=%d\n", d, e);
00601 robotbusy = 1;
00602 drives[d].busy = 1;
00603
00604 write_log("*Tp:DrBusy: drv=%d\n", d);
00605
00606 setkey_int(&p->list, "dnum", d);
00607 setkey_int(&p->list, "snum", snum);
00608 if(tapeid = drives[d].tapeid) {
00609 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00610 libdevname, (drives[d].slotnum)+1, d, robotcmdseq++);
00611 setkey_str(&p->list, "cmd1", cmd);
00612 sprintf(cmd,"mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00613 libdevname, snum+1, d, robotcmdseq++);
00614 setkey_str(&p->list, "cmd2", cmd);
00615 }
00616 else {
00617 sprintf(cmd,"mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
00618 libdevname, snum+1, d, robotcmdseq++);
00619 setkey_str(&p->list, "cmd1", cmd);
00620 }
00621
00622
00623 StartTimer(4);
00624 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)p->list,
00625 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
00626 ftmp = StopTimer(4);
00627
00628 if(status != RPC_SUCCESS) {
00629 if(status != RPC_TIMEDOUT) {
00630 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
00631 write_log("%s %s\n", datestring(), call_err);
00632 robotbusy = 0;
00633 drives[d].busy = 0;
00634
00635 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00636
00637 poff = delete_q_wrt(p);
00638 write_log("*Tp:WtQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00639 sback = 2;
00640 break;
00641 }
00642 }
00643 if(robotback == 1) {
00644 write_log("**Error in ROBOTDO call in tape_svc_proc.c\n");
00645 robotbusy = 0;
00646 drives[d].busy = 0;
00647
00648 write_log("*Tp:DrNotBusy: drv=%d\n", d);
00649
00650 poff = delete_q_wrt(p);
00651 write_log("*Tp:WtQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00652 sback = 2;
00653 break;
00654 }
00655 poff = delete_q_wrt(p);
00656 write_log("*Tp:WtQdel: dsix=%lu drv=%d\n", poff->ds_index, d);
00657 sback = 1;
00658 break;
00659 }
00660 return(sback);
00661 }
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
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
00701
00702
00703 KEY *readdo_1(KEY *params) {
00704 TQ *p;
00705 SUMOFFCNT *offptr;
00706 uint64_t uid, dsix;
00707 int reqcnt, i, j, k, tapefilenum, state;
00708 char *tapeid, *cptr, *user;
00709 char tmpname[80];
00710
00711
00712
00713 if(findkey(params, "DEBUGFLG")) {
00714 debugflg = getkey_int(params, "DEBUGFLG");
00715 if(debugflg) {
00716 write_log("TEMP in readdo_1() call in tape_svc. keylist is:\n");
00717 keyiterate(logkey, params);
00718 }
00719 }
00720 user = getkey_str(params, "username");
00721 uid = getkey_uint64(params, "uid");
00722 write_log("!!TEMP setsumoffcnt uid=%lu\n", uid);
00723 if(!(offptr = setsumoffcnt(&offcnt_hdr, uid, 0))) {
00724 write_log("**Err: setsumoffcnt() in readdo_1() has dup error for uid=%lu\n", uid);
00725 rinfo = 1;
00726 send_ack();
00727 free(user);
00728 return((KEY *)1);
00729 }
00730 offptr->sprog = getkey_uint32(params, "SPROG");
00731
00732
00733 reqcnt = getkey_int(params, "reqcnt");
00734
00735 for(i=0; i < reqcnt; i++) {
00736 sprintf(tmpname, "online_status_%d", i);
00737 cptr = GETKEY_str(params, tmpname);
00738
00739 if(strcmp(cptr, "N") == 0) {
00740 sprintf(tmpname, "archive_status_%d", i);
00741 cptr = GETKEY_str(params, tmpname);
00742 if(strcmp(cptr, "Y") == 0) {
00743
00744 sprintf(tmpname, "tapeid_%d", i);
00745 tapeid = GETKEY_str(params, tmpname);
00746 sprintf(tmpname, "tapefilenum_%d", i);
00747 tapefilenum = getkey_int(params, tmpname);
00748 sprintf(tmpname, "ds_index_%d", i);
00749 dsix = getkey_uint64(params, tmpname);
00750 j = offptr->uniqcnt;
00751 if(j == 0) {
00752 offptr->tapeids[0] = (char *)strdup(tapeid);
00753 offptr->tapefns[0] = tapefilenum;
00754 offptr->reqofflinenum[0] = i;
00755 offptr->dsix[0] = dsix;
00756 offptr->uniqcnt = 1;
00757 }
00758 else {
00759 for(k=0; k < j; k++) {
00760 if(!strcmp(offptr->tapeids[k], tapeid)) {
00761 if(offptr->tapefns[k] == tapefilenum) {
00762 break;
00763 }
00764 }
00765 }
00766 if(k == j) {
00767 offptr->tapeids[j] = (char *)strdup(tapeid);
00768 offptr->tapefns[j] = tapefilenum;
00769 offptr->reqofflinenum[j] = i;
00770 offptr->dsix[j] = dsix;
00771 offptr->uniqcnt++;
00772 }
00773 }
00774 }
00775 }
00776 }
00777 write_log("!!TEMP offptr->uniqcnt = %d\n", offptr->uniqcnt);
00778 for(j=0; j < offptr->uniqcnt; j++) {
00779
00780 if((p=q_entry_make(params, uid, offptr->tapeids[j],
00781 offptr->tapefns[j], user, offptr->dsix[j]))==NULL) {
00782 write_log("**Err: can't malloc a new rd Q entry\n");
00783 rinfo = 1;
00784 send_ack();
00785 free(user);
00786 return((KEY *)1);
00787 }
00788 rinfo = RESULT_PEND;
00789 send_ack();
00790 setkey_int(&p->list, "reqofflinenum", offptr->reqofflinenum[j]);
00791 setkey_str(&p->list, "OP", "rd");
00792 setkey_int(&p->list, "sim", sim);
00793 insert_tq_entry_rd_sort(p);
00794
00795
00796
00797 }
00798 write_log("*Tp:RdQsort:\n");
00799 tq_entry_rd_dump2();
00800 state = kick_next_entry_rd();
00801
00802 free(user);
00803 write_time();
00804
00805
00806 switch(state) {
00807 case 0:
00808 return((KEY *)1);
00809 break;
00810 case 1:
00811 return((KEY *)1);
00812 break;
00813 case 2:
00814 setkey_int(&poff->list, "STATUS", 1);
00815 setkey_fileptr(&poff->list, "current_client", (FILE *)getkey_fileptr(params, "current_client"));
00816 sumprog = getkey_uint32(poff->list, "SPROG");
00817
00818
00819 switch(sumprog) {
00820 case SUMPROG:
00821 clntsum = clntsums[0];
00822 break;
00823 case SUMGET:
00824 clntsum = clntsums[1];
00825 break;
00826 case SUMGET1:
00827 clntsum = clntsums[2];
00828 break;
00829 case SUMGET2:
00830 clntsum = clntsums[3];
00831 break;
00832 case SUMGET3:
00833 clntsum = clntsums[4];
00834 break;
00835 case SUMGET4:
00836 clntsum = clntsums[5];
00837 break;
00838 case SUMGET5:
00839 clntsum = clntsums[6];
00840 break;
00841 case SUMGET6:
00842 clntsum = clntsums[7];
00843 break;
00844 case SUMGET7:
00845 clntsum = clntsums[8];
00846 break;
00847 default:
00848 write_log("**ERROR: bad sumprog in readdo_1()\n");
00849 break;
00850 }
00851 current_client = clntsum;
00852 procnum = SUMRESPDO;
00853 remsumoffcnt(&offcnt_hdr, uid);
00854 return(poff->list);
00855 break;
00856 }
00857 return((KEY *)1);
00858 }
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 KEY *clntgone_1(KEY *params) {
00870 uint64_t uid;
00871 char *user;
00872
00873 uid = getkey_uint64(params, "uid");
00874 user = GETKEY_str(params, "USER");
00875 write_log("CLNTGONE called in tape_svc for user=%s uid=%lu\n",
00876 user, uid);
00877
00878 setsumopened(&rdexitopened_hdr, (uint32_t)uid, NULL, user);
00879 rinfo = 0;
00880 send_ack();
00881 return((KEY *)1);
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928 KEY *writedo_1(KEY *params) {
00929 static CLIENT *clresp;
00930 TAPE tapeinfo;
00931 TQ *p;
00932 int group_id, state, snum, dnum;
00933 int tapearcvers, pidx;
00934 char *tapeid, *user;
00935 uint64_t sumid, dsix;
00936 double total_bytes;
00937
00938 StartTimer(5);
00939 setkey_str(¶ms, "OP", "wt");
00940 if(findkey(params, "DEBUGFLG")) {
00941 debugflg = getkey_int(params, "DEBUGFLG");
00942 if(debugflg) {
00943 write_log("writedo_1() call in tape_svc. keylist is:\n");
00944 keyiterate(logkey, params);
00945 }
00946 }
00947 user = getkey_str(params, "username_0");
00948 sumid = getkey_uint64(params, "sumid_0");
00949 dsix = getkey_uint64(params, "ds_index_0");
00950 group_id = getkey_int(params, "group_id_0");
00951 total_bytes = getkey_double(params, "total_bytes");
00952 tapearcvers = getkey_int(params, "tapearcvers");
00953 if(!(clresp = set_client_handle(TAPEARCPROG, tapearcvers))) {
00954 rinfo = NO_CLNTTCP_CREATE;
00955 send_ack();
00956 ftmp = StopTimer(5);
00957 free(user);
00958 return((KEY *)1);
00959 }
00960 if(findkey(params, "tapearcXpid"))
00961 pidx = getkey_int(params, "tapearcXpid");
00962 else pidx = 0;
00963 setkey_int(¶ms, "tapearcXpid", pidx);
00964 setkey_fileptr(¶ms, "current_client", (FILE *)clresp);
00965 current_client = clresp;
00966 procnum = TAPEARCDO;
00967 setkey_uint32( ¶ms, "procnum", procnum);
00968
00969
00970
00971
00972 tapeinfo.tapeid = getkey_str(params, "tapeid");
00973 if(SUMLIB_TapeFindGroup(group_id, total_bytes, &tapeinfo)) {
00974 rinfo = NO_TAPE_IN_GROUP;
00975 send_ack();
00976 ftmp = StopTimer(5);
00977 free(user);
00978 return((KEY *)1);
00979 }
00980 #ifdef SUMDC
00981 if((snum=tapeinslot(tapeinfo.tapeid)) == -1) {
00982 if((dnum=tapeindrive(tapeinfo.tapeid)) == -1) {
00983 rinfo = NO_TAPE_IN_GROUP;
00984 send_ack();
00985 ftmp = StopTimer(5);
00986 write_log("Tape %s not in T50", tapeinfo.tapeid);
00987 free(user);
00988 return((KEY *)1);
00989 }
00990 }
00991 #endif
00992 setkey_int(¶ms, "sim", sim);
00993 setkey_int(¶ms, "group_id", tapeinfo.group_id);
00994 setkey_int(¶ms, "tape_closed", tapeinfo.closed);
00995 setkey_uint64(¶ms, "availblocks", tapeinfo.availblocks);
00996 tapeid = tapeinfo.tapeid;
00997 setkey_str(¶ms, "tapeid", tapeid);
00998
00999 if((p=q_entry_make(params, sumid, tapeid, 0, user, dsix))==NULL) {
01000 write_log("**Err: can't malloc a new wrt Q entry\n");
01001 rinfo = 1;
01002 send_ack();
01003 ftmp = StopTimer(5);
01004 free(user);
01005 return((KEY *)1);
01006 }
01007 write_log("*Tp:WtQadd: uid=%lu tapeid=%s filenum=0 user=%s dsix=%lu\n",
01008 sumid, tapeid, user, dsix);
01009 free(user);
01010 insert_tq_entry_wrt(p);
01011
01012 state = kick_next_entry_wt();
01013
01014 write_time();
01015
01016
01017 switch(state) {
01018 case 0:
01019 rinfo = RESULT_PEND;
01020 send_ack();
01021 ftmp = StopTimer(5);
01022
01023 return((KEY *)1);
01024 break;
01025 case 1:
01026 rinfo = RESULT_PEND;
01027 send_ack();
01028 ftmp = StopTimer(5);
01029
01030 return((KEY *)1);
01031 break;
01032 case 2:
01033 rinfo = 0;
01034 send_ack();
01035 ftmp = StopTimer(5);
01036
01037 setkey_int(&poff->list, "STATUS", 1);
01038 return(poff->list);
01039 break;
01040 default:
01041 rinfo = 0;
01042 send_ack();
01043 ftmp = StopTimer(5);
01044
01045 write_log("Error: kick_next_entry_wt() ret = %d invalid\n", state);
01046 return((KEY *)1);
01047 break;
01048 }
01049 }
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061 KEY *jmtxtapedo_1(KEY *params) {
01062 static CLIENT *clresp;
01063 int slotnum, drivenum, status, slot1, slot2;
01064 uint64_t robotback;
01065 char cmd[80], errstr[80];
01066 char *call_err, *mode, *tapeid;
01067 KEY *xlist;
01068
01069 robotback = 0;
01070 if(findkey(params, "DEBUGFLG")) {
01071 debugflg = getkey_int(params, "DEBUGFLG");
01072 if(debugflg) {
01073 write_log("jmtxtapedo_1() call in tape_svc. keylist is:\n");
01074 keyiterate(logkey, params);
01075 }
01076 }
01077 mode = getkey_str(params, "mode");
01078 if(findkey(params, "slotnum")) {
01079 slotnum = getkey_int(params, "slotnum");
01080 }
01081 if(findkey(params, "drivenum")) {
01082 drivenum = getkey_int(params, "drivenum");
01083 }
01084 xlist = newkeylist();
01085 if(!(clresp = set_client_handle(JMTXPROG, JMTXVERS))) {
01086 rinfo = NO_CLNTTCP_CREATE;
01087 send_ack();
01088 free(mode);
01089 return((KEY *)1);
01090 }
01091 setkey_fileptr(¶ms, "current_client", (FILE *)clresp);
01092 current_client = clresp;
01093 procnum = JMTXDO;
01094 setkey_uint32( ¶ms, "procnum", procnum);
01095 if(!strcmp(mode, "status")) {
01096 current_client_destroy = 1;
01097 add_keys(params, &xlist);
01098 sprintf(cmd, "mtx -f %s status 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
01099 libdevname, robotcmdseq);
01100 if(system(cmd)) {
01101 write_log("Error on: %s\n", cmd);
01102 setkey_int(&xlist, "STATUS", 1);
01103 sprintf(errstr, "Error on: %s", cmd);
01104 setkey_str(&xlist, "ERRSTR", errstr);
01105 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
01106 ++robotcmdseq;
01107 free(mode);
01108 return(xlist);
01109 }
01110 write_log("jmtx status in: %s:/tmp/mtx/mtx_robot_%d.log\n",
01111 hostn, robotcmdseq);
01112 sprintf(errstr, "jmtx Status in: %s:/tmp/mtx/mtx_robot_%d.log\n",
01113 hostn, robotcmdseq++);
01114 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
01115 setkey_str(&xlist, "MSG", errstr);
01116 setkey_int(&xlist, "STATUS", 0);
01117 free(mode);
01118 return(xlist);
01119 }
01120 if(!strcmp(mode, "transtape")) {
01121 tapeid = GETKEY_str(params, "tapeid");
01122 if((slot1 = tapeinslot(tapeid)) == -1) {
01123 write_log("!!!ERR jmtxtapedo_1(): tape %s must be in a slot\n", tapeid);
01124 rinfo = 2;
01125 send_ack();
01126 return((KEY *)1);
01127 }
01128 slot1++;
01129 setkey_int(¶ms, "slot1", slot1);
01130 slot2 = getkey_int(params, "slot2");
01131 goto TRANSTAPETRANSFER;
01132 }
01133 else if(!strcmp(mode, "transfer")) {
01134 slot1 = getkey_int(params, "slot1");
01135 slot2 = getkey_int(params, "slot2");
01136 TRANSTAPETRANSFER:
01137 robotbusy = 1;
01138 rinfo = 0;
01139 add_keys(params, &xlist);
01140 setkey_str(&xlist, "OP", "mtxtransfer");
01141 sprintf(cmd, "mtx -f %s transfer %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
01142 libdevname, slot1, slot2, robotcmdseq++);
01143 setkey_str(&xlist, "cmd1", cmd);
01144 setkey_int(&xlist, "DEBUGFLG", 0);
01145 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
01146
01147 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)xlist,
01148 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
01149 if(status != RPC_SUCCESS) {
01150 if(status != RPC_TIMEDOUT) {
01151 current_client_destroy = 1;
01152 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
01153 write_log("%s %s\n", datestring(), call_err);
01154 robotbusy = 0;
01155 rinfo = 1;
01156 }
01157 }
01158 if(robotback == 1) {
01159 current_client_destroy = 1;
01160 write_log("**Error in ROBOTDO call in tape_svc_proc.c\n");
01161 robotbusy = 0;
01162 rinfo = 1;
01163 }
01164 if(!rinfo) {
01165 rinfo = RESULT_PEND;
01166 }
01167 send_ack();
01168 free(mode);
01169 return((KEY *)1);
01170 }
01171 else if(drives[drivenum].busy) {
01172 current_client_destroy = 1;
01173 sprintf(errstr, "Error: drive# %d is currently busy\n", drivenum);
01174 add_keys(params, &xlist);
01175 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
01176 setkey_str(&xlist, "ERRSTR", errstr);
01177 setkey_int(&xlist, "STATUS", 1);
01178 free(mode);
01179 return(xlist);
01180 }
01181
01182
01183 robotbusy = 1;
01184 drives[drivenum].busy = 1;
01185 rinfo = 0;
01186 write_log("*Tp:DrBusy: drv=%d\n", drivenum);
01187 add_keys(params, &xlist);
01188 setkey_str(&xlist, "OP", "jmtx");
01189 setkey_int(&xlist, "dnum", drivenum);
01190 setkey_int(&xlist, "snum", slotnum);
01191 sprintf(cmd, "mtx -f %s %s %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
01192 libdevname, mode, slotnum, drivenum, robotcmdseq++);
01193 setkey_str(&xlist, "cmd1", cmd);
01194 setkey_int(&xlist, "DEBUGFLG", 0);
01195 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
01196
01197 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)xlist,
01198 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
01199 if(status != RPC_SUCCESS) {
01200 if(status != RPC_TIMEDOUT) {
01201 current_client_destroy = 1;
01202 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
01203 write_log("%s %s\n", datestring(), call_err);
01204 robotbusy = 0;
01205 drives[drivenum].busy = 0;
01206 rinfo = 1;
01207 write_log("*Tp:DrNotBusy: drv=%d\n", drivenum);
01208 }
01209 }
01210 if(robotback == 1) {
01211 current_client_destroy = 1;
01212 write_log("**Error in ROBOTDO call in tape_svc_proc.c\n");
01213 robotbusy = 0;
01214 drives[drivenum].busy = 0;
01215 rinfo = 1;
01216 write_log("*Tp:DrNotBusy: drv=%d\n", drivenum);
01217 }
01218 if(!rinfo) {
01219 rinfo = RESULT_PEND;
01220 }
01221 send_ack();
01222 free(mode);
01223 return((KEY *)1);
01224 }
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277 KEY *taperespwritedo_1(KEY *params) {
01278 static KEY *retlist, *xlist;
01279 uint64_t tellblock, robotback;
01280 int i, dnum, status, tape_closed, filenum_written, reqcnt, slotnum;
01281 int tapenxtfn;
01282 int tclosed = 0;
01283 double totalbytes = 0.0;
01284 char *tapeid, *md5cksum, *call_err, *errstr;
01285 char tmpname[80], cmd[80];
01286
01287
01288 send_ack();
01289 if(findkey(params, "DEBUGFLG")) {
01290 debugflg = getkey_int(params, "DEBUGFLG");
01291 if(debugflg) {
01292 write_log("!!Keylist in taperespwritedo_1() is:\n");
01293 keyiterate(logkey, params);
01294 }
01295 }
01296 robotback = 0;
01297 dnum = getkey_int(params, "dnum");
01298 tapenxtfn = getkey_int(params, "TAPENXTFN");
01299 slotnum = drives[dnum].slotnum;
01300 drives[dnum].busy = 0;
01301 write_log("*Tp:DrNotBusy: drv=%d\n", dnum);
01302 drives[dnum].filenum = -1;
01303 tapeid = drives[dnum].tapeid;
01304
01305
01306
01307
01308
01309
01310
01311 retlist = newkeylist();
01312 add_keys(params, &retlist);
01313
01314 current_client = (CLIENT *)getkey_fileptr(params, "current_client");
01315 current_client_destroy = 1;
01316 procnum = getkey_uint32(params, "procnum");
01317 tape_closed = getkey_int(params, "tape_closed");
01318 tellblock = getkey_uint64(params, "tellblock");
01319
01320 status = getkey_int(params, "STATUS");
01321 if(status) {
01322 write_log("***Error: write of tape %s gave an error return\n", tapeid);
01323
01324
01325 errstr = GETKEY_str(params, "ERRSTR");
01326 write_log("***%s\n", errstr);
01327 if(status != TAPECLOSEDREJECT) {
01328 write_log("***Tape %s is being closed\n", tapeid);
01329 send_mail("Error on write of tapeid %s", tapeid);
01330 if(SUMLIB_TapeClose(tapeid)) {
01331 send_mail("Error: Can't close tapeid %s", tapeid);
01332 write_log("***Error: Can't close tape %s. Tape may be corrupted!\n",
01333 tapeid);
01334 }
01335 #ifdef SUMDC
01336
01337 if(SUMLIB_MD5info(tapeid)) {
01338 send_mail("Error: Can't make MD5 file for tape %s", tapeid);
01339 write_log("***Error: Can't make MD5 file for tape %s\n", tapeid);
01340
01341 }
01342 #endif
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384 }
01385 }
01386 else {
01387 if(tape_closed == TAPEUNINIT) {
01388 if(SUMLIB_TapeActive(tapeid)) {
01389 send_mail("Error: Can't make active tapeid %s", tapeid);
01390 write_log("***Error: Can't make active tape %s. Tape is unusable.\n",
01391 tapeid);
01392
01393 setkey_int(&retlist, "STATUS", 1);
01394 return(retlist);
01395 }
01396 }
01397 md5cksum = GETKEY_str(retlist, "md5cksum");
01398 write_log("Tape write md5cksum = %s\n", md5cksum);
01399
01400
01401
01402
01403
01404
01405
01406 reqcnt = getkey_int(params, "reqcnt");
01407 for(i=0; i < reqcnt; i++) {
01408 sprintf(tmpname, "bytes_%d", i);
01409 totalbytes += getkey_double(params, tmpname);
01410 }
01411 tellblock = 0;
01412
01413 if((filenum_written=SUMLIB_TapeUpdate(tapeid,tapenxtfn,tellblock,totalbytes)) == 0) {
01414 send_mail("Error: Can't update sum_tape in DB for tape %s\n",tapeid);
01415 write_log("***Error: Can't update sum_tape in DB for tape %s\n",tapeid);
01416 setkey_int(&retlist, "STATUS", 1);
01417 return(retlist);
01418 }
01419 if(filenum_written < 0) {
01420 filenum_written = -filenum_written;
01421 tclosed = 1;
01422
01423
01424 }
01425 setkey_int(&retlist, "nxtwrtfn", filenum_written);
01426
01427 if(SUMLIB_MainTapeUpdate(retlist)) {
01428 send_mail("Error: sum_main update failed after write to %s\n", tapeid);
01429 write_log("***Error: sum_main update failed after write to %s\n",tapeid);
01430 setkey_int(&retlist, "STATUS", 1);
01431 }
01432 if(tclosed) {
01433 #ifdef SUMDC
01434
01435 if(SUMLIB_MD5info(tapeid)) {
01436 send_mail("Error: Can't make MD5 file for tape %s", tapeid);
01437 write_log("***Error: Can't make MD5 file for tape %s\n", tapeid);
01438
01439 }
01440 #endif
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483 }
01484 }
01485 return(retlist);
01486 }
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538 KEY *taperespreaddo_1(KEY *params) {
01539 CLIENT *client;
01540 SUMOFFCNT *offptr;
01541 SUMID_t uid;
01542 static KEY *retlist;
01543 int dnum, reqofflinenum, tapefilenum, status;
01544 int tmpflg;
01545 char tmpname[80];
01546 char *rwd, *tapeid;
01547
01548 if(findkey(params, "DEBUGFLG")) {
01549 debugflg = getkey_int(params, "DEBUGFLG");
01550 if(debugflg) {
01551 write_log("!!Keylist in taperespreaddo_1() is:\n");
01552 keyiterate(logkey, params);
01553 }
01554 }
01555 dnum = getkey_int(params, "dnum");
01556 status = getkey_int(params, "STATUS");
01557 drives[dnum].to = 1;
01558 drives[dnum].tocnt = 2;
01559 drives[dnum].busy = 0;
01560 write_log("*Tp:DrNotBusy: drv=%d\n", dnum);
01561 reqofflinenum = getkey_int(params, "reqofflinenum");
01562 sprintf(tmpname, "tapefilenum_%d", reqofflinenum);
01563 tapefilenum = getkey_int(params, tmpname);
01564 drives[dnum].filenum = tapefilenum;
01565 if(status) drives[dnum].filenum = -1;
01566 sprintf(tmpname, "rootwd_%d", reqofflinenum);
01567 rwd = GETKEY_str(params, tmpname);
01568
01569
01570
01571
01572
01573
01574
01575
01576 sprintf(tmpname, "chmod g-w %s", rwd);
01577 if(system(tmpname)) {
01578 write_log("**Warning: Error on: %s\n", tmpname);
01579 }
01580
01581 sprintf(tmpname, "tapeid_%d", reqofflinenum);
01582 tapeid = GETKEY_str(params, tmpname);
01583
01584
01585
01586
01587
01588
01589
01590 retlist = newkeylist();
01591 add_keys(params, &retlist);
01592 client = (CLIENT *)getkey_fileptr(params, "current_client");
01593
01594 setkey_fileptr(&retlist, "current_client", (FILE *)client);
01595
01596
01597
01598
01599 uid = getkey_uint64(params, "uid");
01600 sumprog = getkey_uint32(params, "SPROG");
01601 if(sumprog == -1) {
01602 remsumoffcnt(&offcnt_hdr, uid);
01603 write_log("**ERROR: SPROG not in keylist when tape rd completes!\n");
01604 setkey_int(&retlist, "STATUS", 1);
01605 return(retlist);
01606 }
01607 offptr = getsumoffcnt(offcnt_hdr, uid);
01608 if(offptr == NULL) {
01609 write_log("!!TMP find out why offptr is NULL. Assume all done...\n");
01610 tmpflg = 1;
01611 }
01612 else {
01613 offptr->offcnt++;
01614 }
01615 if(offptr->sprog != sumprog) {
01616 write_log("**ERROR: Bug. In tape rd sprog (%u) != sumprog (%u)\n",
01617 offptr->sprog, sumprog);
01618
01619 }
01620
01621
01622 switch(sumprog) {
01623 case SUMPROG:
01624 clntsum = clntsums[0];
01625 break;
01626 case SUMGET:
01627 clntsum = clntsums[1];
01628 break;
01629 case SUMGET1:
01630 clntsum = clntsums[2];
01631 break;
01632 case SUMGET2:
01633 clntsum = clntsums[3];
01634 break;
01635 case SUMGET3:
01636 clntsum = clntsums[4];
01637 break;
01638 case SUMGET4:
01639 clntsum = clntsums[5];
01640 break;
01641 case SUMGET5:
01642 clntsum = clntsums[6];
01643 break;
01644 case SUMGET6:
01645 clntsum = clntsums[7];
01646 break;
01647 case SUMGET7:
01648 clntsum = clntsums[8];
01649 break;
01650 default:
01651 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
01652 break;
01653 }
01654 current_client = clntsum;
01655 procnum = SUMRESPDO;
01656 send_ack();
01657 tmpflg = 0;
01658
01659 if((offptr->uniqcnt == offptr->offcnt) || tmpflg) {
01660 if(getsumopened(rdexitopened_hdr, (uint32_t)uid)) {
01661
01662 remsumopened(&rdexitopened_hdr, (uint32_t)uid);
01663 write_log("User=%s uid=%lu exited before tape rd completion. Ignore\n",
01664 GETKEY_str(params, "username"), uid);
01665 }
01666 else {
01667 write_log("!!TEMP remsumoffcnt uid=%lu\n", uid);
01668 remsumoffcnt(&offcnt_hdr, uid);
01669 if(DS_DataRequest_WD(retlist, &retlist)) {
01670 write_log("***Err: DS_DataRequest_WD() returned error.\n");
01671 setkey_int(&retlist, "STATUS", 1);
01672 }
01673 return(retlist);
01674 }
01675 }
01676 freekeylist((KEY **)&retlist);
01677 return((KEY *)1);
01678 }
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727 KEY *taperesprobotdo_1(KEY *params) {
01728 static KEY *retlist;
01729 CLIENT *client;
01730 int s, d, status, slot1, slot2;
01731 char scr[80];
01732 char *cptr, *cmd;
01733
01734 robotbusy = 0;
01735 send_ack();
01736 if(findkey(params, "DEBUGFLG")) {
01737 debugflg = getkey_int(params, "DEBUGFLG");
01738 if(debugflg) {
01739 write_log("!!Keylist in taperesprobotdo_1() is:\n");
01740 keyiterate(logkey, params);
01741 }
01742 }
01743 status = getkey_int(params, "STATUS");
01744 if(status) {
01745 cptr = GETKEY_str(params, "ERRSTR");
01746 write_log("Robot %s\n", cptr);
01747 write_log("***Fatal Robot error: going to try to proceed...\n");
01748
01749 send_mail("***Fatal Robot error: going to try to proceed...\n");
01750
01751 }
01752 if(findkey(params, "slot1")) {
01753 if(status == 0) {
01754 slot1 = getkey_int(params, "slot1");
01755 slot2 = getkey_int(params, "slot2");
01756 --slot1;
01757 --slot2;
01758 slots[slot2].tapeid = slots[slot1].tapeid;
01759 slots[slot1].tapeid = NULL;
01760 }
01761 retlist = newkeylist();
01762 add_keys(params, &retlist);
01763 current_client = (CLIENT *)getkey_fileptr(params, "current_client");
01764 current_client_destroy = 1;
01765
01766 setkey_fileptr(&retlist, "current_client", (FILE *)current_client);
01767 procnum = getkey_uint32(params, "procnum");
01768 return(retlist);
01769 }
01770 cptr = GETKEY_str(params, "OP");
01771 if(!strcmp(cptr, "rd")) {
01772
01773 retlist = taperesprobotdo_1_rd(params);
01774 }
01775 else if(!strcmp(cptr, "wt")) {
01776
01777 retlist = taperesprobotdo_1_wt(params);
01778 }
01779 else if(!strcmp(cptr, "mv")) {
01780
01781 if(status == 0) {
01782 d = getkey_int(params, "dnum");
01783 s = getkey_int(params, "snum");
01784 slots[s].tapeid = drives[d].tapeid;
01785 drives[d].tapeid = NULL;
01786 drives[d].slotnum = -1;
01787 drives[d].tapemode = TAPE_NOT_LOADED;
01788 drives[d].filenum = 0;
01789 }
01790 drives[d].busy = 0;
01791 write_log("*Tp:DrNotBusy: drv=%d\n", d);
01792 retlist = (KEY *)1;
01793 }
01794 else if(!strcmp(cptr, "jmtx")) {
01795 if(findkey(params, "cmd1")) {
01796 cmd = GETKEY_str(params, "cmd1");
01797 if(strstr(cmd, " load ")) {
01798 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01799 s--;
01800 if(status == 0) {
01801
01802 drives[d].tapeid = slots[s].tapeid;
01803 drives[d].slotnum = s;
01804 slots[s].tapeid = NULL;
01805 }
01806 }
01807 if(strstr(cmd, " unload ")) {
01808 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01809 s--;
01810 if(status == 0) {
01811
01812 slots[s].tapeid = drives[d].tapeid;
01813 drives[d].tapeid = NULL;
01814 drives[d].slotnum = -1;
01815 }
01816 }
01817 drives[d].busy = 0;
01818 retlist = newkeylist();
01819 add_keys(params, &retlist);
01820 current_client = (CLIENT *)getkey_fileptr(params, "current_client");
01821 current_client_destroy = 1;
01822
01823 setkey_fileptr(&retlist, "current_client", (FILE *)current_client);
01824 procnum = getkey_uint32(params, "procnum");
01825 return(retlist);
01826 }
01827 }
01828 else if(!strcmp(cptr, "clean")) {
01829 if(findkey(params, "cmd1")) {
01830 cmd = GETKEY_str(params, "cmd1");
01831 if(strstr(cmd, " load ")) {
01832 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01833 s--;
01834
01835 if(status == 0) {
01836 drives[d].tapeid = slots[s].tapeid;
01837 drives[d].slotnum = s;
01838 slots[s].tapeid = NULL;
01839 }
01840 }
01841 if(strstr(cmd, " unload ")) {
01842 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01843 s--;
01844
01845 if(status == 0) {
01846 slots[s].tapeid = drives[d].tapeid;
01847 drives[d].tapeid = NULL;
01848 drives[d].slotnum = -1;
01849 }
01850 }
01851 }
01852 if(findkey(params, "cmd2")) {
01853 cmd = GETKEY_str(params, "cmd2");
01854 if(strstr(cmd, " load ")) {
01855 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01856 s--;
01857
01858 if(status == 0) {
01859 drives[d].tapeid = slots[s].tapeid;
01860 drives[d].slotnum = s;
01861 slots[s].tapeid = NULL;
01862 }
01863 }
01864 if(strstr(cmd, " unload ")) {
01865 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01866 s--;
01867
01868 if(status == 0) {
01869 slots[s].tapeid = drives[d].tapeid;
01870 drives[d].tapeid = NULL;
01871 drives[d].slotnum = -1;
01872 }
01873 }
01874 }
01875 write_log("*Tp:CleanInProgress: drv=%d\n", d);
01876
01877 retlist = (KEY *)1;
01878 }
01879 else if(!strcmp(cptr, "clean_robot_unload")) {
01880 if(findkey(params, "cmd1")) {
01881 cmd = GETKEY_str(params, "cmd1");
01882 if(strstr(cmd, " unload ")) {
01883 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01884 s--;
01885
01886 if(status == 0) {
01887 slots[s].tapeid = drives[d].tapeid;
01888 drives[d].tapeid = NULL;
01889 drives[d].slotnum = -1;
01890 }
01891 }
01892 }
01893 write_log("*Tp:CleaningDone: drv=%d slot=%d\n", d, s+1);
01894 drives[d].busy = 0;
01895 write_log("*Tp:DrNotBusy: drv=%d\n", d);
01896 retlist = (KEY *)1;
01897 }
01898 return(retlist);
01899 }
01900
01901
01902
01903
01904 KEY *taperesprobotdo_1_rd(KEY *params) {
01905 CLIENT *client;
01906 SUMID_t driveback;
01907 static struct timeval TIMEOUT = { 120, 0 };
01908 static KEY *retlist;
01909 char *call_err, *cmd;
01910 char scr[80];
01911 enum clnt_stat status;
01912 int dnum, snum, stat, d, s;
01913
01914 dnum = getkey_int(params, "dnum");
01915 snum = getkey_int(params, "snum");
01916 retlist = newkeylist();
01917 add_keys(params, &retlist);
01918 client = (CLIENT *)getkey_fileptr(params, "current_client");
01919
01920 setkey_fileptr(&retlist, "current_client", (FILE *)client);
01921 if(stat=getkey_int(params, "STATUS")) {
01922 write_log("**Error return from robot_svc for read op.\n");
01923 sumprog = getkey_uint32(params, "SPROG");
01924
01925
01926 switch(sumprog) {
01927 case SUMPROG:
01928 clntsum = clntsums[0];
01929 break;
01930 case SUMGET:
01931 clntsum = clntsums[1];
01932 break;
01933 case SUMGET1:
01934 clntsum = clntsums[2];
01935 break;
01936 case SUMGET2:
01937 clntsum = clntsums[3];
01938 break;
01939 case SUMGET3:
01940 clntsum = clntsums[4];
01941 break;
01942 case SUMGET4:
01943 clntsum = clntsums[5];
01944 break;
01945 case SUMGET5:
01946 clntsum = clntsums[6];
01947 break;
01948 case SUMGET6:
01949 clntsum = clntsums[7];
01950 break;
01951 case SUMGET7:
01952 clntsum = clntsums[8];
01953 break;
01954 default:
01955 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
01956 break;
01957 }
01958 current_client = clntsum;
01959 procnum = SUMRESPDO;
01960 current_client_destroy = 1;
01961 return(retlist);
01962 }
01963 if(findkey(params, "cmd1")) {
01964 cmd = GETKEY_str(params, "cmd1");
01965 if(strstr(cmd, " load ")) {
01966 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01967 s--;
01968
01969 drives[d].tapeid = slots[s].tapeid;
01970 drives[d].slotnum = s;
01971 drives[d].tapemode = TAPE_RD_INIT;
01972 drives[d].filenum = 0;
01973 slots[s].tapeid = NULL;
01974 }
01975 if(strstr(cmd, " unload ")) {
01976 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01977 s--;
01978
01979 slots[s].tapeid = drives[d].tapeid;
01980 drives[d].tapeid = NULL;
01981 drives[d].slotnum = -1;
01982 drives[d].tapemode = TAPE_NOT_LOADED;
01983 drives[d].filenum = 0;
01984 }
01985 }
01986 if(findkey(params, "cmd2")) {
01987 cmd = GETKEY_str(params, "cmd2");
01988 if(strstr(cmd, " load ")) {
01989 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
01990 s--;
01991
01992 drives[d].tapeid = slots[s].tapeid;
01993 drives[d].slotnum = s;
01994 drives[d].tapemode = TAPE_RD_INIT;
01995 drives[d].filenum = 0;
01996 slots[s].tapeid = NULL;
01997 }
01998 if(strstr(cmd, " unload ")) {
01999 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02000 s--;
02001
02002 slots[s].tapeid = drives[d].tapeid;
02003 drives[d].tapeid = NULL;
02004 drives[d].slotnum = -1;
02005 drives[d].tapemode = TAPE_NOT_LOADED;
02006 drives[d].filenum = 0;
02007 }
02008 }
02009 setkey_int(&retlist, "tapemode", drives[d].tapemode);
02010 setkey_int(&retlist, "filenum", drives[d].filenum);
02011
02012
02013 write_log("taperesprobotdo_1_rd(): clnt_call( READDRVDO ) drv=%d\n", dnum);
02014 status = clnt_call(clntdrv[dnum], READDRVDO, (xdrproc_t)xdr_Rkey,
02015 (char *)retlist, (xdrproc_t)xdr_uint32_t, (char *)&driveback, TIMEOUT);
02016 if(status != RPC_SUCCESS) {
02017 if(status != RPC_TIMEDOUT) {
02018 call_err = clnt_sperror(clntdrv[dnum], "Err clnt_call for READDRVDO");
02019 write_log("%s %s\n", datestring(), call_err);
02020 setkey_int(&retlist, "STATUS", 1);
02021 sumprog = getkey_uint32(params, "SPROG");
02022
02023
02024 switch(sumprog) {
02025 case SUMPROG:
02026 clntsum = clntsums[0];
02027 break;
02028 case SUMGET:
02029 clntsum = clntsums[1];
02030 break;
02031 case SUMGET1:
02032 clntsum = clntsums[2];
02033 break;
02034 case SUMGET2:
02035 clntsum = clntsums[3];
02036 break;
02037 case SUMGET3:
02038 clntsum = clntsums[4];
02039 break;
02040 case SUMGET4:
02041 clntsum = clntsums[5];
02042 break;
02043 case SUMGET5:
02044 clntsum = clntsums[6];
02045 break;
02046 case SUMGET6:
02047 clntsum = clntsums[7];
02048 break;
02049 case SUMGET7:
02050 clntsum = clntsums[8];
02051 break;
02052 default:
02053 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
02054 break;
02055 }
02056 current_client = clntsum;
02057 current_client_destroy = 1;
02058 procnum = SUMRESPDO;
02059 return(retlist);
02060 } else {
02061 write_log("%s timeout occured for READDRVDO in taperesprobotdo_1_rd()\n", datestring());
02062 }
02063 }
02064 if(driveback == 1) {
02065 write_log("**Error in readdo_1() in tape_svc_proc.c\n");
02066 setkey_int(&retlist, "STATUS", 1);
02067 sumprog = getkey_uint32(params, "SPROG");
02068
02069
02070 switch(sumprog) {
02071 case SUMPROG:
02072 clntsum = clntsums[0];
02073 break;
02074 case SUMGET:
02075 clntsum = clntsums[1];
02076 break;
02077 case SUMGET1:
02078 clntsum = clntsums[2];
02079 break;
02080 case SUMGET2:
02081 clntsum = clntsums[3];
02082 break;
02083 case SUMGET3:
02084 clntsum = clntsums[4];
02085 break;
02086 case SUMGET4:
02087 clntsum = clntsums[5];
02088 break;
02089 case SUMGET5:
02090 clntsum = clntsums[6];
02091 break;
02092 case SUMGET6:
02093 clntsum = clntsums[7];
02094 break;
02095 case SUMGET7:
02096 clntsum = clntsums[8];
02097 break;
02098 default:
02099 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
02100 break;
02101 }
02102 current_client = clntsum;
02103 current_client_destroy = 1;
02104 procnum = SUMRESPDO;
02105 return(retlist);
02106 }
02107 freekeylist((KEY **)&retlist);
02108 return((KEY *)1);
02109 }
02110
02111
02112
02113
02114 KEY *taperesprobotdo_1_wt(KEY *params) {
02115 CLIENT *client;
02116 SUMID_t driveback;
02117 static struct timeval TIMEOUT = { 120, 0 };
02118 static KEY *retlist;
02119 char *call_err, *cmd;
02120 char scr[80];
02121 enum clnt_stat status;
02122 int dnum, snum, stat, tape_closed, d, s, nxtwrtfn;
02123
02124 dnum = getkey_int(params, "dnum");
02125 snum = getkey_int(params, "snum");
02126 retlist = newkeylist();
02127 add_keys(params, &retlist);
02128 client = (CLIENT *)getkey_fileptr(params, "current_client");
02129
02130 setkey_fileptr(&retlist, "current_client", (FILE *)client);
02131 if(stat=getkey_int(params, "STATUS")) {
02132 write_log("**Error return from robot_svc for write op\n");
02133
02134 current_client_destroy = 1;
02135
02136 sumprog = getkey_uint32(params, "SPROG");
02137
02138
02139 switch(sumprog) {
02140 case SUMPROG:
02141 clntsum = clntsums[3];
02142 break;
02143 case SUMGET:
02144 clntsum = clntsums[1];
02145 break;
02146 case SUMGET1:
02147 clntsum = clntsums[2];
02148 break;
02149 case SUMGET2:
02150 clntsum = clntsums[3];
02151 break;
02152 case SUMGET3:
02153 clntsum = clntsums[4];
02154 break;
02155 case SUMGET4:
02156 clntsum = clntsums[5];
02157 break;
02158 case SUMGET5:
02159 clntsum = clntsums[6];
02160 break;
02161 case SUMGET6:
02162 clntsum = clntsums[7];
02163 break;
02164 case SUMGET7:
02165 clntsum = clntsums[8];
02166 break;
02167 default:
02168 write_log("**ERROR: bad sumprog in taperespreaddo_1()\n");
02169 break;
02170 }
02171 current_client = clntsum;
02172 procnum = SUMRESPDO;
02173 return(retlist);
02174 }
02175 if(findkey(params, "cmd1")) {
02176 cmd = GETKEY_str(params, "cmd1");
02177 if(strstr(cmd, " load ")) {
02178 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02179 s--;
02180
02181 drives[d].tapeid = slots[s].tapeid;
02182 drives[d].slotnum = s;
02183 slots[s].tapeid = NULL;
02184 }
02185 if(strstr(cmd, " unload ")) {
02186 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02187 s--;
02188
02189 slots[s].tapeid = drives[d].tapeid;
02190 drives[d].tapeid = NULL;
02191 drives[d].slotnum = -1;
02192 }
02193 }
02194 if(findkey(params, "cmd2")) {
02195 cmd = GETKEY_str(params, "cmd2");
02196 if(strstr(cmd, " load ")) {
02197 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02198 s--;
02199
02200 drives[d].tapeid = slots[s].tapeid;
02201 drives[d].slotnum = s;
02202 slots[s].tapeid = NULL;
02203 }
02204 if(strstr(cmd, " unload ")) {
02205 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02206 s--;
02207
02208 slots[s].tapeid = drives[d].tapeid;
02209 drives[d].tapeid = NULL;
02210 drives[d].slotnum = -1;
02211 }
02212 }
02213
02214 tape_closed = SUMLIB_TapeState(drives[dnum].tapeid);
02215 setkey_int(&retlist, "tape_closed", tape_closed);
02216
02217 if((nxtwrtfn = SUMLIB_TapeFilenumber(drives[dnum].tapeid)) == 0) {
02218 write_log("Error: can't get next file# to write for tape=%s\n",
02219 drives[dnum].tapeid);
02220 setkey_int(&retlist, "STATUS", 1);
02221 current_client = client;
02222 current_client_destroy = 1;
02223 procnum = getkey_uint32(params, "procnum");
02224 return(retlist);
02225 }
02226 setkey_int(&retlist, "nxtwrtfn", nxtwrtfn);
02227
02228
02229
02230 StartTimer(2);
02231 status = clnt_call(clntdrv[dnum], WRITEDRVDO, (xdrproc_t)xdr_Rkey,
02232 (char *)retlist, (xdrproc_t)xdr_uint32_t, (char *)&driveback, TIMEOUT);
02233 ftmp = StopTimer(2);
02234 write_log("Time 2 for WRITEDRVDO in tape_svc = %f sec\n", ftmp);
02235 if(status != RPC_SUCCESS) {
02236 if(status != RPC_TIMEDOUT) {
02237 call_err = clnt_sperror(clntdrv[dnum], "Err clnt_call for WRITEDRVDO");
02238 write_log("%s %s\n", datestring(), call_err);
02239 setkey_int(&retlist, "STATUS", 1);
02240 current_client = client;
02241 current_client_destroy = 1;
02242 procnum = getkey_uint32(params, "procnum");
02243 return(retlist);
02244 } else {
02245 write_log("%s timeout occured for WRITEDRVDO in taperesprobotdo_1_wt()\n", datestring());
02246 }
02247 }
02248 if(driveback == 1) {
02249 write_log("**Error in writedo_1() in tape_svc_proc.c\n");
02250 setkey_int(&retlist, "STATUS", 1);
02251 current_client = client;
02252 current_client_destroy = 1;
02253 procnum = getkey_uint32(params, "procnum");
02254 return(retlist);
02255 }
02256
02257 return((KEY *)1);
02258 }
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272 KEY *taperesprobotdoordo_1(KEY *params) {
02273 int reqcnt, i, s, d, retry, istat;
02274 char *cmd, *cptr;
02275 char ext[80], scr[80];
02276
02277 robotbusy = 0;
02278 rinfo = 0;
02279 send_ack();
02280
02281 if(debugflg) {
02282 write_log("!!Keylist in taperesprobotdoordo_1() is:\n");
02283 keyiterate(logkey, params);
02284 }
02285 reqcnt = getkey_int(params, "reqcnt");
02286 for(i=0; i < reqcnt; i++) {
02287 sprintf(ext, "cmd_%d", i);
02288 cmd = GETKEY_str(params, ext);
02289 sscanf(cmd, "%s %s %s %s %d %d", scr, scr, scr, scr, &s, &d);
02290
02291 s--;
02292 d--;
02293 slots[d].tapeid = slots[s].tapeid;
02294 slots[s].tapeid = NULL;
02295 }
02296
02297 #ifdef SUMDC
02298 cptr = GETKEY_str(params, "OP");
02299 if(!strcmp(cptr, "door")) {
02300
02301 retry = 6;
02302 while(retry) {
02303 if((istat = tape_reinventory(sim, 0)) == 0) {
02304 write_log("***Error: Can't do tape inventory. Will retry...\n");
02305 --retry;
02306 if(retry == 0) {
02307 write_log("***Fatal error: Can't do tape inventory\n");
02308 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02309 (void) pmap_unset(TAPEPROG, TAPEVERS);
02310 exit(1);
02311 }
02312 continue;
02313 }
02314 if(istat == -1) {
02315 --retry;
02316 if(retry == 0) {
02317 write_log("***Fatal error: Can't do tape inventory\n");
02318 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02319 (void) pmap_unset(TAPEPROG, TAPEVERS);
02320 exit(1);
02321 }
02322 }
02323 else { retry = 0; }
02324 }
02325 }
02326 #endif
02327 return((KEY *)1);
02328 }
02329
02330
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349 KEY *impexpdo_1(KEY *params)
02350 {
02351 TQ *p;
02352 static KEY *retlist, *xlist;
02353 enum clnt_stat status;
02354 char *tid, *call_err, *op, *tapeid;
02355 char ext[64], cmd[128];
02356 uint32_t robotback;
02357 int reqcnt, i, j, snum, dnum, eeslot, retry, istat;
02358 int count_impexp_full, count_slots_empty, cleanslot, cleandrive;
02359 int slotnum;
02360
02361
02362
02363 poff = NULL;
02364 rinfo = 0;
02365 op = getkey_str(params, "OP");
02366 if(!strcmp(op, "clean_start")) {
02367 cleanslot = atoi(GETKEY_str(params, "cleanslot"));
02368 cleandrive = atoi(GETKEY_str(params, "cleandrive"));
02369 write_log("cleanslot=%d cleandrive=%d\n", cleanslot, cleandrive);
02370 xlist = newkeylist();
02371 robotbusy = 1;
02372 robotback = 0;
02373 drives[cleandrive].busy = 1;
02374 write_log("*Tp:DrBusy: drv=%d\n", cleandrive);
02375 setkey_str(&xlist, "OP", "clean");
02376 setkey_int(&xlist, "dnum", cleandrive);
02377 setkey_int(&xlist, "snum", slotnum);
02378 if(tapeid = drives[cleandrive].tapeid) {
02379 slotnum = drives[cleandrive].slotnum;
02380 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02381 libdevname, slotnum+1, cleandrive, robotcmdseq++);
02382 setkey_str(&xlist, "cmd1", cmd);
02383 sprintf(cmd, "mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02384 libdevname, cleanslot, cleandrive, robotcmdseq++);
02385 setkey_str(&xlist, "cmd2", cmd);
02386 }
02387 else {
02388 sprintf(cmd, "mtx -f %s load %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02389 libdevname, cleanslot, cleandrive, robotcmdseq++);
02390 setkey_str(&xlist, "cmd1", cmd);
02391 }
02392 setkey_int(&xlist, "DEBUGFLG", 0);
02393 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
02394 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)xlist,
02395 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
02396 if(status != RPC_SUCCESS) {
02397 if(status != RPC_TIMEDOUT) {
02398 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
02399 write_log("%s %s\n", datestring(), call_err);
02400 robotbusy = 0;
02401 drives[cleandrive].busy = 0;
02402 write_log("*Tp:DrNotBusy: drv=%d\n", cleandrive);
02403 }
02404 }
02405 if(robotback == 1) {
02406 write_log("**Error in ROBOTDO for impexp clean call in tape_svc_proc.c\n");
02407 robotbusy = 0;
02408 drives[cleandrive].busy = 0;
02409 write_log("*Tp:DrNotBusy: drv=%d\n", cleandrive);
02410 }
02411 freekeylist(&xlist);
02412 free(op);
02413 send_ack();
02414 return((KEY *)1);
02415 }
02416 if(!strcmp(op, "clean_stop")) {
02417 cleandrive = atoi(GETKEY_str(params, "cleandrive"));
02418 cleanslot = atoi(GETKEY_str(params, "cleanslot"));
02419 xlist = newkeylist();
02420 robotbusy = 1;
02421 robotback = 0;
02422 drives[cleandrive].busy = 1;
02423 write_log("*Tp:DrBusy: drv=%d\n", cleandrive);
02424 setkey_str(&xlist, "OP", "clean_robot_unload");
02425 setkey_int(&xlist, "dnum", cleandrive);
02426 setkey_int(&xlist, "snum", cleanslot);
02427 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02428 libdevname, cleanslot, cleandrive, robotcmdseq++);
02429 setkey_str(&xlist, "cmd1", cmd);
02430 setkey_int(&xlist, "DEBUGFLG", 0);
02431 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
02432 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)xlist,
02433 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
02434 if(status != RPC_SUCCESS) {
02435 if(status != RPC_TIMEDOUT) {
02436 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
02437 write_log("%s %s\n", datestring(), call_err);
02438 robotbusy = 0;
02439 drives[cleandrive].busy = 0;
02440 write_log("*Tp:DrNotBusy: drv=%d\n", cleandrive);
02441 }
02442 }
02443 if(robotback == 1) {
02444 write_log("**Error in ROBOTDO for impexp clean call in tape_svc_proc.c\n");
02445 robotbusy = 0;
02446 drives[cleandrive].busy = 0;
02447 write_log("*Tp:DrNotBusy: drv=%d\n", cleandrive);
02448 }
02449 freekeylist(&xlist);
02450 free(op);
02451 send_ack();
02452 return((KEY *)1);
02453 }
02454 if(!strcmp(op, "stop")) {
02455 eeactive = 0;
02456 send_ack();
02457 write_log("*Tp:BulkLoadDone\n");
02458 retry = 6;
02459 while(retry) {
02460 #ifdef SUMDC
02461 istat = tape_reinventory(sim, 1);
02462 #else
02463
02464
02465 istat = tape_reinventory(sim, 1);
02466 #endif
02467 if(istat == 0) {
02468 write_log("***Error: Can't do tape inventory. Will retry...\n");
02469 --retry;
02470 if(retry == 0) {
02471 write_log("***Inv: failure\n\n");
02472 write_log("***Fatal error: Can't do tape inventory\n");
02473 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02474 (void) pmap_unset(TAPEPROG, TAPEVERS);
02475 exit(1);
02476 }
02477 continue;
02478 }
02479 if(istat == -1) {
02480 --retry;
02481 if(retry == 0) {
02482 write_log("***Inv: failure\n\n");
02483 write_log("***Fatal error: Can't do tape inventory\n");
02484 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02485 (void) pmap_unset(TAPEPROG, TAPEVERS);
02486 exit(1);
02487 }
02488 }
02489 else { retry = 0; }
02490 }
02491
02492
02495
02496
02497 write_log("*Tp:t50BulkLoadDone\n");
02498 count_impexp_full = 0; count_slots_empty = 0;
02499 xlist = newkeylist();
02500 robotbusy = 1;
02501 setkey_str(&xlist, "OP", "door");
02502 for(j=0, i=(MAX_SLOTS - NUM_IMP_EXP_SLOTS); i < MAX_SLOTS; j++, i++) {
02503 if(slots[i].tapeid != NULL) {
02504 full_impexp_slotnum_internal[j] = i;
02505 count_impexp_full++;
02506 }
02507 else full_impexp_slotnum_internal[j] = -1;
02508 }
02509 for(i=0, j=0; i < MAX_SLOTS_LIVE; i++) {
02510 if(!slots[i].tapeid) {
02511 count_slots_empty++;
02512 if(count_slots_empty > count_impexp_full) {
02513
02514 }
02515 empty_slotnum_internal[j++] = i;
02516 }
02517 }
02518 for(i=0, j=0; i < NUM_IMP_EXP_SLOTS; i++) {
02519 if(full_impexp_slotnum_internal[i] == -1) continue;
02520 eeslot = full_impexp_slotnum_internal[i];
02521 snum = empty_slotnum_internal[j];
02522 sprintf(cmd, "mtx -f %s transfer %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02523 libdevname, eeslot+1, snum+1, robotcmdseq++);
02524 sprintf(ext, "cmd_%d", j++);
02525 setkey_str(&xlist, ext, cmd);
02526
02527
02528 }
02529 setkey_int(&xlist, "reqcnt", j);
02530 write_log("*Rb:t50startdoor:\n");
02531 robotback = 0;
02532 status = clnt_call(clntrobot0, ROBOTDOORDO, (xdrproc_t)xdr_Rkey,
02533 (char *)xlist, (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
02534 if(status != RPC_SUCCESS) {
02535 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDOORDO");
02536 write_log("%s %s\n", datestring(), call_err);
02537 rinfo = 1;
02538 }
02539 if(robotback == 1) {
02540 write_log("**Error in ROBOTDOORDO call in tape_svc_proc.c\n");
02541 rinfo = 1;
02542 }
02543 #endif
02544
02545 while(p = delete_q_rd_need_front()) {
02546 p->next = NULL;
02547 write_log("*Tp:RdQadd: uid=%lu tapeid=%s filenum=%d user=%s dsix=%lu\n",
02548 p->uid, p->tapeid, p->filenum, p->username, p->ds_index);
02549 insert_tq_entry_rd(p);
02550 write_log("RD Q:\n");
02551 rd_q_print(q_rd_front);
02552 }
02553 while((p = delete_q_wrt_need_front())) {
02554 p->next = NULL;
02555 write_log("*Tp:WtQadd: uid=%lu tapeid=%s filenum=0 user=%s dsix=%lu\n",
02556 p->uid, p->tapeid, p->username, p->ds_index);
02557 insert_tq_entry_wrt(p);
02558 }
02559 free(op);
02560 return((KEY *)1);
02561 }
02562
02563 if(strcmp(op, "start")) {
02564 write_log("!!ERR impexpdo_1(): Illegal option=%s\n", op);
02565 rinfo = 1;
02566 send_ack();
02567 free(op);
02568 return((KEY *)1);
02569 }
02570 free(op);
02571
02572 eeactive = 1;
02573 retlist = newkeylist();
02574 add_keys(params, &retlist);
02575 reqcnt = getkey_int(params, "reqcnt");
02576 for(i=0; i < reqcnt; i++) {
02577 sprintf(ext, "tapeid_%d", i);
02578 tid = GETKEY_str(params, ext);
02579 if((snum=tapeinslot(tid)) == -1) {
02580 if((dnum=tapeindrive(tid)) == -1) {
02581 write_log("!!!ERR impexpdo_1(): tape %s must be in a slot\n", tid);
02582 rinfo = 1;
02583 send_ack();
02584 return((KEY *)1);
02585 }
02586 }
02587 if((eeslot=find_empty_impexp_slot()) == -1) {
02588 write_log("!!!ERR impexpdo_1(): There must be an empty imp/exp slot\n", tid);
02589 rinfo = 1;
02590 send_ack();
02591 return((KEY *)1);
02592 }
02593 slots[eeslot].tapeid = tid;
02594 if(snum == -1) {
02595 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02596 libdevname, eeslot+1, dnum, robotcmdseq++);
02597 }
02598 else {
02599 sprintf(cmd, "mtx -f %s transfer %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02600 libdevname, snum+1, eeslot+1, robotcmdseq++);
02601 }
02602 sprintf(ext, "cmd_%d", i);
02603 setkey_str(&retlist, ext, cmd);
02604 }
02605 setkey_str(&retlist, "OP", "impexp");
02606
02607 write_log("In impexpdo_1(): clnt_call(clntrobot0, ROBOTDOORDO, ...) \n");
02608
02609 robotback = 0;
02610 status = clnt_call(clntrobot0, ROBOTDOORDO, (xdrproc_t)xdr_Rkey,
02611 (char *)retlist, (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
02612 if(status != RPC_SUCCESS) {
02613 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDOORDO");
02614 write_log("%s %s\n", datestring(), call_err);
02615 rinfo = 1;
02616 }
02617 if(robotback == 1) {
02618 write_log("**Error in ROBOTDOORDO call in tape_svc_proc.c\n");
02619 rinfo = 1;
02620 }
02621 send_ack();
02622 return((KEY *)1);
02623 }
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634 KEY *expclosedo_1(KEY *params)
02635 {
02636 KEY *xlist;
02637 char cmd[80];
02638 char *op;
02639 int retry, istat;
02640
02641 op = getkey_str(params, "OP");
02642 write_log("***EXPCLOSEDO called for %s\n", op);
02643
02644 if(!strcmp(op, "unload")) {
02645 eeactive = 1;
02646 }
02647 else if(!strcmp(op, "reinventory")) {
02648 eeactive = 0;
02649 retry = 6;
02650 while(retry) {
02651 istat = tape_reinventory(sim, 1);
02652 if(istat == 0) {
02653 write_log("***Error: Can't do tape inventory. Will retry...\n");
02654 --retry;
02655 if(retry == 0) {
02656 write_log("***Inv: failure\n\n");
02657 write_log("***Fatal error: Can't do tape inventory\n");
02658 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02659 (void) pmap_unset(TAPEPROG, TAPEVERS);
02660 exit(1);
02661 }
02662 continue;
02663 }
02664 if(istat == -1) {
02665 --retry;
02666 if(retry == 0) {
02667 write_log("***Inv: failure\n\n");
02668 write_log("***Fatal error: Can't do tape inventory\n");
02669 send_mail("***Fatal error: Can't do tape inventory\nAbort tape_svc\n");
02670 (void) pmap_unset(TAPEPROG, TAPEVERS);
02671 exit(1);
02672 }
02673 }
02674 else { retry = 0; }
02675 }
02676 }
02677 rinfo = 0;
02678 send_ack();
02679 free(op);
02680 return((KEY *)1);
02681 }
02682
02683
02684
02685
02686
02687 KEY *tapetestdo_1(KEY *params) {
02688 static KEY *retlist;
02689 static CLIENT *clresp;
02690 int tapearcvers;
02691
02692 write_log("You've called tapetestdo_1() in tape_svc\n");
02693 if(findkey(params, "DEBUGFLG")) {
02694 debugflg = getkey_int(params, "DEBUGFLG");
02695 if(debugflg) {
02696 write_log("!!Keylist in taperespwritedo_1() is:\n");
02697 keyiterate(logkey, params);
02698 }
02699 }
02700 tapearcvers = getkey_int(params, "tapearcvers");
02701 retlist = newkeylist();
02702 add_keys(params, &retlist);
02703 if(!(clresp = set_client_handle(TAPEARCPROG, tapearcvers))) {
02704 rinfo = 1;
02705 send_ack();
02706 return((KEY *)1);
02707 }
02708 setkey_fileptr(&retlist, "current_client", (FILE *)clresp);
02709 current_client = clresp;
02710 current_client_destroy = 1;
02711 procnum = TAPEARCDO;
02712 rinfo = RESULT_PEND;
02713 send_ack();
02714 setkey_int(&retlist, "STATUS", 0);
02715 setkey_int(&retlist, "group_id", 666);
02716
02717 return(retlist);
02718 }
02719
02720
02721
02722 KEY *onoffdo_1(KEY *params)
02723 {
02724 char *action;
02725 int retry, istat;
02726
02727 action = getkey_str(params, "action");
02728 write_log("%s: tapeonoff = %s\n", datestring(), action);
02729 if(!strcmp(action, "on")) tapeoffline = 0;
02730 else if(!strcmp(action, "off")) {
02731 if(!robotbusy) tapeoffline = 1;
02732 else {
02733 tapeoffline = 4;
02734 write_log("Can't take offline while robot is busy\n");
02735 }
02736 }
02737 else if(!strcmp(action, "inv")) {
02738 if(!tapeoffline) {
02739 write_log("Can't inventory tapes while tape_svc is still online\n");
02740 tapeoffline = 2;
02741 }
02742 else {
02743 retry = 6;
02744 while(retry) {
02745 #ifdef SUMDC
02746 if((istat = tape_reinventory(sim, 1)) == 0) {
02747 #else
02748
02749 if((istat = tape_reinventory(sim, 1)) == 0) {
02750 #endif
02751 write_log("***Error: Can't do tape inventory. Will retry...\n");
02752 --retry;
02753 if(retry == 0) {
02754 write_log("***Fatal error: Can't do tape inventory\n");
02755 send_mail("***Fatal error: Can't do tape inventory.Abort tape_svc\n");
02756 (void) pmap_unset(TAPEPROG, TAPEVERS);
02757 exit(1);
02758 }
02759 continue;
02760 }
02761 if(istat == -1) {
02762 --retry;
02763 if(retry == 0) {
02764 write_log("***Fatal error: Can't do tape inventory\n");
02765 send_mail("***Fatal error: Can't do tape inventory.Abort tape_svc\n");
02766 (void) pmap_unset(TAPEPROG, TAPEVERS);
02767 exit(1);
02768 }
02769 }
02770 else { retry = 0; }
02771 }
02772 tapeoffline = 3;
02773 }
02774 }
02775 rinfo = tapeoffline;
02776 send_ack();
02777 free(action);
02778 return((KEY *)1);
02779 }
02780
02781
02782
02784 KEY *robotonoffdo_1(KEY *params)
02785 {
02786 char *action;
02787
02788 action = getkey_str(params, "action");
02789 write_log("%s: robotonoff = %s\n", datestring(), action);
02790 if(!strcmp(action, "on")) robotoffline = 0;
02791 else if(!strcmp(action, "off")) robotoffline = 1;
02792 rinfo = robotoffline;
02793 send_ack();
02794 free(action);
02795 return((KEY *)1);
02796 }
02797
02798
02799
02800
02801
02802
02803 KEY *tapenopdo_1(KEY *params)
02804 {
02805 rinfo = 0;
02806 write_log("TAPENOPDO for user=%s uid=%lu\n",
02807 GETKEY_str(params, "USER"), getkey_uint64(params, "uid"));
02808 send_ack();
02809 return((KEY *)1);
02810 }
02811
02812
02813
02814 KEY *dronoffdo_1(KEY *params)
02815 {
02816 static KEY *xlist;
02817 uint64_t robotback;
02818 char *action, *tapeid, *call_err;
02819 int drivenum, slotnum, forceflg;
02820 char cmd[80];
02821 enum clnt_stat status;
02822
02823 action = getkey_str(params, "action");
02824 drivenum = getkey_int(params, "drivenum");
02825 forceflg = getkey_int(params, "forceflg");
02826 write_log("%s: driveonoff = %s %d\n", datestring(), action, drivenum);
02827 if(drivenum >= MAX_DRIVES) {
02828 write_log("Error driveonoff drivenum >= MAX_DRIVES (%d)\n", MAX_DRIVES);
02829 driveonoffstatus = 2;
02830 }
02831
02832
02833
02834
02835 else if(!strcmp(action, "on")) {
02836 if(drives[drivenum].busy) {
02837 write_log("Drive# %d currently busy. Try again later.\n", drivenum);
02838 driveonoffstatus = 3;
02839 }
02840 else {
02841 driveonoffstatus = 0;
02842 drives[drivenum].offline = 0;
02843 }
02844 }
02845 else if(!strcmp(action, "off")) {
02846 if(drives[drivenum].busy) {
02847 if(!forceflg) {
02848 write_log("Drive# %d currently busy. Try again later.\n", drivenum);
02849 driveonoffstatus = 3;
02850 rinfo = driveonoffstatus;
02851 send_ack();
02852 free(action);
02853 return((KEY *)1);
02854 }
02855 drives[drivenum].busy = 0;
02856 }
02857 driveonoffstatus = 1;
02858 drives[drivenum].offline = 1;
02859
02860 if(tapeid = drives[drivenum].tapeid) {
02861 xlist = newkeylist();
02862 robotbusy = 1;
02863 drives[drivenum].busy = 1;
02864 write_log("*Tp:DrBusy: drv=%d\n", drivenum);
02865 slotnum = drives[drivenum].slotnum;
02866 setkey_str(&xlist, "OP", "mv");
02867 setkey_int(&xlist, "dnum", drivenum);
02868 setkey_int(&xlist, "snum", slotnum);
02869 sprintf(cmd, "mtx -f %s unload %d %d 1> /tmp/mtx/mtx_robot_%d.log 2>&1",
02870 libdevname, slotnum+1, drivenum, robotcmdseq++);
02871 setkey_str(&xlist, "cmd1", cmd);
02872 setkey_int(&xlist, "DEBUGFLG", 0);
02873 setkey_fileptr(&xlist, "current_client", (FILE *)current_client);
02874 robotback = 0;
02875 status = clnt_call(clntrobot0, ROBOTDO, (xdrproc_t)xdr_Rkey,(char *)xlist,
02876 (xdrproc_t)xdr_uint32_t, (char *)&robotback, TIMEOUT);
02877 if(status != RPC_SUCCESS) {
02878 if(status != RPC_TIMEDOUT) {
02879 call_err = clnt_sperror(clntrobot0, "Err clnt_call for ROBOTDO");
02880 write_log("%s %s\n", datestring(), call_err);
02881 robotbusy = 0;
02882 drives[drivenum].busy = 0;
02883 write_log("*Tp:DrNotBusy: drv=%d\n", drivenum);
02884 }
02885 }
02886 if(robotback == 1) {
02887 write_log("**Error in ROBOTDO call in tape_svc_proc.c\n");
02888 robotbusy = 0;
02889 drives[drivenum].busy = 0;
02890 write_log("*Tp:DrNotBusy: drv=%d\n", drivenum);
02891 }
02892 freekeylist(&xlist);
02893 }
02894 }
02895 else if(!strcmp(action, "status")) {
02896 if(drives[drivenum].busy) {
02897 write_log("Drive# %d currently busy. Try again later.\n", drivenum);
02898 driveonoffstatus = 3;
02899 }
02900 else driveonoffstatus = drives[drivenum].offline;
02901 }
02902 rinfo = driveonoffstatus;
02903 send_ack();
02904 free(action);
02905 return((KEY *)1);
02906 }
02907
02908 int send_mail(char *fmt, ...)
02909 {
02910 va_list args;
02911 char string[1024], cmd[1024];
02912
02913 va_start(args, fmt);
02914 vsprintf(string, fmt, args);
02915
02916 sprintf(cmd, "echo \"%s\" | Mail -s \"tape_svc mail\" jim@sun.stanford.edu,hao@sun.stanford.edu,jeneen@sun.stanford.edu", string);
02917 system(cmd);
02918 va_end(args);
02919 return(0);
02920 }
02921
02922 void write_time()
02923 {
02924 struct timeval tvalr;
02925 struct tm *t_ptr;
02926
02927 if(gettimeofday(&tvalr, NULL) == -1) {
02928 write_log("Error on gettimeofday() in write_time()\n");
02929 return;
02930 }
02931 t_ptr = localtime((const time_t *)&tvalr);
02932 sprintf(dstring, "%s", asctime(t_ptr));
02933 write_log("%s", dstring);
02934 }