/* Machine generated file -- Do NOT edit */

#include "budb.h"

#ifndef NEVERDATE
#define NEVERDATE 037777777777 /* a date that will never come */
#endif
#ifndef Date
#define Date afs_uint32
#endif
#ifndef dumpId
#define dumpId afs_uint32
#endif
#define TB_DUMPSCHEDULE 0
#define TB_VOLUMESET 1
#define TB_TAPEHOSTS 2
#define TB_NUM 3 /* no. of block types */
#define TB_MAX 6 /* unused items are spares */
#define budb_MakeTapeName(name,set,seq) sprintf (name, (set)->format, (set)->a*(seq) + (set)->b)
#define BUDB_DUMP_INCOMPLETE (1<<0) /* some vols omitted due to errors */
#define BUDB_DUMP_TAPEERROR (1<<1) /* tape error during dump */
#define BUDB_DUMP_INPROGRESS (1<<2)
#define BUDB_DUMP_ABORTED (1<<3) /* aborted: prob. dump unavailable */
#define BUDB_DUMP_XBSA_NSS (1<<8) /* dump was done with a client    */
#define BUDB_DUMP_BUTA (1<<11) /* (used by ADSM buta) == 0x800 */
#define BUDB_DUMP_ADSM (1<<12) /* (used by XBSA/ADSM buta) == 0x1000 */
#define BUDB_TAPE_TAPEERROR (1<<0)
#define BUDB_TAPE_DELETED (1<<1)
#define BUDB_TAPE_BEINGWRITTEN (1<<2) /* writing in progress */
#define BUDB_TAPE_ABORTED (1<<3) /* aborted: tape probably garbaged */
#define BUDB_TAPE_STAGED (1<<4) /* not yet on permanent media */
#define BUDB_TAPE_WRITTEN (1<<5) /* tape writing finished: all OK */
#define BUDB_VOL_TAPEERROR (1<<0) /* tape problem during dump */
#define BUDB_VOL_FILEERROR (1<<1) /* voldump aborted during dump */
#define BUDB_VOL_BEINGWRITTEN (1<<2)
#define BUDB_VOL_FIRSTFRAG (1<<3) /* same as low bits of tape position */
#define BUDB_VOL_LASTFRAG (1<<4)
#define BUDB_VOL_ABORTED (1<<5) /* aborted: vol probably undumped */
#define BUDB_OP_NAMES (0x7)
#define BUDB_OP_STARTS (0x7<<3)
#define BUDB_OP_ENDS (0x7<<6)
#define BUDB_OP_TIMES (0x3<<9)
#define BUDB_OP_MISC (0xff<<16)
#define BUDB_OP_DUMPNAME (1<<0)
#define BUDB_OP_VOLUMENAME (2<<0)
#define BUDB_OP_TAPENAME (3<<0)
#define BUDB_OP_TAPESEQ (4<<0)
#define BUDB_OP_STARTTIME (1<<3)
#define BUDB_OP_RANGE (1<<6)
#define BUDB_OP_NPREVIOUS (2<<6)
#define BUDB_OP_NFOLLOWING (3<<6)
#define BUDB_OP_DUMPID (2<<3)
#define BUDB_OP_CLONETIME (1<<9) /* use clone time */
#define BUDB_OP_DUMPTIME (2<<9) /* use dump time (create?) */
#define BUDB_OP_INCTIME (3<<9) /* use inc time */
#define BUDB_OP_FIRSTFRAG (1<<16)
#define BUDB_TEXT_COMPLETE 1
#define SD_DBHEADER 1
#define SD_DUMP 2
#define SD_TAPE 3
#define SD_VOLUME 4
#define SD_TEXT_DUMPSCHEDULE 5
#define SD_TEXT_VOLUMESET 6
#define SD_TEXT_TAPEHOSTS 7
#define SD_END 8
#define BUDB_OP_DATES (0x01)
#define BUDB_OP_GROUPID (0x02)
#define BUDB_OP_APPDUMP (0x01)
#define BUDB_OP_DBDUMP (0x02)
int BUDB_AddVolume(register struct rx_connection *z_conn,struct budb_volumeEntry * vol)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 0;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_volumeEntry(&z_xdrs, vol))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_volumeEntry(&z_xdrs, vol))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_AddVolume(register struct ubik_client *aclient, afs_int32 aflags,struct budb_volumeEntry * vol)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_AddVolume(tc
, vol);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_CreateDump(register struct rx_connection *z_conn,struct budb_dumpEntry * dump)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 1;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_dumpEntry(&z_xdrs, dump))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpEntry(&z_xdrs, dump))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_CreateDump(register struct ubik_client *aclient, afs_int32 aflags,struct budb_dumpEntry * dump)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_CreateDump(tc
, dump);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_DeleteDump(register struct rx_connection *z_conn,afs_uint32 id,afs_uint32 fromTime,afs_uint32 toTime,budb_dumpsList * dumps)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 2;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &id))
	     || (!xdr_afs_uint32(&z_xdrs, &fromTime))
	     || (!xdr_afs_uint32(&z_xdrs, &toTime))
	     || (!xdr_budb_dumpsList(&z_xdrs, dumps))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpsList(&z_xdrs, dumps))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_DeleteDump(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 id,afs_uint32 fromTime,afs_uint32 toTime,budb_dumpsList * dumps)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_DeleteDump(tc
, id, fromTime, toTime, dumps);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_DeleteTape(register struct rx_connection *z_conn,struct budb_tapeEntry * tape)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 3;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_tapeEntry(&z_xdrs, tape))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_DeleteTape(register struct ubik_client *aclient, afs_int32 aflags,struct budb_tapeEntry * tape)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_DeleteTape(tc
, tape);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_DeleteVDP(register struct rx_connection *z_conn,char * dsname,char * dumpPath,afs_int32 curDumpId)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 4;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_string(&z_xdrs, &dsname, 32))
	     || (!xdr_string(&z_xdrs, &dumpPath, 256))
	     || (!xdr_afs_int32(&z_xdrs, &curDumpId))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_DeleteVDP(register struct ubik_client *aclient, afs_int32 aflags,char * dsname,char * dumpPath,afs_int32 curDumpId)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_DeleteVDP(tc
, dsname, dumpPath, curDumpId);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FindClone(register struct rx_connection *z_conn,afs_int32 dumpID,char * volName,afs_int32 * clonetime)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 5;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &dumpID))
	     || (!xdr_string(&z_xdrs, &volName, 32))
	     || (!xdr_afs_int32(&z_xdrs, clonetime))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, clonetime))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FindClone(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 dumpID,char * volName,afs_int32 * clonetime)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FindClone(tc
, dumpID, volName, clonetime);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FindDump(register struct rx_connection *z_conn,char * volumeName,afs_int32 beforeDate,struct budb_dumpEntry * deptr)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 6;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_string(&z_xdrs, &volumeName, 32))
	     || (!xdr_afs_int32(&z_xdrs, &beforeDate))
	     || (!xdr_budb_dumpEntry(&z_xdrs, deptr))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpEntry(&z_xdrs, deptr))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FindDump(register struct ubik_client *aclient, afs_int32 aflags,char * volumeName,afs_int32 beforeDate,struct budb_dumpEntry * deptr)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FindDump(tc
, volumeName, beforeDate, deptr);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FindLatestDump(register struct rx_connection *z_conn,char * vsname,char * dname,budb_dumpEntry * dumpentry)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 7;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_string(&z_xdrs, &vsname, 32))
	     || (!xdr_string(&z_xdrs, &dname, 256))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpEntry(&z_xdrs, dumpentry))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FindLatestDump(register struct ubik_client *aclient, afs_int32 aflags,char * vsname,char * dname,budb_dumpEntry * dumpentry)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FindLatestDump(tc
, vsname, dname, dumpentry);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_MakeDumpAppended(register struct rx_connection *z_conn,afs_int32 appendedDumpID,afs_int32 intialDumpID,afs_int32 startTapeSeq)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 8;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &appendedDumpID))
	     || (!xdr_afs_int32(&z_xdrs, &intialDumpID))
	     || (!xdr_afs_int32(&z_xdrs, &startTapeSeq))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_MakeDumpAppended(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 appendedDumpID,afs_int32 intialDumpID,afs_int32 startTapeSeq)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_MakeDumpAppended(tc
, appendedDumpID, intialDumpID, startTapeSeq);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FindLastTape(register struct rx_connection *z_conn,afs_int32 dumpID,struct budb_dumpEntry * dumpEntry,struct budb_tapeEntry * tapeEntry,struct budb_volumeEntry * volEntry)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 9;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &dumpID))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpEntry(&z_xdrs, dumpEntry))
	     || (!xdr_budb_tapeEntry(&z_xdrs, tapeEntry))
	     || (!xdr_budb_volumeEntry(&z_xdrs, volEntry))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FindLastTape(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 dumpID,struct budb_dumpEntry * dumpEntry,struct budb_tapeEntry * tapeEntry,struct budb_volumeEntry * volEntry)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FindLastTape(tc
, dumpID, dumpEntry, tapeEntry, volEntry);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FinishDump(register struct rx_connection *z_conn,struct budb_dumpEntry * dump)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 10;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_dumpEntry(&z_xdrs, dump))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpEntry(&z_xdrs, dump))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FinishDump(register struct ubik_client *aclient, afs_int32 aflags,struct budb_dumpEntry * dump)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FinishDump(tc
, dump);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FinishTape(register struct rx_connection *z_conn,struct budb_tapeEntry * tape)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 11;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_tapeEntry(&z_xdrs, tape))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_tapeEntry(&z_xdrs, tape))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FinishTape(register struct ubik_client *aclient, afs_int32 aflags,struct budb_tapeEntry * tape)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FinishTape(tc
, tape);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetDumps(register struct rx_connection *z_conn,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,budb_dumpList * dumps)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 12;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &majorVersion))
	     || (!xdr_afs_int32(&z_xdrs, &flags))
	     || (!xdr_string(&z_xdrs, &name, 32))
	     || (!xdr_afs_int32(&z_xdrs, &start))
	     || (!xdr_afs_int32(&z_xdrs, &end))
	     || (!xdr_afs_int32(&z_xdrs, &index))
	     || (!xdr_budb_dumpList(&z_xdrs, dumps))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, nextIndex))
	     || (!xdr_afs_int32(&z_xdrs, dbUpdate))
	     || (!xdr_budb_dumpList(&z_xdrs, dumps))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetDumps(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,budb_dumpList * dumps)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetDumps(tc
, majorVersion, flags, name, start, end, index, nextIndex, dbUpdate, dumps);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetTapes(register struct rx_connection *z_conn,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,struct budb_tapeList * tapes)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 13;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &majorVersion))
	     || (!xdr_afs_int32(&z_xdrs, &flags))
	     || (!xdr_string(&z_xdrs, &name, 32))
	     || (!xdr_afs_int32(&z_xdrs, &start))
	     || (!xdr_afs_int32(&z_xdrs, &end))
	     || (!xdr_afs_int32(&z_xdrs, &index))
	     || (!xdr_budb_tapeList(&z_xdrs, tapes))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, nextIndex))
	     || (!xdr_afs_int32(&z_xdrs, dbUpdate))
	     || (!xdr_budb_tapeList(&z_xdrs, tapes))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetTapes(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,struct budb_tapeList * tapes)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetTapes(tc
, majorVersion, flags, name, start, end, index, nextIndex, dbUpdate, tapes);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetVolumes(register struct rx_connection *z_conn,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,budb_volumeList * volumes)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 14;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &majorVersion))
	     || (!xdr_afs_int32(&z_xdrs, &flags))
	     || (!xdr_string(&z_xdrs, &name, 32))
	     || (!xdr_afs_int32(&z_xdrs, &start))
	     || (!xdr_afs_int32(&z_xdrs, &end))
	     || (!xdr_afs_int32(&z_xdrs, &index))
	     || (!xdr_budb_volumeList(&z_xdrs, volumes))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, nextIndex))
	     || (!xdr_afs_int32(&z_xdrs, dbUpdate))
	     || (!xdr_budb_volumeList(&z_xdrs, volumes))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetVolumes(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 majorVersion,afs_int32 flags,char * name,afs_int32 start,afs_int32 end,afs_int32 index,afs_int32 * nextIndex,afs_int32 * dbUpdate,budb_volumeList * volumes)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetVolumes(tc
, majorVersion, flags, name, start, end, index, nextIndex, dbUpdate, volumes);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_UseTape(register struct rx_connection *z_conn,struct budb_tapeEntry * tape,afs_int32 * new)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 15;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_tapeEntry(&z_xdrs, tape))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_tapeEntry(&z_xdrs, tape))
	     || (!xdr_afs_int32(&z_xdrs, new))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_UseTape(register struct ubik_client *aclient, afs_int32 aflags,struct budb_tapeEntry * tape,afs_int32 * new)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_UseTape(tc
, tape, new);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetText(register struct rx_connection *z_conn,afs_uint32 lockHandle,afs_int32 textType,afs_int32 maxLength,afs_int32 offset,afs_int32 * nextOffset,charListT * charListPtr)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 16;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &lockHandle))
	     || (!xdr_afs_int32(&z_xdrs, &textType))
	     || (!xdr_afs_int32(&z_xdrs, &maxLength))
	     || (!xdr_afs_int32(&z_xdrs, &offset))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, nextOffset))
	     || (!xdr_charListT(&z_xdrs, charListPtr))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetText(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 lockHandle,afs_int32 textType,afs_int32 maxLength,afs_int32 offset,afs_int32 * nextOffset,charListT * charListPtr)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetText(tc
, lockHandle, textType, maxLength, offset, nextOffset, charListPtr);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetTextVersion(register struct rx_connection *z_conn,afs_int32 textType,afs_uint32 * tversion)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 17;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &textType))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_uint32(&z_xdrs, tversion))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetTextVersion(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 textType,afs_uint32 * tversion)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetTextVersion(tc
, textType, tversion);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_SaveText(register struct rx_connection *z_conn,afs_uint32 lockHandle,afs_int32 textType,afs_int32 offset,afs_int32 flags,charListT * charListPtr)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 18;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &lockHandle))
	     || (!xdr_afs_int32(&z_xdrs, &textType))
	     || (!xdr_afs_int32(&z_xdrs, &offset))
	     || (!xdr_afs_int32(&z_xdrs, &flags))
	     || (!xdr_charListT(&z_xdrs, charListPtr))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_SaveText(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 lockHandle,afs_int32 textType,afs_int32 offset,afs_int32 flags,charListT * charListPtr)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_SaveText(tc
, lockHandle, textType, offset, flags, charListPtr);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FreeAllLocks(register struct rx_connection *z_conn,afs_uint32 instanceId)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 19;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &instanceId))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FreeAllLocks(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 instanceId)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FreeAllLocks(tc
, instanceId);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_FreeLock(register struct rx_connection *z_conn,afs_uint32 lockHandle)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 20;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &lockHandle))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_FreeLock(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 lockHandle)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_FreeLock(tc
, lockHandle);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetInstanceId(register struct rx_connection *z_conn,afs_uint32 * instanceId)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 21;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_uint32(&z_xdrs, instanceId))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetInstanceId(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 * instanceId)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetInstanceId(tc
, instanceId);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_GetLock(register struct rx_connection *z_conn,afs_uint32 instanceId,afs_int32 lockName,afs_int32 expiration,afs_uint32 * lockHandle)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 22;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_uint32(&z_xdrs, &instanceId))
	     || (!xdr_afs_int32(&z_xdrs, &lockName))
	     || (!xdr_afs_int32(&z_xdrs, &expiration))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_uint32(&z_xdrs, lockHandle))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_GetLock(register struct ubik_client *aclient, afs_int32 aflags,afs_uint32 instanceId,afs_int32 lockName,afs_int32 expiration,afs_uint32 * lockHandle)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_GetLock(tc
, instanceId, lockName, expiration, lockHandle);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_DbVerify(register struct rx_connection *z_conn,afs_int32 * status,afs_int32 * orphans,afs_int32 * host)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 23;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, status))
	     || (!xdr_afs_int32(&z_xdrs, orphans))
	     || (!xdr_afs_int32(&z_xdrs, host))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_DbVerify(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 * status,afs_int32 * orphans,afs_int32 * host)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_DbVerify(tc
, status, orphans, host);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_DumpDB(register struct rx_connection *z_conn,int firstcall,afs_int32 maxLength,charListT * charListPtr,afs_int32 * flags)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 24;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_int(&z_xdrs, &firstcall))
	     || (!xdr_afs_int32(&z_xdrs, &maxLength))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_charListT(&z_xdrs, charListPtr))
	     || (!xdr_afs_int32(&z_xdrs, flags))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_DumpDB(register struct ubik_client *aclient, afs_int32 aflags,int firstcall,afs_int32 maxLength,charListT * charListPtr,afs_int32 * flags)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_DumpDB(tc
, firstcall, maxLength, charListPtr, flags);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_RestoreDbHeader(register struct rx_connection *z_conn,struct DbHeader * header)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 25;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_DbHeader(&z_xdrs, header))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_RestoreDbHeader(register struct ubik_client *aclient, afs_int32 aflags,struct DbHeader * header)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_RestoreDbHeader(tc
, header);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_T_GetVersion(register struct rx_connection *z_conn,afs_int32 * majorVersion)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 26;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_afs_int32(&z_xdrs, majorVersion))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_T_GetVersion(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 * majorVersion)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_T_GetVersion(tc
, majorVersion);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_T_DumpHashTable(register struct rx_connection *z_conn,afs_int32 type,char * filename)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 27;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &type))
	     || (!xdr_string(&z_xdrs, &filename, 32))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_T_DumpHashTable(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 type,char * filename)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_T_DumpHashTable(tc
, type, filename);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_T_DumpDatabase(register struct rx_connection *z_conn,char * filename)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 28;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_string(&z_xdrs, &filename, 32))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_T_DumpDatabase(register struct ubik_client *aclient, afs_int32 aflags,char * filename)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_T_DumpDatabase(tc
, filename);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_AddVolumes(register struct rx_connection *z_conn,struct budb_volumeList * vols)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 29;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_budb_volumeList(&z_xdrs, vols))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_AddVolumes(register struct ubik_client *aclient, afs_int32 aflags,struct budb_volumeList * vols)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_AddVolumes(tc
, vols);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

int BUDB_ListDumps(register struct rx_connection *z_conn,afs_int32 sflags,char * name,afs_int32 group,afs_uint32 fromTime,afs_uint32 toTime,budb_dumpsList * dumps,budb_dumpsList * flags)
{
	struct rx_call *z_call = rx_NewCall(z_conn);
	static int z_op = 30;
	int z_result;
	XDR z_xdrs;
	xdrrx_create(&z_xdrs, z_call, XDR_ENCODE);

	/* Marshal the arguments */
	if ((!xdr_int(&z_xdrs, &z_op))
	     || (!xdr_afs_int32(&z_xdrs, &sflags))
	     || (!xdr_string(&z_xdrs, &name, 256))
	     || (!xdr_afs_int32(&z_xdrs, &group))
	     || (!xdr_afs_uint32(&z_xdrs, &fromTime))
	     || (!xdr_afs_uint32(&z_xdrs, &toTime))
	     || (!xdr_budb_dumpsList(&z_xdrs, dumps))
	     || (!xdr_budb_dumpsList(&z_xdrs, flags))) {
		z_result = RXGEN_CC_MARSHAL;
		goto fail;
	}

	/* Un-marshal the reply arguments */
	z_xdrs.x_op = XDR_DECODE;
	if ((!xdr_budb_dumpsList(&z_xdrs, dumps))
	     || (!xdr_budb_dumpsList(&z_xdrs, flags))) {
		z_result = RXGEN_CC_UNMARSHAL;
		goto fail;
	}

	z_result = RXGEN_SUCCESS;
fail:
	z_result = rx_EndCall(z_call, z_result);
	return z_result;
}

int ubik_BUDB_ListDumps(register struct ubik_client *aclient, afs_int32 aflags,afs_int32 sflags,char * name,afs_int32 group,afs_uint32 fromTime,afs_uint32 toTime,budb_dumpsList * dumps,budb_dumpsList * flags)
{	afs_int32 rcode, code, newHost, thisHost, i, _ucount;
	int chaseCount, pass, needsync, inlist;
	struct rx_connection *tc;
	struct rx_peer *rxp;
	short origLevel;

	if (!aclient)
		return UNOENT;
	LOCK_UBIK_CLIENT(aclient);

	 restart:
	origLevel = aclient->initializationState;
	rcode = UNOSERVERS;
	chaseCount = inlist = needsync = 0;

	/* 
	* First  pass, we try all servers that are up.
	* Second pass, we try all servers.
	*/
	for (pass = 0; pass < 2; pass++) {  /*p */
		/* For each entry in our servers list */
		for (_ucount = 0;; _ucount++) {     /*s */

		if (needsync) {
			/* Need a sync site. Lets try to quickly find it */
			if (aclient->syncSite) {
				newHost = aclient->syncSite;        /* already in network order */
				aclient->syncSite = 0;      /* Will reset if it works */
			} else if (aclient->conns[3]) {
				/* If there are fewer than four db servers in a cell,
				* there's no point in making the GetSyncSite call.
				* At best, it's a wash. At worst, it results in more
				* RPCs than you would otherwise make.
				*/
				tc = aclient->conns[_ucount];
				if (tc && rx_ConnError(tc)) {
					aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
				}
				if (!tc)
					break;
				code = VOTE_GetSyncSite(tc, &newHost);
				if (aclient->initializationState != origLevel)
					goto restart;   /* somebody did a ubik_ClientInit */
				if (code)
					newHost = 0;
				newHost = htonl(newHost);   /* convert to network order */
			} else {
				newHost = 0;
			}
			if (newHost) {
				/* position count at the appropriate slot in the client
				* structure and retry. If we can't find in slot, we'll
				* just continue through the whole list 
				*/
				for (i = 0; i < MAXSERVERS && aclient->conns[i]; i++) {
					rxp = rx_PeerOf(aclient->conns[i]);
					thisHost = rx_HostOf(rxp);
					if (!thisHost)
						break;
					if (thisHost == newHost) {
						if (chaseCount++ > 2)
							break;  /* avoid loop asking */
						_ucount = i;  /* this index is the sync site */
						break;
					}
				}
			}
		}
		/*needsync */
		tc = aclient->conns[_ucount];
		if (tc && rx_ConnError(tc)) {
			aclient->conns[_ucount] = tc = ubik_RefreshConn(tc);
		}
		if (!tc)
			break;

		if ((pass == 0) && (aclient->states[_ucount] & CFLastFailed)) {
			continue;       /* this guy's down */
		}
		rcode = BUDB_ListDumps(tc
, sflags, name, group, fromTime, toTime, dumps, flags);
		if (aclient->initializationState != origLevel) {
			/* somebody did a ubik_ClientInit */
			if (rcode)
				goto restart;       /* call failed */
			else
				goto done;  /* call suceeded */
		}
		if (rcode < 0) {    /* network errors */
			aclient->states[_ucount] |= CFLastFailed; /* Mark server down */
		} else if (rcode == UNOTSYNC) {
			needsync = 1;
		} else if (rcode != UNOQUORUM) {
			/* either misc ubik code, or misc appl code, or success. */
			aclient->states[_ucount] &= ~CFLastFailed;        /* mark server up*/
			goto done;      /* all done */
		}
		}                       /*s */
	}                           /*p */

	done:
	if (needsync) {
		if (!inlist) {          /* Remember proc call that needs sync site */
			inlist = 1;
		}
		if (!rcode) {           /* Remember the sync site - cmd successful */
			rxp = rx_PeerOf(aclient->conns[_ucount]);
			aclient->syncSite = rx_HostOf(rxp);
		}
	}
	UNLOCK_UBIK_CLIENT(aclient);
	return rcode;
}

