/* now go through our percentage of the buffers */
for (bpp = &cm_data.buf_dirtyListp; bp = *bpp; ) {
-
/* all dirty buffers are held when they are added to the
* dirty list. No need for an additional hold.
*/
-
+ lock_ObtainMutex(&bp->mx);
if (bp->flags & CM_BUF_DIRTY) {
/* start cleaning the buffer; don't touch log pages since
* the log code counts on knowing exactly who is writing
*/
cm_InitReq(&req);
req.flags |= CM_REQ_NORETRY;
- wasDirty |= buf_CleanAsync(bp, &req);
+ wasDirty |= buf_CleanAsyncLocked(bp, &req);
}
/* 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.
*/
- if (!(bp->flags & CM_BUF_DIRTY)) {
- lock_ObtainMutex(&bp->mx);
- if (!(bp->flags & CM_BUF_DIRTY)) {
- /* remove the buffer from the dirty list */
- lock_ObtainWrite(&buf_globalLock);
- *bpp = bp->dirtyp;
- bp->dirtyp = NULL;
- if (cm_data.buf_dirtyListp == NULL)
- cm_data.buf_dirtyListEndp = NULL;
- buf_ReleaseLocked(bp, TRUE);
- lock_ReleaseWrite(&buf_globalLock);
- } else {
- /* advance the pointer so we don't loop forever */
- bpp = &bp->dirtyp;
- }
- lock_ReleaseMutex(&bp->mx);
- } else {
- /* advance the pointer so we don't loop forever */
- bpp = &bp->dirtyp;
- }
+ if (!(bp->flags & CM_BUF_DIRTY)) {
+ /* remove the buffer from the dirty list */
+ lock_ObtainWrite(&buf_globalLock);
+ *bpp = bp->dirtyp;
+ bp->dirtyp = NULL;
+ if (cm_data.buf_dirtyListp == NULL)
+ cm_data.buf_dirtyListEndp = NULL;
+ buf_ReleaseLocked(bp, TRUE);
+ lock_ReleaseWrite(&buf_globalLock);
+ } else {
+ /* advance the pointer so we don't loop forever */
+ bpp = &bp->dirtyp;
+ }
+ lock_ReleaseMutex(&bp->mx);
} /* for loop over a bunch of buffers */
} /* whole daemon's while loop */
}
offset = bp->offset;
LargeIntegerAdd(offset, ConvertLongToLargeInteger(bp->dirty_offset));
- code = (*cm_buf_opsp->Writep)(scp, &offset, bp->dirty_length, 0, bp->userp, reqp);
+ 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,
+#else
+ 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);
bp->dirty_offset = 0;
bp->dirty_length = 0;
bp->error = code;
- bp->dataVersion = -1; /* bad */
+ bp->dataVersion = CM_BUF_VERSION_BAD; /* bad */
bp->dirtyCounter++;
}
/* clean up junk flags */
bp->flags &= ~(CM_BUF_EOF | CM_BUF_ERROR);
- bp->dataVersion = -1; /* unknown so far */
+ bp->dataVersion = CM_BUF_VERSION_BAD; /* unknown so far */
/* now hash in as our new buffer, and give it the
* appropriate label, if requested.
}
/* wait for a buffer's cleaning to finish */
-void buf_CleanWait(cm_scache_t * scp, cm_buf_t *bp)
+void buf_CleanWait(cm_scache_t * scp, cm_buf_t *bp, afs_uint32 locked)
{
osi_assertx(bp->magic == CM_BUF_MAGIC, "invalid cm_buf_t magic");
- lock_ObtainMutex(&bp->mx);
+ if (!locked)
+ lock_ObtainMutex(&bp->mx);
if (bp->flags & CM_BUF_WRITING) {
buf_WaitIO(scp, bp);
}
- lock_ReleaseMutex(&bp->mx);
+ if (!locked)
+ lock_ReleaseMutex(&bp->mx);
}
/* set the dirty flag on a buffer, and set associated write-ahead log,
req.flags |= CM_REQ_NORETRY;
buf_CleanAsync(bp, &req);
- buf_CleanWait(NULL, bp);
+ buf_CleanWait(NULL, bp, FALSE);
/* relock and release buffer */
lock_ObtainRead(&buf_globalLock);
bufp->flags &= ~CM_BUF_DIRTY;
bufp->dirty_offset = 0;
bufp->dirty_length = 0;
- bufp->dataVersion = -1; /* known bad */
+ bufp->dataVersion = CM_BUF_VERSION_BAD; /* known bad */
bufp->dirtyCounter++;
}
else {
if (code && code != CM_ERROR_BADFD)
goto skip;
- /* 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;
- bp->error = code;
- bp->dirty_offset = 0;
- bp->dirty_length = 0;
- bp->dataVersion = -1; /* known bad */
- bp->dirtyCounter++;
- lock_ReleaseMutex(&bp->mx);
+ if (code == CM_ERROR_BADFD) {
+ /* 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;
+ 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);
+ }
/* actually, we only know that buffer is clean if ref
* count is 1, since we don't have buffer itself locked.
lock_ReleaseWrite(&buf_globalLock);
}
- if (code != CM_ERROR_BADFD)
+ if (code == 0)
(*cm_buf_opsp->Unstabilizep)(scp, userp);
}
for (; bp; bp = nbp) {
/* clean buffer synchronously */
if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
+ lock_ObtainMutex(&bp->mx);
if (userp) {
cm_HoldUser(userp);
- lock_ObtainMutex(&bp->mx);
if (bp->userp)
cm_ReleaseUser(bp->userp);
bp->userp = userp;
- lock_ReleaseMutex(&bp->mx);
}
- wasDirty = buf_CleanAsync(bp, reqp);
- buf_CleanWait(scp, bp);
- lock_ObtainMutex(&bp->mx);
+ wasDirty = buf_CleanAsyncLocked(bp, reqp);
+ buf_CleanWait(scp, bp, TRUE);
if (bp->flags & CM_BUF_ERROR) {
code = bp->error;
if (code == 0)
bp->dirty_length = 0;
bp->flags |= CM_BUF_ERROR;
bp->error = VNOVNODE;
- bp->dataVersion = -1; /* bad */
+ bp->dataVersion = CM_BUF_VERSION_BAD; /* bad */
bp->dirtyCounter++;
if (bp->flags & CM_BUF_WAITING) {
osi_Log2(buf_logp, "BUF CleanDirtyBuffers Waking [scp 0x%x] bp 0x%x", scp, bp);