From d6092bab7a9e4a07d1a96040b7ec70da47fd5b79 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. Reviewed-on: http://gerrit.openafs.org/5193 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman (cherry picked from commit 75297d4439bb30ddd9968805aecf2cc2812bfdf0) Change-Id: Ic10b726eb5791c7c8d3eb7c3ad529522f627f73c Reviewed-on: http://gerrit.openafs.org/5214 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- 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 9737ebd9f..b7810fca5 100644 --- a/src/WINNT/afsd/cm_dcache.c +++ b/src/WINNT/afsd/cm_dcache.c @@ -110,13 +110,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); @@ -376,14 +377,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); @@ -423,14 +424,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))) { @@ -528,7 +529,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); @@ -781,7 +782,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) @@ -919,7 +920,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. @@ -930,7 +931,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 19d8d9d03..3783710f2 100644 --- a/src/WINNT/afsd/cm_scache.c +++ b/src/WINNT/afsd/cm_scache.c @@ -89,7 +89,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; } } @@ -210,13 +210,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; @@ -598,7 +599,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) @@ -658,7 +660,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; @@ -794,11 +796,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); @@ -887,11 +889,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 { @@ -903,7 +905,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 @@ -1323,7 +1325,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; } @@ -1345,28 +1347,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)) { @@ -1423,21 +1425,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)) { @@ -1557,7 +1559,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 */ @@ -1586,7 +1588,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; @@ -1819,7 +1821,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