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