vos release: Avoid full dump on all sites
[openafs.git] / src / volser / vsprocs.c
index fa44258..7376ae0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -10,9 +10,6 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
-
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -45,6 +42,12 @@ RCSID
 #include <rx/rxkad.h>
 #include <afs/kautils.h>
 #include <afs/cmd.h>
+#include <afs/ihandle.h>
+#ifdef AFS_NT40_ENV
+#include <afs/ntops.h>
+#endif
+#include <afs/vnode.h>
+#include <afs/volume.h>
 #include <errno.h>
 #define ERRCODE_RANGE 8                /* from error_table.h */
 #define        CLOCKSKEW   2           /* not really skew, but resolution */
@@ -55,6 +58,7 @@ RCSID
 #include <afs/procmgmt.h>      /* signal(), kill(), wait(), etc. */
 #include <setjmp.h>
 
+#include "volser_internal.h"
 #include "volser_prototypes.h"
 #include "vsutils_prototypes.h"
 #include "lockprocs_prototypes.h"
@@ -63,8 +67,8 @@ struct ubik_client *cstruct;
 int verbose = 0, noresolve = 0;
 
 struct release {
-    afs_int32 crtime;
-    afs_int32 uptime;
+    afs_uint32 crtime;
+    afs_uint32 uptime;
     afs_int32 vldbEntryIndex;
 };
 
@@ -161,21 +165,24 @@ do { \
 
 
 /* Protos for static routines */
+#if 0
 static afs_int32 CheckAndDeleteVolume(struct rx_connection *aconn,
-                                     afs_int32 apart, afs_int32 okvol,
-                                     afs_int32 delvol);
-static int DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
+                                     afs_int32 apart, afs_uint32 okvol,
+                                     afs_uint32 delvol);
+#endif
+static int DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
                  afs_int32 flags);
 static int GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
                    struct rx_connection **connPtr, afs_int32 * transPtr,
-                   afs_int32 * crtimePtr, afs_int32 * uptimePtr);
+                   afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
+                   afs_int32 *origflags);
 static int SimulateForwardMultiple(struct rx_connection *fromconn,
                                   afs_int32 fromtid, afs_int32 fromdate,
                                   manyDests * tr, afs_int32 flags,
                                   void *cookie, manyResults * results);
-static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_int32 aserver,
+static afs_int32 CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver,
                             afs_int32 apart, afs_int32 * modentry,
-                            afs_uint32 * maxvolid);
+                            afs_uint32 * maxvolid, struct nvldbentry *aentry);
 
 
 /*map the partition <partId> into partition name <partName>*/
@@ -215,7 +222,7 @@ yesprompt(char *str)
 int
 PrintError(char *msg, afs_int32 errcode)
 {
-    fprintf(STDERR, msg);
+    fprintf(STDERR, "%s", msg);
     /*replace by a big switch statement */
     switch (errcode) {
     case 0:
@@ -392,9 +399,6 @@ PrintError(char *msg, afs_int32 errcode)
        break;
     default:
        {
-
-           afs_int32 offset;
-
            initialize_KA_error_table();
            initialize_RXK_error_table();
            initialize_KTC_error_table();
@@ -402,7 +406,6 @@ PrintError(char *msg, afs_int32 errcode)
            initialize_CMD_error_table();
            initialize_VL_error_table();
 
-           offset = errcode & ((1 << ERRCODE_RANGE) - 1);
            fprintf(STDERR, "%s: %s\n", afs_error_table_name(errcode),
                    afs_error_message(errcode));
            break;
@@ -429,7 +432,7 @@ static struct rx_securityClass *uvclass = 0;
 static int uvindex = -1;
 /* called by VLDBClient_Init to set the security module to be used in the RPC */
 int
-UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
+UV_SetSecurity(struct rx_securityClass *as, afs_int32 aindex)
 {
     uvindex = aindex;
     uvclass = as;
@@ -439,28 +442,71 @@ UV_SetSecurity(register struct rx_securityClass *as, afs_int32 aindex)
 /* bind to volser on <port> <aserver> */
 /* takes server address in network order, port in host order.  dumb */
 struct rx_connection *
-UV_Bind(afs_int32 aserver, afs_int32 port)
+UV_Bind(afs_uint32 aserver, afs_int32 port)
 {
-    register struct rx_connection *tc;
+    struct rx_connection *tc;
 
     tc = rx_NewConnection(aserver, htons(port), VOLSERVICE_ID, uvclass,
                          uvindex);
     return tc;
 }
 
+static int
+AFSVolCreateVolume_retry(struct rx_connection *z_conn,
+                      afs_int32 partition, char *name, afs_int32 type,
+                      afs_int32 parent, afs_uint32 *volid, afs_int32 *trans)
+{
+    afs_int32 code;
+    int retries = 3;
+    while (retries) {
+       code = AFSVolCreateVolume(z_conn, partition, name, type, parent,
+                                 volid, trans);
+        if (code != VOLSERVOLBUSY)
+            break;
+        retries--;
+#ifdef AFS_PTHREAD_ENV
+        sleep(3-retries);
+#else
+        IOMGR_Sleep(3-retries);
+#endif
+    }
+    return code;
+}
+
+static int
+AFSVolTransCreate_retry(struct rx_connection *z_conn,
+                       afs_int32 volume, afs_int32 partition,
+                       afs_int32 flags, afs_int32 * trans)
+{
+    afs_int32 code;
+    int retries = 3;
+    while (retries) {
+       code = AFSVolTransCreate(z_conn, volume, partition, flags, trans);
+        if (code != VOLSERVOLBUSY)
+            break;
+        retries--;
+#ifdef AFS_PTHREAD_ENV
+        sleep(3-retries);
+#else
+        IOMGR_Sleep(3-retries);
+#endif
+    }
+    return code;
+}
+
+#if 0
 /* if <okvol> is allright(indicated by beibg able to
  * start a transaction, delete the <delvol> */
 static afs_int32
 CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
-                    afs_int32 okvol, afs_int32 delvol)
+                    afs_uint32 okvol, afs_uint32 delvol)
 {
     afs_int32 error, code, tid, rcode;
-
     error = 0;
     code = 0;
 
     if (okvol == 0) {
-       code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
+       code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
        if (!error && code)
            error = code;
        code = AFSVolDeleteVolume(aconn, tid);
@@ -473,14 +519,14 @@ CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
            error = code;
        return error;
     } else {
-       code = AFSVolTransCreate(aconn, okvol, apart, ITOffline, &tid);
+       code = AFSVolTransCreate_retry(aconn, okvol, apart, ITOffline, &tid);
        if (!code) {
            code = AFSVolEndTrans(aconn, tid, &rcode);
            if (!code)
                code = rcode;
            if (!error && code)
                error = code;
-           code = AFSVolTransCreate(aconn, delvol, apart, ITOffline, &tid);
+           code = AFSVolTransCreate_retry(aconn, delvol, apart, ITOffline, &tid);
            if (!error && code)
                error = code;
            code = AFSVolDeleteVolume(aconn, tid);
@@ -497,6 +543,8 @@ CheckAndDeleteVolume(struct rx_connection *aconn, afs_int32 apart,
     }
 }
 
+#endif
+
 /* called by EmuerateEntry, show vldb entry in a reasonable format */
 void
 SubEnumerateEntry(struct nvldbentry *entry)
@@ -544,7 +592,7 @@ SubEnumerateEntry(struct nvldbentry *entry)
     for (i = 0; i < entry->nServers; i++) {
        MapPartIdIntoName(entry->serverPartition[i], pname);
        fprintf(STDOUT, "       server %s partition %s ",
-               noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) : 
+               noresolve ? afs_inet_ntoa_r(entry->serverNumber[i], hoststr) :
                 hostutil_GetNameByINet(entry->serverNumber[i]), pname);
        if (entry->serverFlags[i] & ITSRWVOL)
            fprintf(STDOUT, "RW Site ");
@@ -580,10 +628,10 @@ EnumerateEntry(struct nvldbentry *entry)
 
 /* forcibly remove a volume.  Very dangerous call */
 int
-UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
+UV_NukeVolume(afs_uint32 server, afs_int32 partid, afs_uint32 volid)
 {
-    register struct rx_connection *tconn;
-    register afs_int32 code;
+    struct rx_connection *tconn;
+    afs_int32 code;
 
     tconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
     if (tconn) {
@@ -596,17 +644,17 @@ UV_NukeVolume(afs_int32 server, afs_int32 partid, afs_int32 volid)
 
 /* like df. Return usage of <pname> on <server> in <partition> */
 int
-UV_PartitionInfo64(afs_int32 server, char *pname,
+UV_PartitionInfo64(afs_uint32 server, char *pname,
                   struct diskPartition64 *partition)
 {
-    register struct rx_connection *aconn;
+    struct rx_connection *aconn;
     afs_int32 code = 0;
 
     aconn = (struct rx_connection *)0;
     aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
     code = AFSVolPartitionInfo64(aconn, pname, partition);
     if (code == RXGEN_OPCODE) {
-       struct diskPartition *dpp = 
+       struct diskPartition *dpp =
            (struct diskPartition *)malloc(sizeof(struct diskPartition));
        code = AFSVolPartitionInfo(aconn, pname, dpp);
        if (!code) {
@@ -617,7 +665,7 @@ UV_PartitionInfo64(afs_int32 server, char *pname,
            partition->minFree = dpp->minFree;
        }
        free(dpp);
-    } 
+    }
     if (code) {
        fprintf(STDERR, "Could not get information on partition %s\n", pname);
        PrintError("", code);
@@ -627,29 +675,57 @@ UV_PartitionInfo64(afs_int32 server, char *pname,
     return code;
 }
 
-/* old interface to create volume */
+/* old interface to create volumes */
 int
-UV_CreateVolume(afs_int32 aserver, afs_int32 apart, char *aname,
-               afs_int32 * anewid)
+UV_CreateVolume(afs_uint32 aserver, afs_int32 apart, char *aname,
+               afs_uint32 * anewid)
 {
     afs_int32 code;
+    *anewid = 0;
     code = UV_CreateVolume2(aserver, apart, aname, 5000, 0, 0, 0, 0, anewid);
     return code;
 }
 
-/* create a volume, given a server, partition number, volume name --> sends
-* back new vol id in <anewid>*/
+/* less old interface to create volumes */
 int
-UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
+UV_CreateVolume2(afs_uint32 aserver, afs_int32 apart, char *aname,
                 afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
-                afs_int32 aspare3, afs_int32 aspare4, afs_int32 * anewid)
+                afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid)
 {
+    afs_uint32 roid = 0, bkid = 0;
+    return UV_CreateVolume3(aserver, apart, aname, aquota, aspare1, aspare2,
+       aspare3, aspare4, anewid, &roid, &bkid);
+}
 
-    register struct rx_connection *aconn;
+/**
+ * Create a volume on the given server and partition
+ *
+ * @param aserver  server to create volume on
+ * @param spart  partition to create volume on
+ * @param aname  name of new volume
+ * @param aquota  quota for new volume
+ * @param anewid  contains the desired volume id for the new volume. If
+ *                *anewid == 0, a new id will be chosen, and will be placed
+ *                in *anewid when UV_CreateVolume3 returns.
+ * @param aroid  contains the desired RO volume id. If NULL, the RO id entry
+ *               will be unset. If *aroid == 0, an id will be chosen, and
+ *               will be placed in *anewid when UV_CreateVolume3 returns.
+ * @param abkid  same as aroid, except for the BK volume id instead of the
+ *               RO volume id.
+ * @return 0 on success, error code otherwise.
+ */
+int
+UV_CreateVolume3(afs_uint32 aserver, afs_int32 apart, char *aname,
+                afs_int32 aquota, afs_int32 aspare1, afs_int32 aspare2,
+                afs_int32 aspare3, afs_int32 aspare4, afs_uint32 * anewid,
+                afs_uint32 * aroid, afs_uint32 * abkid)
+{
+    struct rx_connection *aconn;
     afs_int32 tid;
-    register afs_int32 code;
+    afs_int32 code;
     afs_int32 error;
     afs_int32 rcode, vcode;
+    afs_int32 lastid;
     struct nvldbentry entry, storeEntry;       /*the new vldb entry */
     struct volintInfo tstatus;
 
@@ -661,13 +737,49 @@ UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
     tstatus.maxquota = aquota;
 
     aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
-    /* next the next 3 available ids from the VLDB */
-    vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 3, anewid);
-    EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
+
+    if (aroid && *aroid) {
+       VPRINT1("Using RO volume ID %d.\n", *aroid);
+    }
+    if (abkid && *abkid) {
+       VPRINT1("Using BK volume ID %d.\n", *abkid);
+    }
+
+    if (*anewid) {
+        vcode = VLDB_GetEntryByID(*anewid, -1, &entry);
+       if (!vcode) {
+           fprintf(STDERR, "Volume ID %d already exists\n", *anewid);
+           return VVOLEXISTS;
+       }
+       VPRINT1("Using volume ID %d.\n", *anewid);
+    } else {
+       vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, anewid);
+       EGOTO1(cfail, vcode, "Could not get an Id for volume %s\n", aname);
+
+       if (aroid && *aroid == 0) {
+           vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, aroid);
+           EGOTO1(cfail, vcode, "Could not get an RO Id for volume %s\n", aname);
+       }
+
+       if (abkid && *abkid == 0) {
+           vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, abkid);
+           EGOTO1(cfail, vcode, "Could not get a BK Id for volume %s\n", aname);
+       }
+    }
+
+    /* rw,ro, bk id are related in the default case */
+    /* If caller specified RW id, but not RO/BK ids, have them be RW+1 and RW+2 */
+    lastid = *anewid;
+    if (aroid && *aroid == 0) {
+       *aroid = ++lastid;
+    }
+    if (abkid && *abkid == 0) {
+       *abkid = ++lastid;
+    }
 
     code =
-       AFSVolCreateVolume(aconn, apart, aname, volser_RW, 0, anewid, &tid);
-    EGOTO2(cfail, vcode, "Failed to create the volume %s %u \n", aname,
+       AFSVolCreateVolume_retry(aconn, apart, aname, volser_RW, 0, anewid, &tid);
+    EGOTO2(cfail, code, "Failed to create the volume %s %u \n", aname,
           *anewid);
 
     code = AFSVolSetInfo(aconn, tid, &tstatus);
@@ -675,7 +787,7 @@ UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
        EPRINT(code, "Could not change quota, continuing...\n");
 
     code = AFSVolSetFlags(aconn, tid, 0);      /* bring it online (mark it InService */
-    EGOTO2(cfail, vcode, "Could not bring the volume %s %u online \n", aname,
+    EGOTO2(cfail, code, "Could not bring the volume %s %u online \n", aname,
           *anewid);
 
     VPRINT2("Volume %s %u created and brought online\n", aname, *anewid);
@@ -683,15 +795,15 @@ UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
     /* set up the vldb entry for this volume */
     strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
     entry.nServers = 1;
-    entry.serverNumber[0] = aserver;   /* this should have another 
+    entry.serverNumber[0] = aserver;   /* this should have another
                                         * level of indirection later */
-    entry.serverPartition[0] = apart;  /* this should also have 
+    entry.serverPartition[0] = apart;  /* this should also have
                                         * another indirection level */
     entry.flags = RW_EXISTS;   /* this records that rw volume exists */
     entry.serverFlags[0] = ITSRWVOL;   /*this rep site has rw  vol */
     entry.volumeId[RWVOL] = *anewid;
-    entry.volumeId[ROVOL] = *anewid + 1;       /* rw,ro, bk id are related in the default case */
-    entry.volumeId[BACKVOL] = *anewid + 2;
+    entry.volumeId[ROVOL] = aroid ? *aroid : 0;
+    entry.volumeId[BACKVOL] = abkid ? *abkid : 0;
     entry.cloneId = 0;
     /*map into right byte order, before passing to xdr, the stuff has to be in host
      * byte order. Xdr converts it into network order */
@@ -732,17 +844,15 @@ UV_CreateVolume2(afs_int32 aserver, afs_int32 apart, char *aname,
        rx_DestroyConnection(aconn);
     PrintError("", error);
     return error;
-
-
 }
 
 /* create a volume, given a server, partition number, volume name --> sends
 * back new vol id in <anewid>*/
 int
-UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
-               afs_int32 aid)
+UV_AddVLDBEntry(afs_uint32 aserver, afs_int32 apart, char *aname,
+               afs_uint32 aid)
 {
-    register struct rx_connection *aconn;
+    struct rx_connection *aconn;
     afs_int32 error;
     afs_int32 vcode;
     struct nvldbentry entry, storeEntry;       /*the new vldb entry */
@@ -753,9 +863,9 @@ UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
     /* set up the vldb entry for this volume */
     strncpy(entry.name, aname, VOLSER_OLDMAXVOLNAME);
     entry.nServers = 1;
-    entry.serverNumber[0] = aserver;   /* this should have another 
+    entry.serverNumber[0] = aserver;   /* this should have another
                                         * level of indirection later */
-    entry.serverPartition[0] = apart;  /* this should also have 
+    entry.serverPartition[0] = apart;  /* this should also have
                                         * another indirection level */
     entry.flags = RW_EXISTS;   /* this records that rw volume exists */
     entry.serverFlags[0] = ITSRWVOL;   /*this rep site has rw  vol */
@@ -790,11 +900,11 @@ UV_AddVLDBEntry(afs_int32 aserver, afs_int32 apart, char *aname,
 }
 
 /* Delete the volume <volid>on <aserver> <apart>
- * the physical entry gets removed from the vldb only if the ref count 
+ * the physical entry gets removed from the vldb only if the ref count
  * becomes zero
  */
 int
-UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
+UV_DeleteVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
 {
     struct rx_connection *aconn = (struct rx_connection *)0;
     afs_int32 ttid = 0;
@@ -827,7 +937,7 @@ UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
 
     /* Whether volume is in the VLDB or not. Delete the volume on disk */
     aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
-    code = AFSVolTransCreate(aconn, avolid, apart, ITOffline, &ttid);
+    code = AFSVolTransCreate_retry(aconn, avolid, apart, ITOffline, &ttid);
     if (code) {
        if (code == VNOVOL) {
            notondisk = 1;
@@ -874,7 +984,7 @@ UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     else if (avolid == entry.volumeId[ROVOL]) {
        /* Its a read-only volume, modify the VLDB entry. Check that the
         * readonly volume is on the server/partition we asked to delete.
-        * If flags does not have RO_EIXSTS set, then this may mean the RO 
+        * If flags does not have RO_EIXSTS set, then this may mean the RO
         * hasn't been released (and could exist in VLDB).
         */
        if (!Lp_ROMatch(aserver, apart, &entry)) {
@@ -906,8 +1016,9 @@ UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
 
        /* Delete backup if it exists */
        code =
-           AFSVolTransCreate(aconn, entry.volumeId[BACKVOL], apart,
-                             ITOffline, &ttid);
+           AFSVolTransCreate_retry(aconn, entry.volumeId[BACKVOL], apart,
+                                   ITOffline, &ttid);
+
        if (!code) {
            if (verbose) {
                fprintf(STDOUT, "Trying to delete the backup volume %u ...",
@@ -1006,7 +1117,7 @@ UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     if (islocked) {
        code =
            ubik_VL_ReleaseLock(cstruct, 0, avolid, -1,
-                               (LOCKREL_OPCODE | LOCKREL_AFSID | 
+                               (LOCKREL_OPCODE | LOCKREL_AFSID |
                                 LOCKREL_TIMESTAMP));
        if (code) {
            EPRINT1(code,
@@ -1029,11 +1140,19 @@ UV_DeleteVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
 jmp_buf env;
 int interrupt = 0;
 
-void
-sigint_handler(int x)
+static void *
+do_interrupt(void * unused)
 {
-    if (interrupt)
+    if (interrupt) {
+#if !defined(AFS_PTHREAD_ENV) && !defined(AFS_NT40_ENV)
+       /* Avoid UNIX LWP from getting confused that our stack has suddenly
+        * changed. This will avoid some sanity checks, but until a better way
+        * is found, the only alternative is always crashing and burning on at
+        * least the stack-overflow check. */
+       lwp_cpptr->stack = NULL;
+#endif
        longjmp(env, 0);
+    }
 
     fprintf(STDOUT, "\nSIGINT handler: vos move operation in progress\n");
     fprintf(STDOUT,
@@ -1042,37 +1161,58 @@ sigint_handler(int x)
     fflush(STDOUT);
 
     interrupt = 1;
-    (void)signal(SIGINT, sigint_handler);
+    return NULL;
+}
 
-    return;
+static void
+sigint_handler(int x)
+{
+#ifdef AFS_PTHREAD_ENV
+    do_interrupt(NULL);
+#else
+    IOMGR_SoftSig(do_interrupt, 0);
+#endif
+    (void)signal(SIGINT, sigint_handler);
 }
 
 /* Move volume <afromvol> on <afromserver> <afrompart> to <atoserver>
  * <atopart>.  The operation is almost idempotent.  The following
  * flags are recognized:
- * 
+ *
  *     RV_NOCLONE - don't use a copy clone
  */
 
 int
-UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
-              afs_int32 atoserver, afs_int32 atopart, int flags)
+UV_MoveVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
+              afs_uint32 atoserver, afs_int32 atopart, int flags)
 {
-    struct rx_connection *toconn, *fromconn;
-    afs_int32 fromtid, totid, clonetid;
+    /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
+     * be changing during the move */
+    struct rx_connection * volatile toconn;
+    struct rx_connection * volatile fromconn;
+    afs_int32 volatile fromtid;
+    afs_int32 volatile totid;
+    afs_int32 volatile clonetid;
+    afs_uint32 volatile newVol;
+    afs_uint32 volatile volid;
+    afs_uint32 volatile backupId;
+    int volatile islocked;
+    int volatile pntg;
+
     char vname[64];
     char *volName = 0;
     char tmpName[VOLSER_MAXVOLNAME + 1];
     afs_int32 rcode;
     afs_int32 fromDate;
+    afs_int32 tmp;
+    afs_uint32 tmpVol;
     struct restoreCookie cookie;
-    register afs_int32 vcode, code;
-    afs_int32 newVol, volid, backupId;
+    afs_int32 vcode, code;
     struct volser_status tstatus;
     struct destServer destination;
 
     struct nvldbentry entry, storeEntry;
-    int i, islocked, pntg;
+    int i;
     afs_int32 error;
     char in, lf;               /* for test code */
     int same;
@@ -1178,9 +1318,12 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        fromtid = 0;
        pntg = 1;
 
+       tmp = fromtid;
        code =
-           AFSVolTransCreate(fromconn, afromvol, afrompart, ITOffline,
-                             &fromtid);
+           AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITOffline,
+                                   &tmp);
+       fromtid = tmp;
+
        if (!code) {            /* volume exists - delete it */
            VPRINT1("Setting flags on leftover source volume %u ...",
                    afromvol);
@@ -1214,8 +1357,10 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        /*delete the backup volume now */
        fromtid = 0;
        code =
-           AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
-                             &fromtid);
+           AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
+                                   &tmp);
+       fromtid = tmp;
+
        if (!code) {            /* backup volume exists - delete it */
            VPRINT1("Setting flags on leftover backup volume %u ...",
                    backupId);
@@ -1251,8 +1396,8 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     }
 
     /* From-info matches the vldb info about volid,
-     * its ok start the move operation, the backup volume 
-     * on the old site is deleted in the process 
+     * its ok start the move operation, the backup volume
+     * on the old site is deleted in the process
      */
     if (afrompart == atopart) {
        same = VLDB_IsSameAddrs(afromserver, atoserver, &error);
@@ -1277,7 +1422,8 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
      * ***/
 
     VPRINT1("Starting transaction on source volume %u ...", afromvol);
-    code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
+    code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
+    fromtid = tmp;
     EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
           afromvol);
     VDONE;
@@ -1286,8 +1432,9 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        /* Get a clone id */
        VPRINT1("Allocating new volume id for clone of volume %u ...",
                afromvol);
-       newVol = 0;
-       vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &newVol);
+       newVol = tmpVol = 0;
+       vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
+       newVol = tmpVol;
        EGOTO1(mfail, vcode,
               "Could not get an ID for the clone of volume %u from the VLDB\n",
               afromvol);
@@ -1297,7 +1444,8 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        VPRINT1("Cloning source volume %u ...", afromvol);
        strcpy(vname, "move-clone-temp");
        code =
-           AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &newVol);
+           AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
+       newVol = tmpVol;
        EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
               afromvol);
        VDONE;
@@ -1327,9 +1475,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     if (!(flags & RV_NOCLONE)) {
        /* All of this is to get the fromDate */
        VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
-                             &clonetid);
+           AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
+                             &tmp);
+       clonetid = tmp;
        EGOTO1(mfail, code,
               "Failed to start a transaction on the cloned volume%u\n",
               newVol);
@@ -1379,7 +1529,9 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
 
     /* create a volume on the target machine */
     volid = afromvol;
-    code = AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
+    tmp = totid;
+    code = AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
+    totid = tmp;
     if (!code) {
        /* Delete the existing volume.
         * While we are deleting the volume in these steps, the transaction
@@ -1407,9 +1559,13 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     }
 
     VPRINT1("Creating the destination volume %u ...", volid);
+    tmp = totid;
+    tmpVol = volid;
     code =
-       AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &volid,
-                          &totid);
+       AFSVolCreateVolume(toconn, atopart, volName, volser_RW, volid, &tmpVol,
+                          &tmp);
+    totid = tmp;
+    volid = tmpVol;
     EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
           volid);
     VDONE;
@@ -1464,7 +1620,9 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
      * ***/
 
     VPRINT1("Starting transaction on source volume %u ...", afromvol);
-    code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
+    tmp = fromtid;
+    code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
+    fromtid = tmp;
     EGOTO1(mfail, code,
           "Failed to create a transaction on the source volume %u\n",
           afromvol);
@@ -1615,8 +1773,10 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     /* Delete the backup volume on the original site */
     VPRINT1("Creating transaction for backup volume %u on source ...",
            backupId);
+    tmp = fromtid;
     code =
-       AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline, &fromtid);
+       AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline, &tmp);
+    fromtid = tmp;
     VDONE;
     if (!code) {
        VPRINT1("Setting flags on backup volume %u on source ...", backupId);
@@ -1651,9 +1811,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     fromtid = 0;
     if (!(flags & RV_NOCLONE)) {
        VPRINT1("Starting transaction on the cloned volume %u ...", newVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
-                             &clonetid);
+           AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
+                             &tmp);
+       clonetid = tmp;
        EGOTO1(mfail, code,
               "Failed to start a transaction on the cloned volume%u\n",
               newVol);
@@ -1790,6 +1952,7 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
                  (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
        VDONE;
+       islocked = 0;
     }
 
     if (clonetid) {
@@ -1821,9 +1984,9 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     }
     MapHostToNetwork(&entry);
 
-    /* Delete either the volume on the source location or the target location. 
+    /* Delete either the volume on the source location or the target location.
      * If the vldb entry still points to the source location, then we know the
-     * volume move didn't finish so we remove the volume from the target 
+     * volume move didn't finish so we remove the volume from the target
      * location. Otherwise, we remove the volume from the source location.
      */
     if (Lp_Match(afromserver, afrompart, &entry)) {    /* didn't move - delete target volume */
@@ -1837,8 +2000,10 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
            VPRINT1
                ("Recovery: Creating transaction for destination volume %u ...",
                 volid);
+           tmp = totid;
            code =
-               AFSVolTransCreate(toconn, volid, atopart, ITOffline, &totid);
+               AFSVolTransCreate_retry(toconn, volid, atopart, ITOffline, &tmp);
+           totid = tmp;
 
            if (!code) {
                VDONE;
@@ -1871,9 +2036,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        if (fromconn) {
            VPRINT1("Recovery: Creating transaction on source volume %u ...",
                    afromvol);
+           tmp = fromtid;
            code =
-               AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
-                                 &fromtid);
+               AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
+                                 &tmp);
+           fromtid = tmp;
            if (!code) {
                VDONE;
 
@@ -1904,9 +2071,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        if (fromconn) {
            VPRINT1("Recovery: Creating transaction on backup volume %u ...",
                    backupId);
+           tmp = fromtid;
            code =
-               AFSVolTransCreate(fromconn, backupId, afrompart, ITOffline,
-                                 &fromtid);
+               AFSVolTransCreate_retry(fromconn, backupId, afrompart, ITOffline,
+                                 &tmp);
+           fromtid = tmp;
            if (!code) {
                VDONE;
 
@@ -1934,9 +2103,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
            /* delete source volume */
            VPRINT1("Recovery: Creating transaction on source volume %u ...",
                    afromvol);
+           tmp = fromtid;
            code =
-               AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
-                                 &fromtid);
+               AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
+                                 &tmp);
+           fromtid = tmp;
            if (!code) {
                VDONE;
 
@@ -1973,9 +2144,11 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     if (newVol) {
        VPRINT1("Recovery: Creating transaction on clone volume %u ...",
                newVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, newVol, afrompart, ITOffline,
-                             &clonetid);
+           AFSVolTransCreate_retry(fromconn, newVol, afrompart, ITOffline,
+                             &tmp);
+       clonetid = tmp;
        if (!code) {
            VDONE;
 
@@ -1995,12 +2168,14 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     }
 
     /* unlock VLDB entry */
-    VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
-           afromvol);
-    ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
-             (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
-    VDONE;
-
+    if (islocked) {
+       VPRINT1("Recovery: Releasing lock on VLDB entry for volume %u ...",
+               afromvol);
+       ubik_VL_ReleaseLock(cstruct, 0, afromvol, -1,
+                           (LOCKREL_OPCODE | LOCKREL_AFSID | LOCKREL_TIMESTAMP));
+       VDONE;
+       islocked = 0;
+    }
   done:                        /* routine cleanup */
     if (volName)
        free(volName);
@@ -2022,8 +2197,8 @@ UV_MoveVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
 
 
 int
-UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
-             afs_int32 atoserver, afs_int32 atopart)
+UV_MoveVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
+             afs_uint32 atoserver, afs_int32 atopart)
 {
     return UV_MoveVolume2(afromvol, afromserver, afrompart,
                          atoserver, atopart, 0);
@@ -2034,7 +2209,7 @@ UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
  * <atopart>.  The new volume is named by <atovolname>.  The new volume
  * has ID <atovolid> if that is nonzero; otherwise a new ID is allocated
  * from the VLDB.  the following flags are supported:
- * 
+ *
  *     RV_RDONLY  - target volume is RO
  *     RV_OFFLINE - leave target volume offline
  *     RV_CPINCR  - do incremental dump if target exists
@@ -2042,27 +2217,34 @@ UV_MoveVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
  *     RV_NOCLONE - don't use a copy clone
  */
 int
-UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
-              char *atovolname, afs_int32 atoserver, afs_int32 atopart,
-              afs_int32 atovolid, int flags)
+UV_CopyVolume2(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
+              char *atovolname, afs_uint32 atoserver, afs_int32 atopart,
+              afs_uint32 atovolid, int flags)
 {
-    struct rx_connection *toconn, *fromconn;
-    afs_int32 fromtid, totid, clonetid;
+    /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
+     * be changing during the copy */
+    int volatile pntg;
+    afs_int32 volatile clonetid;
+    afs_int32 volatile totid;
+    afs_int32 volatile fromtid;
+    struct rx_connection * volatile fromconn;
+    struct rx_connection * volatile toconn;
+    afs_uint32 volatile cloneVol;
+
     char vname[64];
     afs_int32 rcode;
     afs_int32 fromDate, cloneFromDate;
     struct restoreCookie cookie;
-    register afs_int32 vcode, code;
-    afs_int32 cloneVol, newVol, volflag;
+    afs_int32 vcode, code;
+    afs_uint32 newVol;
+    afs_int32 volflag;
     struct volser_status tstatus;
     struct destServer destination;
-
     struct nvldbentry entry, newentry, storeEntry;
-    int islocked, pntg;
     afs_int32 error;
-    int justclone = 0;
+    afs_int32 tmp;
+    afs_uint32 tmpVol;
 
-    islocked = 0;
     fromconn = (struct rx_connection *)0;
     toconn = (struct rx_connection *)0;
     fromtid = 0;
@@ -2088,12 +2270,6 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
     fromtid = totid = 0;       /* initialize to uncreated */
 
-
-    /* check if we can shortcut and use a local clone instead of a full copy */
-    if (afromserver == atoserver && afrompart == atopart) {
-       justclone = 1;
-    }
-
     /* ***
      * clone the read/write volume locally.
      * ***/
@@ -2101,8 +2277,10 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     cloneVol = 0;
     if (!(flags & RV_NOCLONE)) {
        VPRINT1("Starting transaction on source volume %u ...", afromvol);
-       code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
-                                &fromtid);
+       tmp = fromtid;
+       code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
+                                &tmp);
+       fromtid = tmp;
        EGOTO1(mfail, code, "Failed to create transaction on the volume %u\n",
               afromvol);
        VDONE;
@@ -2111,7 +2289,9 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        VPRINT1("Allocating new volume id for clone of volume %u ...",
                afromvol);
        cloneVol = 0;
-       vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &cloneVol);
+       tmpVol = cloneVol;
+       vcode = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
+       cloneVol = tmpVol;
        EGOTO1(mfail, vcode,
           "Could not get an ID for the clone of volume %u from the VLDB\n",
           afromvol);
@@ -2135,9 +2315,11 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
        /* Do the clone. Default flags on clone are set to delete on salvage and out of service */
        VPRINT1("Cloning source volume %u ...", afromvol);
        strcpy(vname, "copy-clone-temp");
+       tmpVol = cloneVol;
        code =
            AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname,
-                       &cloneVol);
+                       &tmpVol);
+       cloneVol = tmpVol;
        EGOTO1(mfail, code, "Failed to clone the source volume %u\n",
               afromvol);
        VDONE;
@@ -2160,9 +2342,11 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
 
     if (!(flags & RV_NOCLONE)) {
        VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
-                         &clonetid);
+           AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
+                         &tmp);
+       clonetid = tmp;
        EGOTO1(mfail, code,
               "Failed to start a transaction on the cloned volume%u\n",
               cloneVol);
@@ -2191,7 +2375,9 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
 
     /* create a volume on the target machine */
     cloneFromDate = 0;
-    code = AFSVolTransCreate(toconn, newVol, atopart, ITOffline, &totid);
+    tmp = totid;
+    code = AFSVolTransCreate_retry(toconn, newVol, atopart, ITOffline, &tmp);
+    totid = tmp;
     if (!code) {
        if ((flags & RV_CPINCR)) {
            VPRINT1("Getting status of pre-existing volume %u ...", newVol);
@@ -2239,10 +2425,12 @@ UV_CopyVolume2(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     }
 
     VPRINT1("Creating the destination volume %u ...", newVol);
+    tmp = totid;
     code =
        AFSVolCreateVolume(toconn, atopart, atovolname,
                           (flags & RV_RDONLY) ? volser_RO : volser_RW,
-                          newVol, &newVol, &totid);
+                          newVol, &newVol, &tmp);
+    totid = tmp;
     EGOTO1(mfail, code, "Failed to create the destination volume %u\n",
           newVol);
     VDONE;
@@ -2300,7 +2488,9 @@ cpincr:
      * ***/
 
     VPRINT1("Starting transaction on source volume %u ...", afromvol);
-    code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
+    tmp = fromtid;
+    code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
+    fromtid = tmp;
     EGOTO1(mfail, code,
           "Failed to create a transaction on the source volume %u\n",
           afromvol);
@@ -2316,7 +2506,7 @@ cpincr:
                      &cookie);
     EGOTO1(mfail, code,
           "Failed to do the%s dump from old site to new site\n",
-          afromvol);
+          (flags & RV_NOCLONE) ? "" : " incremental");
     VDONE;
 
     VPRINT1("Setting volume flags on destination volume %u ...", newVol);
@@ -2351,9 +2541,11 @@ cpincr:
 
     if (!(flags & RV_NOCLONE)) {
        VPRINT1("Starting transaction on the cloned volume %u ...", cloneVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
-                             &clonetid);
+           AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
+                             &tmp);
+       clonetid = tmp;
        EGOTO1(mfail, code,
               "Failed to start a transaction on the cloned volume%u\n",
               cloneVol);
@@ -2500,9 +2692,11 @@ cpincr:
     if (cloneVol) {
        VPRINT1("Recovery: Creating transaction on clone volume %u ...",
                cloneVol);
+       tmp = clonetid;
        code =
-           AFSVolTransCreate(fromconn, cloneVol, afrompart, ITOffline,
-                             &clonetid);
+           AFSVolTransCreate_retry(fromconn, cloneVol, afrompart, ITOffline,
+                             &tmp);
+       clonetid = tmp;
        if (!code) {
            VDONE;
 
@@ -2536,8 +2730,8 @@ cpincr:
 
 
 int
-UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
-             char *atovolname, afs_int32 atoserver, afs_int32 atopart)
+UV_CopyVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
+             char *atovolname, afs_uint32 atoserver, afs_int32 atopart)
 {
     return UV_CopyVolume2(afromvol, afromserver, afrompart,
                           atovolname, atoserver, atopart, 0, 0);
@@ -2545,16 +2739,16 @@ UV_CopyVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
 
 
 
-/* Make a new backup of volume <avolid> on <aserver> and <apart> 
- * if one already exists, update it 
+/* Make a new backup of volume <avolid> on <aserver> and <apart>
+ * if one already exists, update it
  */
 
 int
-UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
+UV_BackupVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid)
 {
     struct rx_connection *aconn = (struct rx_connection *)0;
     afs_int32 ttid = 0, btid = 0;
-    afs_int32 backupID;
+    afs_uint32 backupID;
     afs_int32 code = 0, rcode = 0;
     char vname[VOLSER_MAXVOLNAME + 1];
     struct nvldbentry entry, storeEntry;
@@ -2614,7 +2808,7 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     backupID = entry.volumeId[BACKVOL];
     if (backupID == INVALID_BID) {
        /* Get a backup volume id from the VLDB and update the vldb
-        * entry with it. 
+        * entry with it.
         */
        code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &backupID);
        if (code) {
@@ -2631,7 +2825,7 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     /* Test to see if the backup volume exists by trying to create
      * a transaction on the backup volume. We've assumed the backup exists.
      */
-    code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
+    code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
     if (code) {
        if (code != VNOVOL) {
            fprintf(STDERR, "Could not reach the backup volume %lu\n",
@@ -2654,9 +2848,9 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     }
 
     /* Now go ahead and try to clone the RW volume.
-     * First start a transaction on the RW volume 
+     * First start a transaction on the RW volume
      */
-    code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
+    code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
     if (code) {
        fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
                (unsigned long)avolid);
@@ -2664,7 +2858,7 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
        goto bfail;
     }
 
-    /* Clone or reclone the volume, depending on whether the backup 
+    /* Clone or reclone the volume, depending on whether the backup
      * volume exists or not
      */
     if (backexists) {
@@ -2710,7 +2904,7 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     }
 
     /* Now go back to the backup volume and bring it on line */
-    code = AFSVolTransCreate(aconn, backupID, apart, ITOffline, &btid);
+    code = AFSVolTransCreate_retry(aconn, backupID, apart, ITOffline, &btid);
     if (code) {
        fprintf(STDERR,
                "Failed to start a transaction on the backup volume %lu\n",
@@ -2800,19 +2994,19 @@ UV_BackupVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid)
     return error;
 }
 
-/* Make a new clone of volume <avolid> on <aserver> and <apart> 
+/* Make a new clone of volume <avolid> on <aserver> and <apart>
  * using volume ID <acloneid>, or a new ID allocated from the VLDB.
  * The new volume is named by <aname>, or by appending ".clone" to
  * the existing name if <aname> is NULL.  The following flags are
  * supported:
- * 
+ *
  *     RV_RDONLY  - target volume is RO
  *     RV_OFFLINE - leave target volume offline
  */
 
 int
-UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
-              afs_int32 acloneid, char *aname, int flags)
+UV_CloneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 avolid,
+              afs_uint32 acloneid, char *aname, int flags)
 {
     struct rx_connection *aconn = (struct rx_connection *)0;
     afs_int32 ttid = 0, btid = 0;
@@ -2858,7 +3052,7 @@ UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
      * a transaction on the clone volume. We've assumed the clone exists.
      */
     /* XXX I wonder what happens if the clone has some other parent... */
-    code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
+    code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
     if (code) {
        if (code != VNOVOL) {
            fprintf(STDERR, "Could not reach the clone volume %lu\n",
@@ -2881,9 +3075,9 @@ UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
     }
 
     /* Now go ahead and try to clone the RW volume.
-     * First start a transaction on the RW volume 
+     * First start a transaction on the RW volume
      */
-    code = AFSVolTransCreate(aconn, avolid, apart, ITBusy, &ttid);
+    code = AFSVolTransCreate_retry(aconn, avolid, apart, ITBusy, &ttid);
     if (code) {
        fprintf(STDERR, "Could not start a transaction on the volume %lu\n",
                (unsigned long)avolid);
@@ -2891,7 +3085,7 @@ UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
        goto bfail;
     }
 
-    /* Clone or reclone the volume, depending on whether the backup 
+    /* Clone or reclone the volume, depending on whether the backup
      * volume exists or not
      */
     if (backexists) {
@@ -2931,7 +3125,7 @@ UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
 
     /* Now go back to the backup volume and bring it on line */
     if (!(flags & RV_OFFLINE)) {
-       code = AFSVolTransCreate(aconn, acloneid, apart, ITOffline, &btid);
+       code = AFSVolTransCreate_retry(aconn, acloneid, apart, ITOffline, &btid);
        if (code) {
            fprintf(STDERR,
                    "Failed to start a transaction on the clone volume %lu\n",
@@ -2991,13 +3185,13 @@ UV_CloneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 avolid,
 }
 
 static int
-DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
+DelVol(struct rx_connection *conn, afs_uint32 vid, afs_int32 part,
        afs_int32 flags)
 {
     afs_int32 acode, ccode, rcode, tid;
     ccode = rcode = tid = 0;
 
-    acode = AFSVolTransCreate(conn, vid, part, flags, &tid);
+    acode = AFSVolTransCreate_retry(conn, vid, part, flags, &tid);
     if (!acode) {              /* It really was there */
        acode = AFSVolDeleteVolume(conn, tid);
        if (acode) {
@@ -3019,20 +3213,23 @@ DelVol(struct rx_connection *conn, afs_int32 vid, afs_int32 part,
 }
 
 #define ONERROR(ec, ep, es) if (ec) { fprintf(STDERR, (es), (ep)); error = (ec); goto rfail; }
+#define ONERROR0(ec, es) if (ec) { fprintf(STDERR, (es)); error = (ec); goto rfail; }
 #define ERROREXIT(ec) { error = (ec); goto rfail; }
 
-/* Get a "transaction" on this replica.  Create the volume 
+/* Get a "transaction" on this replica.  Create the volume
  * if necessary.  Return the time from which a dump should
  * be made (0 if it's a new volume)
  */
 static int
 GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
         struct rx_connection **connPtr, afs_int32 * transPtr,
-        afs_int32 * crtimePtr, afs_int32 * uptimePtr)
+        afs_uint32 * crtimePtr, afs_uint32 * uptimePtr,
+        afs_int32 *origflags)
 {
-    afs_int32 volid;
+    afs_uint32 volid;
     struct volser_status tstatus;
-    int code, rcode, tcode;
+    int code = 0;
+    int rcode, tcode;
     char hoststr[16];
 
     *connPtr = (struct rx_connection *)0;
@@ -3046,12 +3243,51 @@ GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
        goto fail;              /* server is down */
 
     volid = vldbEntryPtr->volumeId[ROVOL];
-    if (volid)
+    if (volid) {
        code =
-           AFSVolTransCreate(*connPtr, volid,
+           AFSVolTransCreate_retry(*connPtr, volid,
                              vldbEntryPtr->serverPartition[index], ITOffline,
                              transPtr);
 
+       if (!code && (origflags[index] & RO_DONTUSE)) {
+           /* If RO_DONTUSE is set, this is supposed to be an entirely new
+            * site. Don't trust any data on it, since it is possible we
+            * have encountered some temporary volume from some other
+            * incomplete volume operation. It is difficult to detect if
+            * that has happened vs if this is a legit volume, so just
+            * delete it to be safe. */
+
+           VPRINT1("Deleting extant RO_DONTUSE site on %s...",
+                    noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
+                                                serverNumber[index], hoststr) :
+                    hostutil_GetNameByINet(vldbEntryPtr->
+                                          serverNumber[index]));
+
+           code = AFSVolDeleteVolume(*connPtr, *transPtr);
+           if (code) {
+               PrintError("Failed to delete RO_DONTUSE site: ", code);
+               goto fail;
+           }
+
+           tcode = AFSVolEndTrans(*connPtr, *transPtr, &rcode);
+           *transPtr = 0;
+           if (!tcode) {
+               tcode = rcode;
+           }
+           if (tcode) {
+               PrintError("Failed to end transaction on RO_DONTUSE site: ",
+                          tcode);
+               goto fail;
+           }
+
+           VDONE;
+
+           /* emulate what TransCreate would have returned, so we try to
+            * create the volume below */
+           code = VNOVOL;
+       }
+    }
+
     /* If the volume does not exist, create it */
     if (!volid || code) {
        char volname[64];
@@ -3101,12 +3337,12 @@ GetTrans(struct nvldbentry *vldbEntryPtr, afs_int32 index,
     }
 
     /* Otherwise, the transaction did succeed, so get the creation date of the
-     * latest RO volume on the replication site 
+     * latest RO volume on the replication site
      */
     else {
        VPRINT2("Updating existing ro volume %u on %s ...\n", volid,
                 noresolve ? afs_inet_ntoa_r(vldbEntryPtr->
-                                            serverNumber[index], hoststr) : 
+                                            serverNumber[index], hoststr) :
                 hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
 
        code = AFSVolGetStatus(*connPtr, *transPtr, &tstatus);
@@ -3139,7 +3375,7 @@ SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
                        afs_int32 fromdate, manyDests * tr, afs_int32 flags,
                        void *cookie, manyResults * results)
 {
-    int i;
+    unsigned int i;
 
     for (i = 0; i < tr->manyDests_len; i++) {
        results->manyResults_val[i] =
@@ -3159,19 +3395,20 @@ SimulateForwardMultiple(struct rx_connection *fromconn, afs_int32 fromtid,
  *    successfully.
  *    forceflag: Performs a full release.
  *
- *    Will create a clone from the RW, then dump the clone out to 
+ *    Will create a clone from the RW, then dump the clone out to
  *    the remaining replicas. If there is more than 1 RO sites,
  *    ensure that the VLDB says at least one RO is available all
  *    the time: Influences when we write back the VLDB entry.
  */
 
 int
-UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
+UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
                 afs_int32 afrompart, int forceflag)
 {
     char vname[64];
-    afs_int32 code, vcode, rcode, tcode;
-    afs_int32 cloneVolId, roVolId;
+    afs_int32 code = 0;
+    afs_int32 vcode, rcode, tcode;
+    afs_uint32 cloneVolId, roVolId;
     struct replica *replicas = 0;
     struct nvldbentry entry, storeEntry;
     int i, volcount, m, fullrelease, vldbindex;
@@ -3185,13 +3422,15 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
     int islocked = 0;
     afs_int32 clonetid = 0, onlinetid;
     afs_int32 fromtid = 0;
-    afs_uint32 fromdate, thisdate;
+    afs_uint32 fromdate = 0;
+    afs_uint32 thisdate;
     time_t tmv;
     int s;
     manyDests tr;
     manyResults results;
     int rwindex, roindex, roclone, roexists;
-    afs_int32 rwcrdate, rwupdate, clcrdate;
+    afs_uint32 rwcrdate = 0;
+    afs_uint32 clcrdate;
     struct rtime {
        int validtime;
        afs_uint32 uptime;
@@ -3199,9 +3438,11 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
     int releasecount = 0;
     struct volser_status volstatus;
     char hoststr[16];
+    afs_int32 origflags[NMAXNSERVERS];
 
-    memset((char *)remembertime, 0, sizeof(remembertime));
-    memset((char *)&results, 0, sizeof(results));
+    memset(remembertime, 0, sizeof(remembertime));
+    memset(&results, 0, sizeof(results));
+    memset(origflags, 0, sizeof(origflags));
 
     vcode = ubik_VL_SetLock(cstruct, 0, afromvol, RWVOL, VLOP_RELEASE);
     if (vcode != VL_RERELEASE)
@@ -3240,7 +3481,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
     roclone = ((roindex == -1) ? 0 : 1);
     rwindex = Lp_GetRwIndex(&entry);
     if (rwindex < 0)
-       ONERROR(VOLSERNOVOL, 0, "There is no RW volume \n");
+       ONERROR0(VOLSERNOVOL, "There is no RW volume \n");
 
     /* Make sure we have a RO volume id to work with */
     if (entry.volumeId[ROVOL] == INVALID_BID) {
@@ -3260,6 +3501,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            m++;
            if (entry.serverFlags[i] & NEW_REPSITE) s++;
        }
+       origflags[i] = entry.serverFlags[i];
     }
     if ((forceflag && !fullrelease) || (s == m) || (s == 0))
        fullrelease = 1;
@@ -3281,7 +3523,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            fullrelease = 1;    /* Do a full release if RO clone does not exist */
        else {
            /* Begin transaction on RW and mark it busy while we query it */
-           code = AFSVolTransCreate(
+           code = AFSVolTransCreate_retry(
                        fromconn, afromvol, afrompart, ITBusy, &fromtid
                   );
            ONERROR(code, afromvol,
@@ -3292,7 +3534,6 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            ONERROR(code, afromvol,
                    "Failed to get the status of RW volume %u\n");
            rwcrdate = volstatus.creationDate;
-           rwupdate = volstatus.updateDate;
 
            /* End transaction on RW */
            code = AFSVolEndTrans(fromconn, fromtid, &rcode);
@@ -3301,7 +3542,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
                    "Failed to end transaction on RW volume %u\n");
 
            /* Begin transaction on clone and mark it busy while we query it */
-           code = AFSVolTransCreate(
+           code = AFSVolTransCreate_retry(
                        fromconn, cloneVolId, afrompart, ITBusy, &clonetid
                   );
            ONERROR(code, cloneVolId,
@@ -3367,7 +3608,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
 
        /* Begin transaction on RW and mark it busy while we clone it */
        code =
-           AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy,
+           AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy,
                              &clonetid);
        ONERROR(code, afromvol, "Failed to start transaction on volume %u\n");
 
@@ -3400,7 +3641,6 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
                "Failed to get the status of the RW volume %u\n");
        VDONE;
        rwcrdate = volstatus.creationDate;
-       rwupdate = volstatus.updateDate;
 
        /* End the transaction on the RW volume */
        VPRINT1("Ending cloning transaction on RW volume %u...", afromvol);
@@ -3418,7 +3658,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            VPRINT1("Starting transaction on RO clone volume %u...",
                    cloneVolId);
            code =
-               AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITOffline,
+               AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITOffline,
                                  &onlinetid);
            ONERROR(code, cloneVolId,
                    "Failed to start transaction on volume %u\n");
@@ -3437,7 +3677,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            ONERROR(tcode, cloneVolId, "Could not bring volume %u on line\n");
 
            /* Sleep so that a client searching for an online volume won't
-            * find the clone offline and then the next RO offline while the 
+            * find the clone offline and then the next RO offline while the
             * release brings the clone online and the next RO offline (race).
             * There is a fix in the 3.4 client that does not need this sleep
             * anymore, but we don't know what clients we have.
@@ -3492,7 +3732,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
     results.manyResults_val =
        (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
     if (!replicas || !times || !!!results.manyResults_val || !toconns)
-       ONERROR(ENOMEM, 0,
+       ONERROR0(ENOMEM,
                "Failed to create transaction on the release clone\n");
 
     memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
@@ -3503,11 +3743,11 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
     /* Create a transaction on the cloned volume */
     VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
     code =
-       AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
+       AFSVolTransCreate_retry(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
     if (!fullrelease && code)
        ONERROR(VOLSERNOVOL, afromvol,
                "Old clone is inaccessible. Try vos release -f %u.\n");
-    ONERROR(code, 0, "Failed to create transaction on the release clone\n");
+    ONERROR0(code, "Failed to create transaction on the release clone\n");
     VDONE;
 
     /* For each index in the VLDB */
@@ -3537,7 +3777,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
            /* Get a Transaction on this replica. Get a new connection if
             * necessary.  Create the volume if necessary.  Return the
             * time from which the dump should be made (0 if it's a new
-            * volume).  Each volume might have a different time. 
+            * volume).  Each volume might have a different time.
             */
            replicas[volcount].server.destHost =
                ntohl(entry.serverNumber[vldbindex]);
@@ -3549,7 +3789,8 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
                GetTrans(&entry, vldbindex, &(toconns[volcount]),
                         &(replicas[volcount].trans),
                         &(times[volcount].crtime),
-                        &(times[volcount].uptime));
+                        &(times[volcount].uptime),
+                        origflags);
            if (code)
                continue;
 
@@ -3670,7 +3911,7 @@ UV_ReleaseVolume(afs_int32 afromvol, afs_int32 afromserver,
 
                /* have to clear dest. flags to ensure new vol goes online:
                 * because the restore (forwarded) operation copied
-                * the V_inService(=0) flag over to the destination. 
+                * the V_inService(=0) flag over to the destination.
                 */
                code = AFSVolSetFlags(toconns[m], replicas[m].trans, 0);
                if (code) {
@@ -3865,17 +4106,23 @@ dump_sig_handler(int x)
 /* Dump the volume <afromvol> on <afromserver> and
  * <afrompart> to <afilename> starting from <fromdate>.
  * DumpFunction does the real work behind the scenes after
- * extracting parameters from the rock 
+ * extracting parameters from the rock
  */
 int
-UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
-             afs_int32 fromdate, afs_int32(*DumpFunction) (), char *rock,
+UV_DumpVolume(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
+             afs_int32 fromdate,
+             afs_int32(*DumpFunction) (struct rx_call *, void *), void *rock,
              afs_int32 flags)
 {
-    struct rx_connection *fromconn = (struct rx_connection *)0;
-    struct rx_call *fromcall = (struct rx_call *)0;
-    afs_int32 fromtid = 0, rxError = 0, rcode = 0;
-    afs_int32 code, error = 0, retry = 0;
+    /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
+     * be changing during the dump */
+    struct rx_call * volatile fromcall = NULL;
+    struct rx_connection * volatile fromconn = NULL;
+    afs_int32 volatile fromtid = 0;
+
+    afs_int32 rxError = 0, rcode = 0;
+    afs_int32 code, error = 0;
+    afs_int32 tmp;
     time_t tmv = fromdate;
 
     if (setjmp(env))
@@ -3896,7 +4143,9 @@ UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
 
     VEPRINT1("Starting transaction on volume %u...", afromvol);
-    code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
+    tmp = fromtid;
+    code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &tmp);
+    fromtid = tmp;
     EGOTO1(error_exit, code,
           "Could not start transaction on the volume %u to be dumped\n",
           afromvol);
@@ -3905,17 +4154,16 @@ UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     fromcall = rx_NewCall(fromconn);
 
     VEPRINT1("Starting volume dump on volume %u...", afromvol);
-    if (flags & VOLDUMPV2_OMITDIRS) 
+    if (flags & VOLDUMPV2_OMITDIRS)
        code = StartAFSVolDumpV2(fromcall, fromtid, fromdate, flags);
     else
-      retryold:
        code = StartAFSVolDump(fromcall, fromtid, fromdate);
     EGOTO(error_exit, code, "Could not start the dump process \n");
     VEDONE;
 
     VEPRINT1("Dumping volume %u...", afromvol);
     code = DumpFunction(fromcall, rock);
-    if (code == RXGEN_OPCODE) 
+    if (code == RXGEN_OPCODE)
        goto error_exit;
     EGOTO(error_exit, code, "Error while dumping volume \n");
     VEDONE;
@@ -3923,7 +4171,7 @@ UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
   error_exit:
     if (fromcall) {
        code = rx_EndCall(fromcall, rxError);
-       if (code && code != RXGEN_OPCODE) 
+       if (code && code != RXGEN_OPCODE)
            fprintf(STDERR, "Error in rx_EndCall\n");
        if (code && !error)
            error = code;
@@ -3942,30 +4190,34 @@ UV_DumpVolume(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     if (fromconn)
        rx_DestroyConnection(fromconn);
 
-    if (retry)
-       goto retryold;
     if (error != RXGEN_OPCODE)
        PrintError("", error);
     return (error);
 }
 
 /* Clone the volume <afromvol> on <afromserver> and
- * <afrompart>, and then dump the clone volume to 
+ * <afrompart>, and then dump the clone volume to
  * <afilename> starting from <fromdate>.
  * DumpFunction does the real work behind the scenes after
- * extracting parameters from the rock 
+ * extracting parameters from the rock
  */
 int
-UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
+UV_DumpClonedVolume(afs_uint32 afromvol, afs_uint32 afromserver,
                    afs_int32 afrompart, afs_int32 fromdate,
-                   afs_int32(*DumpFunction) (), char *rock, afs_int32 flags)
+                   afs_int32(*DumpFunction) (struct rx_call *, void *),
+                   void *rock, afs_int32 flags)
 {
-    struct rx_connection *fromconn = (struct rx_connection *)0;
-    struct rx_call *fromcall = (struct rx_call *)0;
+    /* declare stuff 'volatile' that may be used from setjmp/longjmp and may
+     * be changing during the dump */
+    struct rx_connection * volatile fromconn = NULL;
+    struct rx_call * volatile fromcall = NULL;
+    afs_int32 volatile clonetid = 0;
+    afs_uint32 volatile clonevol = 0;
+
+    afs_int32 tmp;
     afs_int32 fromtid = 0, rxError = 0, rcode = 0;
-    afs_int32 clonetid = 0;
-    afs_int32 code = 0, vcode = 0, error = 0;
-    afs_int32 clonevol = 0;
+    afs_int32 code = 0, error = 0;
+    afs_uint32 tmpVol;
     char vname[64];
     time_t tmv = fromdate;
 
@@ -3987,7 +4239,7 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
     fromconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
 
     VEPRINT1("Starting transaction on volume %u...", afromvol);
-    code = AFSVolTransCreate(fromconn, afromvol, afrompart, ITBusy, &fromtid);
+    code = AFSVolTransCreate_retry(fromconn, afromvol, afrompart, ITBusy, &fromtid);
     EGOTO1(error_exit, code,
           "Could not start transaction on the volume %u to be dumped\n",
           afromvol);
@@ -3995,7 +4247,9 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
 
     /* Get a clone id */
     VEPRINT1("Allocating new volume id for clone of volume %u ...", afromvol);
-    code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &clonevol);
+    tmpVol = clonevol;
+    code = ubik_VL_GetNewVolumeId(cstruct, 0, 1, &tmpVol);
+    clonevol = tmpVol;
     EGOTO1(error_exit, code,
           "Could not get an ID for the clone of volume %u from the VLDB\n",
           afromvol);
@@ -4005,8 +4259,10 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
     VEPRINT2("Cloning source volume %u to clone volume %u...", afromvol,
            clonevol);
     strcpy(vname, "dump-clone-temp");
+    tmpVol = clonevol;
     code =
-       AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &clonevol);
+       AFSVolClone(fromconn, fromtid, 0, readonlyVolume, vname, &tmpVol);
+    clonevol = tmpVol;
     EGOTO1(error_exit, code, "Failed to clone the source volume %u\n",
           afromvol);
     VEDONE;
@@ -4023,9 +4279,11 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
 
 
     VEPRINT1("Starting transaction on the cloned volume %u ...", clonevol);
+    tmp = clonetid;
     code =
-       AFSVolTransCreate(fromconn, clonevol, afrompart, ITOffline,
-                         &clonetid);
+       AFSVolTransCreate_retry(fromconn, clonevol, afrompart, ITOffline,
+                         &tmp);
+    clonetid = tmp;
     EGOTO1(error_exit, code,
           "Failed to start a transaction on the cloned volume%u\n",
           clonevol);
@@ -4041,7 +4299,7 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
     fromcall = rx_NewCall(fromconn);
 
     VEPRINT1("Starting volume dump from cloned volume %u...", clonevol);
-    if (flags & VOLDUMPV2_OMITDIRS) 
+    if (flags & VOLDUMPV2_OMITDIRS)
        code = StartAFSVolDumpV2(fromcall, clonetid, fromdate, flags);
     else
        code = StartAFSVolDump(fromcall, clonetid, fromdate);
@@ -4096,12 +4354,13 @@ UV_DumpClonedVolume(afs_int32 afromvol, afs_int32 afromserver,
 /*
  * Restore a volume <tovolid> <tovolname> on <toserver> <topart> from
  * the dump file <afilename>. WriteData does all the real work
- * after extracting params from the rock 
+ * after extracting params from the rock
  */
 int
-UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
-                 afs_int32 toparentid, char tovolname[], int flags,
-                 afs_int32(*WriteData) (), char *rock)
+UV_RestoreVolume2(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
+                 afs_uint32 toparentid, char tovolname[], int flags,
+                 afs_int32(*WriteData) (struct rx_call *, void *),
+                 void *rock)
 {
     struct rx_connection *toconn, *tempconn;
     struct rx_call *tocall;
@@ -4111,8 +4370,8 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
     struct volintInfo vinfo;
     char partName[10];
     char tovolreal[VOLSER_OLDMAXVOLNAME];
-    afs_int32 pvolid, pparentid;
-    afs_int32 temptid;
+    afs_uint32 pvolid;
+    afs_int32 temptid, pparentid;
     int success;
     struct nvldbentry entry, storeEntry;
     afs_int32 error;
@@ -4183,7 +4442,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
     if (!pparentid) pparentid = pvolid;
     /* at this point we have a volume id to use/reuse for the volume to be restored */
     strncpy(tovolreal, tovolname, VOLSER_OLDMAXVOLNAME);
-           
+
     if (strlen(tovolname) > (VOLSER_OLDMAXVOLNAME - 1)) {
        EGOTO1(refail, VOLSERBADOP,
               "The volume name %s exceeds the maximum limit of (VOLSER_OLDMAXVOLNAME -1 ) bytes\n",
@@ -4211,7 +4470,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
            VPRINT1("Deleting the previous volume %u ...", pvolid);
 
            code =
-               AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
+               AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
            EGOTO1(refail, code, "Failed to start transaction on %u\n",
                   pvolid);
 
@@ -4245,7 +4504,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
            EGOTO1(refail, code, "Could not create new volume %u\n", pvolid);
        } else {
            code =
-               AFSVolTransCreate(toconn, pvolid, topart, ITOffline, &totid);
+               AFSVolTransCreate_retry(toconn, pvolid, topart, ITOffline, &totid);
            EGOTO1(refail, code, "Failed to start transaction on %u\n",
                   pvolid);
 
@@ -4356,7 +4615,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
     fprintf(STDOUT, " done\n");
     fflush(STDOUT);
     if (success && (!reuseID || (flags & RV_FULLRST))) {
-       /* Volume was restored on the file server, update the 
+       /* Volume was restored on the file server, update the
         * VLDB to reflect the change.
         */
        vcode = VLDB_GetEntryByID(pvolid, voltype, &entry);
@@ -4458,7 +4717,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
                        tempconn =
                            UV_Bind(entry.serverNumber[index],
                                    AFSCONF_VOLUMEPORT);
-                       
+
                        MapPartIdIntoName(entry.serverPartition[index],
                                          apartName);
                        VPRINT3
@@ -4468,7 +4727,7 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
                             hostutil_GetNameByINet(entry.serverNumber[index]),
                             apartName);
                        code =
-                           AFSVolTransCreate(tempconn, pvolid,
+                           AFSVolTransCreate_retry(tempconn, pvolid,
                                              entry.serverPartition[index],
                                              ITOffline, &temptid);
                        if (!code) {
@@ -4581,9 +4840,10 @@ UV_RestoreVolume2(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
 }
 
 int
-UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
-                char tovolname[], int flags, afs_int32(*WriteData) (),
-                char *rock)
+UV_RestoreVolume(afs_uint32 toserver, afs_int32 topart, afs_uint32 tovolid,
+                char tovolname[], int flags,
+                afs_int32(*WriteData) (struct rx_call *, void *),
+                void *rock)
 {
     return UV_RestoreVolume2(toserver, topart, tovolid, 0, tovolname, flags,
                             WriteData, rock);
@@ -4592,10 +4852,8 @@ UV_RestoreVolume(afs_int32 toserver, afs_int32 topart, afs_int32 tovolid,
 
 /*unlocks the vldb entry associated with <volid> */
 int
-UV_LockRelease(afs_int32 volid)
+UV_LockRelease(afs_uint32 volid)
 {
-
-
     afs_int32 vcode;
 
     VPRINT("Binding to the VLDB server\n");
@@ -4614,13 +4872,22 @@ UV_LockRelease(afs_int32 volid)
 
 }
 
+/* old interface to add rosites */
+int
+UV_AddSite(afs_uint32 server, afs_int32 part, afs_uint32 volid,
+          afs_int32 valid)
+{
+    return UV_AddSite2(server, part, volid, 0, valid);
+}
+
 /*adds <server> and <part> as a readonly replication site for <volid>
 *in vldb */
 int
-UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
+UV_AddSite2(afs_uint32 server, afs_int32 part, afs_uint32 volid,
+           afs_uint32 rovolid, afs_int32 valid)
 {
     int j, nro = 0, islocked = 0;
-    struct nvldbentry entry, storeEntry;
+    struct nvldbentry entry, storeEntry, entry2;
     afs_int32 vcode, error = 0;
     char apartName[10];
 
@@ -4687,6 +4954,25 @@ UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
        goto asfail;
     }
 
+    /* if rovolid == 0, we leave the RO volume id alone. If the volume doesn't
+     * have an RO volid at this point (i.e. entry.volumeId[ROVOL] ==
+     * INVALID_BID) and we leave it alone, it gets an RO volid at release-time.
+     */
+    if (rovolid) {
+       if (entry.volumeId[ROVOL] == INVALID_BID) {
+           vcode = VLDB_GetEntryByID(rovolid, -1, &entry2);
+           if (!vcode) {
+               fprintf(STDERR, "Volume ID %d already exists\n", rovolid);
+               return VVOLEXISTS;
+           }
+           VPRINT1("Using RO volume id %d.\n", rovolid);
+           entry.volumeId[ROVOL] = rovolid;
+       } else {
+           fprintf(STDERR, "Ignoring given RO id %d, since volume already has RO id %d\n",
+               rovolid, entry.volumeId[ROVOL]);
+       }
+    }
+
     VPRINT("Adding a new site ...");
     entry.serverNumber[entry.nServers] = server;
     entry.serverPartition[entry.nServers] = part;
@@ -4728,11 +5014,10 @@ UV_AddSite(afs_int32 server, afs_int32 part, afs_int32 volid, afs_int32 valid)
 
 /*removes <server> <part> as read only site for <volid> from the vldb */
 int
-UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
+UV_RemoveSite(afs_uint32 server, afs_int32 part, afs_uint32 volid)
 {
     afs_int32 vcode;
     struct nvldbentry entry, storeEntry;
-    int islocked;
 
     vcode = ubik_VL_SetLock(cstruct, 0, volid, RWVOL, VLOP_ADDSITE);
     if (vcode) {
@@ -4741,7 +5026,6 @@ UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
        PrintError("", vcode);
        return (vcode);
     }
-    islocked = 1;
     vcode = VLDB_GetEntryByID(volid, RWVOL, &entry);
     if (vcode) {
        fprintf(STDERR,
@@ -4808,7 +5092,7 @@ UV_RemoveSite(afs_int32 server, afs_int32 part, afs_int32 volid)
 
 /*sets <server> <part> as read/write site for <volid> in the vldb */
 int
-UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
+UV_ChangeLocation(afs_uint32 server, afs_int32 part, afs_uint32 volid)
 {
     afs_int32 vcode;
     struct nvldbentry entry, storeEntry;
@@ -4869,13 +5153,13 @@ UV_ChangeLocation(afs_int32 server, afs_int32 part, afs_int32 volid)
 
 /*list all the partitions on <aserver> */
 int
-UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
+UV_ListPartitions(afs_uint32 aserver, struct partList *ptrPartList,
                  afs_int32 * cntp)
 {
     struct rx_connection *aconn;
     struct pIDs partIds;
     struct partEntries partEnts;
-    register int i, j = 0, code;
+    int i, j = 0, code;
 
     *cntp = 0;
     aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
@@ -4927,7 +5211,7 @@ UV_ListPartitions(afs_int32 aserver, struct partList *ptrPartList,
 /*zap the list of volumes specified by volPtrArray (the volCloneId field).
  This is used by the backup system */
 int
-UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
+UV_ZapVolumeClones(afs_uint32 aserver, afs_int32 apart,
                   struct volDescription *volPtr, afs_int32 arraySize)
 {
     struct rx_connection *aconn;
@@ -4946,7 +5230,7 @@ UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
            curPtr->volFlags &= ~CLONEZAPPED;
            success = 1;
            code =
-               AFSVolTransCreate(aconn, curPtr->volCloneId, apart, ITOffline,
+               AFSVolTransCreate_retry(aconn, curPtr->volCloneId, apart, ITOffline,
                                  &tid);
            if (code)
                success = 0;
@@ -4975,10 +5259,10 @@ UV_ZapVolumeClones(afs_int32 aserver, afs_int32 apart,
     return 0;
 }
 
-/*return a list of clones of the volumes specified by volPtrArray. Used by the 
+/*return a list of clones of the volumes specified by volPtrArray. Used by the
  backup system */
 int
-UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
+UV_GenerateVolumeClones(afs_uint32 aserver, afs_int32 apart,
                        struct volDescription *volPtr, afs_int32 arraySize)
 {
     struct rx_connection *aconn;
@@ -4988,7 +5272,7 @@ UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
     afs_int32 rcode = 0;
     afs_int32 tid;
     int reuseCloneId = 0;
-    afs_int32 curCloneId = 0;
+    afs_uint32 curCloneId = 0;
     char cloneName[256];       /*max vol name */
 
     aconn = (struct rx_connection *)0;
@@ -5012,7 +5296,7 @@ UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
            curPtr->volFlags |= CLONEVALID;
            /*make a clone of curParentId and record as curPtr->volCloneId */
            code =
-               AFSVolTransCreate(aconn, curPtr->volId, apart, ITOffline,
+               AFSVolTransCreate_retry(aconn, curPtr->volId, apart, ITOffline,
                                  &tid);
            if (code)
                VPRINT2("Clone for volume %s %u failed \n", curPtr->volName,
@@ -5066,7 +5350,7 @@ UV_GenerateVolumeClones(afs_int32 aserver, afs_int32 apart,
 /*list all the volumes on <aserver> and <apart>. If all = 1, then all the
 * relevant fields of the volume are also returned. This is a heavy weight operation.*/
 int
-UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
+UV_ListVolumes(afs_uint32 aserver, afs_int32 apart, int all,
               struct volintInfo **resultPtr, afs_int32 * size)
 {
     struct rx_connection *aconn;
@@ -5130,7 +5414,7 @@ UV_ListVolumes(afs_int32 aserver, afs_int32 apart, int all,
  *------------------------------------------------------------------------*/
 
 int
-UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
+UV_XListVolumes(afs_uint32 a_serverID, afs_int32 a_partID, int a_all,
                struct volintXInfo **a_resultPP,
                afs_int32 * a_numEntsInResultP)
 {
@@ -5178,7 +5462,7 @@ UV_XListVolumes(afs_int32 a_serverID, afs_int32 a_partID, int a_all,
 
 /* get all the information about volume <volid> on <aserver> and <apart> */
 int
-UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
+UV_ListOneVolume(afs_uint32 aserver, afs_int32 apart, afs_uint32 volid,
                 struct volintInfo **resultPtr)
 {
     struct rx_connection *aconn;
@@ -5237,7 +5521,7 @@ UV_ListOneVolume(afs_int32 aserver, afs_int32 apart, afs_int32 volid,
  *------------------------------------------------------------------------*/
 
 int
-UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
+UV_XListOneVolume(afs_uint32 a_serverID, afs_int32 a_partID, afs_uint32 a_volID,
                  struct volintXInfo **a_resultPP)
 {
     struct rx_connection *rxConnP;     /*Rx connection to Volume Server */
@@ -5280,17 +5564,17 @@ UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
 }
 
 /* CheckVolume()
- *    Given a volume we read from a partition, check if it is 
+ *    Given a volume we read from a partition, check if it is
  *    represented in the VLDB correctly.
- * 
+ *
  *    The VLDB is looked up by the RW volume id (not its name).
  *    The RW contains the true name of the volume (BK and RO set
  *       the name in the VLDB only on creation of the VLDB entry).
  *    We want rules strict enough that when we check all volumes
  *       on one partition, it does not need to be done again. IE:
- *       two volumes on different partitions won't constantly 
+ *       two volumes on different partitions won't constantly
  *       change a VLDB entry away from what the other set.
- *    For RW and BK volumes, we will always check the VLDB to see 
+ *    For RW and BK volumes, we will always check the VLDB to see
  *       if the two exist on the server/partition. May seem redundant,
  *       but this is an easy check of the VLDB. IE: if the VLDB entry
  *       says the BK exists but no BK volume is there, we will detect
@@ -5299,16 +5583,18 @@ UV_XListOneVolume(afs_int32 a_serverID, afs_int32 a_partID, afs_int32 a_volID,
  *    Output changed to look a lot like the "vos syncserv" otuput.
  */
 static afs_int32
-CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
-           afs_int32 * modentry, afs_uint32 * maxvolid)
+CheckVolume(volintInfo * volumeinfo, afs_uint32 aserver, afs_int32 apart,
+           afs_int32 * modentry, afs_uint32 * maxvolid,
+            struct nvldbentry *aentry)
 {
-    int idx, j;
+    int idx = 0;
+    int j;
     afs_int32 code, error = 0;
     struct nvldbentry entry, storeEntry;
     char pname[10];
-    int pass = 0, islocked = 0, createentry, addvolume, modified, mod, doit = 1;
-    afs_int32 rwvolid;
-    char hoststr[16]; 
+    int pass = 0, createentry, addvolume, modified, mod, doit = 1;
+    afs_uint32 rwvolid;
+    char hoststr[16];
 
     if (modentry) {
        if (*modentry == 1)
@@ -5331,29 +5617,32 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
                    (unsigned long)rwvolid);
            ERROR_EXIT(code);
        }
-       islocked = 1;
     }
 
     createentry = 0;           /* Do we need to create a VLDB entry */
     addvolume = 0;             /* Add this volume to the VLDB entry */
     modified = 0;              /* The VLDB entry was modified */
 
-    /* Read the entry from VLDB by its RW volume id */
-    code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
-    if (code) {
-       if (code != VL_NOENT) {
-           fprintf(STDOUT,
-                   "Could not retreive the VLDB entry for volume %lu \n",
-                   (unsigned long)rwvolid);
-           ERROR_EXIT(code);
-       }
+    if (aentry) {
+       memcpy(&entry, aentry, sizeof(entry));
+    } else {
+       /* Read the entry from VLDB by its RW volume id */
+       code = VLDB_GetEntryByID(rwvolid, RWVOL, &entry);
+       if (code) {
+           if (code != VL_NOENT) {
+               fprintf(STDOUT,
+                       "Could not retreive the VLDB entry for volume %lu \n",
+                       (unsigned long)rwvolid);
+               ERROR_EXIT(code);
+           }
 
-       memset(&entry, 0, sizeof(entry));
-       vsu_ExtractName(entry.name, volumeinfo->name);  /* Store name of RW */
+           memset(&entry, 0, sizeof(entry));
+           vsu_ExtractName(entry.name, volumeinfo->name);      /* Store name of RW */
 
-       createentry = 1;
-    } else {
-       MapHostToNetwork(&entry);
+           createentry = 1;
+       } else {
+           MapHostToNetwork(&entry);
+       }
     }
 
     if (verbose && (pass == 1)) {
@@ -5405,7 +5694,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
                            fprintf(STDERR,
                                    "    VLDB reports RW volume %lu exists on %s %s\n",
                                    (unsigned long)rwvolid,
-                                    noresolve ? 
+                                    noresolve ?
                                     afs_inet_ntoa_r(entry.serverNumber[idx], hoststr) :
                                    hostutil_GetNameByINet(entry.
                                                           serverNumber[idx]),
@@ -5432,7 +5721,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
                                fprintf(STDERR,
                                        "    VLDB reports its RW volume %lu exists on %s %s\n",
                                        (unsigned long)rwvolid,
-                                        noresolve ? 
+                                        noresolve ?
                                         afs_inet_ntoa_r(aserver, hoststr) :
                                        hostutil_GetNameByINet(aserver),
                                        pname);
@@ -5568,7 +5857,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
 
            entry.serverNumber[idx] = aserver;
            entry.serverPartition[idx] = apart;
-           entry.serverFlags[idx] = ITSRWVOL;
+           entry.serverFlags[idx] = ITSBACKVOL;
 
            modified++;
        }
@@ -5576,7 +5865,7 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
 
     else if (volumeinfo->type == ROVOL) {      /* A RO volume */
        if (volumeinfo->volid == entry.volumeId[ROVOL]) {
-           /* This is a quick check to see if the RO entry exists in the 
+           /* This is a quick check to see if the RO entry exists in the
             * VLDB so we avoid the CheckVldbRO() call (which checks if each
             * RO volume listed in the VLDB exists).
             */
@@ -5714,8 +6003,6 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
                ERROR_EXIT(code);
            }
        }
-       if (modentry)
-           *modentry = modified;
     } else if (pass == 2) {
        code =
            ubik_VL_ReleaseLock(cstruct, 0, rwvolid, RWVOL,
@@ -5725,7 +6012,15 @@ CheckVolume(volintInfo * volumeinfo, afs_int32 aserver, afs_int32 apart,
        }
     }
 
-    if (verbose && doit) {
+    if (modified && modentry) {
+       *modentry = 1;
+    }
+
+    if (aentry) {
+       memcpy(aentry, &entry, sizeof(entry));
+    }
+
+    if (verbose) {
        fprintf(STDOUT, "-- status after --\n");
        if (modified)
            EnumerateEntry(&entry);
@@ -5743,7 +6038,7 @@ sortVolumes(const void *a, const void *b)
 {
     volintInfo *v1 = (volintInfo *) a;
     volintInfo *v2 = (volintInfo *) b;
-    afs_int32 rwvolid1, rwvolid2;
+    afs_uint32 rwvolid1, rwvolid2;
 
     rwvolid1 = ((v1->type == RWVOL) ? v1->volid : v1->parentID);
     rwvolid2 = ((v2->type == RWVOL) ? v2->volid : v2->parentID);
@@ -5777,32 +6072,35 @@ sortVolumes(const void *a, const void *b)
  *      if the volume exists on specified servers (similar to syncvldb).
  */
 int
-UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
+UV_SyncVolume(afs_uint32 aserver, afs_int32 apart, char *avolname, int flags)
 {
     struct rx_connection *aconn = 0;
     afs_int32 j, k, code, vcode, error = 0;
-    afs_int32 tverbose, mod, modified = 0;
+    afs_int32 tverbose;
+    afs_int32 mod, modified = 0, deleted = 0;
     struct nvldbentry vldbentry;
-    afs_int32 volumeid = 0;
+    afs_uint32 volumeid = 0;
     volEntries volumeInfo;
     struct partList PartList;
-    afs_int32 pcnt, rv;
-    afs_int32 maxvolid = 0;
+    afs_int32 pcnt;
+    afs_uint32 maxvolid = 0;
 
     volumeInfo.volEntries_val = (volintInfo *) 0;
     volumeInfo.volEntries_len = 0;
 
-    if (!aserver && (flags & 1)) {
-       /* fprintf(STDERR,"Partition option requires a server option\n"); */
-       ERROR_EXIT(EINVAL);
-    }
-
     /* Turn verbose logging off and do our own verbose logging */
+    /* tverbose must be set before we call ERROR_EXIT() */
+
     tverbose = verbose;
-    if (flags & 2) 
+    if (flags & 2)
        tverbose = 1;
     verbose = 0;
 
+    if (!aserver && (flags & 1)) {
+       /* fprintf(STDERR,"Partition option requires a server option\n"); */
+       ERROR_EXIT(EINVAL);
+    }
+
     /* Read the VLDB entry */
     vcode = VLDB_GetEntryByName(avolname, &vldbentry);
     if (vcode && (vcode != VL_NOENT)) {
@@ -5827,7 +6125,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
        fprintf(STDOUT, "\n");
     }
 
-    /* Verify that all of the VLDB entries exist on the repective servers 
+    /* Verify that all of the VLDB entries exist on the repective servers
      * and partitions (this does not require that avolname be a volume ID).
      * Equivalent to a syncserv.
      */
@@ -5837,7 +6135,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
            mod = 1;
        else
            mod = 0;
-       code = CheckVldb(&vldbentry, &mod);
+       code = CheckVldb(&vldbentry, &mod, &deleted);
        if (code) {
            fprintf(STDERR, "Could not process VLDB entry for volume %s\n",
                    vldbentry.name);
@@ -5883,7 +6181,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
                    /* Found one, sync it with VLDB entry */
                    code =
                        CheckVolume(volumeInfo.volEntries_val, aserver,
-                                   PartList.partId[j], &mod, &maxvolid);
+                                   PartList.partId[j], &mod, &maxvolid, &vldbentry);
                    if (code)
                        ERROR_EXIT(code);
                    if (mod)
@@ -5900,21 +6198,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
        /* Check to see if the RW, BK, and RO IDs exist on any
         * partitions. We get the volume IDs from the VLDB.
         */
-       rv = 1;                 /* Read the VLDB entry ? */
        for (j = 0; j < MAXTYPES; j++) {        /* for RW, RO, and BK IDs */
-           if (rv) {
-               vcode = VLDB_GetEntryByName(avolname, &vldbentry);
-               if (vcode) {
-                   if (vcode == VL_NOENT)
-                       break;
-                   fprintf(STDERR,
-                           "Could not access the VLDB for volume %s\n",
-                           avolname);
-                   ERROR_EXIT(vcode);
-               }
-               rv = 0;
-           }
-
            if (vldbentry.volumeId[j] == 0)
                continue;
 
@@ -5937,11 +6221,11 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
                    /* Found one, sync it with VLDB entry */
                    code =
                        CheckVolume(volumeInfo.volEntries_val, aserver,
-                                   PartList.partId[k], &mod, &maxvolid);
+                                   PartList.partId[k], &mod, &maxvolid, &vldbentry);
                    if (code)
                        ERROR_EXIT(code);
                    if (mod)
-                       modified++, rv++;
+                       modified++;
                }
 
                if (volumeInfo.volEntries_val)
@@ -5954,15 +6238,9 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
 
     /* if (aserver) */
     /* If verbose output, print a summary of what changed */
-    if (tverbose && !(flags & 2)) {
+    if (tverbose) {
        fprintf(STDOUT, "-- status after --\n");
-       code = VLDB_GetEntryByName(avolname, &vldbentry);
-       if (code && (code != VL_NOENT)) {
-           fprintf(STDERR, "Could not access the VLDB for volume %s\n",
-                   avolname);
-           ERROR_EXIT(code);
-       }
-       if (modified && (code == VL_NOENT)) {
+       if (deleted) {
            fprintf(STDOUT, "\n**entry deleted**\n");
        } else if (modified) {
            EnumerateEntry(&vldbentry);
@@ -5975,7 +6253,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
   error_exit:
     /* Now check if the maxvolid is larger than that stored in the VLDB */
     if (maxvolid) {
-       afs_int32 maxvldbid = 0;
+       afs_uint32 maxvldbid = 0;
        code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
        if (code) {
            fprintf(STDERR,
@@ -5983,7 +6261,7 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
            if (!error)
                error = code;
        } else if (maxvolid > maxvldbid) {
-           afs_int32 id, nid;
+           afs_uint32 id, nid;
            id = maxvolid - maxvldbid + 1;
            code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
            if (code) {
@@ -6016,11 +6294,12 @@ UV_SyncVolume(afs_int32 aserver, afs_int32 apart, char *avolname, int flags)
  *      optionally, <apart>.
  */
 int
-UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
+UV_SyncVldb(afs_uint32 aserver, afs_int32 apart, int flags, int force)
 {
     struct rx_connection *aconn;
     afs_int32 code, error = 0;
-    int i, j, pfail;
+    int i, pfail;
+    unsigned int j;
     volEntries volumeInfo;
     struct partList PartList;
     afs_int32 pcnt;
@@ -6091,7 +6370,7 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
                modified = 1;
            else
                modified = 0;
-           code = CheckVolume(vi, aserver, apart, &modified, &maxvolid);
+           code = CheckVolume(vi, aserver, apart, &modified, &maxvolid, NULL);
            if (code) {
                PrintError("", code);
                failures++;
@@ -6124,17 +6403,17 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
     }                          /* thru all partitions */
 
     if (flags & 2) {
-       VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n", 
+       VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
                tentries, failures, modifications);
     } else {
-       VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", 
+       VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
                tentries, failures, modifications);
     }
 
   error_exit:
     /* Now check if the maxvolid is larger than that stored in the VLDB */
     if (maxvolid) {
-       afs_int32 maxvldbid = 0;
+       afs_uint32 maxvldbid = 0;
        code = ubik_VL_GetNewVolumeId(cstruct, 0, 0, &maxvldbid);
        if (code) {
            fprintf(STDERR,
@@ -6142,7 +6421,7 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
            if (!error)
                error = code;
        } else if (maxvolid > maxvldbid) {
-           afs_int32 id, nid;
+           afs_uint32 id, nid;
            id = maxvolid - maxvldbid + 1;
            code = ubik_VL_GetNewVolumeId(cstruct, 0, id, &nid);
            if (code) {
@@ -6170,7 +6449,7 @@ UV_SyncVldb(afs_int32 aserver, afs_int32 apart, int flags, int force)
  *      still exists - so we catch these error codes.
  */
 afs_int32
-VolumeExists(afs_int32 server, afs_int32 partition, afs_int32 volumeid)
+VolumeExists(afs_uint32 server, afs_int32 partition, afs_uint32 volumeid)
 {
     struct rx_connection *conn = (struct rx_connection *)0;
     afs_int32 code = -1;
@@ -6313,7 +6592,7 @@ CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
        *modified = 0;
 
     /* Check to see if the RO volumes exist and set the RO_EXISTS
-     * flag accordingly. 
+     * flag accordingly.
      */
     for (idx = 0; idx < entry->nServers; idx++) {
        if (!(entry->serverFlags[idx] & ITSROVOL)) {
@@ -6365,7 +6644,7 @@ CheckVldbRO(struct nvldbentry *entry, afs_int32 * modified)
  *      Ensure that <entry> matches with the info on file servers
  */
 afs_int32
-CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
+CheckVldb(struct nvldbentry * entry, afs_int32 * modified, afs_int32 * deleted)
 {
     afs_int32 code, error = 0;
     struct nvldbentry storeEntry;
@@ -6373,7 +6652,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
     int pass = 0, doit=1;
 
     if (modified) {
-       if (*modified == 1) 
+       if (*modified == 1)
            doit = 0;
        *modified = 0;
     }
@@ -6437,7 +6716,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
     if (mod)
        modentry++;
 
-    /* The VLDB entry has been updated. If it as been modified, then 
+    /* The VLDB entry has been updated. If it as been modified, then
      * write the entry back out the the VLDB.
      */
     if (modentry && doit) {
@@ -6470,12 +6749,17 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
                ERROR_EXIT(code);
            }
        }
-       if (modified)
-           *modified = 1;
        islocked = 0;
     }
 
-    if (verbose && doit) {
+    if (modified && modentry) {
+       *modified = 1;
+    }
+    if (deleted && delentry) {
+       *deleted = 1;
+    }
+
+    if (verbose) {
        fprintf(STDOUT, "-- status after --\n");
        if (delentry)
            fprintf(STDOUT, "\n**entry deleted**\n");
@@ -6508,7 +6792,7 @@ CheckVldb(struct nvldbentry * entry, afs_int32 * modified)
  *      Synchronise <aserver> <apart>(if flags = 1) with the VLDB.
  */
 int
-UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
+UV_SyncServer(afs_uint32 aserver, afs_int32 apart, int flags, int force)
 {
     struct rx_connection *aconn;
     afs_int32 code, error = 0;
@@ -6519,7 +6803,7 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
     struct nvldbentry *vlentry;
     afs_int32 si, nsi, j;
 
-    if (flags & 2) 
+    if (flags & 2)
        verbose = 1;
 
     aconn = UV_Bind(aserver, AFSCONF_VOLUMEPORT);
@@ -6563,7 +6847,7 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
                modified = 1;
            else
                modified = 0;
-           code = CheckVldb(vlentry, &modified);
+           code = CheckVldb(vlentry, &modified, NULL);
            if (code) {
                PrintError("", code);
                fprintf(STDERR,
@@ -6593,7 +6877,7 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
        VPRINT3("Total entries: %u, Failed to process %d, Would change %d\n",
                tentries, failures, modifications);
     } else {
-       VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n", 
+       VPRINT3("Total entries: %u, Failed to process %d, Changed %d\n",
                tentries, failures, modifications);
     }
 
@@ -6608,7 +6892,7 @@ UV_SyncServer(afs_int32 aserver, afs_int32 apart, int flags, int force)
     return error;
 }
 
-/*rename volume <oldname> to <newname>, changing the names of the related 
+/*rename volume <oldname> to <newname>, changing the names of the related
  *readonly and backup volumes. This operation is also idempotent.
  *salvager is capable of recovering from rename operation stopping halfway.
  *to recover run syncserver on the affected machines,it will force renaming to completion. name clashes should have been detected before calling this proc */
@@ -6648,7 +6932,7 @@ UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
        goto rvfail;
     }
     VPRINT1("Recorded the new name %s in VLDB\n", newname);
-    /*at this stage the intent to rename is recorded in the vldb, as far as the vldb 
+    /*at this stage the intent to rename is recorded in the vldb, as far as the vldb
      * is concerned, oldname is lost */
     if (entry->flags & RW_EXISTS) {
        index = Lp_GetRwIndex(entry);
@@ -6662,7 +6946,7 @@ UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
        }
        aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
        code =
-           AFSVolTransCreate(aconn, entry->volumeId[RWVOL],
+           AFSVolTransCreate_retry(aconn, entry->volumeId[RWVOL],
                              entry->serverPartition[index], ITOffline, &tid);
        if (code) {             /*volume doesnot exist */
            fprintf(STDERR,
@@ -6712,7 +6996,7 @@ UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
        }
        aconn = UV_Bind(entry->serverNumber[index], AFSCONF_VOLUMEPORT);
        code =
-           AFSVolTransCreate(aconn, entry->volumeId[BACKVOL],
+           AFSVolTransCreate_retry(aconn, entry->volumeId[BACKVOL],
                              entry->serverPartition[index], ITOffline, &tid);
        if (code) {             /*volume doesnot exist */
            fprintf(STDERR,
@@ -6762,7 +7046,7 @@ UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
            if (entry->serverFlags[i] & ITSROVOL) {
                aconn = UV_Bind(entry->serverNumber[i], AFSCONF_VOLUMEPORT);
                code =
-                   AFSVolTransCreate(aconn, entry->volumeId[ROVOL],
+                   AFSVolTransCreate_retry(aconn, entry->volumeId[ROVOL],
                                      entry->serverPartition[i], ITOffline,
                                      &tid);
                if (code) {     /*volume doesnot exist */
@@ -6847,7 +7131,7 @@ UV_RenameVolume(struct nvldbentry *entry, char oldname[], char newname[])
 
 /*report on all the active transactions on volser */
 int
-UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
+UV_VolserStatus(afs_uint32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
 {
     struct rx_connection *aconn;
     transDebugEntries transInfo;
@@ -6879,7 +7163,7 @@ UV_VolserStatus(afs_int32 server, transDebugInfo ** rpntr, afs_int32 * rcount)
 
 /*delete the volume without interacting with the vldb */
 int
-UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
+UV_VolumeZap(afs_uint32 server, afs_int32 part, afs_uint32 volid)
 {
     afs_int32 rcode, ttid, error, code;
     struct rx_connection *aconn;
@@ -6889,7 +7173,7 @@ UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
     ttid = 0;
 
     aconn = UV_Bind(server, AFSCONF_VOLUMEPORT);
-    code = AFSVolTransCreate(aconn, volid, part, ITOffline, &ttid);
+    code = AFSVolTransCreate_retry(aconn, volid, part, ITOffline, &ttid);
     if (code) {
        fprintf(STDERR, "Could not start transaction on volume %lu\n",
                (unsigned long)volid);
@@ -6928,7 +7212,7 @@ UV_VolumeZap(afs_int32 server, afs_int32 part, afs_int32 volid)
 }
 
 int
-UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
+UV_SetVolume(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
             afs_int32 transflag, afs_int32 setflag, int sleeptime)
 {
     struct rx_connection *conn = 0;
@@ -6941,7 +7225,7 @@ UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
        ERROR_EXIT(-1);
     }
 
-    code = AFSVolTransCreate(conn, volid, partition, transflag, &tid);
+    code = AFSVolTransCreate_retry(conn, volid, partition, transflag, &tid);
     if (code) {
        fprintf(STDERR, "SetVolumeStatus: TransCreate Failed\n");
        ERROR_EXIT(code);
@@ -6978,7 +7262,7 @@ UV_SetVolume(afs_int32 server, afs_int32 partition, afs_int32 volid,
 }
 
 int
-UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
+UV_SetVolumeInfo(afs_uint32 server, afs_int32 partition, afs_uint32 volid,
                 volintInfo * infop)
 {
     struct rx_connection *conn = 0;
@@ -6991,7 +7275,7 @@ UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
        ERROR_EXIT(-1);
     }
 
-    code = AFSVolTransCreate(conn, volid, partition, ITOffline, &tid);
+    code = AFSVolTransCreate_retry(conn, volid, partition, ITOffline, &tid);
     if (code) {
        fprintf(STDERR, "SetVolumeInfo: TransCreate Failed\n");
        ERROR_EXIT(code);
@@ -7020,7 +7304,7 @@ UV_SetVolumeInfo(afs_int32 server, afs_int32 partition, afs_int32 volid,
 }
 
 int
-UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
+UV_GetSize(afs_uint32 afromvol, afs_uint32 afromserver, afs_int32 afrompart,
           afs_int32 fromdate, struct volintSize *vol_size)
 {
     struct rx_connection *aconn = (struct rx_connection *)0;
@@ -7032,7 +7316,7 @@ UV_GetSize(afs_int32 afromvol, afs_int32 afromserver, afs_int32 afrompart,
     aconn = UV_Bind(afromserver, AFSCONF_VOLUMEPORT);
 
     VPRINT1("Starting transaction on volume %u...", afromvol);
-    code = AFSVolTransCreate(aconn, afromvol, afrompart, ITBusy, &tid);
+    code = AFSVolTransCreate_retry(aconn, afromvol, afrompart, ITBusy, &tid);
     EGOTO1(error_exit, code,
           "Could not start transaction on the volume %u to be measured\n",
           afromvol);