AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

int set_errbuff(buffer, errcode)
    char *buffer;
    int32 errcode;
{
    /*replace by a big switch statement */
    switch (errcode) {
      case 0:
          break;
      case -1:
          sprintf(buffer, "Possible communication failure\n");
          break;
      case VSALVAGE:
          sprintf(buffer, "Volume needs to be salvaged\n");
          break;
      case VNOVNODE:
          sprintf(buffer, "Bad vnode number quoted\n");
          break;
      case VNOVOL:
          sprintf(buffer, "Volume not attached, does not exist, or not on line\n");
          break;
      case VVOLEXISTS:
          sprintf(buffer, "Volume already exists\n");
          break;
      case VNOSERVICE:
          sprintf(buffer, "Volume is not in service\n");
          break;
      case VOFFLINE:
          sprintf(buffer, "Volume is off line\n");
          break;
      case VONLINE:
          sprintf(buffer, "Volume is already on line\n");
          break;
      case VDISKFULL:
          sprintf(buffer, "Partition is full\n");
          break;
      case VOVERQUOTA:
          sprintf(buffer, "Volume max quota exceeded\n");
          break;
      case VBUSY:
          sprintf(buffer, "Volume temporarily unavailable\n");
          break;
      case VMOVED:
          sprintf(buffer, "Volume has moved to another server\n");
          break;
      case VL_IDEXIST:
          sprintf(buffer, "VLDB: volume Id exists in the vldb\n");
          break;
      case VL_IO:
          sprintf(buffer, "VLDB: a read terminated too early\n");
          break;
      case VL_NAMEEXIST:
          sprintf(buffer, "VLDB: volume entry exists in the vldb\n");
          break;
      case VL_CREATEFAIL:
          sprintf(buffer, "VLDB: internal creation failure\n");
          break;
      case VL_NOENT:
          sprintf(buffer, "VLDB: no such entry\n");
          break;
      case VL_EMPTY:
          sprintf(buffer, "VLDB: vldb database is empty\n");
          break;
      case VL_ENTDELETED:
          sprintf(buffer, "VLDB: entry is deleted (soft delete)\n");
          break;
      case VL_BADNAME:
          sprintf(buffer, "VLDB: volume name is illegal\n");
          break;
      case VL_BADINDEX:
          sprintf(buffer, "VLDB: index was out of range\n");
          break;
      case VL_BADVOLTYPE:
          sprintf(buffer, "VLDB: bad volume type\n");
          break;
      case VL_BADSERVER:
          sprintf(buffer, "VLDB: illegal server number (not within limits)\n");
          break;
      case VL_BADPARTITION:
          sprintf(buffer, "VLDB: bad partition number\n");
          break;
      case VL_REPSFULL:
          sprintf(buffer, "VLDB: run out of space for replication sites\n");
          break;
      case VL_NOREPSERVER:
          sprintf(buffer, "VLDB: no such repsite server exists\n");
          break;
      case VL_DUPREPSERVER:
          sprintf(buffer, "VLDB: replication site server already exists\n");
          break;
      case VL_RWNOTFOUND:
          sprintf(buffer, "VLDB: parent r/w entry not found\n");
          break;
      case VL_BADREFCOUNT:
          sprintf(buffer, "VLDB: illegal reference count number\n");
          break;
      case VL_SIZEEXCEEDED:
          sprintf(buffer, "VLDB: vldb size for attributes exceeded\n");
          break;
      case VL_BADENTRY:
          sprintf(buffer, "VLDB: bad incoming vldb entry\n");
          break;
      case VL_BADVOLIDBUMP:
          sprintf(buffer, "VLDB: illegal max volid increment\n");
          break;
      case VL_IDALREADYHASHED:
          sprintf(buffer, "VLDB: (RO/BACK) Id already hashed\n");
          break;
      case VL_ENTRYLOCKED:
          sprintf(buffer, "VLDB: vldb entry is already locked\n");
          break;
      case VL_BADVOLOPER:
          sprintf(buffer, "VLDB: bad volume operation code\n");
          break;
      case VL_BADRELLOCKTYPE:
          sprintf(buffer, "VLDB: bad release lock type\n");
          break;
      case VL_RERELEASE:
          sprintf(buffer, "VLDB: status report: last release was aborted\n");
          break;
      case VL_BADSERVERFLAG:
          sprintf(buffer, "VLDB: invalid replication site server flag\n");

src/AFS.xs  view on Meta::CPAN

        /* memcpy(&addr, th->h_addr, sizeof(addr)); */
        Copy(th->h_addr, &addr, th->h_length, char);
    }

    return (addr);
}

 /*sends the contents of file associated with <fd> and <blksize>  to Rx Stream 
    * associated  with <call> */
int SendFile(ufd, call, blksize)
    usd_handle_t ufd;
    register struct rx_call *call;
    long blksize;
{
    char *buffer = (char *) 0;
    afs_int32 error = 0;
    int done = 0;
    afs_uint32 nbytes;

    buffer = (char *) safemalloc(blksize);
    if (!buffer) {
        char buf[256];
        sprintf(buf, "malloc failed\n");
        VSETCODE(-1, buf);
        return -1;
    }

    while (!error && !done) {
#ifndef AFS_NT40_ENV            /* NT csn't select on non-socket fd's */
        fd_set in;
        FD_ZERO(&in);
        FD_SET((long) (ufd->handle), &in);
        /* don't timeout if read blocks */
#ifdef AFS_PTHREAD_ENV
        select(((long) (ufd->handle)) + 1, &in, 0, 0, 0);
#else
        IOMGR_Select(((long) (ufd->handle)) + 1, &in, 0, 0, 0); 
#endif /* AFS_PTHREAD_ENV*/
#endif
        error = USD_READ(ufd, buffer, blksize, &nbytes);
        if (error) {
            char buf[256];
            sprintf(buf, "File system read failed\n");
            VSETCODE(error, buf);
            break;
        }
        if (nbytes == 0) {
            done = 1;
            break;
        }
        if (rx_Write(call, buffer, nbytes) != nbytes) {
            error = -1;
            break;
        }
    }
    if (buffer)
        free(buffer);
    return error;
}

/* function invoked by UV_RestoreVolume, reads the data from rx_trx_stream and
 * writes it out to the volume. */
afs_int32 WriteData(call, rock)
    struct rx_call *call;
    char *rock;
{
    char *filename;
    usd_handle_t ufd;
    long blksize;
    afs_int32 error, code;
    int ufdIsOpen = 0;

    error = 0;

    filename = rock;
    if (!filename || !*filename) {
        usd_StandardInput(&ufd);
        blksize = 4096;
        ufdIsOpen = 1;
    }
    else {
        code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
        if (code == 0) {
            ufdIsOpen = 1;
            code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
        }
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not access file '%s'\n", filename);
            error = VOLSERBADOP;
            VSETCODE(error, buffer);
            goto wfail;
        }
    }
    code = SendFile(ufd, call, blksize);
    if (code) {
        error = code;
        goto wfail;
    }
  wfail:
    if (ufdIsOpen) {
        code = USD_CLOSE(ufd);
        if (code) {
            char buffer[256];
            sprintf(buffer, "Could not close dump file %s\n",
                    (filename && *filename) ? filename : "STDOUT");
            VSETCODE(code, buffer);
            if (!error)
                error = code;
        }
    }
    return error;
}

/* Receive data from <call> stream into file associated
 * with <fd> <blksize>
 */
int ReceiveFile(ufd, call, blksize)
    usd_handle_t ufd;
    struct rx_call *call;
    long blksize;
{
    char *buffer = (char *) 0;
    afs_int32 bytesread;
    afs_uint32 bytesleft, w;
    afs_int32 error = 0;

    buffer = (char *) safemalloc(blksize);
    if (!buffer) {
        char buf[256];
        sprintf(buf, "memory allocation failed\n");
        VSETCODE(-1, buf);
        ERROR_EXIT(-1);
    }

    while ((bytesread = rx_Read(call, buffer, blksize)) > 0) {
        for (bytesleft = bytesread; bytesleft; bytesleft -= w) {
#ifndef AFS_NT40_ENV            /* NT csn't select on non-socket fd's */
            fd_set out;
            FD_ZERO(&out);
            FD_SET((long) (ufd->handle), &out);
            /* don't timeout if write blocks */
#ifdef AFS_PTHREAD_ENV
            select(((long) (ufd->handle)) + 1, 0, &out, 0, 0);
#else
            IOMGR_Select(((long) (ufd->handle)) + 1, 0, &out, 0, 0); 
#endif /* AFS_PTHREAD_ENV*/
#endif
            error = USD_WRITE(ufd, &buffer[bytesread - bytesleft], bytesleft, &w);
            if (error) {
                char buf[256];
                sprintf(buf, "File system write failed\n");
                VSETCODE(-1, buf);
                ERROR_EXIT(-1);
            }
        }
    }

  error_exit:
    if (buffer)
        free(buffer);
    return (error);
}

afs_int32 DumpFunction(call, filename)
    struct rx_call *call;
    char *filename;
{
    usd_handle_t ufd;           /* default is to stdout */
    afs_int32 error = 0, code;
    afs_hyper_t size;
    long blksize;
    int ufdIsOpen = 0;

    /* Open the output file */

src/AFS.xs  view on Meta::CPAN

    int encryptLevel;
    struct ktc_principal sname;
    struct ktc_token ttoken;

    /* printf("bos DEBUG-1: %s \n", cdir); */
    th = (struct hostent *) hostutil_GetHostByName(hostname);
    if (!th) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: can't find address for host '%s'\n", hostname);
        *code = -1;
        BSETCODE(code, buffer);
/*         printf("bos DEBUG-1: %s\n", buffer); */
        return NULL;
    }
    /* Copy(th->h_addr, &addr, sizeof(afs_int32), afs_int32); */
    Copy(th->h_addr, &addr, th->h_length, char);

    /* get tokens for making authenticated connections */
    if (!rx_initialized) {
        /* printf("bos DEBUG rx_Init\n"); */
        *code = rx_Init(0);
        if (*code) {
            char buffer[256];
            sprintf(buffer, "AFS::BOS: could not initialize rx (%d)\n", *code);
            BSETCODE(code, buffer);
/*          printf("bos DEBUG-2\n"); */
            return NULL;
        }
    }
    rx_initialized = 1;

    *code = ka_Init(0);
    if (*code) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: could not initialize ka (%d)\n", *code);
        BSETCODE(code, buffer);
/*          printf("bos DEBUG-3\n"); */
        return NULL;
    }

    if (localauth)
        internal_GetServerConfigDir();
    else
        internal_GetConfigDir();
    /* printf("bos DEBUG-2: %s\n", cdir->name); */

    if (!cdir) {
        *code = errno;
        SETCODE(code);
/*         printf("bos DEBUG-4\n"); */
        return NULL;
    }

    struct afsconf_cell info;

    /* next call expands cell name abbrevs for us and handles looking up
     * local cell */
    *code = internal_GetCellInfo(tname, (char *) 0, &info);
    if (*code) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS %d (can't find cell '%s' in cell database)",
                *code, (tname ? tname : "<default>"));
        BSETCODE(code, buffer);
        /*             printf("bos DEBUG-5\n"); */
        return NULL;
    }

    strcpy(sname.cell, info.name);
    sname.instance[0] = 0;
    strcpy(sname.name, "afs");
    sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
    sc[1] = 0;
    sc[2] = (struct rx_securityClass *) NULL;
    scIndex = 0;

    if (!noauth) {              /* not -noauth */
        if (localauth) {        /* -localauth */
            *code = afsconf_GetLatestKey(cdir, 0, 0);
            if (*code)
                fprintf(stderr, "AFS::BOS %d (getting key from local KeyFile)", *code);
            else {
                if (aencrypt)
                    *code = afsconf_ClientAuthSecure(cdir, &sc[2], &scIndex);
                else
                    *code = afsconf_ClientAuth(cdir, &sc[2], &scIndex);
                if (*code)
                    fprintf(stderr, "AFS::BOS %d (calling ClientAuth)", *code);
                else if (scIndex != 2)  /* this shouldn't happen */
                    sc[scIndex] = sc[2];
            }
        }
        else {                  /* not -localauth, check for tickets */
            *code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
            if (*code == 0) {
                /* have tickets, will travel */
                if (ttoken.kvno >= 0 && ttoken.kvno <= 256);
                else {
                    fprintf(stderr,
                            "AFS::BOS: funny kvno (%d) in ticket, proceeding\n",
                            ttoken.kvno);
                }
                /* kerberos tix */
                if (aencrypt)
                    encryptLevel = rxkad_crypt;
                else
                    encryptLevel = rxkad_clear;
                sc[2] = (struct rx_securityClass *)
                    rxkad_NewClientSecurityObject
                    (encryptLevel, &ttoken.sessionKey,
                     ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
                scIndex = 2;
            }
            else
                fprintf(stderr, "AFS::BOS %d (getting tickets)", *code);
        }
        if ((scIndex == 0) || (sc[scIndex] == 0)) {
            fprintf(stderr, "AFS::BOS: running unauthenticated\n");
            scIndex = 0;
        }
    }
    tconn = rx_NewConnection(addr, htons(AFSCONF_NANNYPORT), 1, sc[scIndex], scIndex);

src/AFS.xs  view on Meta::CPAN

        strcat(tbuffer, " -ForceOnLine");
    if (mrafsParm.OptUseRootDirACL)
        strcat(tbuffer, " -UseRootDirACL");
    if (mrafsParm.OptTraceBadLinkCounts)
        strcat(tbuffer, " -TraceBadLinkCounts");
    if (mrafsParm.OptDontAskFS)
        strcat(tbuffer, " -DontAskFS");
    if (mrafsParm.OptLogLevel) {
        sprintf(pbuffer, " -LogLevel %d", mrafsParm.OptLogLevel);
        strcat(tbuffer, pbuffer);
    }
    if (mrafsParm.OptRxDebug)
        strcat(tbuffer, " -rxdebug");
    if (mrafsParm.OptResidencies) {
        sprintf(pbuffer, " -Residencies %u", mrafsParm.OptResidencies);
        strcat(tbuffer, pbuffer);
    }

    parms[0] = tbuffer;
    parms[1] = "now";           /* when to do it */
    code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
                            parms[2], parms[3], parms[4], notifier);
    if (code) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: failed to start 'salvager' (%s)\n", em(code));
        BSETCODE(code, buffer);
        goto done;
    }
    /* now wait for bnode to disappear */
    while (1) {
#ifdef AFS_PTHREAD_ENV
        sleep(5);
#else
        IOMGR_Sleep(5);
#endif /* AFS_PTHREAD_ENV*/
        tp = tbuffer;
        code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
        if (code)
            break;
        /* fprintf(stderr, "AFS::BOS: waiting for salvage to complete.\n"); */
    }
    if (code != BZNOENT) {
        char buffer[256];
        sprintf(buffer, "AFS::BOS: salvage failed (%s)\n", em(code));
        BSETCODE(code, buffer);
        goto done;
    }
    code = 0;

    /* now print the log file to the output file */
    /* fprintf(stderr, "AFS::BOS: salvage completed\n"); */
    if (aoutName || showlog) {
        fprintf(outFile, "SalvageLog:\n");
        tcall = rx_NewCall(aconn);
        /* MUST pass canonical (wire-format) salvager log path to bosserver */
        code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
        if (code) {
            rx_EndCall(tcall, code);
            goto done;
        }
        /* copy data */
        while (1) {
            code = rx_Read(tcall, &buffer, 1);
            if (code != 1)
                break;
            putc(buffer, outFile);
            if (buffer == 0)
                break;          /* the end delimeter */
        }
        code = rx_EndCall(tcall, 0);
        /* fall through into cleanup code */
    }

  done:
    if (closeIt && outFile)
        fclose(outFile);
    return code;
}
/* end of helper functions for BOS class */


/* helper functions for FS class: */

static int32 isafs(path, follow)
    char *path;
    int32 follow;
{
    struct ViceIoctl vi;
    register int32 code;
    char space[MAXSIZE];

    vi.in_size = 0;
    vi.out_size = MAXSIZE;
    vi.out = space;

    code = pioctl(path, VIOC_FILE_CELL_NAME, &vi, follow);
    if (code) {
        if ((errno == EINVAL) || (errno == ENOENT))
            return 0;
        if (errno == ENOSYS)
            return 0;
    }
    return 1;
}

static char *format_rights(rights)
    int32 rights;
{
    static char buff[32];
    char *p;

    p = buff;

    if (rights & PRSFS_READ) {
        *p++ = 'r';
    }
    if (rights & PRSFS_LOOKUP) {
        *p++ = 'l';
    }
    if (rights & PRSFS_INSERT) {
        *p++ = 'i';

src/AFS.xs  view on Meta::CPAN

            len = av_len(av);
            if (len != -1) {
/*         printf("DEBUG-bos-delete-6 \n"); */
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                        name = (char *) safemalloc(BOZO_BSSIZE);
                        name = SvPV(sv, namelen);
/*         printf("DEBUG-bos-delete-7 %s\n", name); */
                        code = BOZO_DeleteBnode(self, name);
/*         printf("DEBUG-bos-delete-8 %d \n", code); */
                        if (code) {
                            char buffer[256];
                            if (code == BZBUSY)
                                sprintf(buffer, "AFS::BOS: can't delete running instance '%s'\n",
                                        name);
                            else
                                sprintf(buffer, "AFS::BOS: failed to delete instance '%s' (%s)\n",
                                        name, em(code));
                            BSETCODE(code, buffer);
                            goto done;
                        }
                    }
                }                       /* for loop */
            }
        }
        SETCODE(0);
/*         printf("DEBUG-bos-delete-9 \n"); */

        done:
        RETVAL = (code == 0);
/*         printf("DEBUG-bos-delete-10 \n"); */
/*         if (name) */
/*             Safefree(name); */
/*         printf("DEBUG-bos-delete-11 \n"); */
    }
    OUTPUT:
        RETVAL

void
bos_getlog(self, file)
        AFS::BOS self
        char* file
    PREINIT:
        register struct rx_call *tcall;
        int32 code = 0;
        char buf, c[255];
        int error, num = 0, i = 0;
    PPCODE:
    {
        tcall = rx_NewCall(self);
        code = StartBOZO_GetLog(tcall, file);
        if (code) {
            char buffer[256];
            rx_EndCall(tcall, code);
            sprintf(buffer, "AFS::BOS error %d (while reading log)\n", code);
            BSETCODE(code, buffer);
            XSRETURN_UNDEF;
        }

            /* copy data */
        error = 0;
        while (1) {
            code = rx_Read(tcall, &buf, 1);
            if (code != 1) {
                error = EIO;
                break;
            }
            if (buf == 0)
                break;                  /* the end delimeter */
            /* putchar(buf); */
            c[i++] = buf;
            if (buf == '\n') {
                XPUSHs(sv_2mortal(newSVpv(c, i)));
                i = 0;
                num++;
            }
        }

        code = rx_EndCall(tcall, error);
        #if (tcall)
        #    Safefree(tcall);
            /* fall through into cleanup code */
        XSRETURN(num);
    }

int32
bos__start(self, object=NULL)
        AFS::BOS self
        SV * object
    PREINIT:
        int32 code = 0;
    CODE:
    {
        if (object && (! (SvTYPE(SvRV(object)) == SVt_PVAV))) {
            code = -1;
            BSETCODE(code, "AFS::BOS: SERVER not an array reference\n");
            goto done;
        }

        if (object && (SvTYPE(SvRV(object)) == SVt_PVAV)) {
            AV *av;
            SV *sv;
            char *instance;
            STRLEN namelen;
            int i, len;

            av = (AV *) SvRV(object);
            len = av_len(av);
            if (len != -1) {
                for (i = 0; i <= len; i++) {
                    sv = *av_fetch(av, i, 0);
                    if (sv) {
                      /* instance = (char *) safemalloc(BOZO_BSSIZE); */
                        Newx(instance, BOZO_BSSIZE, char);
                        instance = SvPV(sv, namelen);
                        code = BOZO_SetStatus(self, instance, BSTAT_NORMAL);
                        if (code) {
                            char buffer[256];
                            sprintf(buffer, "AFS::BOS: failed to start instance %s (%s)\n",
                                    instance, em(code));



( run in 0.802 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )