/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
#include <sys/types.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
-#include <assert.h>
#ifdef AFS_NT40_ENV
#include <winsock2.h>
#include <rx/xdr.h>
#include <rx/rx.h>
#include <afs/afsutil.h>
+#include <afs/cellconfig.h>
#define UBIK_INTERNALS
#include "ubik.h"
*/
/*!
- * if this flag is set, then ubik will use only the primary address
- * (the address specified in the CellServDB) to contact other
- * ubik servers. Ubik recovery will not try opening connections
- * to the alternate interface addresses.
+ * if this flag is set, then ubik will use only the primary address
+ * (the address specified in the CellServDB) to contact other
+ * ubik servers. Ubik recovery will not try opening connections
+ * to the alternate interface addresses.
*/
int ubikPrimaryAddrOnly;
* \brief sync site
*
* routine called when a non-sync site server goes down; restarts recovery
- * process to send missing server the new db when it comes back up.
+ * process to send missing server the new db when it comes back up for
+ * non-sync site servers.
*
- * \note This routine should not do anything with variables used by non-sync site servers.
+ * \note This routine should not do anything with variables used by non-sync site servers.
*/
int
-urecovery_LostServer(void)
+urecovery_LostServer(struct ubik_server *ts)
{
+ ubeacon_ReinitServer(ts);
#if !defined(AFS_PTHREAD_ENV)
/* No corresponding LWP_WaitProcess found anywhere for this -- klm */
LWP_NoYieldSignal(&urecovery_state);
* and we must have a currently-good sync site.
*/
int
-urecovery_AllBetter(register struct ubik_dbase *adbase, int areadAny)
+urecovery_AllBetter(struct ubik_dbase *adbase, int areadAny)
{
- register afs_int32 rcode;
+ afs_int32 rcode;
ubik_dprint_25("allbetter checking\n");
rcode = 0;
int
urecovery_AbortAll(struct ubik_dbase *adbase)
{
- register struct ubik_trans *tt;
+ struct ubik_trans *tt;
for (tt = adbase->activeTrans; tt; tt = tt->next) {
udisk_abort(tt);
}
* \brief this routine aborts the current remote transaction, if any, if the tid is wrong
*/
int
-urecovery_CheckTid(register struct ubik_tid *atid)
+urecovery_CheckTid(struct ubik_tid *atid, int abortalways)
{
if (ubik_currentTrans) {
/* there is remote write trans, see if we match, see if this
* is a new transaction */
if (atid->epoch != ubik_currentTrans->tid.epoch
- || atid->counter > ubik_currentTrans->tid.counter) {
+ || atid->counter > ubik_currentTrans->tid.counter || abortalways) {
/* don't match, abort it */
/* If the thread is not waiting for lock - ok to end it */
-#if !defined(UBIK_PAUSE)
if (ubik_currentTrans->locktype != LOCKWAIT) {
-#endif /* UBIK_PAUSE */
udisk_end(ubik_currentTrans);
-#if !defined(UBIK_PAUSE)
}
-#endif /* UBIK_PAUSE */
ubik_currentTrans = (struct ubik_trans *)0;
}
}
* the log.
*/
static int
-ReplayLog(register struct ubik_dbase *adbase)
+ReplayLog(struct ubik_dbase *adbase)
{
afs_int32 opcode;
- register afs_int32 code, tpos;
+ afs_int32 code, tpos;
int logIsGood;
afs_int32 len, thisSize, tfile, filePos;
afs_int32 buffer[4];
sizeof(afs_int32));
if (code != sizeof(afs_int32))
break;
+ opcode = ntohl(opcode);
if (opcode == LOGNEW) {
/* handle begin trans */
tpos += sizeof(afs_int32);
if (code != 3 * sizeof(afs_int32))
break;
/* otherwise, skip over the data bytes, too */
- tpos += buffer[2] + 3 * sizeof(afs_int32);
+ tpos += ntohl(buffer[2]) + 3 * sizeof(afs_int32);
} else {
- ubik_dprint("corrupt log opcode (%d) at position %d\n", opcode,
- tpos);
+ ubik_print("corrupt log opcode (%d) at position %d\n", opcode,
+ tpos);
break; /* corrupt log! */
}
}
sizeof(afs_int32));
if (code != sizeof(afs_int32))
break;
+ opcode = ntohl(opcode);
if (opcode == LOGNEW) {
/* handle begin trans */
tpos += sizeof(afs_int32);
} else if (opcode == LOGABORT)
panic("log abort\n");
else if (opcode == LOGEND) {
+ struct ubik_version version;
tpos += 4;
code =
(*adbase->read) (adbase, LOGFILE, (char *)buffer, tpos,
2 * sizeof(afs_int32));
if (code != 2 * sizeof(afs_int32))
return UBADLOG;
- code = (*adbase->setlabel) (adbase, 0, (ubik_version *)buffer);
+ version.epoch = ntohl(buffer[0]);
+ version.counter = ntohl(buffer[1]);
+ code = (*adbase->setlabel) (adbase, 0, &version);
if (code)
return code;
+ ubik_print("Successfully replayed log for interrupted "
+ "transaction; db version is now %ld.%ld\n",
+ (long) version.epoch, (long) version.counter);
logIsGood = 1;
break; /* all done now */
} else if (opcode == LOGTRUNCATE) {
len -= thisSize;
}
} else {
- ubik_dprint("corrupt log opcode (%d) at position %d\n",
- opcode, tpos);
+ ubik_print("corrupt log opcode (%d) at position %d\n",
+ opcode, tpos);
break; /* corrupt log! */
}
}
if (code)
return code;
} else {
- ubik_dprint("Log read error on pass 2\n");
+ ubik_print("Log read error on pass 2\n");
return UBADLOG;
}
}
* This routine is called after replaying the log; it reads the restored labels.
*/
static int
-InitializeDB(register struct ubik_dbase *adbase)
+InitializeDB(struct ubik_dbase *adbase)
{
- register afs_int32 code;
+ afs_int32 code;
code = (*adbase->getlabel) (adbase, 0, &adbase->version);
if (code) {
(*adbase->setlabel) (adbase, 0, &adbase->version);
}
#ifdef AFS_PTHREAD_ENV
- assert(pthread_cond_broadcast(&adbase->version_cond) == 0);
+ CV_BROADCAST(&adbase->version_cond);
#else
LWP_NoYieldSignal(&adbase->version);
#endif
* We replay the logs and then read the resulting file to figure out what version we've really got.
*/
int
-urecovery_Initialize(register struct ubik_dbase *adbase)
+urecovery_Initialize(struct ubik_dbase *adbase)
{
- register afs_int32 code;
+ afs_int32 code;
code = ReplayLog(adbase);
if (code)
struct ubik_server *bestServer = NULL;
struct ubik_server *ts;
int dbok, doingRPC, now;
- afs_int32 lastProbeTime, lastDBVCheck;
+ afs_int32 lastProbeTime;
/* if we're the sync site, the best db version we've found yet */
static struct ubik_version bestDBVersion;
struct ubik_version tversion;
struct ubik_stat ubikstat;
struct in_addr inAddr;
char hoststr[16];
-#ifndef OLD_URECOVERY
char pbuffer[1028];
- int flen, fd = -1;
+ int fd = -1;
afs_int32 pass;
-#endif
/* otherwise, begin interaction */
urecovery_state = 0;
lastProbeTime = 0;
- lastDBVCheck = 0;
while (1) {
/* Run through this loop every 4 seconds */
tv.tv_sec = 4;
/* Every 30 seconds, check all the down servers and mark them
* as up if they respond. When a server comes up or found to
- * not be current, then re-find the the best database and
+ * not be current, then re-find the the best database and
* propogate it.
*/
if ((now = FT_ApproxTime()) > 30 + lastProbeTime) {
+
+#ifdef AFS_PTHREAD_ENV
+ DBHOLD(ubik_dbase);
+#endif
+
for (ts = ubik_servers, doingRPC = 0; ts; ts = ts->next) {
if (!ts->up) {
doingRPC = 1;
urecovery_state &= ~UBIK_RECFOUNDDB;
}
}
+
+#ifdef AFS_PTHREAD_ENV
+ DBRELE(ubik_dbase);
+#endif
+
if (doingRPC)
now = FT_ApproxTime();
lastProbeTime = now;
}
urecovery_state |= UBIK_RECSYNCSITE;
- /* If a server has just come up or if we have not found the
+ /* If a server has just come up or if we have not found the
* most current database, then go find the most current db.
*/
if (!(urecovery_state & UBIK_RECFOUNDDB)) {
*/
urecovery_state &= ~UBIK_RECHAVEDB;
}
- lastDBVCheck = FT_ApproxTime();
urecovery_state |= UBIK_RECFOUNDDB;
urecovery_state &= ~UBIK_RECSENTDB;
}
-#if defined(UBIK_PAUSE)
- /* it's not possible for UBIK_RECFOUNDDB not to be set here.
- * However, we might have lost UBIK_RECSYNCSITE, and that
- * IS important.
- */
- if (!(urecovery_state & UBIK_RECSYNCSITE))
- continue; /* lost sync */
-#else
if (!(urecovery_state & UBIK_RECFOUNDDB))
continue; /* not ready */
-#endif /* UBIK_PAUSE */
/* If we, the sync site, do not have the best db version, then
* go and get it from the server that does.
goto FetchEndCall;
}
-#ifdef OLD_URECOVERY
- /* Truncate the file first */
- code = (*ubik_dbase->truncate) (ubik_dbase, file, 0);
- if (code) {
- ubik_dprint("truncate io error=%d\n", code);
- goto FetchEndCall;
- }
- tversion.counter = 0;
-#endif
/* give invalid label during file transit */
tversion.epoch = 0;
code = (*ubik_dbase->setlabel) (ubik_dbase, file, &tversion);
ubik_dprint("setlabel io error=%d\n", code);
goto FetchEndCall;
}
-#ifndef OLD_URECOVERY
- flen = length;
afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file);
fd = open(pbuffer, O_CREAT | O_RDWR | O_TRUNC, 0600);
if (fd < 0) {
close(fd);
goto FetchEndCall;
}
-#endif
pass = 0;
while (length > 0) {
close(fd);
goto FetchEndCall;
}
-#ifdef OLD_URECOVERY
- nbytes =
- (*ubik_dbase->write) (ubik_dbase, file, tbuffer, offset,
- tlen);
-#else
nbytes = write(fd, tbuffer, tlen);
pass++;
-#endif
if (nbytes != tlen) {
code = UIOERROR;
close(fd);
offset += tlen;
length -= tlen;
}
-#ifndef OLD_URECOVERY
code = close(fd);
if (code)
goto FetchEndCall;
-#endif
code = EndDISK_GetFile(rxcall, &tversion);
FetchEndCall:
tcode = rx_EndCall(rxcall, code);
urecovery_state |= UBIK_RECHAVEDB;
memcpy(&ubik_dbase->version, &tversion,
sizeof(struct ubik_version));
-#ifdef OLD_URECOVERY
- (*ubik_dbase->sync) (ubik_dbase, 0); /* get data out first */
-#else
afs_snprintf(tbuffer, sizeof(tbuffer), "%s.DB%s%d", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file);
#ifdef AFS_NT40_ENV
afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file);
code = rename(tbuffer, pbuffer);
afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.TMP", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file);
#endif
- if (!code)
+ if (!code)
code = rename(pbuffer, tbuffer);
if (!code) {
- (*ubik_dbase->open) (ubik_dbase, 0);
-#endif
+ (*ubik_dbase->open) (ubik_dbase, file);
/* after data is good, sync disk with correct label */
code =
(*ubik_dbase->setlabel) (ubik_dbase, 0,
&ubik_dbase->version);
-#ifndef OLD_URECOVERY
}
#ifdef AFS_NT40_ENV
afs_snprintf(pbuffer, sizeof(pbuffer), "%s.DB%s%d.OLD", ubik_dbase->pathName, (file<0)?"SYS":"", (file<0)?-file:file);
unlink(pbuffer);
#endif
-#endif
}
if (code) {
-#ifndef OLD_URECOVERY
unlink(pbuffer);
- /*
+ /*
* We will effectively invalidate the old data forever now.
* Unclear if we *should* but we do.
*/
-#endif
ubik_dbase->version.epoch = 0;
ubik_dbase->version.counter = 0;
ubik_print("Ubik: Synchronize database failed (error = %d)\n",
}
udisk_Invalidate(ubik_dbase, 0); /* data has changed */
#ifdef AFS_PTHREAD_ENV
- assert(pthread_cond_broadcast(&ubik_dbase->version_cond) == 0);
+ CV_BROADCAST(&ubik_dbase->version_cond);
#else
LWP_NoYieldSignal(&ubik_dbase->version);
#endif
DBRELE(ubik_dbase);
}
-#if defined(UBIK_PAUSE)
- if (!(urecovery_state & UBIK_RECSYNCSITE))
- continue; /* lost sync */
-#endif /* UBIK_PAUSE */
if (!(urecovery_state & UBIK_RECHAVEDB))
continue; /* not ready */
(*ubik_dbase->setlabel) (ubik_dbase, 0, &ubik_dbase->version);
udisk_Invalidate(ubik_dbase, 0); /* data may have changed */
#ifdef AFS_PTHREAD_ENV
- assert(pthread_cond_broadcast(&ubik_dbase->version_cond) == 0);
+ CV_BROADCAST(&ubik_dbase->version_cond);
#else
LWP_NoYieldSignal(&ubik_dbase->version);
#endif
}
/*!
- * \brief send a Probe to all the network address of this server
- *
+ * \brief send a Probe to all the network address of this server
+ *
* \return 0 if success, else return 1
*/
int
{
struct rx_connection *conns[UBIK_MAX_INTERFACE_ADDR];
struct rx_connection *connSuccess = 0;
- int i, j;
+ int i, j, success_i = -1;
afs_uint32 addr;
char buffer[32];
char hoststr[16];
break;
}
}
- assert(i); /* at least one interface address for this server */
+ osi_Assert(i); /* at least one interface address for this server */
+
+#ifdef AFS_PTHREAD_ENV
+ DBRELE(ubik_dbase);
+#endif
multi_Rx(conns, i) {
multi_DISK_Probe();
if (!multi_error) { /* first success */
- addr = server->addr[multi_i]; /* successful interface addr */
-
- if (server->disk_rxcid) /* destroy existing conn */
- rx_DestroyConnection(server->disk_rxcid);
- if (server->vote_rxcid)
- rx_DestroyConnection(server->vote_rxcid);
-
- /* make new connections */
- server->disk_rxcid = conns[multi_i];
- server->vote_rxcid = rx_NewConnection(addr, ubik_callPortal, VOTE_SERVICE_ID, ubikSecClass, ubikSecIndex); /* for vote reqs */
-
- connSuccess = conns[multi_i];
- strcpy(buffer, afs_inet_ntoa_r(server->addr[0], hoststr));
- ubik_print
- ("ubik:server %s is back up: will be contacted through %s\n",
- buffer, afs_inet_ntoa_r(addr, hoststr));
+ success_i = multi_i;
multi_Abort;
}
} multi_End_Ignore;
+#ifdef AFS_PTHREAD_ENV
+ DBHOLD(ubik_dbase);
+#endif
+
+ if (success_i >= 0) {
+ addr = server->addr[success_i]; /* successful interface addr */
+
+ if (server->disk_rxcid) /* destroy existing conn */
+ rx_DestroyConnection(server->disk_rxcid);
+ if (server->vote_rxcid)
+ rx_DestroyConnection(server->vote_rxcid);
+
+ /* make new connections */
+ server->disk_rxcid = conns[success_i];
+ server->vote_rxcid = rx_NewConnection(addr, ubik_callPortal,
+ VOTE_SERVICE_ID, ubikSecClass,
+ ubikSecIndex);
+
+ connSuccess = conns[success_i];
+ strcpy(buffer, afs_inet_ntoa_r(server->addr[0], hoststr));
+
+ ubik_print("ubik:server %s is back up: will be contacted through %s\n",
+ buffer, afs_inet_ntoa_r(addr, hoststr));
+ }
+
/* Destroy all connections except the one on which we succeeded */
for (j = 0; j < i; j++)
if (conns[j] != connSuccess)