|
|
1.1 ! root 1: #include <stddef.h> ! 2: #include <stdio.h> ! 3: #include <string.h> ! 4: #include "scsi.h" ! 5: #include "juke.h" ! 6: ! 7: static sort(char *buf); ! 8: ! 9: cold_inv(char type, char *buf) ! 10: { ! 11: Side side; ! 12: int drive, sh, nsh; ! 13: int n; ! 14: char vol_id[512]; ! 15: int didit[NSHELF]; ! 16: ! 17: if(j_getstatus(buf)) /* get the jukebox status */ ! 18: return(-1); ! 19: printf("getstatus done\n"); ! 20: /* first clear out nonexistent labels */ ! 21: n = 0; ! 22: for(sh = 0; sh < NSHELF; sh++){ ! 23: if((j_status.shelf[sh]&0xC0) == 0xC0){ ! 24: n++; ! 25: j_shelf[sh] = "there"; ! 26: } else ! 27: j_shelf[sh] = 0; ! 28: didit[sh] = 0; ! 29: } ! 30: printf("%d disks in shelves.\n", n); ! 31: /* second, clear the drives */ ! 32: for(sh = 0; sh < NSHELF; sh++) ! 33: if(j_shelf[sh] == 0) ! 34: break; ! 35: for(drive = 0; drive < 8; drive++){ ! 36: if(!j_status.lun[drive].diskin) ! 37: continue; /* no disk in drive */ ! 38: printf("clearing drive %d:\n", drive); ! 39: if(j_status.lun[drive].diskindrive && !j_status.lun[drive].shelfvalid){ ! 40: if(j_drive_to_shelf(drive, sh, SIDEA, buf)) ! 41: return(-1); ! 42: for(sh++; sh < NSHELF; sh++) ! 43: if(j_shelf[sh] == 0) ! 44: break; ! 45: n++; ! 46: } else ! 47: if(j_drive_to_shelf(drive, -1, SIDEA, buf)) ! 48: return(-1); ! 49: printf("\n"); ! 50: } ! 51: printf("reloading %d disks.\n", n); ! 52: side = SIDEA; ! 53: drive = min(nlun+1, NLUN-1); ! 54: j_wrshelf = 1; ! 55: for(sh = 0; sh < NSHELF; sh++){ ! 56: if(didit[sh]) ! 57: continue; ! 58: j_shelf[sh] = 0; ! 59: /* the C0 means disk properly present (not temp) */ ! 60: if((j_status.shelf[sh]&0xC0) == 0xC0){ ! 61: if(getvol(sh, drive, vol_id, &side)) ! 62: errexit(vol_id); ! 63: switch(type) ! 64: { ! 65: case 'c': ! 66: for(nsh = 0; j_shelf[nsh]; nsh++) ! 67: ; ! 68: break; ! 69: case 's': ! 70: case 'r': ! 71: while(j_shelf[nsh = nrand(NSHELF)]) ! 72: ; ! 73: break; ! 74: case 'u': ! 75: default: ! 76: nsh = sh; ! 77: break; ! 78: } ! 79: printf("%s@%d -> %d\n", vol_id, sh, nsh); ! 80: if(j_drive_to_shelf(drive, nsh, side, buf) < 0) ! 81: return(-1); ! 82: j_shelf[nsh] = strdup(vol_id); ! 83: didit[nsh] = 1; ! 84: sleep(2); ! 85: } ! 86: } ! 87: printf("process any new disks.\n"); ! 88: if(warm_inv(buf)) ! 89: return(-1); ! 90: if(type == 's') ! 91: return(sort(buf)); ! 92: return(0); ! 93: } ! 94: ! 95: getvol(int sh, int drive, char *vol_id, int *side) ! 96: { ! 97: int i; ! 98: char buf[512]; ! 99: ! 100: if(j_shelf_to_drive(sh, SIDEA, drive, vol_id) < 0) ! 101: return(-1); ! 102: if((i = j_rvolid(drive, buf)) < 0) ! 103: goto softerr; ! 104: if(i == 0) ! 105: *side = SIDEA; ! 106: else { ! 107: *side = SIDEB; ! 108: if(j_drive_to_shelf(drive, sh, SIDEA, vol_id) < 0) ! 109: return(-1); ! 110: if(j_shelf_to_drive(sh, SIDEB, drive, vol_id) < 0) ! 111: return(-1); ! 112: if((i = j_rvolid(drive, buf)) < 0) ! 113: goto softerr; ! 114: } ! 115: if(i > 0) ! 116: strcpy(vol_id, UNALLOCATED); ! 117: else { ! 118: strcpy(vol_id, buf); ! 119: i = strlen(vol_id)-1; ! 120: if(i < 0){ ! 121: sprintf(buf, "apparently good superblock but null vol_id"); ! 122: goto softerr; ! 123: } else if(vol_id[i] == 'a') ! 124: vol_id[i] = 0; ! 125: else if(vol_id[i] == 'b'){ ! 126: vol_id[i] = 0; ! 127: *side = !*side; ! 128: } else { ! 129: sprintf(buf, "vol_id '%s' must end in a or b", vol_id); ! 130: strcpy(vol_id, buf); ! 131: return(-1); ! 132: } ! 133: } ! 134: return(0); ! 135: softerr: ! 136: *side = SIDEA; ! 137: fprintf(stderr, "error in reading shelf %d: %s; proceeding\n", sh, buf); ! 138: sprintf(vol_id, "DISK_ERROR%d", sh); ! 139: gen_reset(0, (int *)0, 0, (char **)0, buf); ! 140: return(0); ! 141: } ! 142: ! 143: static int index[NSHELF]; ! 144: static ! 145: cmp(int *a, int *b) ! 146: { ! 147: char *sa = j_shelf[*a], *sb = j_shelf[*b]; ! 148: ! 149: if((sa == 0) && (sb == 0)) return(0); ! 150: if(sa == 0) return(-1); ! 151: if(sb == 0) return(1); ! 152: return(strcmp(sa, sb)); ! 153: } ! 154: ! 155: static char *disk[8]; ! 156: ! 157: static ! 158: sd(int a, int b, char *err) ! 159: { ! 160: disk[b] = j_shelf[a]; ! 161: return(j_shelf_to_drive(a, SIDEB, b, err)); ! 162: } ! 163: static ! 164: ds(int a, int b, char *err) ! 165: { ! 166: j_shelf[b] = disk[a]; ! 167: return(j_drive_to_shelf(a, b, SIDEB, err)); ! 168: } ! 169: ! 170: static ! 171: sort(char *errbuf) ! 172: { ! 173: int i, j, org; ! 174: ! 175: for(i = 0; i < NSHELF; i++) ! 176: index[i] = i; ! 177: qsort(index, NSHELF, sizeof index[0], cmp); ! 178: for(i = 0; i < NSHELF; i++){ ! 179: if(index[i] < 0) continue; ! 180: if(sd(org = i, NLUN-1, errbuf) < 0) ! 181: return(-1); ! 182: j = index[i]; ! 183: index[i] = -1; ! 184: while(j != org){ ! 185: if(sd(j, NLUN-2, errbuf) < 0) ! 186: return(-1); ! 187: if(ds(NLUN-2, i, errbuf) < 0) ! 188: return(-1); ! 189: i = j; ! 190: if(index[i] < 0) ! 191: break; ! 192: j = index[i]; ! 193: index[i] = -1; ! 194: } ! 195: if(ds(NLUN-1, i, errbuf) < 0) ! 196: return(-1); ! 197: } ! 198: return(0); ! 199: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.