]> andersk Git - moira.git/blame - dbck/phase4.dc
always check error status of every query
[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';
109 EXEC SQL OPEN csr401;
110 while(1) {
111 EXEC SQL FETCH csr401 INTO :id, :cnt;
7bf0a6f3 112 if (sqlca.sqlcode != 0) {
113 ingerr(&sqlca.sqlcode);
114 break;
115 }
208a4f4a 116
117 hash_store(boxes, id, 1);
118 hash_store(counts, id, cnt);
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
129count_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");
141 users = create_hash(10000);
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;
7bf0a6f3 150 if (sqlca.sqlcode != 0) {
151 ingerr(&sqlca.sqlcode);
152 break;
153 }
208a4f4a 154
68bbc9c3 155 u = (struct user *) malloc(sizeof(struct user));
156 if (u == NULL)
157 out_of_mem("storing users");
158 strcpy(u->login, strtrim(name));
159 u->potype = buf[0];
160 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
161 u->fullname = strsave(buf);
162 u->status = status;
163 u->users_id = id;
164 switch (u->potype) {
165 case 'P':
166 u->pobox_id = id2;
167 break;
168 case 'S':
169 u->pobox_id = id3;
170 break;
171 default:
172 u->pobox_id = 0;
173 }
174 hash_store(users, id, u);
208a4f4a 175 }
176 EXEC SQL CLOSE csr402;
68bbc9c3 177
178 dprintf("Loading machines...\n");
179 machines = create_hash(1000);
208a4f4a 180 EXEC SQL DECLARE csr403 CURSOR FOR
181 SELECT mach_id, name FROM machine;
182 EXEC SQL OPEN csr403;
183 while(1) {
184 EXEC SQL FETCH csr403 INTO :id, :name;
7bf0a6f3 185 if (sqlca.sqlcode != 0) {
186 ingerr(&sqlca.sqlcode);
187 break;
188 }
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;
195 hash_store(machines, id, m);
208a4f4a 196 }
197 EXEC SQL CLOSE csr403;
68bbc9c3 198
199 dprintf("Loading nfsphys...\n");
200 nfsphys = create_hash(500);
208a4f4a 201 EXEC SQL DECLARE csr404 CURSOR FOR
202 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
203 EXEC SQL OPEN csr404;
204 while(1) {
205 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
7bf0a6f3 206 if (sqlca.sqlcode != 0) {
207 ingerr(&sqlca.sqlcode);
208 break;
209 }
208a4f4a 210
68bbc9c3 211 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
212 if (n == NULL)
213 out_of_mem("storing nfsphys");
214 strcpy(n->dir, strtrim(name));
215 n->mach_id = id2;
216 n->nfsphys_id = id;
217 n->allocated = id3;
218 n->count = 0;
219 hash_store(nfsphys, id, n);
208a4f4a 220 }
221 EXEC SQL CLOSE csr404;
68bbc9c3 222
223 dprintf("Counting quotas...\n");
208a4f4a 224 EXEC SQL DECLARE csr405 CURSOR FOR
225 SELECT phys_id, quota FROM quota;
226 EXEC SQL OPEN csr405;
227 while(1) {
228 EXEC SQL FETCH csr405 INTO :id, :id2;
7bf0a6f3 229 if (sqlca.sqlcode != 0) {
230 ingerr(&sqlca.sqlcode);
231 break;
232 }
208a4f4a 233
68bbc9c3 234 if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) {
235 n->count += id2;
236 }
208a4f4a 237 }
238 EXEC SQL CLOSE csr405;
239}
This page took 0.277701 seconds and 5 git commands to generate.