|
|
1.1 root 1: #define _POSIX_SOURCE
2: #include <stddef.h>
3: #include <stdlib.h>
4: #include <unistd.h>
5: #include <stdio.h>
6: #include <string.h>
7: #include <ctype.h>
8: #include "jukeface.h"
9: #include "jukebox.h"
10: #include "tcl.h"
11: #include "generic/fns.h"
12:
13: static sort(char *buf);
14:
15: j_cold(Jukebox *j, char *type, char *err)
16: {
17: int side;
18: int drive, sh, nsh;
19: int n;
20: char vol_id[512];
21: char *didit;
22:
23: if(j_drstatus(j, err))
24: return(-1);
25: if(j_shstatus(j, err))
26: return(-1);
27: /* first clear out nonexistent labels */
28: n = 0;
29: didit = (char *)malloc(j->nshelves*sizeof(char));
30: for(sh = 0; sh < j->nshelves; sh++){
31: if(j->shelves[sh]){
32: n++;
33: j->names[sh] = "there";
34: } else
35: j->names[sh] = 0;
36: didit[sh] = 0;
37: }
38: printf("%d disks in shelves.\n", n);
39: /* second, clear the drives */
40: for(sh = 0; sh < j->nshelves; sh++)
41: if(j->shelves[sh] == 0)
42: break;
43: for(drive = 0; drive < j->nluns; drive++){
44: if(!j->luns[drive].occupied)
45: continue; /* no disk in drive */
46: if(j->luns[drive].shelf < 0){
47: if(j_dr_to_sh(drive, sh, SIDEA, err))
48: return(-1);
49: for(sh++; sh < j->nshelves; sh++)
50: if(j->shelves[sh] == 0)
51: break;
52: n++;
53: } else
54: if(j_dr_to_sh(drive, -1, SIDEA, err))
55: return(-1);
56: }
57: drive = j->nluns-1;
58: if(isdigit(*type)){ /* just do one shelf */
59: sh = atol(type);
60: printf("single shelf %d reload\n", sh);
61: if(j_rdshelves(j, err))
62: return(-1);
63: if(getvol(sh, drive, vol_id, &side)){
64: strcpy(err, vol_id);
65: return(-1);
66: }
67: printf("%s@%d -> %d\n", vol_id, sh, sh);
68: if(j_dr_to_sh(drive, -1, side, err) < 0)
69: return(-1);
70: j->names[sh] = strdup(vol_id);
71: j->shelves[sh] = 1;
72: j_wrshelf = 1;
73: return(0);
74: }
75: printf("reloading %d disks.\n", n);
76: side = SIDEA;
77: j_wrshelf = 1;
78: for(sh = 0; sh < j->nshelves; sh++){
79: if(didit[sh])
80: continue;
81: j->names[sh] = 0;
82: if(j->shelves[sh]){
83: printf("%d: ", sh); fflush(stdout);
84: if(getvol(sh, drive, vol_id, &side)){
85: strcpy(err, vol_id);
86: return(-1);
87: }
88: j->shelves[sh] = 0;
89: switch(*type)
90: {
91: case 'c':
92: for(nsh = 0; j->shelves[nsh]; nsh++)
93: ;
94: break;
95: case 's':
96: case 'r':
97: while(j->shelves[nsh = nrand(j->nshelves)])
98: ;
99: break;
100: case 'u':
101: default:
102: nsh = sh;
103: break;
104: }
105: printf("%s@%d -> %d\n", vol_id, sh, nsh);
106: if(j_dr_to_sh(drive, nsh, side, err) < 0)
107: return(-1);
108: j->names[nsh] = strdup(vol_id);
109: j->shelves[nsh] = 1;
110: didit[nsh] = 1;
111: sleep(5);
112: }
113: }
114: printf("process any new disks.\n");
115: if(j_warm(j, err))
116: return(-1);
117: /* if(type == 's')
118: return(sort(err));
119: */
120: return(0);
121: }
122:
123: getvol(int sh, int drive, char *vol_id, int *side)
124: {
125: int i;
126: char buf[512];
127:
128: if(j_sh_to_dr(sh, SIDEA, drive, vol_id) < 0)
129: return(-1);
130: if((i = j_rvolid(drive, buf)) < 0)
131: goto softerr;
132: if(i == 0)
133: *side = SIDEA;
134: else {
135: *side = SIDEB;
136: if(j_dr_to_sh(drive, sh, SIDEA, vol_id) < 0)
137: return(-1);
138: if(j_sh_to_dr(sh, SIDEB, drive, vol_id) < 0)
139: return(-1);
140: if((i = j_rvolid(drive, buf)) < 0)
141: goto softerr;
142: }
143: if(i > 0)
144: strcpy(vol_id, UNALLOCATED);
145: else {
146: strcpy(vol_id, buf);
147: i = strlen(vol_id)-1;
148: if(i < 0){
149: sprintf(buf, "apparently good superblock but null vol_id");
150: goto softerr;
151: } else if(vol_id[i] == 'a')
152: vol_id[i] = 0;
153: else if(vol_id[i] == 'b'){
154: vol_id[i] = 0;
155: *side = !*side;
156: } else {
157: sprintf(buf, "vol_id '%s' must end in a or b", vol_id);
158: strcpy(vol_id, buf);
159: return(-1);
160: }
161: }
162: return(0);
163: softerr:
164: *side = SIDEA;
165: fprintf(stderr, "error in reading shelf %d: %s; proceeding\n", sh, buf);
166: sprintf(vol_id, "DISK_ERROR%d", sh);
167: j_reset();
168: return(0);
169: }
170: #ifdef CRAP
171: static int index[j->nshelves];
172: static
173: cmp(int *a, int *b)
174: {
175: char *sa = j->shelves[*a], *sb = j->shelves[*b];
176:
177: if((sa == 0) && (sb == 0)) return(0);
178: if(sa == 0) return(-1);
179: if(sb == 0) return(1);
180: return(strcmp(sa, sb));
181: }
182:
183: static char *disk[8];
184:
185: static
186: sd(int a, int b, char *err)
187: {
188: disk[b] = j->shelves[a];
189: return(j->shelves_to_drive(a, SIDEB, b, err));
190: }
191: static
192: ds(int a, int b, char *err)
193: {
194: j->shelves[b] = disk[a];
195: return(j_drive_to_shelf(a, b, SIDEB, err));
196: }
197:
198: static
199: sort(char *errbuf)
200: {
201: int i, j, org;
202:
203: for(i = 0; i < j->nshelves; i++)
204: index[i] = i;
205: qsort(index, j->nshelves, sizeof index[0], cmp);
206: for(i = 0; i < j->nshelves; i++){
207: if(index[i] < 0) continue;
208: if(sd(org = i, NLUN-1, errbuf) < 0)
209: return(-1);
210: j = index[i];
211: index[i] = -1;
212: while(j != org){
213: if(sd(j, NLUN-2, errbuf) < 0)
214: return(-1);
215: if(ds(NLUN-2, i, errbuf) < 0)
216: return(-1);
217: i = j;
218: if(index[i] < 0)
219: break;
220: j = index[i];
221: index[i] = -1;
222: }
223: if(ds(NLUN-1, i, errbuf) < 0)
224: return(-1);
225: }
226: return(0);
227: }
228: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.