#include <afs/stds.h>
#include <roken.h>
+#include <afs/opr.h>
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#include <rx/xdr.h>
-#include <afs/afs_assert.h>
#include <lwp.h>
#include <lock.h>
#include <afs/afsint.h>
H_UNLOCK;
return 0;
}
- strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+ strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
localtime_r(&LastCall, &tm));
snprintf(tmpStr, sizeof tmpStr, "Host %s:%d down = %d, LastCall %s\n",
afs_inet_ntoa_r(host->host, hoststr),
for (client = host->FirstClient; client; client = client->next) {
if (!client->deleted) {
expTime = client->expTime;
- strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+ strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
localtime_r(&expTime, &tm));
snprintf(tmpStr, sizeof tmpStr,
" user id=%d, name=%s, sl=%s till %s\n",
return;
}
now = FT_ApproxTime();
- strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+ strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
localtime_r(&now, &tm));
snprintf(tmpStr, sizeof tmpStr, "List of active users at %s\n\n",
tbuffer);
return;
}
now = FT_ApproxTime();
- strftime(tbuffer, sizeof(tbuffer), "%a %b %d %T %Y",
+ strftime(tbuffer, sizeof(tbuffer), "%a %b %d %H:%M:%S %Y",
localtime_r(&now, &tm));
snprintf(tmpStr, sizeof tmpStr, "List of active hosts at %s\n\n", tbuffer);
(void)STREAM_WRITE(tmpStr, strlen(tmpStr), 1, file);
static void h_hostToDiskEntry_r(struct host * in, struct hostDiskEntry * out);
static void h_diskEntryToHost_r(struct hostDiskEntry * in, struct host * out);
+/**
+ * Is this host busy?
+ *
+ * This is just a hint and should not be trusted; this should probably only be
+ * used by the host state serialization code when trying to detect if a host
+ * can be sanely serialized to disk or not. If this function returns 1, the
+ * host may be in an invalid state and thus should not be saved to disk.
+ */
+static int
+h_isBusy_r(struct host *host)
+{
+ struct Lock *hostLock = &host->lock;
+ int locked = 0;
+
+ LOCK_LOCK(hostLock);
+ if (hostLock->excl_locked || hostLock->readers_reading) {
+ locked = 1;
+ }
+ LOCK_UNLOCK(hostLock);
+
+ if (locked) {
+ return 1;
+ }
+
+ if ((host->hostFlags & HWHO_INPROGRESS) || !(host->hostFlags & ALTADDR)) {
+ /* We shouldn't hit this if the host wasn't locked, but just in case... */
+ return 1;
+ }
+
+ return 0;
+}
/* this procedure saves all host state to disk for fast startup */
int
struct iovec iov[4];
int iovcnt = 2;
+ if (h_isBusy_r(host)) {
+ char hoststr[16];
+ ViceLog(1, ("Not saving host %s:%d to disk; host appears busy\n",
+ afs_inet_ntoa_r(host->host, hoststr), (int)ntohs(host->port)));
+ /* Make sure we don't try to save callbacks to disk for this host, or
+ * we'll get confused on restore */
+ DeleteAllCallBacks_r(host, 1);
+ return 0;
+ }
+
memset(&hdr, 0, sizeof(hdr));
if (state->h_hdr->index_max < host->index) {
osi_Assert(hcps != NULL);
}
+ if ((hdsk.hostFlags & HWHO_INPROGRESS) || !(hdsk.hostFlags & ALTADDR)) {
+ char hoststr[16];
+ ViceLog(0, ("h_stateRestoreHost: skipping host %s:%d due to invalid flags 0x%x\n",
+ afs_inet_ntoa_r(hdsk.host, hoststr), (int)ntohs(hdsk.port),
+ (unsigned)hdsk.hostFlags));
+ bail = 0;
+ state->h_map.entries[hdsk.index].valid = FS_STATE_IDX_SKIPPED;
+ goto done;
+ }
+
/* for restoring state, we better be able to get a host! */
host = GetHT();
osi_Assert(host != NULL);
h_InsertList_r(host);
/* setup host id map entry */
+ state->h_map.entries[hdsk.index].valid = FS_STATE_IDX_VALID;
state->h_map.entries[hdsk.index].old_idx = hdsk.index;
state->h_map.entries[hdsk.index].new_idx = host->index;
if (old >= state->h_map.len) {
ViceLog(0, ("h_OldToNew: index %d is out of range\n", old));
ret = 1;
- } else if (state->h_map.entries[old].old_idx != old) { /* sanity check */
+ } else if (state->h_map.entries[old].valid != FS_STATE_IDX_VALID ||
+ state->h_map.entries[old].old_idx != old) { /* sanity check */
ViceLog(0, ("h_OldToNew: index %d points to an invalid host record\n", old));
ret = 1;
} else {