]>
Commit | Line | Data |
---|---|---|
1 | /* $Header$ | |
2 | * | |
3 | * (c) Copyright 1988 by the Massachusetts Institute of Technology. | |
4 | * For copying and distribution information, please see the file | |
5 | * <mit-copyright.h>. | |
6 | */ | |
7 | ||
8 | #include <mit-copyright.h> | |
9 | #include <moira.h> | |
10 | #include "dbck.h" | |
11 | EXEC SQL INCLUDE sqlca; | |
12 | ||
13 | static char phase4_qc_rcsid[] = "$Header$"; | |
14 | ||
15 | ||
16 | count_boxes(id, u, boxes) | |
17 | int id; | |
18 | struct user *u; | |
19 | struct hash *boxes; | |
20 | { | |
21 | int i; | |
22 | ||
23 | if (u->potype == 'P') { | |
24 | if (i = (int) hash_lookup(boxes, u->pobox_id)) | |
25 | hash_store(boxes, u->pobox_id, i+1); | |
26 | else { | |
27 | printf("User %s(%s) has pobox on non-POP server %d\n", | |
28 | u->fullname, u->login, u->pobox_id); | |
29 | printf("Not fixing this error\n"); | |
30 | } | |
31 | } | |
32 | } | |
33 | ||
34 | ||
35 | check_box_counts(id, cnt, counts) | |
36 | EXEC SQL BEGIN DECLARE SECTION; | |
37 | int id, cnt; | |
38 | EXEC SQL END DECLARE SECTION; | |
39 | struct hash *counts; | |
40 | { | |
41 | EXEC SQL BEGIN DECLARE SECTION; | |
42 | int oldval, rowcount; | |
43 | EXEC SQL END DECLARE SECTION; | |
44 | ||
45 | oldval = (int) hash_lookup(counts, id); | |
46 | cnt--; | |
47 | if (oldval != cnt) { | |
48 | printf("Count wrong on POBox machine %s; is %d in db, counted %d\n", | |
49 | ((struct machine *) hash_lookup(machines, id))->name, | |
50 | oldval, cnt); | |
51 | if (single_fix("Update", 1)) { | |
52 | EXEC SQL UPDATE serverhosts SET value1 = :cnt | |
53 | WHERE service='POP' AND mach_id = :id; | |
54 | EXEC SQL INQUIRE_SQL(:rowcount = rowcount); | |
55 | if (rowcount > 0) | |
56 | printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); | |
57 | else | |
58 | printf("Not fixed\n"); | |
59 | modified("serverhosts"); | |
60 | } | |
61 | } | |
62 | } | |
63 | ||
64 | ||
65 | check_nfs_counts(id, n, hint) | |
66 | EXEC SQL BEGIN DECLARE SECTION; | |
67 | int id, hint; | |
68 | EXEC SQL END DECLARE SECTION; | |
69 | struct nfsphys *n; | |
70 | { | |
71 | EXEC SQL BEGIN DECLARE SECTION; | |
72 | int val, rowcount; | |
73 | EXEC SQL END DECLARE SECTION; | |
74 | ||
75 | val = n->count; | |
76 | if (n->allocated != val) { | |
77 | printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n", | |
78 | ((struct machine *) hash_lookup(machines, n->mach_id))->name, | |
79 | n->dir, n->allocated, val); | |
80 | if (single_fix("Update", 1)) { | |
81 | EXEC SQL UPDATE nfsphys SET allocated = :val | |
82 | WHERE nfsphys_id = :id; | |
83 | EXEC SQL INQUIRE_SQL(:rowcount = rowcount); | |
84 | if (rowcount > 0) | |
85 | printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); | |
86 | else | |
87 | printf("Not fixed\n"); | |
88 | modified("nfsphys"); | |
89 | } | |
90 | } | |
91 | } | |
92 | ||
93 | ||
94 | phase4() | |
95 | { | |
96 | struct hash *boxes, *counts; | |
97 | EXEC SQL BEGIN DECLARE SECTION; | |
98 | int id, cnt; | |
99 | EXEC SQL END DECLARE SECTION; | |
100 | ||
101 | printf("Phase 4 - Checking counts\n"); | |
102 | ||
103 | dprintf("Doing POBoxes...\n"); | |
104 | boxes = create_hash(10); | |
105 | counts = create_hash(10); | |
106 | EXEC SQL DECLARE csr401 CURSOR FOR | |
107 | SELECT mach_id, value1 FROM serverhosts | |
108 | WHERE service='POP'; | |
109 | if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); | |
110 | EXEC SQL OPEN csr401; | |
111 | while(1) { | |
112 | EXEC SQL FETCH csr401 INTO :id, :cnt; | |
113 | if (sqlca.sqlcode != 0) { | |
114 | ingerr(&sqlca.sqlcode); | |
115 | break; | |
116 | } | |
117 | ||
118 | hash_store(boxes, id, 1); | |
119 | hash_store(counts, id, cnt); | |
120 | } | |
121 | EXEC SQL CLOSE csr401; | |
122 | hash_step(users, count_boxes, boxes); | |
123 | hash_step(boxes, check_box_counts, counts); | |
124 | ||
125 | dprintf("Doing NFSphys...\n"); | |
126 | hash_step(nfsphys, check_nfs_counts, 0); | |
127 | } | |
128 | ||
129 | ||
130 | count_only_setup() | |
131 | { | |
132 | EXEC SQL BEGIN DECLARE SECTION; | |
133 | int id, status, id2, id3; | |
134 | char name[33], last[17], first[17], buf[257]; | |
135 | EXEC SQL END DECLARE SECTION; | |
136 | struct save_queue *sq; | |
137 | struct user *u; | |
138 | struct nfsphys *n; | |
139 | struct machine *m; | |
140 | ||
141 | dprintf("Loading users...\n"); | |
142 | users = create_hash(10000); | |
143 | EXEC SQL DECLARE csr402 CURSOR FOR | |
144 | SELECT users_id, login, last, first, status, | |
145 | potype, pop_id, box_id FROM users | |
146 | WHERE potype='POP'; | |
147 | if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); | |
148 | EXEC SQL OPEN csr402; | |
149 | while(1) { | |
150 | EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, | |
151 | :buf, :id2, :id3; | |
152 | if (sqlca.sqlcode != 0) { | |
153 | ingerr(&sqlca.sqlcode); | |
154 | break; | |
155 | } | |
156 | ||
157 | u = (struct user *) malloc(sizeof(struct user)); | |
158 | if (u == NULL) | |
159 | out_of_mem("storing users"); | |
160 | strcpy(u->login, strtrim(name)); | |
161 | u->potype = buf[0]; | |
162 | sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); | |
163 | u->fullname = strsave(buf); | |
164 | u->status = status; | |
165 | u->users_id = id; | |
166 | switch (u->potype) { | |
167 | case 'P': | |
168 | u->pobox_id = id2; | |
169 | break; | |
170 | case 'S': | |
171 | u->pobox_id = id3; | |
172 | break; | |
173 | default: | |
174 | u->pobox_id = 0; | |
175 | } | |
176 | hash_store(users, id, u); | |
177 | } | |
178 | EXEC SQL CLOSE csr402; | |
179 | ||
180 | dprintf("Loading machines...\n"); | |
181 | machines = create_hash(1000); | |
182 | EXEC SQL DECLARE csr403 CURSOR FOR | |
183 | SELECT mach_id, name FROM machine; | |
184 | if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); | |
185 | EXEC SQL OPEN csr403; | |
186 | while(1) { | |
187 | EXEC SQL FETCH csr403 INTO :id, :name; | |
188 | if (sqlca.sqlcode != 0) { | |
189 | ingerr(&sqlca.sqlcode); | |
190 | break; | |
191 | } | |
192 | ||
193 | m = (struct machine *) malloc(sizeof(struct machine)); | |
194 | if (m == NULL) | |
195 | out_of_mem("storing machines"); | |
196 | strcpy(m->name, strtrim(name)); | |
197 | m->mach_id = id; | |
198 | hash_store(machines, id, m); | |
199 | } | |
200 | EXEC SQL CLOSE csr403; | |
201 | ||
202 | dprintf("Loading nfsphys...\n"); | |
203 | nfsphys = create_hash(500); | |
204 | EXEC SQL DECLARE csr404 CURSOR FOR | |
205 | SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys; | |
206 | if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); | |
207 | EXEC SQL OPEN csr404; | |
208 | while(1) { | |
209 | EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3; | |
210 | if (sqlca.sqlcode != 0) { | |
211 | ingerr(&sqlca.sqlcode); | |
212 | break; | |
213 | } | |
214 | ||
215 | n = (struct nfsphys *) malloc(sizeof(struct nfsphys)); | |
216 | if (n == NULL) | |
217 | out_of_mem("storing nfsphys"); | |
218 | strcpy(n->dir, strtrim(name)); | |
219 | n->mach_id = id2; | |
220 | n->nfsphys_id = id; | |
221 | n->allocated = id3; | |
222 | n->count = 0; | |
223 | hash_store(nfsphys, id, n); | |
224 | } | |
225 | EXEC SQL CLOSE csr404; | |
226 | ||
227 | dprintf("Counting quotas...\n"); | |
228 | EXEC SQL DECLARE csr405 CURSOR FOR | |
229 | SELECT phys_id, quota FROM quota; | |
230 | if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); | |
231 | EXEC SQL OPEN csr405; | |
232 | while(1) { | |
233 | EXEC SQL FETCH csr405 INTO :id, :id2; | |
234 | if (sqlca.sqlcode != 0) { | |
235 | ingerr(&sqlca.sqlcode); | |
236 | break; | |
237 | } | |
238 | ||
239 | if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) { | |
240 | n->count += id2; | |
241 | } | |
242 | } | |
243 | EXEC SQL CLOSE csr405; | |
244 | } |