From 75297d4439bb30ddd9968805aecf2cc2812bfdf0 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 10 Aug 2011 11:40:35 -0400 Subject: [PATCH] Windows: Interlocked ops for cm_scache Use Interlocked operations for cm_scache flags and mask field changes. Change-Id: Ice87dc5de395b54e7e30e362d2e72caa9062120e Reviewed-on: http://gerrit.openafs.org/5193 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsd/cm_dcache.c | 25 ++++++++------- src/WINNT/afsd/cm_scache.c | 64 ++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/src/WINNT/afsd/cm_dcache.c b/src/WINNT/afsd/cm_dcache.c index 8970477f1..8c003194e 100644 --- a/src/WINNT/afsd/cm_dcache.c +++ b/src/WINNT/afsd/cm_dcache.c @@ -114,13 +114,14 @@ long cm_BufWrite(void *vscp, osi_hyper_t *offsetp, long length, long flags, } /* prepare the output status for the store */ - scp->mask |= CM_SCACHEMASK_CLIENTMODTIME; + _InterlockedOr(&scp->mask, CM_SCACHEMASK_CLIENTMODTIME); cm_StatusFromAttr(&inStatus, scp, NULL); truncPos = scp->length; if ((scp->mask & CM_SCACHEMASK_TRUNCPOS) - && LargeIntegerLessThan(scp->truncPos, truncPos)) + && LargeIntegerLessThan(scp->truncPos, truncPos)) { truncPos = scp->truncPos; - scp->mask &= ~CM_SCACHEMASK_TRUNCPOS; + _InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_TRUNCPOS); + } /* compute how many bytes to write from this buffer */ thyper = LargeIntegerSubtract(scp->length, biod.offset); @@ -380,14 +381,14 @@ long cm_BufWrite(void *vscp, osi_hyper_t *offsetp, long length, long flags, } if (LargeIntegerGreaterThanOrEqualTo(t, scp->length)) - scp->mask &= ~CM_SCACHEMASK_LENGTH; + _InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_LENGTH); cm_MergeStatus(NULL, scp, &outStatus, &volSync, userp, reqp, CM_MERGEFLAG_STOREDATA); } else { if (code == CM_ERROR_SPACE) - scp->flags |= CM_SCACHEFLAG_OUTOFSPACE; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_OUTOFSPACE); else if (code == CM_ERROR_QUOTA) - scp->flags |= CM_SCACHEFLAG_OVERQUOTA; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_OVERQUOTA); } cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL); @@ -427,14 +428,14 @@ long cm_StoreMini(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp) /* prepare the output status for the store */ inStatus.Mask = AFS_SETMODTIME; inStatus.ClientModTime = scp->clientModTime; - scp->mask &= ~CM_SCACHEMASK_CLIENTMODTIME; + _InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_CLIENTMODTIME); /* calculate truncation position */ truncPos = scp->length; if ((scp->mask & CM_SCACHEMASK_TRUNCPOS) && LargeIntegerLessThan(scp->truncPos, truncPos)) truncPos = scp->truncPos; - scp->mask &= ~CM_SCACHEMASK_TRUNCPOS; + _InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_TRUNCPOS); if (LargeIntegerGreaterThan(truncPos, ConvertLongToLargeInteger(LONG_MAX))) { @@ -532,7 +533,7 @@ long cm_StoreMini(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp) } if (LargeIntegerGreaterThanOrEqualTo(t, scp->length)) - scp->mask &= ~CM_SCACHEMASK_LENGTH; + _InterlockedAnd(&scp->mask, ~CM_SCACHEMASK_LENGTH); cm_MergeStatus(NULL, scp, &outStatus, &volSync, userp, reqp, CM_MERGEFLAG_STOREDATA); } cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_STOREDATA_EXCL); @@ -785,7 +786,7 @@ void cm_ClearPrefetchFlag(long code, cm_scache_t *scp, osi_hyper_t *base, osi_hy if (LargeIntegerGreaterThan(end, scp->prefetch.end)) scp->prefetch.end = end; } - scp->flags &= ~CM_SCACHEFLAG_PREFETCHING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_PREFETCHING); } /* do the prefetch. if the prefetch fails, return 0 (success) @@ -923,7 +924,7 @@ void cm_ConsiderPrefetch(cm_scache_t *scp, osi_hyper_t *offsetp, afs_uint32 coun lock_ReleaseWrite(&scp->rw); return; } - scp->flags |= CM_SCACHEFLAG_PREFETCHING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_PREFETCHING); /* start the scan at the latter of the end of this read or * the end of the last fetched region. @@ -934,7 +935,7 @@ void cm_ConsiderPrefetch(cm_scache_t *scp, osi_hyper_t *offsetp, afs_uint32 coun code = cm_CheckFetchRange(scp, &readBase, &readLength, userp, reqp, &realBase); if (code) { - scp->flags &= ~CM_SCACHEFLAG_PREFETCHING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_PREFETCHING); lock_ReleaseWrite(&scp->rw); return; /* can't find something to prefetch */ } diff --git a/src/WINNT/afsd/cm_scache.c b/src/WINNT/afsd/cm_scache.c index d835949a7..d4a8b7ae8 100644 --- a/src/WINNT/afsd/cm_scache.c +++ b/src/WINNT/afsd/cm_scache.c @@ -92,7 +92,7 @@ void cm_RemoveSCacheFromHashTable(cm_scache_t *scp) if (tscp == scp) { *lscpp = scp->nextp; scp->nextp = NULL; - scp->flags &= ~CM_SCACHEFLAG_INHASH; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_INHASH); break; } } @@ -213,13 +213,14 @@ long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags) /* invalidate so next merge works fine; * also initialize some flags */ scp->fileType = 0; - scp->flags &= ~(CM_SCACHEFLAG_STATD + _InterlockedAnd(&scp->flags, + ~(CM_SCACHEFLAG_STATD | CM_SCACHEFLAG_DELETED | CM_SCACHEFLAG_RO | CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_OVERQUOTA | CM_SCACHEFLAG_OUTOFSPACE - | CM_SCACHEFLAG_EACCESS); + | CM_SCACHEFLAG_EACCESS)); scp->serverModTime = 0; scp->dataVersion = CM_SCACHE_VERSION_BAD; scp->bufDataVersionLow = CM_SCACHE_VERSION_BAD; @@ -603,7 +604,8 @@ cm_ShutdownSCache(void) scp->cbServerp = NULL; } scp->cbExpires = 0; - scp->flags &= ~CM_SCACHEFLAG_CALLBACK; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_CALLBACK); + lock_ReleaseWrite(&scp->rw); #ifdef USE_BPLUS if (scp->dirBplus) @@ -661,7 +663,7 @@ void cm_InitSCache(int newFile, long maxSCaches) scp->dirDataVersion = CM_SCACHE_VERSION_BAD; #endif scp->waitQueueT = NULL; - scp->flags &= ~CM_SCACHEFLAG_WAITING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_WAITING); } } cm_allFileLocks = NULL; @@ -797,11 +799,11 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, scp->dotdotFid.volume=AFS_FAKE_ROOT_VOL_ID; scp->dotdotFid.unique=1; scp->dotdotFid.vnode=1; - scp->flags |= (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO); + _InterlockedOr(&scp->flags, (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO)); if (!(scp->flags & CM_SCACHEFLAG_INHASH)) { scp->nextp = cm_data.scacheHashTablep[hash]; cm_data.scacheHashTablep[hash] = scp; - scp->flags |= CM_SCACHEFLAG_INHASH; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH); } scp->refCount = 1; osi_Log1(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%p", scp); @@ -890,11 +892,11 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, * "master" copy is stored (defect 11489) */ if (volp->vol[ROVOL].ID == fidp->volume) { - scp->flags |= (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO); + _InterlockedOr(&scp->flags, (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO)); if (scp->fid.vnode == 1 && scp->fid.unique == 1) scp->dotdotFid = cm_VolumeStateByType(volp, ROVOL)->dotdotFid; } else if (volp->vol[BACKVOL].ID == fidp->volume) { - scp->flags |= CM_SCACHEFLAG_RO; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_RO); if (scp->fid.vnode == 1 && scp->fid.unique == 1) scp->dotdotFid = cm_VolumeStateByType(volp, BACKVOL)->dotdotFid; } else { @@ -906,7 +908,7 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp, cm_PutVolume(volp); scp->nextp = cm_data.scacheHashTablep[hash]; cm_data.scacheHashTablep[hash] = scp; - scp->flags |= CM_SCACHEFLAG_INHASH; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH); lock_ReleaseWrite(&scp->rw); scp->refCount = 1; #ifdef DEBUG_REFCOUNT @@ -1326,7 +1328,7 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *userp, cm_req_t *req scp, scp->waitCount, scp->waitRequests); } else { osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING set for 0x%p", scp); - scp->flags |= CM_SCACHEFLAG_WAITING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_WAITING); scp->waitCount = scp->waitRequests = 1; } @@ -1348,28 +1350,28 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *userp, cm_req_t *req scp, scp->waitCount, scp->waitRequests); if (scp->waitCount == 0) { osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING reset for 0x%p", scp); - scp->flags &= ~CM_SCACHEFLAG_WAITING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_WAITING); scp->waitRequests = 0; } } /* big while loop */ /* now, update the recorded state for RPC-type calls */ if (flags & CM_SCACHESYNC_FETCHSTATUS) - scp->flags |= CM_SCACHEFLAG_FETCHING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_FETCHING); if (flags & CM_SCACHESYNC_STORESTATUS) - scp->flags |= CM_SCACHEFLAG_STORING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_STORING); if (flags & CM_SCACHESYNC_SETSIZE) - scp->flags |= CM_SCACHEFLAG_SIZESETTING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_SIZESETTING); if (flags & CM_SCACHESYNC_STORESIZE) - scp->flags |= CM_SCACHEFLAG_SIZESTORING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_SIZESTORING); if (flags & CM_SCACHESYNC_GETCALLBACK) - scp->flags |= CM_SCACHEFLAG_GETCALLBACK; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_GETCALLBACK); if (flags & CM_SCACHESYNC_STOREDATA_EXCL) - scp->flags |= CM_SCACHEFLAG_DATASTORING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_DATASTORING); if (flags & CM_SCACHESYNC_ASYNCSTORE) - scp->flags |= CM_SCACHEFLAG_ASYNCSTORING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_ASYNCSTORING); if (flags & CM_SCACHESYNC_LOCK) - scp->flags |= CM_SCACHEFLAG_LOCKING; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_LOCKING); /* now update the buffer pointer */ if (bufp && (flags & CM_SCACHESYNC_FETCHDATA)) { @@ -1426,21 +1428,21 @@ void cm_SyncOpDone(cm_scache_t *scp, cm_buf_t *bufp, afs_uint32 flags) /* now, update the recorded state for RPC-type calls */ if (flags & CM_SCACHESYNC_FETCHSTATUS) - scp->flags &= ~CM_SCACHEFLAG_FETCHING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_FETCHING); if (flags & CM_SCACHESYNC_STORESTATUS) - scp->flags &= ~CM_SCACHEFLAG_STORING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_STORING); if (flags & CM_SCACHESYNC_SETSIZE) - scp->flags &= ~CM_SCACHEFLAG_SIZESETTING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_SIZESETTING); if (flags & CM_SCACHESYNC_STORESIZE) - scp->flags &= ~CM_SCACHEFLAG_SIZESTORING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_SIZESTORING); if (flags & CM_SCACHESYNC_GETCALLBACK) - scp->flags &= ~CM_SCACHEFLAG_GETCALLBACK; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_GETCALLBACK); if (flags & CM_SCACHESYNC_STOREDATA_EXCL) - scp->flags &= ~CM_SCACHEFLAG_DATASTORING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_DATASTORING); if (flags & CM_SCACHESYNC_ASYNCSTORE) - scp->flags &= ~CM_SCACHEFLAG_ASYNCSTORING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_ASYNCSTORING); if (flags & CM_SCACHESYNC_LOCK) - scp->flags &= ~CM_SCACHEFLAG_LOCKING; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_LOCKING); /* now update the buffer pointer */ if (bufp && (flags & CM_SCACHESYNC_FETCHDATA)) { @@ -1560,7 +1562,7 @@ void cm_MergeStatus(cm_scache_t *dscp, #endif /* AFS_FREELANCE_CLIENT */ if (statusp->errorCode != 0) { - scp->flags |= CM_SCACHEFLAG_EACCESS; + _InterlockedOr(&scp->flags, CM_SCACHEFLAG_EACCESS); osi_Log2(afsd_logp, "Merge, Failure scp 0x%p code 0x%x", scp, statusp->errorCode); scp->fileType = 0; /* unknown */ @@ -1589,7 +1591,7 @@ void cm_MergeStatus(cm_scache_t *dscp, } goto done; } else { - scp->flags &= ~CM_SCACHEFLAG_EACCESS; + _InterlockedAnd(&scp->flags, ~CM_SCACHEFLAG_EACCESS); } dataVersion = statusp->dataVersionHigh; @@ -1822,7 +1824,7 @@ void cm_DiscardSCache(cm_scache_t *scp) } scp->cbExpires = 0; scp->volumeCreationDate = 0; - scp->flags &= ~(CM_SCACHEFLAG_CALLBACK | CM_SCACHEFLAG_LOCAL); + _InterlockedAnd(&scp->flags, ~(CM_SCACHEFLAG_CALLBACK | CM_SCACHEFLAG_LOCAL)); cm_dnlcPurgedp(scp); cm_dnlcPurgevp(scp); cm_FreeAllACLEnts(scp); -- 2.39.5