Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | #include <afsconfig.h> | |
10 | #include <afs/param.h> | |
11 | ||
12 | #include <roken.h> | |
13 | ||
14 | #include <afs/budb_client.h> | |
15 | #include <afs/budb.h> | |
16 | #include <rx/rx_globals.h> | |
17 | ||
18 | extern struct udbHandleS udbHandle; | |
19 | ||
20 | #define ERROR(code) {err = code; printf(" - Got error %d.\n", err); goto error;} | |
21 | ||
22 | int | |
23 | connect_buserver() | |
24 | { | |
25 | int code, err = 0; | |
26 | char cellName[64]; | |
27 | struct ubik_client *cstruct; | |
28 | int version; | |
29 | ||
30 | /* | |
31 | * Setup RX connection and establish connection with the buserver | |
32 | */ | |
33 | code = rx_Init(htons(0)); | |
34 | if (code) { | |
35 | printf("Error in rx_Init call\n"); | |
36 | ERROR(code); | |
37 | } | |
38 | ||
39 | rx_SetRxDeadTime(60); | |
40 | ||
41 | /* | |
42 | * Connect to buserver | |
43 | */ | |
44 | cellName[0] = '\0'; | |
45 | code = udbClientInit(0, 0, cellName); | |
46 | if (code) { | |
47 | printf("Error in udbClientInit call\n"); | |
48 | ERROR(code); | |
49 | } | |
50 | ||
51 | /* Get the versin */ | |
52 | code = ubik_BUDB_T_GetVersion(udbHandle.uh_client, 0, &version); | |
53 | if (code) { | |
54 | printf("Error in ubik_Call to BUDB_T_GetVersion\n"); | |
55 | ERROR(code); | |
56 | } | |
57 | printf("BUDB Server Version = %d\n", version); | |
58 | ||
59 | error: | |
60 | return err; | |
61 | } | |
62 | ||
63 | int | |
64 | verifyDb() | |
65 | { | |
66 | int code, err = 0; | |
67 | afs_int32 status, orphans, host; | |
68 | ||
69 | code = | |
70 | ubik_BUDB_DbVerify(udbHandle.uh_client, 0, &status, &orphans, | |
71 | &host); | |
72 | if (code) { | |
73 | printf("Error in ubik_Call to BUDB_DbVerify\n"); | |
74 | ERROR(code); | |
75 | } | |
76 | ||
77 | if (!status) | |
78 | printf("DATABASE OK "); | |
79 | else | |
80 | printf("DATABASE NOT OK "); | |
81 | printf("- orphans %d; host %d.%d.%d.%d\n", orphans, | |
82 | ((host & 0xFF000000) >> 24), ((host & 0xFF0000) >> 16), | |
83 | ((host & 0xFF00) >> 8), (host & 0xFF)); | |
84 | ||
85 | error: | |
86 | return err; | |
87 | } | |
88 | ||
89 | int | |
90 | deleteDump(dumpID) | |
91 | afs_int32 dumpID; | |
92 | { | |
93 | int code; | |
94 | budb_dumpsList dumps; | |
95 | ||
96 | dumps.budb_dumpsList_len = 0; | |
97 | dumps.budb_dumpsList_val = 0; | |
98 | ||
99 | code = bcdb_deleteDump(dumpID, 0, 0, &dumps); | |
100 | return code; | |
101 | } | |
102 | ||
103 | #define NPASS 50 | |
104 | #define NDUMPS 4 | |
105 | #define NTAPES 2 | |
106 | #define NVOLUMES 10 | |
107 | ||
108 | int | |
109 | main() | |
110 | { | |
111 | int code, err = 0; | |
112 | int pass = 0; | |
113 | int d, t, v; | |
114 | afs_int32 newTape; | |
115 | struct budb_dumpEntry dumpEntry[NDUMPS]; | |
116 | struct budb_tapeEntry tapeEntry[NTAPES]; | |
117 | struct budb_volumeEntry volumeEntry[NVOLUMES]; | |
118 | ||
119 | code = connect_buserver(); | |
120 | if (code) { | |
121 | printf("Error in connect_buserver call\n"); | |
122 | ERROR(code); | |
123 | } | |
124 | ||
125 | for (pass = 0; pass < NPASS; pass++) { | |
126 | printf("PASS %d\n", pass + 1); | |
127 | ||
128 | ||
129 | for (d = 0; d < NDUMPS; d++) { | |
130 | /* ************************ */ | |
131 | /* Create and finish a dump */ | |
132 | /* ************************ */ | |
133 | dumpEntry[d].id = 0; | |
134 | dumpEntry[d].parent = 0; | |
135 | dumpEntry[d].level = 0; | |
136 | dumpEntry[d].flags = 0; | |
137 | strcpy(dumpEntry[d].volumeSetName, "TestVolSetName"); | |
138 | strcpy(dumpEntry[d].dumpPath, "/TestDumpPath"); | |
139 | strcpy(dumpEntry[d].name, "TestVolSetName.TestDumpPath"); | |
140 | dumpEntry[d].created = 0; | |
141 | dumpEntry[d].incTime = 0; | |
142 | dumpEntry[d].nVolumes = 0; | |
143 | dumpEntry[d].tapes.id = 0; | |
144 | strcpy(dumpEntry[d].tapes.tapeServer, ""); | |
145 | strcpy(dumpEntry[d].tapes.format, | |
146 | "TestVolSetName.TestDumpPath.%d"); | |
147 | dumpEntry[d].tapes.maxTapes = 1; | |
148 | dumpEntry[d].tapes.a = 0; | |
149 | dumpEntry[d].tapes.b = 1; | |
150 | strcpy(dumpEntry[d].dumper.name, "admin"); | |
151 | strcpy(dumpEntry[d].dumper.instance, ""); | |
152 | strcpy(dumpEntry[d].dumper.cell, ""); | |
153 | dumpEntry[d].initialDumpID = 0; | |
154 | if (d == 1) | |
155 | dumpEntry[d].initialDumpID = dumpEntry[0].id; | |
156 | dumpEntry[d].appendedDumpID = 0; | |
157 | ||
158 | code = bcdb_CreateDump(&dumpEntry[d]); | |
159 | if (code) { | |
160 | printf("Error in bcdb_CreateDump call\n"); | |
161 | ERROR(code); | |
162 | } | |
163 | printf("\nCreated dump %s (DumpID %u)\n", dumpEntry[d].name, | |
164 | dumpEntry[d].id); | |
165 | ||
166 | for (t = 0; t < NTAPES; t++) { | |
167 | /* ************************ */ | |
168 | /* Create and finish a tape */ | |
169 | /* ************************ */ | |
170 | sprintf(tapeEntry[t].name, "TestVolSetName.TestDumpPath.%d", | |
171 | t + 1); | |
172 | tapeEntry[t].flags = 0; | |
173 | tapeEntry[t].written = 0; | |
174 | tapeEntry[t].expires = 0; /* date tape expires */ | |
175 | tapeEntry[t].nMBytes = 0; | |
176 | tapeEntry[t].nBytes = 0; | |
177 | tapeEntry[t].nFiles = 0; | |
178 | tapeEntry[t].nVolumes = 0; | |
179 | tapeEntry[t].seq = (t + 1); /* Tape in sequence */ | |
180 | tapeEntry[t].tapeid = 0; | |
181 | tapeEntry[t].useCount = 999; /* Number of time tape is used */ | |
182 | tapeEntry[t].useKBytes = 0; | |
183 | tapeEntry[t].dump = dumpEntry[d].id; | |
184 | ||
185 | bcdb_UseTape(&tapeEntry[t], &newTape); | |
186 | if (code) { | |
187 | printf("Error in bcdb_UseTape call\n"); | |
188 | ERROR(code); | |
189 | } | |
190 | printf(" Created tape %s (%u)\n", tapeEntry[t].name, | |
191 | tapeEntry[t].dump); | |
192 | ||
193 | for (v = 0; v < NVOLUMES; v++) { | |
194 | /* ************************* */ | |
195 | /* Create a volume */ | |
196 | /* ************************* */ | |
197 | sprintf(volumeEntry[v].name, "TestVolumeName.%d", | |
198 | (t * NVOLUMES) + (v + 1)); | |
199 | volumeEntry[v].flags = | |
200 | (BUDB_VOL_FIRSTFRAG | BUDB_VOL_LASTFRAG); | |
201 | volumeEntry[v].id = 1234567890; /* volume id */ | |
202 | strcpy(volumeEntry[v].server, ""); | |
203 | volumeEntry[v].partition = 0; | |
204 | volumeEntry[v].tapeSeq = 0; | |
205 | volumeEntry[v].position = v + 2; /* positin on tape */ | |
206 | volumeEntry[v].clone = 0; /* clone date */ | |
207 | volumeEntry[v].incTime = 0; | |
208 | volumeEntry[v].startByte = 0; | |
209 | volumeEntry[v].nBytes = (v + 1) * 100000; /* vary size of volume */ | |
210 | volumeEntry[v].seq = 1; /* The first fragment */ | |
211 | volumeEntry[v].dump = dumpEntry[d].id; /* the dump id */ | |
212 | strcpy(volumeEntry[v].tape, tapeEntry[t].name); /* the tape name */ | |
213 | ||
214 | code = bcdb_AddVolume(&volumeEntry[v]); | |
215 | if (code) { | |
216 | printf("Error in bcdb_AddVolume call\n"); | |
217 | ERROR(code); | |
218 | } | |
219 | printf(" Added volume %s\n", volumeEntry[v].name); | |
220 | } | |
221 | ||
222 | tapeEntry[t].nFiles = 77777; | |
223 | tapeEntry[t].useKBytes = 88888; | |
224 | code = bcdb_FinishTape(&tapeEntry[t]); | |
225 | if (code) { | |
226 | printf("Error in bcdb_FinishTape call\n"); | |
227 | ERROR(code); | |
228 | } | |
229 | printf(" Finished tape %s (%u)\n", tapeEntry[t].name, | |
230 | tapeEntry[t].dump); | |
231 | } | |
232 | ||
233 | code = bcdb_FinishDump(&dumpEntry[d]); | |
234 | if (code) { | |
235 | printf("Error in bcdb_FinishDump call\n"); | |
236 | ERROR(code); | |
237 | } | |
238 | printf("Finished dump %s (DumpID %u)\n", dumpEntry[d].name, | |
239 | dumpEntry[d].id); | |
240 | ||
241 | code = verifyDb(); | |
242 | if (code) { | |
243 | printf("Error in verifyDb call\n"); | |
244 | ERROR(code); | |
245 | } | |
246 | } | |
247 | ||
248 | /* ********************************************** */ | |
249 | /* Delete one of the dumps - only if not appended */ | |
250 | /* ********************************************** */ | |
251 | if (!dumpEntry[(pass % NDUMPS)].initialDumpID) { | |
252 | code = deleteDump(dumpEntry[(pass % NDUMPS)].id); | |
253 | if (code) { | |
254 | printf("Error in deleteDump call\n"); | |
255 | ERROR(code); | |
256 | } | |
257 | printf("Deleted DumpID %u\n", dumpEntry[(pass % NDUMPS)].id); | |
258 | } | |
259 | ||
260 | code = verifyDb(); | |
261 | if (code) { | |
262 | printf("Error in verifyDb call\n"); | |
263 | ERROR(code); | |
264 | } | |
265 | } | |
266 | ||
267 | error: | |
268 | return err; | |
269 | } |