void buf_Release(cm_buf_t *bp)
#endif
{
- afs_int32 refCount;
-
- /* ensure that we're in the LRU queue if our ref count is 0 */
- osi_assertx(bp->magic == CM_BUF_MAGIC,"incorrect cm_buf_t magic");
-
- refCount = InterlockedDecrement(&bp->refCount);
-#ifdef DEBUG_REFCOUNT
- osi_Log2(afsd_logp,"buf_Release bp 0x%p ref %d", bp, refCount);
- afsi_log("%s:%d buf_ReleaseLocked bp 0x%p, ref %d", file, line, bp, refCount);
-#endif
-#ifdef DEBUG
- if (refCount < 0)
- osi_panic("buf refcount 0",__FILE__,__LINE__);;
-#else
- osi_assertx(refCount >= 0, "cm_buf_t refCount == 0");
-#endif
- if (refCount == 0) {
- lock_ObtainWrite(&buf_globalLock);
- if (bp->refCount == 0 &&
- !(bp->qFlags & (CM_BUF_QINLRU|CM_BUF_QREDIR))) {
- osi_QAddH( (osi_queue_t **) &cm_data.buf_freeListp,
- (osi_queue_t **) &cm_data.buf_freeListEndp,
- &bp->q);
- _InterlockedOr(&bp->qFlags, CM_BUF_QINLRU);
- buf_IncrementFreeCount();
- }
- lock_ReleaseWrite(&buf_globalLock);
- }
+ lock_ObtainRead(&buf_globalLock);
+ buf_ReleaseLocked(bp, FALSE);
+ lock_ReleaseRead(&buf_globalLock);
}
long
bp = cm_data.bufHeaderBaseAddress;
data = cm_data.bufDataBaseAddress;
+ lock_ObtainWrite(&buf_globalLock);
for (i=0; i<cm_data.buf_nbuffers; i++) {
lock_InitializeMutex(&bp->mx, "Buffer mutex", LOCK_HIERARCHY_BUFFER);
bp->userp = NULL;
* extent was not returned by the file system driver.
* clean up the mess.
*/
+ buf_RemoveFromRedirQueue(NULL, bp);
bp->dataVersion = CM_BUF_VERSION_BAD;
- _InterlockedAnd(&bp->qFlags, ~CM_BUF_QREDIR);
- osi_QRemoveHT( (osi_queue_t **) &cm_data.buf_redirListp,
- (osi_queue_t **) &cm_data.buf_redirListEndp,
- &bp->q);
- buf_DecrementRedirCount();
bp->redirq.nextp = bp->redirq.prevp = NULL;
bp->redirLastAccess = 0;
bp->redirReleaseRequested = 0;
- buf_Release(bp);
+ buf_ReleaseLocked(bp, TRUE);
}
bp++;
}
* extent was not returned by the file system driver.
* clean up the mess.
*/
+ buf_RemoveFromRedirQueue(NULL, bp);
bp->dataVersion = CM_BUF_VERSION_BAD;
- _InterlockedAnd(&bp->qFlags, ~CM_BUF_QREDIR);
- osi_QRemoveHT( (osi_queue_t **) &cm_data.buf_redirListp,
- (osi_queue_t **) &cm_data.buf_redirListEndp,
- &bp->q);
- buf_DecrementRedirCount();
bp->redirq.nextp = bp->redirq.prevp = NULL;
bp->redirLastAccess = 0;
bp->redirReleaseRequested = 0;
- buf_Release(bp);
+ buf_ReleaseLocked(bp, TRUE);
}
+ lock_ReleaseWrite(&buf_globalLock);
}
#ifdef TESTING
* that the cm_scache_t was recycled out of the cache even though
* a cm_buf_t with the same FID is in the cache.
*/
- if (scp == NULL) {
- if ((scp = cm_FindSCache(&bp->fid)) ||
- (cm_GetSCache(&bp->fid, &scp,
- bp->userp ? bp->userp : cm_rootUserp,
- reqp) == 0)) {
- release_scp = 1;
- }
+ if (scp == NULL &&
+ cm_GetSCache(&bp->fid, NULL, &scp,
+ bp->userp ? bp->userp : cm_rootUserp,
+ reqp) == 0)
+ {
+ release_scp = 1;
}
while ((bp->flags & CM_BUF_DIRTY) == CM_BUF_DIRTY) {
}
/* Must be called with scp->rw held */
+long buf_InvalidateBuffers(cm_scache_t * scp)
+{
+ cm_buf_t * bp;
+ afs_uint32 i;
+ int found = 0;
+
+ lock_AssertAny(&scp->rw);
+
+ i = BUF_FILEHASH(&scp->fid);
+
+ lock_ObtainRead(&buf_globalLock);
+
+ for (bp = cm_data.buf_fileHashTablepp[i]; bp; bp = bp->fileHashp) {
+ if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
+ bp->dataVersion = CM_BUF_VERSION_BAD;
+ found = 1;
+ }
+ }
+ lock_ReleaseRead(&buf_globalLock);
+
+ if (found)
+ return 0;
+ else
+ return ENOENT;
+}
+
+/* Must be called with scp->rw held */
long buf_ForceDataVersion(cm_scache_t * scp, afs_uint64 fromVersion, afs_uint64 toVersion)
{
cm_buf_t * bp;