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