vlserver: prevent duplicate IPs via ChangeAddr
[openafs.git] / src / vlserver / vlprocs.c
index d052b64..0bd0c01 100644 (file)
 #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
 
 extern int smallMem;
-extern extent_mod;
+extern int extent_mod;
 extern struct afsconf_dir *vldb_confdir;
 extern struct ubik_dbase *VL_dbase;
 struct vlheader cheader;       /* kept in network byte order */
 extern afs_uint32 HostAddress[];       /* host addresses kept in host byte order */
 int maxnservers;
 struct extentaddr *ex_addr[VL_MAX_ADDREXTBLKS] = { 0, 0, 0, 0 };
-static char rxinfo_str[128];   /* Need rxinfo string to be non-local */
 #define ABORT(c) { errorcode = (c); goto abort; }
 #undef END
 #define END(c) { errorcode = (c); goto end; }
@@ -50,36 +52,52 @@ static char rxinfo_str[128];        /* Need rxinfo string to be non-local */
 #define VLDBALLOCLIMIT 10000
 #define VLDBALLOCINCR  2048
 
-static int put_attributeentry();
-static int put_nattributeentry();
-static int RemoveEntry();
-static void ReleaseEntry();
-static int check_vldbentry();
-static int check_nvldbentry();
-static int vldbentry_to_vlentry();
-static int nvldbentry_to_vlentry();
-static get_vldbupdateentry();
-static int repsite_exists();
-static void repsite_compress();
-static void vlentry_to_vldbentry();
-static void vlentry_to_nvldbentry();
-static void vlentry_to_uvldbentry();
-static int InvalidVolname();
-static int InvalidVoltype();
-static int InvalidOperation();
-static int InvalidReleasetype();
-static int IpAddrToRelAddr();
-static int ChangeIPAddr();
-
-char *
-rxinfo(rxcall)
-     struct rx_call *rxcall;
+static int put_attributeentry(struct vldbentry **, struct vldbentry **,
+                             struct vldbentry **, bulkentries *,
+                             struct nvlentry *, afs_int32 *, afs_int32 *);
+static int put_nattributeentry(struct nvldbentry **, struct nvldbentry **,
+                              struct nvldbentry **, nbulkentries *,
+                              struct nvlentry *, afs_int32, afs_int32,
+                              afs_int32 *, afs_int32 *);
+static int RemoveEntry(struct ubik_trans *trans, afs_int32 entryptr,
+                      struct nvlentry *tentry);
+static void ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype);
+static int check_vldbentry(struct vldbentry *aentry);
+static int check_nvldbentry(struct nvldbentry *aentry);
+static int vldbentry_to_vlentry(struct ubik_trans *atrans,
+                               struct vldbentry *VldbEntry,
+                               struct nvlentry *VlEntry);
+static int nvldbentry_to_vlentry(struct ubik_trans *atrans,
+                                struct nvldbentry *VldbEntry,
+                                struct nvlentry *VlEntry);
+static int get_vldbupdateentry(struct ubik_trans *trans, afs_int32 blockindex,
+                              struct VldbUpdateEntry *updateentry,
+                              struct nvlentry *VlEntry);
+static int repsite_exists(struct nvlentry *VlEntry, int server, int partition);
+static void repsite_compress(struct nvlentry *VlEntry, int offset);
+static void vlentry_to_vldbentry(struct nvlentry *VlEntry,
+                                struct vldbentry *VldbEntry);
+static void vlentry_to_nvldbentry(struct nvlentry *VlEntry,
+                                 struct nvldbentry *VldbEntry);
+static void vlentry_to_uvldbentry(struct nvlentry *VlEntry,
+                                 struct uvldbentry *VldbEntry);
+static int InvalidVolname(char *volname);
+static int InvalidVoltype(afs_int32 voltype);
+static int InvalidOperation(afs_int32 voloper);
+static int InvalidReleasetype(afs_int32 releasetype);
+static int IpAddrToRelAddr(afs_uint32 ipaddr, struct ubik_trans *atrans);
+static int ChangeIPAddr(afs_uint32 ipaddr1, afs_uint32 ipaddr2,
+                       struct ubik_trans *atrans);
+
+#define AFS_RXINFO_LEN 128
+static char *
+rxinfo(char * str, struct rx_call *rxcall)
 {
     int code;
     register struct rx_connection *tconn;
-    char tname[64];
-    char tinst[64];
-    char tcell[64];
+    char tname[64] = "";
+    char tinst[64] = "";
+    char tcell[64] = "";
     afs_uint32 exp;
     struct in_addr hostAddr;
 
@@ -89,19 +107,21 @@ rxinfo(rxcall)
        rxkad_GetServerInfo(rxcall->conn, NULL, &exp, tname, tinst, tcell,
                            NULL);
     if (!code)
-       sprintf(rxinfo_str, "%s %s%s%s%s%s", inet_ntoa(hostAddr), tname,
-               tinst?".":"", tinst?tinst:"", tcell?"@":"", tcell?tcell:"");
+       sprintf(str, "%s %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(rxinfo_str, "%s noauth", inet_ntoa(hostAddr));
-    return (rxinfo_str);
+       sprintf(str, "%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(trans, locktype, this_op)
-     struct ubik_trans **trans;
-     int locktype;             /* indicate read or write transaction */
-     int this_op;
+Init_VLdbase(struct ubik_trans **trans,
+            int locktype,      /* indicate read or write transaction */
+            int this_op)
 {
     int errorcode = 0, pass, wl;
 
@@ -153,16 +173,17 @@ Init_VLdbase(trans, locktype, this_op)
 }
 
 
-/* Create a new vldb entry; both new volume id and name must be unique (non-existant in vldb). */
+/* Create a new vldb entry; both new volume id and name must be unique
+ * (non-existant in vldb).
+ */
 
 afs_int32
-SVL_CreateEntry(rxcall, newentry)
-     struct rx_call *rxcall;
-     struct vldbentry *newentry;
+SVL_CreateEntry(struct rx_call *rxcall, struct vldbentry *newentry)
 {
     struct ubik_trans *trans;
     afs_int32 errorcode, blockindex;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLCREATEENTRY);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
@@ -177,10 +198,9 @@ SVL_CreateEntry(rxcall, newentry)
 
     VLog(1,
         ("OCreate Volume %d %s\n", newentry->volumeId[RWVOL],
-         rxinfo(rxcall)));
-    /* XXX shouldn't we check to see if the r/o volume is duplicated? */
-    if (newentry->volumeId[RWVOL]
-       && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) {    /* entry already exists, we fail */
+         rxinfo(rxstr, rxcall)));
+    if (EntryIDExists(trans, newentry->volumeId, MAXTYPES, &errorcode)) {
+       /* at least one of the specified IDs already exists; we fail */
        errorcode = VL_IDEXIST;
        goto abort;
     } else if (errorcode) {
@@ -204,7 +224,7 @@ SVL_CreateEntry(rxcall, newentry)
 
     memset(&tentry, 0, sizeof(struct nvlentry));
     /* Convert to its internal representation; both in host byte order */
-    if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) {
+    if ((errorcode = vldbentry_to_vlentry(trans, newentry, &tentry))) {
        FreeBlock(trans, blockindex);
        goto abort;
     }
@@ -231,13 +251,12 @@ SVL_CreateEntry(rxcall, newentry)
 
 
 afs_int32
-SVL_CreateEntryN(rxcall, newentry)
-     struct rx_call *rxcall;
-     struct nvldbentry *newentry;
+SVL_CreateEntryN(struct rx_call *rxcall, struct nvldbentry *newentry)
 {
     struct ubik_trans *trans;
     afs_int32 errorcode, blockindex;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLCREATEENTRYN);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
@@ -252,10 +271,9 @@ SVL_CreateEntryN(rxcall, newentry)
 
     VLog(1,
         ("Create Volume %d %s\n", newentry->volumeId[RWVOL],
-         rxinfo(rxcall)));
-    /* XXX shouldn't we check to see if the r/o volume is duplicated? */
-    if (newentry->volumeId[RWVOL]
-       && FindByID(trans, newentry->volumeId[RWVOL], RWVOL, &tentry, &errorcode)) {    /* entry already exists, we fail */
+         rxinfo(rxstr, rxcall)));
+    if (EntryIDExists(trans, newentry->volumeId, MAXTYPES, &errorcode)) {
+       /* at least one of the specified IDs already exists; we fail */
        errorcode = VL_IDEXIST;
        goto abort;
     } else if (errorcode) {
@@ -279,7 +297,7 @@ SVL_CreateEntryN(rxcall, newentry)
 
     memset(&tentry, 0, sizeof(struct nvlentry));
     /* Convert to its internal representation; both in host byte order */
-    if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) {
+    if ((errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry))) {
        FreeBlock(trans, blockindex);
        goto abort;
     }
@@ -306,12 +324,11 @@ SVL_CreateEntryN(rxcall, newentry)
 
 
 afs_int32
-SVL_ChangeAddr(rxcall, ip1, ip2)
-     struct rx_call *rxcall;
-     afs_uint32 ip1, ip2;
+SVL_ChangeAddr(struct rx_call *rxcall, afs_uint32 ip1, afs_uint32 ip2)
 {
     struct ubik_trans *trans;
     afs_int32 errorcode;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLCHANGEADDR);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
@@ -319,11 +336,11 @@ SVL_ChangeAddr(rxcall, ip1, ip2)
        goto end;
     }
 
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxcall)));
-    if (errorcode = ChangeIPAddr(ip1, ip2, trans))
+    VLog(1, ("Change Addr %u -> %u %s\n", ip1, ip2, rxinfo(rxstr, rxcall)));
+    if ((errorcode = ChangeIPAddr(ip1, ip2, trans)))
        goto abort;
     else {
        errorcode = ubik_EndTrans(trans);
@@ -342,14 +359,12 @@ SVL_ChangeAddr(rxcall, ip1, ip2)
 
 /* Delete a vldb entry given the volume id. */
 afs_int32
-SVL_DeleteEntry(rxcall, volid, voltype)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
+SVL_DeleteEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLDELETEENTRY);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
@@ -358,10 +373,10 @@ SVL_DeleteEntry(rxcall, volid, voltype)
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        END(VL_BADVOLTYPE);
 
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("Delete Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == 0) {     /* volid not found */
        if (!errorcode)
@@ -372,7 +387,7 @@ SVL_DeleteEntry(rxcall, volid, voltype)
     if (tentry.flags & VLDELETED) {    /* Already deleted; return */
        ABORT(VL_ENTDELETED);
     }
-    if (errorcode = RemoveEntry(trans, blockindex, &tentry)) {
+    if ((errorcode = RemoveEntry(trans, blockindex, &tentry))) {
        goto abort;
     }
     errorcode = (ubik_EndTrans(trans));
@@ -390,22 +405,26 @@ SVL_DeleteEntry(rxcall, volid, voltype)
 
 
 /* Get a vldb entry given its volume id; make sure it's not a deleted entry. */
-GetEntryByID(rxcall, volid, voltype, aentry, new, this_op)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype, new, this_op;
-     char *aentry;             /* entry data copied here */
+int
+GetEntryByID(struct rx_call *rxcall,
+            afs_uint32 volid,
+            afs_int32 voltype,
+            char *aentry,      /* entry data copied here */
+            afs_int32 new,
+            afs_int32 this_op)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     if ((voltype != -1) && (InvalidVoltype(voltype)))
        return VL_BADVOLTYPE;
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
 
-    VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new, rxinfo(rxcall)));
+    VLog(5, ("GetVolumeByID %u (%d) %s\n", volid, new,
+             rxinfo(rxstr, rxcall)));
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == 0) {     /* entry not found */
        if (!errorcode)
@@ -430,33 +449,30 @@ GetEntryByID(rxcall, volid, voltype, aentry, new, this_op)
 }
 
 afs_int32
-SVL_GetEntryByID(rxcall, volid, voltype, aentry)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     vldbentry *aentry;                /* entry data copied here */
+SVL_GetEntryByID(struct rx_call *rxcall,
+                afs_uint32 volid,
+                afs_int32 voltype,
+                vldbentry *aentry)             /* entry data copied here */
 {
     COUNT_REQ(VLGETENTRYBYID);
     return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 0, this_op));
 }
 
 afs_int32
-SVL_GetEntryByIDN(rxcall, volid, voltype, aentry)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     nvldbentry *aentry;       /* entry data copied here */
+SVL_GetEntryByIDN(struct rx_call *rxcall,
+                 afs_uint32 volid,
+                 afs_int32 voltype,
+                 nvldbentry *aentry)   /* entry data copied here */
 {
     COUNT_REQ(VLGETENTRYBYIDN);
     return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 1, this_op));
 }
 
 afs_int32
-SVL_GetEntryByIDU(rxcall, volid, voltype, aentry)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     uvldbentry *aentry;       /* entry data copied here */
+SVL_GetEntryByIDU(struct rx_call *rxcall,
+                 afs_uint32 volid,
+                 afs_int32 voltype,
+                 uvldbentry *aentry)   /* entry data copied here */
 {
     COUNT_REQ(VLGETENTRYBYIDU);
     return (GetEntryByID(rxcall, volid, voltype, (char *)aentry, 2, this_op));
@@ -464,39 +480,41 @@ SVL_GetEntryByIDU(rxcall, volid, voltype, aentry)
 
 
 
-/* returns true if the id is a decimal integer, in which case we interpret it
-    as an id.  make the cache manager much simpler */
+/* 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
-NameIsId(aname)
-     register char *aname;
+NameIsId(char *aname)
 {
     register int tc;
-    while (tc = *aname++) {
+    while ((tc = *aname++)) {
        if (tc > '9' || tc < '0')
            return 0;
     }
     return 1;
 }
 
-/* Get a vldb entry given the volume's name; of course, very similar to VLGetEntryByID() above. */
-GetEntryByName(rxcall, volname, aentry, new, this_op)
-     struct rx_call *rxcall;
-     char *volname;
-     char *aentry;             /* entry data copied here */
-     int new, this_op;
+/* Get a vldb entry given the volume's name; of course, very similar to
+ * VLGetEntryByID() above. */
+afs_int32
+GetEntryByName(struct rx_call *rxcall,
+              char *volname,
+              char *aentry,            /* entry data copied here */
+              int new,
+              int this_op)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     if (NameIsId(volname)) {
        return GetEntryByID(rxcall, atoi(volname), -1, aentry, new, this_op);
     }
     if (InvalidVolname(volname))
        return VL_BADNAME;
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
-    VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxcall)));
+    VLog(5, ("GetVolumeByName %s (%d) %s\n", volname, new, rxinfo(rxstr, rxcall)));
     blockindex = FindByName(trans, volname, &tentry, &errorcode);
     if (blockindex == 0) {     /* entry not found */
        if (!errorcode)
@@ -521,10 +539,9 @@ GetEntryByName(rxcall, volname, aentry, new, this_op)
 }
 
 afs_int32
-SVL_GetEntryByNameO(rxcall, volname, aentry)
-     struct rx_call *rxcall;
-     char *volname;
-     struct vldbentry *aentry; /* entry data copied here */
+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));
@@ -532,20 +549,18 @@ SVL_GetEntryByNameO(rxcall, volname, aentry)
 
 
 afs_int32
-SVL_GetEntryByNameN(rxcall, volname, aentry)
-     struct rx_call *rxcall;
-     char *volname;
-     struct nvldbentry *aentry;        /* entry data copied here */
+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));
 }
 
 afs_int32
-SVL_GetEntryByNameU(rxcall, volname, aentry)
-     struct rx_call *rxcall;
-     char *volname;
-     struct uvldbentry *aentry;        /* entry data copied here */
+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));
@@ -555,14 +570,13 @@ SVL_GetEntryByNameU(rxcall, volname, aentry)
 
 /* Get the current value of the maximum volume id and bump the volume id counter by Maxvolidbump. */
 afs_int32
-SVL_GetNewVolumeId(rxcall, Maxvolidbump, newvolumeid)
-     struct rx_call *rxcall;
-     afs_uint32 Maxvolidbump;
-     afs_uint32 *newvolumeid;
+SVL_GetNewVolumeId(struct rx_call *rxcall, afs_uint32 Maxvolidbump,
+                  afs_uint32 *newvolumeid)
 {
-    register afs_int32 errorcode;
+    afs_int32 errorcode;
     afs_uint32 maxvolumeid;
     struct ubik_trans *trans;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLGETNEWVOLUMEID);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
@@ -571,12 +585,17 @@ SVL_GetNewVolumeId(rxcall, Maxvolidbump, newvolumeid)
     if (Maxvolidbump < 0 || Maxvolidbump > MAXBUMPCOUNT)
        END(VL_BADVOLIDBUMP);
 
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    *newvolumeid = maxvolumeid = ntohl(cheader.vital_header.MaxVolumeId);
+    *newvolumeid = maxvolumeid = NextUnusedID(trans,
+       ntohl(cheader.vital_header.MaxVolumeId), Maxvolidbump, &errorcode);
+    if (errorcode) {
+       goto abort;
+    }
+
     maxvolumeid += Maxvolidbump;
-    VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxcall)));
+    VLog(1, ("GetNewVolid newmax=%u %s\n", maxvolumeid, rxinfo(rxstr, rxcall)));
     cheader.vital_header.MaxVolumeId = htonl(maxvolumeid);
     if (write_vital_vlheader(trans)) {
        ABORT(VL_IO);
@@ -599,18 +618,16 @@ SVL_GetNewVolumeId(rxcall, Maxvolidbump, newvolumeid)
  * VLUpdateEntry) is done. */
 
 afs_int32
-SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     struct vldbentry *newentry;
-     afs_int32 releasetype;
+SVL_ReplaceEntry(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+                struct vldbentry *newentry, afs_int32 releasetype)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode, typeindex;
     int hashnewname;
     int hashVol[MAXTYPES];
     struct nvlentry tentry;
+    afs_uint32 checkids[MAXTYPES];
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLREPLACEENTRY);
     for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
@@ -619,7 +636,7 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
-    if (errorcode = check_vldbentry(newentry))
+    if ((errorcode = check_vldbentry(newentry)))
        goto end;
 
     if (voltype != -1 && InvalidVoltype(voltype))
@@ -627,10 +644,10 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
 
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("OReplace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == 0) {     /* entry not found */
@@ -644,14 +661,37 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
        ABORT(VL_BADENTRY);
     }
 
+    /* make sure none of the IDs we are changing to are already in use */
+    memset(&checkids, 0, sizeof(checkids));
+    for (typeindex = ROVOL; typeindex < MAXTYPES; typeindex++) {
+       if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
+           checkids[typeindex] = newentry->volumeId[typeindex];
+       }
+    }
+    if (EntryIDExists(trans, checkids, MAXTYPES, &errorcode)) {
+       ABORT(VL_IDEXIST);
+    } else if (errorcode) {
+       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(trans, newentry->name, &tmp_entry, &errorcode)) {
+           ABORT(VL_NAMEEXIST);
+       } else if (errorcode) {
+           goto abort;
+       }
+    }
+
     /* unhash volid entries if they're disappearing or changing.
      * Remember if we need to hash in the new value (we don't have to
      * rehash if volid stays same */
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
            if (tentry.volumeId[typeindex])
-               if (errorcode =
-                   UnhashVolid(trans, typeindex, blockindex, &tentry)) {
+               if ((errorcode =
+                   UnhashVolid(trans, typeindex, blockindex, &tentry))) {
                    goto abort;
                }
            /* we must rehash new id if the id is different and the ID is nonzero */
@@ -661,7 +701,7 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
 
     /* Rehash volname if it changes */
     if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
-       if (errorcode = UnhashVolname(trans, blockindex, &tentry)) {
+       if ((errorcode = UnhashVolname(trans, blockindex, &tentry))) {
            goto abort;
        }
        hashnewname = 1;
@@ -669,13 +709,13 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
 
     /* after this, tentry is new entry, not old one.  vldbentry_to_vlentry
      * doesn't touch hash chains */
-    if (errorcode = vldbentry_to_vlentry(trans, newentry, &tentry)) {
+    if ((errorcode = vldbentry_to_vlentry(trans, newentry, &tentry))) {
        goto abort;
     }
 
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
-           if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) {
+           if ((errorcode = HashVolid(trans, typeindex, blockindex, &tentry))) {
                goto abort;
            }
        }
@@ -703,18 +743,15 @@ SVL_ReplaceEntry(rxcall, volid, voltype, newentry, releasetype)
 }
 
 afs_int32
-SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     struct nvldbentry *newentry;
-     afs_int32 releasetype;
+SVL_ReplaceEntryN(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+                 struct nvldbentry *newentry, afs_int32 releasetype)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode, typeindex;
     int hashnewname;
     int hashVol[MAXTYPES];
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLREPLACEENTRYN);
     for (typeindex = 0; typeindex < MAXTYPES; typeindex++)
@@ -723,7 +760,7 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        END(VL_PERM);
 
-    if (errorcode = check_nvldbentry(newentry))
+    if ((errorcode = check_nvldbentry(newentry)))
        goto end;
 
     if (voltype != -1 && InvalidVoltype(voltype))
@@ -731,10 +768,10 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
 
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("Replace Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     /* find vlentry we're changing */
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == 0) {     /* entry not found */
@@ -754,8 +791,8 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (tentry.volumeId[typeindex] != newentry->volumeId[typeindex]) {
            if (tentry.volumeId[typeindex])
-               if (errorcode =
-                   UnhashVolid(trans, typeindex, blockindex, &tentry)) {
+               if ((errorcode =
+                   UnhashVolid(trans, typeindex, blockindex, &tentry))) {
                    goto abort;
                }
            /* we must rehash new id if the id is different and the ID is nonzero */
@@ -765,7 +802,7 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
 
     /* Rehash volname if it changes */
     if (strcmp(newentry->name, tentry.name)) { /* Name changes; redo hashing */
-       if (errorcode = UnhashVolname(trans, blockindex, &tentry)) {
+       if ((errorcode = UnhashVolname(trans, blockindex, &tentry))) {
            goto abort;
        }
        hashnewname = 1;
@@ -773,13 +810,13 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
 
     /* after this, tentry is new entry, not old one.  vldbentry_to_vlentry
      * doesn't touch hash chains */
-    if (errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry)) {
+    if ((errorcode = nvldbentry_to_vlentry(trans, newentry, &tentry))) {
        goto abort;
     }
 
     for (typeindex = ROVOL; typeindex <= BACKVOL; typeindex++) {
        if (hashVol[typeindex] && tentry.volumeId[typeindex]) {
-           if (errorcode = HashVolid(trans, typeindex, blockindex, &tentry)) {
+           if ((errorcode = HashVolid(trans, typeindex, blockindex, &tentry))) {
                goto abort;
            }
        }
@@ -807,19 +844,22 @@ SVL_ReplaceEntryN(rxcall, volid, voltype, newentry, releasetype)
 }
 
 
-/* Update a vldb entry (accessed thru its volume id). Almost all of the entry's fields can be modified in a single call by setting the appropriate bits in the Mask field in VldbUpdateentry. */
-/* this routine may never have been tested; use replace entry instead unless you're brave */
+/* Update a vldb entry (accessed thru its volume id). Almost all of the
+ * entry's fields can be modified in a single call by setting the
+ * appropriate bits in the Mask field in VldbUpdateentry. */
+/* this routine may never have been tested; use replace entry instead
+ * unless you're brave */
 afs_int32
-SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     afs_int32 releasetype;
-     struct VldbUpdateEntry *updateentry;      /* Update entry copied here */
+SVL_UpdateEntry(struct rx_call *rxcall,
+               afs_uint32 volid,
+               afs_int32 voltype,
+               struct VldbUpdateEntry *updateentry,    /* Update entry copied here */
+               afs_int32 releasetype)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLUPDATEENTRY);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
@@ -828,10 +868,10 @@ SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype)
        END(VL_BADVOLTYPE);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("Update Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == 0) {     /* entry not found */
        if (!errorcode)
@@ -840,8 +880,8 @@ SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype)
     }
 
     /* Do the actual updating of the entry, tentry. */
-    if (errorcode =
-       get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) {
+    if ((errorcode =
+       get_vldbupdateentry(trans, blockindex, updateentry, &tentry))) {
        goto abort;
     }
     if (releasetype)
@@ -863,11 +903,10 @@ SVL_UpdateEntry(rxcall, volid, voltype, updateentry, releasetype)
 
 
 afs_int32
-SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype)
-     struct rx_call *rxcall;
-     char *volname;
-     afs_int32 releasetype;
-     struct VldbUpdateEntry *updateentry;      /* Update entry copied here */
+SVL_UpdateEntryByName(struct rx_call *rxcall,
+                     char *volname,
+                     struct VldbUpdateEntry *updateentry, /* Update entry copied here */
+                     afs_int32 releasetype)
 {
     struct ubik_trans *trans;
     afs_int32 blockindex, errorcode;
@@ -878,7 +917,7 @@ SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype)
        END(VL_PERM);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
     blockindex = FindByName(trans, volname, &tentry, &errorcode);
@@ -889,8 +928,8 @@ SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype)
     }
 
     /* Do the actual updating of the entry, tentry. */
-    if (errorcode =
-       get_vldbupdateentry(trans, blockindex, updateentry, &tentry)) {
+    if ((errorcode =
+       get_vldbupdateentry(trans, blockindex, updateentry, &tentry))) {
        goto abort;
     }
     if (releasetype)
@@ -912,15 +951,13 @@ SVL_UpdateEntryByName(rxcall, volname, updateentry, releasetype)
 
 /* Set a lock to the vldb entry for volid (of type voltype if not -1). */
 afs_int32
-SVL_SetLock(rxcall, volid, voltype, voloper)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     afs_int32 voloper;
+SVL_SetLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+           afs_int32 voloper)
 {
     afs_int32 timestamp, blockindex, errorcode;
     struct ubik_trans *trans;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLSETLOCK);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
@@ -929,10 +966,10 @@ SVL_SetLock(rxcall, volid, voltype, voloper)
        END(VL_BADVOLTYPE);
     if (InvalidOperation(voloper))
        END(VL_BADVOLOPER);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("SetLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == NULLO) {
        if (!errorcode)
@@ -981,15 +1018,13 @@ SVL_SetLock(rxcall, volid, voltype, voloper)
  * the lock time stamp. */
 
 afs_int32
-SVL_ReleaseLock(rxcall, volid, voltype, releasetype)
-     struct rx_call *rxcall;
-     afs_uint32 volid;
-     afs_int32 voltype;
-     afs_int32 releasetype;
+SVL_ReleaseLock(struct rx_call *rxcall, afs_uint32 volid, afs_int32 voltype,
+               afs_int32 releasetype)
 {
     afs_int32 blockindex, errorcode;
     struct ubik_trans *trans;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLRELEASELOCK);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
@@ -998,10 +1033,10 @@ SVL_ReleaseLock(rxcall, volid, voltype, releasetype)
        END(VL_BADVOLTYPE);
     if (releasetype && InvalidReleasetype(releasetype))
        END(VL_BADRELLOCKTYPE);
-    if (errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        goto end;
 
-    VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxcall)));
+    VLog(1, ("ReleaseLock Volume %u %s\n", volid, rxinfo(rxstr, rxcall)));
     blockindex = FindByID(trans, volid, voltype, &tentry, &errorcode);
     if (blockindex == NULLO) {
        if (!errorcode)
@@ -1029,46 +1064,49 @@ SVL_ReleaseLock(rxcall, volid, voltype, releasetype)
 }
 
 
-/* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */
+/* ListEntry returns a single vldb entry, aentry, with offset previous_index;
+ * the remaining parameters (i.e. next_index) are used so that sequential
+ * calls to this routine will get the next (all) vldb entries.
+ */
 afs_int32
-SVL_ListEntry(rxcall, previous_index, count, next_index, aentry)
-     struct rx_call *rxcall;
-     afs_int32 previous_index;
-     afs_int32 *count;
-     afs_int32 *next_index;
-     struct vldbentry *aentry;
+SVL_ListEntry(struct rx_call *rxcall, afs_int32 previous_index,
+             afs_int32 *count, afs_int32 *next_index,
+             struct vldbentry *aentry)
 {
     int errorcode;
     struct ubik_trans *trans;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLLISTENTRY);
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
-    VLog(25, ("OListEntry index=%d %s\n", previous_index, rxinfo(rxcall)));
+    VLog(25, ("OListEntry index=%d %s\n", previous_index,
+              rxinfo(rxstr, rxcall)));
     *next_index = NextEntry(trans, previous_index, &tentry, count);
     if (*next_index)
        vlentry_to_vldbentry(&tentry, aentry);
     return (ubik_EndTrans(trans));
 }
 
-/* ListEntry returns a single vldb entry, aentry, with offset previous_index; the remaining parameters (i.e. next_index) are used so that sequential calls to this routine will get the next (all) vldb entries. */
+/* ListEntry returns a single vldb entry, aentry, with offset previous_index;
+ * the remaining parameters (i.e. next_index) are used so that sequential
+ * calls to this routine will get the next (all) vldb entries.
+ */
 afs_int32
-SVL_ListEntryN(rxcall, previous_index, count, next_index, aentry)
-     struct rx_call *rxcall;
-     afs_int32 previous_index;
-     afs_int32 *count;
-     afs_int32 *next_index;
-     struct nvldbentry *aentry;
+SVL_ListEntryN(struct rx_call *rxcall, afs_int32 previous_index,
+              afs_int32 *count, afs_int32 *next_index,
+              struct nvldbentry *aentry)
 {
     int errorcode;
     struct ubik_trans *trans;
     struct nvlentry tentry;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLLISTENTRYN);
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
-    VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxcall)));
+    VLog(25, ("ListEntry index=%d %s\n", previous_index, rxinfo(rxstr, rxcall)));
     *next_index = NextEntry(trans, previous_index, &tentry, count);
     if (*next_index)
        vlentry_to_nvldbentry(&tentry, aentry);
@@ -1076,24 +1114,29 @@ SVL_ListEntryN(rxcall, previous_index, count, next_index, aentry)
 }
 
 
-/* Retrieves in vldbentries all vldb entries that match the specified attributes (by server number, partition, volume type, and flag); if volume id is specified then the associated list for that entry is returned. CAUTION: This could be a very expensive call since in most cases sequential search of all vldb entries is performed. */
+/* Retrieves in vldbentries all vldb entries that match the specified
+ * attributes (by server number, partition, volume type, and flag); if volume
+ * id is specified then the associated list for that entry is returned.
+ * CAUTION: This could be a very expensive call since in most cases
+ * sequential search of all vldb entries is performed.
+ */
 afs_int32
-SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
-     struct rx_call *rxcall;
-     struct VldbListByAttributes *attributes;
-     afs_int32 *nentries;
-     bulkentries *vldbentries;
+SVL_ListAttributes(struct rx_call *rxcall,
+                  struct VldbListByAttributes *attributes,
+                  afs_int32 *nentries,
+                  bulkentries *vldbentries)
 {
     int errorcode, allocCount = 0;
     struct ubik_trans *trans;
     struct nvlentry tentry;
     struct vldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
     int pollcount = 0;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLLISTATTRIBUTES);
     vldbentries->bulkentries_val = 0;
     vldbentries->bulkentries_len = *nentries = 0;
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->bulkentries_val =
@@ -1104,7 +1147,8 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
        return VL_NOMEM;
     }
     VldbentryLast = VldbentryFirst + allocCount;
-    /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
+    /* Handle the attribute by volume id totally separate of the rest
+     * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
     if (attributes->Mask & VLLIST_VOLUMEID) {
        afs_int32 blockindex;
 
@@ -1121,9 +1165,9 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
            vldbentries->bulkentries_len = 0;
            return errorcode;
        }
-       if (errorcode =
+       if ((errorcode =
            put_attributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast,
-                              vldbentries, &tentry, nentries, &allocCount)) {
+                              vldbentries, &tentry, nentries, &allocCount))) {
            COUNT_ABO;
            ubik_AbortTrans(trans);
            if (vldbentries->bulkentries_val)
@@ -1134,8 +1178,8 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
        }
     } else {
        afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
-       while (nextblockindex =
-              NextEntry(trans, nextblockindex, &tentry, &count)) {
+       while ((nextblockindex =
+              NextEntry(trans, nextblockindex, &tentry, &count))) {
            if (++pollcount > 50) {
 #ifndef AFS_PTHREAD_ENV
                IOMGR_Poll();
@@ -1146,8 +1190,7 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
            if (attributes->Mask & VLLIST_SERVER) {
                int serverindex;
                if ((serverindex =
-                    IpAddrToRelAddr(attributes->server,
-                                    (struct ubik_trans *)0)) == -1)
+                    IpAddrToRelAddr(attributes->server, NULL)) == -1)
                    continue;
                for (k = 0; k < OMAXNSERVERS; k++) {
                    if (tentry.serverNumber[k] == BADSERVERID)
@@ -1183,10 +1226,10 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
                if (!(tentry.flags & attributes->flag))
                    continue;
            }
-           if (errorcode =
+           if ((errorcode =
                put_attributeentry(&Vldbentry, &VldbentryFirst,
                                   &VldbentryLast, vldbentries, &tentry,
-                                  nentries, &allocCount)) {
+                                  nentries, &allocCount))) {
                COUNT_ABO;
                ubik_AbortTrans(trans);
                if (vldbentries->bulkentries_val)
@@ -1212,27 +1255,27 @@ SVL_ListAttributes(rxcall, attributes, nentries, vldbentries)
     }
     VLog(5,
         ("ListAttrs nentries=%d %s\n", vldbentries->bulkentries_len,
-         rxinfo(rxcall)));
+         rxinfo(rxstr, rxcall)));
     return (ubik_EndTrans(trans));
 }
 
 afs_int32
-SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
-     struct rx_call *rxcall;
-     struct VldbListByAttributes *attributes;
-     afs_int32 *nentries;
-     nbulkentries *vldbentries;
+SVL_ListAttributesN(struct rx_call *rxcall,
+                   struct VldbListByAttributes *attributes,
+                   afs_int32 *nentries,
+                   nbulkentries *vldbentries)
 {
     int errorcode, allocCount = 0;
     struct ubik_trans *trans;
     struct nvlentry tentry;
     struct nvldbentry *Vldbentry = 0, *VldbentryFirst = 0, *VldbentryLast = 0;
     int pollcount = 0;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLLISTATTRIBUTESN);
     vldbentries->nbulkentries_val = 0;
     vldbentries->nbulkentries_len = *nentries = 0;
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
     allocCount = VLDBALLOCCOUNT;
     Vldbentry = VldbentryFirst = vldbentries->nbulkentries_val =
@@ -1243,7 +1286,8 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
        return VL_NOMEM;
     }
     VldbentryLast = VldbentryFirst + allocCount;
-    /* Handle the attribute by volume id totally separate of the rest (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
+    /* Handle the attribute by volume id totally separate of the rest
+     * (thus additional Mask values are ignored if VLLIST_VOLUMEID is set!) */
     if (attributes->Mask & VLLIST_VOLUMEID) {
        afs_int32 blockindex;
 
@@ -1260,10 +1304,10 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
            vldbentries->nbulkentries_len = 0;
            return errorcode;
        }
-       if (errorcode =
+       if ((errorcode =
            put_nattributeentry(&Vldbentry, &VldbentryFirst, &VldbentryLast,
                                vldbentries, &tentry, 0, 0, nentries,
-                               &allocCount)) {
+                               &allocCount))) {
            COUNT_ABO;
            ubik_AbortTrans(trans);
            if (vldbentries->nbulkentries_val)
@@ -1274,8 +1318,8 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
        }
     } else {
        afs_int32 nextblockindex = 0, count = 0, k = 0, match = 0;
-       while (nextblockindex =
-              NextEntry(trans, nextblockindex, &tentry, &count)) {
+       while ((nextblockindex =
+              NextEntry(trans, nextblockindex, &tentry, &count))) {
            if (++pollcount > 50) {
 #ifndef AFS_PTHREAD_ENV
                IOMGR_Poll();
@@ -1287,8 +1331,7 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
            if (attributes->Mask & VLLIST_SERVER) {
                int serverindex;
                if ((serverindex =
-                    IpAddrToRelAddr(attributes->server,
-                                    (struct ubik_trans *)0)) == -1)
+                    IpAddrToRelAddr(attributes->server, NULL)) == -1)
                    continue;
                for (k = 0; k < NMAXNSERVERS; k++) {
                    if (tentry.serverNumber[k] == BADSERVERID)
@@ -1324,10 +1367,10 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
                if (!(tentry.flags & attributes->flag))
                    continue;
            }
-           if (errorcode =
+           if ((errorcode =
                put_nattributeentry(&Vldbentry, &VldbentryFirst,
                                    &VldbentryLast, vldbentries, &tentry, 0,
-                                   0, nentries, &allocCount)) {
+                                   0, nentries, &allocCount))) {
                COUNT_ABO;
                ubik_AbortTrans(trans);
                if (vldbentries->nbulkentries_val)
@@ -1353,21 +1396,19 @@ SVL_ListAttributesN(rxcall, attributes, nentries, vldbentries)
     }
     VLog(5,
         ("NListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
-         rxinfo(rxcall)));
+         rxinfo(rxstr, rxcall)));
     return (ubik_EndTrans(trans));
 }
 
 
 afs_int32
-SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
-                    vldbentries, nextstartindex)
-     struct rx_call *rxcall;
-     struct VldbListByAttributes *attributes;
-     char *name;               /* Wildcarded volume name */
-     afs_int32 startindex;
-     afs_int32 *nentries;
-     nbulkentries *vldbentries;
-     afs_int32 *nextstartindex;
+SVL_ListAttributesN2(struct rx_call *rxcall,
+                    struct VldbListByAttributes *attributes,
+                    char *name,                /* Wildcarded volume name */
+                    afs_int32 startindex,
+                    afs_int32 *nentries,
+                    nbulkentries *vldbentries,
+                    afs_int32 *nextstartindex)
 {
     int errorcode = 0, maxCount = VLDBALLOCCOUNT;
     struct ubik_trans *trans;
@@ -1377,14 +1418,16 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
     afs_int32 matchindex = 0;
     int serverindex = -1;      /* no server found */
     int findserver = 0, findpartition = 0, findflag = 0, findname = 0;
-    char *t;
     int pollcount = 0;
     int namematchRWBK, namematchRO, thismatch;
     int matchtype = 0;
     char volumename[VL_MAXNAMELEN];
+    char rxstr[AFS_RXINFO_LEN];
 #ifdef HAVE_POSIX_REGEX
     regex_t re;
     int need_regfree = 0;
+#else
+    char *t;
 #endif
 
     COUNT_REQ(VLLISTATTRIBUTESN2);
@@ -1434,7 +1477,7 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
        /* Get the server index for matching server address */
        if (attributes->Mask & VLLIST_SERVER) {
            serverindex =
-               IpAddrToRelAddr(attributes->server, (struct ubik_trans *)0);
+               IpAddrToRelAddr(attributes->server, NULL);
            if (serverindex == -1)
                goto done;
            findserver = 1;
@@ -1461,7 +1504,7 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
 
        /* Read each entry and see if it is the one we want */
        blockindex = startindex;
-       while (blockindex = NextEntry(trans, blockindex, &tentry, &count)) {
+       while ((blockindex = NextEntry(trans, blockindex, &tentry, &count))) {
            if (++pollcount > 50) {
 #ifndef AFS_PTHREAD_ENV
                IOMGR_Poll();
@@ -1621,7 +1664,7 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
     } else {
        VLog(5,
             ("N2ListAttrs nentries=%d %s\n", vldbentries->nbulkentries_len,
-             rxinfo(rxcall)));
+             rxinfo(rxstr, rxcall)));
        return (ubik_EndTrans(trans));
     }
 }
@@ -1634,11 +1677,10 @@ SVL_ListAttributesN2(rxcall, attributes, name, startindex, nentries,
  * cases sequential search of all vldb entries is performed.
  */
 afs_int32
-SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
-     struct rx_call *rxcall;
-     struct VldbListByAttributes *attributes;
-     afs_int32 *nentries;
-     vldb_list *vldbentries;
+SVL_LinkedList(struct rx_call *rxcall,
+              struct VldbListByAttributes *attributes,
+              afs_int32 *nentries,
+              vldb_list *vldbentries)
 {
     int errorcode;
     struct ubik_trans *trans;
@@ -1650,7 +1692,7 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
     int pollcount = 0;
 
     COUNT_REQ(VLLINKEDLIST);
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
 
     *nentries = 0;
@@ -1697,8 +1739,7 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
            /* Does this volume exist on the desired server */
            if (attributes->Mask & VLLIST_SERVER) {
                serverindex =
-                   IpAddrToRelAddr(attributes->server,
-                                   (struct ubik_trans *)0);
+                   IpAddrToRelAddr(attributes->server, NULL);
                if (serverindex == -1)
                    continue;
                for (k = 0; k < OMAXNSERVERS; k++) {
@@ -1763,11 +1804,10 @@ SVL_LinkedList(rxcall, attributes, nentries, vldbentries)
 }
 
 afs_int32
-SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
-     struct rx_call *rxcall;
-     struct VldbListByAttributes *attributes;
-     afs_int32 *nentries;
-     nvldb_list *vldbentries;
+SVL_LinkedListN(struct rx_call *rxcall,
+               struct VldbListByAttributes *attributes,
+               afs_int32 *nentries,
+               nvldb_list *vldbentries)
 {
     int errorcode;
     struct ubik_trans *trans;
@@ -1779,7 +1819,7 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
     int pollcount = 0;
 
     COUNT_REQ(VLLINKEDLISTN);
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
 
     *nentries = 0;
@@ -1826,8 +1866,7 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
            /* Does this volume exist on the desired server */
            if (attributes->Mask & VLLIST_SERVER) {
                serverindex =
-                   IpAddrToRelAddr(attributes->server,
-                                   (struct ubik_trans *)0);
+                   IpAddrToRelAddr(attributes->server, NULL);
                if (serverindex == -1)
                    continue;
                for (k = 0; k < NMAXNSERVERS; k++) {
@@ -1891,15 +1930,18 @@ SVL_LinkedListN(rxcall, attributes, nentries, vldbentries)
     return (ubik_EndTrans(trans));
 }
 
-/* Get back vldb header statistics (allocs, frees, maxvolumeid, totalentries, etc) and dynamic statistics (number of requests and/or aborts per remote procedure call, etc) */
+/* Get back vldb header statistics (allocs, frees, maxvolumeid,
+ * totalentries, etc) and dynamic statistics (number of requests and/or
+ * aborts per remote procedure call, etc)
+ */
 afs_int32
-SVL_GetStats(rxcall, stats, vital_header)
-     struct rx_call *rxcall;
-     vldstats *stats;
-     vital_vlheader *vital_header;
+SVL_GetStats(struct rx_call *rxcall,
+            vldstats *stats,
+            vital_vlheader *vital_header)
 {
     register afs_int32 errorcode;
     struct ubik_trans *trans;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLGETSTATS);
 #ifdef notdef
@@ -1907,9 +1949,9 @@ SVL_GetStats(rxcall, stats, vital_header)
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))        /* Must be in 'UserList' to use */
        return VL_PERM;
 #endif
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
-    VLog(5, ("GetStats %s\n", rxinfo(rxcall)));
+    VLog(5, ("GetStats %s\n", rxinfo(rxstr, rxcall)));
     memcpy((char *)vital_header, (char *)&cheader.vital_header,
           sizeof(vital_vlheader));
     memcpy((char *)stats, (char *)&dynamic_statistics, sizeof(vldstats));
@@ -1921,12 +1963,12 @@ SVL_GetStats(rxcall, stats, vital_header)
  * through the VLDB, but that's life.
  */
 afs_int32
-SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
-     struct rx_call *rxcall;
-     afs_int32 Handle, spare2;
-     struct VLCallBack *spare3;
-     afs_int32 *nentries;
-     bulkaddrs *addrsp;
+SVL_GetAddrs(struct rx_call *rxcall,
+            afs_int32 Handle,
+            afs_int32 spare2,
+            struct VLCallBack *spare3,
+            afs_int32 *nentries,
+            bulkaddrs *addrsp)
 {
     register afs_int32 errorcode;
     struct ubik_trans *trans;
@@ -1938,7 +1980,7 @@ SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
     addrsp->bulkaddrs_val = 0;
     memset(spare3, 0, sizeof(struct VLCallBack));
 
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
 
     VLog(5, ("GetAddrs\n"));
@@ -1953,7 +1995,7 @@ SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
     }
 
     for (i = 0; i <= MAXSERVERID; i++) {
-       if (*taddrp = ntohl(cheader.IpMappedAddr[i])) {
+       if ((*taddrp = ntohl(cheader.IpMappedAddr[i]))) {
            taddrp++;
            nservers++;
        }
@@ -1966,11 +2008,8 @@ SVL_GetAddrs(rxcall, Handle, spare2, spare3, nentries, addrsp)
 #define PADDR(addr) VLog(0,("%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8) &0xff, addr&0xff));
 
 afs_int32
-SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp)
-     struct rx_call *rxcall;
-     afsUUID *uuidp;
-     afs_int32 spare1;
-     bulkaddrs *addrsp;
+SVL_RegisterAddrs(struct rx_call *rxcall, afsUUID *uuidp, afs_int32 spare1,
+                 bulkaddrs *addrsp)
 {
     afs_int32 code;
     struct ubik_trans *trans;
@@ -1988,7 +2027,7 @@ SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp)
     COUNT_REQ(VLREGADDR);
     if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL))
        return (VL_PERM);
-    if (code = Init_VLdbase(&trans, LOCKWRITE, this_op))
+    if ((code = Init_VLdbase(&trans, LOCKWRITE, this_op)))
        return code;
 
     /* Eliminate duplicates from IP address list */
@@ -2344,12 +2383,12 @@ SVL_RegisterAddrs(rxcall, uuidp, spare1, addrsp)
 }
 
 afs_int32
-SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
-     struct rx_call *rxcall;
-     struct ListAddrByAttributes *attributes;
-     afsUUID *uuidpo;
-     afs_int32 *uniquifier, *nentries;
-     bulkaddrs *addrsp;
+SVL_GetAddrsU(struct rx_call *rxcall,
+             struct ListAddrByAttributes *attributes,
+             afsUUID *uuidpo,
+             afs_int32 *uniquifier,
+             afs_int32 *nentries,
+             bulkaddrs *addrsp)
 {
     register afs_int32 errorcode, index = -1, offset;
     struct ubik_trans *trans;
@@ -2357,12 +2396,13 @@ SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
     struct extentaddr *exp = 0;
     afsUUID tuuid;
     afs_uint32 *taddrp, taddr;
+    char rxstr[AFS_RXINFO_LEN];
 
     COUNT_REQ(VLGETADDRSU);
     addrsp->bulkaddrs_len = *nentries = 0;
     addrsp->bulkaddrs_val = 0;
-    VLog(5, ("GetAddrsU %s\n", rxinfo(rxcall)));
-    if (errorcode = Init_VLdbase(&trans, LOCKREAD, this_op))
+    VLog(5, ("GetAddrsU %s\n", rxinfo(rxstr, rxcall)));
+    if ((errorcode = Init_VLdbase(&trans, LOCKREAD, this_op)))
        return errorcode;
 
     if (attributes->Mask & VLADDR_IPADDR) {
@@ -2425,8 +2465,8 @@ SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
            ubik_AbortTrans(trans);
            return VL_NOENT;
        }
-       if (errorcode =
-           FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base)) {
+       if ((errorcode =
+           FindExtentBlock(trans, &attributes->uuid, 0, -1, &exp, &base))) {
            ubik_AbortTrans(trans);
            return errorcode;
        }
@@ -2480,12 +2520,13 @@ SVL_GetAddrsU(rxcall, attributes, uuidpo, uniquifier, nentries, addrsp)
 
 /* Routine that copies the given vldb entry to the output buffer, vldbentries. */
 static int
-put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
-                  entry, nentries, alloccnt)
-     struct vldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
-     bulkentries *vldbentries;
-     struct nvlentry *entry;
-     afs_int32 *nentries, *alloccnt;
+put_attributeentry(struct vldbentry **Vldbentry,
+                  struct vldbentry **VldbentryFirst,
+                  struct vldbentry **VldbentryLast,
+                  bulkentries *vldbentries,
+                  struct nvlentry *entry,
+                  afs_int32 *nentries,
+                  afs_int32 *alloccnt)
 {
     vldbentry *reall;
     afs_int32 allo;
@@ -2518,12 +2559,15 @@ put_attributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
 }
 
 static int
-put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
-                   entry, matchtype, matchindex, nentries, alloccnt)
-     struct nvldbentry **Vldbentry, **VldbentryFirst, **VldbentryLast;
-     nbulkentries *vldbentries;
-     struct nvlentry *entry;
-     afs_int32 matchtype, matchindex, *nentries, *alloccnt;
+put_nattributeentry(struct nvldbentry **Vldbentry,
+                   struct nvldbentry **VldbentryFirst,
+                   struct nvldbentry **VldbentryLast,
+                   nbulkentries *vldbentries,
+                   struct nvlentry *entry,
+                   afs_int32 matchtype,
+                   afs_int32 matchindex,
+                   afs_int32 *nentries,
+                   afs_int32 *alloccnt)
 {
     nvldbentry *reall;
     afs_int32 allo;
@@ -2559,24 +2603,20 @@ put_nattributeentry(Vldbentry, VldbentryFirst, VldbentryLast, vldbentries,
 
 /* Common code to actually remove a vldb entry from the database. */
 static int
-RemoveEntry(trans, entryptr, tentry)
-     struct ubik_trans *trans;
-     afs_int32 entryptr;
-     struct nvlentry *tentry;
+RemoveEntry(struct ubik_trans *trans, afs_int32 entryptr,
+           struct nvlentry *tentry)
 {
     register int errorcode;
 
-    if (errorcode = UnthreadVLentry(trans, entryptr, tentry))
+    if ((errorcode = UnthreadVLentry(trans, entryptr, tentry)))
        return errorcode;
-    if (errorcode = FreeBlock(trans, entryptr))
+    if ((errorcode = FreeBlock(trans, entryptr)))
        return errorcode;
     return 0;
 }
 
 static void
-ReleaseEntry(tentry, releasetype)
-     struct nvlentry *tentry;
-     afs_int32 releasetype;
+ReleaseEntry(struct nvlentry *tentry, afs_int32 releasetype)
 {
     if (releasetype & LOCKREL_TIMESTAMP)
        tentry->LockTimestamp = 0;
@@ -2587,10 +2627,10 @@ ReleaseEntry(tentry, releasetype)
 }
 
 
-/* Verify that the incoming vldb entry is valid; multi type of error codes are returned. */
+/* Verify that the incoming vldb entry is valid; multi type of error codes
+ * are returned. */
 static int
-check_vldbentry(aentry)
-     struct vldbentry *aentry;
+check_vldbentry(struct vldbentry *aentry)
 {
     afs_int32 i;
 
@@ -2612,8 +2652,7 @@ check_vldbentry(aentry)
 }
 
 static int
-check_nvldbentry(aentry)
-     struct nvldbentry *aentry;
+check_nvldbentry(struct nvldbentry *aentry)
 {
     afs_int32 i;
 
@@ -2638,10 +2677,9 @@ check_nvldbentry(aentry)
 /* Convert from the external vldb entry representation to its internal
    (more compact) form.  This call should not change the hash chains! */
 static int
-vldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
-     struct ubik_trans *atrans;
-     struct vldbentry *VldbEntry;
-     struct nvlentry *VlEntry;
+vldbentry_to_vlentry(struct ubik_trans *atrans,
+                    struct vldbentry *VldbEntry,
+                    struct nvlentry *VlEntry)
 {
     int i, serverindex;
 
@@ -2666,10 +2704,9 @@ vldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
 }
 
 static int
-nvldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
-     struct ubik_trans *atrans;
-     struct nvldbentry *VldbEntry;
-     struct nvlentry *VlEntry;
+nvldbentry_to_vlentry(struct ubik_trans *atrans,
+                     struct nvldbentry *VldbEntry,
+                     struct nvlentry *VlEntry)
 {
     int i, serverindex;
 
@@ -2694,27 +2731,59 @@ nvldbentry_to_vlentry(atrans, VldbEntry, VlEntry)
 }
 
 
-/* Update the vldb entry with the new fields as indicated by the value of the Mask entry in the updateentry structure. All necessary validation checks are performed. */
-static
-get_vldbupdateentry(trans, blockindex, updateentry, VlEntry)
-     struct ubik_trans *trans;
-     afs_int32 blockindex;
-     struct VldbUpdateEntry *updateentry;
-     struct nvlentry *VlEntry;
+/* Update the vldb entry with the new fields as indicated by the value of
+ * the Mask entry in the updateentry structure. All necessary validation
+ * checks are performed.
+ */
+static int
+get_vldbupdateentry(struct ubik_trans *trans,
+                   afs_int32 blockindex,
+                   struct VldbUpdateEntry *updateentry,
+                   struct nvlentry *VlEntry)
 {
     int i, j, errorcode, serverindex;
+    afs_uint32 checkids[MAXTYPES];
+
+    /* check if any specified new IDs are already present in the db. Do
+     * this check before doing anything else, so we don't get a half-
+     * updated entry. */
+    memset(&checkids, 0, sizeof(checkids));
+    if (updateentry->Mask & VLUPDATE_RWID) {
+       checkids[RWVOL] = updateentry->spares3; /* rw id */
+    }
+    if (updateentry->Mask & VLUPDATE_READONLYID) {
+       checkids[ROVOL] = updateentry->ReadOnlyId;
+    }
+    if (updateentry->Mask & VLUPDATE_BACKUPID) {
+       checkids[BACKVOL] = updateentry->BackupId;
+    }
+
+    if (EntryIDExists(trans, checkids, MAXTYPES, &errorcode)) {
+       return VL_IDEXIST;
+    } else if (errorcode) {
+       return errorcode;
+    }
 
     if (updateentry->Mask & VLUPDATE_VOLUMENAME) {
+       struct nvlentry tentry;
+
        if (InvalidVolname(updateentry->name))
            return VL_BADNAME;
-       if (errorcode = UnhashVolname(trans, blockindex, VlEntry))
+
+       if (FindByName(trans, updateentry->name, &tentry, &errorcode)) {
+           return VL_NAMEEXIST;
+       } else if (errorcode) {
+           return errorcode;
+       }
+
+       if ((errorcode = UnhashVolname(trans, blockindex, VlEntry)))
            return errorcode;
        strncpy(VlEntry->name, updateentry->name, sizeof(VlEntry->name));
        HashVolname(trans, blockindex, VlEntry);
     }
 
     if (updateentry->Mask & VLUPDATE_VOLNAMEHASH) {
-       if (errorcode = UnhashVolname(trans, blockindex, VlEntry)) {
+       if ((errorcode = UnhashVolname(trans, blockindex, VlEntry))) {
            if (errorcode != VL_NOENT)
                return errorcode;
        }
@@ -2728,30 +2797,30 @@ get_vldbupdateentry(trans, blockindex, updateentry, VlEntry)
        VlEntry->cloneId = updateentry->cloneId;
     }
     if (updateentry->Mask & VLUPDATE_RWID) {
-       if (errorcode = UnhashVolid(trans, RWVOL, blockindex, VlEntry)) {
+       if ((errorcode = UnhashVolid(trans, RWVOL, blockindex, VlEntry))) {
            if (errorcode != VL_NOENT)
                return errorcode;
        }
        VlEntry->volumeId[RWVOL] = updateentry->spares3;        /* rw id */
-       if (errorcode = HashVolid(trans, RWVOL, blockindex, VlEntry))
+       if ((errorcode = HashVolid(trans, RWVOL, blockindex, VlEntry)))
            return errorcode;
     }
     if (updateentry->Mask & VLUPDATE_READONLYID) {
-       if (errorcode = UnhashVolid(trans, ROVOL, blockindex, VlEntry)) {
+       if ((errorcode = UnhashVolid(trans, ROVOL, blockindex, VlEntry))) {
            if (errorcode != VL_NOENT)
                return errorcode;
        }
        VlEntry->volumeId[ROVOL] = updateentry->ReadOnlyId;
-       if (errorcode = HashVolid(trans, ROVOL, blockindex, VlEntry))
+       if ((errorcode = HashVolid(trans, ROVOL, blockindex, VlEntry)))
            return errorcode;
     }
     if (updateentry->Mask & VLUPDATE_BACKUPID) {
-       if (errorcode = UnhashVolid(trans, BACKVOL, blockindex, VlEntry)) {
+       if ((errorcode = UnhashVolid(trans, BACKVOL, blockindex, VlEntry))) {
            if (errorcode != VL_NOENT)
                return errorcode;
        }
        VlEntry->volumeId[BACKVOL] = updateentry->BackupId;
-       if (errorcode = HashVolid(trans, BACKVOL, blockindex, VlEntry))
+       if ((errorcode = HashVolid(trans, BACKVOL, blockindex, VlEntry)))
            return errorcode;
     }
     if (updateentry->Mask & VLUPDATE_REPSITES) {
@@ -2858,11 +2927,11 @@ get_vldbupdateentry(trans, blockindex, updateentry, VlEntry)
 }
 
 
-/* Check if the specified [server,partition] entry is found in the vldb entry's repsite table; it's offset in the table is returned, if it's present there. */
+/* Check if the specified [server,partition] entry is found in the vldb
+ * entry's repsite table; it's offset in the table is returned, if it's
+ * present there. */
 static int
-repsite_exists(VlEntry, server, partition)
-     struct nvlentry *VlEntry;
-     int server, partition;
+repsite_exists(struct nvlentry *VlEntry, int server, int partition)
 {
     int i;
 
@@ -2877,11 +2946,10 @@ repsite_exists(VlEntry, server, partition)
 
 
 
-/* Repsite table compression: used when deleting a repsite entry so that all active repsite entries are on the top of the table. */
+/* Repsite table compression: used when deleting a repsite entry so that
+ * all active repsite entries are on the top of the table. */
 static void
-repsite_compress(VlEntry, offset)
-     struct nvlentry *VlEntry;
-     int offset;
+repsite_compress(struct nvlentry *VlEntry, int offset)
 {
     int repsite_offset = offset;
     for (;
@@ -2898,11 +2966,10 @@ repsite_compress(VlEntry, offset)
 }
 
 
-/* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
+/* Convert from the internal (compacted) vldb entry to the external
+ * representation used by the interface. */
 static void
-vlentry_to_vldbentry(VlEntry, VldbEntry)
-     struct nvlentry *VlEntry;
-     struct vldbentry *VldbEntry;
+vlentry_to_vldbentry(struct nvlentry *VlEntry, struct vldbentry *VldbEntry)
 {
     int i, j;
 
@@ -2940,11 +3007,10 @@ vlentry_to_vldbentry(VlEntry, VldbEntry)
 }
 
 
-/* Convert from the internal (compacted) vldb entry to the external representation used by the interface. */
+/* Convert from the internal (compacted) vldb entry to the external
+ * representation used by the interface. */
 static void
-vlentry_to_nvldbentry(VlEntry, VldbEntry)
-     struct nvlentry *VlEntry;
-     struct nvldbentry *VldbEntry;
+vlentry_to_nvldbentry(struct nvlentry *VlEntry, struct nvldbentry *VldbEntry)
 {
     int i, j;
 
@@ -2982,9 +3048,7 @@ vlentry_to_nvldbentry(VlEntry, VldbEntry)
 }
 
 static void
-vlentry_to_uvldbentry(VlEntry, VldbEntry)
-     struct nvlentry *VlEntry;
-     struct uvldbentry *VldbEntry;
+vlentry_to_uvldbentry(struct nvlentry *VlEntry, struct uvldbentry *VldbEntry)
 {
     int i, j;
 
@@ -3028,8 +3092,7 @@ vlentry_to_uvldbentry(VlEntry, VldbEntry)
 
 /* Verify that the volname is a valid volume name. */
 static int
-InvalidVolname(volname)
-     char *volname;
+InvalidVolname(char *volname)
 {
     char *map;
     int slen;
@@ -3044,8 +3107,7 @@ InvalidVolname(volname)
 
 /* Verify that the given volume type is valid. */
 static int
-InvalidVoltype(voltype)
-     afs_int32 voltype;
+InvalidVoltype(afs_int32 voltype)
 {
     if (voltype != RWVOL && voltype != ROVOL && voltype != BACKVOL)
        return 1;
@@ -3054,8 +3116,7 @@ InvalidVoltype(voltype)
 
 
 static int
-InvalidOperation(voloper)
-     afs_int32 voloper;
+InvalidOperation(afs_int32 voloper)
 {
     if (voloper != VLOP_MOVE && voloper != VLOP_RELEASE
        && voloper != VLOP_BACKUP && voloper != VLOP_DELETE
@@ -3065,8 +3126,7 @@ InvalidOperation(voloper)
 }
 
 static int
-InvalidReleasetype(releasetype)
-     afs_int32 releasetype;
+InvalidReleasetype(afs_int32 releasetype)
 {
     if ((releasetype & LOCKREL_TIMESTAMP) || (releasetype & LOCKREL_OPCODE)
        || (releasetype & LOCKREL_AFSID))
@@ -3075,9 +3135,7 @@ InvalidReleasetype(releasetype)
 }
 
 static int
-IpAddrToRelAddr(ipaddr, atrans)
-     struct ubik_trans *atrans;
-     register afs_uint32 ipaddr;
+IpAddrToRelAddr(register afs_uint32 ipaddr, struct ubik_trans *atrans)
 {
     register int i, j;
     register afs_int32 code, base, index;
@@ -3137,9 +3195,7 @@ IpAddrToRelAddr(ipaddr, atrans)
 }
 
 static int
-ChangeIPAddr(ipaddr1, ipaddr2, atrans)
-     struct ubik_trans *atrans;
-     register afs_uint32 ipaddr1, ipaddr2;
+ChangeIPAddr(afs_uint32 ipaddr1, afs_uint32 ipaddr2, struct ubik_trans *atrans)
 {
     int i, j;
     afs_int32 code;
@@ -3150,6 +3206,7 @@ ChangeIPAddr(ipaddr1, ipaddr2, atrans)
     afs_int32 blockindex, count;
     int pollcount = 0;
     struct nvlentry tentry;
+    int ipaddr1_id = -1, ipaddr2_id = -1;
 
     if (!atrans)
        return VL_CREATEFAIL;
@@ -3184,22 +3241,44 @@ ChangeIPAddr(ipaddr1, ipaddr2, atrans)
            for (mhidx = 0; mhidx < VL_MAXIPADDRS_PERMH; mhidx++) {
                if (!exp->ex_addrs[mhidx])
                    continue;
-               if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1)
-                   break;
+               if (ntohl(exp->ex_addrs[mhidx]) == ipaddr1) {
+                   ipaddr1_id = i;
+               }
+               if (ipaddr2 != 0 && ntohl(exp->ex_addrs[mhidx]) == ipaddr2) {
+                   ipaddr2_id = i;
+               }
            }
-           if (mhidx < VL_MAXIPADDRS_PERMH) {
-               break;
+       } else {
+           if (HostAddress[i] == ipaddr1) {
+               exp = NULL;
+               ipaddr1_id = i;
+           }
+           if (ipaddr2 != 0 && HostAddress[i] == ipaddr2) {
+               ipaddr2_id = i;
            }
-       } else if (HostAddress[i] == ipaddr1) {
-           exp = NULL;
+       }
+
+       if (ipaddr1_id >= 0 && (ipaddr2 == 0 || ipaddr2_id >= 0)) {
+           /* we've either found both IPs already in the VLDB, or we found
+            * ipaddr1, and we're not going to find ipaddr2 because it's 0 */
            break;
        }
     }
 
-    if (i >= MAXSERVERID) {
+    if (ipaddr1_id < 0) {
        return VL_NOENT;        /* not found */
     }
 
+    if (ipaddr2_id >= 0 && ipaddr2_id != ipaddr1_id) {
+       char buf1[16], buf2[16];
+       VLog(0, ("Cannot change IP address from %s to %s because the latter "
+                "is in use by server id %d\n",
+                afs_inet_ntoa_r(htonl(ipaddr1), buf1),
+                afs_inet_ntoa_r(htonl(ipaddr2), buf2),
+                ipaddr2_id));
+       return VL_MULTIPADDR;
+    }
+
     /* If we are removing a server entry, a volume cannot
      * exist on the server. If one does, don't remove the
      * server entry: return error "volume entry exists".
@@ -3216,7 +3295,7 @@ ChangeIPAddr(ipaddr1, ipaddr2, atrans)
            for (j = 0; j < NMAXNSERVERS; j++) {
                if (tentry.serverNumber[j] == BADSERVERID)
                    break;
-               if (tentry.serverNumber[j] == i) {
+               if (tentry.serverNumber[j] == ipaddr1_id) {
                    return VL_IDEXIST;
                }
            }
@@ -3262,12 +3341,12 @@ ChangeIPAddr(ipaddr1, ipaddr2, atrans)
     }
 
     /* Now change the host address entry */
-    cheader.IpMappedAddr[i] = htonl(ipaddr2);
+    cheader.IpMappedAddr[ipaddr1_id] = htonl(ipaddr2);
     code =
-       vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[i]),
+       vlwrite(atrans, DOFFSET(0, &cheader, &cheader.IpMappedAddr[ipaddr1_id]),
                (char *)
-               &cheader.IpMappedAddr[i], sizeof(afs_int32));
-    HostAddress[i] = ipaddr2;
+               &cheader.IpMappedAddr[ipaddr1_id], sizeof(afs_int32));
+    HostAddress[ipaddr1_id] = ipaddr2;
     if (code)
        return VL_IO;
 
@@ -3276,8 +3355,7 @@ ChangeIPAddr(ipaddr1, ipaddr2, atrans)
 
 /* see if the vlserver is back yet */
 afs_int32
-SVL_ProbeServer(rxcall)
-     struct rx_call *rxcall;
+SVL_ProbeServer(struct rx_call *rxcall)
 {
     return 0;
 }