#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
#include <sys/types.h>
#include <string.h>
}
/* 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;
DBRELE(dbase);
return 0;
code = udisk_abort(ubik_currentTrans);
/* 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;
DBRELE(dbase);
return code;
struct rx_connection *tconn;
afs_uint32 otherHost = 0;
char hoststr[16];
-#ifndef OLD_URECOVERY
char pbuffer[1028];
int fd = -1;
afs_int32 epoch = 0;
afs_int32 pass;
-#endif
/* send the file back to the requester */
+ dbase = ubik_dbase;
+
if ((code = ubik_CheckAuth(rxcall))) {
+ DBHOLD(dbase);
goto failed;
}
if (offset && offset != otherHost) {
/* we *know* this is the wrong guy */
code = USYNC;
+ DBHOLD(dbase);
goto failed;
}
- dbase = ubik_dbase;
DBHOLD(dbase);
/* abort any active trans that may scribble over the database */
afs_inet_ntoa_r(otherHost, hoststr));
offset = 0;
-#ifdef OLD_URECOVERY
- (*dbase->truncate) (dbase, file, 0); /* truncate first */
- tversion.counter = 0;
-#else
- epoch =
-#endif
- tversion.epoch = 0; /* start off by labelling in-transit db as invalid */
+ epoch = tversion.epoch = 0; /* start off by labelling in-transit db as invalid */
(*dbase->setlabel) (dbase, file, &tversion); /* setlabel does sync */
-#ifndef OLD_URECOVERY
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) {
goto failed;
}
pass = 0;
-#endif
memcpy(&ubik_dbase->version, &tversion, sizeof(struct ubik_version));
while (length > 0) {
tlen = (length > sizeof(tbuffer) ? sizeof(tbuffer) : length);
-#if !defined(OLD_URECOVERY) && !defined(AFS_PTHREAD_ENV)
+#if !defined(AFS_PTHREAD_ENV)
if (pass % 4 == 0)
IOMGR_Poll();
#endif
code = rx_Read(rxcall, tbuffer, tlen);
if (code != tlen) {
- DBRELE(dbase);
ubik_dprint("Rx-read length error=%d\n", code);
code = BULK_ERROR;
close(fd);
goto failed;
}
-#ifdef OLD_URECOVERY
- code = (*dbase->write) (dbase, file, tbuffer, offset, tlen);
-#else
code = write(fd, tbuffer, tlen);
pass++;
-#endif
if (code != tlen) {
- DBRELE(dbase);
ubik_dprint("write failed error=%d\n", code);
code = UIOERROR;
close(fd);
offset += tlen;
length -= tlen;
}
-#ifndef OLD_URECOVERY
code = close(fd);
if (code)
goto failed;
-#endif
/* sync data first, then write label and resync (resync done by setlabel call).
* This way, good label is only on good database. */
-#ifdef OLD_URECOVERY
- (*ubik_dbase->sync) (dbase, file);
-#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(pbuffer, tbuffer);
if (!code) {
(*ubik_dbase->open) (ubik_dbase, file);
-#endif
code = (*ubik_dbase->setlabel) (dbase, file, avers);
-#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
memcpy(&ubik_dbase->version, avers, sizeof(struct ubik_version));
udisk_Invalidate(dbase, file); /* new dbase, flush disk buffers */
#ifdef AFS_PTHREAD_ENV
#else
LWP_NoYieldSignal(&dbase->version);
#endif
- DBRELE(dbase);
- failed:
+
+failed:
if (code) {
-#ifndef OLD_URECOVERY
unlink(pbuffer);
/* Failed to sync. Allow reads again for now. */
if (dbase != NULL) {
tversion.epoch = epoch;
(*dbase->setlabel) (dbase, file, &tversion);
}
-#endif
ubik_print
("Ubik: Synchronize database with server %s failed (error = %d)\n",
afs_inet_ntoa_r(otherHost, hoststr), code);
} else {
ubik_print("Ubik: Synchronize database completed\n");
}
+ DBRELE(dbase);
return code;
}