* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
+
#include <afs/afs_args.h>
#include <afs/stds.h>
cep->lock.pid_last_reader = 0;
cep->lock.pid_writer = 0;
cep->lock.src_indicator = 0;
-#if !defined(AFS_64BIT_ENV)
- cep->Length.high = scp->length.HighPart;
- cep->Length.low = scp->length.LowPart;
-#else
cep->Length = (afs_int64) scp->length.QuadPart;
-#endif
cep->DataVersion = (afs_uint32)(scp->dataVersion & 0xFFFFFFFF);
cep->callback = afs_data_pointer_to_int32(scp->cbServerp);
if (scp->flags & CM_SCACHEFLAG_PURERO) {
int cm_HaveCallback(cm_scache_t *scp)
{
#ifdef AFS_FREELANCE_CLIENT
- // yj: we handle callbacks specially for callbacks on the root directory
- // Since it's local, we almost always say that we have callback on it
- // The only time we send back a 0 is if we're need to initialize or
- // reinitialize the fake directory
-
- // There are 2 state variables cm_fakeGettingCallback and cm_fakeDirCallback
- // cm_fakeGettingCallback is 1 if we're in the process of initialization and
- // hence should return false. it's 0 otherwise
- // cm_fakeDirCallback is 0 if we haven't loaded the fake directory, it's 1
- // if the fake directory is loaded and this is the first time cm_HaveCallback
- // is called since then. We return false in this case to allow cm_GetCallback
- // to be called because cm_GetCallback has some initialization work to do.
- // If cm_fakeDirCallback is 2, then it means that the fake directory is in
- // good shape and we simply return true, provided no change is detected.
- int fdc, fgc;
-
if (cm_freelanceEnabled &&
- scp->fid.cell==AFS_FAKE_ROOT_CELL_ID && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
- lock_ObtainMutex(&cm_Freelance_Lock);
- fdc = cm_fakeDirCallback;
- fgc = cm_fakeGettingCallback;
- lock_ReleaseMutex(&cm_Freelance_Lock);
-
- if (fdc==1) { // first call since init
- return 0;
- } else if (fdc==2 && !fgc) { // we're in good shape
- if (cm_getLocalMountPointChange()) { // check for changes
- cm_clearLocalMountPointChange(); // clear the changefile
- lock_ReleaseWrite(&scp->rw); // this is re-locked in reInitLocalMountPoints
- cm_reInitLocalMountPoints(); // start reinit
- lock_ObtainWrite(&scp->rw); // now get the lock back
- return 0;
- }
- return (cm_data.fakeDirVersion == scp->dataVersion);
+ scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
+ scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
+ if (cm_getLocalMountPointChange()) {
+ cm_clearLocalMountPointChange();
+ lock_ReleaseWrite(&scp->rw);
+ cm_reInitLocalMountPoints();
+ lock_ObtainWrite(&scp->rw);
}
- return 0;
+ return (cm_data.fakeDirVersion == scp->dataVersion);
}
#endif
- if (scp->flags & CM_SCACHEFLAG_PURERO) {
+ if (cm_readonlyVolumeVersioning &&
+ (scp->flags & CM_SCACHEFLAG_PURERO)) {
cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
if (volp) {
int haveCB = 0;
#ifdef AFS_FREELANCE_CLIENT
// The case where a callback is needed on /afs is handled
// specially. We need to fetch the status by calling
- // cm_MergeStatus and mark that cm_fakeDirCallback is 2
+ // cm_MergeStatus
if (cm_freelanceEnabled &&
(scp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
scp->fid.volume==AFS_FAKE_ROOT_VOL_ID)) {
goto done;
syncop_done = 1;
- if (cm_fakeDirCallback != 2) {
- // Start by indicating that we're in the process
- // of fetching the callback
- lock_ObtainMutex(&cm_Freelance_Lock);
- osi_Log0(afsd_logp,"GetCallback Freelance fakeGettingCallback=1");
- cm_fakeGettingCallback = 1;
- lock_ReleaseMutex(&cm_Freelance_Lock);
-
+ if (scp->dataVersion != cm_data.fakeDirVersion) {
memset(&afsStatus, 0, sizeof(afsStatus));
+ memset(&volSync, 0, sizeof(volSync));
// Fetch the status info
cm_MergeStatus(NULL, scp, &afsStatus, &volSync, userp, reqp, 0);
-
- // Indicate that the callback is not done
- lock_ObtainMutex(&cm_Freelance_Lock);
- osi_Log0(afsd_logp,"GetCallback Freelance fakeDirCallback=2");
- cm_fakeDirCallback = 2;
-
- // Indicate that we're no longer fetching the callback
- osi_Log0(afsd_logp,"GetCallback Freelance fakeGettingCallback=0");
- cm_fakeGettingCallback = 0;
- lock_ReleaseMutex(&cm_Freelance_Lock);
}
goto done;
}
}
-/* called with cm_scacheLock held */
-long cm_CBServersUp(cm_scache_t *scp, time_t * downTime)
+/*
+ * cm_CBServersDownTime() returns 1 if the downTime parameter is valid.
+ *
+ * Servers with multiple interfaces have multiple cm_server_t objects
+ * which share the same UUID. If one interface is down but others are up,
+ * the server should not be considered down. The returned downTime should
+ * be the largest non-zero value if down or zero if up. If the cbServerp
+ * is down, it is updated to refer to an interface that is up (if one exists).
+ *
+ * called with cm_scacheLock held
+ */
+static long
+cm_CBServersDownTime(cm_scache_t *scp, cm_volume_t *volp, time_t * pdownTime)
{
cm_vol_state_t *statep;
- cm_volume_t * volp;
- afs_uint32 volID = scp->fid.volume;
cm_serverRef_t *tsrp;
- int found;
+ int alldown = 1;
+ time_t downTime = 0;
+ cm_server_t * upserver = NULL;
+ cm_server_t * downserver;
- *downTime = 0;
+ *pdownTime = 0;
if (scp->cbServerp == NULL)
return 1;
- volp = cm_GetVolumeByFID(&scp->fid);
- if (!volp)
+ if (!(scp->cbServerp->flags & CM_SERVERFLAG_DOWN))
return 1;
- statep = cm_VolumeStateByID(volp, volID);
- cm_PutVolume(volp);
- if (statep->state == vl_online)
- return 1;
+ statep = cm_VolumeStateByID(volp, scp->fid.volume);
+ if (statep) {
+ for (tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
+ if (tsrp->status == srv_deleted)
+ continue;
- for (found = 0,tsrp = statep->serversp; tsrp; tsrp=tsrp->next) {
- if (tsrp->status == srv_deleted)
- continue;
- if (cm_ServerEqual(tsrp->server, scp->cbServerp))
- found = 1;
- if (tsrp->server->downTime > *downTime)
- *downTime = tsrp->server->downTime;
+ if (!cm_ServerEqual(tsrp->server, scp->cbServerp))
+ continue;
+
+ if (!(tsrp->server->flags & CM_SERVERFLAG_DOWN)) {
+ alldown = 0;
+ if (!upserver) {
+ upserver = tsrp->server;
+ cm_GetServer(upserver);
+ }
+ }
+
+ if (tsrp->server->downTime > downTime)
+ downTime = tsrp->server->downTime;
+ }
+ } else {
+ downTime = scp->cbServerp->downTime;
}
/* if the cbServerp does not match the current volume server list
* we report the callback server as up so the callback can be
* expired.
*/
- return(found ? 0 : 1);
+
+ if (alldown) {
+ *pdownTime = downTime;
+ } else {
+ lock_ObtainWrite(&scp->rw);
+ downserver = scp->cbServerp;
+ scp->cbServerp = upserver;
+ lock_ReleaseWrite(&scp->rw);
+ cm_PutServer(downserver);
+ }
+ return 1;
}
/* called periodically by cm_daemon to shut down use of expired callbacks */
{
afs_uint32 i;
cm_scache_t *scp;
+ cm_volume_t *volp;
+ enum volstatus volstate;
time_t now, downTime;
osi_Log0(afsd_logp, "CheckCBExpiration");
lock_ObtainWrite(&cm_scacheLock);
for (i=0; i<cm_data.scacheHashTableSize; i++) {
for (scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp) {
+ volp = NULL;
+ cm_HoldSCacheNoLock(scp);
+ lock_ReleaseWrite(&cm_scacheLock);
+
+ /*
+ * If this is not a PURERO object and there is no callback
+ * or it hasn't expired, there is nothing to do
+ */
+ if (!(scp->flags & CM_SCACHEFLAG_PURERO) &&
+ (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires))
+ goto scp_complete;
+
+ /*
+ * Determine the volume state and update the callback info
+ * to the latest if it is a PURERO object.
+ */
+ volp = cm_GetVolumeByFID(&scp->fid);
+ volstate = vl_unknown;
downTime = 0;
- if (scp->flags & CM_SCACHEFLAG_PURERO) {
- cm_volume_t *volp = cm_GetVolumeByFID(&scp->fid);
- if (volp) {
- if (volp->cbExpiresRO > scp->cbExpires &&
- scp->cbExpires > 0)
- {
- scp->cbExpires = volp->cbExpiresRO;
- if (volp->cbServerpRO != scp->cbServerp) {
- if (scp->cbServerp)
- cm_PutServer(scp->cbServerp);
- cm_GetServer(volp->cbServerpRO);
- scp->cbServerp = volp->cbServerpRO;
- }
- }
- cm_PutVolume(volp);
+ if (volp) {
+ if ((scp->flags & CM_SCACHEFLAG_PURERO) &&
+ volp->cbExpiresRO > scp->cbExpires && scp->cbExpires > 0)
+ {
+ lock_ObtainWrite(&scp->rw);
+ scp->cbExpires = volp->cbExpiresRO;
+ if (volp->cbServerpRO != scp->cbServerp) {
+ if (scp->cbServerp)
+ cm_PutServer(scp->cbServerp);
+ cm_GetServer(volp->cbServerpRO);
+ scp->cbServerp = volp->cbServerpRO;
+ }
+ lock_ReleaseWrite(&scp->rw);
}
+ volstate = cm_GetVolumeStatus(volp, scp->fid.volume);
}
- if (scp->cbServerp && scp->cbExpires > 0 && now > scp->cbExpires &&
- (cm_CBServersUp(scp, &downTime) || downTime == 0 || downTime >= scp->cbExpires))
- {
- cm_HoldSCacheNoLock(scp);
- lock_ReleaseWrite(&cm_scacheLock);
-
- osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
- scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
- lock_ObtainWrite(&scp->rw);
- cm_DiscardSCache(scp);
- lock_ReleaseWrite(&scp->rw);
- cm_CallbackNotifyChange(scp);
- lock_ObtainWrite(&cm_scacheLock);
- cm_ReleaseSCacheNoLock(scp);
- }
+ /* If there is no callback or it hasn't expired, there is nothing to do */
+ if (scp->cbServerp == NULL || scp->cbExpires == 0 || now < scp->cbExpires)
+ goto scp_complete;
+
+ /* If the volume is known not to be online, do not expire the callback */
+ if (volstate != vl_online)
+ goto scp_complete;
+
+ /*
+ * If all the servers are down and the callback expired after the
+ * issuing server went down, do not expire the callback
+ */
+ if (cm_CBServersDownTime(scp, volp, &downTime) && downTime && downTime < scp->cbExpires)
+ goto scp_complete;
+
+ /* The callback has expired, discard the status info */
+ osi_Log4(afsd_logp, "Callback Expiration Discarding SCache scp 0x%p vol %u vn %u uniq %u",
+ scp, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
+ lock_ObtainWrite(&scp->rw);
+ cm_DiscardSCache(scp);
+ lock_ReleaseWrite(&scp->rw);
+
+ cm_CallbackNotifyChange(scp);
+
+ scp_complete:
+ if (volp)
+ cm_PutVolume(volp);
+
+ lock_ObtainWrite(&cm_scacheLock);
+ cm_ReleaseSCacheNoLock(scp);
}
}
lock_ReleaseWrite(&cm_scacheLock);
lock_ReleaseWrite(&cm_serverLock);
}
+void
+cm_GiveUpAllCallbacksAllServersMulti(afs_int32 markDown)
+{
+ long code;
+ cm_conn_t **conns = NULL;
+ struct rx_connection **rxconns = NULL;
+ afs_int32 i, nconns = 0, maxconns;
+ cm_server_t ** serversp, *tsp;
+ afs_int32 *results;
+ time_t start, *deltas;
+
+ maxconns = cm_numFileServers;
+ if (maxconns == 0)
+ return;
+
+ conns = (cm_conn_t **)malloc(maxconns * sizeof(cm_conn_t *));
+ rxconns = (struct rx_connection **)malloc(maxconns * sizeof(struct rx_connection *));
+ deltas = (time_t *)malloc(maxconns * sizeof (time_t));
+ results = (afs_int32 *)malloc(maxconns * sizeof (afs_int32));
+ serversp = (cm_server_t **)malloc(maxconns * sizeof(cm_server_t *));
+
+ lock_ObtainRead(&cm_serverLock);
+ for (nconns=0, tsp = cm_allServersp; tsp && nconns < maxconns; tsp = tsp->allNextp) {
+ if (tsp->type != CM_SERVER_FILE ||
+ (tsp->flags & CM_SERVERFLAG_DOWN) ||
+ tsp->cellp == NULL /* SetPrefs only */)
+ continue;
+
+ cm_GetServerNoLock(tsp);
+ lock_ReleaseRead(&cm_serverLock);
+
+ serversp[nconns] = tsp;
+ code = cm_ConnByServer(tsp, cm_rootUserp, &conns[nconns]);
+ if (code) {
+ lock_ObtainRead(&cm_serverLock);
+ cm_PutServerNoLock(tsp);
+ continue;
+ }
+ lock_ObtainRead(&cm_serverLock);
+ rxconns[nconns] = cm_GetRxConn(conns[nconns]);
+ rx_SetConnDeadTime(rxconns[nconns], 10);
+
+ nconns++;
+ }
+ lock_ReleaseRead(&cm_serverLock);
+
+ if (nconns) {
+ /* Perform the multi call */
+ start = time(NULL);
+ multi_Rx(rxconns,nconns)
+ {
+ multi_RXAFS_GiveUpAllCallBacks();
+ results[multi_i]=multi_error;
+ } multi_End;
+ }
+
+ /* Process results of servers that support RXAFS_GetCapabilities */
+ for (i=0; i<nconns; i++) {
+ rx_SetConnDeadTime(rxconns[i], ConnDeadtimeout);
+ rx_PutConnection(rxconns[i]);
+ cm_PutConn(conns[i]);
+
+ tsp = serversp[i];
+ cm_GCConnections(tsp);
+
+ if (markDown) {
+ cm_server_vols_t * tsrvp;
+ cm_volume_t * volp;
+ int i;
+
+ cm_ForceNewConnections(tsp);
+
+ lock_ObtainMutex(&tsp->mx);
+ if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
+ tsp->flags |= CM_SERVERFLAG_DOWN;
+ tsp->downTime = time(NULL);
+ }
+ /* Now update the volume status */
+ for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
+ for (i=0; i<NUM_SERVER_VOLS; i++) {
+ if (tsrvp->ids[i] != 0) {
+ cm_req_t req;
+
+ cm_InitReq(&req);
+ lock_ReleaseMutex(&tsp->mx);
+ code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
+ &req, CM_GETVOL_FLAG_NO_LRU_UPDATE | CM_GETVOL_FLAG_NO_RESET, &volp);
+ lock_ObtainMutex(&tsp->mx);
+ if (code == 0) {
+ cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
+ cm_PutVolume(volp);
+ }
+ }
+ }
+ }
+ lock_ReleaseMutex(&tsp->mx);
+ }
+ }
+
+ free(conns);
+ free(rxconns);
+ free(deltas);
+ free(results);
+ free(serversp);
+}
+