From: Andrew Deason Date: Fri, 21 May 2010 20:54:33 +0000 (-0500) Subject: vlserver: Access cache via vl_ctx X-Git-Tag: openafs-devel-1_7_1~1650 X-Git-Url: https://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=1f532d099b8b084d43dd0140890448464325b602 vlserver: Access cache via vl_ctx The vlserver application-level ubik cache (which consists of HostAddress, ex_addr, and cheader) is currently being accessed via global variables everywhere. Instead, access these via the new vl_ctx struct that is passed to functions during a transaction, so we have the ability to modify the cache without making all changes visible as we change it. Change-Id: I24bd5495539057d169aef4b5b0b6850b77172cab Reviewed-on: http://gerrit.openafs.org/2105 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/vlserver/vlprocs.c b/src/vlserver/vlprocs.c index 7029a2a..b42b821 100644 --- a/src/vlserver/vlprocs.c +++ b/src/vlserver/vlprocs.c @@ -41,10 +41,7 @@ extern int smallMem; extern int extent_mod; extern struct afsconf_dir *vldb_confdir; extern struct ubik_dbase *VL_dbase; -struct vlheader cheader; /* kept in network byte order */ -extern afs_uint32 HostAddress[]; /* host addresses kept in host byte order */ int maxnservers; -struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 }; #define ABORT(c) { errorcode = (c); goto abort; } #undef END #define END(c) { errorcode = (c); goto end; } @@ -52,10 +49,12 @@ struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 }; #define VLDBALLOCLIMIT 10000 #define VLDBALLOCINCR 2048 -static int put_attributeentry(struct vldbentry **, struct vldbentry **, +static int put_attributeentry(struct vl_ctx *ctx, + struct vldbentry **, struct vldbentry **, struct vldbentry **, bulkentries *, struct nvlentry *, afs_int32 *, afs_int32 *); -static int put_nattributeentry(struct nvldbentry **, struct nvldbentry **, +static int put_nattributeentry(struct vl_ctx *ctx, + struct nvldbentry **, struct nvldbentry **, struct nvldbentry **, nbulkentries *, struct nvlentry *, afs_int32, afs_int32, afs_int32 *, afs_int32 *); @@ -75,11 +74,14 @@ static int get_vldbupdateentry(struct vl_ctx *ctx, afs_int32 blockindex, struct nvlentry *VlEntry); static int repsite_exists(struct nvlentry *VlEntry, int server, int partition); static void repsite_compress(struct nvlentry *VlEntry, int offset); -static void vlentry_to_vldbentry(struct nvlentry *VlEntry, +static void vlentry_to_vldbentry(struct vl_ctx *ctx, + struct nvlentry *VlEntry, struct vldbentry *VldbEntry); -static void vlentry_to_nvldbentry(struct nvlentry *VlEntry, +static void vlentry_to_nvldbentry(struct vl_ctx *ctx, + struct nvlentry *VlEntry, struct nvldbentry *VldbEntry); -static void vlentry_to_uvldbentry(struct nvlentry *VlEntry, +static void vlentry_to_uvldbentry(struct vl_ctx *ctx, + struct nvlentry *VlEntry, struct uvldbentry *VldbEntry); static int InvalidVolname(char *volname); static int InvalidVoltype(afs_int32 voltype); @@ -169,6 +171,9 @@ Init_VLdbase(struct vl_ctx *ctx, } } } + if (errorcode == 0) { + errorcode = vlsetcache(ctx, locktype); + } return errorcode; } @@ -440,11 +445,11 @@ GetEntryByID(struct rx_call *rxcall, } /* Convert from the internal to external form */ if (new == 1) - vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry); + vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry); else if (new == 2) - vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry); + vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry); else - vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry); + vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry); return (ubik_EndTrans(ctx.trans)); } @@ -530,11 +535,11 @@ GetEntryByName(struct rx_call *rxcall, } /* Convert to external entry representation */ if (new == 1) - vlentry_to_nvldbentry(&tentry, (struct nvldbentry *)aentry); + vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry); else if (new == 2) - vlentry_to_uvldbentry(&tentry, (struct uvldbentry *)aentry); + vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry); else - vlentry_to_vldbentry(&tentry, (struct vldbentry *)aentry); + vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry); return (ubik_EndTrans(ctx.trans)); } @@ -589,14 +594,14 @@ SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump, goto end; *newvolumeid = maxvolumeid = NextUnusedID(&ctx, - ntohl(cheader.vital_header.MaxVolumeId), Maxvolidbump, &errorcode); + ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &errorcode); if (errorcode) { goto abort; } maxvolumeid += Maxvolidbump; VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall))); - cheader.vital_header.MaxVolumeId = htonl(maxvolumeid); + ctx.cheader->vital_header.MaxVolumeId = htonl(maxvolumeid); if (write_vital_vlheader(&ctx)) { ABORT(VL_IO); } @@ -1085,7 +1090,7 @@ SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index, rxinfo(rxstr, rxcall))); *next_index = NextEntry(&ctx, previous_index, &tentry, count); if (*next_index) - vlentry_to_vldbentry(&tentry, aentry); + vlentry_to_vldbentry(&ctx, &tentry, aentry); return (ubik_EndTrans(ctx.trans)); } @@ -1109,7 +1114,7 @@ SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index, VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall))); *next_index = NextEntry(&ctx, previous_index, &tentry, count); if (*next_index) - vlentry_to_nvldbentry(&tentry, aentry); + vlentry_to_nvldbentry(&ctx, &tentry, aentry); return (ubik_EndTrans(ctx.trans)); } @@ -1166,7 +1171,7 @@ SVL_ListAttributes(struct rx_call *rxcall, return errorcode; } if ((errorcode = - put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, + put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, nentries, &allocCount))) { COUNT_ABO; ubik_AbortTrans(ctx.trans); @@ -1227,7 +1232,7 @@ SVL_ListAttributes(struct rx_call *rxcall, continue; } if ((errorcode = - put_attributeentry(&Vldbentry, &VldbentryFirst, + put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, nentries, &allocCount))) { COUNT_ABO; @@ -1305,7 +1310,7 @@ SVL_ListAttributesN(struct rx_call *rxcall, return errorcode; } if ((errorcode = - put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast, + put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, 0, 0, nentries, &allocCount))) { COUNT_ABO; @@ -1368,7 +1373,7 @@ SVL_ListAttributesN(struct rx_call *rxcall, continue; } if ((errorcode = - put_nattributeentry(&Vldbentry, &VldbentryFirst, + put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, 0, 0, nentries, &allocCount))) { COUNT_ABO; @@ -1461,7 +1466,7 @@ SVL_ListAttributesN2(struct rx_call *rxcall, errorcode = VL_NOENT; } else { errorcode = - put_nattributeentry(&Vldbentry, &VldbentryFirst, + put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, 0, 0, nentries, &maxCount); if (errorcode) @@ -1632,7 +1637,7 @@ SVL_ListAttributesN2(struct rx_call *rxcall, /* Passed all the tests. Take it */ if (match) { errorcode = - put_nattributeentry(&Vldbentry, &VldbentryFirst, + put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast, vldbentries, &tentry, matchtype, matchindex, nentries, &maxCount); @@ -1715,7 +1720,7 @@ SVL_LinkedList(struct rx_call *rxcall, ubik_AbortTrans(ctx.trans); return VL_NOMEM; } - vlentry_to_vldbentry(&tentry, &vllist->VldbEntry); + vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; *vllistptr = vllist; /* Thread onto list */ @@ -1786,7 +1791,7 @@ SVL_LinkedList(struct rx_call *rxcall, ubik_AbortTrans(ctx.trans); return VL_NOMEM; } - vlentry_to_vldbentry(&tentry, &vllist->VldbEntry); + vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; *vllistptr = vllist; /* Thread onto list */ @@ -1842,7 +1847,7 @@ SVL_LinkedListN(struct rx_call *rxcall, ubik_AbortTrans(ctx.trans); return VL_NOMEM; } - vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry); + vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; *vllistptr = vllist; /* Thread onto list */ @@ -1913,7 +1918,7 @@ SVL_LinkedListN(struct rx_call *rxcall, ubik_AbortTrans(ctx.trans); return VL_NOMEM; } - vlentry_to_nvldbentry(&tentry, &vllist->VldbEntry); + vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry); vllist->next_vldb = NULL; *vllistptr = vllist; /* Thread onto list */ @@ -1952,7 +1957,7 @@ SVL_GetStats(struct rx_call *rxcall, if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op))) return errorcode; VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall))); - memcpy((char *)vital_header, (char *)&cheader.vital_header, + memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header, sizeof(vital_vlheader)); memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats)); return (ubik_EndTrans(ctx.trans)); @@ -1995,7 +2000,7 @@ SVL_GetAddrs(struct rx_call *rxcall, } for (i = 0; i <= MAXSERVERID; i++) { - if ((*taddrp = ntohl(cheader.IpMappedAddr[i]))) { + if ((*taddrp = ntohl(ctx.cheader->IpMappedAddr[i]))) { taddrp++; nservers++; } @@ -2061,10 +2066,10 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) { willChangeEntry = 0; WillReplaceEntry = 1; - if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) { + if ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) { /* The server is registered as a multihomed */ - base = (HostAddress[srvidx] >> 16) & 0xff; - index = HostAddress[srvidx] & 0x0000ffff; + base = (ctx.hostaddress[srvidx] >> 16) & 0xff; + index = ctx.hostaddress[srvidx] & 0x0000ffff; if (base >= VL_MAX_ADDREXTBLKS) { VLog(0, ("Internal error: Multihome extent base is too large. Base %d index %d\n", @@ -2077,7 +2082,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, base, index)); continue; } - if (!ex_addr[base]) { + if (!ctx.ex_addr[base]) { VLog(0, ("Internal error: Multihome extent does not exist. Base %d\n", base)); @@ -2085,7 +2090,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, } /* See if the addresses to register will change this server entry */ - exp = &ex_addr[base][index]; + exp = &ctx.ex_addr[base][index]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); if (afs_uuid_equal(uuidp, &tuuid)) { @@ -2111,7 +2116,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, * See if the addresses to register will replace this server entry. */ for (k = 0; k < cnt; k++) { - if (HostAddress[srvidx] == addrs[k]) { + if (ctx.hostaddress[srvidx] == addrs[k]) { willChangeEntry = 1; WillChange[count] = srvidx; WillReplaceEntry = 1; @@ -2150,9 +2155,9 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, VLog(0, (" It would have replaced the existing VLDB server entry:\n")); VLog(0, (" entry %d: [", FoundUuid)); - base = (HostAddress[FoundUuid] >> 16) & 0xff; - index = HostAddress[FoundUuid] & 0x0000ffff; - exp = &ex_addr[base][index]; + base = (ctx.hostaddress[FoundUuid] >> 16) & 0xff; + index = ctx.hostaddress[FoundUuid] & 0x0000ffff; + exp = &ctx.ex_addr[base][index]; for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { if (!exp->ex_addrs[mhidx]) continue; @@ -2170,11 +2175,11 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, for (j = 0; j < count; j++) { srvidx = WillChange[j]; VLog(0, (" entry %d: ", srvidx)); - if ((HostAddress[srvidx] & 0xff000000) == 0xff000000) { + if ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) { VLog(0, ("[")); - base = (HostAddress[srvidx] >> 16) & 0xff; - index = HostAddress[srvidx] & 0x0000ffff; - exp = &ex_addr[base][index]; + base = (ctx.hostaddress[srvidx] >> 16) & 0xff; + index = ctx.hostaddress[srvidx] & 0x0000ffff; + exp = &ctx.ex_addr[base][index]; for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { if (!exp->ex_addrs[mhidx]) continue; @@ -2184,7 +2189,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, } VLog(0, ("]")); } else { - PADDR(HostAddress[srvidx]); + PADDR(ctx.hostaddress[srvidx]); } VLog(0, ("\n")); } @@ -2210,9 +2215,9 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, /* Found the entry with same uuid. See if we need to change it */ int change = 0; - fbase = (HostAddress[FoundUuid] >> 16) & 0xff; - index = HostAddress[FoundUuid] & 0x0000ffff; - exp = &ex_addr[fbase][index]; + fbase = (ctx.hostaddress[FoundUuid] >> 16) & 0xff; + index = ctx.hostaddress[FoundUuid] & 0x0000ffff; + exp = &ctx.ex_addr[fbase][index]; /* Determine if the entry has changed */ for (k = 0; ((k < cnt) && !change); k++) { @@ -2259,10 +2264,10 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, } /* Have an entry that needs to be replaced */ - if ((HostAddress[ReplaceEntry] & 0xff000000) == 0xff000000) { - fbase = (HostAddress[ReplaceEntry] >> 16) & 0xff; - index = HostAddress[ReplaceEntry] & 0x0000ffff; - exp = &ex_addr[fbase][index]; + if ((ctx.hostaddress[ReplaceEntry] & 0xff000000) == 0xff000000) { + fbase = (ctx.hostaddress[ReplaceEntry] >> 16) & 0xff; + index = ctx.hostaddress[ReplaceEntry] & 0x0000ffff; + exp = &ctx.ex_addr[fbase][index]; VLog(0, (" It will replace the following existing entry in the VLDB (new uuid):\n")); @@ -2277,10 +2282,10 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, VLog(0, ("]\n")); } else { /* Not a mh entry. So we have to create a new mh entry and - * put it on the ReplaceEntry slot of the HostAddress array. + * put it on the ReplaceEntry slot of the ctx.hostaddress array. */ VLog(0, (" It will replace existing entry %d, ", ReplaceEntry)); - PADDR(HostAddress[ReplaceEntry]); + PADDR(ctx.hostaddress[ReplaceEntry]); VLog(0,(", in the VLDB (new uuid):\n")); code = @@ -2292,7 +2297,7 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, } } else { /* There is no entry for this server, must create a new mh entry as - * well as use a new slot of the HostAddress array. + * well as use a new slot of the ctx.hostaddress array. */ VLog(0, (" It will create a new entry in the VLDB.\n")); code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &fbase); @@ -2319,8 +2324,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, /* Write the new mh entry out */ if (vlwrite (ctx.trans, - DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[fbase]), - (char *)ex_addr[fbase], (char *)exp), (char *)exp, + DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[fbase]), + (char *)ctx.ex_addr[fbase], (char *)exp), (char *)exp, sizeof(*exp))) { ubik_AbortTrans(ctx.trans); return VL_IO; @@ -2337,9 +2342,9 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, if (willReplaceCnt && (WillChange[i] == ReplaceEntry)) continue; - base = (HostAddress[WillChange[i]] >> 16) & 0xff; - index = HostAddress[WillChange[i]] & 0x0000ffff; - tex = &ex_addr[fbase][index]; + base = (ctx.hostaddress[WillChange[i]] >> 16) & 0xff; + index = ctx.hostaddress[WillChange[i]] & 0x0000ffff; + tex = &ctx.ex_addr[fbase][index]; if (++m == 1) VLog(0, @@ -2371,8 +2376,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1, /* Write out the modified mh entry */ tex->ex_uniquifier = htonl(ntohl(tex->ex_uniquifier) + 1); doff = - DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)tex); + DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]), + (char *)ctx.ex_addr[base], (char *)tex); if (vlwrite(ctx.trans, doff, (char *)tex, sizeof(*tex))) { ubik_AbortTrans(ctx.trans); return VL_IO; @@ -2411,10 +2416,10 @@ SVL_GetAddrsU(struct rx_call *rxcall, return VL_BADMASK; } for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) { - if (!ex_addr[base]) + if (!ctx.ex_addr[base]) break; for (i = 1; i < VL_MHSRV_PERBLK; i++) { - exp = &ex_addr[base][i]; + exp = &ctx.ex_addr[base][i]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); if (afs_uuid_is_nil(&tuuid)) @@ -2451,17 +2456,17 @@ SVL_GetAddrsU(struct rx_call *rxcall, ubik_AbortTrans(ctx.trans); return VL_NOENT; } - if (!ex_addr[base]) { + if (!ctx.ex_addr[base]) { ubik_AbortTrans(ctx.trans); return VL_INDEXERANGE; } - exp = &ex_addr[base][offset]; + exp = &ctx.ex_addr[base][offset]; } else if (attributes->Mask & VLADDR_UUID) { if (attributes->Mask & (VLADDR_IPADDR | VLADDR_INDEX)) { ubik_AbortTrans(ctx.trans); return VL_BADMASK; } - if (!ex_addr[0]) { /* mh servers probably aren't setup on this vldb */ + if (!ctx.ex_addr[0]) { /* mh servers probably aren't setup on this vldb */ ubik_AbortTrans(ctx.trans); return VL_NOENT; } @@ -2520,7 +2525,8 @@ SVL_GetAddrsU(struct rx_call *rxcall, /* Routine that copies the given vldb entry to the output buffer, vldbentries. */ static int -put_attributeentry(struct vldbentry **Vldbentry, +put_attributeentry(struct vl_ctx *ctx, + struct vldbentry **Vldbentry, struct vldbentry **VldbentryFirst, struct vldbentry **VldbentryLast, bulkentries *vldbentries, @@ -2551,7 +2557,7 @@ put_attributeentry(struct vldbentry **Vldbentry, *VldbentryLast = *Vldbentry + allo; *alloccnt += allo; } - vlentry_to_vldbentry(entry, *Vldbentry); + vlentry_to_vldbentry(ctx, entry, *Vldbentry); (*Vldbentry)++; (*nentries)++; vldbentries->bulkentries_len++; @@ -2559,7 +2565,8 @@ put_attributeentry(struct vldbentry **Vldbentry, } static int -put_nattributeentry(struct nvldbentry **Vldbentry, +put_nattributeentry(struct vl_ctx *ctx, + struct nvldbentry **Vldbentry, struct nvldbentry **VldbentryFirst, struct nvldbentry **VldbentryLast, nbulkentries *vldbentries, @@ -2592,7 +2599,7 @@ put_nattributeentry(struct nvldbentry **Vldbentry, *VldbentryLast = *Vldbentry + allo; *alloccnt += allo; } - vlentry_to_nvldbentry(entry, *Vldbentry); + vlentry_to_nvldbentry(ctx, entry, *Vldbentry); (*Vldbentry)->matchindex = (matchtype << 16) + matchindex; (*Vldbentry)++; (*nentries)++; @@ -2968,7 +2975,8 @@ repsite_compress(struct nvlentry *VlEntry, int offset) /* Convert from the internal (compacted) vldb entry to the external * representation used by the interface. */ static void -vlentry_to_vldbentry(struct nvlentry *VlEntry, struct vldbentry *VldbEntry) +vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry, + struct vldbentry *VldbEntry) { int i, j; @@ -2977,14 +2985,14 @@ vlentry_to_vldbentry(struct nvlentry *VlEntry, struct vldbentry *VldbEntry) for (i = 0; i < OMAXNSERVERS; i++) { if (VlEntry->serverNumber[i] == BADSERVERID) break; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { struct extentaddr *exp; int base, index; - base = (HostAddress[j] >> 16) & 0xff; - index = HostAddress[j] & 0x0000ffff; - exp = &ex_addr[base][index]; + base = (ctx->hostaddress[j] >> 16) & 0xff; + index = ctx->hostaddress[j] & 0x0000ffff; + exp = &ctx->ex_addr[base][index]; /* For now return the first ip address back */ for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { if (exp->ex_addrs[j]) { @@ -2994,7 +3002,7 @@ vlentry_to_vldbentry(struct nvlentry *VlEntry, struct vldbentry *VldbEntry) } } else VldbEntry->serverNumber[i] = - HostAddress[VlEntry->serverNumber[i]]; + ctx->hostaddress[VlEntry->serverNumber[i]]; VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; } @@ -3009,7 +3017,8 @@ vlentry_to_vldbentry(struct nvlentry *VlEntry, struct vldbentry *VldbEntry) /* Convert from the internal (compacted) vldb entry to the external * representation used by the interface. */ static void -vlentry_to_nvldbentry(struct nvlentry *VlEntry, struct nvldbentry *VldbEntry) +vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry, + struct nvldbentry *VldbEntry) { int i, j; @@ -3018,14 +3027,14 @@ vlentry_to_nvldbentry(struct nvlentry *VlEntry, struct nvldbentry *VldbEntry) for (i = 0; i < NMAXNSERVERS; i++) { if (VlEntry->serverNumber[i] == BADSERVERID) break; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { struct extentaddr *exp; int base, index; - base = (HostAddress[j] >> 16) & 0xff; - index = HostAddress[j] & 0x0000ffff; - exp = &ex_addr[base][index]; + base = (ctx->hostaddress[j] >> 16) & 0xff; + index = ctx->hostaddress[j] & 0x0000ffff; + exp = &ctx->ex_addr[base][index]; /* For now return the first ip address back */ for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { if (exp->ex_addrs[j]) { @@ -3035,7 +3044,7 @@ vlentry_to_nvldbentry(struct nvlentry *VlEntry, struct nvldbentry *VldbEntry) } } else VldbEntry->serverNumber[i] = - HostAddress[VlEntry->serverNumber[i]]; + ctx->hostaddress[VlEntry->serverNumber[i]]; VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; } @@ -3047,7 +3056,8 @@ vlentry_to_nvldbentry(struct nvlentry *VlEntry, struct nvldbentry *VldbEntry) } static void -vlentry_to_uvldbentry(struct nvlentry *VlEntry, struct uvldbentry *VldbEntry) +vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry, + struct uvldbentry *VldbEntry) { int i, j; @@ -3058,15 +3068,15 @@ vlentry_to_uvldbentry(struct nvlentry *VlEntry, struct uvldbentry *VldbEntry) break; VldbEntry->serverFlags[i] = VlEntry->serverFlags[i]; VldbEntry->serverUnique[i] = 0; - if ((HostAddress[j = VlEntry->serverNumber[i]] & 0xff000000) == + if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) == 0xff000000) { struct extentaddr *exp; int base, index; afsUUID tuuid; - base = (HostAddress[j] >> 16) & 0xff; - index = HostAddress[j] & 0x0000ffff; - exp = &ex_addr[base][index]; + base = (ctx->hostaddress[j] >> 16) & 0xff; + index = ctx->hostaddress[j] & 0x0000ffff; + exp = &ctx->ex_addr[base][index]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); VldbEntry->serverFlags[i] |= VLSERVER_FLAG_UUID; @@ -3074,7 +3084,7 @@ vlentry_to_uvldbentry(struct nvlentry *VlEntry, struct uvldbentry *VldbEntry) VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier); } else { VldbEntry->serverNumber[i].time_low = - HostAddress[VlEntry->serverNumber[i]]; + ctx->hostaddress[VlEntry->serverNumber[i]]; } VldbEntry->serverPartition[i] = VlEntry->serverPartition[i]; @@ -3141,11 +3151,11 @@ IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create) struct extentaddr *exp; for (i = 0; i <= MAXSERVERID; i++) { - if (HostAddress[i] == ipaddr) + if (ctx->hostaddress[i] == ipaddr) return i; - if ((HostAddress[i] & 0xff000000) == 0xff000000) { - base = (HostAddress[i] >> 16) & 0xff; - index = HostAddress[i] & 0x0000ffff; + if ((ctx->hostaddress[i] & 0xff000000) == 0xff000000) { + base = (ctx->hostaddress[i] >> 16) & 0xff; + index = ctx->hostaddress[i] & 0x0000ffff; if (base >= VL_MAX_ADDREXTBLKS) { VLog(0, ("Internal error: Multihome extent base is too large. Base %d index %d\n", @@ -3158,13 +3168,13 @@ IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create) base, index)); return -1; /* EINVAL */ } - if (!ex_addr[base]) { + if (!ctx->ex_addr[base]) { VLog(0, ("Internal error: Multihome extent does not exist. Base %d\n", base)); return -1; /* EINVAL */ } - exp = &ex_addr[base][index]; + exp = &ctx->ex_addr[base][index]; for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) { if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) { return i; @@ -3176,14 +3186,14 @@ IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create) /* allocate the new server a server id pronto */ if (create) { for (i = 0; i <= MAXSERVERID; i++) { - if (cheader.IpMappedAddr[i] == 0) { - cheader.IpMappedAddr[i] = htonl(ipaddr); + if (ctx->cheader->IpMappedAddr[i] == 0) { + ctx->cheader->IpMappedAddr[i] = htonl(ipaddr); code = vlwrite(ctx->trans, - DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]), - (char *)&cheader.IpMappedAddr[i], + DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[i]), + (char *)&ctx->cheader->IpMappedAddr[i], sizeof(afs_int32)); - HostAddress[i] = ipaddr; + ctx->hostaddress[i] = ipaddr; if (code) return -1; return i; @@ -3223,9 +3233,9 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2) } for (i = 0; i <= MAXSERVERID; i++) { - if ((HostAddress[i] & 0xff000000) == 0xff000000) { - base = (HostAddress[i] >> 16) & 0xff; - index = HostAddress[i] & 0x0000ffff; + if ((ctx->hostaddress[i] & 0xff000000) == 0xff000000) { + base = (ctx->hostaddress[i] >> 16) & 0xff; + index = ctx->hostaddress[i] & 0x0000ffff; if ((base >= VL_MAX_ADDREXTBLKS) || (index >= VL_MHSRV_PERBLK)) { VLog(0, ("Internal error: Multihome extent addr is too large. Base %d index %d\n", @@ -3233,7 +3243,7 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2) return -1; /* EINVAL */ } - exp = &ex_addr[base][index]; + exp = &ctx->ex_addr[base][index]; for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) { if (!exp->ex_addrs[mhidx]) continue; @@ -3245,11 +3255,11 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2) } } } else { - if (HostAddress[i] == ipaddr1) { + if (ctx->hostaddress[i] == ipaddr1) { exp = NULL; ipaddr1_id = i; } - if (ipaddr2 != 0 && HostAddress[i] == ipaddr2) { + if (ipaddr2 != 0 && ctx->hostaddress[i] == ipaddr2) { ipaddr2_id = i; } } @@ -3329,20 +3339,20 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2) exp->ex_hostuuid = tuuid; code = vlwrite(ctx->trans, - DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)exp), + DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]), + (char *)ctx->ex_addr[base], (char *)exp), (char *)&tuuid, sizeof(tuuid)); if (code) return VL_IO; } /* Now change the host address entry */ - cheader.IpMappedAddr[ipaddr1_id] = htonl(ipaddr2); + ctx->cheader->IpMappedAddr[ipaddr1_id] = htonl(ipaddr2); code = - vlwrite(ctx->trans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[ipaddr1_id]), + vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->IpMappedAddr[ipaddr1_id]), (char *) - &cheader.IpMappedAddr[ipaddr1_id], sizeof(afs_int32)); - HostAddress[ipaddr1_id] = ipaddr2; + &ctx->cheader->IpMappedAddr[ipaddr1_id], sizeof(afs_int32)); + ctx->hostaddress[ipaddr1_id] = ipaddr2; if (code) return VL_IO; diff --git a/src/vlserver/vlserver.c b/src/vlserver/vlserver.c index 738b36a..d123377 100644 --- a/src/vlserver/vlserver.c +++ b/src/vlserver/vlserver.c @@ -59,7 +59,7 @@ int lwps = 9; struct vldstats dynamic_statistics; struct ubik_dbase *VL_dbase; -afs_uint32 HostAddress[MAXSERVERID + 1]; +afs_uint32 rd_HostAddress[MAXSERVERID + 1]; static void *CheckSignal(void*); int LogLevel = 0; @@ -363,7 +363,7 @@ main(int argc, char **argv) } rx_SetRxDeadTime(50); - memset(HostAddress, 0, sizeof(HostAddress)); + memset(rd_HostAddress, 0, sizeof(rd_HostAddress)); initialize_dstats(); afsconf_BuildServerSecurityObjects(tdir, 0, &securityClasses, &numClasses); diff --git a/src/vlserver/vlserver_internal.h b/src/vlserver/vlserver_internal.h index 716ac21..c23e99c 100644 --- a/src/vlserver/vlserver_internal.h +++ b/src/vlserver/vlserver_internal.h @@ -15,6 +15,9 @@ */ struct vl_ctx { struct ubik_trans *trans; + afs_uint32 *hostaddress; + struct extentaddr **ex_addr; + struct vlheader *cheader; }; /* vlprocs.c */ @@ -59,4 +62,5 @@ extern int UnhashVolname(struct vl_ctx *ctx, afs_int32 blockindex, extern afs_int32 NextEntry(struct vl_ctx *ctx, afs_int32 blockindex, struct nvlentry *tentry, afs_int32 *remaining); extern int FreeBlock(struct vl_ctx *ctx, afs_int32 blockindex); +extern int vlsetcache(struct vl_ctx *ctx, int locktype); #endif diff --git a/src/vlserver/vlutils.c b/src/vlserver/vlutils.c index c327f7e..ebc080f 100644 --- a/src/vlserver/vlutils.c +++ b/src/vlserver/vlutils.c @@ -25,12 +25,11 @@ #include "vlserver.h" #include "vlserver_internal.h" -extern struct vlheader cheader; struct vlheader xheader; -extern afs_uint32 HostAddress[]; extern int maxnservers; struct extentaddr extentaddr; -extern struct extentaddr *ex_addr[]; +struct extentaddr *rd_ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 }; +struct vlheader rd_cheader; /* kept in network byte order */ int vldbversion = 0; static int index_OK(struct vl_ctx *ctx, afs_int32 blockindex); @@ -191,7 +190,7 @@ int write_vital_vlheader(struct vl_ctx *ctx) { if (vlwrite - (ctx->trans, 0, (char *)&cheader.vital_header, sizeof(vital_vlheader))) + (ctx->trans, 0, (char *)&ctx->cheader->vital_header, sizeof(vital_vlheader))) return VL_IO; return 0; } @@ -215,20 +214,20 @@ readExtents(struct ubik_trans *trans) int i; extent_mod = 0; - extentAddr = ntohl(cheader.SIT); + extentAddr = ntohl(rd_cheader.SIT); if (!extentAddr) return 0; /* Read the first extension block */ - if (!ex_addr[0]) { - ex_addr[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!ex_addr[0]) + if (!rd_ex_addr[0]) { + rd_ex_addr[0] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!rd_ex_addr[0]) ERROR_EXIT(VL_NOMEM); } - code = vlread(trans, extentAddr, (char *)ex_addr[0], VL_ADDREXTBLK_SIZE); + code = vlread(trans, extentAddr, (char *)rd_ex_addr[0], VL_ADDREXTBLK_SIZE); if (code) { - free(ex_addr[0]); /* Not the place to create it */ - ex_addr[0] = 0; + free(rd_ex_addr[0]); /* Not the place to create it */ + rd_ex_addr[0] = 0; ERROR_EXIT(VL_IO); } @@ -236,47 +235,47 @@ readExtents(struct ubik_trans *trans) * continuation blocks */ for (i = 1; i < VL_MAX_ADDREXTBLKS; i++) { - if (!ex_addr[0]->ex_contaddrs[i]) + if (!rd_ex_addr[0]->ex_contaddrs[i]) continue; /* Before reading it in, check to see if the address is good */ - if ((ntohl(ex_addr[0]->ex_contaddrs[i]) < - ntohl(ex_addr[0]->ex_contaddrs[i - 1]) + VL_ADDREXTBLK_SIZE) - || (ntohl(ex_addr[0]->ex_contaddrs[i]) > - ntohl(cheader.vital_header.eofPtr) - VL_ADDREXTBLK_SIZE)) { + if ((ntohl(rd_ex_addr[0]->ex_contaddrs[i]) < + ntohl(rd_ex_addr[0]->ex_contaddrs[i - 1]) + VL_ADDREXTBLK_SIZE) + || (ntohl(rd_ex_addr[0]->ex_contaddrs[i]) > + ntohl(rd_cheader.vital_header.eofPtr) - VL_ADDREXTBLK_SIZE)) { extent_mod = 1; - ex_addr[0]->ex_contaddrs[i] = 0; + rd_ex_addr[0]->ex_contaddrs[i] = 0; continue; } /* Read the continuation block */ - if (!ex_addr[i]) { - ex_addr[i] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!ex_addr[i]) + if (!rd_ex_addr[i]) { + rd_ex_addr[i] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!rd_ex_addr[i]) ERROR_EXIT(VL_NOMEM); } code = - vlread(trans, ntohl(ex_addr[0]->ex_contaddrs[i]), - (char *)ex_addr[i], VL_ADDREXTBLK_SIZE); + vlread(trans, ntohl(rd_ex_addr[0]->ex_contaddrs[i]), + (char *)rd_ex_addr[i], VL_ADDREXTBLK_SIZE); if (code) { - free(ex_addr[i]); /* Not the place to create it */ - ex_addr[i] = 0; + free(rd_ex_addr[i]); /* Not the place to create it */ + rd_ex_addr[i] = 0; ERROR_EXIT(VL_IO); } /* After reading it in, check to see if its a real continuation block */ - if (ntohl(ex_addr[i]->ex_flags) != VLCONTBLOCK) { + if (ntohl(rd_ex_addr[i]->ex_flags) != VLCONTBLOCK) { extent_mod = 1; - ex_addr[0]->ex_contaddrs[i] = 0; - free(ex_addr[i]); /* Not the place to create it */ - ex_addr[i] = 0; + rd_ex_addr[0]->ex_contaddrs[i] = 0; + free(rd_ex_addr[i]); /* Not the place to create it */ + rd_ex_addr[i] = 0; continue; } } if (extent_mod) { - code = vlwrite(trans, extentAddr, ex_addr[0], VL_ADDREXTBLK_SIZE); + code = vlwrite(trans, extentAddr, rd_ex_addr[0], VL_ADDREXTBLK_SIZE); if (!code) { VLog(0, ("Multihome server support modification\n")); } @@ -307,15 +306,16 @@ UpdateCache(struct ubik_trans *trans, void *rock) int *builddb_rock = rock; int builddb = *builddb_rock; afs_int32 error = 0, i, code, ubcode; + extern afs_uint32 rd_HostAddress[]; /* if version changed (or first call), read the header */ - ubcode = vlread(trans, 0, (char *)&cheader, sizeof(cheader)); - vldbversion = ntohl(cheader.vital_header.vldbversion); + ubcode = vlread(trans, 0, (char *)&rd_cheader, sizeof(rd_cheader)); + vldbversion = ntohl(rd_cheader.vital_header.vldbversion); if (!ubcode && (vldbversion != 0)) { - memcpy(HostAddress, cheader.IpMappedAddr, sizeof(cheader.IpMappedAddr)); + memcpy(rd_HostAddress, rd_cheader.IpMappedAddr, sizeof(rd_cheader.IpMappedAddr)); for (i = 0; i < MAXSERVERID + 1; i++) { /* cvt HostAddress to host order */ - HostAddress[i] = ntohl(HostAddress[i]); + rd_HostAddress[i] = ntohl(rd_HostAddress[i]); } code = readExtents(trans); @@ -329,22 +329,22 @@ UpdateCache(struct ubik_trans *trans, void *rock) printf("Can't read VLDB header, re-initialising...\n"); /* try to write a good header */ - memset(&cheader, 0, sizeof(cheader)); - cheader.vital_header.vldbversion = htonl(VLDBVERSION); - cheader.vital_header.headersize = htonl(sizeof(cheader)); + memset(&rd_cheader, 0, sizeof(rd_cheader)); + rd_cheader.vital_header.vldbversion = htonl(VLDBVERSION); + rd_cheader.vital_header.headersize = htonl(sizeof(rd_cheader)); /* DANGER: Must get this from a master place!! */ - cheader.vital_header.MaxVolumeId = htonl(0x20000000); - cheader.vital_header.eofPtr = htonl(sizeof(cheader)); + rd_cheader.vital_header.MaxVolumeId = htonl(0x20000000); + rd_cheader.vital_header.eofPtr = htonl(sizeof(rd_cheader)); for (i = 0; i < MAXSERVERID + 1; i++) { - cheader.IpMappedAddr[i] = 0; - HostAddress[i] = 0; + rd_cheader.IpMappedAddr[i] = 0; + rd_HostAddress[i] = 0; } - code = vlwrite(trans, 0, (char *)&cheader, sizeof(cheader)); + code = vlwrite(trans, 0, (char *)&rd_cheader, sizeof(rd_cheader)); if (code) { printf("Can't write VLDB header (error = %d)\n", code); ERROR_EXIT(VL_IO); } - vldbversion = ntohl(cheader.vital_header.vldbversion); + vldbversion = ntohl(rd_cheader.vital_header.vldbversion); } else { ERROR_EXIT(VL_EMPTY); } @@ -396,48 +396,48 @@ GetExtentBlock(struct vl_ctx *ctx, register afs_int32 base) afs_int32 blockindex, code, error = 0; /* Base 0 must exist before any other can be created */ - if ((base != 0) && !ex_addr[0]) + if ((base != 0) && !ctx->ex_addr[0]) ERROR_EXIT(VL_CREATEFAIL); /* internal error */ - if (!ex_addr[0] || !ex_addr[0]->ex_contaddrs[base]) { + if (!ctx->ex_addr[0] || !ctx->ex_addr[0]->ex_contaddrs[base]) { /* Create a new extension block */ - if (!ex_addr[base]) { - ex_addr[base] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); - if (!ex_addr[base]) + if (!ctx->ex_addr[base]) { + ctx->ex_addr[base] = (struct extentaddr *)malloc(VL_ADDREXTBLK_SIZE); + if (!ctx->ex_addr[base]) ERROR_EXIT(VL_NOMEM); } - memset(ex_addr[base], 0, VL_ADDREXTBLK_SIZE); + memset(ctx->ex_addr[base], 0, VL_ADDREXTBLK_SIZE); /* Write the full extension block at end of vldb */ - ex_addr[base]->ex_flags = htonl(VLCONTBLOCK); - blockindex = ntohl(cheader.vital_header.eofPtr); + ctx->ex_addr[base]->ex_flags = htonl(VLCONTBLOCK); + blockindex = ntohl(ctx->cheader->vital_header.eofPtr); code = - vlwrite(ctx->trans, blockindex, (char *)ex_addr[base], + vlwrite(ctx->trans, blockindex, (char *)ctx->ex_addr[base], VL_ADDREXTBLK_SIZE); if (code) ERROR_EXIT(VL_IO); /* Update the cheader.vitalheader structure on disk */ - cheader.vital_header.eofPtr = blockindex + VL_ADDREXTBLK_SIZE; - cheader.vital_header.eofPtr = htonl(cheader.vital_header.eofPtr); + ctx->cheader->vital_header.eofPtr = blockindex + VL_ADDREXTBLK_SIZE; + ctx->cheader->vital_header.eofPtr = htonl(ctx->cheader->vital_header.eofPtr); code = write_vital_vlheader(ctx); if (code) ERROR_EXIT(VL_IO); /* Write the address of the base extension block in the vldb header */ if (base == 0) { - cheader.SIT = htonl(blockindex); + ctx->cheader->SIT = htonl(blockindex); code = - vlwrite(ctx->trans, DOFFSET(0, &cheader, &cheader.SIT), - (char *)&cheader.SIT, sizeof(cheader.SIT)); + vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->SIT), + (char *)&ctx->cheader->SIT, sizeof(ctx->cheader->SIT)); if (code) ERROR_EXIT(VL_IO); } /* Write the address of this extension block into the base extension block */ - ex_addr[0]->ex_contaddrs[base] = htonl(blockindex); + ctx->ex_addr[0]->ex_contaddrs[base] = htonl(blockindex); code = - vlwrite(ctx->trans, ntohl(cheader.SIT), ex_addr[0], + vlwrite(ctx->trans, ntohl(ctx->cheader->SIT), ctx->ex_addr[0], sizeof(struct extentaddr)); if (code) ERROR_EXIT(VL_IO); @@ -461,21 +461,21 @@ FindExtentBlock(struct vl_ctx *ctx, afsUUID *uuidp, *basep = 0; /* Create the first extension block if it does not exist */ - if (!cheader.SIT) { + if (!ctx->cheader->SIT) { code = GetExtentBlock(ctx, 0); if (code) ERROR_EXIT(code); } for (i = 0; i < MAXSERVERID + 1; i++) { - if ((HostAddress[i] & 0xff000000) == 0xff000000) { - if ((base = (HostAddress[i] >> 16) & 0xff) > VL_MAX_ADDREXTBLKS) { + if ((ctx->hostaddress[i] & 0xff000000) == 0xff000000) { + if ((base = (ctx->hostaddress[i] >> 16) & 0xff) > VL_MAX_ADDREXTBLKS) { ERROR_EXIT(VL_INDEXERANGE); } - if ((index = HostAddress[i] & 0x0000ffff) > VL_MHSRV_PERBLK) { + if ((index = ctx->hostaddress[i] & 0x0000ffff) > VL_MHSRV_PERBLK) { ERROR_EXIT(VL_INDEXERANGE); } - exp = &ex_addr[base][index]; + exp = &ctx->ex_addr[base][index]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); if (afs_uuid_equal(uuidp, &tuuid)) { @@ -489,7 +489,7 @@ FindExtentBlock(struct vl_ctx *ctx, afsUUID *uuidp, if (createit) { if (hostslot == -1) { for (i = 0; i < MAXSERVERID + 1; i++) { - if (!HostAddress[i]) + if (!ctx->hostaddress[i]) break; } if (i > MAXSERVERID) @@ -499,13 +499,13 @@ FindExtentBlock(struct vl_ctx *ctx, afsUUID *uuidp, } for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) { - if (!ex_addr[0]->ex_contaddrs[base]) { + if (!ctx->ex_addr[0]->ex_contaddrs[base]) { code = GetExtentBlock(ctx, base); if (code) ERROR_EXIT(code); } for (j = 1; j < VL_MHSRV_PERBLK; j++) { - exp = &ex_addr[base][j]; + exp = &ctx->ex_addr[base][j]; tuuid = exp->ex_hostuuid; afs_ntohuuid(&tuuid); if (afs_uuid_is_nil(&tuuid)) { @@ -514,28 +514,28 @@ FindExtentBlock(struct vl_ctx *ctx, afsUUID *uuidp, exp->ex_hostuuid = tuuid; code = vlwrite(ctx->trans, - DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]), - (char *)ex_addr[base], (char *)exp), + DOFFSET(ntohl(ctx->ex_addr[0]->ex_contaddrs[base]), + (char *)ctx->ex_addr[base], (char *)exp), (char *)&tuuid, sizeof(tuuid)); if (code) ERROR_EXIT(VL_IO); - HostAddress[i] = + ctx->hostaddress[i] = 0xff000000 | ((base << 16) & 0xff0000) | (j & 0xffff); *expp = exp; *basep = base; if (vldbversion != VLDBVERSION_4) { - cheader.vital_header.vldbversion = + ctx->cheader->vital_header.vldbversion = htonl(VLDBVERSION_4); code = write_vital_vlheader(ctx); if (code) ERROR_EXIT(VL_IO); } - cheader.IpMappedAddr[i] = htonl(HostAddress[i]); + ctx->cheader->IpMappedAddr[i] = htonl(ctx->hostaddress[i]); code = vlwrite(ctx->trans, - DOFFSET(0, &cheader, - &cheader.IpMappedAddr[i]), - (char *)&cheader.IpMappedAddr[i], + DOFFSET(0, ctx->cheader, + &ctx->cheader->IpMappedAddr[i]), + (char *)&ctx->cheader->IpMappedAddr[i], sizeof(afs_int32)); if (code) ERROR_EXIT(VL_IO); @@ -557,18 +557,18 @@ AllocBlock(struct vl_ctx *ctx, struct nvlentry *tentry) { afs_int32 blockindex; - if (cheader.vital_header.freePtr) { + if (ctx->cheader->vital_header.freePtr) { /* allocate this dude */ - blockindex = ntohl(cheader.vital_header.freePtr); + blockindex = ntohl(ctx->cheader->vital_header.freePtr); if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(vlentry))) return 0; - cheader.vital_header.freePtr = htonl(tentry->nextIdHash[0]); + ctx->cheader->vital_header.freePtr = htonl(tentry->nextIdHash[0]); } else { /* hosed, nothing on free list, grow file */ - blockindex = ntohl(cheader.vital_header.eofPtr); /* remember this guy */ - cheader.vital_header.eofPtr = htonl(blockindex + sizeof(vlentry)); + blockindex = ntohl(ctx->cheader->vital_header.eofPtr); /* remember this guy */ + ctx->cheader->vital_header.eofPtr = htonl(blockindex + sizeof(vlentry)); } - cheader.vital_header.allocs++; + ctx->cheader->vital_header.allocs++; if (write_vital_vlheader(ctx)) return 0; memset(tentry, 0, sizeof(nvlentry)); /* zero new entry */ @@ -586,12 +586,12 @@ FreeBlock(struct vl_ctx *ctx, afs_int32 blockindex) if (!index_OK(ctx, blockindex)) return VL_BADINDEX; memset(&tentry, 0, sizeof(nvlentry)); - tentry.nextIdHash[0] = cheader.vital_header.freePtr; /* already in network order */ + tentry.nextIdHash[0] = ctx->cheader->vital_header.freePtr; /* already in network order */ tentry.flags = htonl(VLFREE); - cheader.vital_header.freePtr = htonl(blockindex); + ctx->cheader->vital_header.freePtr = htonl(blockindex); if (vlwrite(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry))) return VL_IO; - cheader.vital_header.frees++; + ctx->cheader->vital_header.frees++; if (write_vital_vlheader(ctx)) return VL_IO; return 0; @@ -614,7 +614,7 @@ FindByID(struct vl_ctx *ctx, afs_uint32 volid, afs_int32 voltype, if (voltype == -1) { /* Should we have one big hash table for volids as opposed to the three ones? */ for (typeindex = 0; typeindex < MAXTYPES; typeindex++) { - for (blockindex = ntohl(cheader.VolidHash[typeindex][hashindex]); + for (blockindex = ntohl(ctx->cheader->VolidHash[typeindex][hashindex]); blockindex != NULLO; blockindex = tentry->nextIdHash[typeindex]) { if (vlentryread @@ -627,7 +627,7 @@ FindByID(struct vl_ctx *ctx, afs_uint32 volid, afs_int32 voltype, } } } else { - for (blockindex = ntohl(cheader.VolidHash[voltype][hashindex]); + for (blockindex = ntohl(ctx->cheader->VolidHash[voltype][hashindex]); blockindex != NULLO; blockindex = tentry->nextIdHash[voltype]) { if (vlentryread (ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) { @@ -672,7 +672,7 @@ FindByName(struct vl_ctx *ctx, char *volname, struct nvlentry *tentry, *error = 0; hashindex = NameHash(tname); - for (blockindex = ntohl(cheader.VolnameHash[hashindex]); + for (blockindex = ntohl(ctx->cheader->VolnameHash[hashindex]); blockindex != NULLO; blockindex = tentry->nextNameHash) { if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *error = VL_IO; @@ -768,7 +768,7 @@ HashNDump(struct vl_ctx *ctx, int hashindex) int blockindex; struct nvlentry tentry; - for (blockindex = ntohl(cheader.VolnameHash[hashindex]); + for (blockindex = ntohl(ctx->cheader->VolnameHash[hashindex]); blockindex != NULLO; blockindex = tentry.nextNameHash) { if (vlentryread(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry))) return 0; @@ -788,7 +788,7 @@ HashIdDump(struct vl_ctx *ctx, int hashindex) int blockindex; struct nvlentry tentry; - for (blockindex = ntohl(cheader.VolidHash[0][hashindex]); + for (blockindex = ntohl(ctx->cheader->VolidHash[0][hashindex]); blockindex != NULLO; blockindex = tentry.nextIdHash[0]) { if (vlentryread(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry))) return 0; @@ -887,11 +887,11 @@ HashVolid(struct vl_ctx *ctx, afs_int32 voltype, afs_int32 blockindex, return errorcode; hashindex = IDHash(tentry->volumeId[voltype]); tentry->nextIdHash[voltype] = - ntohl(cheader.VolidHash[voltype][hashindex]); - cheader.VolidHash[voltype][hashindex] = htonl(blockindex); + ntohl(ctx->cheader->VolidHash[voltype][hashindex]); + ctx->cheader->VolidHash[voltype][hashindex] = htonl(blockindex); if (vlwrite - (ctx->trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]), - (char *)&cheader.VolidHash[voltype][hashindex], sizeof(afs_int32))) + (ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->VolidHash[voltype][hashindex]), + (char *)&ctx->cheader->VolidHash[voltype][hashindex], sizeof(afs_int32))) return VL_IO; return 0; } @@ -911,16 +911,16 @@ UnhashVolid(struct vl_ctx *ctx, afs_int32 voltype, afs_int32 blockindex, return 0; /* Take it out of the VolId[voltype] hash list */ hashindex = IDHash(aentry->volumeId[voltype]); - nextblockindex = ntohl(cheader.VolidHash[voltype][hashindex]); + nextblockindex = ntohl(ctx->cheader->VolidHash[voltype][hashindex]); if (nextblockindex == blockindex) { /* First on the hash list; just adjust pointers */ - cheader.VolidHash[voltype][hashindex] = + ctx->cheader->VolidHash[voltype][hashindex] = htonl(aentry->nextIdHash[voltype]); code = vlwrite(ctx->trans, - DOFFSET(0, &cheader, - &cheader.VolidHash[voltype][hashindex]), - (char *)&cheader.VolidHash[voltype][hashindex], + DOFFSET(0, ctx->cheader, + &ctx->cheader->VolidHash[voltype][hashindex]), + (char *)&ctx->cheader->VolidHash[voltype][hashindex], sizeof(afs_int32)); if (code) return VL_IO; @@ -955,11 +955,11 @@ HashVolname(struct vl_ctx *ctx, afs_int32 blockindex, /* Insert into volname's hash linked list */ hashindex = NameHash(aentry->name); - aentry->nextNameHash = ntohl(cheader.VolnameHash[hashindex]); - cheader.VolnameHash[hashindex] = htonl(blockindex); + aentry->nextNameHash = ntohl(ctx->cheader->VolnameHash[hashindex]); + ctx->cheader->VolnameHash[hashindex] = htonl(blockindex); code = - vlwrite(ctx->trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), - (char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32)); + vlwrite(ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->VolnameHash[hashindex]), + (char *)&ctx->cheader->VolnameHash[hashindex], sizeof(afs_int32)); if (code) return VL_IO; return 0; @@ -976,13 +976,13 @@ UnhashVolname(struct vl_ctx *ctx, afs_int32 blockindex, /* Take it out of the Volname hash list */ hashindex = NameHash(aentry->name); - nextblockindex = ntohl(cheader.VolnameHash[hashindex]); + nextblockindex = ntohl(ctx->cheader->VolnameHash[hashindex]); if (nextblockindex == blockindex) { /* First on the hash list; just adjust pointers */ - cheader.VolnameHash[hashindex] = htonl(aentry->nextNameHash); + ctx->cheader->VolnameHash[hashindex] = htonl(aentry->nextNameHash); if (vlwrite - (ctx->trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]), - (char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32))) + (ctx->trans, DOFFSET(0, ctx->cheader, &ctx->cheader->VolnameHash[hashindex]), + (char *)&ctx->cheader->VolnameHash[hashindex], sizeof(afs_int32))) return VL_IO; } else { while (nextblockindex != blockindex) { @@ -1017,7 +1017,7 @@ NextEntry(struct vl_ctx *ctx, afs_int32 blockindex, afs_int32 lastblockindex; if (blockindex == 0) /* get first one */ - blockindex = sizeof(cheader); + blockindex = sizeof(*ctx->cheader); else { if (!index_OK(ctx, blockindex)) { *remaining = -1; /* error */ @@ -1026,7 +1026,7 @@ NextEntry(struct vl_ctx *ctx, afs_int32 blockindex, blockindex += sizeof(nvlentry); } /* now search for the first entry that isn't free */ - for (lastblockindex = ntohl(cheader.vital_header.eofPtr); + for (lastblockindex = ntohl(ctx->cheader->vital_header.eofPtr); blockindex < lastblockindex;) { if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) { *remaining = -1; @@ -1058,8 +1058,19 @@ NextEntry(struct vl_ctx *ctx, afs_int32 blockindex, static int index_OK(struct vl_ctx *ctx, afs_int32 blockindex) { - if ((blockindex < sizeof(cheader)) - || (blockindex >= ntohl(cheader.vital_header.eofPtr))) + if ((blockindex < sizeof(*ctx->cheader)) + || (blockindex >= ntohl(ctx->cheader->vital_header.eofPtr))) return 0; return 1; } + +int +vlsetcache(struct vl_ctx *ctx, int locktype) +{ + extern afs_uint32 rd_HostAddress[]; + + ctx->hostaddress = rd_HostAddress; + ctx->ex_addr = rd_ex_addr; + ctx->cheader = &rd_cheader; + return 0; +}