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