Ejemplo n.º 1
0
afs_int32
bc_UpdateHosts(void)
{
    struct udbHandleS *uhptr = &udbHandle;
    udbClientTextP ctPtr;
    afs_int32 code;
    int lock = 0;

    /* lock schedules and check validity */
    ctPtr = &bc_globalConfig->configText[TB_TAPEHOSTS];

    code = bc_CheckTextVersion(ctPtr);
    if (code != BC_VERSIONMISMATCH) {
	ERROR(code);		/* Version matches or some other error */
    }

    /* Must update the hosts */
    /* If we are not already locked, then lock it now */
    if (ctPtr->lockHandle == 0) {
	code = bc_LockText(ctPtr);
	if (code)
	    ERROR(code);
	lock = 1;
    }

    if (ctPtr->textVersion != -1) {
	afs_com_err(whoami, 0, "obsolete tapehosts - updating");
	bc_ClearHosts();
    }

    /* open a temp file to store the config text received from buserver *
     * The open file stream is stored in ctPtr->textStream */
    code =
	bc_openTextFile(ctPtr,
			&bc_globalConfig->tmpTextFileNames[TB_TAPEHOSTS][0]);
    if (code)
	ERROR(code);
    /* now get a fresh set of information from the database */
    code = bcdb_GetTextFile(ctPtr);
    if (code)
	ERROR(code);

    /* fetch the version number */
    code =
	ubik_BUDB_GetTextVersion(uhptr->uh_client, 0, ctPtr->textType,
		  &ctPtr->textVersion);
    if (code)
	ERROR(code);

    /* parse the file */
    code = bc_ParseHosts();
    if (code)
	ERROR(code);

  error_exit:
    if (lock && ctPtr->lockHandle)
	bc_UnlockText(ctPtr);
    return (code);
}
Ejemplo n.º 2
0
int
bc_CheckTextVersion(udbClientTextP ctPtr)
{
    afs_int32 code;
    afs_uint32 tversion;

    if (ctPtr->textVersion == -1)
	return (BC_VERSIONMISMATCH);

    code =
	ubik_BUDB_GetTextVersion(udbHandle.uh_client, 0,
		  ctPtr->textType, &tversion);
    if (code)
	return (code);
    if (tversion != ctPtr->textVersion)
	return (BC_VERSIONMISMATCH);
    return (0);
}
Ejemplo n.º 3
0
afs_int32
bc_UpdateDumpSchedule(void)
{
    struct bc_dumpSchedule *dumpPtr, *nextDumpPtr;
    struct udbHandleS *uhptr = &udbHandle;
    udbClientTextP ctPtr;
    afs_int32 code;
    int lock = 0;

    /* lock schedules and check validity */
    ctPtr = &bc_globalConfig->configText[TB_DUMPSCHEDULE];

    code = bc_CheckTextVersion(ctPtr);
    if (code != BC_VERSIONMISMATCH) {
	ERROR(code);		/* Version matches or some other error */
    }

    /* Must update the dump schedules */
    /* If we are not already locked, then lock it now */
    if (!ctPtr->lockHandle) {
	code = bc_LockText(ctPtr);
	if (code)
	    ERROR(code);
	lock = 1;
    }

    if (ctPtr->textVersion != -1) {
	printf("backup: obsolete dump schedule - updating\n");

	/* clear all old schedule information */
	dumpPtr = bc_globalConfig->dsched;
	while (dumpPtr) {
	    nextDumpPtr = dumpPtr->next;
	    free(dumpPtr);
	    dumpPtr = nextDumpPtr;
	}
	bc_globalConfig->dsched = 0;;
    }

    /* open a temp file to store the config text received from buserver *
     * The open file stream is stored in ctPtr->textStream */
    code =
	bc_openTextFile(ctPtr,
			&bc_globalConfig->
			tmpTextFileNames[TB_DUMPSCHEDULE][0]);
    if (code)
	ERROR(code);
    /* now get a fresh set of information from the database */
    code = bcdb_GetTextFile(ctPtr);
    if (code)
	ERROR(code);

    /* fetch the version number */
    code =
	ubik_BUDB_GetTextVersion(uhptr->uh_client, 0, ctPtr->textType,
		  &ctPtr->textVersion);
    if (code)
	ERROR(code);

    /* parse the file */
    code = bc_ParseDumpSchedule();
    if (code)
	ERROR(code);

    /* rebuild the tree */
    code = bc_ProcessDumpSchedule(bc_globalConfig);
    if (code)
	ERROR(code);

  error_exit:
    if (lock && ctPtr->lockHandle)
	bc_UnlockText(ctPtr);
    return (code);
}
Ejemplo n.º 4
0
int
bcdb_GetTextFile(udbClientTextP ctPtr)
{
    afs_int32 bufferSize;
    afs_int32 offset, nextOffset;
    charListT charList;
    afs_int32 code = 0;

    /* Initialize charlistT_val. We try to deallocate this structure based on
     * this */
    memset((void *)&charList, 0, sizeof(charList));

    /* check params and cleanup any previous state */
    if (ctPtr->lockHandle == 0)
	ERROR(BUDB_INTERNALERROR);

    if (ctPtr->textStream == NULL)	/* Should have an open stream */
	ERROR(BUDB_INTERNALERROR);

    /* allocate a buffer */
    bufferSize = 1024;
    charList.charListT_val = malloc(bufferSize);
    if (charList.charListT_val == 0)
	ERROR(BUDB_INTERNALERROR);
    charList.charListT_len = bufferSize;

    nextOffset = 0;
    ctPtr->textSize = 0;
    while (nextOffset != -1) {
	offset = nextOffset;
	charList.charListT_len = bufferSize;
	code =
	    ubik_BUDB_GetText(udbHandle.uh_client, 0, ctPtr->lockHandle,
		      ctPtr->textType, bufferSize, offset, &nextOffset,
		      &charList);

	if (code)
	    ERROR(code);

	code =
	    fwrite(charList.charListT_val, sizeof(char),
		   charList.charListT_len, ctPtr->textStream);
	if (ferror(ctPtr->textStream))
	    ERROR(BUDB_INTERNALERROR);

	ctPtr->textSize += charList.charListT_len;
    }

    /* get text version */
    code =
	ubik_BUDB_GetTextVersion(udbHandle.uh_client, 0,
		  ctPtr->textType, &ctPtr->textVersion);
    if (code)
	ERROR(code);

  normal_exit:
    fflush(ctPtr->textStream);	/* debug */

    /* exit, leaving the configuration text file open */
    if (charList.charListT_val)
	free(charList.charListT_val);
    return (code);

  error_exit:
    if (ctPtr->textStream != NULL) {
	fclose(ctPtr->textStream);
	ctPtr->textStream = NULL;
    }
    goto normal_exit;
}