AFS
view release on metacpan or search on metacpan
char buffer[256];
sprintf(buffer, "Could not fetch the entry for volume %u from VLDB \n", volid);
VSETCODE(vcode, buffer);
return (vcode);
}
MapHostToNetwork(rentry);
if (volid == rentry->volumeId[ROVOL]) {
*voltype = ROVOL;
for (i = 0; i < rentry->nServers; i++) {
if ((index == -1) && (rentry->serverFlags[i] & ITSROVOL) &&
!(rentry->serverFlags[i] & RO_DONTUSE))
index = i;
}
if (index == -1) {
char buffer[256];
sprintf(buffer, "RO volume is not found in VLDB entry for volume %u\n",
volid);
VSETCODE(-1, buffer);
return -1;
}
*server = rentry->serverNumber[index];
*part = rentry->serverPartition[index];
return 0;
}
index = Lp_GetRwIndex(rentry);
if (index == -1) {
char buffer[256];
sprintf(buffer, "RW Volume is not found in VLDB entry for volume %u\n", volid);
VSETCODE(-1, buffer);
return -1;
}
if (volid == rentry->volumeId[RWVOL]) {
*voltype = RWVOL;
*server = rentry->serverNumber[index];
*part = rentry->serverPartition[index];
return 0;
}
if (volid == rentry->volumeId[BACKVOL]) {
*voltype = BACKVOL;
*server = rentry->serverNumber[index];
*part = rentry->serverPartition[index];
return 0;
}
/* should never reach this ? */
printf("FIXME: reached end of control at %d\n",__LINE__);
return -1;
}
static int VolNameOK(name)
char *name;
{
int total;
total = strlen(name);
if (!strcmp(&name[total - 9], ".readonly")) {
return 0;
}
else if (!strcmp(&name[total - 7], ".backup")) {
return 0;
}
else {
return 1;
}
}
static int IsNumeric(name)
char *name;
{
int result, len, i;
char *ptr;
result = 1;
ptr = name;
len = strlen(name);
for (i = 0; i < len; i++) {
if (*ptr < '0' || *ptr > '9') {
result = 0;
break;
}
ptr++;
}
return result;
}
int IsPartValid(partId, server, code)
afs_int32 server, partId, *code;
{
struct partList dummyPartList;
int i, success, cnt;
success = 0;
*code = 0;
*code = UV_ListPartitions(server, &dummyPartList, &cnt);
if (*code)
return success;
for (i = 0; i < cnt; i++) {
if (dummyPartList.partFlags[i] & PARTVALID)
if (dummyPartList.partId[i] == partId)
success = 1;
}
return success;
}
afs_int32 GetServer(aname)
char *aname;
{
register struct hostent *th;
afs_int32 addr;
int b1, b2, b3, b4;
register afs_int32 code;
char hostname[MAXHOSTCHARS];
code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
if (code == 4) {
static int FileExists(filename)
char *filename;
{
usd_handle_t ufd;
int code;
afs_hyper_t size;
code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
if (code) {
return 0;
}
code = USD_IOCTL(ufd, USD_IOCTL_GETSIZE, &size);
USD_CLOSE(ufd);
if (code) {
return 0;
}
return 1;
}
static void myDisplayFormat(vol, pntr, server, part, totalOK, totalNotOK, totalBusy, fast)
HV *vol;
volintInfo *pntr;
afs_int32 server, part;
int *totalOK, *totalNotOK, *totalBusy;
int fast;
{
char pname[10];
char hostname[256];
if (fast) {
safe_hv_store(vol, "volid", 5, newSViv(pntr->volid), 0);
}
else {
safe_hv_store(vol, "status", 6, newSViv(pntr->status), 0);
safe_hv_store(vol, "volid", 5, newSViv(pntr->volid), 0);
if (pntr->status == VOK) {
safe_hv_store(vol, "name", 4, newSVpv(pntr->name, strlen((char *) pntr->name)), 0);
if (pntr->type == 0)
safe_hv_store(vol, "type", 4, newSVpv("RW", 2), 0);
if (pntr->type == 1)
safe_hv_store(vol, "type", 4, newSVpv("RO", 2), 0);
if (pntr->type == 2)
safe_hv_store(vol, "type", 4, newSVpv("BK", 2), 0);
safe_hv_store(vol, "size", 4, newSViv(pntr->size), 0);
if (pntr->inUse == 1) {
safe_hv_store(vol, "inUse", 5, newSVpv("On-line", 7), 0);
*totalOK += 1;
}
else {
safe_hv_store(vol, "inUse", 5, newSVpv("Off-line", 8), 0);
*totalNotOK += 1;
}
MapPartIdIntoName(part, pname);
strcpy(hostname, (char *) hostutil_GetNameByINet(server));
safe_hv_store(vol, "server", 6, newSVpv(hostname, strlen((char *) hostname)), 0);
safe_hv_store(vol, "backupID", 8, newSViv(pntr->backupID), 0);
safe_hv_store(vol, "parentID", 8, newSViv(pntr->parentID), 0);
safe_hv_store(vol, "cloneID", 7, newSViv(pntr->cloneID), 0);
safe_hv_store(vol, "maxquota", 8, newSViv(pntr->maxquota), 0);
safe_hv_store(vol, "creationDate", 12, newSViv(pntr->creationDate), 0);
#ifdef OpenAFS /* copy taken from <src/volser/vos.c> OpenAFS-1.2.11 FULL_LISTVOL_SWITCH*/
safe_hv_store(vol, "copyDate", 8, newSViv(pntr->copyDate), 0);
if (!pntr->backupDate)
safe_hv_store(vol, "backupDate", 10, newSVpv("Never", 5), 0);
else
safe_hv_store(vol, "backupDate", 10, newSViv(pntr->backupDate), 0);
if (pntr->accessDate)
safe_hv_store(vol, "accessDate", 10, newSViv(pntr->accessDate), 0);
#endif
if (!pntr->updateDate)
safe_hv_store(vol, "updateDate", 10, newSVpv("Never", 5), 0);
else
safe_hv_store(vol, "updateDate", 10, newSViv(pntr->updateDate), 0);
safe_hv_store(vol, "dayUse", 6, newSViv(pntr->dayUse), 0);
}
else if (pntr->status == VBUSY) {
*totalBusy += 1;
qPut(&busyHead, pntr->volid);
}
else {
*totalNotOK += 1;
qPut(¬okHead, pntr->volid);
}
}
}
static void myXDisplayFormat(stats, a_xInfoP, a_servID, a_partID, a_totalOKP,
a_totalNotOKP, a_totalBusyP)
HV *stats;
volintXInfo *a_xInfoP;
afs_int32 a_servID;
afs_int32 a_partID;
int *a_totalOKP;
int *a_totalNotOKP;
int *a_totalBusyP;
{ /*XDisplayFormat */
char hostname[256];
char pname[10];
HV *stat1 = (HV *) sv_2mortal((SV *) newHV());
HV *stat2 = (HV *) sv_2mortal((SV *) newHV());
HV *stat3 = (HV *) sv_2mortal((SV *) newHV());
HV *stat4 = (HV *) sv_2mortal((SV *) newHV());
HV *stat5 = (HV *) sv_2mortal((SV *) newHV());
HV *stat6 = (HV *) sv_2mortal((SV *) newHV());
HV *stat7 = (HV *) sv_2mortal((SV *) newHV());
HV *stat8 = (HV *) sv_2mortal((SV *) newHV());
/* Fully-detailed listing. */
safe_hv_store(stats, "status", 6, newSViv(a_xInfoP->status), 0);
safe_hv_store(stats, "volid", 5, newSViv(a_xInfoP->volid), 0);
if (a_xInfoP->status == VOK) {
/* Volume's status is OK - all the fields are valid. */
if (a_xInfoP->type == 0)
safe_hv_store(stats, "type", 4, newSVpv("RW", 2), 0);
if (a_xInfoP->type == 1)
safe_hv_store(stats, "type", 4, newSVpv("RO", 2), 0);
if (a_xInfoP->type == 2)
safe_hv_store(stats, "type", 4, newSVpv("BK", 2), 0);
safe_hv_store(stats, "size", 4, newSViv(a_xInfoP->size), 0);
safe_hv_store(stats, "filecount", 9, newSViv(a_xInfoP->filecount), 0);
if (a_xInfoP->inUse == 1) {
safe_hv_store(stats, "inUse", 5, newSVpv("On-line", 7), 0);
(*a_totalOKP)++;
}
else {
safe_hv_store(stats, "inUse", 5, newSVpv("Off-line", 8), 0);
(*a_totalNotOKP)++;
}
MapPartIdIntoName(a_partID, pname);
strcpy(hostname, (char *) hostutil_GetNameByINet(a_servID));
safe_hv_store(stats, "server", 6, newSVpv(hostname, strlen((char *) hostname)), 0);
safe_hv_store(stats, "partition", 9, newSVpv(pname, strlen(pname)), 0);
safe_hv_store(stats, "parentID", 8, newSViv(a_xInfoP->parentID), 0);
safe_hv_store(stats, "cloneID", 7, newSViv(a_xInfoP->cloneID), 0);
safe_hv_store(stats, "backupID", 8, newSViv(a_xInfoP->backupID), 0);
safe_hv_store(stats, "maxquota", 8, newSViv(a_xInfoP->maxquota), 0);
safe_hv_store(stats, "creationDate", 12, newSViv(a_xInfoP->creationDate), 0);
#ifdef OpenAFS /* copy taken from <src/volser/vos.c> OpenAFS-1.2.11 FULL_LISTVOL_SWITCH*/
safe_hv_store(stats, "copyDate", 8, newSViv(a_xInfoP->copyDate), 0);
if (!a_xInfoP->backupDate)
safe_hv_store(stats, "backupDate", 10, newSVpv("Never", 5), 0);
else
safe_hv_store(stats, "backupDate", 10, newSViv(a_xInfoP->backupDate), 0);
if (a_xInfoP->accessDate)
safe_hv_store(stats, "accessDate", 10, newSViv(a_xInfoP->accessDate), 0);
#endif
if (!a_xInfoP->updateDate) {
safe_hv_store(stats, "updateDate", 10, newSVpv("Never", 5), 0);
}
else {
safe_hv_store(stats, "updateDate", 10, newSViv(a_xInfoP->updateDate), 0);
}
safe_hv_store(stats, "dayUse", 6, newSViv(a_xInfoP->dayUse), 0);
safe_hv_store(stat1, "samenet", 7,
newSViv(a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET]), 0);
safe_hv_store(stat1, "samenetauth", 11,
newSViv(a_xInfoP->stat_reads[VOLINT_STATS_SAME_NET_AUTH]), 0);
safe_hv_store(stat1, "diffnet", 7,
newSViv(a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET]), 0);
safe_hv_store(stat1, "diffnetauth", 11,
newSViv(a_xInfoP->stat_reads[VOLINT_STATS_DIFF_NET_AUTH]), 0);
safe_hv_store(stats, "Reads", 5, newRV_inc((SV *) (stat1)), 0);
safe_hv_store(stat2, "samenet", 7,
newSViv(a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET]), 0);
safe_hv_store(stat2, "samenetauth", 11,
newSViv(a_xInfoP->stat_writes[VOLINT_STATS_SAME_NET_AUTH]), 0);
safe_hv_store(stat2, "diffnet", 7,
newSViv(a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET]), 0);
safe_hv_store(stat2, "diffnetauth", 11,
newSViv(a_xInfoP->stat_writes[VOLINT_STATS_DIFF_NET_AUTH]), 0);
safe_hv_store(stats, "Writes", 6, newRV_inc((SV *) (stat2)), 0);
safe_hv_store(stat3, "fileSameAuthor", 12,
newSViv(a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_0]), 0);
safe_hv_store(stat3, "fileDiffAuthor", 12,
newSViv(a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_0]), 0);
safe_hv_store(stat3, "dirSameAuthor", 11,
newSViv(a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_0]), 0);
safe_hv_store(stat3, "dirDiffAuthor", 11,
newSViv(a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_0]), 0);
safe_hv_store(stats, "0-60sec", 7, newRV_inc((SV *) (stat3)), 0);
safe_hv_store(stat4, "fileSameAuthor", 12,
newSViv(a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_1]), 0);
safe_hv_store(stat4, "fileDiffAuthor", 12,
newSViv(a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_1]), 0);
safe_hv_store(stat4, "dirSameAuthor", 11,
newSViv(a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_1]), 0);
safe_hv_store(stat4, "dirDiffAuthor", 11,
newSViv(a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_1]), 0);
safe_hv_store(stats, "1-10min", 7, newRV_inc((SV *) (stat4)), 0);
safe_hv_store(stat5, "fileSameAuthor", 12,
newSViv(a_xInfoP->stat_fileSameAuthor[VOLINT_STATS_TIME_IDX_2]), 0);
safe_hv_store(stat5, "fileDiffAuthor", 12,
newSViv(a_xInfoP->stat_fileDiffAuthor[VOLINT_STATS_TIME_IDX_2]), 0);
safe_hv_store(stat5, "dirSameAuthor", 11,
newSViv(a_xInfoP->stat_dirSameAuthor[VOLINT_STATS_TIME_IDX_2]), 0);
safe_hv_store(stat5, "dirDiffAuthor", 11,
newSViv(a_xInfoP->stat_dirDiffAuthor[VOLINT_STATS_TIME_IDX_2]), 0);
safe_hv_store(stats, "10min-1hr", 9, newRV_inc((SV *) (stat5)), 0);
if (entry->flags & RW_EXISTS)
safe_hv_store(stats, "RWrite", 6, newSViv(entry->volumeId[RWVOL]), 0);
if (entry->flags & RO_EXISTS)
safe_hv_store(stats, "ROnly", 5, newSViv(entry->volumeId[ROVOL]), 0);
if (entry->flags & BACK_EXISTS)
safe_hv_store(stats, "Backup", 6, newSViv(entry->volumeId[BACKVOL]), 0);
if ((entry->cloneId != 0) && (entry->flags & RO_EXISTS))
safe_hv_store(stats, "cloneId", 7, newSViv(entry->cloneId), 0);
safe_hv_store(stats, "nServers", 8, newSViv(entry->nServers), 0);
for (i = 0; i < entry->nServers; i++) {
if (entry->serverFlags[i] & NEW_REPSITE)
isMixed = 1;
}
for (i = 0; i < entry->nServers; i++) {
HV *server = (HV *) sv_2mortal((SV *) newHV());
MapPartIdIntoName(entry->serverPartition[i], pname);
strcpy(hostname, (char *) hostutil_GetNameByINet(entry->serverNumber[i]));
safe_hv_store(server, "name", 4, newSVpv(hostname, strlen((char *) hostname)), 0);
safe_hv_store(server, "partition", 9, newSVpv(pname, strlen((char *) pname)), 0);
safe_hv_store(server, "serverFlags", 11, newSViv(entry->serverFlags[i]), 0);
if (entry->serverFlags[i] & ITSRWVOL)
safe_hv_store(server, "type", 4, newSVpv("RW", 2), 0);
else
safe_hv_store(server, "type", 4, newSVpv("RO", 2), 0);
if (isMixed) {
if (entry->serverFlags[i] & NEW_REPSITE)
safe_hv_store(server, "release", 7, newSVpv("New release", 11), 0);
else
safe_hv_store(server, "release", 7, newSVpv("Old release", 11), 0);
}
else {
if (entry->serverFlags[i] & RO_DONTUSE)
safe_hv_store(server, "release", 7, newSVpv("Not released", 12), 0);
}
av_push(av, newRV_inc((SV *) (server)));
}
safe_hv_store(stats, "server", 6, newRV_inc((SV *) (av)), 0);
safe_hv_store(stats, "flags", 5, newSViv(entry->flags), 0);
if (entry->flags & VLOP_ALLOPERS)
safe_hv_store(stats, "locked", 6, newSViv(entry->flags & VLOP_ALLOPERS), 0);
return;
}
static int VolumeInfoCmd(stats, name)
HV *stats;
char *name;
{
struct nvldbentry entry;
afs_int32 vcode;
/* printf("DEBUG-1-VolumeInfoCmd %s \n", name); */
/* The vlserver will handle names with the .readonly
* and .backup extension as well as volume ids.
*/
vcode = VLDB_GetEntryByName(name, &entry);
/* printf("DEBUG-2-VolumeInfoCmd %d \n", vcode); */
if (vcode)
return (vcode);
/* printf("DEBUG-3-VolumeInfoCmd \n"); */
MapHostToNetwork(&entry);
/* printf("DEBUG-4-VolumeInfoCmd \n"); */
myEnumerateEntry(stats, &entry);
/* printf("DEBUG-5-VolumeInfoCmd \n"); */
return 0;
}
/* static void PostVolumeStats_ZZZ(volinfo, entry) */
/* HV *volinfo; */
/* struct nvldbentry *entry; */
/* { */
/* myEnumerateEntry(volinfo, entry); */
/* /\* Check for VLOP_ALLOPERS *\/ */
/* if (entry->flags & VLOP_ALLOPERS) */
/* fprintf(STDOUT, " Volume is currently LOCKED \n"); */
/* return; */
/* } */
static void myprint_addrs(addr, addrs, m_uuid, nentries, print, noresolve)
HV * addr;
const bulkaddrs * addrs;
const afsUUID * m_uuid;
int nentries;
int print;
int noresolve;
{
afs_int32 vcode;
afs_int32 i;
afs_int32 *addrp;
bulkaddrs m_addrs;
ListAddrByAttributes m_attrs;
afs_int32 m_unique, m_nentries, *m_addrp;
afs_int32 base, index;
char buf[1024];
#ifdef OpenAFS
if (print) {
afsUUID_to_string(m_uuid, buf, sizeof(buf));
safe_hv_store(addr, "UUID", 4, newSVpv(buf, strlen(buf)), 0);
}
#else
noresolve = 0;
#endif
/* print out the list of all the server */
addrp = (afs_int32 *) addrs->bulkaddrs_val;
for (i = 0; i < nentries; i++, addrp++) {
char key[7];
int j = i + 1;
/* If it is a multihomed address, then we will need to
* get the addresses for this multihomed server from
* the vlserver and print them.
av_push(IPs, newSVpv(buf, strlen(buf)));
}
else {
#endif
sprintf(buf, "%s", (char *) hostutil_GetNameByINet(*m_addrp));
av_push(names, newSVpv(buf, strlen(buf)));
#ifdef OpenAFS
}
#endif
} /* for loop */
if (j == 0) {
printf("<unknown>\n");
av_push(names, newSVpv(NULL, 0));
av_push(IPs, newSVpv(NULL, 0));
}
continue;
safe_hv_store(addr, "IP", 2, newRV_inc((SV *) (IPs)), 0);
safe_hv_store(addr, "name", 4, newRV_inc((SV *) (names)), 0);
}
}
/* Otherwise, it is a non-multihomed entry and contains
* the IP address of the server - print it.
*/
*addrp = htonl(*addrp);
#ifdef OpenAFS
if (noresolve) {
char hoststr[16];
sprintf(key, "IP-%d", j);
sprintf(buf, "%s", afs_inet_ntoa_r(*addrp, hoststr));
safe_hv_store(addr, key, 4, newSVpv(buf, strlen(buf)), 0);
}
else {
#endif
sprintf(key, "name-%d", j);
sprintf(buf, "%s", (char *) hostutil_GetNameByINet(*addrp));
safe_hv_store(addr, key, 6, newSVpv(buf, strlen(buf)), 0);
#ifdef OpenAFS
}
#endif
} /* for loop */
return;
}
static void GetServerAndPart(entry, voltype, server, part, previdx)
struct nvldbentry *entry;
afs_int32 *server, *part;
int voltype;
int *previdx;
{
int i, istart, vtype;
*server = -1;
*part = -1;
/* Doesn't check for non-existance of backup volume */
if ((voltype == RWVOL) || (voltype == BACKVOL)) {
vtype = ITSRWVOL;
istart = 0; /* seach the entire entry */
}
else {
vtype = ITSROVOL;
/* Seach from beginning of entry or pick up where we left off */
istart = ((*previdx < 0) ? 0 : *previdx + 1);
}
for (i = istart; i < entry->nServers; i++) {
if (entry->serverFlags[i] & vtype) {
*server = entry->serverNumber[i];
*part = entry->serverPartition[i];
*previdx = i;
return;
}
}
/* Didn't find any, return -1 */
*previdx = -1;
return;
}
/* end of helper functions for VLDB class */
/* helper functions for BOS class */
#ifndef OpenAFS
/* is this a digit or a digit-like thing? */
static int ismeta(ac, abase)
register int abase;
register int ac;
{
/* if (ac == '-' || ac == 'x' || ac == 'X') return 1; */
if (ac >= '0' && ac <= '7')
return 1;
if (abase <= 8)
return 0;
if (ac >= '8' && ac <= '9')
return 1;
if (abase <= 10)
return 0;
if (ac >= 'a' && ac <= 'f')
return 1;
if (ac >= 'A' && ac <= 'F')
return 1;
return 0;
}
/* given that this is a digit or a digit-like thing, compute its value */
static int getmeta(ac)
register int ac;
{
if (ac >= '0' && ac <= '9')
return ac - '0';
if (ac >= 'a' && ac <= 'f')
return ac - 'a' + 10;
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;
}
pnum = volutil_GetPartitionID(partition);
if (pnum < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partition);
VSETCODE(ENOENT, buffer);
goto done;
}
if (!IsPartValid(pnum, tserver, &code)) { /*check for validity of the partition */
char buffer[256];
if (code)
set_errbuff(buffer, code);
else
sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
partition);
VSETCODE(code ? code : ENOENT, buffer);
goto done;
}
if (!ISNAMEVALID(name)) {
char buffer[256];
sprintf(buffer,
"AFS::VOS: the name of the root volume %s exceeds the size limit of %d\n",
name, VOLSER_OLDMAXVOLNAME - 10);
VSETCODE(E2BIG, buffer);
goto done;
}
if (!VolNameOK(name)) {
char buffer[256];
sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
name);
VSETCODE(EINVAL, buffer);
goto done;
}
if (IsNumeric(name)) {
char buffer[256];
sprintf(buffer, "Illegal volume name %s, should not be a number\n", name);
VSETCODE(EINVAL, buffer);
goto done;
}
vcode = VLDB_GetEntryByName(name, &entry);
if (!vcode) {
char buffer[256];
sprintf(buffer, "Volume %s already exists\n", name);
#PrintDiagnostics("create", code);
VSETCODE(EEXIST, buffer);
goto done;
}
/* printf("vos-create DEBUG-2 server %d part %d vol %s maxq %d vid %d rovid %d \n", tserver, pnum, name, SvIV(maxquota), SvIV(vid), SvIV(rovid)); */
if ((maxquota) && (!SvIOKp(maxquota))) {
char buffer[256];
sprintf(buffer, "Initial quota should be numeric.\n");
VSETCODE(EINVAL, buffer);
goto done;
}
quota = SvIV(maxquota);
/* printf("vos-create DEBUG-3 quota %d \n", quota); */
#ifdef OpenAFS_1_4_12
if ((vid) && (!SvIOKp(vid))) {
/* printf("vos-create DEBUG-4 vid %d \n", SvIV(vid)); */
char buffer[256];
sprintf(buffer, "Given volume ID should be numeric.\n");
VSETCODE(EINVAL, buffer);
goto done;
}
/* printf("vos-create DEBUG-5 vid %d \n", SvIV(vid)); */
volid = SvIV(vid);
/* printf("vos-create DEBUG-6 volid %d \n", volid); */
if ((rovid) && (!SvIOKp(rovid))) {
/* printf("vos-create DEBUG-7 rovid %d \n", SvIV(rovid)); */
char buffer[256];
sprintf(buffer, "Given RO volume ID should be numeric.\n");
VSETCODE(EINVAL, buffer);
goto done;
}
/* printf("vos-create DEBUG-8 rovid %d \n", SvIV(rovid)); */
arovolid = &rovolid;
rovolid = SvIV(rovid);
/* printf("vos-create DEBUG-9 rovolid %d \n", rovolid); */
if (rovolid == 0) {
arovolid = NULL;
}
code = UV_CreateVolume3(tserver, pnum, name, quota, 0, 0, 0, 0, &volid, arovolid, &bkvolid);
#else
code = UV_CreateVolume2(tserver, pnum, name, quota, 0, 0, 0, 0, &volid);
#endif
if (code) {
#PrintDiagnostics("create", code);
SETCODE(code);
goto done;
}
SETCODE(0);
RETVAL = (int32)volid;
done:
;
}
OUTPUT:
RETVAL
int32
vos_backup(cstruct, name)
AFS::VOS cstruct
char *name
PREINIT:
int32 avolid, aserver, apart, vtype, code, err;
int32 buvolid, buserver, bupart, butype;
struct nvldbentry entry;
struct nvldbentry buentry;
CODE:
{
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 ID or name '%s'\n", name);
VSETCODE(err ? err : ENOENT, buffer);
goto done;
}
code = GetVolumeInfo(avolid, &aserver, &apart, &vtype, &entry);
if (code) {
SETCODE(code);
goto done;
}
/* verify this is a readwrite volume */
if (vtype != RWVOL) {
char buffer[256];
sprintf(buffer, "%s not RW volume\n", name);
VSETCODE(-1, buffer);
goto done;
}
/* is there a backup volume already? */
if (entry.flags & BACK_EXISTS) {
/* yep, where is it? */
buvolid = entry.volumeId[BACKVOL];
code = GetVolumeInfo(buvolid, &buserver, &bupart, &butype, &buentry);
if (code) {
SETCODE(code);
goto done;
}
/* is it local? */
code = VLDB_IsSameAddrs(buserver, aserver, &err);
if (err) {
char buffer[256];
sprintf(buffer,
"Failed to get info about server's %d address(es) from vlserver; aborting call!\n",
buserver);
VSETCODE(err, buffer);
goto done;
}
if (!code) {
char buffer[256];
sprintf(buffer, "FATAL ERROR: backup volume %u exists on server %u\n",
buvolid, buserver);
VSETCODE(-1, buffer);
goto done;
}
}
/* nope, carry on */
code = UV_BackupVolume(aserver, apart, avolid);
if (code) {
PrintDiagnostics("backup", code);
SETCODE(0);
goto done;
}
#fprintf(STDOUT, "Created backup volume for %s \n", name);
SETCODE(0);
RETVAL = 1;
done:
;
}
OUTPUT:
RETVAL
int32
vos_remove(cstruct, name, servername=NULL, parti=NULL)
AFS::VOS cstruct
char *name
char *servername
char *parti
PREINIT:
afs_int32 err, code = 0;
afs_int32 server = 0, partition = -1, volid;
afs_int32 idx, j;
CODE:
{
RETVAL = 0;
if (servername && strlen(servername) != 0) {
server = GetServer(servername);
if (!server) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
VSETCODE(ENOENT, buffer);
goto done;
}
}
if (parti && strlen(parti) != 0) {
partition = volutil_GetPartitionID(parti);
if (partition < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", parti);
VSETCODE(EINVAL, buffer);
goto done;
}
/* Check for validity of the partition */
if (!IsPartValid(partition, server, &code)) {
char buffer[256];
if (code)
set_errbuff(buffer, code);
else
sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
parti);
VSETCODE(ENOENT, buffer);
goto done;
}
}
volid = vsu_GetVolumeID(name, cstruct, &err);
if (volid == 0) {
char buffer[256];
sprintf(buffer, "Can't find volume name '%s' in VLDB\n", name);
if (err)
set_errbuff(buffer, err);
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);
}
else if ((strcmp(overwrite, "f") == 0) || (strcmp(overwrite, "full") == 0)) {
aoverwrite = AFS_FULL;
}
else if ((strcmp(overwrite, "i") == 0) ||
(strcmp(overwrite, "inc") == 0) ||
(strcmp(overwrite, "increment") == 0) ||
(strcmp(overwrite, "incremental") == 0)) {
aoverwrite = AFS_INC;
}
else {
char buffer[256];
sprintf(buffer, "AFS::VOS: %s is not a valid OVERWRITE argument\n",
overwrite);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
}
if ((ireadonly))
voltype = ROVOL;
aserver = GetServer(server);
if (aserver == 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
apart = volutil_GetPartitionID(partition);
if (apart < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partition);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
if (!IsPartValid(apart, aserver, &code)) { /*check for validity of the partition */
char buffer[256];
if (code)
set_errbuff(buffer, code);
else
sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
partition);
VSETCODE(code ? code : -1, buffer);
RETVAL = 0;
goto done;
}
strcpy(avolname, name);
if (!ISNAMEVALID(avolname)) {
char buffer[256];
sprintf(buffer, "AFS::VOS: the name of the volume %s exceeds the size limit\n",
avolname);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
if (!VolNameOK(avolname)) {
char buffer[256];
sprintf(buffer, "Illegal volume name %s, should not end in .readonly or .backup\n",
avolname);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
if (file && strlen(file) != 0) {
strcpy(afilename, file);
if (!FileExists(afilename)) {
char buffer[256];
sprintf(buffer, "Can't access file %s\n", afilename);
VSETCODE(-1, buffer);
RETVAL = 0;
goto done;
}
}
else {
strcpy(afilename, "");
}
/* Check if volume exists or not */
vsu_ExtractName(volname, avolname);
vcode = VLDB_GetEntryByName(volname, &entry);
if (vcode) { /* no volume - do a full restore */
restoreflags = RV_FULLRST;
if ((aoverwrite == AFS_INC) || (aoverwrite == AFS_ABORT)) {
char buffer[256];
sprintf(buffer, "Volume does not exist; Will perform a full restore\n");
VSETCODE(vcode, buffer);
}
}
else if ((!ireadonly && Lp_GetRwIndex(&entry) == -1) /* RW volume does not exist - do a full */
||(ireadonly && !Lp_ROMatch(0, 0, &entry))) { /* RO volume does not exist - do a full */
restoreflags = RV_FULLRST;
if ((aoverwrite == AFS_INC) || (aoverwrite == AFS_ABORT))
fprintf(stderr, "%s Volume does not exist; Will perform a full restore\n",
ireadonly ? "RO" : "RW");
if (avolid == 0) {
avolid = entry.volumeId[voltype];
}
else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
avolid = entry.volumeId[voltype];
}
aparentid = entry.volumeId[RWVOL];
}
else { /* volume exists - do we do a full incremental or abort */
int Oserver, Opart, Otype, vol_elsewhere = 0;
struct nvldbentry Oentry;
int c, dc;
if (avolid == 0) {
avolid = entry.volumeId[voltype];
}
else if (entry.volumeId[voltype] != 0 && entry.volumeId[voltype] != avolid) {
avolid = entry.volumeId[voltype];
}
aparentid = entry.volumeId[RWVOL];
/* A file name was specified - check if volume is on another partition */
MapPartIdIntoName(topart, toPartName);
MapPartIdIntoName(frompart, fromPartName);
/*
check target partition for space to move volume
*/
#ifdef OpenAFS_1_4_64
code = UV_PartitionInfo64(toserver, toPartName, &partition);
#else
code = UV_PartitionInfo(toserver, toPartName, &partition);
#endif
if (code) {
char buffer[256];
sprintf(buffer, "AFS::VOS: cannot access partition %s\n", toPartName);
VSETCODE(code, buffer);
goto done;
}
p = (volintInfo *) 0;
code = UV_ListOneVolume(fromserver, frompart, volid, &p);
if (code) {
char buffer[256];
sprintf(buffer, "AFS::VOS:cannot access volume %u\n", volid);
free(p);
VSETCODE(code, buffer);
goto done;
}
if (partition.free <= p->size) {
char buffer[256];
sprintf(buffer, "AFS::VOS: no space on target partition %s to move volume %u\n",
toPartName, volid);
VSETCODE(-1, buffer);
if (p)
free(p);
goto done;
}
if (p)
free(p);
/* successful move still not guaranteed but shoot for it */
code = UV_MoveVolume(volid, fromserver, frompart, toserver, topart);
if (code) {
PrintDiagnostics("move", code);
SETCODE(code);
goto done;
}
#SETCODE(1); ???
SETCODE(0);
RETVAL = volid;
done:
;
}
OUTPUT:
RETVAL
int32
vos_zap(cstruct, servername, parti, id, force=Nullsv, backup=Nullsv)
AFS::VOS cstruct
char *servername
char *parti
char *id
SV * force
SV * backup
PREINIT:
struct nvldbentry entry;
int32 volid, code, server, part, iforce=0, zapbackupid=0, backupid=0, err;
CODE:
{
if (!force)
force = newSViv(0);
if (!backup)
backup = newSViv(0);
if ((!SvIOKp(force))) {
char buffer[256];
sprintf(buffer, "Flag \"force\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
RETVAL = 0;
goto done;
}
else
iforce = 1; /* -force */
if ((!SvIOKp(backup))) {
char buffer[256];
sprintf(buffer, "Flag \"backup\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
RETVAL = 0;
goto done;
}
else
zapbackupid = 1; /* -backup */
RETVAL = 0;
volid = vsu_GetVolumeID(id, cstruct, &err);
if (volid == 0) {
char buffer[256];
if (err)
set_errbuff(buffer, err);
else
sprintf(buffer, "AFS::VOS: can't find volume '%s'\n", id);
VSETCODE(err ? err : -1, buffer);
goto done;
}
part = volutil_GetPartitionID(parti);
if (part < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", parti);
VSETCODE(-1, buffer);
goto done;
}
server = GetServer(servername);
if (!server) {
char buffer[256];
sprintf(buffer, "AFS::VOS: host '%s' not found in host table\n", servername);
VSETCODE(-1, buffer);
goto done;
}
if (iforce) { /* -force */
code = UV_NukeVolume(server, part, volid);
if (code) {
PrintDiagnostics("zap", code);
SETCODE(code);
goto done;
}
SETCODE(0);
RETVAL = volid;
goto done;
}
if (!IsPartValid(part, server, &code)) { /*check for validity of the partition */
char buffer[256];
if (code)
set_errbuff(buffer, code);
else
sprintf(buffer, "AFS::VOS: partition %s does not exist on the server\n",
servername);
VSETCODE(code ? code : -1, buffer);
goto done;
}
code = VLDB_GetEntryByID(volid, -1, &entry);
if (!code) {
if (volid == entry.volumeId[RWVOL])
backupid = entry.volumeId[BACKVOL];
#fprintf(stderr,
# "Warning: Entry for volume number %u exists in VLDB (but we're zapping it anyway!)\n",
# volid);
}
if (zapbackupid) {
volintInfo *pntr = (volintInfo *) 0;
if (!backupid) {
code = UV_ListOneVolume(server, part, volid, &pntr);
if (!code) {
if (volid == pntr->parentID)
backupid = pntr->backupID;
if (pntr)
free(pntr);
}
}
if (backupid) {
code = UV_VolumeZap(server, part, backupid);
if (code) {
PrintDiagnostics("zap", code);
SETCODE(code);
goto done;
}
fprintf(STDOUT, "Backup Volume %u deleted\n", backupid);
}
}
code = UV_VolumeZap(server, part, volid);
if (code) {
PrintDiagnostics("zap", code);
SETCODE(code);
goto done;
}
#fprintf(STDOUT, "Volume %u deleted\n", volid);
SETCODE(0);
RETVAL = volid;
done:
;
}
OUTPUT:
RETVAL
int32
vos_offline(cstruct, servername, parti, id, busy=Nullsv, sleep=Nullsv)
AFS::VOS cstruct
char* servername
char* parti
char *id
SV * busy
SV * sleep
PREINIT:
int32 server, partition, volid;
int32 code, err=0;
int32 ibusy=0, isleep=0, transflag, transdone;
CODE:
{
if (!busy)
busy = newSViv(0);
if (!sleep)
sleep = newSViv(0);
if ((!SvIOKp(busy))) {
char buffer[256];
sprintf(buffer, "Flag \"busy\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
RETVAL = 0;
goto done;
}
else
ibusy = SvIV(busy); /* -busy */
if ((!SvIOKp(sleep))) {
char buffer[256];
sprintf(buffer, "Flag \"sleep\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
RETVAL = 0;
goto done;
}
else
isleep = SvIV(sleep); /* -sleep */
RETVAL = 0;
server = GetServer(servername);
if (server == 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
VSETCODE(-1, buffer);
}
OUTPUT:
RETVAL
int32
vos_online(cstruct, servername, parti, id)
AFS::VOS cstruct
char* servername
char* parti
char *id
PREINIT:
int32 server, partition, volid;
int32 code, err=0;
CODE:
{
RETVAL = 0;
server = GetServer(servername);
if (server == 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
VSETCODE(-1, buffer);
goto done;
}
partition = volutil_GetPartitionID(parti);
if (partition < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", parti);
VSETCODE(ENOENT, buffer);
goto done;
}
volid = vsu_GetVolumeID(id, cstruct, &err); /* -id */
if (!volid) {
char buffer[256];
if (err)
set_errbuff(buffer, err);
else
sprintf(buffer, "Unknown volume ID or name '%s'\n", servername);
VSETCODE(err ? err : -1, buffer);
goto done;
}
code = UV_SetVolume(server, partition, volid, ITOffline, 0 /*online */ , 0 /*sleep */ );
if (code) {
char buffer[256];
sprintf(buffer, "Failed to set volume. Code = %d\n", code);
VSETCODE(code, buffer);
goto done;
}
SETCODE(0);
RETVAL = 1;
done:
;
}
OUTPUT:
RETVAL
void
vos__backupsys(cstruct, seenprefix=Nullsv, servername=NULL, partition=NULL, exclude=Nullsv, seenxprefix=Nullsv, noaction=Nullsv)
AFS::VOS cstruct
SV * seenprefix
char *servername
char *partition
SV * exclude
SV * seenxprefix
SV * noaction
PREINIT:
int32 apart=0, avolid;
int32 aserver=0, code, aserver1, apart1;
int32 vcode, iexclude=0, inoaction=0;
struct VldbListByAttributes attributes;
nbulkentries arrayEntries;
register struct nvldbentry *vllist;
int32 nentries;
int j, i, len, verbose = 1;
afs_int32 totalBack=0;
afs_int32 totalFail=0;
int previdx=-1, error, same;
char *ccode, *itp;
int match = 0;
STRLEN prfxlength=0;
SV *regex;
AV *av;
AV *av1 = (AV*)sv_2mortal((SV*)newAV());
AV *av2 = (AV*)sv_2mortal((SV*)newAV());
PPCODE:
{
/* printf("vos-backupsys DEBUG-1 server %s part %s exclude %d noaction %d \n", servername, partition, (int)SvIV(exclude), (int)SvIV(noaction)); */
if (!exclude)
exclude = newSViv(0);
if (!noaction)
noaction = newSViv(0);
if ((!SvIOKp(exclude))) {
char buffer[256];
sprintf(buffer, "Flag \"exclude\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
XSRETURN_UNDEF;
}
else
iexclude = SvIV(exclude); /* -exclude */
/* printf("vos-backupsys DEBUG-2: iexclude = %d \n", iexclude); */
if ((!SvIOKp(noaction))) {
char buffer[256];
sprintf(buffer, "Flag \"noaction\" should be numeric.\n");
VSETCODE(EINVAL, buffer);
XSRETURN_UNDEF;
}
else
inoaction = SvIV(noaction); /* -noaction */
Zero(&attributes, 1, VldbListByAttributes);
attributes.Mask = 0;
/* printf("vos-backupsys DEBUG-3\n"); */
if (servername && (strlen(servername) != 0)) { /* -server */
/* printf("vos-backupsys DEBUG-4\n"); */
aserver = GetServer(servername);
if (aserver == 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", servername);
VSETCODE(-1, buffer);
XSRETURN_UNDEF;
}
attributes.server = ntohl(aserver);
attributes.Mask |= VLLIST_SERVER;
}
else {
servername = NULL;
}
/* printf("vos-backupsys DEBUG-5\n"); */
if (partition && (strlen(partition) != 0)) { /* -partition */
/* printf("vos-backupsys DEBUG-6\n"); */
apart = volutil_GetPartitionID(partition);
if (apart < 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: could not interpret partition name '%s'\n", partition);
VSETCODE(-1, buffer);
XSRETURN_UNDEF;
}
attributes.partition = apart;
attributes.Mask |= VLLIST_PARTITION;
}
else {
partition = NULL;
}
/* printf("vos-backupsys DEBUG-7\n"); */
/* Check to make sure the prefix and xprefix expressions compile ok */
if (seenprefix && (prfxlength = sv_len(seenprefix)) == 0)
seenprefix = NULL;
/* printf("vos-backupsys DEBUG-7-1 PrfxLen %d\n", prfxlength); */
if (seenprefix && (! (SvTYPE(SvRV(seenprefix)) == SVt_PVAV))) {
VSETCODE(-1, "AFS::VOS: PREFIX not an array reference");
XSRETURN_UNDEF;
}
if (seenprefix) {
av = (AV *) SvRV(seenprefix);
len = av_len(av);
/* printf("vos-backupsys DEBUG-7-2 Len %d\n", len); */
if (len != -1) {
for (j = 0; j <= len; j++) {
regex = *av_fetch(av, j, 0);
itp = SvPV_nolen(regex);
if (strncmp(itp, "^", 1) == 0) {
ccode = (char *) re_comp(itp);
if (ccode) {
char buffer[256];
sprintf(buffer,
"Unrecognizable PREFIX regular expression: '%s': %s\n", itp,
ccode);
VSETCODE(ccode, buffer);
XSRETURN_UNDEF;
}
}
} /*for loop */
/* printf("vos-backupsys DEBUG-8 RE %s \n", itp); */
}
}
/* printf("vos-backupsys DEBUG-9\n"); */
if (seenxprefix && (prfxlength = sv_len(seenxprefix)) == 0)
seenxprefix = NULL;
/* printf("vos-backupsys DEBUG-10\n"); */
if (seenxprefix && (! (SvTYPE(SvRV(seenxprefix)) == SVt_PVAV))) {
VSETCODE(-1, "AFS::VOS: XPREFIX not an array reference");
XSRETURN_UNDEF;
}
if (seenxprefix) {
/* printf("vos-backupsys DEBUG-11\n"); */
av = (AV *) SvRV(seenxprefix);
len = av_len(av);
if (len != -1) {
for (j = 0; j <= len; j++) {
regex = *av_fetch(av, j, 0);
itp = SvPV_nolen(regex);
if (strncmp(itp, "^", 1) == 0) {
ccode = (char *) re_comp(itp);
if (ccode) {
char buffer[256];
sprintf(buffer,
"Unrecognizable XPREFIX regular expression: '%s': %s\n", itp,
ccode);
VSETCODE(ccode, buffer);
XSRETURN_UNDEF;
}
}
} /*for */
}
}
/* printf("vos-backupsys DEBUG-12\n"); */
Zero(&arrayEntries, 1, nbulkentries); /* initialize to hint the stub to alloc space */
vcode = VLDB_ListAttributes(&attributes, &nentries, &arrayEntries);
if (vcode) {
VSETCODE(vcode, "Could not access the VLDB for attributes");
XSRETURN_UNDEF;
}
/* a bunch of output generation code deleted. A.W. */
/* printf("vos-backupsys DEBUG-13\n"); */
for (j = 0; j < nentries; j++) { /* process each vldb entry */
vllist = &arrayEntries.nbulkentries_val[j];
/* printf("vos-backupsys DEBUG-13-1 Name %s\n", vllist->name); */
if (seenprefix) {
av = (AV *) SvRV(seenprefix);
len = av_len(av);
/* printf("vos-backupsys DEBUG-14 Len %d\n", len); */
for (i = 0; i <= len; i++) {
regex = *av_fetch(av, i, 0);
itp = SvPV_nolen(regex);
/* printf("vos-backupsys DEBUG-14-1 RE %s \n", itp); */
if (strncmp(itp, "^", 1) == 0) {
ccode = (char *) re_comp(itp);
if (ccode) {
char buffer[256];
sprintf(buffer, "Error in PREFIX regular expression: '%s': %s\n",
itp, ccode);
VSETCODE(ccode, buffer);
XSRETURN_UNDEF;
}
match = (re_exec(vllist->name) == 1);
}
else {
match = (strncmp(vllist->name, itp, strlen(itp)) == 0);
}
if (match)
break;
}
}
else {
match = 1;
/* printf("vos-backupsys DEBUG-15 MATCH %d\n", match); */
}
/* Without the -exclude flag: If it matches the prefix, then
* check if we want to exclude any from xprefix.
* With the -exclude flag: If it matches the prefix, then
* check if we want to add any from xprefix.
*/
if (match && seenxprefix) {
av = (AV *) SvRV(seenxprefix);
len = av_len(av);
for (i = 0; i <= len; i++) {
regex = *av_fetch(av, i, 0);
itp = SvPV_nolen(regex);
if (strncmp(itp, "^", 1) == 0) {
ccode = (char *) re_comp(itp);
if (ccode) {
char buffer[256];
sprintf(buffer, "Error in PREFIX regular expression: '%s': %s\n",
itp, ccode);
VSETCODE(ccode, buffer);
XSRETURN_UNDEF;
}
if (re_exec(vllist->name) == 1) {
match = 0;
break;
}
}
else {
if (strncmp(vllist->name, itp, strlen(itp)) == 0) {
match = 0;
break;
}
}
}
}
/* printf("vos-backupsys DEBUG-16-1: exclude %d match %d\n", iexclude, match); */
if (iexclude)
match = !match; /* -exclude will reverse the match */
if (!match)
continue; /* Skip if no match */
/* printf("vos-backupsys DEBUG-16-2: noaction %d match %d\n", inoaction, match); */
/* Print list of volumes to backup */
if (inoaction) {
av_push(av1, newSVpv(vllist->name, strlen(vllist->name)));
continue;
}
/* printf("vos-backupsys DEBUG-17\n"); */
if (!(vllist->flags & RW_EXISTS)) {
if (verbose) {
fprintf(STDOUT, "Omitting to backup %s since RW volume does not exist \n",
vllist->name);
fprintf(STDOUT, "\n");
}
fflush(STDOUT);
continue;
}
/* printf("vos-backupsys DEBUG-18\n"); */
avolid = vllist->volumeId[RWVOL];
MapHostToNetwork(vllist);
GetServerAndPart(vllist, RWVOL, &aserver1, &apart1, &previdx);
if (aserver1 == -1 || apart1 == -1) {
av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
fprintf(STDOUT, "could not backup %s, invalid VLDB entry\n", vllist->name);
totalFail++;
continue;
}
/* printf("vos-backupsys DEBUG-19\n"); */
if (aserver) {
same = VLDB_IsSameAddrs(aserver, aserver1, &error);
if (error) {
av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
fprintf(stderr,
"Failed to get info about server's %d address(es) from vlserver (err=%d); aborting call!\n",
aserver, error);
totalFail++;
continue;
}
}
/* printf("vos-backupsys DEBUG-20\n"); */
if ((aserver && !same) || (apart && (apart != apart1))) {
if (verbose) {
fprintf(STDOUT,
"Omitting to backup %s since the RW is in a different location\n",
vllist->name);
}
continue;
}
if (verbose) {
time_t now = time(0);
fprintf(STDOUT, "Creating backup volume for %s on %s", vllist->name, ctime(&now));
fflush(STDOUT);
}
/* printf("vos-backupsys DEBUG-21\n"); */
code = UV_BackupVolume(aserver1, apart1, avolid);
if (code) {
av_push(av2, newSVpv(vllist->name, strlen(vllist->name)));
fprintf(STDOUT, "Could not backup %s\n", vllist->name);
totalFail++;
}
else {
av_push(av1, newSVpv(vllist->name, strlen(vllist->name)));
totalBack++;
}
} /* process each vldb entry */
/* printf("vos-backupsys DEBUG-22: Succ %d Fail %d\n", totalBack, totalFail); */
if (arrayEntries.nbulkentries_val)
free(arrayEntries.nbulkentries_val);
SETCODE(0);
XPUSHs(sv_2mortal(newRV_inc((SV *) (av1))));
XPUSHs(sv_2mortal(newRV_inc((SV *) (av2))));
XSRETURN(2);
}
void
vos_listpart(cstruct, server)
AFS::VOS cstruct
char *server
PREINIT:
int32 aserver, code;
struct partList dummyPartList;
int i, total, cnt;
char pname[10];
PPCODE:
{
aserver = GetServer(server);
if (aserver == 0) {
char buffer[256];
sprintf(buffer, "AFS::VOS: server '%s' not found in host table\n", server);
VSETCODE(-1, buffer);
XSRETURN_UNDEF;
}
code = UV_ListPartitions(aserver, &dummyPartList, &cnt);
if (code) {
PrintDiagnostics("listpart", code);
XSRETURN_UNDEF;
}
total = 0;
for (i = 0; i < cnt; i++) {
if (dummyPartList.partFlags[i] & PARTVALID) {
Zero(pname, 10, char);
MapPartIdIntoName(dummyPartList.partId[i], pname);
XPUSHs(sv_2mortal(newSVpv(pname, strlen(pname))));
total++;
}
}
SETCODE(0);
XSRETURN(total);
}
void
vos_listvolume(cstruct, name)
AFS::VOS cstruct
char *name
PREINIT:
struct nvldbentry entry;
afs_int32 vcode = 0;
volintInfo *pntr = (volintInfo *)0;
afs_int32 volid;
afs_int32 code, err;
int voltype, foundserv = 0, foundentry = 0;
afs_int32 aserver, apart;
char apartName[10];
int previdx = -1;
HV *volinfo = (HV*)sv_2mortal((SV*)newHV());
PPCODE:
{
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);
XSRETURN_UNDEF;
}
vcode = VLDB_GetEntryByID(volid, -1, &entry);
if (vcode) {
char buffer[256];
sprintf(buffer, "Could not fetch the entry for volume number %u from VLDB \n", volid);
VSETCODE(vcode, buffer);
XSRETURN_UNDEF;
}
MapHostToNetwork(&entry);
if (entry.volumeId[RWVOL] == volid)
voltype = RWVOL;
else if (entry.volumeId[BACKVOL] == volid)
voltype = BACKVOL;
else /* (entry.volumeId[ROVOL] == volid) */
voltype = ROVOL;
do { /* do {...} while (voltype == ROVOL) */
/* Get the entry for the volume. If its a RW vol, get the RW entry.
* It its a BK vol, get the RW entry (even if VLDB may say the BK doen't exist).
* If its a RO vol, get the next RO entry.
*/
GetServerAndPart(&entry, ((voltype == ROVOL) ? ROVOL : RWVOL), &aserver, &apart,
&previdx);
if (previdx == -1) { /* searched all entries */
if (!foundentry) {
char buffer[256];
sprintf(buffer, "Volume %s does not exist in VLDB\n\n", name);
VSETCODE(ENOENT, buffer);
XSRETURN_UNDEF;
}
break;
}
foundentry = 1;
/* Get information about the volume from the server */
code = UV_ListOneVolume(aserver, apart, volid, &pntr);
if (code) {
char buffer[256];
if (code == ENODEV) {
if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
/* The VLDB says there is no backup volume and its not on disk */
sprintf(buffer, "Volume %s does not exist\n", name);
}
else {
sprintf(buffer,
"Volume does not exist on server %s as indicated by the VLDB\n",
hostutil_GetNameByINet(aserver));
}
}
else {
sprintf(buffer, "examine");
}
if (pntr)
free(pntr);
VSETCODE(code, buffer);
XSRETURN_UNDEF;
}
else {
foundserv = 1;
MapPartIdIntoName(apart, apartName);
/* safe_hv_store(volinfo, "name", 4, newSVpv(name, strlen((char *) name)), 0); */
safe_hv_store(volinfo, "partition", 9, newSVpv(apartName, strlen((char *) apartName)), 0);
VolumeStats(volinfo, pntr, &entry, aserver, apart, voltype);
if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
/* The VLDB says there is no backup volume yet we found one on disk */
char buffer[256];
sprintf(buffer, "Volume %s does not exist in VLDB\n", name);
if (pntr)
free(pntr);
VSETCODE(ENOENT, buffer);
XSRETURN_UNDEF;
}
}
if (pntr)
free(pntr);
} while (voltype == ROVOL);
SETCODE(0);
ST(0) = sv_2mortal(newRV_inc((SV *) volinfo));
XSRETURN(1);
}
MODULE = AFS PACKAGE = AFS::VLDB PREFIX = vldb_
AFS::VLDB
vldb_new(class=0, verb=0, timeout=90, noauth=0, localauth=0, tcell=NULL, crypt=0)
char * class
int verb
int timeout
int noauth
int localauth
char * tcell
int crypt
PREINIT:
int32 code = -1;
extern int verbose;
PPCODE:
{
if (tcell && (tcell[0] == '\0' || tcell[0] == '0'))
tcell = NULL;
/* Initialize the ubik_client connection */
rx_SetRxDeadTime(timeout); /* timeout seconds inactivity before declared dead */
cstruct = (struct ubik_client *) 0;
verbose = verb;
if (crypt) /* -crypt specified */
vsu_SetCrypt(1);
code = internal_vsu_ClientInit((noauth != 0),
AFSDIR_CLIENT_ETC_DIRPATH, tcell, localauth,
&cstruct, UV_SetSecurity);
if (code == 0) {
ST(0) = sv_newmortal();
sv_setref_pv(ST(0), "AFS::VLDB", (void *) cstruct);
XSRETURN(1);
}
else
XSRETURN_UNDEF;
}
int32
vldb__DESTROY(self)
AFS::VLDB self
PREINIT:
( run in 1.313 second using v1.01-cache-2.11-cpan-39bf76dae61 )