vlserver: unsigned values are always >0
[openafs.git] / src / vlserver / vlprocs.c
index 06c9fbf..6868edb 100644 (file)
 
 #include <roken.h>
 
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
 #include <lock.h>
 #include <afs/afsutil.h>
 #include <ubik.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rxkad.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
 #include <afs/keys.h>
 #include <afs/cellconfig.h>
+
 #include "vlserver.h"
 #include "vlserver_internal.h"
 #include "afs/audit.h"
-#ifndef AFS_NT40_ENV
-#include <unistd.h>
-#endif
+
 #ifdef HAVE_POSIX_REGEX                /* use POSIX regexp library */
 #include <regex.h>
 #endif
@@ -44,12 +35,12 @@ extern struct afsconf_dir *vldb_confdir;
 extern struct ubik_dbase *VL_dbase;
 int maxnservers;
 #define ABORT(c) do { \
-    errorcode = (c); \
+    code = (c); \
     goto abort; \
 } while (0)
 #undef END
 #define END(c) do { \
-    errorcode = (c); \
+    code = (c); \
     goto end; \
 } while (0)
 
@@ -81,15 +72,15 @@ 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 vl_ctx *ctx,
+static int vlentry_to_vldbentry(struct vl_ctx *ctx,
+                               struct nvlentry *VlEntry,
+                               struct vldbentry *VldbEntry);
+static int vlentry_to_nvldbentry(struct vl_ctx *ctx,
                                 struct nvlentry *VlEntry,
-                                struct vldbentry *VldbEntry);
-static void vlentry_to_nvldbentry(struct vl_ctx *ctx,
-                                 struct nvlentry *VlEntry,
-                                 struct nvldbentry *VldbEntry);
-static void vlentry_to_uvldbentry(struct vl_ctx *ctx,
-                                 struct nvlentry *VlEntry,
-                                 struct uvldbentry *VldbEntry);
+                                struct nvldbentry *VldbEntry);
+static int vlentry_to_uvldbentry(struct vl_ctx *ctx,
+                                struct nvlentry *VlEntry,
+                                struct uvldbentry *VldbEntry);
 static int InvalidVolname(char *volname);
 static int InvalidVoltype(afs_int32 voltype);
 static int InvalidOperation(afs_int32 voloper);
@@ -98,79 +89,159 @@ static int IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create);
 static int ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1,
                         afs_uint32 ipaddr2);
 
+static_inline void
+countRequest(int opcode)
+{
+    if (opcode != 0) {
+        dynamic_statistics.requests[opcode - VL_LOWEST_OPCODE]++;
+    }
+}
+
+static_inline void
+countAbort(int opcode)
+{
+    if (opcode != 0) {
+       dynamic_statistics.aborts[opcode - VL_LOWEST_OPCODE]++;
+    }
+}
+
+
+static_inline int
+multiHomedExtentBase(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp,
+                    int *basePtr)
+{
+    int base;
+    int index;
+
+    *exp = NULL;
+    *basePtr = 0;
+
+    if ((ctx->hostaddress[srvidx] & 0xff000000) == 0xff000000) {
+       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", base, index));
+           return VL_IO;
+       }
+       if (index >= VL_MHSRV_PERBLK) {
+           VLog(0, ("Internal error: Multihome extent index is too large. "
+                    "Base %d index %d\n", base, index));
+           return VL_IO;
+       }
+       if (!ctx->ex_addr[base]) {
+           VLog(0, ("Internal error: Multihome extent does not exist. "
+                    "Base %d\n", base));
+           return VL_IO;
+       }
+
+       *basePtr = base;
+       *exp = &ctx->ex_addr[base][index];
+    }
+
+    return 0;
+}
+
+static_inline int
+multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
+{
+    int base;
+
+    return multiHomedExtentBase(ctx, srvidx, exp, &base);
+}
+
 #define AFS_RXINFO_LEN 128
 static char *
-rxinfo(char * str, struct rx_call *rxcall)
+rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
 {
     int code;
-    struct rx_connection *tconn;
     char tname[64] = "";
     char tinst[64] = "";
     char tcell[64] = "";
     afs_uint32 exp;
-    struct in_addr hostAddr;
 
-    tconn = rx_ConnectionOf(rxcall);
-    hostAddr.s_addr = rx_HostOf(rx_PeerOf(tconn));
-    code =
-       rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell,
-                           NULL);
+    code = rxkad_GetServerInfo(conn, NULL, &exp, tname, tinst, tcell,
+                              NULL);
     if (!code)
-       sprintf(str, "%s %s%s%s%s%s", inet_ntoa(hostAddr), tname,
+       snprintf(str, AFS_RXINFO_LEN,
+                "%s rxkad:%s%s%s%s%s", inet_ntoa(hostAddr), tname,
                (tinst[0] == '\0') ? "" : ".",
                (tinst[0] == '\0') ? "" : tinst,
                (tcell[0] == '\0') ? "" : "@",
                (tcell[0] == '\0') ? "" : tcell);
     else
-       sprintf(str, "%s noauth", inet_ntoa(hostAddr));
+       snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
     return (str);
 }
 
+static char *
+rxinfo(char *str, struct rx_call *rxcall)
+{
+    struct rx_connection *conn;
+    struct in_addr hostAddr;
+    rx_securityIndex authClass;
+
+    conn = rx_ConnectionOf(rxcall);
+    authClass = rx_SecurityClassOf(conn);
+    hostAddr.s_addr = rx_HostOf(rx_PeerOf(conn));
+
+    switch(authClass) {
+    case RX_SECIDX_KAD:
+       return rxkadInfo(str, conn, hostAddr);
+    default:
+       ;
+    }
+
+    snprintf(str, AFS_RXINFO_LEN, "%s noauth", inet_ntoa(hostAddr));
+    return str;
+}
+
+
 /* This is called to initialize the database, set the appropriate locks and make sure that the vldb header is valid */
 int
 Init_VLdbase(struct vl_ctx *ctx,
             int locktype,      /* indicate read or write transaction */
-            int this_op)
+            int opcode)
 {
-    int errorcode = 0, pass, wl;
+    int code = 0, pass, wl;
 
     for (pass = 1; pass <= 3; pass++) {
        if (pass == 2) {        /* take write lock to rebuild the db */
-           errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
+           code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
            wl = 1;
        } else if (locktype == LOCKREAD) {
-           errorcode =
+           code =
                ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
            wl = 0;
        } else {
-           errorcode = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
+           code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
            wl = 1;
        }
-       if (errorcode)
-           return errorcode;
+       if (code)
+           return code;
 
-       errorcode = ubik_SetLock(ctx->trans, 1, 1, locktype);
-       if (errorcode) {
-           COUNT_ABO;
+       code = ubik_SetLock(ctx->trans, 1, 1, locktype);
+       if (code) {
+           countAbort(opcode);
            ubik_AbortTrans(ctx->trans);
-           return errorcode;
+           return code;
        }
 
        /* check that dbase is initialized and setup cheader */
        /* 2nd pass we try to rebuild the header */
-       errorcode = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
-       if (!errorcode && wl && extent_mod)
-           errorcode = readExtents(ctx->trans);        /* Fix the mh extent blocks */
-       if (errorcode) {
-           COUNT_ABO;
+       code = CheckInit(ctx->trans, ((pass == 2) ? 1 : 0));
+       if (!code && wl && extent_mod)
+           code = readExtents(ctx->trans);     /* Fix the mh extent blocks */
+       if (code) {
+           countAbort(opcode);
            ubik_AbortTrans(ctx->trans);
            /* Only rebuld if the database is empty */
            /* Exit if can't rebuild */
-           if ((pass == 1) && (errorcode != VL_EMPTY))
-               return errorcode;
+           if ((pass == 1) && (code != VL_EMPTY))
+               return code;
            if (pass == 2)
-               return errorcode;
-       } else {                /* No errorcode */
+               return code;
+       } else {                /* No code */
            if (pass == 2) {
                ubik_EndTrans(ctx->trans);      /* Rebuilt db. End trans, then retake original lock */
            } else {
@@ -178,10 +249,10 @@ Init_VLdbase(struct vl_ctx *ctx,
            }
        }
     }
-    if (errorcode == 0) {
-       errorcode = vlsetcache(ctx, locktype);
+    if (code == 0) {
+       code = vlsetcache(ctx, locktype);
     }
-    return errorcode;
+    return code;
 }
 
 
@@ -192,227 +263,231 @@ Init_VLdbase(struct vl_ctx *ctx,
 afs_int32
 SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
 {
+    int this_op = VLCREATEENTRY;
     struct vl_ctx ctx;
-    afs_int32 errorcode, blockindex;
+    afs_int32 code, blockindex;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLCREATEENTRY);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       errorcode = VL_PERM;
+       code = VL_PERM;
        goto end;
     }
 
     /* Do some validity tests on new entry */
-    if ((errorcode = check_vldbentry(newentry))
-       || (errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = check_vldbentry(newentry))
+       || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1,
         ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
          rxinfo(rxstr, rxcall)));
-    if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &errorcode)) {
+    if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
        /* at least one of the specified IDs already exists; we fail */
-       errorcode = VL_IDEXIST;
+       code = VL_IDEXIST;
        goto abort;
-    } else if (errorcode) {
+    } else if (code) {
        goto abort;
     }
 
     /* Is this following check (by volume name) necessary?? */
     /* If entry already exists, we fail */
-    if (FindByName(&ctx, newentry->name, &tentry, &errorcode)) {
-       errorcode = VL_NAMEEXIST;
+    if (FindByName(&ctx, newentry->name, &tentry, &code)) {
+       code = VL_NAMEEXIST;
        goto abort;
-    } else if (errorcode) {
+    } else if (code) {
        goto abort;
     }
 
     blockindex = AllocBlock(&ctx, &tentry);
     if (blockindex == 0) {
-       errorcode = VL_CREATEFAIL;
+       code = VL_CREATEFAIL;
        goto abort;
     }
 
     memset(&tentry, 0, sizeof(struct nvlentry));
     /* Convert to its internal representation; both in host byte order */
-    if ((errorcode = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
+    if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
        FreeBlock(&ctx, blockindex);
        goto abort;
     }
 
     /* Actually insert the entry in vldb */
-    errorcode = ThreadVLentry(&ctx, blockindex, &tentry);
-    if (errorcode) {
+    code = ThreadVLentry(&ctx, blockindex, &tentry);
+    if (code) {
        FreeBlock(&ctx, blockindex);
        goto abort;
     } else {
-       errorcode = ubik_EndTrans(ctx.trans);
+       code = ubik_EndTrans(ctx.trans);
        goto end;
     }
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR,
+    osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
               (newentry ? newentry->name : NULL), AUD_END);
-    return errorcode;
+    return code;
 }
 
 
 afs_int32
 SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
 {
+    int this_op = VLCREATEENTRYN;
     struct vl_ctx ctx;
-    afs_int32 errorcode, blockindex;
+    afs_int32 code, blockindex;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLCREATEENTRYN);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       errorcode = VL_PERM;
+       code = VL_PERM;
        goto end;
     }
 
     /* Do some validity tests on new entry */
-    if ((errorcode = check_nvldbentry(newentry))
-       || (errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = check_nvldbentry(newentry))
+       || (code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1,
         ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
          rxinfo(rxstr, rxcall)));
-    if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &errorcode)) {
+    if (EntryIDExists(&ctx, newentry->volumeId, MAXTYPES, &code)) {
        /* at least one of the specified IDs already exists; we fail */
-       errorcode = VL_IDEXIST;
+       code = VL_IDEXIST;
        goto abort;
-    } else if (errorcode) {
+    } else if (code) {
        goto abort;
     }
 
     /* Is this following check (by volume name) necessary?? */
     /* If entry already exists, we fail */
-    if (FindByName(&ctx, newentry->name, &tentry, &errorcode)) {
-       errorcode = VL_NAMEEXIST;
+    if (FindByName(&ctx, newentry->name, &tentry, &code)) {
+       code = VL_NAMEEXIST;
        goto abort;
-    } else if (errorcode) {
+    } else if (code) {
        goto abort;
     }
 
     blockindex = AllocBlock(&ctx, &tentry);
     if (blockindex == 0) {
-       errorcode = VL_CREATEFAIL;
+       code = VL_CREATEFAIL;
        goto abort;
     }
 
     memset(&tentry, 0, sizeof(struct nvlentry));
     /* Convert to its internal representation; both in host byte order */
-    if ((errorcode = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
+    if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
        FreeBlock(&ctx, blockindex);
        goto abort;
     }
 
     /* Actually insert the entry in vldb */
-    errorcode = ThreadVLentry(&ctx, blockindex, &tentry);
-    if (errorcode) {
+    code = ThreadVLentry(&ctx, blockindex, &tentry);
+    if (code) {
        FreeBlock(&ctx, blockindex);
        goto abort;
     } else {
-       errorcode = ubik_EndTrans(ctx.trans);
+       code = ubik_EndTrans(ctx.trans);
        goto end;
     }
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLCreateEntryEvent, errorcode, AUD_STR,
+    osi_auditU(rxcall, VLCreateEntryEvent, code, AUD_STR,
               (newentry ? newentry->name : NULL), AUD_END);
-    return errorcode;
+    return code;
 }
 
 
 afs_int32
 SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
 {
+    int this_op = VLCHANGEADDR;
     struct vl_ctx ctx;
-    afs_int32 errorcode;
+    afs_int32 code;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLCHANGEADDR);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
-       errorcode = VL_PERM;
+       code = VL_PERM;
        goto end;
     }
 
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
-    if ((errorcode = ChangeIPAddr(&ctx, ip1, ip2)))
+    if ((code = ChangeIPAddr(&ctx, ip1, ip2)))
        goto abort;
     else {
-       errorcode = ubik_EndTrans(ctx.trans);
+       code = ubik_EndTrans(ctx.trans);
        goto end;
     }
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLChangeAddrEvent, errorcode, AUD_LONG, ip1, AUD_LONG,
+    osi_auditU(rxcall, VLChangeAddrEvent, code, AUD_LONG, ip1, AUD_LONG,
               ip2, AUD_END);
-    return errorcode;
+    return code;
 }
 
 /* Delete a vldb entry given the volume id. */
 afs_int32
 SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
 {
+    int this_op = VLDELETEENTRY;
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode;
+    afs_int32 blockindex, code;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLDELETEENTRY);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        END(VL_BADVOLTYPE);
 
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == 0) {     /* volid not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
 
     if (tentry.flags & VLDELETED) {    /* Already deleted; return */
        ABORT(VL_ENTDELETED);
     }
-    if ((errorcode = RemoveEntry(&ctx, blockindex, &tentry))) {
+    if ((code = RemoveEntry(&ctx, blockindex, &tentry))) {
        goto abort;
     }
-    errorcode = (ubik_EndTrans(ctx.trans));
+    code = (ubik_EndTrans(ctx.trans));
     goto end;
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLDeleteEntryEvent, errorcode, AUD_LONG, volid,
+    osi_auditU(rxcall, VLDeleteEntryEvent, code, AUD_LONG, volid,
               AUD_END);
-    return errorcode;
+    return code;
 }
 
 
@@ -426,38 +501,46 @@ GetEntryByID(struct rx_call *rxcall,
             afs_int32 this_op)
 {
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode;
+    afs_int32 blockindex, code;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
+    countRequest(this_op);
+
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        return VL_BADVOLTYPE;
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
 
     VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
              rxinfo(rxstr, rxcall)));
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return errorcode;
+       if (!code)
+           code = VL_NOENT;
+       goto abort;
     }
     if (tentry.flags & VLDELETED) {    /* Entry is deleted! */
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_ENTDELETED;
+       code = VL_ENTDELETED;
+       goto abort;
     }
     /* Convert from the internal to external form */
     if (new == 1)
-       vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
     else if (new == 2)
-       vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
+       code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
     else
-       vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+
+    if (code)
+       goto abort;
+
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 afs_int32
@@ -466,8 +549,8 @@ SVL_GetEntryByID(struct rx_call *rxcall,
                 afs_int32 voltype,
                 vldbentry *aentry)             /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYID);
-    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0, this_op));
+    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0,
+                        VLGETENTRYBYID));
 }
 
 afs_int32
@@ -476,8 +559,8 @@ SVL_GetEntryByIDN(struct rx_call *rxcall,
                  afs_int32 voltype,
                  nvldbentry *aentry)   /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYIDN);
-    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1, this_op));
+    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1,
+                        VLGETENTRYBYIDN));
 }
 
 afs_int32
@@ -486,12 +569,10 @@ SVL_GetEntryByIDU(struct rx_call *rxcall,
                  afs_int32 voltype,
                  uvldbentry *aentry)   /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYIDU);
-    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2, this_op));
+    return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2,
+                        VLGETENTRYBYIDU));
 }
 
-
-
 /* returns true if the id is a decimal integer, in which case we interpret
  * it as an id.  make the cache manager much simpler */
 static int
@@ -515,39 +596,46 @@ GetEntryByName(struct rx_call *rxcall,
               int this_op)
 {
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode;
+    afs_int32 blockindex, code;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
     if (NameIsId(volname)) {
-       return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op);
+       return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
     }
     if (InvalidVolname(volname))
        return VL_BADNAME;
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
-    blockindex = FindByName(&ctx, volname, &tentry, &errorcode);
+    blockindex = FindByName(&ctx, volname, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return errorcode;
+       if (!code)
+           code = VL_NOENT;
+       goto abort;
     }
     if (tentry.flags & VLDELETED) {    /* Entry is deleted */
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_ENTDELETED;
+       code = VL_ENTDELETED;
+       goto abort;
     }
     /* Convert to external entry representation */
     if (new == 1)
-       vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, (struct nvldbentry *)aentry);
     else if (new == 2)
-       vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
+       code = vlentry_to_uvldbentry(&ctx, &tentry, (struct uvldbentry *)aentry);
     else
-       vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, (struct vldbentry *)aentry);
+
+    if (code)
+       goto abort;
+
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
+
 }
 
 afs_int32
@@ -555,8 +643,8 @@ SVL_GetEntryByNameO(struct rx_call *rxcall,
                    char *volname,
                    struct vldbentry *aentry)   /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYNAME);
-    return (GetEntryByName(rxcall, volname, (char *)aentry, 0, this_op));
+    return (GetEntryByName(rxcall, volname, (char *)aentry, 0,
+                          VLGETENTRYBYNAME));
 }
 
 
@@ -565,8 +653,8 @@ SVL_GetEntryByNameN(struct rx_call *rxcall,
                    char *volname,
                    struct nvldbentry *aentry)  /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYNAMEN);
-    return (GetEntryByName(rxcall, volname, (char *)aentry, 1, this_op));
+    return (GetEntryByName(rxcall, volname, (char *)aentry, 1,
+                          VLGETENTRYBYNAMEN));
 }
 
 afs_int32
@@ -574,8 +662,8 @@ SVL_GetEntryByNameU(struct rx_call *rxcall,
                    char *volname,
                    struct uvldbentry *aentry)  /* entry data copied here */
 {
-    COUNT_REQ(VLGETENTRYBYNAMEU);
-    return (GetEntryByName(rxcall, volname, (char *)aentry, 2, this_op));
+    return (GetEntryByName(rxcall, volname, (char *)aentry, 2,
+                          VLGETENTRYBYNAMEU));
 }
 
 
@@ -585,24 +673,25 @@ afs_int32
 SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
                   afs_uint32 *newvolumeid)
 {
-    afs_int32 errorcode;
+    int this_op = VLGETNEWVOLUMEID;
+    afs_int32 code;
     afs_uint32 maxvolumeid;
     struct vl_ctx ctx;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLGETNEWVOLUMEID);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
-    if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
+    if (Maxvolidbump > MAXBUMPCOUNT)
        END(VL_BADVOLIDBUMP);
 
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     *newvolumeid = maxvolumeid = NextUnusedID(&ctx,
-       ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &errorcode);
-    if (errorcode) {
+       ntohl(ctx.cheader->vital_header.MaxVolumeId), Maxvolidbump, &code);
+    if (code) {
        goto abort;
     }
 
@@ -612,16 +701,16 @@ SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
     if (write_vital_vlheader(&ctx)) {
        ABORT(VL_IO);
     }
-    errorcode = (ubik_EndTrans(ctx.trans));
+    code = (ubik_EndTrans(ctx.trans));
     goto end;
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLGetNewVolumeIdEvent, errorcode, AUD_END);
-    return errorcode;
+    osi_auditU(rxcall, VLGetNewVolumeIdEvent, code, AUD_END);
+    return code;
 }
 
 
@@ -633,22 +722,23 @@ afs_int32
 SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
                 struct vldbentry *newentry, afs_int32 releasetype)
 {
+    int this_op = VLREPLACEENTRY;
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode, typeindex;
+    afs_int32 blockindex, code, typeindex;
     int hashnewname;
     int hashVol[MAXTYPES];
     struct nvlentry tentry;
     afs_uint32 checkids[MAXTYPES];
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLREPLACEENTRY);
+    countRequest(this_op);
     for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
        hashVol[typeindex] = 0;
     hashnewname = 0;
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
-    if ((errorcode = check_vldbentry(newentry)))
+    if ((code = check_vldbentry(newentry)))
        goto end;
 
     if (voltype != -1 && InvalidVoltype(voltype))
@@ -656,15 +746,15 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
 
@@ -680,18 +770,18 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
            checkids[typeindex] = newentry->volumeId[typeindex];
        }
     }
-    if (EntryIDExists(&ctx, checkids, MAXTYPES, &errorcode)) {
+    if (EntryIDExists(&ctx, checkids, MAXTYPES, &code)) {
        ABORT(VL_IDEXIST);
-    } else if (errorcode) {
+    } else if (code) {
        goto abort;
     }
 
     /* make sure the name we're changing to doesn't already exist */
     if (strcmp(newentry->name, tentry.name)) {
        struct nvlentry tmp_entry;
-       if (FindByName(&ctx, newentry->name, &tmp_entry, &errorcode)) {
+       if (FindByName(&ctx, newentry->name, &tmp_entry, &code)) {
            ABORT(VL_NAMEEXIST);
-       } else if (errorcode) {
+       } else if (code) {
            goto abort;
        }
     }
@@ -702,7 +792,7 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
            if (tentry.volumeId[typeindex])
-               if ((errorcode =
+               if ((code =
                    UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
                    goto abort;
                }
@@ -713,7 +803,7 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     /* Rehash volname if it changes */
     if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
-       if ((errorcode = UnhashVolname(&ctx, blockindex, &tentry))) {
+       if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
            goto abort;
        }
        hashnewname = 1;
@@ -721,13 +811,13 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     /* after this, tentry is new entry, not old one.  vldbentry_to_vlentry
      * doesn't touch hash chains */
-    if ((errorcode = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
+    if ((code = vldbentry_to_vlentry(&ctx, newentry, &tentry))) {
        goto abort;
     }
 
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
-           if ((errorcode = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
+           if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
                goto abort;
            }
        }
@@ -745,34 +835,35 @@ SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid,
+    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
               AUD_END);
-    return errorcode;
+    return code;
 }
 
 afs_int32
 SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
                  struct nvldbentry *newentry, afs_int32 releasetype)
 {
+    int this_op = VLREPLACEENTRYN;
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode, typeindex;
+    afs_int32 blockindex, code, typeindex;
     int hashnewname;
     int hashVol[MAXTYPES];
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLREPLACEENTRYN);
+    countRequest(this_op);
     for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
        hashVol[typeindex] = 0;
     hashnewname = 0;
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
-    if ((errorcode = check_nvldbentry(newentry)))
+    if ((code = check_nvldbentry(newentry)))
        goto end;
 
     if (voltype != -1 && InvalidVoltype(voltype))
@@ -780,15 +871,15 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
 
@@ -803,7 +894,7 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
            if (tentry.volumeId[typeindex])
-               if ((errorcode =
+               if ((code =
                    UnhashVolid(&ctx, typeindex, blockindex, &tentry))) {
                    goto abort;
                }
@@ -814,7 +905,7 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     /* Rehash volname if it changes */
     if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
-       if ((errorcode = UnhashVolname(&ctx, blockindex, &tentry))) {
+       if ((code = UnhashVolname(&ctx, blockindex, &tentry))) {
            goto abort;
        }
        hashnewname = 1;
@@ -822,13 +913,13 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
 
     /* after this, tentry is new entry, not old one.  vldbentry_to_vlentry
      * doesn't touch hash chains */
-    if ((errorcode = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
+    if ((code = nvldbentry_to_vlentry(&ctx, newentry, &tentry))) {
        goto abort;
     }
 
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
-           if ((errorcode = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
+           if ((code = HashVolid(&ctx, typeindex, blockindex, &tentry))) {
                goto abort;
            }
        }
@@ -846,13 +937,13 @@ SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLReplaceVLEntryEvent, errorcode, AUD_LONG, volid,
+    osi_auditU(rxcall, VLReplaceVLEntryEvent, code, AUD_LONG, volid,
               AUD_END);
-    return errorcode;
+    return code;
 }
 
 
@@ -868,31 +959,32 @@ SVL_UpdateEntry(struct rx_call *rxcall,
                struct VldbUpdateEntry *updateentry,    /* Update entry copied here */
                afs_int32 releasetype)
 {
+    int this_op = VLUPDATEENTRY;
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode;
+    afs_int32 blockindex, code;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLUPDATEENTRY);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        END(VL_BADVOLTYPE);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
 
     /* Do the actual updating of the entry, tentry. */
-    if ((errorcode =
+    if ((code =
        get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
        goto abort;
     }
@@ -904,13 +996,13 @@ SVL_UpdateEntry(struct rx_call *rxcall,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, volid,
+    osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, volid,
               AUD_END);
-    return errorcode;
+    return code;
 }
 
 
@@ -920,27 +1012,28 @@ SVL_UpdateEntryByName(struct rx_call *rxcall,
                      struct VldbUpdateEntry *updateentry, /* Update entry copied here */
                      afs_int32 releasetype)
 {
+    int this_op = VLUPDATEENTRYBYNAME;
     struct vl_ctx ctx;
-    afs_int32 blockindex, errorcode;
+    afs_int32 blockindex, code;
     struct nvlentry tentry;
 
-    COUNT_REQ(VLUPDATEENTRYBYNAME);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
-    blockindex = FindByName(&ctx, volname, &tentry, &errorcode);
+    blockindex = FindByName(&ctx, volname, &tentry, &code);
     if (blockindex == 0) {     /* entry not found */
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
 
     /* Do the actual updating of the entry, tentry. */
-    if ((errorcode =
+    if ((code =
        get_vldbupdateentry(&ctx, blockindex, updateentry, &tentry))) {
        goto abort;
     }
@@ -952,12 +1045,12 @@ SVL_UpdateEntryByName(struct rx_call *rxcall,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLUpdateEntryEvent, errorcode, AUD_LONG, -1, AUD_END);
-    return errorcode;
+    osi_auditU(rxcall, VLUpdateEntryEvent, code, AUD_LONG, -1, AUD_END);
+    return code;
 }
 
 
@@ -966,26 +1059,27 @@ afs_int32
 SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
            afs_int32 voloper)
 {
-    afs_int32 timestamp, blockindex, errorcode;
+    int this_op = VLSETLOCK;
+    afs_int32 timestamp, blockindex, code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLSETLOCK);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        END(VL_BADVOLTYPE);
     if (InvalidOperation(voloper))
        END(VL_BADVOLOPER);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == NULLO) {
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
     if (tentry.flags & VLDELETED) {
@@ -1016,12 +1110,12 @@ SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLSetLockEvent, errorcode, AUD_LONG, volid, AUD_END);
-    return errorcode;
+    osi_auditU(rxcall, VLSetLockEvent, code, AUD_LONG, volid, AUD_END);
+    return code;
 }
 
 
@@ -1033,26 +1127,27 @@ afs_int32
 SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
                afs_int32 releasetype)
 {
-    afs_int32 blockindex, errorcode;
+    int this_op = VLRELEASELOCK;
+    afs_int32 blockindex, code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLRELEASELOCK);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        END(VL_BADVOLTYPE);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
+    if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
        goto end;
 
     VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
-    blockindex = FindByID(&ctx, volid, voltype, &tentry, &errorcode);
+    blockindex = FindByID(&ctx, volid, voltype, &tentry, &code);
     if (blockindex == NULLO) {
-       if (!errorcode)
-           errorcode = VL_NOENT;
+       if (!code)
+           code = VL_NOENT;
        goto abort;
     }
     if (tentry.flags & VLDELETED) {
@@ -1066,13 +1161,13 @@ SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
     END(ubik_EndTrans(ctx.trans));
 
   abort:
-    COUNT_ABO;
+    countAbort(this_op);
     ubik_AbortTrans(ctx.trans);
 
   end:
-    osi_auditU(rxcall, VLReleaseLockEvent, errorcode, AUD_LONG, volid,
+    osi_auditU(rxcall, VLReleaseLockEvent, code, AUD_LONG, volid,
               AUD_END);
-    return errorcode;
+    return code;
 }
 
 
@@ -1085,19 +1180,26 @@ SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
              afs_int32 *count, afs_int32 *next_index,
              struct vldbentry *aentry)
 {
-    int errorcode;
+    int this_op = VLLISTENTRY;
+    int code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLLISTENTRY);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    countRequest(this_op);
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     VLog(25, ("OListEntry index=%d %s\n", previous_index,
               rxinfo(rxstr, rxcall)));
     *next_index = NextEntry(&ctx, previous_index, &tentry, count);
-    if (*next_index)
-       vlentry_to_vldbentry(&ctx, &tentry, aentry);
+    if (*next_index) {
+       code = vlentry_to_vldbentry(&ctx, &tentry, aentry);
+       if (code) {
+           countAbort(this_op);
+           ubik_AbortTrans(ctx.trans);
+           return code;
+       }
+    }
     return (ubik_EndTrans(ctx.trans));
 }
 
@@ -1110,18 +1212,26 @@ SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
               afs_int32 *count, afs_int32 *next_index,
               struct nvldbentry *aentry)
 {
-    int errorcode;
+    int this_op = VLLISTENTRYN;
+    int code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLLISTENTRYN);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    countRequest(this_op);
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     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(&ctx, &tentry, aentry);
+    if (*next_index) {
+       code = vlentry_to_nvldbentry(&ctx, &tentry, aentry);
+       if (code) {
+           countAbort(this_op);
+           ubik_AbortTrans(ctx.trans);
+           return code;
+       }
+    }
+
     return (ubik_EndTrans(ctx.trans));
 }
 
@@ -1138,25 +1248,25 @@ SVL_ListAttributes(struct rx_call *rxcall,
                   afs_int32 *nentries,
                   bulkentries *vldbentries)
 {
-    int errorcode, allocCount = 0;
+    int this_op = VLLISTATTRIBUTES;
+    int code, allocCount = 0;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
     int pollcount = 0;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLLISTATTRIBUTES);
+    countRequest(this_op);
     vldbentries->bulkentries_val = 0;
     vldbentries->bulkentries_len = *nentries = 0;
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
        (vldbentry *) malloc(allocCount * sizeof(vldbentry));
     if (Vldbentry == NULL) {
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOMEM;
+       code = VL_NOMEM;
+       goto abort;
     }
     VldbentryLast = VldbentryFirst + allocCount;
     /* Handle the attribute by volume id totally separate of the rest
@@ -1165,29 +1275,18 @@ SVL_ListAttributes(struct rx_call *rxcall,
        afs_int32 blockindex;
 
        blockindex =
-           FindByID(&ctx, attributes->volumeid, -1, &tentry, &errorcode);
+           FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
        if (blockindex == 0) {
-           if (!errorcode)
-               errorcode = VL_NOENT;
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           if (vldbentries->bulkentries_val)
-               free((char *)vldbentries->bulkentries_val);
-           vldbentries->bulkentries_val = 0;
-           vldbentries->bulkentries_len = 0;
-           return errorcode;
-       }
-       if ((errorcode =
-           put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast,
-                              vldbentries, &tentry, nentries, &allocCount))) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           if (vldbentries->bulkentries_val)
-               free((char *)vldbentries->bulkentries_val);
-           vldbentries->bulkentries_val = 0;
-           vldbentries->bulkentries_len = 0;
-           return VL_SIZEEXCEEDED;
+           if (!code)
+               code = VL_NOENT;
+           goto abort;
        }
+
+       code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
+                                 &VldbentryLast, vldbentries, &tentry,
+                                 nentries, &allocCount);
+       if (code)
+           goto abort;
     } else {
        afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
        while ((nextblockindex =
@@ -1238,18 +1337,11 @@ SVL_ListAttributes(struct rx_call *rxcall,
                if (!(tentry.flags & attributes->flag))
                    continue;
            }
-           if ((errorcode =
-               put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
-                                  &VldbentryLast, vldbentries, &tentry,
-                                  nentries, &allocCount))) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               if (vldbentries->bulkentries_val)
-                   free((char *)vldbentries->bulkentries_val);
-               vldbentries->bulkentries_val = 0;
-               vldbentries->bulkentries_len = 0;
-               return errorcode;
-           }
+           code = put_attributeentry(&ctx, &Vldbentry, &VldbentryFirst,
+                                     &VldbentryLast, vldbentries, &tentry,
+                                     nentries, &allocCount);
+           if (code)
+               goto abort;
        }
     }
     if (vldbentries->bulkentries_len
@@ -1260,15 +1352,25 @@ SVL_ListAttributes(struct rx_call *rxcall,
                                  vldbentries->bulkentries_len *
                                  sizeof(vldbentry));
        if (vldbentries->bulkentries_val == NULL) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOMEM;
+           code = VL_NOMEM;
+           goto abort;
        }
     }
     VLog(5,
         ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
          rxinfo(rxstr, rxcall)));
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    if (vldbentries->bulkentries_val)
+       free(vldbentries->bulkentries_val);
+    vldbentries->bulkentries_val = 0;
+    vldbentries->bulkentries_len = 0;
+
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+
+    return code;
 }
 
 afs_int32
@@ -1277,25 +1379,25 @@ SVL_ListAttributesN(struct rx_call *rxcall,
                    afs_int32 *nentries,
                    nbulkentries *vldbentries)
 {
-    int errorcode, allocCount = 0;
+    int this_op = VLLISTATTRIBUTESN;
+    int code, allocCount = 0;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
     int pollcount = 0;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLLISTATTRIBUTESN);
+    countRequest(this_op);
     vldbentries->nbulkentries_val = 0;
     vldbentries->nbulkentries_len = *nentries = 0;
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
        (nvldbentry *) malloc(allocCount * sizeof(nvldbentry));
     if (Vldbentry == NULL) {
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOMEM;
+       code = VL_NOMEM;
+       goto abort;
     }
     VldbentryLast = VldbentryFirst + allocCount;
     /* Handle the attribute by volume id totally separate of the rest
@@ -1304,30 +1406,18 @@ SVL_ListAttributesN(struct rx_call *rxcall,
        afs_int32 blockindex;
 
        blockindex =
-           FindByID(&ctx, attributes->volumeid, -1, &tentry, &errorcode);
+           FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
        if (blockindex == 0) {
-           if (!errorcode)
-               errorcode = VL_NOENT;
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           if (vldbentries->nbulkentries_val)
-               free((char *)vldbentries->nbulkentries_val);
-           vldbentries->nbulkentries_val = 0;
-           vldbentries->nbulkentries_len = 0;
-           return errorcode;
-       }
-       if ((errorcode =
-           put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst, &VldbentryLast,
-                               vldbentries, &tentry, 0, 0, nentries,
-                               &allocCount))) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           if (vldbentries->nbulkentries_val)
-               free((char *)vldbentries->nbulkentries_val);
-           vldbentries->nbulkentries_val = 0;
-           vldbentries->nbulkentries_len = 0;
-           return VL_SIZEEXCEEDED;
+           if (!code)
+               code = VL_NOENT;
+           goto abort;
        }
+
+       code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
+                                  &VldbentryLast, vldbentries, &tentry,
+                                  0, 0, nentries, &allocCount);
+       if (code)
+           goto abort;
     } else {
        afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
        while ((nextblockindex =
@@ -1379,18 +1469,11 @@ SVL_ListAttributesN(struct rx_call *rxcall,
                if (!(tentry.flags & attributes->flag))
                    continue;
            }
-           if ((errorcode =
-               put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
-                                   &VldbentryLast, vldbentries, &tentry, 0,
-                                   0, nentries, &allocCount))) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               if (vldbentries->nbulkentries_val)
-                   free((char *)vldbentries->nbulkentries_val);
-               vldbentries->nbulkentries_val = 0;
-               vldbentries->nbulkentries_len = 0;
-               return errorcode;
-           }
+           code = put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
+                                      &VldbentryLast, vldbentries,
+                                      &tentry, 0, 0, nentries, &allocCount);
+           if (code)
+               goto abort;
        }
     }
     if (vldbentries->nbulkentries_len
@@ -1401,15 +1484,23 @@ SVL_ListAttributesN(struct rx_call *rxcall,
                                   vldbentries->nbulkentries_len *
                                   sizeof(nvldbentry));
        if (vldbentries->nbulkentries_val == NULL) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOMEM;
+           code = VL_NOMEM;
+           goto abort;
        }
     }
     VLog(5,
         ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
          rxinfo(rxstr, rxcall)));
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    if (vldbentries->nbulkentries_val)
+       free(vldbentries->nbulkentries_val);
+    vldbentries->nbulkentries_val = 0;
+    vldbentries->nbulkentries_len = 0;
+    return code;
 }
 
 
@@ -1422,7 +1513,8 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
                     nbulkentries *vldbentries,
                     afs_int32 *nextstartindex)
 {
-    int errorcode = 0, maxCount = VLDBALLOCCOUNT;
+    int this_op = VLLISTATTRIBUTESN2;
+    int code = 0, maxCount = VLDBALLOCCOUNT;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
@@ -1442,20 +1534,20 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
     char *t;
 #endif
 
-    COUNT_REQ(VLLISTATTRIBUTESN2);
+    countRequest(this_op);
     vldbentries->nbulkentries_val = 0;
     vldbentries->nbulkentries_len = 0;
     *nentries = 0;
     *nextstartindex = -1;
 
-    errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op);
-    if (errorcode)
-       return errorcode;
+    code = Init_VLdbase(&ctx, LOCKREAD, this_op);
+    if (code)
+       return code;
 
     Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
        (nvldbentry *) malloc(maxCount * sizeof(nvldbentry));
     if (Vldbentry == NULL) {
-       COUNT_ABO;
+       countAbort(this_op);
        ubik_AbortTrans(ctx.trans);
        return VL_NOMEM;
     }
@@ -1467,16 +1559,16 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
      */
     if (attributes->Mask & VLLIST_VOLUMEID) {
        blockindex =
-           FindByID(&ctx, attributes->volumeid, -1, &tentry, &errorcode);
+           FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
        if (blockindex == 0) {
-           if (!errorcode)
-               errorcode = VL_NOENT;
+           if (!code)
+               code = VL_NOENT;
        } else {
-           errorcode =
+           code =
                put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
                                    &VldbentryLast, vldbentries, &tentry, 0,
                                    0, nentries, &maxCount);
-           if (errorcode)
+           if (code)
                goto done;
        }
     }
@@ -1500,14 +1592,14 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
            sprintf(volumename, "^%s$", name);
 #ifdef HAVE_POSIX_REGEX
            if (regcomp(&re, volumename, REG_NOSUB) != 0) {
-               errorcode = VL_BADNAME;
+               code = VL_BADNAME;
                goto done;
            }
            need_regfree = 1;
 #else
            t = (char *)re_comp(volumename);
            if (t) {
-               errorcode = VL_BADNAME;
+               code = VL_BADNAME;
                goto done;
            }
 #endif
@@ -1643,12 +1735,12 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
 
            /* Passed all the tests. Take it */
            if (match) {
-               errorcode =
+               code =
                    put_nattributeentry(&ctx, &Vldbentry, &VldbentryFirst,
                                        &VldbentryLast, vldbentries, &tentry,
                                        matchtype, matchindex, nentries,
                                        &maxCount);
-               if (errorcode)
+               if (code)
                    goto done;
 
                if (*nentries >= maxCount)
@@ -1664,15 +1756,15 @@ SVL_ListAttributesN2(struct rx_call *rxcall,
        regfree(&re);
 #endif
 
-    if (errorcode) {
-       COUNT_ABO;
+    if (code) {
+       countAbort(this_op);
        ubik_AbortTrans(ctx.trans);
        if (vldbentries->nbulkentries_val)
            free((char *)vldbentries->nbulkentries_val);
        vldbentries->nbulkentries_val = 0;
        vldbentries->nbulkentries_len = 0;
        *nextstartindex = -1;
-       return errorcode;
+       return code;
     } else {
        VLog(5,
             ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
@@ -1694,7 +1786,8 @@ SVL_LinkedList(struct rx_call *rxcall,
               afs_int32 *nentries,
               vldb_list *vldbentries)
 {
-    int errorcode;
+    int this_op = VLLINKEDLIST;
+    int code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     vldblist vllist, *vllistptr;
@@ -1703,9 +1796,9 @@ SVL_LinkedList(struct rx_call *rxcall,
     int serverindex;
     int pollcount = 0;
 
-    COUNT_REQ(VLLINKEDLIST);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    countRequest(this_op);
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
 
     *nentries = 0;
     vldbentries->node = NULL;
@@ -1714,20 +1807,22 @@ SVL_LinkedList(struct rx_call *rxcall,
     /* List by volumeid */
     if (attributes->Mask & VLLIST_VOLUMEID) {
        blockindex =
-           FindByID(&ctx, attributes->volumeid, -1, &tentry, &errorcode);
+           FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
        if (!blockindex) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return (errorcode ? errorcode : VL_NOENT);
+           if (!code)
+               code = VL_NOENT;
+           goto abort;
        }
 
        vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
        if (vllist == NULL) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOMEM;
+           code = VL_NOMEM;
+           goto abort;
        }
-       vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       if (code)
+           goto abort;
+
        vllist->next_vldb = NULL;
 
        *vllistptr = vllist;    /* Thread onto list */
@@ -1794,25 +1889,31 @@ SVL_LinkedList(struct rx_call *rxcall,
 
            vllist = (single_vldbentry *) malloc(sizeof(single_vldbentry));
            if (vllist == NULL) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               return VL_NOMEM;
+               code = VL_NOMEM;
+               goto abort;
            }
-           vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           code = vlentry_to_vldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           if (code)
+               goto abort;
+
            vllist->next_vldb = NULL;
 
            *vllistptr = vllist;        /* Thread onto list */
            vllistptr = &vllist->next_vldb;
            (*nentries)++;
            if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               return VL_SIZEEXCEEDED;
+               code = VL_SIZEEXCEEDED;
+               goto abort;
            }
        }
     }
     *vllistptr = NULL;
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 afs_int32
@@ -1821,7 +1922,8 @@ SVL_LinkedListN(struct rx_call *rxcall,
                afs_int32 *nentries,
                nvldb_list *vldbentries)
 {
-    int errorcode;
+    int this_op = VLLINKEDLISTN;
+    int code;
     struct vl_ctx ctx;
     struct nvlentry tentry;
     nvldblist vllist, *vllistptr;
@@ -1830,9 +1932,9 @@ SVL_LinkedListN(struct rx_call *rxcall,
     int serverindex;
     int pollcount = 0;
 
-    COUNT_REQ(VLLINKEDLISTN);
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    countRequest(this_op);
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
 
     *nentries = 0;
     vldbentries->node = NULL;
@@ -1841,20 +1943,22 @@ SVL_LinkedListN(struct rx_call *rxcall,
     /* List by volumeid */
     if (attributes->Mask & VLLIST_VOLUMEID) {
        blockindex =
-           FindByID(&ctx, attributes->volumeid, -1, &tentry, &errorcode);
+           FindByID(&ctx, attributes->volumeid, -1, &tentry, &code);
        if (!blockindex) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return (errorcode ? errorcode : VL_NOENT);
+           if (!code)
+               code = VL_NOENT;
+           goto abort;
        }
 
        vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
        if (vllist == NULL) {
-           COUNT_ABO;
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOMEM;
+           code = VL_NOMEM;
+           goto abort;
        }
-       vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+       if (code)
+           goto abort;
+
        vllist->next_vldb = NULL;
 
        *vllistptr = vllist;    /* Thread onto list */
@@ -1921,25 +2025,31 @@ SVL_LinkedListN(struct rx_call *rxcall,
 
            vllist = (single_nvldbentry *) malloc(sizeof(single_nvldbentry));
            if (vllist == NULL) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               return VL_NOMEM;
+               code = VL_NOMEM;
+               goto abort;
            }
-           vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           code = vlentry_to_nvldbentry(&ctx, &tentry, &vllist->VldbEntry);
+           if (code)
+               goto abort;
+
            vllist->next_vldb = NULL;
 
            *vllistptr = vllist;        /* Thread onto list */
            vllistptr = &vllist->next_vldb;
            (*nentries)++;
            if (smallMem && (*nentries >= VLDBALLOCCOUNT)) {
-               COUNT_ABO;
-               ubik_AbortTrans(ctx.trans);
-               return VL_SIZEEXCEEDED;
+               code = VL_SIZEEXCEEDED;
+               goto abort;
            }
        }
     }
     *vllistptr = NULL;
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 /* Get back vldb header statistics (allocs, frees, maxvolumeid,
@@ -1951,18 +2061,19 @@ SVL_GetStats(struct rx_call *rxcall,
             vldstats *stats,
             vital_vlheader *vital_header)
 {
-    afs_int32 errorcode;
+    int this_op = VLGETSTATS;
+    afs_int32 code;
     struct vl_ctx ctx;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLGETSTATS);
+    countRequest(this_op);
 #ifdef notdef
     /* Allow users to get statistics freely */
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))        /* Must be in 'UserList' to use */
        return VL_PERM;
 #endif
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
     VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
     memcpy((char *)vital_header, (char *)&ctx.cheader->vital_header,
           sizeof(vital_vlheader));
@@ -1982,18 +2093,19 @@ SVL_GetAddrs(struct rx_call *rxcall,
             afs_int32 *nentries,
             bulkaddrs *addrsp)
 {
-    afs_int32 errorcode;
+    int this_op = VLGETADDRS;
+    afs_int32 code;
     struct vl_ctx ctx;
     int nservers, i;
     afs_uint32 *taddrp;
 
-    COUNT_REQ(VLGETADDRS);
+    countRequest(this_op);
     addrsp->bulkaddrs_len = *nentries = 0;
     addrsp->bulkaddrs_val = 0;
     memset(spare3, 0, sizeof(struct VLCallBack));
 
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
 
     VLog(5, ("GetAddrs\n"));
     addrsp->bulkaddrs_val = taddrp =
@@ -2001,9 +2113,8 @@ SVL_GetAddrs(struct rx_call *rxcall,
     nservers = *nentries = addrsp->bulkaddrs_len = 0;
 
     if (!taddrp) {
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOMEM;
+       code = VL_NOMEM;
+       goto abort;
     }
 
     for (i = 0; i <= MAXSERVERID; i++) {
@@ -2015,6 +2126,11 @@ SVL_GetAddrs(struct rx_call *rxcall,
 
     addrsp->bulkaddrs_len = *nentries = nservers;
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
@@ -2023,20 +2139,21 @@ afs_int32
 SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
                  bulkaddrs *addrsp)
 {
+    int this_op = VLREGADDR;
     afs_int32 code;
     struct vl_ctx ctx;
-    int cnt, h, i, j, k, m, base, index;
+    int cnt, h, i, j, k, m;
     struct extentaddr *exp = 0, *tex;
     afsUUID tuuid;
     afs_uint32 addrs[VL_MAXIPADDRS_PERMH];
-    afs_int32 fbase;
+    int base;
     int count, willChangeEntry, foundUuidEntry, willReplaceCnt;
     int WillReplaceEntry, WillChange[MAXSERVERID + 1];
     int FoundUuid = 0;
     int ReplaceEntry = 0;
     int srvidx, mhidx;
 
-    COUNT_REQ(VLREGADDR);
+    countRequest(this_op);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        return (VL_PERM);
     if ((code = Init_VLdbase(&ctx, LOCKWRITE, this_op)))
@@ -2062,8 +2179,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        }
     }
     if (cnt <= 0) {
-       ubik_AbortTrans(ctx.trans);
-       return VL_INDEXERANGE;
+       code = VL_INDEXERANGE;
+       goto abort;
     }
 
     count = 0;
@@ -2073,31 +2190,12 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     for (srvidx = 0; srvidx <= MAXSERVERID; srvidx++) {
        willChangeEntry = 0;
        WillReplaceEntry = 1;
-       if ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) {
-           /* The server is registered as a multihomed */
-           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",
-                     base, index));
-               continue;
-           }
-           if (index >= VL_MHSRV_PERBLK) {
-               VLog(0,
-                    ("Internal error: Multihome extent index is too large. Base %d index %d\n",
-                     base, index));
-               continue;
-           }
-           if (!ctx.ex_addr[base]) {
-               VLog(0,
-                    ("Internal error: Multihome extent does not exist. Base %d\n",
-                     base));
-               continue;
-           }
+       code = multiHomedExtent(&ctx, srvidx, &exp);
+       if (code)
+            continue;
 
+       if (exp) {
            /* See if the addresses to register will change this server entry */
-           exp = &ctx.ex_addr[base][index];
            tuuid = exp->ex_hostuuid;
            afs_ntohuuid(&tuuid);
            if (afs_uuid_equal(uuidp, &tuuid)) {
@@ -2159,20 +2257,20 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        VLog(0,("]\n"));
 
        if (foundUuidEntry) {
-           VLog(0,
-                ("   It would have replaced the existing VLDB server entry:\n"));
-           VLog(0, ("      entry %d: [", FoundUuid));
-           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;
-               if (mhidx > 0)
-                   VLog(0,(" "));
-               PADDR(ntohl(exp->ex_addrs[mhidx]));
+           code = multiHomedExtent(&ctx, FoundUuid, &exp);
+           if (code == 0) {
+               VLog(0, ("   It would have replaced the existing VLDB server "
+                        "entry:\n"));
+               VLog(0, ("      entry %d: [", FoundUuid));
+               for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
+                   if (!exp->ex_addrs[mhidx])
+                       continue;
+                   if (mhidx > 0)
+                       VLog(0,(" "));
+                   PADDR(ntohl(exp->ex_addrs[mhidx]));
+               }
+               VLog(0, ("]\n"));
            }
-           VLog(0, ("]\n"));
        }
 
        if (count == 1)
@@ -2182,11 +2280,13 @@ 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 ((ctx.hostaddress[srvidx] & 0xff000000) == 0xff000000) {
+
+           code = multiHomedExtent(&ctx, srvidx, &exp);
+           if (code)
+               goto abort;
+
+           if (exp) {
                VLog(0, ("["));
-               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;
@@ -2211,8 +2311,8 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
                ("   and/or remove the sysid file from the registering fileserver\n"));
        VLog(0, ("   before the fileserver can be registered in the VLDB.\n"));
 
-       ubik_AbortTrans(ctx.trans);
-       return VL_MULTIPADDR;
+       code = VL_MULTIPADDR;
+       goto abort;
     }
 
     /* Passed the checks. Now find and update the existing mh entry, or create
@@ -2222,9 +2322,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 = (ctx.hostaddress[FoundUuid] >> 16) & 0xff;
-       index = ctx.hostaddress[FoundUuid] & 0x0000ffff;
-       exp = &ctx.ex_addr[fbase][index];
+       code = multiHomedExtentBase(&ctx, FoundUuid, &exp, &base);
+       if (code)
+           goto abort;
 
        /* Determine if the entry has changed */
        for (k = 0; ((k < cnt) && !change); k++) {
@@ -2271,11 +2371,11 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        }
 
        /* Have an entry that needs to be replaced */
-       if ((ctx.hostaddress[ReplaceEntry] & 0xff000000) == 0xff000000) {
-           fbase = (ctx.hostaddress[ReplaceEntry] >> 16) & 0xff;
-           index = ctx.hostaddress[ReplaceEntry] & 0x0000ffff;
-           exp = &ctx.ex_addr[fbase][index];
+       code = multiHomedExtentBase(&ctx, ReplaceEntry, &exp, &base);
+       if (code)
+           goto abort;
 
+       if (exp) {
            VLog(0,
                ("   It will replace the following existing entry in the VLDB (new uuid):\n"));
            VLog(0, ("      entry %d: [", ReplaceEntry));
@@ -2296,10 +2396,11 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
            VLog(0,(", in the VLDB (new uuid):\n"));
 
            code =
-               FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &fbase);
+               FindExtentBlock(&ctx, uuidp, 1, ReplaceEntry, &exp, &base);
            if (code || !exp) {
-               ubik_AbortTrans(ctx.trans);
-               return (code ? code : VL_IO);
+               if (!code)
+                   code = VL_IO;
+               goto abort;
            }
        }
     } else {
@@ -2307,10 +2408,11 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
         * 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);
+       code = FindExtentBlock(&ctx, uuidp, 1, -1, &exp, &base);
        if (code || !exp) {
-           ubik_AbortTrans(ctx.trans);
-           return (code ? code : VL_IO);
+           if (!code)
+               code = VL_IO;
+           goto abort;
        }
     }
 
@@ -2331,11 +2433,11 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
     /* Write the new mh entry out */
     if (vlwrite
        (ctx.trans,
-        DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[fbase]),
-                (char *)ctx.ex_addr[fbase], (char *)exp), (char *)exp,
+        DOFFSET(ntohl(ctx.ex_addr[0]->ex_contaddrs[base]),
+                (char *)ctx.ex_addr[base], (char *)exp), (char *)exp,
         sizeof(*exp))) {
-       ubik_AbortTrans(ctx.trans);
-       return VL_IO;
+       code = VL_IO;
+       goto abort;
     }
 
     /* Remove any common addresses from other mh entres. We know these entries
@@ -2349,9 +2451,9 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
        if (willReplaceCnt && (WillChange[i] == ReplaceEntry))
            continue;
 
-       base = (ctx.hostaddress[WillChange[i]] >> 16) & 0xff;
-       index = ctx.hostaddress[WillChange[i]] & 0x0000ffff;
-       tex = &ctx.ex_addr[fbase][index];
+       code = multiHomedExtentBase(&ctx, WillChange[i], &tex, &base);
+       if (code)
+           goto abort;
 
        if (++m == 1)
            VLog(0,
@@ -2386,12 +2488,17 @@ SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
            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;
+           code = VL_IO;
+           goto abort;
        }
     }
 
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 afs_int32
@@ -2402,7 +2509,8 @@ SVL_GetAddrsU(struct rx_call *rxcall,
              afs_int32 *nentries,
              bulkaddrs *addrsp)
 {
-    afs_int32 errorcode, index = -1, offset;
+    int this_op = VLGETADDRSU;
+    afs_int32 code, index = -1, offset;
     struct vl_ctx ctx;
     int nservers, i, j, base = 0;
     struct extentaddr *exp = 0;
@@ -2410,17 +2518,17 @@ SVL_GetAddrsU(struct rx_call *rxcall,
     afs_uint32 *taddrp, taddr;
     char rxstr[AFS_RXINFO_LEN];
 
-    COUNT_REQ(VLGETADDRSU);
+    countRequest(this_op);
     addrsp->bulkaddrs_len = *nentries = 0;
     addrsp->bulkaddrs_val = 0;
     VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
-    if ((errorcode = Init_VLdbase(&ctx, LOCKREAD, this_op)))
-       return errorcode;
+    if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
+       return code;
 
     if (attributes->Mask & VLADDR_IPADDR) {
        if (attributes->Mask & (VLADDR_INDEX | VLADDR_UUID)) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_BADMASK;
+           code = VL_BADMASK;
+           goto abort;
        }
        for (base = 0; base < VL_MAX_ADDREXTBLKS; base++) {
            if (!ctx.ex_addr[base])
@@ -2444,66 +2552,63 @@ SVL_GetAddrsU(struct rx_call *rxcall,
                break;
        }
        if (base >= VL_MAX_ADDREXTBLKS) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOENT;
+           code = VL_NOENT;
+           goto abort;
        }
     } else if (attributes->Mask & VLADDR_INDEX) {
        if (attributes->Mask & (VLADDR_IPADDR | VLADDR_UUID)) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_BADMASK;
+           code = VL_BADMASK;
+           goto abort;
        }
        index = attributes->index;
        if (index < 1 || index >= (VL_MAX_ADDREXTBLKS * VL_MHSRV_PERBLK)) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_INDEXERANGE;
+           code = VL_INDEXERANGE;
+           goto abort;
        }
        base = index / VL_MHSRV_PERBLK;
        offset = index % VL_MHSRV_PERBLK;
        if (offset == 0) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOENT;
+           code = VL_NOENT;
+           goto abort;
        }
        if (!ctx.ex_addr[base]) {
-           ubik_AbortTrans(ctx.trans);
-           return VL_INDEXERANGE;
+           code = VL_INDEXERANGE;
+           goto abort;
        }
        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;
+           code = VL_BADMASK;
+           goto abort;
        }
        if (!ctx.ex_addr[0]) {  /* mh servers probably aren't setup on this vldb */
-           ubik_AbortTrans(ctx.trans);
-           return VL_NOENT;
-       }
-       if ((errorcode =
-           FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base))) {
-           ubik_AbortTrans(ctx.trans);
-           return errorcode;
+           code = VL_NOENT;
+           goto abort;
        }
+       code = FindExtentBlock(&ctx, &attributes->uuid, 0, -1, &exp, &base);
+       if (code)
+           goto abort;
     } else {
-       ubik_AbortTrans(ctx.trans);
-       return VL_BADMASK;
+       code = VL_BADMASK;
+       goto abort;
     }
 
     if (exp == NULL) {
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOENT;
+       code = VL_NOENT;
+       goto abort;
     }
     addrsp->bulkaddrs_val = taddrp =
        (afs_uint32 *) malloc(sizeof(afs_int32) * (MAXSERVERID + 1));
     nservers = *nentries = addrsp->bulkaddrs_len = 0;
     if (!taddrp) {
-       COUNT_ABO;
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOMEM;
+       code = VL_NOMEM;
+       goto abort;
     }
     tuuid = exp->ex_hostuuid;
     afs_ntohuuid(&tuuid);
     if (afs_uuid_is_nil(&tuuid)) {
-       ubik_AbortTrans(ctx.trans);
-       return VL_NOENT;
+       code = VL_NOENT;
+       goto abort;
     }
     if (uuidpo)
        *uuidpo = tuuid;
@@ -2525,6 +2630,11 @@ SVL_GetAddrsU(struct rx_call *rxcall,
     }
     addrsp->bulkaddrs_len = *nentries = nservers;
     return (ubik_EndTrans(ctx.trans));
+
+abort:
+    countAbort(this_op);
+    ubik_AbortTrans(ctx.trans);
+    return code;
 }
 
 /* ============> End of Exported vldb RPC functions <============= */
@@ -2543,6 +2653,7 @@ put_attributeentry(struct vl_ctx *ctx,
 {
     vldbentry *reall;
     afs_int32 allo;
+    int code;
 
     if (*Vldbentry == *VldbentryLast) {
        if (smallMem)
@@ -2564,7 +2675,11 @@ put_attributeentry(struct vl_ctx *ctx,
        *VldbentryLast = *Vldbentry + allo;
        *alloccnt += allo;
     }
-    vlentry_to_vldbentry(ctx, entry, *Vldbentry);
+
+    code = vlentry_to_vldbentry(ctx, entry, *Vldbentry);
+    if (code)
+       return code;
+
     (*Vldbentry)++;
     (*nentries)++;
     vldbentries->bulkentries_len++;
@@ -2585,6 +2700,7 @@ put_nattributeentry(struct vl_ctx *ctx,
 {
     nvldbentry *reall;
     afs_int32 allo;
+    int code;
 
     if (*Vldbentry == *VldbentryLast) {
        if (smallMem)
@@ -2606,7 +2722,10 @@ put_nattributeentry(struct vl_ctx *ctx,
        *VldbentryLast = *Vldbentry + allo;
        *alloccnt += allo;
     }
-    vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
+    code = vlentry_to_nvldbentry(ctx, entry, *Vldbentry);
+    if (code)
+       return code;
+
     (*Vldbentry)->matchindex = (matchtype << 16) + matchindex;
     (*Vldbentry)++;
     (*nentries)++;
@@ -2620,12 +2739,12 @@ static int
 RemoveEntry(struct vl_ctx *ctx, afs_int32 entryptr,
            struct nvlentry *tentry)
 {
-    int errorcode;
+    int code;
 
-    if ((errorcode = UnthreadVLentry(ctx, entryptr, tentry)))
-       return errorcode;
-    if ((errorcode = FreeBlock(ctx, entryptr)))
-       return errorcode;
+    if ((code = UnthreadVLentry(ctx, entryptr, tentry)))
+       return code;
+    if ((code = FreeBlock(ctx, entryptr)))
+       return code;
     return 0;
 }
 
@@ -2755,7 +2874,7 @@ get_vldbupdateentry(struct vl_ctx *ctx,
                    struct VldbUpdateEntry *updateentry,
                    struct nvlentry *VlEntry)
 {
-    int i, j, errorcode, serverindex;
+    int i, j, code, serverindex;
     afs_uint32 checkids[MAXTYPES];
 
     /* check if any specified new IDs are already present in the db. Do
@@ -2772,10 +2891,10 @@ get_vldbupdateentry(struct vl_ctx *ctx,
        checkids[BACKVOL] = updateentry->BackupId;
     }
 
-    if (EntryIDExists(ctx, checkids, MAXTYPES, &errorcode)) {
+    if (EntryIDExists(ctx, checkids, MAXTYPES, &code)) {
        return VL_IDEXIST;
-    } else if (errorcode) {
-       return errorcode;
+    } else if (code) {
+       return code;
     }
 
     if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
@@ -2784,22 +2903,22 @@ get_vldbupdateentry(struct vl_ctx *ctx,
        if (InvalidVolname(updateentry->name))
            return VL_BADNAME;
 
-       if (FindByName(ctx, updateentry->name, &tentry, &errorcode)) {
+       if (FindByName(ctx, updateentry->name, &tentry, &code)) {
            return VL_NAMEEXIST;
-       } else if (errorcode) {
-           return errorcode;
+       } else if (code) {
+           return code;
        }
 
-       if ((errorcode = UnhashVolname(ctx, blockindex, VlEntry)))
-           return errorcode;
+       if ((code = UnhashVolname(ctx, blockindex, VlEntry)))
+           return code;
        strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
        HashVolname(ctx, blockindex, VlEntry);
     }
 
     if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
-       if ((errorcode = UnhashVolname(ctx, blockindex, VlEntry))) {
-           if (errorcode != VL_NOENT)
-               return errorcode;
+       if ((code = UnhashVolname(ctx, blockindex, VlEntry))) {
+           if (code != VL_NOENT)
+               return code;
        }
        HashVolname(ctx, blockindex, VlEntry);
     }
@@ -2811,31 +2930,31 @@ get_vldbupdateentry(struct vl_ctx *ctx,
        VlEntry->cloneId = updateentry->cloneId;
     }
     if (updateentry->Mask & VLUPDATE_RWID) {
-       if ((errorcode = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
-           if (errorcode != VL_NOENT)
-               return errorcode;
+       if ((code = UnhashVolid(ctx, RWVOL, blockindex, VlEntry))) {
+           if (code != VL_NOENT)
+               return code;
        }
        VlEntry->volumeId[RWVOL] = updateentry->spares3;        /* rw id */
-       if ((errorcode = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
-           return errorcode;
+       if ((code = HashVolid(ctx, RWVOL, blockindex, VlEntry)))
+           return code;
     }
     if (updateentry->Mask & VLUPDATE_READONLYID) {
-       if ((errorcode = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
-           if (errorcode != VL_NOENT)
-               return errorcode;
+       if ((code = UnhashVolid(ctx, ROVOL, blockindex, VlEntry))) {
+           if (code != VL_NOENT)
+               return code;
        }
        VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
-       if ((errorcode = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
-           return errorcode;
+       if ((code = HashVolid(ctx, ROVOL, blockindex, VlEntry)))
+           return code;
     }
     if (updateentry->Mask & VLUPDATE_BACKUPID) {
-       if ((errorcode = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
-           if (errorcode != VL_NOENT)
-               return errorcode;
+       if ((code = UnhashVolid(ctx, BACKVOL, blockindex, VlEntry))) {
+           if (code != VL_NOENT)
+               return code;
        }
        VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
-       if ((errorcode = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
-           return errorcode;
+       if ((code = HashVolid(ctx, BACKVOL, blockindex, VlEntry)))
+           return code;
     }
     if (updateentry->Mask & VLUPDATE_REPSITES) {
        if (updateentry->nModifiedRepsites <= 0
@@ -2981,25 +3100,23 @@ repsite_compress(struct nvlentry *VlEntry, int offset)
 
 /* Convert from the internal (compacted) vldb entry to the external
  * representation used by the interface. */
-static void
+static int
 vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                      struct vldbentry *VldbEntry)
 {
-    int i, j;
+    int i, j, code;
+    struct extentaddr *exp;
 
     memset(VldbEntry, 0, sizeof(struct vldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < OMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
-
-           base = (ctx->hostaddress[j] >> 16) & 0xff;
-           index = ctx->hostaddress[j] & 0x0000ffff;
-           exp = &ctx->ex_addr[base][index];
+       j = VlEntry->serverNumber[i];
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+       if (exp) {
            /* For now return the first ip address back */
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j]) {
@@ -3018,30 +3135,30 @@ vlentry_to_vldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
 
 /* Convert from the internal (compacted) vldb entry to the external
  * representation used by the interface. */
-static void
+static int
 vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                       struct nvldbentry *VldbEntry)
 {
-    int i, j;
+    int i, j, code;
+    struct extentaddr *exp;
 
-    memset(VldbEntry, 0, sizeof(struct vldbentry));
+    memset(VldbEntry, 0, sizeof(struct nvldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < NMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
-
-           base = (ctx->hostaddress[j] >> 16) & 0xff;
-           index = ctx->hostaddress[j] & 0x0000ffff;
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+
+       if (exp) {
            /* For now return the first ip address back */
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j]) {
@@ -3060,33 +3177,34 @@ vlentry_to_nvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
-static void
+static int
 vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
                       struct uvldbentry *VldbEntry)
 {
-    int i, j;
+    int i, code;
+    struct extentaddr *exp;
 
-    memset(VldbEntry, 0, sizeof(struct vldbentry));
+    memset(VldbEntry, 0, sizeof(struct uvldbentry));
     strncpy(VldbEntry->name, VlEntry->name, sizeof(VldbEntry->name));
     for (i = 0; i < NMAXNSERVERS; i++) {
        if (VlEntry->serverNumber[i] == BADSERVERID)
            break;
        VldbEntry->serverFlags[i] = VlEntry->serverFlags[i];
        VldbEntry->serverUnique[i] = 0;
-       if ((ctx->hostaddress[j = VlEntry->serverNumber[i]] & 0xff000000) ==
-           0xff000000) {
-           struct extentaddr *exp;
-           int base, index;
+       code = multiHomedExtent(ctx, VlEntry->serverNumber[i], &exp);
+       if (code)
+           return code;
+
+       if (exp) {
            afsUUID tuuid;
 
-           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;
+           VldbEntry->serverFlags[i] |= VLSF_UUID;
            VldbEntry->serverNumber[i] = tuuid;
            VldbEntry->serverUnique[i] = ntohl(exp->ex_uniquifier);
        } else {
@@ -3101,6 +3219,8 @@ vlentry_to_uvldbentry(struct vl_ctx *ctx, struct nvlentry *VlEntry,
        VldbEntry->volumeId[i] = VlEntry->volumeId[i];
     VldbEntry->cloneId = VlEntry->cloneId;
     VldbEntry->flags = VlEntry->flags;
+
+    return 0;
 }
 
 #define LEGALCHARS ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
@@ -3154,34 +3274,16 @@ static int
 IpAddrToRelAddr(struct vl_ctx *ctx, afs_uint32 ipaddr, int create)
 {
     int i, j;
-    afs_int32 code, base, index;
+    afs_int32 code;
     struct extentaddr *exp;
 
     for (i = 0; i <= MAXSERVERID; i++) {
        if (ctx->hostaddress[i] == ipaddr)
            return i;
-       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",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
-           if (index >= VL_MHSRV_PERBLK) {
-               VLog(0,
-                    ("Internal error: Multihome extent index is too large. Base %d index %d\n",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
-           if (!ctx->ex_addr[base]) {
-               VLog(0,
-                    ("Internal error: Multihome extent does not exist. Base %d\n",
-                     base));
-               return -1;      /* EINVAL */
-           }
-           exp = &ctx->ex_addr[base][index];
+       code = multiHomedExtent(ctx, i, &exp);
+       if (code)
+           return -1;
+       if (exp) {
            for (j = 0; j < VL_MAXIPADDRS_PERMH; j++) {
                if (exp->ex_addrs[j] && (ntohl(exp->ex_addrs[j]) == ipaddr)) {
                    return i;
@@ -3216,8 +3318,8 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
     int i, j;
     afs_int32 code;
     struct extentaddr *exp = NULL;
-    int base = 0;
-    int index, mhidx;
+    int base;
+    int mhidx;
     afsUUID tuuid;
     afs_int32 blockindex, count;
     int pollcount = 0;
@@ -3240,17 +3342,11 @@ ChangeIPAddr(struct vl_ctx *ctx, afs_uint32 ipaddr1, afs_uint32 ipaddr2)
     }
 
     for (i = 0; i <= MAXSERVERID; i++) {
-       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",
-                     base, index));
-               return -1;      /* EINVAL */
-           }
+       code = multiHomedExtentBase(ctx, i, &exp, &base);
+       if (code)
+           return code;
 
-           exp = &ctx->ex_addr[base][index];
+       if (exp) {
            for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
                if (!exp->ex_addrs[mhidx])
                    continue;