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