#include <afsconfig.h>
#include "afs/param.h"
-RCSID
- ("$Header$");
#ifdef AFS_AIX51_ENV
#define __FULL_PROTO
#include <sys/adspace.h> /* for vm_att(), vm_det() */
#endif
-
+#if defined(AFS_CACHE_BYPASS)
+#include "afs/afs_bypasscache.h"
+#endif// defined(AFS_CACHE_BYPASS)
/* background request queue size */
afs_lock_t afs_xbrs; /* lock for brs */
static int brsInit = 0;
afs_int32 afs_gcpags_procsize = 0;
afs_int32 afs_CheckServerDaemonStarted = 0;
-#ifdef DEFAULT_PROBE_INTERVAL
-afs_int32 PROBE_INTERVAL = DEFAULT_PROBE_INTERVAL; /* overridding during compile */
-#else
-afs_int32 PROBE_INTERVAL = 180; /* default to 3 min */
+#ifndef DEFAULT_PROBE_INTERVAL
+#define DEFAULT_PROBE_INTERVAL 30 /* default to 3 min */
#endif
+afs_int32 afs_probe_interval = DEFAULT_PROBE_INTERVAL;
+afs_int32 afs_probe_all_interval = 600;
+afs_int32 afs_nat_probe_interval = 60;
+afs_int32 afs_preCache = 0;
-#define PROBE_WAIT() (1000 * (PROBE_INTERVAL - ((afs_random() & 0x7fffffff) \
- % (PROBE_INTERVAL/2))))
+#define PROBE_WAIT() (1000 * (afs_probe_interval - ((afs_random() & 0x7fffffff) \
+ % (afs_probe_interval/2))))
+
+void
+afs_SetCheckServerNATmode(int isnat)
+{
+ static afs_int32 old_intvl, old_all_intvl;
+ static int wasnat;
+
+ if (isnat && !wasnat) {
+ old_intvl = afs_probe_interval;
+ old_all_intvl = afs_probe_all_interval;
+ afs_probe_interval = afs_nat_probe_interval;
+ afs_probe_all_interval = afs_nat_probe_interval;
+ afs_osi_CancelWait(&AFS_CSWaitHandler);
+ } else if (!isnat && wasnat) {
+ afs_probe_interval = old_intvl;
+ afs_probe_all_interval = old_all_intvl;
+ }
+ wasnat = isnat;
+}
void
afs_CheckServerDaemon(void)
}
now = osi_Time();
- if (PROBE_INTERVAL + lastCheck <= now) {
+ if (afs_probe_interval + lastCheck <= now) {
afs_CheckServers(1, NULL); /* check down servers */
lastCheck = now = osi_Time();
}
- if (600 + last10MinCheck <= now) {
- afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, ICL_TYPE_INT32, 600);
+ if (afs_probe_all_interval + last10MinCheck <= now) {
+ afs_Trace1(afs_iclSetp, CM_TRACE_PROBEUP, ICL_TYPE_INT32, afs_probe_all_interval);
afs_CheckServers(0, NULL);
last10MinCheck = now = osi_Time();
}
}
/* Compute time to next probe. */
- delay = PROBE_INTERVAL + lastCheck;
- if (delay > 600 + last10MinCheck)
- delay = 600 + last10MinCheck;
+ delay = afs_probe_interval + lastCheck;
+ if (delay > afs_probe_all_interval + last10MinCheck)
+ delay = afs_probe_all_interval + last10MinCheck;
delay -= now;
if (delay < 1)
delay = 1;
}
afs_CheckServerDaemonStarted = 0;
}
-#define RECURSIVE_VFS_CONTEXT 1
-#if RECURSIVE_VFS_CONTEXT
+
extern int vfs_context_ref;
-#else
-#define vfs_context_ref 1
-#endif
+
+/* This function always holds the GLOCK whilst it is running. The caller
+ * gets the GLOCK before invoking it, and afs_osi_Sleep drops the GLOCK
+ * whilst we are sleeping, and regains it when we're woken up.
+ */
void
afs_Daemon(void)
{
struct afs_exporter *exporter;
afs_int32 now;
afs_int32 last3MinCheck, last10MinCheck, last60MinCheck, lastNMinCheck;
- afs_int32 last1MinCheck;
+ afs_int32 last1MinCheck, last5MinCheck;
afs_uint32 lastCBSlotBump;
char cs_warned = 0;
AFS_STATCNT(afs_Daemon);
last1MinCheck = last3MinCheck = last60MinCheck = last10MinCheck =
- lastNMinCheck = 0;
+ last5MinCheck = lastNMinCheck = 0;
afs_rootFid.Fid.Volume = 0;
while (afs_initState < 101)
osi_Panic("vfs context already initialized");
while (afs_osi_ctxtp && vfs_context_ref)
afs_osi_Sleep(&afs_osi_ctxtp);
-#if RECURSIVE_VFS_CONTEXT
if (afs_osi_ctxtp && !vfs_context_ref)
vfs_context_rele(afs_osi_ctxtp);
-#endif
afs_osi_ctxtp = vfs_context_create(NULL);
afs_osi_ctxtp_initialized = 1;
#endif
last3MinCheck = now - 90 + ((afs_random() & 0x7fffffff) % 180);
last60MinCheck = now - 1800 + ((afs_random() & 0x7fffffff) % 3600);
last10MinCheck = now - 300 + ((afs_random() & 0x7fffffff) % 600);
+ last5MinCheck = now - 150 + ((afs_random() & 0x7fffffff) % 300);
lastNMinCheck = now - 90 + ((afs_random() & 0x7fffffff) % 180);
/* start off with afs_initState >= 101 (basic init done) */
/* things to do every minute */
DFlush(); /* write out dir buffers */
afs_WriteThroughDSlots(); /* write through cacheinfo entries */
+ ObtainWriteLock(&afs_xvcache, 736);
+ afs_FlushReclaimedVcaches();
+ ReleaseWriteLock(&afs_xvcache);
afs_FlushActiveVcaches(1); /* keep flocks held & flush nfs writes */
+#if 0
#ifdef AFS_DISCON_ENV
afs_StoreDirtyVcaches();
#endif
+#endif
afs_CheckRXEpoch();
last1MinCheck = now;
}
* tickets */
last3MinCheck = now;
}
+
+ if (afsd_dynamic_vcaches && (last5MinCheck + 300 < now)) {
+ /* start with trying to drop us back to our base usage */
+ int anumber;
+ if (afs_maxvcount <= afs_cacheStats)
+ anumber = VCACHE_FREE;
+ else
+ anumber = VCACHE_FREE + (afs_maxvcount - afs_cacheStats);
+
+ ObtainWriteLock(&afs_xvcache, 734);
+ afs_ShakeLooseVCaches(anumber);
+ ReleaseWriteLock(&afs_xvcache);
+ last5MinCheck = now;
+ }
+
if (!afs_CheckServerDaemonStarted) {
/* Do the check here if the correct afsd is not installed. */
if (!cs_warned) {
cs_warned = 1;
- printf("Please install afsd with check server daemon.\n");
+ afs_warn("Please install afsd with check server daemon.\n");
}
- if (lastNMinCheck + PROBE_INTERVAL < now) {
+ if (lastNMinCheck + afs_probe_interval < now) {
/* only check down servers */
afs_CheckServers(1, NULL);
lastNMinCheck = now;
afs_rootFid.Cell = localcell;
if (afs_rootFid.Fid.Volume && afs_rootFid.Fid.Volume != volid
&& afs_globalVp) {
- struct vcache *tvc = afs_globalVp;
/* If we had a root fid before and it changed location we reset
* the afs_globalVp so that it will be reevaluated.
* Just decrement the reference count. This only occurs during
{
register struct dcache *tdc;
register struct vcache *tvc;
- afs_size_t offset, len;
+ afs_size_t offset, len, abyte, totallen = 0;
struct vrequest treq;
AFS_STATCNT(BPrefetch);
if ((len = afs_InitReq(&treq, ab->cred)))
return;
+ abyte = ab->size_parm[0];
tvc = ab->vc;
- tdc = afs_GetDCache(tvc, ab->size_parm[0], &treq, &offset, &len, 1);
- if (tdc) {
- afs_PutDCache(tdc);
- }
+ do {
+ tdc = afs_GetDCache(tvc, abyte, &treq, &offset, &len, 1);
+ if (tdc) {
+ afs_PutDCache(tdc);
+ }
+ abyte+=len;
+ totallen += len;
+ } while ((totallen < afs_preCache) && tdc && (len > 0));
/* now, dude may be waiting for us to clear DFFetchReq bit; do so. Can't
* use tdc from GetDCache since afs_GetDCache may fail, but someone may
* be waiting for our wakeup anyway.
}
}
+#if defined(AFS_CACHE_BYPASS)
+#if 1 /* XXX Matt debugging */
+static
+#endif
+void
+BPrefetchNoCache(register struct brequest *ab)
+{
+ struct vrequest treq;
+ afs_size_t len;
+
+ if ((len = afs_InitReq(&treq, ab->cred)))
+ return;
+
+#ifndef UKERNEL
+ /* OS-specific prefetch routine */
+ afs_PrefetchNoCache(ab->vc, ab->cred, (struct nocache_read_request *) ab->ptr_parm[0]);
+#else
+#warning Cache-bypass code path not implemented in UKERNEL
+#endif
+}
+#endif
static void
BStore(register struct brequest *ab)
{
AFS_STATCNT(afs_BRelease);
- MObtainWriteLock(&afs_xbrs, 294);
+ ObtainWriteLock(&afs_xbrs, 294);
if (--ab->refCount <= 0) {
ab->flags = 0;
}
if (afs_brsWaiters)
afs_osi_Wakeup(&afs_brsWaiters);
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
}
/* return true if bkg fetch daemons are all busy */
struct brequest *
afs_BQueue(register short aopcode, register struct vcache *avc,
- afs_int32 dontwait, afs_int32 ause, struct AFS_UCRED *acred,
- afs_size_t asparm0, afs_size_t asparm1, void *apparm0)
+ afs_int32 dontwait, afs_int32 ause, afs_ucred_t *acred,
+ afs_size_t asparm0, afs_size_t asparm1, void *apparm0,
+ void *apparm1, void *apparm2)
{
register int i;
register struct brequest *tb;
AFS_STATCNT(afs_BQueue);
- MObtainWriteLock(&afs_xbrs, 296);
+ ObtainWriteLock(&afs_xbrs, 296);
while (1) {
tb = afs_brs;
for (i = 0; i < NBRS; i++, tb++) {
tb->size_parm[0] = asparm0;
tb->size_parm[1] = asparm1;
tb->ptr_parm[0] = apparm0;
+ tb->ptr_parm[1] = apparm1;
+ tb->ptr_parm[2] = apparm2;
tb->flags = 0;
tb->code = 0;
tb->ts = afs_brs_count++;
if (afs_brsDaemons > 0) {
afs_osi_Wakeup(&afs_brsDaemons);
}
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
return tb;
}
if (dontwait) {
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
return NULL;
}
/* no free buffers, sleep a while */
afs_brsWaiters++;
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
afs_osi_Sleep(&afs_brsWaiters);
- MObtainWriteLock(&afs_xbrs, 301);
+ ObtainWriteLock(&afs_xbrs, 301);
afs_brsWaiters--;
}
}
if (vcp->v.v_gnode->gn_mwrcnt) {
afs_offs_t newlength =
(afs_offs_t) dbtob(bp->b_blkno) + bp->b_bcount;
- if (vcp->m.Length < newlength) {
+ if (vcp->f.m.Length < newlength) {
afs_Trace4(afs_iclSetp, CM_TRACE_SETLENGTH,
ICL_TYPE_STRING, __FILE__, ICL_TYPE_LONG,
__LINE__, ICL_TYPE_OFFSET,
- ICL_HANDLE_OFFSET(vcp->m.Length),
+ ICL_HANDLE_OFFSET(vcp->f.m.Length),
ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(newlength));
- vcp->m.Length = newlength;
+ vcp->f.m.Length = newlength;
}
}
ReleaseWriteLock(&vcp->lock);
int afs_nbrs = 0;
+static_inline void
+afs_BackgroundDaemon_once(void)
+{
+ LOCK_INIT(&afs_xbrs, "afs_xbrs");
+ memset(afs_brs, 0, sizeof(afs_brs));
+ brsInit = 1;
+#if defined (AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
+ /*
+ * steal the first daemon for doing delayed DSlot flushing
+ * (see afs_GetDownDSlot)
+ */
+ AFS_GUNLOCK();
+ afs_sgidaemon();
+ exit(CLD_EXITED, 0);
+#endif
+}
+
+static_inline void
+brequest_release(struct brequest *tb)
+{
+ if (tb->vc) {
+ AFS_RELE(AFSTOV(tb->vc)); /* MUST call vnode layer or could lose vnodes */
+ tb->vc = NULL;
+ }
+ if (tb->cred) {
+ crfree(tb->cred);
+ tb->cred = (afs_ucred_t *)0;
+ }
+ tb->code = 0;
+ afs_BRelease(tb); /* this grabs and releases afs_xbrs lock */
+}
+
+#ifdef AFS_DARWIN80_ENV
+int
+afs_BackgroundDaemon(struct afs_uspc_param *uspc, void *param1, void *param2)
+#else
void
afs_BackgroundDaemon(void)
+#endif
{
struct brequest *tb;
int i, foundAny;
AFS_STATCNT(afs_BackgroundDaemon);
/* initialize subsystem */
- if (brsInit == 0) {
- LOCK_INIT(&afs_xbrs, "afs_xbrs");
- memset((char *)afs_brs, 0, sizeof(afs_brs));
- brsInit = 1;
-#if defined (AFS_SGI_ENV) && defined(AFS_SGI_SHORTSTACK)
- /*
- * steal the first daemon for doing delayed DSlot flushing
- * (see afs_GetDownDSlot)
- */
- AFS_GUNLOCK();
- afs_sgidaemon();
- return;
+ if (brsInit == 0)
+ /* Irix with "short stack" exits */
+ afs_BackgroundDaemon_once();
+
+#ifdef AFS_DARWIN80_ENV
+ /* If it's a re-entering syscall, complete the request and release */
+ if (uspc->ts > -1) {
+ tb = afs_brs;
+ for (i = 0; i < NBRS; i++, tb++) {
+ if (tb->ts == uspc->ts) {
+ /* copy the userspace status back in */
+ ((struct afs_uspc_param *) tb->ptr_parm[0])->retval =
+ uspc->retval;
+ /* mark it valid and notify our caller */
+ tb->flags |= BUVALID;
+ if (tb->flags & BUWAIT) {
+ tb->flags &= ~BUWAIT;
+ afs_osi_Wakeup(tb);
+ }
+ brequest_release(tb);
+ break;
+ }
+ }
+ } else {
+ afs_osi_MaskUserLoop();
#endif
+ /* Otherwise it's a new one */
+ afs_nbrs++;
+#ifdef AFS_DARWIN80_ENV
}
- afs_nbrs++;
+#endif
- MObtainWriteLock(&afs_xbrs, 302);
+ ObtainWriteLock(&afs_xbrs, 302);
while (1) {
int min_ts = 0;
struct brequest *min_tb = NULL;
if (afs_termState == AFSOP_STOP_BKG) {
if (--afs_nbrs <= 0)
afs_termState = AFSOP_STOP_TRUNCDAEMON;
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
afs_osi_Wakeup(&afs_termState);
+#ifdef AFS_DARWIN80_ENV
+ return -2;
+#else
return;
+#endif
}
/* find a request */
if ((tb = min_tb)) {
/* claim and process this request */
tb->flags |= BSTARTED;
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
foundAny = 1;
afs_Trace1(afs_iclSetp, CM_TRACE_BKG1, ICL_TYPE_INT32,
tb->opcode);
if (tb->opcode == BOP_FETCH)
BPrefetch(tb);
+#if defined(AFS_CACHE_BYPASS)
+ else if (tb->opcode == BOP_FETCH_NOCACHE)
+ BPrefetchNoCache(tb);
+#endif
else if (tb->opcode == BOP_STORE)
BStore(tb);
else if (tb->opcode == BOP_PATH)
BPath(tb);
+#ifdef AFS_DARWIN80_ENV
+ else if (tb->opcode == BOP_MOVE) {
+ memcpy(uspc, (struct afs_uspc_param *) tb->ptr_parm[0],
+ sizeof(struct afs_uspc_param));
+ uspc->ts = tb->ts;
+ /* string lengths capped in move vop; copy NUL tho */
+ memcpy(param1, (char *)tb->ptr_parm[1],
+ strlen(tb->ptr_parm[1])+1);
+ memcpy(param2, (char *)tb->ptr_parm[2],
+ strlen(tb->ptr_parm[2])+1);
+ return 0;
+ }
+#endif
else
panic("background bop");
- if (tb->vc) {
- AFS_RELE(AFSTOV(tb->vc)); /* MUST call vnode layer or could lose vnodes */
- tb->vc = NULL;
- }
- if (tb->cred) {
- crfree(tb->cred);
- tb->cred = (struct AFS_UCRED *)0;
- }
- afs_BRelease(tb); /* this grabs and releases afs_xbrs lock */
- MObtainWriteLock(&afs_xbrs, 305);
+ brequest_release(tb);
+ ObtainWriteLock(&afs_xbrs, 305);
}
if (!foundAny) {
/* wait for new request */
afs_brsDaemons++;
- MReleaseWriteLock(&afs_xbrs);
+ ReleaseWriteLock(&afs_xbrs);
afs_osi_Sleep(&afs_brsDaemons);
- MObtainWriteLock(&afs_xbrs, 307);
+ ObtainWriteLock(&afs_xbrs, 307);
afs_brsDaemons--;
}
}
+#ifdef AFS_DARWIN80_ENV
+ return -2;
+#endif
}
if (afs_cold_shutdown) {
afs_brsDaemons = brsInit = 0;
rxepoch_checked = afs_nbrs = 0;
- memset((char *)afs_brs, 0, sizeof(afs_brs));
- memset((char *)&afs_xbrs, 0, sizeof(afs_lock_t));
+ memset(afs_brs, 0, sizeof(afs_brs));
+ memset(&afs_xbrs, 0, sizeof(afs_lock_t));
afs_brsWaiters = 0;
#ifdef AFS_AIX41_ENV
lock_free(&afs_asyncbuf_lock);