extern struct extentaddr *ex_addr[];
int vldbversion = 0;
-static int index_OK(struct ubik_trans *trans, afs_int32 blockindex);
+static int index_OK(struct vl_ctx *ctx, afs_int32 blockindex);
#define ERROR_EXIT(code) {error=(code); goto error_exit;}
/* Convenient write of small critical vldb header info to the database. */
int
-write_vital_vlheader(struct ubik_trans *trans)
+write_vital_vlheader(struct vl_ctx *ctx)
{
if (vlwrite
- (trans, 0, (char *)&cheader.vital_header, sizeof(vital_vlheader)))
+ (ctx->trans, 0, (char *)&cheader.vital_header, sizeof(vital_vlheader)))
return VL_IO;
return 0;
}
afs_int32
-GetExtentBlock(struct ubik_trans *trans, afs_int32 base)
+GetExtentBlock(struct vl_ctx *ctx, register afs_int32 base)
{
afs_int32 blockindex, code, error = 0;
ex_addr[base]->ex_flags = htonl(VLCONTBLOCK);
blockindex = ntohl(cheader.vital_header.eofPtr);
code =
- vlwrite(trans, blockindex, (char *)ex_addr[base],
+ vlwrite(ctx->trans, blockindex, (char *)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);
- code = write_vital_vlheader(trans);
+ code = write_vital_vlheader(ctx);
if (code)
ERROR_EXIT(VL_IO);
if (base == 0) {
cheader.SIT = htonl(blockindex);
code =
- vlwrite(trans, DOFFSET(0, &cheader, &cheader.SIT),
+ vlwrite(ctx->trans, DOFFSET(0, &cheader, &cheader.SIT),
(char *)&cheader.SIT, sizeof(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);
code =
- vlwrite(trans, ntohl(cheader.SIT), ex_addr[0],
+ vlwrite(ctx->trans, ntohl(cheader.SIT), ex_addr[0],
sizeof(struct extentaddr));
if (code)
ERROR_EXIT(VL_IO);
afs_int32
-FindExtentBlock(struct ubik_trans *trans, afsUUID *uuidp,
+FindExtentBlock(struct vl_ctx *ctx, afsUUID *uuidp,
afs_int32 createit, afs_int32 hostslot,
struct extentaddr **expp, afs_int32 *basep)
{
/* Create the first extension block if it does not exist */
if (!cheader.SIT) {
- code = GetExtentBlock(trans, 0);
+ code = GetExtentBlock(ctx, 0);
if (code)
ERROR_EXIT(code);
}
for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
if (!ex_addr[0]->ex_contaddrs[base]) {
- code = GetExtentBlock(trans, base);
+ code = GetExtentBlock(ctx, base);
if (code)
ERROR_EXIT(code);
}
afs_htonuuid(&tuuid);
exp->ex_hostuuid = tuuid;
code =
- vlwrite(trans,
+ vlwrite(ctx->trans,
DOFFSET(ntohl(ex_addr[0]->ex_contaddrs[base]),
(char *)ex_addr[base], (char *)exp),
(char *)&tuuid, sizeof(tuuid));
if (vldbversion != VLDBVERSION_4) {
cheader.vital_header.vldbversion =
htonl(VLDBVERSION_4);
- code = write_vital_vlheader(trans);
+ code = write_vital_vlheader(ctx);
if (code)
ERROR_EXIT(VL_IO);
}
cheader.IpMappedAddr[i] = htonl(HostAddress[i]);
code =
- vlwrite(trans,
+ vlwrite(ctx->trans,
DOFFSET(0, &cheader,
&cheader.IpMappedAddr[i]),
(char *)&cheader.IpMappedAddr[i],
/* Allocate a free block of storage for entry, returning address of a new
zeroed entry (or zero if something is wrong). */
afs_int32
-AllocBlock(struct ubik_trans *trans, struct nvlentry *tentry)
+AllocBlock(struct vl_ctx *ctx, struct nvlentry *tentry)
{
afs_int32 blockindex;
if (cheader.vital_header.freePtr) {
/* allocate this dude */
blockindex = ntohl(cheader.vital_header.freePtr);
- if (vlentryread(trans, blockindex, (char *)tentry, sizeof(vlentry)))
+ if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(vlentry)))
return 0;
cheader.vital_header.freePtr = htonl(tentry->nextIdHash[0]);
} else {
cheader.vital_header.eofPtr = htonl(blockindex + sizeof(vlentry));
}
cheader.vital_header.allocs++;
- if (write_vital_vlheader(trans))
+ if (write_vital_vlheader(ctx))
return 0;
memset(tentry, 0, sizeof(nvlentry)); /* zero new entry */
return blockindex;
/* Free a block given its index. It must already have been unthreaded. Returns zero for success or an error code on failure. */
int
-FreeBlock(struct ubik_trans *trans, afs_int32 blockindex)
+FreeBlock(struct vl_ctx *ctx, afs_int32 blockindex)
{
struct nvlentry tentry;
/* check validity of blockindex just to be on the safe side */
- if (!index_OK(trans, 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.flags = htonl(VLFREE);
cheader.vital_header.freePtr = htonl(blockindex);
- if (vlwrite(trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
+ if (vlwrite(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
return VL_IO;
cheader.vital_header.frees++;
- if (write_vital_vlheader(trans))
+ if (write_vital_vlheader(ctx))
return VL_IO;
return 0;
}
* pointed to by tentry and return the block's index. If not found return 0.
*/
afs_int32
-FindByID(struct ubik_trans *trans, afs_uint32 volid, afs_int32 voltype,
+FindByID(struct vl_ctx *ctx, afs_uint32 volid, afs_int32 voltype,
struct nvlentry *tentry, afs_int32 *error)
{
afs_int32 typeindex, hashindex, blockindex;
blockindex != NULLO;
blockindex = tentry->nextIdHash[typeindex]) {
if (vlentryread
- (trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
+ (ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
*error = VL_IO;
return 0;
}
for (blockindex = ntohl(cheader.VolidHash[voltype][hashindex]);
blockindex != NULLO; blockindex = tentry->nextIdHash[voltype]) {
if (vlentryread
- (trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
+ (ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
*error = VL_IO;
return 0;
}
* found return 0.
*/
afs_int32
-FindByName(struct ubik_trans *trans, char *volname, struct nvlentry *tentry,
+FindByName(struct vl_ctx *ctx, char *volname, struct nvlentry *tentry,
afs_int32 *error)
{
afs_int32 hashindex;
hashindex = NameHash(tname);
for (blockindex = ntohl(cheader.VolnameHash[hashindex]);
blockindex != NULLO; blockindex = tentry->nextNameHash) {
- if (vlentryread(trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
+ if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
*error = VL_IO;
return 0;
}
* Returns whether or not any of the supplied volume IDs already exist
* in the vldb.
*
- * @param trans the ubik transaction
+ * @param ctx transaction context
* @param ids an array of volume IDs
* @param ids_len the number of elements in the 'ids' array
* @param error filled in with an error code in case of error
* @retval 0 none of the volume IDs are used, or an error occurred
*/
int
-EntryIDExists(struct ubik_trans *trans, const afs_uint32 *ids,
+EntryIDExists(struct vl_ctx *ctx, const afs_uint32 *ids,
afs_int32 ids_len, afs_int32 *error)
{
afs_int32 typeindex;
for (typeindex = 0; typeindex < ids_len; typeindex++) {
if (ids[typeindex]
- && FindByID(trans, ids[typeindex], -1, &tentry, error)) {
+ && FindByID(ctx, ids[typeindex], -1, &tentry, error)) {
return 1;
} else if (*error) {
/**
* Finds the next range of unused volume IDs in the vldb.
*
- * @param trans the ubik transaction
+ * @param ctx transaction context
* @param maxvolid the current max vol ID, and where to start looking
* for an unused volume ID range
* @param bump how many volume IDs we need to be unused
* an error
*/
afs_uint32
-NextUnusedID(struct ubik_trans *trans, afs_uint32 maxvolid, afs_uint32 bump,
+NextUnusedID(struct vl_ctx *ctx, afs_uint32 maxvolid, afs_uint32 bump,
afs_int32 *error)
{
struct nvlentry tentry;
* how many free volume IDs we've seen in a row, and return when
* we've seen 'bump' unused IDs in a row */
for (id = maxvolid, nfree = 0; nfree < bump; ++id) {
- if (FindByID(trans, id, -1, &tentry, error)) {
+ if (FindByID(ctx, id, -1, &tentry, error)) {
nfree = 0;
} else if (*error) {
return 0;
}
int
-HashNDump(struct ubik_trans *trans, int hashindex)
+HashNDump(struct vl_ctx *ctx, int hashindex)
{
int i = 0;
int blockindex;
for (blockindex = ntohl(cheader.VolnameHash[hashindex]);
blockindex != NULLO; blockindex = tentry.nextNameHash) {
- if (vlentryread(trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
+ if (vlentryread(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
return 0;
i++;
VLog(0,
int
-HashIdDump(struct ubik_trans *trans, int hashindex)
+HashIdDump(struct vl_ctx *ctx, int hashindex)
{
int i = 0;
int blockindex;
for (blockindex = ntohl(cheader.VolidHash[0][hashindex]);
blockindex != NULLO; blockindex = tentry.nextIdHash[0]) {
- if (vlentryread(trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
+ if (vlentryread(ctx->trans, blockindex, (char *)&tentry, sizeof(nvlentry)))
return 0;
i++;
VLog(0,
* routine returns zero if there were no errors.
*/
int
-ThreadVLentry(struct ubik_trans *trans, afs_int32 blockindex,
+ThreadVLentry(struct vl_ctx *ctx, afs_int32 blockindex,
struct nvlentry *tentry)
{
int errorcode;
- if (!index_OK(trans, blockindex))
+ if (!index_OK(ctx, blockindex))
return VL_BADINDEX;
/* Insert into volid's hash linked list */
- if ((errorcode = HashVolid(trans, RWVOL, blockindex, tentry)))
+ if ((errorcode = HashVolid(ctx, RWVOL, blockindex, tentry)))
return errorcode;
/* For rw entries we also enter the RO and BACK volume ids (if they
* exist) in the hash tables; note all there volids (RW, RO, BACK)
* should not be hashed yet! */
if (tentry->volumeId[ROVOL]) {
- if ((errorcode = HashVolid(trans, ROVOL, blockindex, tentry)))
+ if ((errorcode = HashVolid(ctx, ROVOL, blockindex, tentry)))
return errorcode;
}
if (tentry->volumeId[BACKVOL]) {
- if ((errorcode = HashVolid(trans, BACKVOL, blockindex, tentry)))
+ if ((errorcode = HashVolid(ctx, BACKVOL, blockindex, tentry)))
return errorcode;
}
/* Insert into volname's hash linked list */
- HashVolname(trans, blockindex, tentry);
+ HashVolname(ctx, blockindex, tentry);
/* Update cheader entry */
- if (write_vital_vlheader(trans))
+ if (write_vital_vlheader(ctx))
return VL_IO;
/* Update hash list pointers in the entry itself */
- if (vlentrywrite(trans, blockindex, (char *)tentry, sizeof(nvlentry)))
+ if (vlentrywrite(ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry)))
return VL_IO;
return 0;
}
/* Remove a block from both the hash tables. If success return 0, else
* return an error code. */
int
-UnthreadVLentry(struct ubik_trans *trans, afs_int32 blockindex,
+UnthreadVLentry(struct vl_ctx *ctx, afs_int32 blockindex,
struct nvlentry *aentry)
{
afs_int32 errorcode, typeindex;
- if (!index_OK(trans, blockindex))
+ if (!index_OK(ctx, blockindex))
return VL_BADINDEX;
- if ((errorcode = UnhashVolid(trans, RWVOL, blockindex, aentry)))
+ if ((errorcode = UnhashVolid(ctx, RWVOL, blockindex, aentry)))
return errorcode;
/* Take the RO/RW entries of their respective hash linked lists. */
for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
- if ((errorcode = UnhashVolid(trans, typeindex, blockindex, aentry)))
+ if ((errorcode = UnhashVolid(ctx, typeindex, blockindex, aentry)))
return errorcode;
}
/* Take it out of the Volname hash list */
- if ((errorcode = UnhashVolname(trans, blockindex, aentry)))
+ if ((errorcode = UnhashVolname(ctx, blockindex, aentry)))
return errorcode;
/* Update cheader entry */
- write_vital_vlheader(trans);
+ write_vital_vlheader(ctx);
return 0;
}
/* cheader must have be read before this routine is called. */
int
-HashVolid(struct ubik_trans *trans, afs_int32 voltype, afs_int32 blockindex,
+HashVolid(struct vl_ctx *ctx, afs_int32 voltype, afs_int32 blockindex,
struct nvlentry *tentry)
{
afs_int32 hashindex, errorcode;
struct nvlentry ventry;
if (FindByID
- (trans, tentry->volumeId[voltype], voltype, &ventry, &errorcode))
+ (ctx, tentry->volumeId[voltype], voltype, &ventry, &errorcode))
return VL_IDALREADYHASHED;
else if (errorcode)
return errorcode;
ntohl(cheader.VolidHash[voltype][hashindex]);
cheader.VolidHash[voltype][hashindex] = htonl(blockindex);
if (vlwrite
- (trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]),
+ (ctx->trans, DOFFSET(0, &cheader, &cheader.VolidHash[voltype][hashindex]),
(char *)&cheader.VolidHash[voltype][hashindex], sizeof(afs_int32)))
return VL_IO;
return 0;
/* cheader must have be read before this routine is called. */
int
-UnhashVolid(struct ubik_trans *trans, afs_int32 voltype, afs_int32 blockindex,
+UnhashVolid(struct vl_ctx *ctx, afs_int32 voltype, afs_int32 blockindex,
struct nvlentry *aentry)
{
int hashindex, nextblockindex, prevblockindex;
cheader.VolidHash[voltype][hashindex] =
htonl(aentry->nextIdHash[voltype]);
code =
- vlwrite(trans,
+ vlwrite(ctx->trans,
DOFFSET(0, &cheader,
&cheader.VolidHash[voltype][hashindex]),
(char *)&cheader.VolidHash[voltype][hashindex],
while (nextblockindex != blockindex) {
prevblockindex = nextblockindex; /* always done once */
if (vlentryread
- (trans, nextblockindex, (char *)&tentry, sizeof(nvlentry)))
+ (ctx->trans, nextblockindex, (char *)&tentry, sizeof(nvlentry)))
return VL_IO;
if ((nextblockindex = tentry.nextIdHash[voltype]) == NULLO)
return VL_NOENT;
temp = tentry.nextIdHash[voltype] = aentry->nextIdHash[voltype];
temp = htonl(temp); /* convert to network byte order before writing */
if (vlwrite
- (trans,
+ (ctx->trans,
DOFFSET(prevblockindex, &tentry, &tentry.nextIdHash[voltype]),
(char *)&temp, sizeof(afs_int32)))
return VL_IO;
int
-HashVolname(struct ubik_trans *trans, afs_int32 blockindex,
+HashVolname(struct vl_ctx *ctx, afs_int32 blockindex,
struct nvlentry *aentry)
{
afs_int32 hashindex;
aentry->nextNameHash = ntohl(cheader.VolnameHash[hashindex]);
cheader.VolnameHash[hashindex] = htonl(blockindex);
code =
- vlwrite(trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]),
+ vlwrite(ctx->trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]),
(char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32));
if (code)
return VL_IO;
int
-UnhashVolname(struct ubik_trans *trans, afs_int32 blockindex,
+UnhashVolname(struct vl_ctx *ctx, afs_int32 blockindex,
struct nvlentry *aentry)
{
afs_int32 hashindex, nextblockindex, prevblockindex;
/* First on the hash list; just adjust pointers */
cheader.VolnameHash[hashindex] = htonl(aentry->nextNameHash);
if (vlwrite
- (trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]),
+ (ctx->trans, DOFFSET(0, &cheader, &cheader.VolnameHash[hashindex]),
(char *)&cheader.VolnameHash[hashindex], sizeof(afs_int32)))
return VL_IO;
} else {
while (nextblockindex != blockindex) {
prevblockindex = nextblockindex; /* always done at least once */
if (vlentryread
- (trans, nextblockindex, (char *)&tentry, sizeof(nvlentry)))
+ (ctx->trans, nextblockindex, (char *)&tentry, sizeof(nvlentry)))
return VL_IO;
if ((nextblockindex = tentry.nextNameHash) == NULLO)
return VL_NOENT;
tentry.nextNameHash = aentry->nextNameHash;
temp = htonl(tentry.nextNameHash);
if (vlwrite
- (trans, DOFFSET(prevblockindex, &tentry, &tentry.nextNameHash),
+ (ctx->trans, DOFFSET(prevblockindex, &tentry, &tentry.nextNameHash),
(char *)&temp, sizeof(afs_int32)))
return VL_IO;
}
*/
afs_int32
-NextEntry(struct ubik_trans *trans, afs_int32 blockindex,
+NextEntry(struct vl_ctx *ctx, afs_int32 blockindex,
struct nvlentry *tentry, afs_int32 *remaining)
{
afs_int32 lastblockindex;
if (blockindex == 0) /* get first one */
blockindex = sizeof(cheader);
else {
- if (!index_OK(trans, blockindex)) {
+ if (!index_OK(ctx, blockindex)) {
*remaining = -1; /* error */
return 0;
}
/* now search for the first entry that isn't free */
for (lastblockindex = ntohl(cheader.vital_header.eofPtr);
blockindex < lastblockindex;) {
- if (vlentryread(trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
+ if (vlentryread(ctx->trans, blockindex, (char *)tentry, sizeof(nvlentry))) {
*remaining = -1;
return 0;
}
* table
*/
static int
-index_OK(struct ubik_trans *trans, afs_int32 blockindex)
+index_OK(struct vl_ctx *ctx, afs_int32 blockindex)
{
if ((blockindex < sizeof(cheader))
|| (blockindex >= ntohl(cheader.vital_header.eofPtr)))