]> andersk Git - moira.git/blame - dbck/phase4.dc
better logging
[moira.git] / dbck / phase4.dc
CommitLineData
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 11EXEC SQL INCLUDE sqlca;
68bbc9c3 12
13static char phase4_qc_rcsid[] = "$Header$";
14
15
16count_boxes(id, u, boxes)
17int id;
18struct user *u;
19struct 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
208a4f4a 35check_box_counts(id, cnt, counts)
36EXEC SQL BEGIN DECLARE SECTION;
37int id, cnt;
38EXEC SQL END DECLARE SECTION;
68bbc9c3 39struct hash *counts;
208a4f4a 40{
41 EXEC SQL BEGIN DECLARE SECTION;
42 int oldval, rowcount;
43 EXEC SQL END DECLARE SECTION;
68bbc9c3 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)) {
208a4f4a 52 EXEC SQL UPDATE serverhosts SET value1 = :cnt
53 WHERE service='POP' AND mach_id = :id;
54 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
68bbc9c3 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 }
208a4f4a 62}
68bbc9c3 63
64
208a4f4a 65check_nfs_counts(id, n, hint)
66EXEC SQL BEGIN DECLARE SECTION;
67int id, hint;
68EXEC SQL END DECLARE SECTION;
68bbc9c3 69struct nfsphys *n;
208a4f4a 70{
71 EXEC SQL BEGIN DECLARE SECTION;
72 int val, rowcount;
73 EXEC SQL END DECLARE SECTION;
68bbc9c3 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)) {
208a4f4a 81 EXEC SQL UPDATE nfsphys SET allocated = :val
82 WHERE nfsphys_id = :id;
83 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
68bbc9c3 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 }
208a4f4a 91}
68bbc9c3 92
93
94phase4()
208a4f4a 95{
68bbc9c3 96 struct hash *boxes, *counts;
208a4f4a 97 EXEC SQL BEGIN DECLARE SECTION;
98 int id, cnt;
99 EXEC SQL END DECLARE SECTION;
68bbc9c3 100
101 printf("Phase 4 - Checking counts\n");
102
103 dprintf("Doing POBoxes...\n");
104 boxes = create_hash(10);
105 counts = create_hash(10);
208a4f4a 106 EXEC SQL DECLARE csr401 CURSOR FOR
107 SELECT mach_id, value1 FROM serverhosts
108 WHERE service='POP';
ced12e61 109 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 110 EXEC SQL OPEN csr401;
111 while(1) {
112 EXEC SQL FETCH csr401 INTO :id, :cnt;
7bf0a6f3 113 if (sqlca.sqlcode != 0) {
114 ingerr(&sqlca.sqlcode);
115 break;
116 }
208a4f4a 117
118 hash_store(boxes, id, 1);
119 hash_store(counts, id, cnt);
120 }
121 EXEC SQL CLOSE csr401;
68bbc9c3 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);
208a4f4a 127}
68bbc9c3 128
129
130count_only_setup()
208a4f4a 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;
68bbc9c3 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);
208a4f4a 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';
ced12e61 147 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 148 EXEC SQL OPEN csr402;
149 while(1) {
150 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
151 :buf, :id2, :id3;
7bf0a6f3 152 if (sqlca.sqlcode != 0) {
153 ingerr(&sqlca.sqlcode);
154 break;
155 }
208a4f4a 156
68bbc9c3 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);
208a4f4a 177 }
178 EXEC SQL CLOSE csr402;
68bbc9c3 179
180 dprintf("Loading machines...\n");
181 machines = create_hash(1000);
208a4f4a 182 EXEC SQL DECLARE csr403 CURSOR FOR
183 SELECT mach_id, name FROM machine;
ced12e61 184 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 185 EXEC SQL OPEN csr403;
186 while(1) {
187 EXEC SQL FETCH csr403 INTO :id, :name;
7bf0a6f3 188 if (sqlca.sqlcode != 0) {
189 ingerr(&sqlca.sqlcode);
190 break;
191 }
208a4f4a 192
68bbc9c3 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);
208a4f4a 199 }
200 EXEC SQL CLOSE csr403;
68bbc9c3 201
202 dprintf("Loading nfsphys...\n");
203 nfsphys = create_hash(500);
208a4f4a 204 EXEC SQL DECLARE csr404 CURSOR FOR
205 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
ced12e61 206 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 207 EXEC SQL OPEN csr404;
208 while(1) {
209 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
7bf0a6f3 210 if (sqlca.sqlcode != 0) {
211 ingerr(&sqlca.sqlcode);
212 break;
213 }
208a4f4a 214
68bbc9c3 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);
208a4f4a 224 }
225 EXEC SQL CLOSE csr404;
68bbc9c3 226
227 dprintf("Counting quotas...\n");
208a4f4a 228 EXEC SQL DECLARE csr405 CURSOR FOR
229 SELECT phys_id, quota FROM quota;
ced12e61 230 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 231 EXEC SQL OPEN csr405;
232 while(1) {
233 EXEC SQL FETCH csr405 INTO :id, :id2;
7bf0a6f3 234 if (sqlca.sqlcode != 0) {
235 ingerr(&sqlca.sqlcode);
236 break;
237 }
208a4f4a 238
68bbc9c3 239 if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) {
240 n->count += id2;
241 }
208a4f4a 242 }
243 EXEC SQL CLOSE csr405;
244}
This page took 0.082619 seconds and 5 git commands to generate.