/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
/* Copyright (C) 1994 Cazamar Systems, Inc. */
+#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
+
#include <afs/stds.h>
#include <windows.h>
#include <osi.h>
#include <stdio.h>
-#include <assert.h>
#include <strsafe.h>
#include <math.h>
*
* The mutexes in the buffer structures protect the remaining fields in the
* buffers, as well the data itself.
- *
+ *
* The locking hierarchy here is this:
- *
+ *
* - resv multiple simul. buffers reservation
* - lock buffer I/O flags
* - lock buffer's mutex
osi_assertx(refCount >= 0, "cm_buf_t refCount == 0");
#endif
if (refCount == 0) {
- /*
+ /*
* If we are read locked there could be a race condition
* with buf_Find() so we must obtain a write lock and
* double check that the refCount is actually zero
lock_ConvertRToW(&buf_globalLock);
if (bp->refCount == 0 &&
- !(bp->flags & CM_BUF_INLRU)) {
- osi_QAdd((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
-
- /* watch for transition from empty to one element */
- if (!cm_data.buf_freeListEndp)
- cm_data.buf_freeListEndp = cm_data.buf_freeListp;
- bp->flags |= CM_BUF_INLRU;
+ !(bp->qFlags & CM_BUF_QINLRU)) {
+ osi_QAddH( (osi_queue_t **) &cm_data.buf_freeListp,
+ (osi_queue_t **) &cm_data.buf_freeListEndp,
+ &bp->q);
+ _InterlockedOr(&bp->qFlags, CM_BUF_QINLRU);
}
if (!writeLocked)
lock_ConvertWToR(&buf_globalLock);
}
-}
+}
/* release a buffer. Buffer must be referenced, but unlocked. */
#ifdef DEBUG_REFCOUNT
#endif
if (refCount == 0) {
lock_ObtainWrite(&buf_globalLock);
- if (bp->refCount == 0 &&
- !(bp->flags & CM_BUF_INLRU)) {
- osi_QAdd((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
-
- /* watch for transition from empty to one element */
- if (!cm_data.buf_freeListEndp)
- cm_data.buf_freeListEndp = cm_data.buf_freeListp;
- bp->flags |= CM_BUF_INLRU;
+ if (bp->refCount == 0 &&
+ !(bp->qFlags & CM_BUF_QINLRU)) {
+ osi_QAddH( (osi_queue_t **) &cm_data.buf_freeListp,
+ (osi_queue_t **) &cm_data.buf_freeListEndp,
+ &bp->q);
+ _InterlockedOr(&bp->qFlags, CM_BUF_QINLRU);
}
lock_ReleaseWrite(&buf_globalLock);
}
}
-long
-buf_Sync(int quitOnShutdown)
+long
+buf_Sync(int quitOnShutdown)
{
cm_buf_t **bpp, *bp, *prevbp;
afs_uint32 wasDirty = 0;
*/
lock_ObtainMutex(&bp->mx);
- if (bp->flags & CM_BUF_DIRTY && !(bp->flags & CM_BUF_REDIR)) {
+ if (bp->flags & CM_BUF_DIRTY && !(bp->qFlags & CM_BUF_QREDIR)) {
/* start cleaning the buffer; don't touch log pages since
* the log code counts on knowing exactly who is writing
* a log page at any given instant.
case vl_unknown:
cm_InitReq(&req);
req.flags |= CM_REQ_NORETRY;
- buf_CleanAsyncLocked(bp, &req, &dirty);
+ buf_CleanAsyncLocked(NULL, bp, &req, 0, &dirty);
wasDirty |= dirty;
}
cm_PutVolume(volp);
/* the buffer may or may not have been dirty
* and if dirty may or may not have been cleaned
- * successfully. check the dirty flag again.
+ * successfully. check the dirty flag again.
*/
if (!(bp->flags & CM_BUF_DIRTY)) {
/* remove the buffer from the dirty list */
lock_ObtainWrite(&buf_globalLock);
#ifdef DEBUG_REFCOUNT
if (bp->dirtyp == NULL && bp != cm_data.buf_dirtyListEndp) {
- osi_Log1(afsd_logp,"buf_IncrSyncer bp 0x%p list corruption",bp);
- afsi_log("buf_IncrSyncer bp 0x%p list corruption", bp);
+ osi_Log1(afsd_logp,"buf_Sync bp 0x%p list corruption",bp);
+ afsi_log("buf_Sync bp 0x%p list corruption", bp);
}
#endif
*bpp = bp->dirtyp;
bp->dirtyp = NULL;
- bp->flags &= ~CM_BUF_INDL;
+ _InterlockedAnd(&bp->qFlags, ~CM_BUF_QINDL);
if (cm_data.buf_dirtyListp == NULL)
cm_data.buf_dirtyListEndp = NULL;
else if (cm_data.buf_dirtyListEndp == bp)
snprintf(volstr, sizeof(volstr), "%u", bp->fid.volume);
}
- LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_DIRTY_BUFFER_AT_SHUTDOWN,
- cellp->name, volstr, bp->fid.vnode, bp->fid.unique,
+ LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_DIRTY_BUFFER_AT_SHUTDOWN,
+ cellp->name, volstr, bp->fid.vnode, bp->fid.unique,
bp->offset.QuadPart+bp->dirty_offset, bp->dirty_length);
}
long i;
while (buf_ShutdownFlag == 0) {
-
if (!wasDirty) {
i = SleepEx(5000, 1);
- if (i != 0)
+ if (i != 0)
continue;
} else {
Sleep(50);
cm_data.buf_freeListp != NULL && cm_data.buf_freeListEndp == NULL) {
afsi_log("cm_ValidateBuffers failure: inconsistent free list pointers");
fprintf(stderr, "cm_ValidateBuffers failure: inconsistent free list pointers\n");
- return -9;
+ return -9;
}
- for (bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
+ for (bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
if (bp->magic != CM_BUF_MAGIC) {
afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
- return -1;
+ return -1;
}
- countb++;
- bpb = bp;
+ countb++;
+ bpb = bp;
if (countb > cm_data.buf_nbuffers) {
afsi_log("cm_ValidateBuffers failure: countb > cm_data.buf_nbuffers");
fprintf(stderr, "cm_ValidateBuffers failure: countb > cm_data.buf_nbuffers\n");
- return -6;
+ return -6;
}
}
- for (bp = cm_data.buf_freeListp; bp; bp=(cm_buf_t *) osi_QNext(&bp->q)) {
+ for (bp = cm_data.buf_freeListp; bp; bp=(cm_buf_t *) osi_QNext(&bp->q)) {
if (bp->magic != CM_BUF_MAGIC) {
afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
- return -2;
+ return -2;
}
- countf++;
- bpf = bp;
+ countf++;
+ bpf = bp;
if (countf > cm_data.buf_nbuffers) {
afsi_log("cm_ValidateBuffers failure: countf > cm_data.buf_nbuffers");
fprintf(stderr, "cm_ValidateBuffers failure: countf > cm_data.buf_nbuffers\n");
return -7;
}
- }
-
- for (bp = cm_data.buf_allp; bp; bp=bp->allp) {
+ }
+
+ for (bp = cm_data.buf_allp; bp; bp=bp->allp) {
if (bp->magic != CM_BUF_MAGIC) {
afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
- return -3;
+ return -3;
}
- counta++;
- bpa = bp;
+ counta++;
+ bpa = bp;
if (counta > cm_data.buf_nbuffers) {
afsi_log("cm_ValidateBuffers failure: counta > cm_data.buf_nbuffers");
fprintf(stderr, "cm_ValidateBuffers failure: counta > cm_data.buf_nbuffers\n");
- return -8;
+ return -8;
}
- }
-
+ }
+
if (countb != countf) {
afsi_log("cm_ValidateBuffers failure: countb != countf");
fprintf(stderr, "cm_ValidateBuffers failure: countb != countf\n");
- return -4;
+ return -4;
}
-
+
if (counta != cm_data.buf_nbuffers) {
afsi_log("cm_ValidateBuffers failure: counta != cm_data.buf_nbuffers");
fprintf(stderr, "cm_ValidateBuffers failure: counta != cm_data.buf_nbuffers\n");
- return -5;
+ return -5;
}
-
- return 0;
+
+ return 0;
}
-void buf_Shutdown(void)
-{
+void buf_Shutdown(void)
+{
/* disable the buf_IncrSyncer() threads */
buf_ShutdownFlag = 1;
/* then force all dirty buffers to the file servers */
buf_Sync(0);
-}
+}
/* initialize the buffer package; called with no locks
* held during the initialization phase.
char *data;
if ( newFile ) {
- if (nbuffers)
+ if (nbuffers)
cm_data.buf_nbuffers = nbuffers;
/* Have to be able to reserve a whole chunk */
if ( newFile ) {
/* remember this for those who want to reset it */
cm_data.buf_nOrigBuffers = cm_data.buf_nbuffers;
-
+
/* lower hash size to a prime number */
cm_data.buf_hashSize = osi_PrimeLessThan((afs_uint32)(cm_data.buf_nbuffers/7 + 1));
-
+
/* create hash table */
memset((void *)cm_data.buf_scacheHashTablepp, 0, cm_data.buf_hashSize * sizeof(cm_buf_t *));
-
+
/* another hash table */
memset((void *)cm_data.buf_fileHashTablepp, 0, cm_data.buf_hashSize * sizeof(cm_buf_t *));
bp = cm_data.bufHeaderBaseAddress;
data = cm_data.bufDataBaseAddress;
cm_data.buf_allp = NULL;
-
+
for (i=0; i<cm_data.buf_nbuffers; i++) {
- osi_assertx(bp >= cm_data.bufHeaderBaseAddress && bp < (cm_buf_t *)cm_data.bufDataBaseAddress,
+ osi_assertx(bp >= cm_data.bufHeaderBaseAddress && bp < (cm_buf_t *)cm_data.bufDataBaseAddress,
"invalid cm_buf_t address");
osi_assertx(data >= cm_data.bufDataBaseAddress && data < cm_data.bufEndOfData,
"invalid cm_buf_t data address");
-
+
/* allocate and zero some storage */
memset(bp, 0, sizeof(cm_buf_t));
bp->magic = CM_BUF_MAGIC;
/* thread on list of all buffers */
bp->allp = cm_data.buf_allp;
cm_data.buf_allp = bp;
-
- osi_QAdd((osi_queue_t **)&cm_data.buf_freeListp, &bp->q);
- bp->flags |= CM_BUF_INLRU;
+
+ osi_QAddH( (osi_queue_t **) &cm_data.buf_freeListp,
+ (osi_queue_t **) &cm_data.buf_freeListEndp,
+ &bp->q);
+ _InterlockedOr(&bp->qFlags, CM_BUF_QINLRU);
lock_InitializeMutex(&bp->mx, "Buffer mutex", LOCK_HIERARCHY_BUFFER);
-
+
/* grab appropriate number of bytes from aligned zone */
bp->datap = data;
-
- /* setup last buffer pointer */
- if (i == 0)
- cm_data.buf_freeListEndp = bp;
-
+
/* next */
bp++;
data += cm_data.buf_blockSize;
- }
-
+ }
+
/* none reserved at first */
cm_data.buf_reservedBufs = 0;
-
+
/* just for safety's sake */
cm_data.buf_maxReservedBufs = cm_data.buf_nbuffers - 3;
} else {
bp = cm_data.bufHeaderBaseAddress;
data = cm_data.bufDataBaseAddress;
-
+
for (i=0; i<cm_data.buf_nbuffers; i++) {
lock_InitializeMutex(&bp->mx, "Buffer mutex", LOCK_HIERARCHY_BUFFER);
bp->userp = NULL;
bp->waitCount = 0;
bp->waitRequests = 0;
- bp->flags &= ~CM_BUF_WAITING;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_WAITING);
bp++;
- }
+ }
}
-
+
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
{
/* The size of a virtual cache cannot be changed after it has
* been created. Subsequent calls to MapViewofFile() with
- * an existing mapping object name would not allow the
+ * an existing mapping object name would not allow the
* object to be resized. Return failure immediately.
*
* A similar problem now occurs with the persistent cache
nbuffers, cm_data.buf_nbuffers);
return CM_ERROR_INVAL;
-}
+}
/* interface to set the number of buffers to an exact figure.
* Called with no locks held.
*/
long buf_SetNBuffers(afs_uint64 nbuffers)
{
- if (nbuffers < 10)
+ if (nbuffers < 10)
return CM_ERROR_INVAL;
- if (nbuffers == cm_data.buf_nbuffers)
+ if (nbuffers == cm_data.buf_nbuffers)
return 0;
else if (nbuffers > cm_data.buf_nbuffers)
return buf_AddBuffers(nbuffers - cm_data.buf_nbuffers);
- else
+ else
return CM_ERROR_INVAL;
}
/* if no IO is happening, we're done */
if (!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING)))
break;
-
+
/* otherwise I/O is happening, but some other thread is waiting for
* the I/O already. Wait for that guy to figure out what happened,
* and then check again.
osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING already set for 0x%p", bp);
} else {
osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING set for 0x%p", bp);
- bp->flags |= CM_BUF_WAITING;
+ _InterlockedOr(&bp->flags, CM_BUF_WAITING);
bp->waitCount = bp->waitRequests = 1;
}
osi_SleepM((LONG_PTR)bp, &bp->mx);
bp->waitCount--;
if (bp->waitCount == 0) {
osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING reset for 0x%p", bp);
- bp->flags &= ~CM_BUF_WAITING;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_WAITING);
bp->waitRequests = 0;
}
lock_ReleaseRead(&scp->rw);
}
}
-
+
/* if we get here, the IO is done, but we may have to wakeup people waiting for
* the I/O to complete. Do so.
*/
/* find a buffer, if any, for a particular file ID and offset. Assumes
* that buf_globalLock is write locked when called.
*/
-cm_buf_t *buf_FindLocked(struct cm_scache *scp, osi_hyper_t *offsetp)
+cm_buf_t *buf_FindLocked(struct cm_fid *fidp, osi_hyper_t *offsetp)
{
afs_uint32 i;
cm_buf_t *bp;
- i = BUF_HASH(&scp->fid, offsetp);
+ lock_AssertAny(&buf_globalLock);
+
+ i = BUF_HASH(fidp, offsetp);
for(bp = cm_data.buf_scacheHashTablepp[i]; bp; bp=bp->hashp) {
- if (cm_FidCmp(&scp->fid, &bp->fid) == 0
+ if (cm_FidCmp(fidp, &bp->fid) == 0
&& offsetp->LowPart == bp->offset.LowPart
&& offsetp->HighPart == bp->offset.HighPart) {
buf_HoldLocked(bp);
break;
}
}
-
+
/* return whatever we found, if anything */
return bp;
}
/* find a buffer with offset *offsetp for vnode *scp. Called
* with no locks held.
*/
-cm_buf_t *buf_Find(struct cm_scache *scp, osi_hyper_t *offsetp)
+cm_buf_t *buf_Find(struct cm_fid *fidp, osi_hyper_t *offsetp)
{
cm_buf_t *bp;
lock_ObtainRead(&buf_globalLock);
- bp = buf_FindLocked(scp, offsetp);
+ bp = buf_FindLocked(fidp, offsetp);
lock_ReleaseRead(&buf_globalLock);
return bp;
-}
+}
/* find a buffer, if any, for a particular file ID and offset. Assumes
* that buf_globalLock is write locked when called. Uses the all buffer
* list.
*/
-cm_buf_t *buf_FindAllLocked(struct cm_scache *scp, osi_hyper_t *offsetp, afs_uint32 flags)
+cm_buf_t *buf_FindAllLocked(struct cm_fid *fidp, osi_hyper_t *offsetp, afs_uint32 flags)
{
cm_buf_t *bp;
if (flags == 0) {
for(bp = cm_data.buf_allp; bp; bp=bp->allp) {
- if (cm_FidCmp(&scp->fid, &bp->fid) == 0
+ if (cm_FidCmp(fidp, &bp->fid) == 0
&& offsetp->LowPart == bp->offset.LowPart
&& offsetp->HighPart == bp->offset.HighPart) {
buf_HoldLocked(bp);
}
} else {
for(bp = cm_data.buf_allp; bp; bp=bp->allp) {
- if (cm_FidCmp(&scp->fid, &bp->fid) == 0) {
+ if (cm_FidCmp(fidp, &bp->fid) == 0) {
char * fileOffset;
-
+
fileOffset = offsetp->QuadPart + cm_data.baseAddress;
if (fileOffset == bp->datap) {
buf_HoldLocked(bp);
/* find a buffer with offset *offsetp for vnode *scp. Called
* with no locks held. Use the all buffer list.
*/
-cm_buf_t *buf_FindAll(struct cm_scache *scp, osi_hyper_t *offsetp, afs_uint32 flags)
+cm_buf_t *buf_FindAll(struct cm_fid *fidp, osi_hyper_t *offsetp, afs_uint32 flags)
{
cm_buf_t *bp;
lock_ObtainRead(&buf_globalLock);
- bp = buf_FindAllLocked(scp, offsetp, flags);
+ bp = buf_FindAllLocked(fidp, offsetp, flags);
lock_ReleaseRead(&buf_globalLock);
return bp;
-}
+}
/* start cleaning I/O on this buffer. Buffer must be write locked, and is returned
* write-locked.
* if this buffer contains logged data.
*
* Returns non-zero if the buffer was dirty.
+ *
+ * 'scp' may or may not be NULL. If it is not NULL, the FID for both cm_scache_t
+ * and cm_buf_t must match.
*/
-afs_uint32 buf_CleanAsyncLocked(cm_buf_t *bp, cm_req_t *reqp, afs_uint32 *pisdirty)
+afs_uint32 buf_CleanAsyncLocked(cm_scache_t *scp, cm_buf_t *bp, cm_req_t *reqp,
+ afs_uint32 flags, afs_uint32 *pisdirty)
{
afs_uint32 code = 0;
afs_uint32 isdirty = 0;
- cm_scache_t * scp = NULL;
osi_hyper_t offset;
+ int release_scp = 0;
osi_assertx(bp->magic == CM_BUF_MAGIC, "invalid cm_buf_t magic");
+ osi_assertx(scp == NULL || cm_FidCmp(&scp->fid, &bp->fid) == 0, "scp fid != bp fid");
+
+ /*
+ * If the matching cm_scache_t was not provided as a parameter
+ * we must either find one or allocate a new one. It is possible
+ * 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;
+ }
+ }
while ((bp->flags & CM_BUF_DIRTY) == CM_BUF_DIRTY) {
- isdirty = 1;
+ isdirty = 1;
lock_ReleaseMutex(&bp->mx);
- scp = cm_FindSCache(&bp->fid);
- if (scp) {
- osi_Log2(buf_logp, "buf_CleanAsyncLocked starts I/O on scp 0x%p buf 0x%p", scp, bp);
+ if (!scp) {
+ /*
+ * If we didn't find a cm_scache_t object for bp->fid it means
+ * that we no longer have that FID in the cache. It does not
+ * mean that the object does not exist in the cell. That may
+ * in fact be the case but we don't know that until we attempt
+ * a FetchStatus on the FID.
+ */
+ osi_Log1(buf_logp, "buf_CleanAsyncLocked unable to start I/O - scp not found buf 0x%p", bp);
+ code = CM_ERROR_NOSUCHFILE;
+ } else {
+ osi_Log2(buf_logp, "buf_CleanAsyncLocked starts I/O on scp 0x%p buf 0x%p", scp, bp);
offset = bp->offset;
LargeIntegerAdd(offset, ConvertLongToLargeInteger(bp->dirty_offset));
- code = (*cm_buf_opsp->Writep)(scp, &offset,
+ code = (*cm_buf_opsp->Writep)(scp, &offset,
#if 1
- /* we might as well try to write all of the contiguous
- * dirty buffers in one RPC
- */
- cm_chunkSize,
+ /* we might as well try to write all of the contiguous
+ * dirty buffers in one RPC
+ */
+ cm_chunkSize,
#else
- bp->dirty_length,
+ bp->dirty_length,
#endif
- 0, bp->userp, reqp);
- osi_Log3(buf_logp, "buf_CleanAsyncLocked I/O on scp 0x%p buf 0x%p, done=%d", scp, bp, code);
-
- cm_ReleaseSCache(scp);
- scp = NULL;
- } else {
- osi_Log1(buf_logp, "buf_CleanAsyncLocked unable to start I/O - scp not found buf 0x%p", bp);
- code = CM_ERROR_NOSUCHFILE;
- }
-
- lock_ObtainMutex(&bp->mx);
+ flags, bp->userp, reqp);
+ osi_Log3(buf_logp, "buf_CleanAsyncLocked I/O on scp 0x%p buf 0x%p, done=%d", scp, bp, code);
+ }
+ lock_ObtainMutex(&bp->mx);
/* if the Write routine returns No Such File, clear the dirty flag
* because we aren't going to be able to write this data to the file
* server.
*/
- if (code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BADFD || code == CM_ERROR_NOACCESS ||
- code == CM_ERROR_QUOTA || code == CM_ERROR_SPACE || code == CM_ERROR_TOOBIG ||
+ if (code == CM_ERROR_NOSUCHFILE || code == CM_ERROR_BADFD || code == CM_ERROR_NOACCESS ||
+ code == CM_ERROR_QUOTA || code == CM_ERROR_SPACE || code == CM_ERROR_TOOBIG ||
code == CM_ERROR_READONLY || code == CM_ERROR_NOSUCHPATH){
- bp->flags &= ~CM_BUF_DIRTY;
- bp->flags |= CM_BUF_ERROR;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_DIRTY);
+ _InterlockedOr(&bp->flags, CM_BUF_ERROR);
bp->dirty_offset = 0;
bp->dirty_length = 0;
bp->error = code;
diskcache_Update(bp->dcp, bp->datap, cm_data.buf_blockSize, bp->dataVersion);
#endif /* DISKCACHE95 */
- /* if we get here and retries are not permitted
- * then we need to exit this loop regardless of
+ /* if we get here and retries are not permitted
+ * then we need to exit this loop regardless of
* whether or not we were able to clear the dirty bit
*/
if (reqp->flags & CM_REQ_NORETRY)
}
}
+ if (release_scp)
+ cm_ReleaseSCache(scp);
+
/* if someone was waiting for the I/O that just completed or failed,
* wake them up.
*/
"incorrect cm_buf_t flags");
lock_AssertWrite(&buf_globalLock);
- if (bp->flags & CM_BUF_INHASH) {
+ if (bp->qFlags & CM_BUF_QINHASH) {
/* Remove from hash */
i = BUF_HASH(&bp->fid, &bp->offset);
lbpp = &(cm_data.buf_scacheHashTablepp[i]);
- for(tbp = *lbpp; tbp; lbpp = &tbp->hashp, tbp = *lbpp) {
- if (tbp == bp)
+ for(tbp = *lbpp; tbp; lbpp = &tbp->hashp, tbp = tbp->hashp) {
+ if (tbp == bp)
break;
}
if (nextBp)
nextBp->fileHashBackp = prevBp;
- bp->flags &= ~CM_BUF_INHASH;
+ _InterlockedAnd(&bp->qFlags, ~CM_BUF_QINHASH);
}
/* make the fid unrecognizable */
memset(&bp->fid, 0, sizeof(cm_fid_t));
-}
+
+ /* clean up junk flags */
+ _InterlockedAnd(&bp->flags, ~(CM_BUF_EOF | CM_BUF_ERROR));
+ bp->dataVersion = CM_BUF_VERSION_BAD; /* unknown so far */
+}
/* recycle a buffer, removing it from the free list, hashing in its new identity
* and returning it write-locked so that no one can use it. Called without
- * any locks held, and can return an error if it loses the race condition and
+ * any locks held, and can return an error if it loses the race condition and
* finds that someone else created the desired buffer.
*
* If success is returned, the buffer is returned write-locked.
lock_ObtainWrite(&buf_globalLock);
/* check to see if we lost the race */
if (scp) {
- if (bp = buf_FindLocked(scp, offsetp)) {
- /* Do not call buf_ReleaseLocked() because we
+ if (bp = buf_FindLocked(&scp->fid, offsetp)) {
+ /* Do not call buf_ReleaseLocked() because we
* do not want to allow the buffer to be added
* to the free list.
*/
* code can bump refcounts, at least, so it may not be
* zero.
*/
- if (bp->refCount > 0)
+ if (bp->refCount > 0)
continue;
-
+
/* we don't have to lock buffer itself, since the ref
* count is 0 and we know it will stay zero as long as
* we hold the global lock.
*/
/* Don't recycle a buffer held by the redirector. */
- if (bp->flags & CM_BUF_REDIR)
+ if (bp->qFlags & CM_BUF_QREDIR)
continue;
/* don't recycle someone in our own chunk */
*/
continue;
}
-
+
if (bp->flags & CM_BUF_DIRTY) {
/* if the buffer is dirty, start cleaning it and
* move on to the next buffer. We do this with
* have the WRITING flag set, so we won't get
* back here.
*/
- buf_CleanAsync(bp, reqp, NULL);
+ if (cm_FidCmp(&scp->fid, &bp->fid) == 0)
+ buf_CleanAsync(scp, bp, reqp, 0, NULL);
+ else
+ buf_CleanAsync(NULL, bp, reqp, 0, NULL);
/* now put it back and go around again */
buf_Release(bp);
*/
buf_Recycle(bp);
- /* clean up junk flags */
- bp->flags &= ~(CM_BUF_EOF | CM_BUF_ERROR);
- bp->dataVersion = CM_BUF_VERSION_BAD; /* unknown so far */
-
/* now hash in as our new buffer, and give it the
* appropriate label, if requested.
*/
if (scp) {
- bp->flags |= CM_BUF_INHASH;
+ lock_AssertWrite(&buf_globalLock);
+
+ _InterlockedOr(&bp->qFlags, CM_BUF_QINHASH);
bp->fid = scp->fid;
#ifdef DEBUG
bp->scp = scp;
cm_data.buf_fileHashTablepp[i] = bp;
}
- /* we should move it from the lru queue. It better still be there,
+ /* we should remove it from the lru queue. It better still be there,
* since we've held the global (big) lock since we found it there.
*/
- osi_assertx(bp->flags & CM_BUF_INLRU,
+ osi_assertx(bp->qFlags & CM_BUF_QINLRU,
"buf_GetNewLocked: LRU screwup");
- if (cm_data.buf_freeListEndp == bp) {
- /* we're the last guy in this queue, so maintain it */
- cm_data.buf_freeListEndp = (cm_buf_t *) osi_QPrev(&bp->q);
- }
- osi_QRemove((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
- bp->flags &= ~CM_BUF_INLRU;
+ osi_QRemoveHT( (osi_queue_t **) &cm_data.buf_freeListp,
+ (osi_queue_t **) &cm_data.buf_freeListEndp,
+ &bp->q);
+ _InterlockedAnd(&bp->qFlags, ~CM_BUF_QINLRU);
/* prepare to return it. Give it a refcount */
bp->refCount = 1;
afsi_log("%s:%d buf_GetNewLocked bp 0x%p, ref %d", __FILE__, __LINE__, bp, 1);
#endif
/* grab the mutex so that people don't use it
- * before the caller fills it with data. Again, no one
+ * before the caller fills it with data. Again, no one
* should have been able to get to this dude to lock it.
*/
if (!lock_TryMutex(&bp->mx)) {
/* not reached */
} /* the proc */
-/* get a page, returning it held but unlocked. Doesn't fill in the page
- * with I/O, since we're going to write the whole thing new.
+/*
+ * get a page, returning it held but unlocked. the page may or may not
+ * contain valid data.
+ *
+ * The scp must be unlocked when passed in unlocked.
*/
-long buf_GetNew(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf_t **bufpp)
-{
- cm_buf_t *bp;
- long code;
- osi_hyper_t pageOffset;
- int created;
-
- created = 0;
- pageOffset.HighPart = offsetp->HighPart;
- pageOffset.LowPart = offsetp->LowPart & ~(cm_data.buf_blockSize-1);
- while (1) {
- bp = buf_Find(scp, &pageOffset);
- if (bp) {
- /* lock it and break out */
- lock_ObtainMutex(&bp->mx);
- break;
- }
-
- /* otherwise, we have to create a page */
- code = buf_GetNewLocked(scp, &pageOffset, reqp, &bp);
-
- /* check if the buffer was created in a race condition branch.
- * If so, go around so we can hold a reference to it.
- */
- if (code == CM_BUF_EXISTS)
- continue;
-
- /* something else went wrong */
- if (code != 0)
- return code;
-
- /* otherwise, we have a locked buffer that we just created */
- created = 1;
- break;
- } /* big while loop */
-
- /* wait for reads */
- if (bp->flags & CM_BUF_READING)
- buf_WaitIO(scp, bp);
-
- /* once it has been read once, we can unlock it and return it, still
- * with its refcount held.
- */
- lock_ReleaseMutex(&bp->mx);
- *bufpp = bp;
- osi_Log4(buf_logp, "buf_GetNew returning bp 0x%p for scp 0x%p, offset 0x%x:%08x",
- bp, scp, offsetp->HighPart, offsetp->LowPart);
- return 0;
-}
-
-/* get a page, returning it held but unlocked. Make sure it is complete */
-/* The scp must be unlocked when passed to this function */
long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf_t **bufpp)
{
cm_buf_t *bp;
created = 0;
pageOffset.HighPart = offsetp->HighPart;
pageOffset.LowPart = offsetp->LowPart & ~(cm_data.buf_blockSize-1);
- while (1) {
+ while (!created) {
lcount++;
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
- bp = buf_Find(scp, &pageOffset);
+ bp = buf_Find(&scp->fid, &pageOffset);
if (bp) {
/* lock it and break out */
lock_ObtainMutex(&bp->mx);
/* otherwise, we have to create a page */
code = buf_GetNewLocked(scp, &pageOffset, reqp, &bp);
- /* bp->mx is now held */
-
- /* check if the buffer was created in a race condition branch.
- * If so, go around so we can hold a reference to it.
- */
- if (code == CM_BUF_EXISTS)
- continue;
-
- /* something else went wrong */
- if (code != 0) {
+ switch (code) {
+ case 0:
+ /* the requested buffer was created */
+ created = 1;
+ break;
+ case CM_BUF_EXISTS:
+ /*
+ * the requested buffer existed by the time the
+ * scp->bufCreateLock and buf_globalLock could be obtained.
+ * loop again and permit buf_Find() to obtain a reference.
+ */
+ break;
+ default:
+ /*
+ * the requested buffer could not be created.
+ * return the error to the caller.
+ */
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
return code;
}
-
- /* otherwise, we have a locked buffer that we just created */
- created = 1;
- break;
} /* big while loop */
/* if we get here, we have a locked buffer that may have just been
/* load the page; freshly created pages should be idle */
osi_assertx(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING)), "incorrect cm_buf_t flags");
- /* start the I/O; may drop lock */
- bp->flags |= CM_BUF_READING;
+ /*
+ * start the I/O; may drop lock. as of this writing, the only
+ * implementation of Readp is cm_BufRead() which simply sets
+ * tcount to 0 and returns success.
+ */
+ _InterlockedOr(&bp->flags, CM_BUF_READING);
code = (*cm_buf_opsp->Readp)(bp, cm_data.buf_blockSize, &tcount, NULL);
#ifdef DISKCACHE95
/* failure or queued */
if (code != ERROR_IO_PENDING) {
bp->error = code;
- bp->flags |= CM_BUF_ERROR;
- bp->flags &= ~CM_BUF_READING;
+ _InterlockedOr(&bp->flags, CM_BUF_ERROR);
+ _InterlockedAnd(&bp->flags, ~CM_BUF_READING);
if (bp->flags & CM_BUF_WAITING) {
osi_Log1(buf_logp, "buf_Get Waking bp 0x%p", bp);
osi_Wakeup((LONG_PTR) bp);
return code;
}
} else {
- /* otherwise, I/O completed instantly and we're done, except
+ /*
+ * otherwise, I/O completed instantly and we're done, except
* for padding the xfr out with 0s and checking for EOF
*/
if (tcount < (unsigned long) cm_data.buf_blockSize) {
memset(bp->datap+tcount, 0, cm_data.buf_blockSize - tcount);
if (tcount == 0)
- bp->flags |= CM_BUF_EOF;
+ _InterlockedOr(&bp->flags, CM_BUF_EOF);
}
- bp->flags &= ~CM_BUF_READING;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_READING);
if (bp->flags & CM_BUF_WAITING) {
osi_Log1(buf_logp, "buf_Get Waking bp 0x%p", bp);
osi_Wakeup((LONG_PTR) bp);
}
}
-
} /* if created */
/* wait for reads, either that which we started above, or that someone
* being recycled) when we're done in buf_Release.
*/
lock_ObtainWrite(&buf_globalLock);
- if (bp->flags & CM_BUF_INLRU) {
- if (cm_data.buf_freeListEndp == bp)
- cm_data.buf_freeListEndp = (cm_buf_t *) osi_QPrev(&bp->q);
- osi_QRemove((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
- bp->flags &= ~CM_BUF_INLRU;
+ if (bp->qFlags & CM_BUF_QINLRU) {
+ osi_QRemoveHT( (osi_queue_t **) &cm_data.buf_freeListp,
+ (osi_queue_t **) &cm_data.buf_freeListEndp,
+ &bp->q);
+ _InterlockedAnd(&bp->qFlags, ~CM_BUF_QINLRU);
}
lock_ReleaseWrite(&buf_globalLock);
* has been invalidate (by having its DV stomped upon), then
* count it as free, since it isn't really being utilized.
*/
- if (!(bufp->flags & CM_BUF_INHASH) || bufp->dataVersion == CM_BUF_VERSION_BAD)
+ if (!(bufp->qFlags & CM_BUF_QINHASH) || bufp->dataVersion == CM_BUF_VERSION_BAD)
count++;
- }
+ }
lock_ReleaseRead(&buf_globalLock);
return count;
}
/* clean a buffer synchronously */
-afs_uint32 buf_CleanAsync(cm_buf_t *bp, cm_req_t *reqp, afs_uint32 *pisdirty)
+afs_uint32 buf_CleanAsync(cm_scache_t *scp, cm_buf_t *bp, cm_req_t *reqp, afs_uint32 flags, afs_uint32 *pisdirty)
{
long code;
osi_assertx(bp->magic == CM_BUF_MAGIC, "invalid cm_buf_t magic");
+ osi_assertx(!(flags & CM_BUF_WRITE_SCP_LOCKED), "scp->rw must not be held when calling buf_CleanAsync");
lock_ObtainMutex(&bp->mx);
- code = buf_CleanAsyncLocked(bp, reqp, pisdirty);
+ code = buf_CleanAsyncLocked(scp, bp, reqp, flags, pisdirty);
lock_ReleaseMutex(&bp->mx);
return code;
-}
+}
/* wait for a buffer's cleaning to finish */
void buf_CleanWait(cm_scache_t * scp, cm_buf_t *bp, afs_uint32 locked)
}
if (!locked)
lock_ReleaseMutex(&bp->mx);
-}
+}
/* set the dirty flag on a buffer, and set associated write-ahead log,
* if there is one. Allow one to be added to a buffer, but not changed.
*
* The buffer must be locked before calling this routine.
*/
-void buf_SetDirty(cm_buf_t *bp, afs_uint32 offset, afs_uint32 length, cm_user_t *userp)
+void buf_SetDirty(cm_buf_t *bp, cm_req_t *reqp, afs_uint32 offset, afs_uint32 length, cm_user_t *userp)
{
osi_assertx(bp->magic == CM_BUF_MAGIC, "invalid cm_buf_t magic");
osi_assertx(bp->refCount > 0, "cm_buf_t refcount 0");
+ if (length == 0)
+ return;
+
if (bp->flags & CM_BUF_DIRTY) {
osi_Log1(buf_logp, "buf_SetDirty 0x%p already dirty", bp);
osi_Log1(buf_logp, "buf_SetDirty 0x%p", bp);
/* set dirty bit */
- bp->flags |= CM_BUF_DIRTY;
+ _InterlockedOr(&bp->flags, CM_BUF_DIRTY);
/* and turn off EOF flag, since it has associated data now */
- bp->flags &= ~CM_BUF_EOF;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_EOF);
bp->dirty_offset = offset;
bp->dirty_length = length;
- /* and add to the dirty list.
- * we obtain a hold on the buffer for as long as it remains
- * in the list. buffers are only removed from the list by
+ /* and add to the dirty list.
+ * we obtain a hold on the buffer for as long as it remains
+ * in the list. buffers are only removed from the list by
* the buf_IncrSyncer function regardless of when else the
* dirty flag might be cleared.
*
* This should never happen but just in case there is a bug
- * elsewhere, never add to the dirty list if the buffer is
+ * elsewhere, never add to the dirty list if the buffer is
* already there.
*/
lock_ObtainWrite(&buf_globalLock);
- if (!(bp->flags & CM_BUF_INDL)) {
+ if (!(bp->qFlags & CM_BUF_QINDL)) {
buf_HoldLocked(bp);
if (!cm_data.buf_dirtyListp) {
cm_data.buf_dirtyListp = cm_data.buf_dirtyListEndp = bp;
cm_data.buf_dirtyListEndp = bp;
}
bp->dirtyp = NULL;
- bp->flags |= CM_BUF_INDL;
+ _InterlockedOr(&bp->qFlags, CM_BUF_QINDL);
}
lock_ReleaseWrite(&buf_globalLock);
}
/* and record the last writer */
if (bp->userp != userp) {
cm_HoldUser(userp);
- if (bp->userp)
+ if (bp->userp)
cm_ReleaseUser(bp->userp);
bp->userp = userp;
}
cm_InitReq(&req);
req.flags |= CM_REQ_NORETRY;
- buf_CleanAsync(bp, &req, NULL);
+ buf_CleanAsync(NULL, bp, &req, 0, NULL);
buf_CleanWait(NULL, bp, FALSE);
/* relock and release buffer */
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
-
+
/* and we're done */
return 0;
-}
+}
/* called without global lock being held, reserves buffers for callers
* that need more than one held (not locked) at once.
}
lock_ReleaseWrite(&buf_globalLock);
return code;
-}
+}
/* called without global lock held, releases reservation held by
* buf_ReserveBuffers.
osi_Wakeup((LONG_PTR) &cm_data.buf_reservedBufs);
}
lock_ReleaseWrite(&buf_globalLock);
-}
+}
/* truncate the buffers past sizep, zeroing out the page, if we don't
* end on a page boundary.
buf_WaitIO(scp, bufp);
}
lock_ObtainWrite(&scp->rw);
-
+
/* make sure we have a callback (so we have the right value for
* the length), and wait for it to be safe to do a truncate.
*/
| CM_SCACHESYNC_SETSIZE
| CM_SCACHESYNC_BUFLOCKED);
-
+
/* if we succeeded in our locking, and this applies to the right
* file, and the truncate request overlaps the buffer either
* totally or partially, then do something.
*/
if (LargeIntegerLessThanOrEqualTo(*sizep, bufp->offset)) {
/* truncating the entire page */
- bufp->flags &= ~CM_BUF_DIRTY;
+ _InterlockedAnd(&bufp->flags, ~CM_BUF_DIRTY);
bufp->dirty_offset = 0;
bufp->dirty_length = 0;
bufp->dataVersion = CM_BUF_VERSION_BAD; /* known bad */
cm_data.buf_blockSize - bufferPos);
}
}
-
- cm_SyncOpDone( scp, bufp,
+
+ cm_SyncOpDone( scp, bufp,
CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS
| CM_SCACHESYNC_SETSIZE | CM_SCACHESYNC_BUFLOCKED);
lock_ReleaseWrite(&scp->rw);
lock_ReleaseMutex(&bufp->mx);
-
+
if (!code) {
nbufp = bufp->fileHashp;
- if (nbufp)
+ if (nbufp)
buf_Hold(nbufp);
} else {
/* This forces the loop to end and the error code
cm_buf_t *nbp;
int didRelease;
afs_uint32 i;
+ afs_uint32 stable = 0;
i = BUF_FILEHASH(&scp->fid);
code = 0;
lock_ObtainRead(&buf_globalLock);
bp = cm_data.buf_fileHashTablepp[i];
- if (bp)
+ if (bp)
buf_HoldLocked(bp);
lock_ReleaseRead(&buf_globalLock);
-
+
for (; bp; bp = nbp) {
didRelease = 0; /* haven't released this buffer yet */
/* clean buffer synchronously */
if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
- lock_ObtainMutex(&bp->mx);
-
- /* start cleaning the buffer, and wait for it to finish */
- buf_CleanAsyncLocked(bp, reqp, NULL);
- buf_WaitIO(scp, bp);
- lock_ReleaseMutex(&bp->mx);
- /*
- * if the error for the previous buffer was BADFD
- * then all buffers for the FID are bad. Do not
- * attempt to stabalize.
- */
- if (code != CM_ERROR_BADFD) {
+ if (code == 0 && !stable && (bp->flags & CM_BUF_DIRTY)) {
+ /*
+ * we must stabilize the object to ensure that buffer
+ * changes cannot occur while the flush is performed.
+ * However, we do not want to Stabilize if we do not
+ * need to because Stabilize obtains a callback.
+ */
code = (*cm_buf_opsp->Stabilizep)(scp, userp, reqp);
- if (code && code != CM_ERROR_BADFD)
- goto skip;
+ stable = (code == 0);
}
+
if (code == CM_ERROR_BADFD) {
- /* if the scp's FID is bad its because we received VNOVNODE
+ /* if the scp's FID is bad its because we received VNOVNODE
* when attempting to FetchStatus before the write. This
* page therefore contains data that can no longer be stored.
*/
lock_ObtainMutex(&bp->mx);
- bp->flags &= ~CM_BUF_DIRTY;
- bp->flags |= CM_BUF_ERROR;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_DIRTY);
+ _InterlockedOr(&bp->flags, CM_BUF_ERROR);
bp->error = CM_ERROR_BADFD;
bp->dirty_offset = 0;
bp->dirty_length = 0;
bp->dataVersion = CM_BUF_VERSION_BAD; /* known bad */
bp->dirtyCounter++;
lock_ReleaseMutex(&bp->mx);
+ } else if (!(scp->flags & CM_SCACHEFLAG_RO)) {
+ if (code) {
+ goto skip;
+ }
+
+ lock_ObtainMutex(&bp->mx);
+
+ /* start cleaning the buffer, and wait for it to finish */
+ buf_CleanAsyncLocked(scp, bp, reqp, 0, NULL);
+ buf_WaitIO(scp, bp);
+
+ lock_ReleaseMutex(&bp->mx);
}
/* actually, we only know that buffer is clean if ref
lock_ObtainWrite(&buf_globalLock);
if (bp->refCount == 1) { /* bp is held above */
nbp = bp->fileHashp;
- if (nbp)
+ if (nbp)
buf_HoldLocked(nbp);
buf_ReleaseLocked(bp, TRUE);
didRelease = 1;
}
lock_ReleaseWrite(&buf_globalLock);
}
-
- if (code == 0)
- (*cm_buf_opsp->Unstabilizep)(scp, userp);
}
skip:
}
} /* for loop over a bunch of buffers */
+ if (stable)
+ (*cm_buf_opsp->Unstabilizep)(scp, userp);
+
#ifdef TESTING
buf_ValidateBufQueues();
#endif /* TESTING */
/* done */
return code;
-}
+}
/* Must be called with scp->rw held */
long buf_ForceDataVersion(cm_scache_t * scp, afs_uint64 fromVersion, afs_uint64 toVersion)
lock_ObtainRead(&buf_globalLock);
bp = cm_data.buf_fileHashTablepp[i];
- if (bp)
+ if (bp)
buf_HoldLocked(bp);
lock_ReleaseRead(&buf_globalLock);
for (; bp; bp = nbp) {
if (bp->flags & CM_BUF_DIRTY) {
if (userp && userp != bp->userp) {
cm_HoldUser(userp);
- if (bp->userp)
+ if (bp->userp)
cm_ReleaseUser(bp->userp);
bp->userp = userp;
- }
+ }
switch (code) {
case CM_ERROR_NOSUCHFILE:
case CM_ERROR_TOOBIG:
case CM_ERROR_READONLY:
case CM_ERROR_NOSUCHPATH:
- /*
+ /*
* Apply the previous fatal error to this buffer.
* Do not waste the time attempting to store to
* the file server when we know it will fail.
*/
- bp->flags &= ~CM_BUF_DIRTY;
- bp->flags |= CM_BUF_ERROR;
+ _InterlockedAnd(&bp->flags, ~CM_BUF_DIRTY);
+ _InterlockedOr(&bp->flags, CM_BUF_ERROR);
bp->dirty_offset = 0;
bp->dirty_length = 0;
bp->error = code;
*/
break;
default:
- code = buf_CleanAsyncLocked(bp, reqp, &wasDirty);
+ code = buf_CleanAsyncLocked(scp, bp, reqp, 0, &wasDirty);
if (bp->flags & CM_BUF_ERROR) {
code = bp->error;
if (code == 0)
lock_ObtainRead(&buf_globalLock);
nbp = bp->fileHashp;
- if (nbp)
+ if (nbp)
buf_HoldLocked(nbp);
buf_ReleaseLocked(bp, FALSE);
lock_ReleaseRead(&buf_globalLock);
cm_buf_t *bp;
char output[1024];
afs_uint32 i;
-
+
if (cm_data.buf_scacheHashTablepp == NULL)
return -1;
if (lock)
lock_ObtainRead(&buf_globalLock);
-
- StringCbPrintfA(output, sizeof(output), "%s - dumping buf_HashTable - buf_hashSize=%d\r\n",
+
+ StringCbPrintfA(output, sizeof(output), "%s - dumping buf_HashTable - buf_hashSize=%d\r\n",
cookie, cm_data.buf_hashSize);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-
+
for (i = 0; i < cm_data.buf_hashSize; i++)
{
- for (bp = cm_data.buf_scacheHashTablepp[i]; bp; bp=bp->hashp)
+ for (bp = cm_data.buf_scacheHashTablepp[i]; bp; bp=bp->hashp)
{
- StringCbPrintfA(output, sizeof(output),
+ StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, hash=%d, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), offset=%x:%08x, dv=%I64d, "
- "flags=0x%x, cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
- cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume,
- bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
- bp->offset.LowPart, bp->dataVersion, bp->flags,
+ "flags=0x%x, qFlags=0x%x cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
+ cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume,
+ bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
+ bp->offset.LowPart, bp->dataVersion, bp->flags, bp->qFlags,
bp->cmFlags, bp->error, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
}
-
+
StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_HashTable.\r\n", cookie);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
StringCbPrintfA(output, sizeof(output), "%s - dumping buf_freeListEndp\r\n", cookie);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for(bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
- StringCbPrintfA(output, sizeof(output),
+ StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), offset=%x:%08x, dv=%I64d, "
- "flags=0x%x, cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
- cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
- bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
- bp->offset.LowPart, bp->dataVersion, bp->flags,
+ "flags=0x%x, qFlags=0x%x, cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
+ cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
+ bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
+ bp->offset.LowPart, bp->dataVersion, bp->flags, bp->qFlags,
bp->cmFlags, bp->error, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
StringCbPrintfA(output, sizeof(output), "%s - dumping buf_dirtyListp\r\n", cookie);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
for(bp = cm_data.buf_dirtyListp; bp; bp=bp->dirtyp) {
- StringCbPrintfA(output, sizeof(output),
+ StringCbPrintfA(output, sizeof(output),
"%s bp=0x%08X, fid (cell=%d, volume=%d, "
"vnode=%d, unique=%d), offset=%x:%08x, dv=%I64d, "
- "flags=0x%x, cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
- cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
- bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
- bp->offset.LowPart, bp->dataVersion, bp->flags,
+ "flags=0x%x, qFlags=0x%x, cmFlags=0x%x, error=0x%x, refCount=%d\r\n",
+ cookie, (void *)bp, bp->fid.cell, bp->fid.volume,
+ bp->fid.vnode, bp->fid.unique, bp->offset.HighPart,
+ bp->offset.LowPart, bp->dataVersion, bp->flags, bp->qFlags,
bp->cmFlags, bp->error, bp->refCount);
WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
}
int len;
char buf[256];
- if (!buf_logp)
+ if (!buf_logp)
return;
len = GetTempPath(sizeof(buf)-10, buf);
if (!cm_FidCmp(fidp, &bp->fid) && (bp->flags & CM_BUF_DIRTY)) {
buf_Hold(bp);
lock_ObtainMutex(&bp->mx);
- bp->cmFlags &= ~CM_BUF_CMSTORING;
- bp->flags &= ~CM_BUF_DIRTY;
+ _InterlockedAnd(&bp->cmFlags, ~CM_BUF_CMSTORING);
+ _InterlockedAnd(&bp->flags, ~CM_BUF_DIRTY);
bp->dirty_offset = 0;
bp->dirty_length = 0;
- bp->flags |= CM_BUF_ERROR;
+ _InterlockedOr(&bp->flags, CM_BUF_ERROR);
bp->error = VNOVNODE;
bp->dataVersion = CM_BUF_VERSION_BAD; /* bad */
bp->dirtyCounter++;