00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <SUM.h>
00054 #include <sum_rpc.h>
00055 #include <tape.h>
00056 #include <string.h>
00057 #include <sys/errno.h>
00058 extern int errno;
00059
00060 #ifdef SUMDC
00061 #define STATUSDUMP "/tmp/t50_status_dump.out"
00062 #define STATUSDUMPSIM "/usr/local/logs/SUM/t50_status_dump.out.sim"
00063 #elif SUMT120
00064 #define STATUSDUMP "/tmp/t120_status_dump.out"
00065 #define STATUSDUMPSIM "/usr/local/logs/SUM/t120_status_dump.out.sim"
00066 #elif SUMT950
00067 #define STATUSDUMP "/tmp/t950_status_dump.out"
00068 #define STATUSDUMPSIM "/usr/local/logs/SUM/t950_status_dump.out.sim"
00069 #define STATUSDUMPSIMREINV "/tmp/t950_status_dump.jmtx"
00070 #endif
00071 #define VDUMP "/usr/local/logs/SUM/t950_status.verify"
00072
00073 extern int write_log();
00074
00075 extern SLOT slots[];
00076 extern DRIVE drives[];
00077 extern int Empty_Slot_Cnt;
00078
00079
00080
00081
00082
00083
00084
00085 int tape_inventory(int sim, int catalog)
00086 {
00087 FILE *finv;
00088 char cmd[MAXSTR], row[MAXSTR], smsg[MAXSTR];
00089 char *token, *cptr;
00090 char *tapeidclosed[MAX_SLOTS+MAX_DRIVES];
00091 int drivenum, slotnum, i, j, k, tstate;
00092 int drive_full[MAX_DRIVES];
00093 int cx = 0;
00094
00095 write_log("tape_inventory() called with sim = %d\n", sim);
00096
00097
00098
00099 sprintf(cmd, "/usr/sbin/mtx -f %s status 1> %s 2>&1", LIBDEV, STATUSDUMP);
00100 write_log("*Inv: %s\n", cmd);
00101 if(sim) {
00102 sleep(5);
00103 sprintf(cmd, "cp %s %s", STATUSDUMPSIM, STATUSDUMP);
00104 system(cmd);
00105 }
00106 else {
00107 if(system(cmd)) {
00108
00109 return(0);
00110 }
00111 }
00112 write_log("***Inv: success\n\n");
00113 if (!(finv = fopen(STATUSDUMP, "r"))) {
00114 write_log("**Fatal error: can't open %s\n", STATUSDUMP);
00115 return(0);
00116 }
00117 drivenum = slotnum = 0;
00118 Empty_Slot_Cnt = 0;
00119 for(i=0; i < MAX_DRIVES; i++) { drive_full[i] = -1; }
00120 i = j = 0;
00121 while (fgets (row,MAXSTR,finv)) {
00122 if(strstr(row, "Data Transfer Element")) {
00123 if(drivenum == MAX_DRIVES) {
00124 write_log("**Warning: there are more drives then MAX_DRIVES (%d)\n",
00125 MAX_DRIVES);
00126
00127 }
00128 if(strstr(row, ":Full")) {
00129 token = (char *)strtok(row, "=");
00130 token = (char *)strtok(NULL, "=");
00131 if(!token) {
00132 token = "NoBar ";
00133 } else {
00134 token = token+1;
00135 cptr = index(token, ' ');
00136 *cptr = (char)NULL;
00137 }
00138 drive_full[i++] = drivenum;
00139 drives[drivenum].tapeid = (char *)strdup(token);
00140 drives[drivenum].sumid = 0;
00141 drives[drivenum].busy = 0;
00142 drives[drivenum].tapemode = 0;
00143 drives[drivenum].filenum = 0;
00144 drives[drivenum].blocknum = 0;
00145 drives[drivenum].slotnum = 0;
00146 write_log("tapeid in drive %d = %s\n",
00147 drivenum, drives[drivenum].tapeid);
00148 if(catalog) {
00149 if((tstate=SUMLIB_TapeCatalog(drives[drivenum].tapeid)) == 0) {
00150 write_log("***ERROR: Can't catalog new tapeid = %s\n",
00151 drives[drivenum].tapeid);
00152 }
00153 else {
00154 if(tstate == TAPECLOSED) {
00155 tapeidclosed[cx++] = drives[drivenum].tapeid;
00156 }
00157 }
00158 }
00159 }
00160 else {
00161 drives[drivenum].tapeid = NULL;
00162 drives[drivenum].sumid = 0;
00163 drives[drivenum].busy = 0;
00164 drives[drivenum].tapemode = 0;
00165 drives[drivenum].filenum = 0;
00166 drives[drivenum].blocknum = 0;
00167 drives[drivenum].slotnum = -1;
00168 write_log("tapeid in drive %d = %s\n",
00169 drivenum, drives[drivenum].tapeid);
00170 }
00171 drivenum++;
00172 }
00173 else if(strstr(row, "Storage Element")) {
00174 if(slotnum == MAX_SLOTS) {
00175 write_log("**Fatal error: there are more slots then MAX_SLOTS=%d\n",
00176 MAX_SLOTS);
00177 return(0);
00178 }
00179 sprintf(smsg, " ");
00180 if(strstr(row, ":Full")) {
00181 token = (char *)strtok(row, "=");
00182 token = (char *)strtok(NULL, "=");
00183 if(!token) {
00184 token = "NoBar ";
00185 } else {
00186 cptr = index(token, ' ');
00187 *cptr = (char)NULL;
00188 }
00189 slots[slotnum].slotnum = slotnum;
00190 slots[slotnum].tapeid = (char *)strdup(token);
00191 if(catalog) {
00192 if((tstate=SUMLIB_TapeCatalog(slots[slotnum].tapeid)) == 0) {
00193 write_log("***ERROR: Can't catalog new tapeid = %s\n",
00194 slots[slotnum].tapeid);
00195 }
00196 else {
00197 if(tstate == TAPECLOSED) {
00198 tapeidclosed[cx++] = slots[slotnum].tapeid;
00199 }
00200 }
00201 }
00202 }
00203 else {
00204 if(j < MAX_DRIVES) {
00205 if((k = drive_full[j++]) != -1) {
00206 drives[k].slotnum = slotnum;
00207 sprintf(smsg, "Slot assigned to drive #%d", k);
00208 }
00209 }
00210 slots[slotnum].slotnum = slotnum;
00211 slots[slotnum].tapeid = NULL;
00212 Empty_Slot_Cnt++;
00213 }
00214 write_log("tapeid in slot# %d = %s %s\n",
00215 slotnum+1, slots[slotnum].tapeid, smsg);
00216 slotnum++;
00217 }
00218 }
00219 write_log("***ENDInv: slots=%d\n", slotnum);
00220 fclose(finv);
00221 if(slotnum != MAX_SLOTS) {
00222 write_log("Inv returned wrong # of slots. Retry.\n");
00223 return(-1);
00224 }
00225
00226
00227
00228
00229 write_log("***ENDInvPhase:\n");
00230 for(i=0; i < cx; i++) {
00231
00232 }
00233 return(1);
00234 }
00235
00236
00237
00238
00239
00240
00241
00242
00243 int tape_reinventory(int sim, int catalog)
00244 {
00245 FILE *finv;
00246 char cmd[MAXSTR], row[MAXSTR], smsg[MAXSTR];
00247 char *token, *cptr;
00248 char *tapeidclosed[MAX_SLOTS+MAX_DRIVES];
00249 int drivenum, slotnum, i, j, k, tstate;
00250 int drive_full[MAX_DRIVES];
00251 int cx = 0;
00252
00253 write_log("tape_reinventory() called with catalog = %d\n", catalog);
00254
00255
00256
00257 sprintf(cmd, "/usr/sbin/mtx -f %s status 1> %s 2>&1", LIBDEV, STATUSDUMP);
00258 if(sim) {
00259 sleep(5);
00260 sprintf(cmd, "cp %s %s", STATUSDUMPSIMREINV, STATUSDUMP);
00261 write_log("*Inv: %s\n", cmd);
00262 system(cmd);
00263 }
00264 else {
00265 write_log("*Inv: %s\n", cmd);
00266 if(system(cmd)) {
00267 write_log("ReInv Fail on: %s\n", cmd);
00268 return(0);
00269 }
00270 }
00271 if (!(finv = fopen(STATUSDUMP, "r"))) {
00272 write_log("**Fatal error: can't open %s\n", STATUSDUMP);
00273 return(0);
00274 }
00275 write_log("***Inv: success\n\n");
00276 drivenum = slotnum = 0;
00277 Empty_Slot_Cnt = 0;
00278 for(i=0; i < MAX_DRIVES; i++) { drive_full[i] = -1; }
00279 i = j = 0;
00280 while (fgets (row,MAXSTR,finv)) {
00281 if(strstr(row, "Data Transfer Element")) {
00282 if(drivenum == MAX_DRIVES) {
00283 write_log("**Warning: there are more drives then MAX_DRIVES (%d)\n",
00284 MAX_DRIVES);
00285 return(0);
00286 }
00287 if(strstr(row, ":Full")) {
00288 token = (char *)strtok(row, "=");
00289 token = (char *)strtok(NULL, "=");
00290 if(!token) {
00291 token = "NoBar ";
00292 } else {
00293 token = token+1;
00294 cptr = index(token, ' ');
00295 *cptr = (char)NULL;
00296 }
00297 drive_full[i++] = drivenum;
00298 drives[drivenum].tapeid = (char *)strdup(token);
00299
00300
00301
00302 drives[drivenum].filenum = 0;
00303
00304
00305 write_log("tapeid in drive %d = %s\n",
00306 drivenum, drives[drivenum].tapeid);
00307 if(catalog) {
00308 if((tstate=SUMLIB_TapeCatalog(drives[drivenum].tapeid)) == 0) {
00309 write_log("***ERROR: Can't catalog new tapeid = %s\n",
00310 drives[drivenum].tapeid);
00311 }
00312 else {
00313 if(tstate == TAPECLOSED) {
00314 tapeidclosed[cx++] = drives[drivenum].tapeid;
00315 }
00316 }
00317 }
00318 }
00319 else {
00320 drives[drivenum].tapeid = NULL;
00321 drives[drivenum].sumid = 0;
00322 drives[drivenum].busy = 0;
00323 drives[drivenum].tapemode = 0;
00324 drives[drivenum].filenum = 0;
00325 drives[drivenum].blocknum = 0;
00326 drives[drivenum].slotnum = -1;
00327 write_log("tapeid in drive %d = %s\n",
00328 drivenum, drives[drivenum].tapeid);
00329 }
00330 drivenum++;
00331 }
00332 else if(strstr(row, "Storage Element")) {
00333 if(slotnum == MAX_SLOTS) {
00334 write_log("**Fatal error: there are more slots then MAX_SLOTS=%d\n",
00335 MAX_SLOTS);
00336 return(0);
00337 }
00338 sprintf(smsg, " ");
00339 if(strstr(row, ":Full")) {
00340 token = (char *)strtok(row, "=");
00341 token = (char *)strtok(NULL, "=");
00342 if(!token) {
00343 token = "NoBar ";
00344 } else {
00345 cptr = index(token, ' ');
00346 *cptr = (char)NULL;
00347 }
00348 slots[slotnum].slotnum = slotnum;
00349 slots[slotnum].tapeid = (char *)strdup(token);
00350 if(catalog) {
00351 if((tstate=SUMLIB_TapeCatalog(slots[slotnum].tapeid)) == 0) {
00352 write_log("***ERROR: Can't catalog new tapeid = %s\n",
00353 slots[slotnum].tapeid);
00354 }
00355 else {
00356 if(tstate == TAPECLOSED) {
00357 tapeidclosed[cx++] = slots[slotnum].tapeid;
00358 }
00359 }
00360 }
00361 }
00362 else {
00363 if(j < MAX_DRIVES) {
00364 if((k = drive_full[j++]) != -1) {
00365 drives[k].slotnum = slotnum;
00366 sprintf(smsg, "Slot assigned to drive #%d", k);
00367 }
00368 }
00369 slots[slotnum].slotnum = slotnum;
00370 slots[slotnum].tapeid = NULL;
00371 Empty_Slot_Cnt++;
00372 }
00373 write_log("tapeid in slot# %d = %s %s\n",
00374 slotnum+1, slots[slotnum].tapeid, smsg);
00375 slotnum++;
00376 }
00377 }
00378 write_log("***ENDInv: slots=%d\n", slotnum);
00379 fclose(finv);
00380 if(slotnum != MAX_SLOTS) {
00381 write_log("Inv returned wrong # of slots. Retry.\n");
00382 return(-1);
00383 }
00384
00385
00386
00387
00388 write_log("***ENDInvPhase:\n");
00389 for(i=0; i < cx; i++) {
00390 write_log("*Tp:ReClose: tapeid=%s\n", tapeidclosed[i]);
00391 }
00392 return(1);
00393 }
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 int robot_verify(char *action, int slot, int slotordrive)
00409 {
00410 FILE *finv;
00411 int s, sord, retry;
00412 int drivenum, slotnum, i, j, k, tstate;
00413 char *drive_tapes[MAX_DRIVES], *slot_tapes[MAX_SLOTS];
00414 char *token, *cptr;
00415 char cmd[MAXSTR], row[MAXSTR];
00416
00417 retry = 6;
00418 while(retry) {
00419 sprintf(cmd, "/usr/sbin/mtx -f %s status 1> %s 2>&1", LIBDEV, VDUMP);
00420 if(system(cmd)) {
00421 write_log("***Verify: failure. errno=%d\n", errno);
00422 return(-1);
00423 }
00424 if (!(finv = fopen(VDUMP, "r"))) {
00425 write_log("**Fatal error: can't open %s\n", VDUMP);
00426 return(-1);
00427 }
00428 drivenum = slotnum = 0;
00429 for(i=0; i < MAX_DRIVES; i++) { drive_tapes[i] = "NoTape"; }
00430 while (fgets (row,MAXSTR,finv)) {
00431 if(strstr(row, "Data Transfer Element")) {
00432 if(strstr(row, ":Full")) {
00433 token = (char *)strtok(row, "=");
00434 token = (char *)strtok(NULL, "=");
00435 if(!token) {
00436 token = "NoTape";
00437
00438
00439 cptr = index(token, ' ');
00440 *cptr = (char)NULL;
00441 }
00442 drive_tapes[drivenum] = (char *)strdup(token);
00443 }
00444 write_log("tapeid in drive %d = %s\n",
00445 drivenum, drive_tapes[drivenum]);
00446 drivenum++;
00447 }
00448 else if(strstr(row, "Storage Element")) {
00449 if(strstr(row, ":Full")) {
00450 token = (char *)strtok(row, "=");
00451 token = (char *)strtok(NULL, "=");
00452 if(!token) {
00453 token = "NoTape";
00454 } else {
00455 cptr = index(token, ' ');
00456 *cptr = (char)NULL;
00457 }
00458 slot_tapes[slotnum] = (char *)strdup(token);
00459 }
00460 else {
00461 slot_tapes[slotnum] = "NoTape";
00462 }
00463 write_log("tapeid in slot# %d = %s\n",
00464 slotnum+1, slot_tapes[slotnum]);
00465 slotnum++;
00466 }
00467 }
00468 fclose(finv);
00469 if(slotnum != MAX_SLOTS) {
00470 write_log("Inv returned wrong # of slots. Retry.\n");
00471 --retry;
00472 if(retry == 0) {
00473 write_log("***Fatal error: Can't do tape inventory\n");
00474 return(-1);
00475 }
00476 }
00477 else { retry = 0; }
00478 }
00479
00480 if(!strcmp(action, "unload")) {
00481 if(strcmp(drive_tapes[slotordrive], "NoTape")) {
00482 return(0);
00483 }
00484 if(!strcmp(slot_tapes[slot], "NoTape")) {
00485 return(0);
00486 }
00487 return(1);
00488 }
00489 else if(!strcmp(action, "load")) {
00490 if(!strcmp(drive_tapes[slotordrive], "NoTape")) {
00491 return(0);
00492 }
00493 if(strcmp(slot_tapes[slot], "NoTape")) {
00494 return(0);
00495 }
00496 return(1);
00497 }
00498 else {
00499 if(strcmp(slot_tapes[slot], "NoTape")) {
00500 return(0);
00501 }
00502 if(!strcmp(slot_tapes[slotordrive], "NoTape")) {
00503 return(0);
00504 }
00505 return(1);
00506 }
00507 }