AFS

 view release on metacpan or  search on metacpan

src/AFS.xs  view on Meta::CPAN

        }
        ST(0) = sv_newmortal();
        SETCODE(0);
        if (count == 0) {
            sprintf(buffer, "No active transactions on %s\n", aserver);
            sv_setpv(ST(0), buffer);
        }
        else {
            sprintf(buffer, "Total transactions: %d\n", count);
            sv_setpv(ST(0), buffer);
        }
        XSRETURN(1);
    }

int32
vos_release(cstruct, name, force=Nullsv)
        AFS::VOS cstruct
        char *name
        SV *  force
    PREINIT:
        struct nvldbentry entry;
        afs_int32 avolid, aserver, apart, vtype, code, err;
        int iforce;
    CODE:
    {
        if (!force) {
            force = newSViv(0);
        }
        if (!SvIOKp(force)) {
            char buffer[256];
            sprintf(buffer, "Flag \"force\" should be numeric.\n");
            VSETCODE(EINVAL, buffer);
            XSRETURN_UNDEF;
        }
        iforce = SvIV(force);
        RETVAL = 0;
        avolid = vsu_GetVolumeID(name, cstruct, &err);
        if (avolid == 0) {
            char buffer[256];
            if (err)
                set_errbuff(buffer, err);
            else
                sprintf(buffer, "AFS::VOS: can't find volume '%s'\n", name);
            VSETCODE(err ? err : ENOENT, buffer);
            goto done;
        }
        code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
        if (code) {
            SETCODE(code);
            goto done;
        }
        if (vtype != RWVOL) {
            char buffer[256];
            sprintf(buffer, "%s not a RW volume\n", name);
            VSETCODE(ENOENT, buffer);
            goto done;
        }

        if (!ISNAMEVALID(entry.name)) {
            char buffer[256];
            sprintf(buffer, "Volume name %s is too long, rename before releasing\n", entry.name);
            VSETCODE(E2BIG, buffer);
            goto done;
        }

        code = UV_ReleaseVolume(avolid, aserver, apart, iforce);
        if (code) {
            PrintDiagnostics("release", code);
            SETCODE(code);
            goto done;
        }
        #fprintf(STDOUT, "Released volume %s successfully\n", name);
        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos_create(cstruct, server, partition, name, maxquota=Nullsv, vid=Nullsv, rovid=Nullsv)
        AFS::VOS cstruct
        char *server
        char *partition
        char *name
        SV * maxquota
        SV * vid
        SV * rovid
    PREINIT:
        int32 pnum;
        int32 code;
        struct nvldbentry entry;
        int32 vcode;
        int32 quota = 5000;
        afs_int32 tserver;
#ifdef OpenAFS_1_4_12
        afs_uint32 volid = 0, rovolid = 0, bkvolid = 0;
        afs_uint32 *arovolid = NULL;
#else
        afs_int32 volid = 0;
#endif
    CODE:
    {
        if (!maxquota)
            maxquota = newSViv(0);
        if (!vid)
            vid = newSViv(0);
        if (!rovid)
            rovid = newSViv(0);

        RETVAL = 0;
        /* printf("vos-create DEBUG-1 server %s part %s vol %s maxq %d vid %d rovid %d \n", server, partition, name, SvIV(maxquota), SvIV(vid), SvIV(rovid)); */

        tserver = GetServer(server);
        if (!tserver) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: host '%s' not found in host table\n", server);
            VSETCODE(ENOENT, buffer);
            goto done;

src/AFS.xs  view on Meta::CPAN

                    (server && (server != entry.serverNumber[idx])) ||
                    ((partition != -1) && (partition != entry.serverPartition[idx]))) {
                    char buffer[256];
                    sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                    VSETCODE(ENOENT, buffer);
                    goto done;
                }
            }
            else if ((volid == entry.volumeId[ROVOL]) && (entry.flags & RO_EXISTS)) {
                for (idx = -1, j = 0; j < entry.nServers; j++) {
                    if (entry.serverFlags[j] != ITSROVOL)
                        continue;

                    if (((server == 0) || (server == entry.serverNumber[j])) &&
                        ((partition == -1) || (partition == entry.serverPartition[j]))) {
                        if (idx != -1) {
                            char buffer[256];
                            sprintf(buffer, "AFS::VOS: Volume '%s' matches more than one RO\n",
                                    name);
                            VSETCODE(ENOENT, buffer);
                            goto done;
                        }
                        idx = j;
                    }
                }
                if (idx == -1) {
                    char buffer[256];
                    sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                    VSETCODE(ENOENT, buffer);
                    goto done;
                }
            }
            else {
                char buffer[256];
                sprintf(buffer, "AFS::VOS: Volume '%s' no match\n", name);
                VSETCODE(ENOENT, buffer);
                goto done;
            }

            server = htonl(entry.serverNumber[idx]);
            partition = entry.serverPartition[idx];
        }

        code = UV_DeleteVolume(server, partition, volid);
        if (code) {
            PrintDiagnostics("remove", code);
            SETCODE(code);
            goto done;
        }

        SETCODE(0);
        RETVAL = volid;

        done:
        ;
    }
    OUTPUT: 
        RETVAL

int32
vos_rename(cstruct,oldname,newname)
        AFS::VOS cstruct
        char * oldname
        char * newname
    PREINIT:
        afs_int32 code1, code2, code;
        struct nvldbentry entry;
    CODE:
    {
        RETVAL = 0;
        code1 = VLDB_GetEntryByName(oldname, &entry);
        if (code1) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: Could not find entry for volume %s\n", oldname);
            VSETCODE(-1, buffer);
            goto done;
        }
        code2 = VLDB_GetEntryByName(newname, &entry);
        if ((!code1) && (!code2)) {     /*the newname already exists */
            char buffer[256];
            sprintf(buffer, "AFS::VOS: volume %s already exists\n", newname);
            VSETCODE(-1, buffer);
            goto done;
        }

        if (code1 && code2) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: Could not find entry for volume %s or %s\n", oldname,
                    newname);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (!VolNameOK(oldname)) {
            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
                    oldname);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (!ISNAMEVALID(newname)) {
            char buffer[256];
            sprintf(buffer, "AFS::VOS: the new volume name %s exceeds the size limit of %d\n",
                    newname, VOLSER_OLDMAXVOLNAME - 10);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (!VolNameOK(newname)) {
            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
                    newname);
            VSETCODE(-1, buffer);
            goto done;
        }
        if (IsNumeric(newname)) {
            char buffer[256];
            sprintf(buffer, "Illegal volume name %s, should not be a number\n", newname);
            VSETCODE(-1, buffer);
            goto done;
        }
        MapHostToNetwork(&entry);
        code = UV_RenameVolume(&entry, oldname, newname);
        if (code) {
            PrintDiagnostics("rename", code);
            SETCODE(code);
            goto done;
        }
        #fprintf(STDOUT, "Renamed volume %s to %s\n", oldname, newname);

        SETCODE(0);
        RETVAL = 1;

        done:
        ;
    }
    OUTPUT:
        RETVAL

int32
vos__setfields(cstruct, name, mquota=Nullsv, clearuse=Nullsv)
        AFS::VOS cstruct
        char *name
        SV * mquota
        SV * clearuse
    PREINIT:
#ifdef OpenAFS
        struct nvldbentry entry;
        volintInfo info;
        int32 volid;
        int32 clear, code, err;
        int32 aserver, apart;
        int previdx = -1;
#endif
    CODE:
    {
#ifdef OpenAFS
        if (!mquota)
            mquota = newSViv(-1);
        if (!clearuse)
            clearuse = newSViv(0);
        if ((!SvIOKp(mquota))) {     /* -max <quota> */
            char buffer[256];
            sprintf(buffer, "invalid quota value\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }
        if ((!SvIOKp(clearuse))) {     /* -clearuse */
            char buffer[256];
            sprintf(buffer, "flag \"clearuse\" is not an integer\n");
            VSETCODE(EINVAL, buffer);
            goto done;
        }

        /* printf("vos-setfields DEBUG-1 name %s mquota %d clearuse %d \n", name, (int)SvIV(mquota), (int)SvIV(clearuse)); */
        RETVAL = 0;
        volid = vsu_GetVolumeID(name, cstruct, &err);   /* -id */
        if (volid == 0) {
            char buffer[256];
            if (err)
                set_errbuff(buffer, err);
            else
                sprintf(buffer, "Unknown volume ID or name '%s'\n", name);
            VSETCODE(err ? err : -1, buffer);
            goto done;

src/AFS.xs  view on Meta::CPAN

        code = ubik_Call(PR_ListEntry, server, 0, id, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prcheckentry(server, stats, &entry, 0, 0);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_dumpentry(server,pos,lookupids=1,convertflags=1)
        AFS::PTS server
        int32   pos
        int32   lookupids
        int32   convertflags
    PPCODE:
    {
        int32 code;
        struct prdebugentry entry;

        code = ubik_Call(PR_DumpEntry, server, 0, pos, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prdebugentry(server, stats, &entry, lookupids, convertflags);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_PR_DumpEntry(server,pos)
        AFS::PTS server
        int32   pos
    PPCODE:
    {
        int32 code;
        struct prdebugentry entry;

        code = ubik_Call(PR_DumpEntry, server, 0, pos, &entry);

        SETCODE(code);

        if (code == 0) {
            HV *stats;
            stats = newHV();
            parse_prdebugentry(server, stats, &entry, 0, 0);
            EXTEND(sp, 1);
            PUSHs(sv_2mortal(newRV_noinc((SV *) stats)));
        }
    }

void
pts_rename(server,name,newname)
        AFS::PTS server
        char *  name
        char *  newname
    PPCODE:
    {
        int32 code;
        int32 id;

        code = internal_pr_id(server, name, &id, 0);

        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, newname, 0, 0);

        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_chown(server,name,owner)
        AFS::PTS server
        char *  name
        char *  owner
    PPCODE:
    {
        int32 code;
        int32 id, oid;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = internal_pr_id(server, owner, &oid, 0);
        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, "", oid, 0);
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_chid(server,name,newid)
        AFS::PTS server
        char *  name
        int32   newid
    PPCODE:
    {
        int32 code;
        int32 id;

        code = internal_pr_id(server, name, &id, 0);
        if (code == 0)
            code = ubik_Call(PR_ChangeEntry, server, 0, id, "", 0, newid);
        SETCODE(code);
        ST(0) = sv_2mortal(newSViv(code == 0));
        XSRETURN(1);
    }

void
pts_PR_ChangeEntry(server,id,name,oid,newid)
        AFS::PTS server
        int32   id



( run in 0.595 second using v1.01-cache-2.11-cpan-ceb78f64989 )