00001
00002
00003
00004
00005 #include <SUM.h>
00006 #include <soi_key.h>
00007 #include <sys/time.h>
00008 #include <sys/errno.h>
00009 #include <rpc/rpc.h>
00010 #include <sum_rpc.h>
00011 #include <sum_info.h>
00012 #include <soi_error.h>
00013
00014
00015 #include <sys/mtio.h>
00016
00017 #include <scsi/sg.h>
00018 #include <unistd.h>
00019 #include <sys/socket.h>
00020 #include <stdio.h>
00021 #include "tape.h"
00022
00023 static char *rcsid="$Id: main3.c,v 1.9 2012/09/28 17:42:28 arta Exp $";
00024
00025 extern int errno;
00026
00027
00028
00029
00030 void logkey();
00031
00032 KEY *rlist;
00033 KEY *list = NULL;
00034 FILE *logfp;
00035 SUM_t *sum;
00036 SUMID_t uid;
00037 CLIENT *cl;
00038
00039 int soi_errno = NO_ERROR;
00040 int bytes, msgtag, petid, req_num, status, cnt, i, j, inum;
00041 char **cptr;
00042 float ftmp;
00043 uint64_t *dsixpt;
00044 uint64_t alloc_index;
00045 uint64_t ix;
00046 char alloc_wd[64];
00047 char cmd[128];
00048 char mod_name[] = "sum_rpc";
00049 char dsname[] = "hmi_lev1_fd_V";
00050 char hcomment[] = "this is a dummy history comment that is greater than 80 chars long to check out the code";
00051
00052 static struct timeval first[8], second[8];
00053
00054 void StartTimer(int n)
00055 {
00056 gettimeofday (&first[n], NULL);
00057 }
00058
00059 float StopTimer(int n)
00060 {
00061 gettimeofday (&second[n], NULL);
00062 if (first[n].tv_usec > second[n].tv_usec) {
00063 second[n].tv_usec += 1000000;
00064 second[n].tv_sec--;
00065 }
00066 return (float) (second[n].tv_sec-first[n].tv_sec) +
00067 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00068 }
00069
00070 int write_log(const char *fmt, ...)
00071 {
00072 va_list args;
00073 char string[4096];
00074
00075 va_start(args, fmt);
00076 vsprintf(string, fmt, args);
00077 if(logfp) {
00078 fprintf(logfp, string);
00079 fflush(logfp);
00080 }
00081 else
00082 fprintf(stderr, string);
00083 va_end(args);
00084 return(0);
00085 }
00086
00087 void str_compress (char *s) {
00088 char *source, *dest;
00089 source = dest = s;
00090 while (*source) {
00091 if (!isspace (*source)) {
00092 *dest = *source;
00093 dest++;
00094 }
00095 source++;
00096 }
00097 *dest = 0;
00098 }
00099
00100 int my_random(int min, int max)
00101 {
00102 return rand() % (max - min + 1) + min;
00103 }
00104
00105
00106
00107
00108
00109
00110 int main(int argc, char *argv[])
00111 {
00112
00113
00114 int num, c;
00115 int stime;
00116 int xflg = 0;
00117 long ltime;
00118
00119
00120 while(--argc > 0 && (*++argv)[0] == '-') {
00121 while(c = *++argv[0])
00122 switch(c) {
00123 case 'x':
00124 xflg=1;
00125 break;
00126 }
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 FILE *logfp, *drfp;
00216 int jmode, order0;
00217 char *j_env, *deldate;
00218 char sqlcmd[256], pcmd[256], line[256], logget[80];
00219 char logname[256], rwchars[32];
00220 int drive_order_rd[MAX_DRIVES];
00221 int drive_order_wt[MAX_DRIVES];
00222 int nxtscanrd;
00223 int nxtscanwt;
00224 int max_drives_rd = 0;
00225 int max_drives_wt = 0;
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 if((sum = SUM_open(NULL, NULL, printf)) == 0) {
00342 printf("Failed on SUM_open()\n");
00343 exit(1);
00344 }
00345
00346
00347
00348
00349
00350
00351
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 uid = sum->uid;
00364
00365
00366 sum->username = "production";
00367 printf("Opened with sumid = %d\n", uid);
00368
00369 sum->bytes = (double)120000000;
00370 sum->reqcnt = 1;
00371 sum->storeset = 0;
00372 sum->group = 4;
00373
00374 if(status = SUM_alloc(sum, printf)) {
00375 printf("SUM_alloc() failed to alloc %g bytes. Error code = %d\n",
00376 sum->bytes, status);
00377 SUM_close(sum, printf);
00378 exit(1);
00379 }
00380
00381
00382 cptr = sum->wd;
00383 dsixpt = sum->dsix_ptr;
00384 alloc_index = *dsixpt;
00385 strcpy(alloc_wd, *cptr);
00386 printf("Allocated %g bytes at %s with dsindex=%ld\n",
00387 sum->bytes, *cptr, alloc_index);
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 XXX:
00400
00401 sum->mode = RETRIEVE + TOUCH;
00402
00403
00404 sum->tdays = 30;
00405
00406 sum->reqcnt = 1;
00407 dsixpt = sum->dsix_ptr;
00408
00409
00410 *dsixpt++ = 101706864;
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 status = SUM_get(sum, printf);
00433 printf("status from SUM_get() = %d\n", status);
00434
00435 switch(status) {
00436 case 0:
00437 cnt = sum->reqcnt;
00438 cptr = sum->wd;
00439 dsixpt = sum->dsix_ptr;
00440
00441 for(i = 0; i < cnt; i++) {
00442 printf("ds_index = %u\n", *dsixpt++);
00443 printf("wd = %s\n", *cptr++);
00444 }
00445 break;
00446 case 1:
00447 cptr = sum->wd;
00448 dsixpt = sum->dsix_ptr;
00449 printf("Failed on SUM_get() for ix=%lu\n", *dsixpt++);
00450 break;
00451 case RESULT_PEND:
00452 printf("SUM_get() call RESULT_PEND...\n");
00453
00455 dsixpt = sum->dsix_ptr;
00456 *dsixpt++ = 101702788;
00457 status = SUM_get(sum, printf);
00458 printf("status from SECOND SUM_get() = %d\n", status);
00460 while(1) {
00461 status = SUM_poll(sum);
00462 printf("SUM_poll() returns %d\n", status);
00463 if(status == 0) break;
00464 sleep(8);
00465
00466
00467
00468
00469
00470 }
00471
00472
00473
00474
00475
00476
00477 if(sum->status) {
00478 printf("***Error on SUM_get() call. tape_svc may have died or\n");
00479 printf("check /usr/local/logs/SUM/ logs for possible tape errs\n\n");
00480 break;
00481 }
00482 cnt = sum->reqcnt;
00483 cptr = sum->wd;
00484 printf("The wd's found from the SUM_get() call are:\n");
00485 for(i = 0; i < cnt; i++) {
00486 printf("wd = %s\n", *cptr++);
00487 }
00488 break;
00489 default:
00490 printf("Error: unknown status from SUM_get()\n");
00491 break;
00492 }
00493
00494
00495
00496 SUM_info_t *sinfo;
00497 int i, j, cnt;
00498
00499 ftmp = StopTimer(0);
00500
00501
00502 uint64_t dxarray[65536];
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 ix = 18857884;
00513 for(i=0; i < 65536; i++) {
00514 dxarray[i] = ix++;
00515 }
00516
00517 dxarray[0] = 18857884;
00518 dxarray[1] = 40350694;
00519 dxarray[2] = 18857895;
00520 dxarray[3] = 18857886;
00521 dxarray[4] = 18857891;
00522 dxarray[5] = 18857888;
00523 dxarray[6] = 18857893;
00524 dxarray[7] = 18857888;
00525 dxarray[8] = 18857896;
00526 dxarray[9] = 18857897;
00527
00528
00529 cnt = 2048;
00530
00531
00532 for(i=0; i < 1; i++) {
00533 sum->sinfo = NULL;
00534 StartTimer(0);
00535 status = SUM_infoArray(sum, &dxarray, cnt, printf);
00536 ftmp = StopTimer ( 0 ) ;
00537 printf( "Time sec for %d SUM_infoArray() = %f\n", cnt, ftmp );
00538
00539 if(xflg) {
00540 sinfo = sum->sinfo;
00541 for(j=0; j < cnt; j++) {
00542 printf("\ncount of sinfo = %d\n", j);
00543 printf("sum_info sunum = %u\n", sinfo->sunum);
00544 printf("sum_info username = %s\n", sinfo->username);
00545 printf("sum_info online_loc = %s\n", sinfo->online_loc);
00546 printf("sum_info online_status = %s\n", sinfo->online_status);
00547 printf("sum_info archive_status = %s\n", sinfo->archive_status);
00548 printf("sum_info history_comment = %s\n", sinfo->history_comment);
00549 printf("sum_info owning_series = %s\n", sinfo->owning_series);
00550 printf("sum_info bytes = %g\n", sinfo->bytes);
00551 printf("sum_info creat_date = %s\n", sinfo->creat_date);
00552 printf("sum_info arch_tape = %s\n", sinfo->arch_tape);
00553 printf("sum_info arch_tape_fn = %d\n", sinfo->arch_tape_fn);
00554 printf("sum_info arch_tape_date = %s\n", sinfo->arch_tape_date);
00555 printf("sum_info pa_status = %d\n", sinfo->pa_status);
00556 printf("sum_info pa_substatus = %d\n", sinfo->pa_substatus);
00557 printf("sum_info effective_date = %s\n", sinfo->effective_date);
00558 sinfo = sinfo->next;
00559 }
00560 }
00561 SUM_infoArray_free(sum);
00562
00563
00564 }
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 ix = 669;
00580
00581
00582 goto ABC;
00583
00584
00585 StartTimer(1);
00586 for(i=0; i < 64; i++) {
00587 if(SUM_info(sum, ix, printf)) {
00588 printf("Fail on SUM_info() in main3 ix=%u\n", ix);
00589 }
00590 else {
00591 sinfo = sum->sinfo;
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 }
00607 ix++;
00608 }
00609 ftmp = StopTimer ( 1 ) ;
00610 printf( "\nTime sec for 64 SUM_info() = %f\n\n", ftmp );
00611
00612
00613 ABC:
00614
00615 ;int cy, dcnt, rcnt;
00616 ix = 187699530;
00617
00618 StartTimer(1);
00619
00620 rcnt = 512;
00621 sum->reqcnt = rcnt;
00622
00623 dsixpt = sum->dsix_ptr;
00624 for(i=0; i < 512; i++) {
00625 *dsixpt++ = ix++;
00626 }
00627
00628
00629 write_log("\n");
00630
00631
00632 dcnt = 1;
00633 for(cy=0; cy < dcnt; cy++) {
00634 sum->sinfo = NULL;
00635 StartTimer(0);
00636 if(SUM_infoEx(sum, printf)) {
00637 printf("\nFail on SUM_infoEx()\n");
00638 }
00639 else {
00640 ftmp = StopTimer ( 0 ) ;
00641 printf( "Time sec for %d SUM_infoEX() = %f\n", rcnt, ftmp );
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665 }
00666 }
00667 ftmp = StopTimer ( 1 ) ;
00668 printf( "\nTime sec for %d cycles of %d SUM_infoEX() = %f\n\n", dcnt, rcnt, ftmp );
00669
00670 goto GOEND;
00671
00672 DEF:
00673
00674 sum->reqcnt = 512;
00675 sum->sinfo = NULL;
00676 dsixpt = sum->dsix_ptr;
00677 ix = 40350694;
00678 for(i=0; i < 512; i++) {
00679 *dsixpt++ = ix++;
00680 }
00681 StartTimer(0);
00682 if(SUM_infoEx(sum, printf)) {
00683 printf("\nFail on SUM_infoEx()\n");
00684 }
00685 else {
00686 printf("\nOk, on SUM_infoEx()\n");
00687 sinfo = sum->sinfo;
00688 i = 1;
00689 while(sinfo) {
00690 printf("\ncount of sinfo = %d\n", i++);
00691 printf("sum_info sunum = %lu\n", sinfo->sunum);
00692 sinfo = sinfo->next;
00693 }
00694 SUM_infoEx_free(sum);
00695 }
00696 ftmp = StopTimer ( 0 ) ;
00697 printf( "\nTime sec for 512 SUM_infoEX() = %f\n\n", ftmp );
00698 GOEND:
00699 SUM_close(sum, printf);
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715 #define VDUMP "/usr/local/logs/SUM/t950_status.verify"
00716
00717 int robot_verify(char *action, int slot, int slotordrive)
00718 {
00719 FILE *finv;
00720 int s, sord, retry;
00721 int drivenum, slotnum, i, j, k, tstate;
00722 char *drive_tapes[MAX_DRIVES], *slot_tapes[MAX_SLOTS];
00723 char *token, *cptr;
00724 char cmd[MAXSTR], row[MAXSTR];
00725
00726 retry = 6;
00727 while(retry) {
00728 sprintf(cmd, "/usr/sbin/mtx -f %s status 1> %s 2>&1", LIBDEV, VDUMP);
00729 if(system(cmd)) {
00730 write_log("***Verify: failure. errno=%d\n", errno);
00731 return(-1);
00732 }
00733 if (!(finv = fopen(VDUMP, "r"))) {
00734 write_log("**Fatal error: can't open %s\n", VDUMP);
00735 return(-1);
00736 }
00737 drivenum = slotnum = 0;
00738 for(i=0; i < MAX_DRIVES; i++) { drive_tapes[i] = "NoTape"; }
00739 while (fgets (row,MAXSTR,finv)) {
00740 if(strstr(row, "Data Transfer Element")) {
00741 if(strstr(row, ":Full")) {
00742 token = (char *)strtok(row, "=");
00743 token = (char *)strtok(NULL, "=");
00744 if(!token) {
00745 token = "NoTape";
00746
00747
00748 cptr = index(token, ' ');
00749 *cptr = (char)NULL;
00750 }
00751 drive_tapes[drivenum] = (char *)strdup(token);
00752 }
00753 write_log("tapeid in drive %d = %s\n",
00754 drivenum, drive_tapes[drivenum]);
00755 drivenum++;
00756 }
00757 else if(strstr(row, "Storage Element")) {
00758 if(strstr(row, ":Full")) {
00759 token = (char *)strtok(row, "=");
00760 token = (char *)strtok(NULL, "=");
00761 if(!token) {
00762 token = "NoTape";
00763 } else {
00764 cptr = index(token, ' ');
00765 *cptr = (char)NULL;
00766 }
00767 slot_tapes[slotnum] = (char *)strdup(token);
00768 }
00769 else {
00770 slot_tapes[slotnum] = "NoTape";
00771 }
00772 write_log("tapeid in slot# %d = %s\n",
00773 slotnum+1, slot_tapes[slotnum]);
00774 slotnum++;
00775 }
00776 }
00777 fclose(finv);
00778 if(slotnum != MAX_SLOTS) {
00779 write_log("Inv returned wrong # of slots. Retry.\n");
00780 --retry;
00781 if(retry == 0) {
00782 write_log("***Fatal error: Can't do tape inventory\n");
00783 return(-1);
00784 }
00785 }
00786 else { retry = 0; }
00787 }
00788
00789 if(!strcmp(action, "unload")) {
00790 if(strcmp(drive_tapes[slotordrive], "NoTape")) {
00791 return(0);
00792 }
00793 if(!strcmp(slot_tapes[slot], "NoTape")) {
00794 return(0);
00795 }
00796 return(1);
00797 }
00798 else if(!strcmp(action, "load")) {
00799 if(!strcmp(drive_tapes[slotordrive], "NoTape")) {
00800 return(0);
00801 }
00802 if(strcmp(slot_tapes[slot], "NoTape")) {
00803 return(0);
00804 }
00805 return(1);
00806 }
00807 else {
00808 if(strcmp(slot_tapes[slot], "NoTape")) {
00809 return(0);
00810 }
00811 if(!strcmp(slot_tapes[slotordrive], "NoTape")) {
00812 return(0);
00813 }
00814 return(1);
00815 }
00816 }