2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afsconfig.h>
15 #include <afs/param.h>
20 #include <sys/types.h>
25 #include <sys/param.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
34 #include <afs/bubasics.h>
36 #include <afs/com_err.h>
37 #include <lock.h> /* for checking TC_ABORTFAILED. PA */
38 #include <afs/tcdata.h> /* for checking TC_ABORTFAILED. PA */
42 #include "error_macros.h"
44 struct bc_dumpTask bc_dumpTasks[BC_MAXSIMDUMPS];
46 extern struct bc_config *bc_globalConfig;
47 extern char *bc_CopyString();
48 extern void bc_HandleMisc();
50 extern char *tailCompPtr();
51 extern statusP createStatusNode();
52 extern afs_int32 bc_jobNumber();
54 extern afs_int32 lastTaskCode;
57 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.S_un.S_addr
59 #define HOSTADDR(sockaddr) (sockaddr)->sin_addr.s_addr
63 * called (indirectly) to make a dump
65 * aindex - index into dumpTask array, contains all the information
66 * relevant to the dump
70 struct rx_connection *tconn;
71 register struct bc_volumeDump *tde;
72 afs_int32 count, port;
73 struct tc_dumpDesc *volDesc = 0;
74 struct tc_dumpArray volArray;
78 struct tc_dumpInterface dumpInterface;
79 struct tc_dumpInterface *tcdiPtr = &dumpInterface;
80 register struct bc_dumpTask *dumpTaskPtr;
82 register afs_int32 code = 0;
84 dumpTaskPtr = &bc_dumpTasks[aindex];
86 if (!dumpTaskPtr->portOffset || (dumpTaskPtr->portCount == 0))
89 port = dumpTaskPtr->portOffset[0];
91 code = ConnectButc(dumpTaskPtr->config, port, &tconn);
95 /* count number of volumes to be dumped and
96 * build array of volumes to be sent to backup system
98 for (count = 0, tde = dumpTaskPtr->volumes; tde;
99 tde = tde->next, count++);
101 (struct tc_dumpDesc *)malloc(count * sizeof(struct tc_dumpDesc));
103 com_err(whoami, BC_NOMEM, "");
107 for (count = 0, tde = dumpTaskPtr->volumes; tde; tde = tde->next, count++) {
108 strcpy(volDesc[count].name, tde->name);
109 volDesc[count].vid = tde->vid;
110 volDesc[count].vtype = tde->volType;
111 volDesc[count].partition = tde->partition;
112 volDesc[count].hostAddr = HOSTADDR(&tde->server); /* the internet address */
113 volDesc[count].date = tde->date;
114 volDesc[count].cloneDate = tde->cloneDate; /* Not yet known */
117 volArray.tc_dumpArray_len = count; /* element count */
118 volArray.tc_dumpArray_val = volDesc; /* and data */
120 baseNamePtr = tailCompPtr(dumpTaskPtr->dumpName);
122 /* setup the interface structure */
123 memset(tcdiPtr, 0, sizeof(*tcdiPtr));
126 strcpy(tcdiPtr->dumpPath, dumpTaskPtr->dumpName);
127 strcpy(tcdiPtr->volumeSetName, dumpTaskPtr->volSetName);
130 strcpy(tcdiPtr->tapeSet.format, dumpTaskPtr->volSetName);
131 strcat(tcdiPtr->tapeSet.format, ".");
132 strcat(tcdiPtr->tapeSet.format, baseNamePtr);
133 strcat(tcdiPtr->tapeSet.format, ".%d");
134 tcdiPtr->tapeSet.a = 1;
135 tcdiPtr->tapeSet.b = 1;
136 tcdiPtr->tapeSet.maxTapes = 1000000000;
137 tcdiPtr->tapeSet.expDate = dumpTaskPtr->expDate; /* PA */
138 tcdiPtr->tapeSet.expType = dumpTaskPtr->expType;
140 /* construct dump set name */
141 strcpy(tcdiPtr->dumpName, dumpTaskPtr->volSetName);
142 strcat(tcdiPtr->dumpName, ".");
143 strcat(tcdiPtr->dumpName, baseNamePtr);
145 tcdiPtr->parentDumpId = dumpTaskPtr->parentDumpID;
146 tcdiPtr->dumpLevel = dumpTaskPtr->dumpLevel;
147 tcdiPtr->doAppend = dumpTaskPtr->doAppend;
149 /* start the dump on the tape coordinator */
150 printf("Starting dump\n");
151 code = TC_PerformDump(tconn, tcdiPtr, &volArray, &dumpTaskPtr->dumpID);
153 com_err(whoami, code, "; Failed to start dump");
157 com_err(whoami, 0, "Task %u: Dump (%s)", dumpTaskPtr->dumpID,
160 /* create status monitor block */
161 statusPtr = createStatusNode();
163 statusPtr->taskId = dumpTaskPtr->dumpID;
164 statusPtr->port = port;
165 statusPtr->jobNumber = bc_jobNumber();
166 statusPtr->volsTotal = volArray.tc_dumpArray_len;
167 statusPtr->flags &= ~STARTING;
168 sprintf(statusPtr->taskName, "Dump (%s.%s)", dumpTaskPtr->volSetName,
173 /* locally allocated resources */
178 rx_DestroyConnection(tconn);
183 /* freeDumpTaskVolumeList
184 * free the list of volumes used for dumps
187 freeDumpTaskVolumeList(vdptr)
188 struct bc_volumeDump *vdptr;
190 struct bc_volumeDump *nextVdPtr;
193 nextVdPtr = vdptr->next;
204 * The other half of the dump/restore create process call. In bc_StartDmpRst,
205 * we allocated a dumpTask entry. Here we do the task and then free the entry.
207 bc_DmpRstStart(aindex)
210 register struct bc_dumpTask *tdump;
211 register afs_int32 code;
213 tdump = &bc_dumpTasks[aindex];
215 code = (tdump->callProc) (aindex);
219 /* Cleanup allocated data structures */
220 freeDumpTaskVolumeList(tdump->volumes);
223 free(tdump->dumpName);
226 if (tdump->volSetName)
227 free(tdump->volSetName);
228 if (tdump->portOffset)
229 free(tdump->portOffset);
230 tdump->flags &= ~BC_DI_INUSE;
236 * function to start dump running. Packages the relevant information
237 * (from params) into any free dumpTask structure (globally allocated),
238 * and then invokes bc_DmpRstStart to do the work, passing it a single
239 * parameter, the index into the dumpTask array.
242 * aconfig - normally is bc_globalConfig
243 * aproc - bc_Dumper for doing dumps
244 * bc_Restorer for doing restores
247 bc_StartDmpRst(aconfig, adname, avname, avolsToDump, adestServer,
248 adestPartition, afromDate, anewExt, aoldFlag, aparent, alevel,
249 aproc, ports, portCount, dsptr, append, dontExecute)
250 struct bc_config *aconfig;
253 struct bc_volumeDump *avolsToDump;
254 struct sockaddr_in *adestServer;
255 afs_int32 adestPartition;
259 afs_int32 aparent, alevel;
263 struct bc_dumpSchedule *dsptr;
264 int append, dontExecute;
267 register afs_int32 code;
270 for (i = 0; i < BC_MAXSIMDUMPS; i++)
271 if (!(bc_dumpTasks[i].flags & BC_DI_INUSE))
274 if (i >= BC_MAXSIMDUMPS) {
275 com_err(whoami, BC_NOTLOCKED,
276 "All of the dump/restore slots are in use, try again later");
277 return (BC_NOTLOCKED);
280 memset(&bc_dumpTasks[i], 0, sizeof(struct bc_dumpTask));
281 bc_dumpTasks[i].callProc = aproc;
282 bc_dumpTasks[i].config = aconfig;
283 bc_dumpTasks[i].volumes = avolsToDump;
284 bc_dumpTasks[i].flags = BC_DI_INUSE;
285 bc_dumpTasks[i].dumpName = bc_CopyString(adname);
286 bc_dumpTasks[i].volSetName = bc_CopyString(avname);
287 bc_dumpTasks[i].newExt = bc_CopyString(anewExt);
288 bc_dumpTasks[i].dumpLevel = alevel;
289 bc_dumpTasks[i].parentDumpID = aparent;
290 bc_dumpTasks[i].oldFlag = aoldFlag;
291 bc_dumpTasks[i].fromDate = afromDate;
292 bc_dumpTasks[i].destPartition = adestPartition;
293 bc_dumpTasks[i].portOffset = ports;
294 bc_dumpTasks[i].portCount = portCount;
295 bc_dumpTasks[i].doAppend = append;
296 bc_dumpTasks[i].dontExecute = dontExecute;
299 /* This should be specified for dumps, but will be 0 for restores */
300 bc_dumpTasks[i].expDate = dsptr->expDate;
301 bc_dumpTasks[i].expType = dsptr->expType;
304 memcpy(&bc_dumpTasks[i].destServer, adestServer,
305 sizeof(struct sockaddr_in));
307 memset(&bc_dumpTasks[i].destServer, 0, sizeof(struct sockaddr_in));
310 LWP_CreateProcess(bc_DmpRstStart, 20480, LWP_NORMAL_PRIORITY,
311 (void *)i, "helper", &junk);
314 com_err(whoami, code, "; Can't start thread");
316 /* Cleanup allocated data structures */
317 freeDumpTaskVolumeList(bc_dumpTasks[i].volumes);
318 bc_dumpTasks[i].dumpID = 0;
319 if (bc_dumpTasks[i].dumpName)
320 free(bc_dumpTasks[i].dumpName);
321 if (bc_dumpTasks[i].newExt)
322 free(bc_dumpTasks[i].newExt);
323 if (bc_dumpTasks[i].volSetName)
324 free(bc_dumpTasks[i].volSetName);
325 if (bc_dumpTasks[i].portOffset)
326 free(bc_dumpTasks[i].portOffset);
327 bc_dumpTasks[i].flags &= ~BC_DI_INUSE;
336 * Returns the dump slot of the dump with dumpID
338 * dumpID - id to look for
339 * port - portoffset for tape coordinator
341 * 0-n - i.e. 0 or positive number, is the dump slot
342 * -1 - failed to find dumpID
346 bc_FindDumpSlot(dumpID, port)
352 for (i = 0; i < BC_MAXSIMDUMPS; i++) {
353 if ((bc_dumpTasks[i].flags & BC_DI_INUSE)
354 && (bc_dumpTasks[i].dumpID == dumpID)
355 && ((afs_int32) bc_dumpTasks[i].portOffset == port)) {
364 * opens a connection to the tape coordinator and requests that it
368 bc_LabelTape(afsname, pname, size, config, port)
369 char *afsname, *pname;
370 struct bc_config *config;
374 struct rx_connection *tconn;
376 struct tc_tapeLabel label;
380 code = ConnectButc(config, port, &tconn);
384 memset(&label, 0, sizeof(label));
386 strcpy(label.afsname, afsname);
388 strcpy(label.pname, (strcmp(pname, "") ? pname : "<NULL>"));
391 code = TC_LabelTape(tconn, &label, &taskId);
393 com_err(whoami, code, "; Failed to start labeltape");
397 /* create status monitor block */
398 statusPtr = createStatusNode();
400 statusPtr->taskId = taskId;
401 statusPtr->port = port;
402 statusPtr->jobNumber = bc_jobNumber();
403 /* statusPtr->flags |= SILENT; *//* don't report termination */
404 statusPtr->flags &= ~STARTING; /* ok to examine */
406 sprintf(statusPtr->taskName, "Labeltape (%s)",
407 (pname ? pname : (afsname ? afsname : "<NULL>")));
414 * open a connection to the tape coordinator and read the label on
418 bc_ReadLabel(config, port)
419 struct bc_config *config;
422 struct rx_connection *tconn;
423 struct tc_tapeLabel label;
428 code = ConnectButc(config, port, &tconn);
432 memset(&label, 0, sizeof(label));
433 code = TC_ReadLabel(tconn, &label, &taskId);
435 if (code == BUTM_NOLABEL) {
436 printf("Tape read was unlabelled\n");
439 com_err(whoami, code, "; Failed to start readlabel");
443 if (strcmp(label.pname, ""))
445 else if (strcmp(label.afsname, ""))
446 tname = label.afsname;
449 printf("Tape read was labelled : <NULL> size : %u\n", label.size);
450 } else if (!label.tapeId) {
451 printf("Tape read was labelled : %s size : %lu Kbytes\n", tname,
454 printf("Tape read was labelled : %s (%lu) size : %lu Kbytes\n", tname,
455 label.tapeId, label.size);
461 bc_ScanDumps(config, dbAddFlag, port)
462 struct bc_config *config;
466 struct rx_connection *tconn;
471 code = ConnectButc(config, port, &tconn);
475 code = TC_ScanDumps(tconn, dbAddFlag, &taskId);
477 com_err(whoami, code, "; Failed to start scantape");
481 /* create status monitor block */
482 statusPtr = createStatusNode();
484 statusPtr->taskId = taskId;
485 statusPtr->port = port;
486 statusPtr->jobNumber = bc_jobNumber();
487 statusPtr->flags &= ~STARTING; /* ok to examine */
488 sprintf(statusPtr->taskName, "Scantape");
498 /* get a connection to the tape controller */
500 bc_GetConn(aconfig, aport, tconn)
501 struct bc_config *aconfig;
503 struct rx_connection **tconn;
508 static struct rx_securityClass *rxsc;
509 struct bc_hostEntry *te;
511 *tconn = (struct rx_connection *)0;
513 /* use non-secure connections to butc */
515 rxsc = rxnull_NewClientSecurityObject();
516 if (!rxsc || !aconfig)
519 for (te = aconfig->tapeHosts; te; te = te->next) {
520 if (te->portOffset == aport) {
521 /* found the right port */
522 host = te->addr.sin_addr.s_addr;
524 return (BC_NOHOSTENTRY); /* gethostbyname in bc_ParseHosts failed */
526 port = htons(BC_TAPEPORT + aport);
528 /* servers is 1; sec index is 0 */
529 *tconn = rx_NewConnection(host, port, 1, rxsc, 0);
530 return ((*tconn ? 0 : -1));
533 return (BC_NOHOSTENTRY);
537 * make sure we are talking to a compatible butc process.
540 * -1 - not compatible
543 CheckTCVersion(tconn)
544 struct rx_connection *tconn;
546 struct tc_tcInfo tci;
549 code = TC_TCInfo(tconn, &tci);
553 if (tci.tcVersion != CUR_BUTC_VERSION)
554 return (BC_VERSIONFAIL);
559 ConnectButc(config, port, tconn)
560 struct bc_config *config;
562 struct rx_connection **tconn;
566 code = bc_GetConn(config, port, tconn);
568 com_err(whoami, code,
569 "; Can't connect to tape coordinator at port %d", port);
573 code = CheckTCVersion(*tconn);
575 rx_DestroyConnection(*tconn);
577 if (code == BC_VERSIONFAIL)
578 com_err(whoami, code,
579 "; Backup and butc are not the same version");
581 com_err(whoami, code,
582 "; Can't access tape coordinator at port %d", port);