2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
12 #include <afs/param.h>
23 #include "cm_memmap.h"
26 #define TRACE_BUFFER 1
29 extern void afsi_log(char *pattern, ...);
31 /* This module implements the buffer package used by the local transaction
32 * system (cm). It is initialized by calling cm_Init, which calls buf_Init;
33 * it must be initalized before any of its main routines are called.
35 * Each buffer is hashed into a hash table by file ID and offset, and if its
36 * reference count is zero, it is also in a free list.
38 * There are two locks involved in buffer processing. The global lock
39 * buf_globalLock protects all of the global variables defined in this module,
40 * the reference counts and hash pointers in the actual cm_buf_t structures,
41 * and the LRU queue pointers in the buffer structures.
43 * The mutexes in the buffer structures protect the remaining fields in the
44 * buffers, as well the data itself.
46 * The locking hierarchy here is this:
48 * - resv multiple simul. buffers reservation
49 * - lock buffer I/O flags
50 * - lock buffer's mutex
51 * - lock buf_globalLock
55 /* global debugging log */
56 osi_log_t *buf_logp = NULL;
58 /* Global lock protecting hash tables and free lists */
59 osi_rwlock_t buf_globalLock;
61 /* ptr to head of the free list (most recently used) and the
62 * tail (the guy to remove first). We use osi_Q* functions
63 * to put stuff in buf_freeListp, and maintain the end
67 /* a pointer to a list of all buffers, just so that we can find them
68 * easily for debugging, and for the incr syncer. Locked under
72 /* defaults setup; these variables may be manually assigned into
73 * before calling cm_Init, as a way of changing these defaults.
76 /* callouts for reading and writing data, etc */
77 cm_buf_ops_t *cm_buf_opsp;
80 /* for experimental disk caching support in Win95 client */
81 cm_buf_t *buf_diskFreeListp;
82 cm_buf_t *buf_diskFreeListEndp;
83 cm_buf_t *buf_diskAllp;
84 extern int cm_diskCacheEnabled;
85 #endif /* DISKCACHE95 */
87 /* set this to 1 when we are terminating to prevent access attempts */
88 static int buf_ShutdownFlag = 0;
90 void buf_HoldLocked(cm_buf_t *bp)
92 osi_assert(bp->magic == CM_BUF_MAGIC);
96 /* hold a reference to an already held buffer */
97 void buf_Hold(cm_buf_t *bp)
99 lock_ObtainWrite(&buf_globalLock);
101 lock_ReleaseWrite(&buf_globalLock);
104 /* code to drop reference count while holding buf_globalLock */
105 void buf_ReleaseLocked(cm_buf_t *bp)
107 /* ensure that we're in the LRU queue if our ref count is 0 */
108 osi_assert(bp->magic == CM_BUF_MAGIC);
110 if (bp->refCount == 0)
111 osi_panic("buf refcount 0",__FILE__,__LINE__);;
113 osi_assert(bp->refCount > 0);
115 if (--bp->refCount == 0) {
116 if (!(bp->flags & CM_BUF_INLRU)) {
117 osi_QAdd((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
119 /* watch for transition from empty to one element */
120 if (!cm_data.buf_freeListEndp)
121 cm_data.buf_freeListEndp = cm_data.buf_freeListp;
122 bp->flags |= CM_BUF_INLRU;
127 /* release a buffer. Buffer must be referenced, but unlocked. */
128 void buf_Release(cm_buf_t *bp)
130 lock_ObtainWrite(&buf_globalLock);
131 buf_ReleaseLocked(bp);
132 lock_ReleaseWrite(&buf_globalLock);
135 /* incremental sync daemon. Writes 1/10th of all the buffers every 5000 ms */
136 void buf_IncrSyncer(long parm)
138 cm_buf_t *bp; /* buffer we're hacking on; held */
139 long i; /* counter */
143 lock_ObtainWrite(&buf_globalLock);
144 bp = cm_data.buf_allp;
146 lock_ReleaseWrite(&buf_globalLock);
149 while (buf_ShutdownFlag == 0) {
151 i = SleepEx(5000, 1);
152 if (i != 0) continue;
155 if (buf_ShutdownFlag == 1)
160 /* now go through our percentage of the buffers */
161 for (i=0; i<cm_data.buf_nbuffers; i++) {
162 /* don't want its identity changing while we're
163 * messing with it, so must do all of this with
167 /* start cleaning the buffer; don't touch log pages since
168 * the log code counts on knowing exactly who is writing
169 * a log page at any given instant.
172 req.flags |= CM_REQ_NORETRY;
173 wasDirty |= buf_CleanAsync(bp, &req);
175 /* now advance to the next buffer; the allp chain never changes,
176 * and so can be followed even when holding no locks.
178 lock_ObtainWrite(&buf_globalLock);
179 buf_ReleaseLocked(bp);
182 bp = cm_data.buf_allp;
184 lock_ReleaseWrite(&buf_globalLock);
185 } /* for loop over a bunch of buffers */
186 } /* whole daemon's while loop */
190 buf_ValidateBuffers(void)
192 cm_buf_t * bp, *bpf, *bpa, *bpb;
193 afs_uint64 countb = 0, countf = 0, counta = 0;
195 if (cm_data.buf_freeListp == NULL && cm_data.buf_freeListEndp != NULL ||
196 cm_data.buf_freeListp != NULL && cm_data.buf_freeListEndp == NULL) {
197 afsi_log("cm_ValidateBuffers failure: inconsistent free list pointers");
198 fprintf(stderr, "cm_ValidateBuffers failure: inconsistent free list pointers\n");
202 for (bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
203 if (bp->magic != CM_BUF_MAGIC) {
204 afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
205 fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
211 if (countb > cm_data.buf_nbuffers) {
212 afsi_log("cm_ValidateBuffers failure: countb > cm_data.buf_nbuffers");
213 fprintf(stderr, "cm_ValidateBuffers failure: countb > cm_data.buf_nbuffers\n");
218 for (bp = cm_data.buf_freeListp; bp; bp=(cm_buf_t *) osi_QNext(&bp->q)) {
219 if (bp->magic != CM_BUF_MAGIC) {
220 afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
221 fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
227 if (countf > cm_data.buf_nbuffers) {
228 afsi_log("cm_ValidateBuffers failure: countf > cm_data.buf_nbuffers");
229 fprintf(stderr, "cm_ValidateBuffers failure: countf > cm_data.buf_nbuffers\n");
234 for (bp = cm_data.buf_allp; bp; bp=bp->allp) {
235 if (bp->magic != CM_BUF_MAGIC) {
236 afsi_log("cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC");
237 fprintf(stderr, "cm_ValidateBuffers failure: bp->magic != CM_BUF_MAGIC\n");
243 if (counta > cm_data.buf_nbuffers) {
244 afsi_log("cm_ValidateBuffers failure: counta > cm_data.buf_nbuffers");
245 fprintf(stderr, "cm_ValidateBuffers failure: counta > cm_data.buf_nbuffers\n");
250 if (countb != countf) {
251 afsi_log("cm_ValidateBuffers failure: countb != countf");
252 fprintf(stderr, "cm_ValidateBuffers failure: countb != countf\n");
256 if (counta != cm_data.buf_nbuffers) {
257 afsi_log("cm_ValidateBuffers failure: counta != cm_data.buf_nbuffers");
258 fprintf(stderr, "cm_ValidateBuffers failure: counta != cm_data.buf_nbuffers\n");
265 void buf_Shutdown(void)
267 buf_ShutdownFlag = 1;
270 /* initialize the buffer package; called with no locks
271 * held during the initialization phase.
273 long buf_Init(int newFile, cm_buf_ops_t *opsp, afs_uint64 nbuffers)
275 static osi_once_t once;
284 cm_data.buf_nbuffers = nbuffers;
286 /* Have to be able to reserve a whole chunk */
287 if (((cm_data.buf_nbuffers - 3) * cm_data.buf_blockSize) < cm_chunkSize)
288 return CM_ERROR_TOOFEWBUFS;
291 /* recall for callouts */
294 if (osi_Once(&once)) {
295 /* initialize global locks */
296 lock_InitializeRWLock(&buf_globalLock, "Global buffer lock");
299 /* remember this for those who want to reset it */
300 cm_data.buf_nOrigBuffers = cm_data.buf_nbuffers;
302 /* lower hash size to a prime number */
303 cm_data.buf_hashSize = osi_PrimeLessThan(CM_BUF_HASHSIZE);
305 /* create hash table */
306 memset((void *)cm_data.buf_hashTablepp, 0, cm_data.buf_hashSize * sizeof(cm_buf_t *));
308 /* another hash table */
309 memset((void *)cm_data.buf_fileHashTablepp, 0, cm_data.buf_hashSize * sizeof(cm_buf_t *));
311 /* create buffer headers and put in free list */
312 bp = cm_data.bufHeaderBaseAddress;
313 data = cm_data.bufDataBaseAddress;
314 cm_data.buf_allp = NULL;
316 for (i=0; i<cm_data.buf_nbuffers; i++) {
317 osi_assert(bp >= cm_data.bufHeaderBaseAddress && bp < (cm_buf_t *)cm_data.bufDataBaseAddress);
318 osi_assert(data >= cm_data.bufDataBaseAddress && data < cm_data.bufEndOfData);
320 /* allocate and zero some storage */
321 memset(bp, 0, sizeof(cm_buf_t));
322 bp->magic = CM_BUF_MAGIC;
323 /* thread on list of all buffers */
324 bp->allp = cm_data.buf_allp;
325 cm_data.buf_allp = bp;
327 osi_QAdd((osi_queue_t **)&cm_data.buf_freeListp, &bp->q);
328 bp->flags |= CM_BUF_INLRU;
329 lock_InitializeMutex(&bp->mx, "Buffer mutex");
331 /* grab appropriate number of bytes from aligned zone */
334 /* setup last buffer pointer */
336 cm_data.buf_freeListEndp = bp;
340 data += cm_data.buf_blockSize;
343 /* none reserved at first */
344 cm_data.buf_reservedBufs = 0;
346 /* just for safety's sake */
347 cm_data.buf_maxReservedBufs = cm_data.buf_nbuffers - 3;
349 bp = cm_data.bufHeaderBaseAddress;
350 data = cm_data.bufDataBaseAddress;
352 for (i=0; i<cm_data.buf_nbuffers; i++) {
353 lock_InitializeMutex(&bp->mx, "Buffer mutex");
356 bp->waitRequests = 0;
357 bp->flags &= ~CM_BUF_WAITING;
363 buf_ValidateBufQueues();
367 /* init the buffer trace log */
368 buf_logp = osi_LogCreate("buffer", 1000);
369 osi_LogEnable(buf_logp);
374 /* and create the incr-syncer */
375 phandle = thrd_Create(0, 0,
376 (ThreadFunc) buf_IncrSyncer, 0, 0, &pid,
379 osi_assertx(phandle != NULL, "buf: can't create incremental sync proc");
380 CloseHandle(phandle);
384 buf_ValidateBufQueues();
389 /* add nbuffers to the buffer pool, if possible.
390 * Called with no locks held.
392 long buf_AddBuffers(afs_uint64 nbuffers)
394 /* The size of a virtual cache cannot be changed after it has
395 * been created. Subsequent calls to MapViewofFile() with
396 * an existing mapping object name would not allow the
397 * object to be resized. Return failure immediately.
399 * A similar problem now occurs with the persistent cache
400 * given that the memory mapped file now contains a complex
403 afsi_log("request to add %d buffers to the existing cache of size %d denied",
404 nbuffers, cm_data.buf_nbuffers);
406 return CM_ERROR_INVAL;
409 /* interface to set the number of buffers to an exact figure.
410 * Called with no locks held.
412 long buf_SetNBuffers(afs_uint64 nbuffers)
415 return CM_ERROR_INVAL;
416 if (nbuffers == cm_data.buf_nbuffers)
418 else if (nbuffers > cm_data.buf_nbuffers)
419 return buf_AddBuffers(nbuffers - cm_data.buf_nbuffers);
421 return CM_ERROR_INVAL;
424 /* wait for reading or writing to clear; called with write-locked
425 * buffer and unlocked scp and returns with locked buffer.
427 void buf_WaitIO(cm_scache_t * scp, cm_buf_t *bp)
432 osi_assert(scp->magic == CM_SCACHE_MAGIC);
433 osi_assert(bp->magic == CM_BUF_MAGIC);
436 /* if no IO is happening, we're done */
437 if (!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING)))
440 /* otherwise I/O is happening, but some other thread is waiting for
441 * the I/O already. Wait for that guy to figure out what happened,
442 * and then check again.
444 if ( bp->flags & CM_BUF_WAITING ) {
447 osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING already set for 0x%p", bp);
449 osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING set for 0x%p", bp);
450 bp->flags |= CM_BUF_WAITING;
451 bp->waitCount = bp->waitRequests = 1;
453 osi_SleepM((LONG_PTR)bp, &bp->mx);
455 smb_UpdateServerPriority();
457 lock_ObtainMutex(&bp->mx);
458 osi_Log1(buf_logp, "buf_WaitIO conflict wait done for 0x%p", bp);
460 if (bp->waitCount == 0) {
461 osi_Log1(buf_logp, "buf_WaitIO CM_BUF_WAITING reset for 0x%p", bp);
462 bp->flags &= ~CM_BUF_WAITING;
463 bp->waitRequests = 0;
467 if (scp = cm_FindSCache(&bp->fid))
471 lock_ObtainMutex(&scp->mx);
472 if (scp->flags & CM_SCACHEFLAG_WAITING) {
473 osi_Log1(buf_logp, "buf_WaitIO waking scp 0x%p", scp);
474 osi_Wakeup((LONG_PTR)&scp->flags);
476 lock_ReleaseMutex(&scp->mx);
480 /* if we get here, the IO is done, but we may have to wakeup people waiting for
481 * the I/O to complete. Do so.
483 if (bp->flags & CM_BUF_WAITING) {
484 osi_Log1(buf_logp, "buf_WaitIO Waking bp 0x%p", bp);
485 osi_Wakeup((LONG_PTR) bp);
487 osi_Log1(buf_logp, "WaitIO finished wait for bp 0x%p", bp);
490 cm_ReleaseSCache(scp);
493 /* find a buffer, if any, for a particular file ID and offset. Assumes
494 * that buf_globalLock is write locked when called.
496 cm_buf_t *buf_FindLocked(struct cm_scache *scp, osi_hyper_t *offsetp)
501 i = BUF_HASH(&scp->fid, offsetp);
502 for(bp = cm_data.buf_hashTablepp[i]; bp; bp=bp->hashp) {
503 if (cm_FidCmp(&scp->fid, &bp->fid) == 0
504 && offsetp->LowPart == bp->offset.LowPart
505 && offsetp->HighPart == bp->offset.HighPart) {
511 /* return whatever we found, if anything */
515 /* find a buffer with offset *offsetp for vnode *scp. Called
516 * with no locks held.
518 cm_buf_t *buf_Find(struct cm_scache *scp, osi_hyper_t *offsetp)
522 lock_ObtainWrite(&buf_globalLock);
523 bp = buf_FindLocked(scp, offsetp);
524 lock_ReleaseWrite(&buf_globalLock);
529 /* start cleaning I/O on this buffer. Buffer must be write locked, and is returned
532 * Makes sure that there's only one person writing this block
533 * at any given time, and also ensures that the log is forced sufficiently far,
534 * if this buffer contains logged data.
536 * Returns non-zero if the buffer was dirty.
538 long buf_CleanAsyncLocked(cm_buf_t *bp, cm_req_t *reqp)
542 cm_scache_t * scp = NULL;
544 osi_assert(bp->magic == CM_BUF_MAGIC);
546 while ((bp->flags & CM_BUF_DIRTY) == CM_BUF_DIRTY) {
548 lock_ReleaseMutex(&bp->mx);
550 scp = cm_FindSCache(&bp->fid);
552 osi_Log2(buf_logp, "buf_CleanAsyncLocked starts I/O on scp 0x%p buf 0x%p", scp, bp);
553 code = (*cm_buf_opsp->Writep)(scp, &bp->offset,
554 cm_data.buf_blockSize, 0, bp->userp,
556 osi_Log3(buf_logp, "buf_CleanAsyncLocked I/O on scp 0x%p buf 0x%p, done=%d", scp, bp, code);
558 cm_ReleaseSCache(scp);
561 osi_Log1(buf_logp, "buf_CleanAsyncLocked unable to start I/O - scp not found buf 0x%p", bp);
562 code = CM_ERROR_NOSUCHFILE;
565 lock_ObtainMutex(&bp->mx);
566 /* if the Write routine returns No Such File, clear the dirty flag
567 * because we aren't going to be able to write this data to the file
570 if (code == CM_ERROR_NOSUCHFILE){
571 bp->flags &= ~CM_BUF_DIRTY;
572 bp->flags |= CM_BUF_ERROR;
573 bp->error = CM_ERROR_NOSUCHFILE;
574 bp->dataVersion = -1; /* bad */
579 /* Disk cache support */
580 /* write buffer to disk cache (synchronous for now) */
581 diskcache_Update(bp->dcp, bp->datap, cm_data.buf_blockSize, bp->dataVersion);
582 #endif /* DISKCACHE95 */
584 /* if we get here and retries are not permitted
585 * then we need to exit this loop regardless of
586 * whether or not we were able to clear the dirty bit
588 if (reqp->flags & CM_REQ_NORETRY)
592 /* do logging after call to GetLastError, or else */
594 /* if someone was waiting for the I/O that just completed or failed,
597 if (bp->flags & CM_BUF_WAITING) {
598 /* turn off flags and wakeup users */
599 osi_Log1(buf_logp, "buf_WaitIO Waking bp 0x%p", bp);
600 osi_Wakeup((LONG_PTR) bp);
605 /* Called with a zero-ref count buffer and with the buf_globalLock write locked.
606 * recycles the buffer, and leaves it ready for reuse with a ref count of 1.
607 * The buffer must already be clean, and no I/O should be happening to it.
609 void buf_Recycle(cm_buf_t *bp)
614 cm_buf_t *prevBp, *nextBp;
616 osi_assert(bp->magic == CM_BUF_MAGIC);
618 /* if we get here, we know that the buffer still has a 0 ref count,
619 * and that it is clean and has no currently pending I/O. This is
620 * the dude to return.
621 * Remember that as long as the ref count is 0, we know that we won't
622 * have any lock conflicts, so we can grab the buffer lock out of
623 * order in the locking hierarchy.
625 osi_Log2( buf_logp, "buf_Recycle recycles 0x%p, off 0x%x",
626 bp, bp->offset.LowPart);
628 osi_assert(bp->refCount == 0);
629 osi_assert(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING | CM_BUF_DIRTY)));
630 lock_AssertWrite(&buf_globalLock);
632 if (bp->flags & CM_BUF_INHASH) {
633 /* Remove from hash */
635 i = BUF_HASH(&bp->fid, &bp->offset);
636 lbpp = &(cm_data.buf_hashTablepp[i]);
637 for(tbp = *lbpp; tbp; lbpp = &tbp->hashp, tbp = *lbpp) {
638 if (tbp == bp) break;
641 /* we better find it */
642 osi_assertx(tbp != NULL, "buf_Recycle: hash table screwup");
644 *lbpp = bp->hashp; /* hash out */
646 /* Remove from file hash */
648 i = BUF_FILEHASH(&bp->fid);
649 prevBp = bp->fileHashBackp;
650 nextBp = bp->fileHashp;
652 prevBp->fileHashp = nextBp;
654 cm_data.buf_fileHashTablepp[i] = nextBp;
656 nextBp->fileHashBackp = prevBp;
658 bp->flags &= ~CM_BUF_INHASH;
661 /* bump the soft reference counter now, to invalidate softRefs; no
662 * wakeup is required since people don't sleep waiting for this
667 /* make the fid unrecognizable */
668 memset(&bp->fid, 0, sizeof(cm_fid_t));
671 /* recycle a buffer, removing it from the free list, hashing in its new identity
672 * and returning it write-locked so that no one can use it. Called without
673 * any locks held, and can return an error if it loses the race condition and
674 * finds that someone else created the desired buffer.
676 * If success is returned, the buffer is returned write-locked.
678 * May be called with null scp and offsetp, if we're just trying to reclaim some
679 * space from the buffer pool. In that case, the buffer will be returned
680 * without being hashed into the hash table.
682 long buf_GetNewLocked(struct cm_scache *scp, osi_hyper_t *offsetp, cm_buf_t **bufpp)
684 cm_buf_t *bp; /* buffer we're dealing with */
685 cm_buf_t *nextBp; /* next buffer in file hash chain */
689 cm_InitReq(&req); /* just in case */
692 buf_ValidateBufQueues();
697 lock_ObtainWrite(&buf_globalLock);
698 /* check to see if we lost the race */
700 if (bp = buf_FindLocked(scp, offsetp)) {
701 /* Do not call buf_ReleaseLocked() because we
702 * do not want to allow the buffer to be added
706 lock_ReleaseWrite(&buf_globalLock);
707 return CM_BUF_EXISTS;
711 /* does this fix the problem below? it's a simple solution. */
712 if (!cm_data.buf_freeListEndp)
714 lock_ReleaseWrite(&buf_globalLock);
719 /* for debugging, assert free list isn't empty, although we
720 * really should try waiting for a running tranasction to finish
721 * instead of this; or better, we should have a transaction
722 * throttler prevent us from entering this situation.
724 osi_assertx(cm_data.buf_freeListEndp != NULL, "buf_GetNewLocked: no free buffers");
726 /* look at all buffers in free list, some of which may temp.
727 * have high refcounts and which then should be skipped,
728 * starting cleaning I/O for those which are dirty. If we find
729 * a clean buffer, we rehash it, lock it and return it.
731 for(bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
732 /* check to see if it really has zero ref count. This
733 * code can bump refcounts, at least, so it may not be
736 if (bp->refCount > 0)
739 /* we don't have to lock buffer itself, since the ref
740 * count is 0 and we know it will stay zero as long as
741 * we hold the global lock.
744 /* don't recycle someone in our own chunk */
745 if (!cm_FidCmp(&bp->fid, &scp->fid)
746 && (bp->offset.LowPart & (-cm_chunkSize))
747 == (offsetp->LowPart & (-cm_chunkSize)))
750 /* if this page is being filled (!) or cleaned, see if
751 * the I/O has completed. If not, skip it, otherwise
752 * do the final processing for the I/O.
754 if (bp->flags & (CM_BUF_READING | CM_BUF_WRITING)) {
755 /* probably shouldn't do this much work while
756 * holding the big lock? Watch for contention
762 if (bp->flags & CM_BUF_DIRTY) {
763 /* if the buffer is dirty, start cleaning it and
764 * move on to the next buffer. We do this with
765 * just the lock required to minimize contention
769 lock_ReleaseWrite(&buf_globalLock);
771 /* grab required lock and clean; this only
772 * starts the I/O. By the time we're back,
773 * it'll still be marked dirty, but it will also
774 * have the WRITING flag set, so we won't get
777 buf_CleanAsync(bp, &req);
779 /* now put it back and go around again */
784 /* if we get here, we know that the buffer still has a 0
785 * ref count, and that it is clean and has no currently
786 * pending I/O. This is the dude to return.
787 * Remember that as long as the ref count is 0, we know
788 * that we won't have any lock conflicts, so we can grab
789 * the buffer lock out of order in the locking hierarchy.
793 /* clean up junk flags */
794 bp->flags &= ~(CM_BUF_EOF | CM_BUF_ERROR);
795 bp->dataVersion = -1; /* unknown so far */
797 /* now hash in as our new buffer, and give it the
798 * appropriate label, if requested.
801 bp->flags |= CM_BUF_INHASH;
806 bp->offset = *offsetp;
807 i = BUF_HASH(&scp->fid, offsetp);
808 bp->hashp = cm_data.buf_hashTablepp[i];
809 cm_data.buf_hashTablepp[i] = bp;
810 i = BUF_FILEHASH(&scp->fid);
811 nextBp = cm_data.buf_fileHashTablepp[i];
812 bp->fileHashp = nextBp;
813 bp->fileHashBackp = NULL;
815 nextBp->fileHashBackp = bp;
816 cm_data.buf_fileHashTablepp[i] = bp;
819 /* prepare to return it. Start by giving it a good
823 /* and since it has a non-zero ref count, we should move
824 * it from the lru queue. It better be still there,
825 * since we've held the global (big) lock since we found
828 osi_assertx(bp->flags & CM_BUF_INLRU,
829 "buf_GetNewLocked: LRU screwup");
830 if (cm_data.buf_freeListEndp == bp) {
831 /* we're the last guy in this queue, so maintain it */
832 cm_data.buf_freeListEndp = (cm_buf_t *) osi_QPrev(&bp->q);
834 osi_QRemove((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
835 bp->flags &= ~CM_BUF_INLRU;
837 /* finally, grab the mutex so that people don't use it
838 * before the caller fills it with data. Again, no one
839 * should have been able to get to this dude to lock it.
841 osi_assertx(lock_TryMutex(&bp->mx),
842 "buf_GetNewLocked: TryMutex failed");
844 lock_ReleaseWrite(&buf_globalLock);
848 buf_ValidateBufQueues();
851 } /* for all buffers in lru queue */
852 lock_ReleaseWrite(&buf_globalLock);
853 } /* while loop over everything */
857 /* get a page, returning it held but unlocked. Doesn't fill in the page
858 * with I/O, since we're going to write the whole thing new.
860 long buf_GetNew(struct cm_scache *scp, osi_hyper_t *offsetp, cm_buf_t **bufpp)
864 osi_hyper_t pageOffset;
868 pageOffset.HighPart = offsetp->HighPart;
869 pageOffset.LowPart = offsetp->LowPart & ~(cm_data.buf_blockSize-1);
871 bp = buf_Find(scp, &pageOffset);
873 /* lock it and break out */
874 lock_ObtainMutex(&bp->mx);
878 /* otherwise, we have to create a page */
879 code = buf_GetNewLocked(scp, &pageOffset, &bp);
881 /* check if the buffer was created in a race condition branch.
882 * If so, go around so we can hold a reference to it.
884 if (code == CM_BUF_EXISTS)
887 /* something else went wrong */
891 /* otherwise, we have a locked buffer that we just created */
894 } /* big while loop */
897 if (bp->flags & CM_BUF_READING)
900 /* once it has been read once, we can unlock it and return it, still
901 * with its refcount held.
903 lock_ReleaseMutex(&bp->mx);
905 osi_Log3(buf_logp, "buf_GetNew returning bp 0x%p for scp 0x%p, offset 0x%x",
906 bp, scp, offsetp->LowPart);
910 /* get a page, returning it held but unlocked. Make sure it is complete */
911 /* The scp must be unlocked when passed to this function */
912 long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_buf_t **bufpp)
916 osi_hyper_t pageOffset;
917 unsigned long tcount;
922 #endif /* DISKCACHE95 */
925 pageOffset.HighPart = offsetp->HighPart;
926 pageOffset.LowPart = offsetp->LowPart & ~(cm_data.buf_blockSize-1);
930 buf_ValidateBufQueues();
933 bp = buf_Find(scp, &pageOffset);
935 /* lock it and break out */
936 lock_ObtainMutex(&bp->mx);
939 /* touch disk chunk to update LRU info */
940 diskcache_Touch(bp->dcp);
941 #endif /* DISKCACHE95 */
945 /* otherwise, we have to create a page */
946 code = buf_GetNewLocked(scp, &pageOffset, &bp);
947 /* bp->mx is now held */
949 /* check if the buffer was created in a race condition branch.
950 * If so, go around so we can hold a reference to it.
952 if (code == CM_BUF_EXISTS)
955 /* something else went wrong */
958 buf_ValidateBufQueues();
963 /* otherwise, we have a locked buffer that we just created */
966 } /* big while loop */
968 /* if we get here, we have a locked buffer that may have just been
969 * created, in which case it needs to be filled with data.
972 /* load the page; freshly created pages should be idle */
973 osi_assert(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING)));
975 /* setup offset, event */
976 bp->over.Offset = bp->offset.LowPart;
977 bp->over.OffsetHigh = bp->offset.HighPart;
979 /* start the I/O; may drop lock */
980 bp->flags |= CM_BUF_READING;
981 code = (*cm_buf_opsp->Readp)(bp, cm_data.buf_blockSize, &tcount, NULL);
984 code = diskcache_Get(&bp->fid, &bp->offset, bp->datap, cm_data.buf_blockSize, &bp->dataVersion, &tcount, &dcp);
985 bp->dcp = dcp; /* pointer to disk cache struct. */
986 #endif /* DISKCACHE95 */
989 /* failure or queued */
990 if (code != ERROR_IO_PENDING) {
992 bp->flags |= CM_BUF_ERROR;
993 bp->flags &= ~CM_BUF_READING;
994 if (bp->flags & CM_BUF_WAITING) {
995 osi_Log1(buf_logp, "buf_Get Waking bp 0x%p", bp);
996 osi_Wakeup((LONG_PTR) bp);
998 lock_ReleaseMutex(&bp->mx);
1001 buf_ValidateBufQueues();
1002 #endif /* TESTING */
1006 /* otherwise, I/O completed instantly and we're done, except
1007 * for padding the xfr out with 0s and checking for EOF
1009 if (tcount < (unsigned long) cm_data.buf_blockSize) {
1010 memset(bp->datap+tcount, 0, cm_data.buf_blockSize - tcount);
1012 bp->flags |= CM_BUF_EOF;
1014 bp->flags &= ~CM_BUF_READING;
1015 if (bp->flags & CM_BUF_WAITING) {
1016 osi_Log1(buf_logp, "buf_Get Waking bp 0x%p", bp);
1017 osi_Wakeup((LONG_PTR) bp);
1023 /* wait for reads, either that which we started above, or that someone
1024 * else started. We don't care if we return a buffer being cleaned.
1026 if (bp->flags & CM_BUF_READING)
1027 buf_WaitIO(scp, bp);
1029 /* once it has been read once, we can unlock it and return it, still
1030 * with its refcount held.
1032 lock_ReleaseMutex(&bp->mx);
1035 /* now remove from queue; will be put in at the head (farthest from
1036 * being recycled) when we're done in buf_Release.
1038 lock_ObtainWrite(&buf_globalLock);
1039 if (bp->flags & CM_BUF_INLRU) {
1040 if (cm_data.buf_freeListEndp == bp)
1041 cm_data.buf_freeListEndp = (cm_buf_t *) osi_QPrev(&bp->q);
1042 osi_QRemove((osi_queue_t **) &cm_data.buf_freeListp, &bp->q);
1043 bp->flags &= ~CM_BUF_INLRU;
1045 lock_ReleaseWrite(&buf_globalLock);
1047 osi_Log3(buf_logp, "buf_Get returning bp 0x%p for scp 0x%p, offset 0x%x",
1048 bp, scp, offsetp->LowPart);
1050 buf_ValidateBufQueues();
1051 #endif /* TESTING */
1055 /* count # of elements in the free list;
1056 * we don't bother doing the proper locking for accessing dataVersion or flags
1057 * since it is a pain, and this is really just an advisory call. If you need
1058 * to do better at some point, rewrite this function.
1060 long buf_CountFreeList(void)
1066 lock_ObtainRead(&buf_globalLock);
1067 for(bufp = cm_data.buf_freeListp; bufp; bufp = (cm_buf_t *) osi_QNext(&bufp->q)) {
1068 /* if the buffer doesn't have an identity, or if the buffer
1069 * has been invalidate (by having its DV stomped upon), then
1070 * count it as free, since it isn't really being utilized.
1072 if (!(bufp->flags & CM_BUF_INHASH) || bufp->dataVersion <= 0)
1075 lock_ReleaseRead(&buf_globalLock);
1079 /* clean a buffer synchronously */
1080 long buf_CleanAsync(cm_buf_t *bp, cm_req_t *reqp)
1083 osi_assert(bp->magic == CM_BUF_MAGIC);
1085 lock_ObtainMutex(&bp->mx);
1086 code = buf_CleanAsyncLocked(bp, reqp);
1087 lock_ReleaseMutex(&bp->mx);
1092 /* wait for a buffer's cleaning to finish */
1093 void buf_CleanWait(cm_scache_t * scp, cm_buf_t *bp)
1095 osi_assert(bp->magic == CM_BUF_MAGIC);
1097 lock_ObtainMutex(&bp->mx);
1098 if (bp->flags & CM_BUF_WRITING) {
1099 buf_WaitIO(scp, bp);
1101 lock_ReleaseMutex(&bp->mx);
1104 /* set the dirty flag on a buffer, and set associated write-ahead log,
1105 * if there is one. Allow one to be added to a buffer, but not changed.
1107 * The buffer must be locked before calling this routine.
1109 void buf_SetDirty(cm_buf_t *bp)
1111 osi_assert(bp->magic == CM_BUF_MAGIC);
1112 osi_assert(bp->refCount > 0);
1114 osi_Log1(buf_logp, "buf_SetDirty 0x%p", bp);
1117 bp->flags |= CM_BUF_DIRTY;
1119 /* and turn off EOF flag, since it has associated data now */
1120 bp->flags &= ~CM_BUF_EOF;
1123 /* clean all buffers, reset log pointers and invalidate all buffers.
1124 * Called with no locks held, and returns with same.
1126 * This function is guaranteed to clean and remove the log ptr of all the
1127 * buffers that were dirty or had non-zero log ptrs before the call was
1128 * made. That's sufficient to clean up any garbage left around by recovery,
1129 * which is all we're counting on this for; there may be newly created buffers
1130 * added while we're running, but that should be OK.
1132 * In an environment where there are no transactions (artificially imposed, for
1133 * example, when switching the database to raw mode), this function is used to
1134 * make sure that all updates have been written to the disk. In that case, we don't
1135 * really require that we forget the log association between pages and logs, but
1136 * it also doesn't hurt. Since raw mode I/O goes through this buffer package, we don't
1137 * have to worry about invalidating data in the buffers.
1139 * This function is used at the end of recovery as paranoia to get the recovered
1140 * database out to disk. It removes all references to the recovery log and cleans
1143 long buf_CleanAndReset(void)
1149 lock_ObtainWrite(&buf_globalLock);
1150 for(i=0; i<cm_data.buf_hashSize; i++) {
1151 for(bp = cm_data.buf_hashTablepp[i]; bp; bp = bp->hashp) {
1152 if ((bp->flags & CM_BUF_DIRTY) == CM_BUF_DIRTY) {
1154 lock_ReleaseWrite(&buf_globalLock);
1156 /* now no locks are held; clean buffer and go on */
1158 req.flags |= CM_REQ_NORETRY;
1160 buf_CleanAsync(bp, &req);
1161 buf_CleanWait(NULL, bp);
1163 /* relock and release buffer */
1164 lock_ObtainWrite(&buf_globalLock);
1165 buf_ReleaseLocked(bp);
1167 } /* over one bucket */
1168 } /* for loop over all hash buckets */
1171 lock_ReleaseWrite(&buf_globalLock);
1174 buf_ValidateBufQueues();
1175 #endif /* TESTING */
1177 /* and we're done */
1181 /* called without global lock being held, reserves buffers for callers
1182 * that need more than one held (not locked) at once.
1184 void buf_ReserveBuffers(afs_uint64 nbuffers)
1186 lock_ObtainWrite(&buf_globalLock);
1188 if (cm_data.buf_reservedBufs + nbuffers > cm_data.buf_maxReservedBufs) {
1189 cm_data.buf_reserveWaiting = 1;
1190 osi_Log1(buf_logp, "buf_ReserveBuffers waiting for %d bufs", nbuffers);
1191 osi_SleepW((LONG_PTR) &cm_data.buf_reservedBufs, &buf_globalLock);
1192 lock_ObtainWrite(&buf_globalLock);
1195 cm_data.buf_reservedBufs += nbuffers;
1199 lock_ReleaseWrite(&buf_globalLock);
1202 int buf_TryReserveBuffers(afs_uint64 nbuffers)
1206 lock_ObtainWrite(&buf_globalLock);
1207 if (cm_data.buf_reservedBufs + nbuffers > cm_data.buf_maxReservedBufs) {
1211 cm_data.buf_reservedBufs += nbuffers;
1214 lock_ReleaseWrite(&buf_globalLock);
1218 /* called without global lock held, releases reservation held by
1219 * buf_ReserveBuffers.
1221 void buf_UnreserveBuffers(afs_uint64 nbuffers)
1223 lock_ObtainWrite(&buf_globalLock);
1224 cm_data.buf_reservedBufs -= nbuffers;
1225 if (cm_data.buf_reserveWaiting) {
1226 cm_data.buf_reserveWaiting = 0;
1227 osi_Wakeup((LONG_PTR) &cm_data.buf_reservedBufs);
1229 lock_ReleaseWrite(&buf_globalLock);
1232 /* truncate the buffers past sizep, zeroing out the page, if we don't
1233 * end on a page boundary.
1235 * Requires cm_bufCreateLock to be write locked.
1237 long buf_Truncate(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp,
1241 cm_buf_t *nbufp; /* next buffer, if didRelease */
1247 /* assert that cm_bufCreateLock is held in write mode */
1248 lock_AssertWrite(&scp->bufCreateLock);
1250 i = BUF_FILEHASH(&scp->fid);
1252 lock_ObtainWrite(&buf_globalLock);
1253 bufp = cm_data.buf_fileHashTablepp[i];
1255 lock_ReleaseWrite(&buf_globalLock);
1259 buf_HoldLocked(bufp);
1260 lock_ReleaseWrite(&buf_globalLock);
1261 for(; bufp; bufp = nbufp) {
1262 lock_ObtainMutex(&bufp->mx);
1264 bufEnd.HighPart = 0;
1265 bufEnd.LowPart = cm_data.buf_blockSize;
1266 bufEnd = LargeIntegerAdd(bufEnd, bufp->offset);
1268 if (cm_FidCmp(&bufp->fid, &scp->fid) == 0 &&
1269 LargeIntegerLessThan(*sizep, bufEnd)) {
1270 buf_WaitIO(scp, bufp);
1272 lock_ObtainMutex(&scp->mx);
1274 /* make sure we have a callback (so we have the right value for
1275 * the length), and wait for it to be safe to do a truncate.
1277 code = cm_SyncOp(scp, bufp, userp, reqp, 0,
1278 CM_SCACHESYNC_NEEDCALLBACK
1279 | CM_SCACHESYNC_GETSTATUS
1280 | CM_SCACHESYNC_SETSIZE
1281 | CM_SCACHESYNC_BUFLOCKED);
1284 lock_ObtainWrite(&buf_globalLock);
1285 /* if we succeeded in our locking, and this applies to the right
1286 * file, and the truncate request overlaps the buffer either
1287 * totally or partially, then do something.
1289 if (code == 0 && cm_FidCmp(&bufp->fid, &scp->fid) == 0
1290 && LargeIntegerLessThan(*sizep, bufEnd)) {
1293 /* destroy the buffer, turning off its dirty bit, if
1294 * we're truncating the whole buffer. Otherwise, set
1295 * the dirty bit, and clear out the tail of the buffer
1296 * if we just overlap some.
1298 if (LargeIntegerLessThanOrEqualTo(*sizep, bufp->offset)) {
1299 /* truncating the entire page */
1300 bufp->flags &= ~CM_BUF_DIRTY;
1301 bufp->dataVersion = -1; /* known bad */
1302 bufp->dirtyCounter++;
1305 /* don't set dirty, since dirty implies
1306 * currently up-to-date. Don't need to do this,
1307 * since we'll update the length anyway.
1309 * Zero out remainder of the page, in case we
1310 * seek and write past EOF, and make this data
1313 bufferPos = sizep->LowPart & (cm_data.buf_blockSize - 1);
1314 osi_assert(bufferPos != 0);
1315 memset(bufp->datap + bufferPos, 0,
1316 cm_data.buf_blockSize - bufferPos);
1320 cm_SyncOpDone( scp, bufp,
1321 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS
1322 | CM_SCACHESYNC_SETSIZE | CM_SCACHESYNC_BUFLOCKED);
1324 lock_ReleaseMutex(&scp->mx);
1325 lock_ReleaseMutex(&bufp->mx);
1328 nbufp = bufp->fileHashp;
1330 buf_HoldLocked(nbufp);
1332 /* This forces the loop to end and the error code
1333 * to be returned. */
1336 buf_ReleaseLocked(bufp);
1337 lock_ReleaseWrite(&buf_globalLock);
1341 buf_ValidateBufQueues();
1342 #endif /* TESTING */
1348 long buf_FlushCleanPages(cm_scache_t *scp, cm_user_t *userp, cm_req_t *reqp)
1351 cm_buf_t *bp; /* buffer we're hacking on */
1356 i = BUF_FILEHASH(&scp->fid);
1359 lock_ObtainWrite(&buf_globalLock);
1360 bp = cm_data.buf_fileHashTablepp[i];
1363 lock_ReleaseWrite(&buf_globalLock);
1365 for (; bp; bp = nbp) {
1366 didRelease = 0; /* haven't released this buffer yet */
1368 /* clean buffer synchronously */
1369 if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
1370 lock_ObtainMutex(&bp->mx);
1372 /* start cleaning the buffer, and wait for it to finish */
1373 buf_CleanAsyncLocked(bp, reqp);
1374 buf_WaitIO(scp, bp);
1375 lock_ReleaseMutex(&bp->mx);
1377 code = (*cm_buf_opsp->Stabilizep)(scp, userp, reqp);
1381 lock_ObtainWrite(&buf_globalLock);
1382 /* actually, we only know that buffer is clean if ref
1383 * count is 1, since we don't have buffer itself locked.
1385 if (!(bp->flags & CM_BUF_DIRTY)) {
1386 if (bp->refCount == 1) { /* bp is held above */
1387 nbp = bp->fileHashp;
1389 buf_HoldLocked(nbp);
1390 buf_ReleaseLocked(bp);
1395 lock_ReleaseWrite(&buf_globalLock);
1397 (*cm_buf_opsp->Unstabilizep)(scp, userp);
1402 lock_ObtainWrite(&buf_globalLock);
1403 nbp = bp->fileHashp;
1405 buf_HoldLocked(nbp);
1406 buf_ReleaseLocked(bp);
1407 lock_ReleaseWrite(&buf_globalLock);
1409 } /* for loop over a bunch of buffers */
1412 buf_ValidateBufQueues();
1413 #endif /* TESTING */
1419 long buf_CleanVnode(struct cm_scache *scp, cm_user_t *userp, cm_req_t *reqp)
1423 cm_buf_t *bp; /* buffer we're hacking on */
1424 cm_buf_t *nbp; /* next one */
1427 i = BUF_FILEHASH(&scp->fid);
1429 lock_ObtainWrite(&buf_globalLock);
1430 bp = cm_data.buf_fileHashTablepp[i];
1433 lock_ReleaseWrite(&buf_globalLock);
1434 for (; bp; bp = nbp) {
1435 /* clean buffer synchronously */
1436 if (cm_FidCmp(&bp->fid, &scp->fid) == 0) {
1439 lock_ObtainMutex(&bp->mx);
1441 cm_ReleaseUser(bp->userp);
1443 lock_ReleaseMutex(&bp->mx);
1445 wasDirty = buf_CleanAsync(bp, reqp);
1446 buf_CleanWait(scp, bp);
1447 lock_ObtainMutex(&bp->mx);
1448 if (bp->flags & CM_BUF_ERROR) {
1453 lock_ReleaseMutex(&bp->mx);
1456 lock_ObtainWrite(&buf_globalLock);
1457 nbp = bp->fileHashp;
1459 buf_HoldLocked(nbp);
1460 buf_ReleaseLocked(bp);
1461 lock_ReleaseWrite(&buf_globalLock);
1462 } /* for loop over a bunch of buffers */
1465 buf_ValidateBufQueues();
1466 #endif /* TESTING */
1474 buf_ValidateBufQueues(void)
1476 cm_buf_t * bp, *bpb, *bpf, *bpa;
1477 afs_uint32 countf=0, countb=0, counta=0;
1479 lock_ObtainRead(&buf_globalLock);
1480 for (bp = cm_data.buf_freeListEndp; bp; bp=(cm_buf_t *) osi_QPrev(&bp->q)) {
1481 if (bp->magic != CM_BUF_MAGIC)
1482 osi_panic("buf magic error",__FILE__,__LINE__);
1487 for (bp = cm_data.buf_freeListp; bp; bp=(cm_buf_t *) osi_QNext(&bp->q)) {
1488 if (bp->magic != CM_BUF_MAGIC)
1489 osi_panic("buf magic error",__FILE__,__LINE__);
1494 for (bp = cm_data.buf_allp; bp; bp=bp->allp) {
1495 if (bp->magic != CM_BUF_MAGIC)
1496 osi_panic("buf magic error",__FILE__,__LINE__);
1500 lock_ReleaseRead(&buf_globalLock);
1502 if (countb != countf)
1503 osi_panic("buf magic error",__FILE__,__LINE__);
1505 if (counta != cm_data.buf_nbuffers)
1506 osi_panic("buf magic error",__FILE__,__LINE__);
1508 #endif /* TESTING */
1510 /* dump the contents of the buf_hashTablepp. */
1511 int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock)
1518 if (cm_data.buf_hashTablepp == NULL)
1522 lock_ObtainRead(&buf_globalLock);
1524 StringCbPrintfA(output, sizeof(output), "%s - dumping buf_HashTable - buf_hashSize=%d\n",
1525 cookie, cm_data.buf_hashSize);
1526 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1528 for (i = 0; i < cm_data.buf_hashSize; i++)
1530 for (bp = cm_data.buf_hashTablepp[i]; bp; bp=bp->hashp)
1534 StringCbPrintfA(output, sizeof(output), "vnode=%d, unique=%d), size=%d refCount=%d\n",
1535 cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume,
1536 bp->fid.vnode, bp->fid.unique, bp->size, bp->refCount);
1537 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1542 StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_HashTable.\n", cookie);
1543 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1546 lock_ReleaseRead(&buf_globalLock);
1550 void buf_ForceTrace(BOOL flush)
1559 len = GetTempPath(sizeof(buf)-10, buf);
1560 StringCbCopyA(&buf[len], sizeof(buf)-len, "/afs-buffer.log");
1561 handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
1562 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1563 if (handle == INVALID_HANDLE_VALUE) {
1564 osi_panic("Cannot create log file", __FILE__, __LINE__);
1566 osi_LogPrint(buf_logp, handle);
1568 FlushFileBuffers(handle);
1569 CloseHandle(handle);
1572 long buf_DirtyBuffersExist(cm_fid_t *fidp)
1575 afs_uint32 bcount = 0;
1577 for (bp = cm_data.buf_allp; bp; bp=bp->allp, bcount++) {
1578 if (!cm_FidCmp(fidp, &bp->fid) && (bp->flags & CM_BUF_DIRTY))
1585 long buf_CleanDirtyBuffers(cm_scache_t *scp)
1588 afs_uint32 bcount = 0;
1589 cm_fid_t * fidp = &scp->fid;
1591 for (bp = cm_data.buf_allp; bp; bp=bp->allp, bcount++) {
1592 if (!cm_FidCmp(fidp, &bp->fid) && (bp->flags & CM_BUF_DIRTY)) {
1594 lock_ObtainMutex(&bp->mx);
1595 bp->cmFlags &= ~CM_BUF_CMSTORING;
1596 bp->flags &= ~CM_BUF_DIRTY;
1597 bp->flags |= CM_BUF_ERROR;
1598 bp->error = VNOVNODE;
1599 bp->dataVersion = -1; /* bad */
1601 if (bp->flags & CM_BUF_WAITING) {
1602 osi_Log2(buf_logp, "BUF CleanDirtyBuffers Waking [scp 0x%x] bp 0x%x", scp, bp);
1603 osi_Wakeup((long) &bp);
1605 lock_ReleaseMutex(&bp->mx);