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 | #ifdef AFS_AIX_ENV | |
15 | #include <sys/statfs.h> | |
16 | #endif | |
17 | ||
18 | #include <lock.h> | |
19 | #include <rx/xdr.h> | |
20 | #include <rx/rx.h> | |
21 | #include <rx/rx_globals.h> | |
22 | #include <afs/nfs.h> | |
23 | #include <afs/vlserver.h> | |
24 | #include <afs/cellconfig.h> | |
25 | #include <afs/keys.h> | |
26 | #include <ubik.h> | |
27 | #include <afs/afsint.h> | |
28 | #include <afs/cmd.h> | |
29 | #include <rx/rxkad.h> | |
30 | #include <afs/tcdata.h> | |
31 | ||
32 | #define SERVERNAME "server1" | |
33 | ||
34 | afs_int32 code = 0; | |
35 | struct tc_tapeSet ttapeSet; | |
36 | char tdumpSetName[TC_MAXNAMELEN]; | |
37 | tc_dumpArray tdumps; /*defined by rxgen */ | |
38 | tc_restoreArray trestores; /*defined by rxgen */ | |
39 | afs_int32 tdumpID; | |
40 | struct tc_dumpStat tstatus; | |
41 | int rxInitDone = 0; | |
42 | ||
43 | struct rx_connection * | |
44 | UV_Bind(aserver, port) | |
45 | afs_uint32 aserver; | |
46 | afs_int32 port; | |
47 | { | |
48 | struct rx_connection *tc; | |
49 | struct rx_securityClass *uvclass; | |
50 | ||
51 | uvclass = rxnull_NewClientSecurityObject(); | |
52 | tc = rx_NewConnection(aserver, htons(port), TCSERVICE_ID, uvclass, 0); | |
53 | return tc; | |
54 | } | |
55 | ||
56 | ||
57 | /* return host address in network byte order */ | |
58 | afs_uint32 | |
59 | GetServer(aname) | |
60 | char *aname; | |
61 | { | |
62 | struct hostent *th; | |
63 | afs_uint32 addr; | |
64 | char b1, b2, b3, b4; | |
65 | afs_int32 code; | |
66 | ||
67 | code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4); | |
68 | if (code == 4) { | |
69 | addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; | |
70 | return htonl(addr); /* convert to network order (128 in byte 0) */ | |
71 | } | |
72 | th = gethostbyname(aname); | |
73 | if (!th) | |
74 | return 0; | |
75 | memcpy(&addr, th->h_addr, sizeof(addr)); | |
76 | return addr; | |
77 | } | |
78 | ||
79 | ||
80 | static int | |
81 | PerformDump(struct cmd_syndesc *as, void *arock) | |
82 | { | |
83 | struct rx_connection *aconn; | |
84 | afs_uint32 server; | |
85 | FILE *fopen(), *fp; | |
86 | struct tc_dumpDesc *ptr; | |
87 | int i; | |
88 | afs_int32 parentDumpID, dumpLevel; | |
89 | ||
90 | server = GetServer(SERVERNAME); | |
91 | if (!server) { | |
92 | printf("cant get server id \n"); | |
93 | exit(1); | |
94 | } | |
95 | parentDumpID = 1; | |
96 | dumpLevel = 1; | |
97 | strcpy(tdumpSetName, "Test"); | |
98 | ttapeSet.id = 1; | |
99 | ttapeSet.maxTapes = 10; | |
100 | fp = fopen("dumpScr", "r"); | |
101 | fscanf(fp, "%u %u %u\n", &tdumps.tc_dumpArray_len, &ttapeSet.a, | |
102 | &ttapeSet.b); | |
103 | strcpy(ttapeSet.format, "tapeName%u"); | |
104 | strcpy(ttapeSet.tapeServer, "diskTapes"); | |
105 | tdumps.tc_dumpArray_val = | |
106 | malloc(tdumps.tc_dumpArray_len * sizeof(struct tc_dumpDesc)); | |
107 | ptr = tdumps.tc_dumpArray_val; | |
108 | for (i = 0; i < tdumps.tc_dumpArray_len; i++) { | |
109 | fscanf(fp, "%s\n", ptr->name); | |
110 | fscanf(fp, "%s\n", ptr->hostAddr); | |
111 | fscanf(fp, "%u %u %u\n", &ptr->vid, &ptr->partition, &ptr->date); | |
112 | ptr++; | |
113 | } | |
114 | ||
115 | aconn = UV_Bind(server, TCPORT); | |
116 | code = | |
117 | TC_PerformDump(aconn, tdumpSetName, &ttapeSet, &tdumps, parentDumpID, | |
118 | dumpLevel, &tdumpID); | |
119 | free(tdumps.tc_dumpArray_val); | |
120 | if (code) { | |
121 | printf("call to TC_PerformDump failed %u\n", code); | |
122 | exit(1); | |
123 | } | |
124 | printf("dumpid returned %u\n", tdumpID); | |
125 | ||
126 | return 0; | |
127 | } | |
128 | ||
129 | static int | |
130 | PerformRestore(struct cmd_syndesc *as, void *arock) | |
131 | { | |
132 | struct rx_connection *aconn; | |
133 | afs_uint32 server; | |
134 | int i; | |
135 | FILE *fopen(), *fp; | |
136 | struct tc_restoreDesc *ptr; | |
137 | ||
138 | server = GetServer(SERVERNAME); | |
139 | if (!server) { | |
140 | printf("cant get server id \n"); | |
141 | exit(1); | |
142 | } | |
143 | aconn = UV_Bind(server, TCPORT); | |
144 | strcpy(tdumpSetName, ""); | |
145 | strcpy(tdumpSetName, "Test"); | |
146 | fp = fopen("restoreScr", "r"); | |
147 | fscanf(fp, "%u\n", &trestores.tc_restoreArray_len); | |
148 | trestores.tc_restoreArray_val | |
149 | = malloc(trestores.tc_restoreArray_len * | |
150 | sizeof(struct tc_restoreDesc)); | |
151 | ptr = trestores.tc_restoreArray_val; | |
152 | for (i = 0; i < trestores.tc_restoreArray_len; i++) { | |
153 | fscanf(fp, "%s\n", ptr->oldName); | |
154 | fscanf(fp, "%s\n", ptr->newName); | |
155 | fscanf(fp, "%s\n", ptr->tapeName); | |
156 | fscanf(fp, "%s\n", ptr->hostAddr); | |
157 | fscanf(fp, "%u %u %u %u %d %u\n", &ptr->origVid, &ptr->vid, | |
158 | &ptr->partition, &ptr->flags, &ptr->frag, &ptr->position); | |
159 | ptr++; | |
160 | ||
161 | } | |
162 | code = TC_PerformRestore(aconn, tdumpSetName, &trestores, &tdumpID); | |
163 | if (code) { | |
164 | printf("call to TC_PerformRestore failed %u\n", code); | |
165 | exit(1); | |
166 | } | |
167 | printf("dumpid returned %u\n", tdumpID); | |
168 | return 0; | |
169 | } | |
170 | ||
171 | static int | |
172 | CheckDump(struct cmd_syndesc *as, void *arock) | |
173 | { | |
174 | struct rx_connection *aconn; | |
175 | afs_uint32 server; | |
176 | server = GetServer(SERVERNAME); | |
177 | if (!server) { | |
178 | printf("cant get server id \n"); | |
179 | exit(1); | |
180 | } | |
181 | tdumpID = atol(as->parms[0].items->data); | |
182 | aconn = UV_Bind(server, TCPORT); | |
183 | code = TC_CheckDump(aconn, tdumpID, &tstatus); | |
184 | if (code) { | |
185 | printf("call to TC_CheckDump failed %u\n", code); | |
186 | exit(1); | |
187 | } | |
188 | return 0; | |
189 | } | |
190 | ||
191 | static int | |
192 | AbortDump(struct cmd_syndesc *as, void *arock) | |
193 | { | |
194 | struct rx_connection *aconn; | |
195 | afs_uint32 server; | |
196 | server = GetServer(SERVERNAME); | |
197 | if (!server) { | |
198 | printf("cant get server id \n"); | |
199 | exit(1); | |
200 | } | |
201 | tdumpID = atol(as->parms[0].items->data); | |
202 | aconn = UV_Bind(server, TCPORT); | |
203 | code = TC_AbortDump(aconn, tdumpID); | |
204 | if (code) { | |
205 | printf("call to TC_AbortDump failed %u\n", code); | |
206 | exit(1); | |
207 | } | |
208 | return 0; | |
209 | } | |
210 | ||
211 | static int | |
212 | WaitForDump(struct cmd_syndesc *as, void *arock) | |
213 | { | |
214 | struct rx_connection *aconn; | |
215 | afs_uint32 server; | |
216 | server = GetServer(SERVERNAME); | |
217 | if (!server) { | |
218 | printf("cant get server id \n"); | |
219 | exit(1); | |
220 | } | |
221 | tdumpID = atol(as->parms[0].items->data); | |
222 | aconn = UV_Bind(server, TCPORT); | |
223 | code = TC_WaitForDump(aconn, tdumpID); | |
224 | if (code) { | |
225 | printf("call to TC_WaitForDump failed %u\n", code); | |
226 | exit(1); | |
227 | } | |
228 | return 0; | |
229 | } | |
230 | ||
231 | static int | |
232 | EndDump(struct cmd_syndesc *as, void *arock) | |
233 | { | |
234 | struct rx_connection *aconn; | |
235 | afs_uint32 server; | |
236 | server = GetServer(SERVERNAME); | |
237 | if (!server) { | |
238 | printf("cant get server id \n"); | |
239 | exit(1); | |
240 | } | |
241 | tdumpID = atol(as->parms[0].items->data); | |
242 | aconn = UV_Bind(server, TCPORT); | |
243 | code = TC_EndDump(aconn, tdumpID); | |
244 | if (code) { | |
245 | printf("call to TC_EndDump failed %u\n", code); | |
246 | exit(1); | |
247 | } | |
248 | return 0; | |
249 | } | |
250 | ||
251 | static int | |
252 | MyBeforeProc(struct cmd_syndesc *as, void *arock) | |
253 | { | |
254 | afs_int32 code; | |
255 | ||
256 | code = rx_Init(0); | |
257 | if (code) { | |
258 | printf("Could not initialize rx.\n"); | |
259 | return code; | |
260 | } | |
261 | rxInitDone = 1; | |
262 | rx_SetRxDeadTime(50); | |
263 | return 0; | |
264 | } | |
265 | ||
266 | #include "AFS_component_version_number.c" | |
267 | ||
268 | main(argc, argv) | |
269 | int argc; | |
270 | char **argv; | |
271 | { | |
272 | afs_int32 code; | |
273 | ||
274 | struct cmd_syndesc *ts; | |
275 | ||
276 | #ifdef AFS_AIX32_ENV | |
277 | /* | |
278 | * The following signal action for AIX is necessary so that in case of a | |
279 | * crash (i.e. core is generated) we can include the user's data section | |
280 | * in the core dump. Unfortunately, by default, only a partial core is | |
281 | * generated which, in many cases, isn't too useful. | |
282 | */ | |
283 | struct sigaction nsa; | |
284 | ||
285 | sigemptyset(&nsa.sa_mask); | |
286 | nsa.sa_handler = SIG_DFL; | |
287 | nsa.sa_flags = SA_FULLDUMP; | |
288 | sigaction(SIGABRT, &nsa, NULL); | |
289 | sigaction(SIGSEGV, &nsa, NULL); | |
290 | #endif | |
291 | cmd_SetBeforeProc(MyBeforeProc, NULL); | |
292 | ||
293 | ts = cmd_CreateSyntax("dump", PerformDump, NULL, 0, "perform a dump"); | |
294 | ||
295 | ts = cmd_CreateSyntax("restore", PerformRestore, NULL, 0, "perform a restore"); | |
296 | ||
297 | ts = cmd_CreateSyntax("check", CheckDump, NULL, 0, "check a dump"); | |
298 | cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id"); | |
299 | ||
300 | ts = cmd_CreateSyntax("abort", AbortDump, NULL, 0, "abort a dump"); | |
301 | cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id"); | |
302 | ||
303 | ts = cmd_CreateSyntax("wait", WaitForDump, NULL, 0, "wait for a dump"); | |
304 | cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id"); | |
305 | ||
306 | ts = cmd_CreateSyntax("end", EndDump, NULL, 0, "end a dump"); | |
307 | cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "dump id"); | |
308 | ||
309 | code = cmd_Dispatch(argc, argv); | |
310 | if (rxInitDone) | |
311 | rx_Finalize(); | |
312 | exit(code); | |
313 | } |