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 #include <afs/param.h>
24 /*extern void afsi_log(char *pattern, ...);*/
26 extern osi_hyper_t hzero;
29 osi_queue_t *cm_allFileLocks;
30 osi_queue_t *cm_freeFileLocks;
31 unsigned long cm_lockRefreshCycle;
33 /* lock for globals */
34 osi_rwlock_t cm_scacheLock;
36 /* Dummy scache entry for use with pioctl fids */
37 cm_scache_t cm_fakeSCache;
39 osi_queue_t * cm_allFreeWaiters; /* protected by cm_scacheLock */
41 #ifdef AFS_FREELANCE_CLIENT
42 extern osi_mutex_t cm_Freelance_Lock;
45 /* must be called with cm_scacheLock write-locked! */
46 void cm_AdjustScacheLRU(cm_scache_t *scp)
48 if (scp == cm_data.scacheLRULastp)
49 cm_data.scacheLRULastp = (cm_scache_t *) osi_QPrev(&scp->q);
50 osi_QRemoveHT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
51 osi_QAdd((osi_queue_t **) &cm_data.scacheLRUFirstp, &scp->q);
52 if (!cm_data.scacheLRULastp)
53 cm_data.scacheLRULastp = scp;
56 /* call with scache write-locked and mutex held */
57 void cm_RemoveSCacheFromHashTable(cm_scache_t *scp)
63 if (scp->flags & CM_SCACHEFLAG_INHASH) {
64 /* hash it out first */
65 i = CM_SCACHE_HASH(&scp->fid);
66 for (lscpp = &cm_data.scacheHashTablep[i], tscp = cm_data.scacheHashTablep[i];
68 lscpp = &tscp->nextp, tscp = tscp->nextp) {
71 scp->flags &= ~CM_SCACHEFLAG_INHASH;
78 /* called with cm_scacheLock write-locked; recycles an existing scp.
80 * this function ignores all of the locking hierarchy.
82 long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags)
84 if (scp->refCount != 0) {
88 if (scp->flags & CM_SCACHEFLAG_SMB_FID) {
89 osi_Log1(afsd_logp,"cm_RecycleSCache CM_SCACHEFLAG_SMB_FID detected scp 0x%p", scp);
91 osi_panic("cm_RecycleSCache CM_SCACHEFLAG_SMB_FID detected",__FILE__,__LINE__);
96 cm_RemoveSCacheFromHashTable(scp);
99 if (flags & CM_SCACHE_RECYCLEFLAG_DESTROY_BUFFERS) {
100 osi_queueData_t *qdp;
103 while(qdp = scp->bufWritesp) {
104 bufp = osi_GetQData(qdp);
105 osi_QRemove((osi_queue_t **) &scp->bufWritesp, &qdp->q);
108 lock_ObtainMutex(&bufp->mx);
109 bufp->cmFlags &= ~CM_BUF_CMSTORING;
110 bufp->flags &= ~CM_BUF_DIRTY;
111 bufp->dirty_offset = 0;
112 bufp->dirty_length = 0;
113 bufp->flags |= CM_BUF_ERROR;
114 bufp->error = VNOVNODE;
115 bufp->dataVersion = -1; /* bad */
116 bufp->dirtyCounter++;
117 if (bufp->flags & CM_BUF_WAITING) {
118 osi_Log2(afsd_logp, "CM RecycleSCache Waking [scp 0x%x] bufp 0x%x", scp, bufp);
119 osi_Wakeup((long) &bufp);
121 lock_ReleaseMutex(&bufp->mx);
125 while(qdp = scp->bufReadsp) {
126 bufp = osi_GetQData(qdp);
127 osi_QRemove((osi_queue_t **) &scp->bufReadsp, &qdp->q);
130 lock_ObtainMutex(&bufp->mx);
131 bufp->cmFlags &= ~CM_BUF_CMFETCHING;
132 bufp->flags &= ~CM_BUF_DIRTY;
133 bufp->dirty_offset = 0;
134 bufp->dirty_length = 0;
135 bufp->flags |= CM_BUF_ERROR;
136 bufp->error = VNOVNODE;
137 bufp->dataVersion = -1; /* bad */
138 bufp->dirtyCounter++;
139 if (bufp->flags & CM_BUF_WAITING) {
140 osi_Log2(afsd_logp, "CM RecycleSCache Waking [scp 0x%x] bufp 0x%x", scp, bufp);
141 osi_Wakeup((long) &bufp);
143 lock_ReleaseMutex(&bufp->mx);
147 buf_CleanDirtyBuffers(scp);
149 /* look for things that shouldn't still be set */
150 osi_assertx(scp->bufWritesp == NULL, "non-null cm_scache_t bufWritesp");
151 osi_assertx(scp->bufReadsp == NULL, "non-null cm_scache_t bufReadsp");
155 /* invalidate so next merge works fine;
156 * also initialize some flags */
158 scp->flags &= ~(CM_SCACHEFLAG_STATD
159 | CM_SCACHEFLAG_DELETED
161 | CM_SCACHEFLAG_PURERO
162 | CM_SCACHEFLAG_OVERQUOTA
163 | CM_SCACHEFLAG_OUTOFSPACE
164 | CM_SCACHEFLAG_EACCESS);
165 scp->serverModTime = 0;
166 scp->dataVersion = 0;
167 scp->bufDataVersionLow = 0;
168 scp->bulkStatProgress = hzero;
170 scp->waitQueueT = NULL;
172 if (scp->cbServerp) {
173 cm_PutServer(scp->cbServerp);
174 scp->cbServerp = NULL;
184 /* remove from dnlc */
188 /* discard cached status; if non-zero, Close
189 * tried to store this to server but failed */
192 /* drop held volume ref */
194 cm_PutVolume(scp->volp);
198 /* discard symlink info */
199 scp->mountPointStringp[0] = '\0';
200 memset(&scp->mountRootFid, 0, sizeof(cm_fid_t));
201 memset(&scp->dotdotFid, 0, sizeof(cm_fid_t));
203 /* reset locking info */
204 scp->fileLocksH = NULL;
205 scp->fileLocksT = NULL;
206 scp->serverLock = (-1);
207 scp->exclusiveLocks = 0;
208 scp->sharedLocks = 0;
209 scp->lockDataVersion = -1;
211 /* not locked, but there can be no references to this guy
212 * while we hold the global refcount lock.
214 cm_FreeAllACLEnts(scp);
217 /* destroy directory Bplus Tree */
219 LARGE_INTEGER start, end;
220 QueryPerformanceCounter(&start);
222 freeBtree(scp->dirBplus);
223 scp->dirBplus = NULL;
224 QueryPerformanceCounter(&end);
226 bplus_free_time += (end.QuadPart - start.QuadPart);
233 /* called with cm_scacheLock write-locked; find a vnode to recycle.
234 * Can allocate a new one if desperate, or if below quota (cm_data.maxSCaches).
236 cm_scache_t *cm_GetNewSCache(void)
242 /* first pass - look for deleted objects */
243 for ( scp = cm_data.scacheLRULastp;
245 scp = (cm_scache_t *) osi_QPrev(&scp->q))
247 osi_assertx(scp >= cm_data.scacheBaseAddress && scp < (cm_scache_t *)cm_data.scacheHashTablep,
248 "invalid cm_scache_t address");
250 if (scp->refCount == 0) {
251 if (scp->flags & CM_SCACHEFLAG_DELETED) {
252 osi_Log1(afsd_logp, "GetNewSCache attempting to recycle deleted scp 0x%x", scp);
253 if (!cm_RecycleSCache(scp, CM_SCACHE_RECYCLEFLAG_DESTROY_BUFFERS)) {
255 /* we found an entry, so return it */
256 /* now remove from the LRU queue and put it back at the
257 * head of the LRU queue.
259 cm_AdjustScacheLRU(scp);
264 osi_Log1(afsd_logp, "GetNewSCache recycled failed scp 0x%x", scp);
265 } else if (!(scp->flags & CM_SCACHEFLAG_INHASH)) {
266 /* we found an entry, so return it */
267 /* now remove from the LRU queue and put it back at the
268 * head of the LRU queue.
270 cm_AdjustScacheLRU(scp);
277 osi_Log0(afsd_logp, "GetNewSCache no deleted or recycled entries available for reuse");
280 if (cm_data.currentSCaches >= cm_data.maxSCaches) {
281 /* There were no deleted scache objects that we could use. Try to find
282 * one that simply hasn't been used in a while.
284 for ( scp = cm_data.scacheLRULastp;
286 scp = (cm_scache_t *) osi_QPrev(&scp->q))
288 /* It is possible for the refCount to be zero and for there still
289 * to be outstanding dirty buffers. If there are dirty buffers,
290 * we must not recycle the scp. */
291 if (scp->refCount == 0 && scp->bufReadsp == NULL && scp->bufWritesp == NULL) {
292 if (!buf_DirtyBuffersExist(&scp->fid)) {
293 if (!cm_RecycleSCache(scp, 0)) {
294 /* we found an entry, so return it */
295 /* now remove from the LRU queue and put it back at the
296 * head of the LRU queue.
298 cm_AdjustScacheLRU(scp);
304 osi_Log1(afsd_logp,"GetNewSCache dirty buffers exist scp 0x%x", scp);
308 osi_Log1(afsd_logp, "GetNewSCache all scache entries in use (retry = %d)", retry);
313 /* if we get here, we should allocate a new scache entry. We either are below
314 * quota or we have a leak and need to allocate a new one to avoid panicing.
316 scp = cm_data.scacheBaseAddress + cm_data.currentSCaches;
317 osi_assertx(scp >= cm_data.scacheBaseAddress && scp < (cm_scache_t *)cm_data.scacheHashTablep,
318 "invalid cm_scache_t address");
319 memset(scp, 0, sizeof(cm_scache_t));
320 scp->magic = CM_SCACHE_MAGIC;
321 lock_InitializeMutex(&scp->mx, "cm_scache_t mutex");
322 lock_InitializeRWLock(&scp->bufCreateLock, "cm_scache_t bufCreateLock");
324 lock_InitializeRWLock(&scp->dirlock, "cm_scache_t dirlock");
326 scp->serverLock = -1;
328 /* and put it in the LRU queue */
329 osi_QAdd((osi_queue_t **) &cm_data.scacheLRUFirstp, &scp->q);
330 if (!cm_data.scacheLRULastp)
331 cm_data.scacheLRULastp = scp;
332 cm_data.currentSCaches++;
333 cm_dnlcPurgedp(scp); /* make doubly sure that this is not in dnlc */
335 scp->allNextp = cm_data.allSCachesp;
336 cm_data.allSCachesp = scp;
340 void cm_SetFid(cm_fid_t *fidp, afs_uint32 cell, afs_uint32 volume, afs_uint32 vnode, afs_uint32 unique)
343 fidp->volume = volume;
345 fidp->unique = unique;
346 fidp->hash = ((cell & 0xF) << 28) | ((volume & 0x3F) << 22) | ((vnode & 0x7FF) << 11) | (unique & 0x7FF);
349 /* like strcmp, only for fids */
350 __inline int cm_FidCmp(cm_fid_t *ap, cm_fid_t *bp)
352 if (ap->hash != bp->hash)
354 if (ap->vnode != bp->vnode)
356 if (ap->volume != bp->volume)
358 if (ap->unique != bp->unique)
360 if (ap->cell != bp->cell)
365 void cm_fakeSCacheInit(int newFile)
368 memset(&cm_data.fakeSCache, 0, sizeof(cm_scache_t));
369 cm_data.fakeSCache.cbServerp = (struct cm_server *)(-1);
370 /* can leave clientModTime at 0 */
371 cm_data.fakeSCache.fileType = CM_SCACHETYPE_FILE;
372 cm_data.fakeSCache.unixModeBits = 0777;
373 cm_data.fakeSCache.length.LowPart = 1000;
374 cm_data.fakeSCache.linkCount = 1;
375 cm_data.fakeSCache.refCount = 1;
377 lock_InitializeMutex(&cm_data.fakeSCache.mx, "cm_scache_t mutex");
381 cm_ValidateSCache(void)
383 cm_scache_t * scp, *lscp;
386 if ( cm_data.scacheLRUFirstp == NULL && cm_data.scacheLRULastp != NULL ||
387 cm_data.scacheLRUFirstp != NULL && cm_data.scacheLRULastp == NULL) {
388 afsi_log("cm_ValidateSCache failure: inconsistent LRU pointers");
389 fprintf(stderr, "cm_ValidateSCache failure: inconsistent LRU pointers\n");
393 for ( scp = cm_data.scacheLRUFirstp, lscp = NULL, i = 0;
395 lscp = scp, scp = (cm_scache_t *) osi_QNext(&scp->q), i++ ) {
396 if (scp->magic != CM_SCACHE_MAGIC) {
397 afsi_log("cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC");
398 fprintf(stderr, "cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC\n");
401 if (scp->nextp && scp->nextp->magic != CM_SCACHE_MAGIC) {
402 afsi_log("cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC");
403 fprintf(stderr, "cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC\n");
406 if (scp->randomACLp && scp->randomACLp->magic != CM_ACLENT_MAGIC) {
407 afsi_log("cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC");
408 fprintf(stderr, "cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC\n");
411 if (scp->volp && scp->volp->magic != CM_VOLUME_MAGIC) {
412 afsi_log("cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC");
413 fprintf(stderr, "cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC\n");
416 if (i > cm_data.currentSCaches ) {
417 afsi_log("cm_ValidateSCache failure: LRU First queue loops");
418 fprintf(stderr, "cm_ValidateSCache failure: LUR First queue loops\n");
421 if (lscp != (cm_scache_t *) osi_QPrev(&scp->q)) {
422 afsi_log("cm_ValidateSCache failure: QPrev(scp) != previous");
423 fprintf(stderr, "cm_ValidateSCache failure: QPrev(scp) != previous\n");
428 for ( scp = cm_data.scacheLRULastp, lscp = NULL, i = 0; scp;
429 lscp = scp, scp = (cm_scache_t *) osi_QPrev(&scp->q), i++ ) {
430 if (scp->magic != CM_SCACHE_MAGIC) {
431 afsi_log("cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC");
432 fprintf(stderr, "cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC\n");
435 if (scp->nextp && scp->nextp->magic != CM_SCACHE_MAGIC) {
436 afsi_log("cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC");
437 fprintf(stderr, "cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC\n");
440 if (scp->randomACLp && scp->randomACLp->magic != CM_ACLENT_MAGIC) {
441 afsi_log("cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC");
442 fprintf(stderr, "cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC\n");
445 if (scp->volp && scp->volp->magic != CM_VOLUME_MAGIC) {
446 afsi_log("cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC");
447 fprintf(stderr, "cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC\n");
450 if (i > cm_data.currentSCaches ) {
451 afsi_log("cm_ValidateSCache failure: LRU Last queue loops");
452 fprintf(stderr, "cm_ValidateSCache failure: LUR Last queue loops\n");
455 if (lscp != (cm_scache_t *) osi_QNext(&scp->q)) {
456 afsi_log("cm_ValidateSCache failure: QNext(scp) != next");
457 fprintf(stderr, "cm_ValidateSCache failure: QNext(scp) != next\n");
462 for ( i=0; i < cm_data.scacheHashTableSize; i++ ) {
463 for ( scp = cm_data.scacheHashTablep[i]; scp; scp = scp->nextp ) {
464 if (scp->magic != CM_SCACHE_MAGIC) {
465 afsi_log("cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC");
466 fprintf(stderr, "cm_ValidateSCache failure: scp->magic != CM_SCACHE_MAGIC\n");
469 if (scp->nextp && scp->nextp->magic != CM_SCACHE_MAGIC) {
470 afsi_log("cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC");
471 fprintf(stderr, "cm_ValidateSCache failure: scp->nextp->magic != CM_SCACHE_MAGIC\n");
474 if (scp->randomACLp && scp->randomACLp->magic != CM_ACLENT_MAGIC) {
475 afsi_log("cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC");
476 fprintf(stderr, "cm_ValidateSCache failure: scp->randomACLp->magic != CM_ACLENT_MAGIC\n");
479 if (scp->volp && scp->volp->magic != CM_VOLUME_MAGIC) {
480 afsi_log("cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC");
481 fprintf(stderr, "cm_ValidateSCache failure: scp->volp->magic != CM_VOLUME_MAGIC\n");
487 return cm_dnlcValidate();
491 cm_SuspendSCache(void)
496 cm_GiveUpAllCallbacksAllServers(TRUE);
499 * After this call all servers are marked down.
500 * Do not clear the callbacks, instead change the
501 * expiration time so that the callbacks will be expired
502 * when the servers are marked back up. However, we
503 * want the callbacks to be preserved as long as the
504 * servers are down. That way if the machine resumes
505 * without network, the stat cache item will still be
510 lock_ObtainWrite(&cm_scacheLock);
511 for ( scp = cm_data.allSCachesp; scp; scp = scp->allNextp ) {
512 if (scp->cbServerp) {
513 if (scp->flags & CM_SCACHEFLAG_PURERO && scp->volp) {
514 if (scp->volp->cbExpiresRO == scp->cbExpires) {
515 scp->volp->cbExpiresRO = now+1;
518 scp->cbExpires = now+1;
521 lock_ReleaseWrite(&cm_scacheLock);
525 cm_ShutdownSCache(void)
529 lock_ObtainWrite(&cm_scacheLock);
531 for ( scp = cm_data.allSCachesp; scp;
532 scp = scp->allNextp ) {
533 if (scp->randomACLp) {
534 lock_ObtainMutex(&scp->mx);
535 cm_FreeAllACLEnts(scp);
536 lock_ReleaseMutex(&scp->mx);
539 if (scp->cbServerp) {
540 cm_PutServer(scp->cbServerp);
541 scp->cbServerp = NULL;
544 scp->flags &= ~CM_SCACHEFLAG_CALLBACK;
548 freeBtree(scp->dirBplus);
549 scp->dirBplus = NULL;
550 scp->dirDataVersion = -1;
551 lock_FinalizeRWLock(&scp->dirlock);
553 lock_FinalizeMutex(&scp->mx);
554 lock_FinalizeRWLock(&scp->bufCreateLock);
556 lock_ReleaseWrite(&cm_scacheLock);
558 cm_GiveUpAllCallbacksAllServers(FALSE);
560 return cm_dnlcShutdown();
563 void cm_InitSCache(int newFile, long maxSCaches)
565 static osi_once_t once;
567 if (osi_Once(&once)) {
568 lock_InitializeRWLock(&cm_scacheLock, "cm_scacheLock");
570 memset(cm_data.scacheHashTablep, 0, sizeof(cm_scache_t *) * cm_data.scacheHashTableSize);
571 cm_data.allSCachesp = NULL;
572 cm_data.currentSCaches = 0;
573 cm_data.maxSCaches = maxSCaches;
574 cm_data.scacheLRUFirstp = cm_data.scacheLRULastp = NULL;
578 for ( scp = cm_data.allSCachesp; scp;
579 scp = scp->allNextp ) {
580 lock_InitializeMutex(&scp->mx, "cm_scache_t mutex");
581 lock_InitializeRWLock(&scp->bufCreateLock, "cm_scache_t bufCreateLock");
583 lock_InitializeRWLock(&scp->dirlock, "cm_scache_t dirlock");
585 scp->cbServerp = NULL;
587 scp->fileLocksH = NULL;
588 scp->fileLocksT = NULL;
589 scp->serverLock = (-1);
590 scp->lastRefreshCycle = 0;
591 scp->exclusiveLocks = 0;
592 scp->sharedLocks = 0;
599 scp->dirBplus = NULL;
600 scp->dirDataVersion = -1;
602 scp->waitQueueT = NULL;
603 scp->flags &= ~CM_SCACHEFLAG_WAITING;
606 cm_allFileLocks = NULL;
607 cm_freeFileLocks = NULL;
608 cm_lockRefreshCycle = 0;
609 cm_fakeSCacheInit(newFile);
610 cm_allFreeWaiters = NULL;
611 cm_dnlcInit(newFile);
616 /* version that doesn't bother creating the entry if we don't find it */
617 cm_scache_t *cm_FindSCache(cm_fid_t *fidp)
622 hash = CM_SCACHE_HASH(fidp);
624 if (fidp->cell == 0) {
628 lock_ObtainWrite(&cm_scacheLock);
629 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
630 if (cm_FidCmp(fidp, &scp->fid) == 0) {
631 cm_HoldSCacheNoLock(scp);
632 cm_AdjustScacheLRU(scp);
633 lock_ReleaseWrite(&cm_scacheLock);
637 lock_ReleaseWrite(&cm_scacheLock);
641 #ifdef DEBUG_REFCOUNT
642 long cm_GetSCacheDbg(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
643 cm_req_t *reqp, char * file, long line)
645 long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
652 cm_volume_t *volp = NULL;
654 int special = 0; // yj: boolean variable to test if file is on root.afs
656 extern cm_fid_t cm_rootFid;
658 hash = CM_SCACHE_HASH(fidp);
660 osi_assertx(fidp->cell != 0, "unassigned cell value");
662 if (fidp->cell== cm_data.rootFid.cell &&
663 fidp->volume==cm_data.rootFid.volume &&
664 fidp->vnode==0x0 && fidp->unique==0x0)
666 osi_Log0(afsd_logp,"cm_GetSCache called with root cell/volume and vnode=0 and unique=0");
669 // yj: check if we have the scp, if so, we don't need
670 // to do anything else
671 lock_ObtainWrite(&cm_scacheLock);
672 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
673 if (cm_FidCmp(fidp, &scp->fid) == 0) {
674 #ifdef DEBUG_REFCOUNT
675 afsi_log("%s:%d cm_GetSCache (1) outScpp 0x%p ref %d", file, line, scp, scp->refCount);
676 osi_Log1(afsd_logp,"cm_GetSCache (1) outScpp 0x%p", scp);
678 cm_HoldSCacheNoLock(scp);
680 cm_AdjustScacheLRU(scp);
681 lock_ReleaseWrite(&cm_scacheLock);
686 // yj: when we get here, it means we don't have an scp
687 // so we need to either load it or fake it, depending
688 // on whether the file is "special", see below.
690 // yj: if we're trying to get an scp for a file that's
691 // on root.afs of homecell, we want to handle it specially
692 // because we have to fill in the status stuff 'coz we
693 // don't want trybulkstat to fill it in for us
694 #ifdef AFS_FREELANCE_CLIENT
695 special = (fidp->cell==AFS_FAKE_ROOT_CELL_ID &&
696 fidp->volume==AFS_FAKE_ROOT_VOL_ID &&
697 !(fidp->vnode==0x1 && fidp->unique==0x1));
698 isRoot = (fidp->cell==AFS_FAKE_ROOT_CELL_ID &&
699 fidp->volume==AFS_FAKE_ROOT_VOL_ID &&
700 fidp->vnode==0x1 && fidp->unique==0x1);
701 if (cm_freelanceEnabled && isRoot) {
702 osi_Log0(afsd_logp,"cm_GetSCache Freelance and isRoot");
703 /* freelance: if we are trying to get the root scp for the first
704 * time, we will just put in a place holder entry.
709 if (cm_freelanceEnabled && special) {
710 char mp[MOUNTPOINTLEN] = "";
713 osi_Log0(afsd_logp,"cm_GetSCache Freelance and special");
714 lock_ObtainMutex(&cm_Freelance_Lock);
715 if (fidp->vnode >= 2 && fidp->vnode - 2 < cm_noLocalMountPoints) {
716 strncpy(mp,(cm_localMountPoints+fidp->vnode-2)->mountPointStringp, MOUNTPOINTLEN);
717 mp[MOUNTPOINTLEN-1] = '\0';
718 if ( !strnicmp(mp, "msdfs:", strlen("msdfs:")) )
719 fileType = CM_SCACHETYPE_DFSLINK;
721 fileType = (cm_localMountPoints+fidp->vnode-2)->fileType;
723 fileType = CM_SCACHETYPE_INVALID;
726 lock_ReleaseMutex(&cm_Freelance_Lock);
728 scp = cm_GetNewSCache();
730 osi_Log0(afsd_logp,"cm_GetSCache unable to obtain *new* scache entry");
731 lock_ReleaseWrite(&cm_scacheLock);
732 return CM_ERROR_WOULDBLOCK;
735 #if not_too_dangerous
736 /* dropping the cm_scacheLock allows more than one thread
737 * to obtain the same cm_scache_t from the LRU list. Since
738 * the refCount is known to be zero at this point we have to
739 * assume that no one else is using the one this is returned.
741 lock_ReleaseWrite(&cm_scacheLock);
742 lock_ObtainMutex(&scp->mx);
743 lock_ObtainWrite(&cm_scacheLock);
746 scp->volp = cm_data.rootSCachep->volp;
747 cm_GetVolume(scp->volp); /* grab an additional reference */
748 scp->dotdotFid.cell=AFS_FAKE_ROOT_CELL_ID;
749 scp->dotdotFid.volume=AFS_FAKE_ROOT_VOL_ID;
750 scp->dotdotFid.unique=1;
751 scp->dotdotFid.vnode=1;
752 scp->flags |= (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO);
753 scp->nextp=cm_data.scacheHashTablep[hash];
754 cm_data.scacheHashTablep[hash]=scp;
755 scp->flags |= CM_SCACHEFLAG_INHASH;
757 osi_Log1(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%x", scp);
758 scp->fileType = fileType;
759 scp->length.LowPart = (DWORD)strlen(mp)+4;
760 scp->length.HighPart = 0;
761 strncpy(scp->mountPointStringp,mp,MOUNTPOINTLEN);
763 scp->unixModeBits=0777;
764 scp->clientModTime=FakeFreelanceModTime;
765 scp->serverModTime=FakeFreelanceModTime;
766 scp->parentUnique = 0x1;
767 scp->parentVnode=0x1;
769 scp->dataVersion=cm_data.fakeDirVersion;
770 scp->bufDataVersionLow=cm_data.fakeDirVersion;
771 scp->lockDataVersion=-1; /* no lock yet */
772 #if not_too_dangerous
773 lock_ReleaseMutex(&scp->mx);
776 lock_ReleaseWrite(&cm_scacheLock);
777 #ifdef DEBUG_REFCOUNT
778 afsi_log("%s:%d cm_GetSCache (2) outScpp 0x%p ref %d", file, line, scp, scp->refCount);
779 osi_Log1(afsd_logp,"cm_GetSCache (2) outScpp 0x%p", scp);
784 #endif /* AFS_FREELANCE_CLIENT */
786 /* otherwise, we need to find the volume */
787 if (!cm_freelanceEnabled || !isRoot) {
788 lock_ReleaseWrite(&cm_scacheLock); /* for perf. reasons */
789 cellp = cm_FindCellByID(fidp->cell, 0);
791 return CM_ERROR_NOSUCHCELL;
793 code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
796 lock_ObtainWrite(&cm_scacheLock);
799 /* otherwise, we have the volume, now reverify that the scp doesn't
800 * exist, and proceed.
802 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
803 if (cm_FidCmp(fidp, &scp->fid) == 0) {
804 #ifdef DEBUG_REFCOUNT
805 afsi_log("%s:%d cm_GetSCache (3) outScpp 0x%p ref %d", file, line, scp, scp->refCount);
806 osi_Log1(afsd_logp,"cm_GetSCache (3) outScpp 0x%p", scp);
808 cm_HoldSCacheNoLock(scp);
809 osi_assertx(scp->volp == volp, "cm_scache_t volume has unexpected value");
810 cm_AdjustScacheLRU(scp);
811 lock_ReleaseWrite(&cm_scacheLock);
819 /* now, if we don't have the fid, recycle something */
820 scp = cm_GetNewSCache();
822 osi_Log0(afsd_logp,"cm_GetNewSCache unable to obtain *new* scache entry");
823 lock_ReleaseWrite(&cm_scacheLock);
826 return CM_ERROR_WOULDBLOCK;
828 osi_Log2(afsd_logp,"cm_GetNewSCache returns scp 0x%x flags 0x%x", scp, scp->flags);
830 osi_assertx(!(scp->flags & CM_SCACHEFLAG_INHASH), "CM_SCACHEFLAG_INHASH set");
832 #if not_too_dangerous
833 /* dropping the cm_scacheLock allows more than one thread
834 * to obtain the same cm_scache_t from the LRU list. Since
835 * the refCount is known to be zero at this point we have to
836 * assume that no one else is using the one this is returned.
838 lock_ReleaseWrite(&cm_scacheLock);
839 lock_ObtainMutex(&scp->mx);
840 lock_ObtainWrite(&cm_scacheLock);
843 scp->volp = volp; /* a held reference */
845 if (!cm_freelanceEnabled || !isRoot) {
846 /* if this scache entry represents a volume root then we need
847 * to copy the dotdotFipd from the volume structure where the
848 * "master" copy is stored (defect 11489)
850 if (scp->fid.vnode == 1 && scp->fid.unique == 1) {
851 scp->dotdotFid = volp->dotdotFid;
854 if (volp->ro.ID == fidp->volume)
855 scp->flags |= (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO);
856 else if (volp->bk.ID == fidp->volume)
857 scp->flags |= CM_SCACHEFLAG_RO;
859 scp->nextp = cm_data.scacheHashTablep[hash];
860 cm_data.scacheHashTablep[hash] = scp;
861 scp->flags |= CM_SCACHEFLAG_INHASH;
863 osi_Log1(afsd_logp,"cm_GetSCache sets refCount to 1 scp 0x%x", scp);
864 #if not_too_dangerous
865 lock_ReleaseMutex(&scp->mx);
868 /* XXX - The following fields in the cm_scache are
874 lock_ReleaseWrite(&cm_scacheLock);
876 /* now we have a held scache entry; just return it */
878 #ifdef DEBUG_REFCOUNT
879 afsi_log("%s:%d cm_GetSCache (4) outScpp 0x%p ref %d", file, line, scp, scp->refCount);
880 osi_Log1(afsd_logp,"cm_GetSCache (4) outScpp 0x%p", scp);
885 /* Returns a held reference to the scache's parent
887 cm_scache_t * cm_FindSCacheParent(cm_scache_t * scp)
892 cm_scache_t * pscp = NULL;
894 lock_ObtainWrite(&cm_scacheLock);
895 cm_SetFid(&parent_fid, scp->fid.cell, scp->fid.volume, scp->parentVnode, scp->parentUnique);
897 if (cm_FidCmp(&scp->fid, &parent_fid)) {
898 i = CM_SCACHE_HASH(&parent_fid);
899 for (pscp = cm_data.scacheHashTablep[i]; pscp; pscp = pscp->nextp) {
900 if (!cm_FidCmp(&pscp->fid, &parent_fid)) {
901 cm_HoldSCacheNoLock(pscp);
907 lock_ReleaseWrite(&cm_scacheLock);
912 void cm_SyncOpAddToWaitQueue(cm_scache_t * scp, afs_int32 flags, cm_buf_t * bufp)
914 cm_scache_waiter_t * w;
916 /* Do not use the queue for asynchronous store operations */
917 if (flags == CM_SCACHESYNC_ASYNCSTORE)
920 lock_ObtainWrite(&cm_scacheLock);
921 if (cm_allFreeWaiters == NULL) {
922 w = malloc(sizeof(*w));
923 memset(w, 0, sizeof(*w));
925 w = (cm_scache_waiter_t *) cm_allFreeWaiters;
926 osi_QRemove(&cm_allFreeWaiters, (osi_queue_t *) w);
929 w->threadId = thrd_Current();
931 cm_HoldSCacheNoLock(scp);
935 osi_QAddT(&scp->waitQueueH, &scp->waitQueueT, (osi_queue_t *) w);
936 lock_ReleaseWrite(&cm_scacheLock);
938 osi_Log2(afsd_logp, "cm_SyncOpAddToWaitQueue : Adding thread to wait queue scp 0x%p w 0x%p", scp, w);
941 int cm_SyncOpCheckContinue(cm_scache_t * scp, afs_int32 flags, cm_buf_t * bufp)
943 cm_scache_waiter_t * w;
946 /* Do not use the queue for asynchronous store operations */
947 if (flags == CM_SCACHESYNC_ASYNCSTORE)
950 osi_Log0(afsd_logp, "cm_SyncOpCheckContinue checking for continuation");
952 lock_ObtainRead(&cm_scacheLock);
953 for (w = (cm_scache_waiter_t *)scp->waitQueueH;
955 w = (cm_scache_waiter_t *)osi_QNext((osi_queue_t *) w)) {
956 if (w->flags == flags && w->bufp == bufp) {
961 osi_assertx(w != NULL, "null cm_scache_waiter_t");
962 this_is_me = (w->threadId == thrd_Current());
963 lock_ReleaseRead(&cm_scacheLock);
966 osi_Log1(afsd_logp, "cm_SyncOpCheckContinue MISS: Waiter 0x%p", w);
970 osi_Log1(afsd_logp, "cm_SyncOpCheckContinue HIT: Waiter 0x%p", w);
972 lock_ObtainWrite(&cm_scacheLock);
973 osi_QRemoveHT(&scp->waitQueueH, &scp->waitQueueT, (osi_queue_t *) w);
974 cm_ReleaseSCacheNoLock(scp);
975 memset(w, 0, sizeof(*w));
976 osi_QAdd(&cm_allFreeWaiters, (osi_queue_t *) w);
977 lock_ReleaseWrite(&cm_scacheLock);
983 /* synchronize a fetch, store, read, write, fetch status or store status.
984 * Called with scache mutex held, and returns with it held, but temporarily
985 * drops it during the fetch.
987 * At most one flag can be on in flags, if this is an RPC request.
989 * Also, if we're fetching or storing data, we must ensure that we have a buffer.
991 * There are a lot of weird restrictions here; here's an attempt to explain the
992 * rationale for the concurrency restrictions implemented in this function.
994 * First, although the file server will break callbacks when *another* machine
995 * modifies a file or status block, the client itself is responsible for
996 * concurrency control on its own requests. Callback breaking events are rare,
997 * and simply invalidate any concurrent new status info.
999 * In the absence of callback breaking messages, we need to know how to
1000 * synchronize incoming responses describing updates to files. We synchronize
1001 * operations that update the data version by comparing the data versions.
1002 * However, updates that do not update the data, but only the status, can't be
1003 * synchronized with fetches or stores, since there's nothing to compare
1004 * to tell which operation executed first at the server.
1006 * Thus, we can allow multiple ops that change file data, or dir data, and
1007 * fetches. However, status storing ops have to be done serially.
1009 * Furthermore, certain data-changing ops are incompatible: we can't read or
1010 * write a buffer while doing a truncate. We can't read and write the same
1011 * buffer at the same time, or write while fetching or storing, or read while
1012 * fetching a buffer (this may change). We can't fetch and store at the same
1015 * With respect to status, we can't read and write at the same time, read while
1016 * fetching, write while fetching or storing, or fetch and store at the same time.
1018 * We can't allow a get callback RPC to run in concurrently with something that
1019 * will return updated status, since we could start a call, have the server
1020 * return status, have another machine make an update to the status (which
1021 * doesn't change serverModTime), have the original machine get a new callback,
1022 * and then have the original machine merge in the early, old info from the
1023 * first call. At this point, the easiest way to avoid this problem is to have
1024 * getcallback calls conflict with all others for the same vnode. Other calls
1025 * to cm_MergeStatus that aren't associated with calls to cm_SyncOp on the same
1026 * vnode must be careful not to merge in their status unless they have obtained
1027 * a callback from the start of their call.
1029 * Note added 1/23/96
1030 * Concurrent StoreData RPC's can cause trouble if the file is being extended.
1031 * Each such RPC passes a FileLength parameter, which the server uses to do
1032 * pre-truncation if necessary. So if two RPC's are processed out of order at
1033 * the server, the one with the smaller FileLength will be processed last,
1034 * possibly resulting in a bogus truncation. The simplest way to avoid this
1035 * is to serialize all StoreData RPC's. This is the reason we defined
1036 * CM_SCACHESYNC_STOREDATA_EXCL and CM_SCACHEFLAG_DATASTORING.
1038 long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *userp, cm_req_t *reqp,
1039 afs_uint32 rights, afs_uint32 flags)
1041 osi_queueData_t *qdp;
1044 afs_uint32 outRights;
1046 afs_uint32 sleep_scp_flags = 0;
1047 afs_uint32 sleep_buf_cmflags = 0;
1048 afs_uint32 sleep_scp_bufs = 0;
1051 /* lookup this first */
1052 bufLocked = flags & CM_SCACHESYNC_BUFLOCKED;
1055 osi_assertx(bufp->refCount > 0, "cm_buf_t refCount 0");
1058 /* Do the access check. Now we don't really do the access check
1059 * atomically, since the caller doesn't expect the parent dir to be
1060 * returned locked, and that is what we'd have to do to prevent a
1061 * callback breaking message on the parent due to a setacl call from
1062 * being processed while we're running. So, instead, we check things
1063 * here, and if things look fine with the access, we proceed to finish
1064 * the rest of this check. Sort of a hack, but probably good enough.
1068 if (flags & CM_SCACHESYNC_FETCHSTATUS) {
1069 /* if we're bringing in a new status block, ensure that
1070 * we aren't already doing so, and that no one is
1071 * changing the status concurrently, either. We need
1072 * to do this, even if the status is of a different
1073 * type, since we don't have the ability to figure out,
1074 * in the AFS 3 protocols, which status-changing
1075 * operation ran first, or even which order a read and
1076 * a write occurred in.
1078 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING
1079 | CM_SCACHEFLAG_SIZESTORING | CM_SCACHEFLAG_GETCALLBACK)) {
1080 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING|GETCALLBACK want FETCHSTATUS", scp);
1084 if (flags & (CM_SCACHESYNC_STORESIZE | CM_SCACHESYNC_STORESTATUS
1085 | CM_SCACHESYNC_SETSIZE | CM_SCACHESYNC_GETCALLBACK)) {
1086 /* if we're going to make an RPC to change the status, make sure
1087 * that no one is bringing in or sending out the status.
1089 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING |
1090 CM_SCACHEFLAG_SIZESTORING | CM_SCACHEFLAG_GETCALLBACK)) {
1091 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING|GETCALLBACK want STORESIZE|STORESTATUS|SETSIZE|GETCALLBACK", scp);
1094 if (scp->bufReadsp || scp->bufWritesp) {
1095 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is bufRead|bufWrite want STORESIZE|STORESTATUS|SETSIZE|GETCALLBACK", scp);
1099 if (flags & CM_SCACHESYNC_FETCHDATA) {
1100 /* if we're bringing in a new chunk of data, make sure that
1101 * nothing is happening to that chunk, and that we aren't
1102 * changing the basic file status info, either.
1104 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING
1105 | CM_SCACHEFLAG_SIZESTORING | CM_SCACHEFLAG_GETCALLBACK)) {
1106 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING|GETCALLBACK want FETCHDATA", scp);
1109 if (bufp && (bufp->cmFlags & (CM_BUF_CMFETCHING | CM_BUF_CMSTORING | CM_BUF_CMWRITING))) {
1110 osi_Log2(afsd_logp, "CM SyncOp scp 0x%p bufp 0x%p is BUF_CMFETCHING|BUF_CMSTORING|BUF_CMWRITING want FETCHDATA", scp, bufp);
1114 if (flags & CM_SCACHESYNC_STOREDATA) {
1115 /* same as fetch data */
1116 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING
1117 | CM_SCACHEFLAG_SIZESTORING | CM_SCACHEFLAG_GETCALLBACK)) {
1118 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING|GETCALLBACK want STOREDATA", scp);
1121 if (bufp && (bufp->cmFlags & (CM_BUF_CMFETCHING | CM_BUF_CMSTORING | CM_BUF_CMWRITING))) {
1122 osi_Log2(afsd_logp, "CM SyncOp scp 0x%p bufp 0x%p is BUF_CMFETCHING|BUF_CMSTORING|BUF_CMWRITING want STOREDATA", scp, bufp);
1127 if (flags & CM_SCACHESYNC_STOREDATA_EXCL) {
1128 /* Don't allow concurrent StoreData RPC's */
1129 if (scp->flags & CM_SCACHEFLAG_DATASTORING) {
1130 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is DATASTORING want STOREDATA_EXCL", scp);
1135 if (flags & CM_SCACHESYNC_ASYNCSTORE) {
1136 /* Don't allow more than one BKG store request */
1137 if (scp->flags & CM_SCACHEFLAG_ASYNCSTORING) {
1138 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is ASYNCSTORING want ASYNCSTORE", scp);
1143 if (flags & CM_SCACHESYNC_LOCK) {
1144 /* Don't allow concurrent fiddling with lock lists */
1145 if (scp->flags & CM_SCACHEFLAG_LOCKING) {
1146 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is LOCKING want LOCK", scp);
1151 /* now the operations that don't correspond to making RPCs */
1152 if (flags & CM_SCACHESYNC_GETSTATUS) {
1153 /* we can use the status that's here, if we're not
1154 * bringing in new status.
1156 if (scp->flags & (CM_SCACHEFLAG_FETCHING)) {
1157 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING want GETSTATUS", scp);
1161 if (flags & CM_SCACHESYNC_SETSTATUS) {
1162 /* we can make a change to the local status, as long as
1163 * the status isn't changing now.
1165 * If we're fetching or storing a chunk of data, we can
1166 * change the status locally, since the fetch/store
1167 * operations don't change any of the data that we're
1170 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING | CM_SCACHEFLAG_SIZESTORING)) {
1171 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING want SETSTATUS", scp);
1175 if (flags & CM_SCACHESYNC_READ) {
1176 /* we're going to read the data, make sure that the
1177 * status is available, and that the data is here. It
1178 * is OK to read while storing the data back.
1180 if (scp->flags & CM_SCACHEFLAG_FETCHING) {
1181 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING want READ", scp);
1184 if (bufp && ((bufp->cmFlags & (CM_BUF_CMFETCHING | CM_BUF_CMFULLYFETCHED)) == CM_BUF_CMFETCHING)) {
1185 osi_Log2(afsd_logp, "CM SyncOp scp 0x%p bufp 0x%p is BUF_CMFETCHING want READ", scp, bufp);
1188 if (bufp && (bufp->cmFlags & CM_BUF_CMWRITING)) {
1189 osi_Log2(afsd_logp, "CM SyncOp scp 0x%p bufp 0x%p is BUF_CMWRITING want READ", scp, bufp);
1193 if (flags & CM_SCACHESYNC_WRITE) {
1194 /* don't write unless the status is stable and the chunk
1197 if (scp->flags & (CM_SCACHEFLAG_FETCHING | CM_SCACHEFLAG_STORING
1198 | CM_SCACHEFLAG_SIZESTORING)) {
1199 osi_Log1(afsd_logp, "CM SyncOp scp 0x%p is FETCHING|STORING|SIZESTORING want WRITE", scp);
1202 if (bufp && (bufp->cmFlags & (CM_BUF_CMFETCHING |
1204 CM_BUF_CMWRITING))) {
1205 osi_Log3(afsd_logp, "CM SyncOp scp 0x%p bufp 0x%p is %s want WRITE",
1207 ((bufp->cmFlags & CM_BUF_CMFETCHING) ? "CM_BUF_CMFETCHING":
1208 ((bufp->cmFlags & CM_BUF_CMSTORING) ? "CM_BUF_CMSTORING" :
1209 ((bufp->cmFlags & CM_BUF_CMWRITING) ? "CM_BUF_CMWRITING" :
1215 // yj: modified this so that callback only checked if we're
1216 // not checking something on /afs
1217 /* fix the conditional to match the one in cm_HaveCallback */
1218 if ((flags & CM_SCACHESYNC_NEEDCALLBACK)
1219 #ifdef AFS_FREELANCE_CLIENT
1220 && (!cm_freelanceEnabled ||
1221 !(scp->fid.vnode==0x1 && scp->fid.unique==0x1) ||
1222 scp->fid.cell!=AFS_FAKE_ROOT_CELL_ID ||
1223 scp->fid.volume!=AFS_FAKE_ROOT_VOL_ID ||
1224 cm_fakeDirCallback < 2)
1225 #endif /* AFS_FREELANCE_CLIENT */
1227 if ((flags & CM_SCACHESYNC_FORCECB) || !cm_HaveCallback(scp)) {
1228 osi_Log1(afsd_logp, "CM SyncOp getting callback on scp 0x%p",
1231 lock_ReleaseMutex(&bufp->mx);
1232 code = cm_GetCallback(scp, userp, reqp, (flags & CM_SCACHESYNC_FORCECB)?1:0);
1234 lock_ReleaseMutex(&scp->mx);
1235 lock_ObtainMutex(&bufp->mx);
1236 lock_ObtainMutex(&scp->mx);
1240 flags &= ~CM_SCACHESYNC_FORCECB; /* only force once */
1246 /* can't check access rights without a callback */
1247 osi_assertx(flags & CM_SCACHESYNC_NEEDCALLBACK, "!CM_SCACHESYNC_NEEDCALLBACK");
1249 if ((rights & PRSFS_WRITE) && (scp->flags & CM_SCACHEFLAG_RO))
1250 return CM_ERROR_READONLY;
1252 if (cm_HaveAccessRights(scp, userp, rights, &outRights)) {
1253 if (~outRights & rights)
1254 return CM_ERROR_NOACCESS;
1257 /* we don't know the required access rights */
1258 if (bufLocked) lock_ReleaseMutex(&bufp->mx);
1259 code = cm_GetAccessRights(scp, userp, reqp);
1261 lock_ReleaseMutex(&scp->mx);
1262 lock_ObtainMutex(&bufp->mx);
1263 lock_ObtainMutex(&scp->mx);
1271 /* if we get here, we're happy */
1275 /* first check if we're not supposed to wait: fail
1276 * in this case, returning with everything still locked.
1278 if (flags & CM_SCACHESYNC_NOWAIT)
1279 return CM_ERROR_WOULDBLOCK;
1281 /* These are used for minidump debugging */
1282 sleep_scp_flags = scp->flags; /* so we know why we slept */
1283 sleep_buf_cmflags = bufp ? bufp->cmFlags : 0;
1284 sleep_scp_bufs = (scp->bufReadsp ? 1 : 0) | (scp->bufWritesp ? 2 : 0);
1286 /* wait here, then try again */
1287 osi_Log1(afsd_logp, "CM SyncOp sleeping scp 0x%p", scp);
1288 if ( scp->flags & CM_SCACHEFLAG_WAITING ) {
1290 scp->waitRequests++;
1291 osi_Log3(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING already set for 0x%p; %d threads; %d requests",
1292 scp, scp->waitCount, scp->waitRequests);
1294 osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING set for 0x%p", scp);
1295 scp->flags |= CM_SCACHEFLAG_WAITING;
1296 scp->waitCount = scp->waitRequests = 1;
1299 cm_SyncOpAddToWaitQueue(scp, flags, bufp);
1303 lock_ReleaseMutex(&bufp->mx);
1304 osi_SleepM((LONG_PTR) &scp->flags, &scp->mx);
1306 lock_ObtainMutex(&bufp->mx);
1307 lock_ObtainMutex(&scp->mx);
1308 } while (!cm_SyncOpCheckContinue(scp, flags, bufp));
1310 smb_UpdateServerPriority();
1313 osi_Log3(afsd_logp, "CM SyncOp woke! scp 0x%p; still waiting %d threads of %d requests",
1314 scp, scp->waitCount, scp->waitRequests);
1315 if (scp->waitCount == 0) {
1316 osi_Log1(afsd_logp, "CM SyncOp CM_SCACHEFLAG_WAITING reset for 0x%p", scp);
1317 scp->flags &= ~CM_SCACHEFLAG_WAITING;
1318 scp->waitRequests = 0;
1320 } /* big while loop */
1322 /* now, update the recorded state for RPC-type calls */
1323 if (flags & CM_SCACHESYNC_FETCHSTATUS)
1324 scp->flags |= CM_SCACHEFLAG_FETCHING;
1325 if (flags & CM_SCACHESYNC_STORESTATUS)
1326 scp->flags |= CM_SCACHEFLAG_STORING;
1327 if (flags & CM_SCACHESYNC_STORESIZE)
1328 scp->flags |= CM_SCACHEFLAG_SIZESTORING;
1329 if (flags & CM_SCACHESYNC_GETCALLBACK)
1330 scp->flags |= CM_SCACHEFLAG_GETCALLBACK;
1331 if (flags & CM_SCACHESYNC_STOREDATA_EXCL)
1332 scp->flags |= CM_SCACHEFLAG_DATASTORING;
1333 if (flags & CM_SCACHESYNC_ASYNCSTORE)
1334 scp->flags |= CM_SCACHEFLAG_ASYNCSTORING;
1335 if (flags & CM_SCACHESYNC_LOCK)
1336 scp->flags |= CM_SCACHEFLAG_LOCKING;
1338 /* now update the buffer pointer */
1339 if (flags & CM_SCACHESYNC_FETCHDATA) {
1340 /* ensure that the buffer isn't already in the I/O list */
1342 for(qdp = scp->bufReadsp; qdp; qdp = (osi_queueData_t *) osi_QNext(&qdp->q)) {
1343 tbufp = osi_GetQData(qdp);
1344 osi_assertx(tbufp != bufp, "unexpected cm_buf_t value");
1348 /* queue a held reference to the buffer in the "reading" I/O list */
1349 qdp = osi_QDAlloc();
1350 osi_SetQData(qdp, bufp);
1353 bufp->cmFlags |= CM_BUF_CMFETCHING;
1355 osi_QAdd((osi_queue_t **) &scp->bufReadsp, &qdp->q);
1358 if (flags & CM_SCACHESYNC_STOREDATA) {
1359 /* ensure that the buffer isn't already in the I/O list */
1361 for(qdp = scp->bufWritesp; qdp; qdp = (osi_queueData_t *) osi_QNext(&qdp->q)) {
1362 tbufp = osi_GetQData(qdp);
1363 osi_assertx(tbufp != bufp, "unexpected cm_buf_t value");
1367 /* queue a held reference to the buffer in the "writing" I/O list */
1368 qdp = osi_QDAlloc();
1369 osi_SetQData(qdp, bufp);
1372 bufp->cmFlags |= CM_BUF_CMSTORING;
1374 osi_QAdd((osi_queue_t **) &scp->bufWritesp, &qdp->q);
1377 if (flags & CM_SCACHESYNC_WRITE) {
1378 /* mark the buffer as being written to. */
1380 bufp->cmFlags |= CM_BUF_CMWRITING;
1387 /* for those syncops that setup for RPCs.
1388 * Called with scache locked.
1390 void cm_SyncOpDone(cm_scache_t *scp, cm_buf_t *bufp, afs_uint32 flags)
1392 osi_queueData_t *qdp;
1395 lock_AssertMutex(&scp->mx);
1397 /* now, update the recorded state for RPC-type calls */
1398 if (flags & CM_SCACHESYNC_FETCHSTATUS)
1399 scp->flags &= ~CM_SCACHEFLAG_FETCHING;
1400 if (flags & CM_SCACHESYNC_STORESTATUS)
1401 scp->flags &= ~CM_SCACHEFLAG_STORING;
1402 if (flags & CM_SCACHESYNC_STORESIZE)
1403 scp->flags &= ~CM_SCACHEFLAG_SIZESTORING;
1404 if (flags & CM_SCACHESYNC_GETCALLBACK)
1405 scp->flags &= ~CM_SCACHEFLAG_GETCALLBACK;
1406 if (flags & CM_SCACHESYNC_STOREDATA_EXCL)
1407 scp->flags &= ~CM_SCACHEFLAG_DATASTORING;
1408 if (flags & CM_SCACHESYNC_ASYNCSTORE)
1409 scp->flags &= ~CM_SCACHEFLAG_ASYNCSTORING;
1410 if (flags & CM_SCACHESYNC_LOCK)
1411 scp->flags &= ~CM_SCACHEFLAG_LOCKING;
1413 /* now update the buffer pointer */
1414 if (flags & CM_SCACHESYNC_FETCHDATA) {
1417 /* ensure that the buffer isn't already in the I/O list */
1418 for(qdp = scp->bufReadsp; qdp; qdp = (osi_queueData_t *) osi_QNext(&qdp->q)) {
1419 tbufp = osi_GetQData(qdp);
1424 osi_QRemove((osi_queue_t **) &scp->bufReadsp, &qdp->q);
1429 bufp->cmFlags &= ~(CM_BUF_CMFETCHING | CM_BUF_CMFULLYFETCHED);
1430 if (bufp->flags & CM_BUF_WAITING) {
1431 osi_Log2(afsd_logp, "CM SyncOpDone Waking [scp 0x%p] bufp 0x%p", scp, bufp);
1432 osi_Wakeup((LONG_PTR) &bufp);
1439 /* now update the buffer pointer */
1440 if (flags & CM_SCACHESYNC_STOREDATA) {
1442 /* ensure that the buffer isn't already in the I/O list */
1443 for(qdp = scp->bufWritesp; qdp; qdp = (osi_queueData_t *) osi_QNext(&qdp->q)) {
1444 tbufp = osi_GetQData(qdp);
1449 osi_QRemove((osi_queue_t **) &scp->bufWritesp, &qdp->q);
1454 bufp->cmFlags &= ~CM_BUF_CMSTORING;
1455 if (bufp->flags & CM_BUF_WAITING) {
1456 osi_Log2(afsd_logp, "CM SyncOpDone Waking [scp 0x%p] bufp 0x%p", scp, bufp);
1457 osi_Wakeup((LONG_PTR) &bufp);
1464 if (flags & CM_SCACHESYNC_WRITE) {
1466 osi_assertx(bufp->cmFlags & CM_BUF_CMWRITING, "!CM_BUF_CMWRITING");
1468 bufp->cmFlags &= ~CM_BUF_CMWRITING;
1472 /* and wakeup anyone who is waiting */
1473 if (scp->flags & CM_SCACHEFLAG_WAITING) {
1474 osi_Log1(afsd_logp, "CM SyncOpDone Waking scp 0x%p", scp);
1475 osi_Wakeup((LONG_PTR) &scp->flags);
1479 /* merge in a response from an RPC. The scp must be locked, and the callback
1482 * Don't overwrite any status info that is dirty, since we could have a store
1483 * operation (such as store data) that merges some info in, and we don't want
1484 * to lose the local updates. Typically, there aren't many updates we do
1485 * locally, anyway, probably only mtime.
1487 * There is probably a bug in here where a chmod (which doesn't change
1488 * serverModTime) that occurs between two fetches, both of whose responses are
1489 * handled after the callback breaking is done, but only one of whose calls
1490 * started before that, can cause old info to be merged from the first call.
1492 void cm_MergeStatus(cm_scache_t *dscp,
1493 cm_scache_t *scp, AFSFetchStatus *statusp,
1494 AFSVolSync *volsyncp,
1495 cm_user_t *userp, afs_uint32 flags)
1497 afs_uint64 dataVersion;
1499 // yj: i want to create some fake status for the /afs directory and the
1500 // entries under that directory
1501 #ifdef AFS_FREELANCE_CLIENT
1502 if (cm_freelanceEnabled && scp == cm_data.rootSCachep) {
1503 osi_Log0(afsd_logp,"cm_MergeStatus Freelance cm_data.rootSCachep");
1504 statusp->InterfaceVersion = 0x1;
1505 statusp->FileType = CM_SCACHETYPE_DIRECTORY;
1506 statusp->LinkCount = scp->linkCount;
1507 statusp->Length = cm_fakeDirSize;
1508 statusp->Length_hi = 0;
1509 statusp->DataVersion = (afs_uint32)(cm_data.fakeDirVersion & 0xFFFFFFFF);
1510 statusp->Author = 0x1;
1511 statusp->Owner = 0x0;
1512 statusp->CallerAccess = 0x9;
1513 statusp->AnonymousAccess = 0x9;
1514 statusp->UnixModeBits = 0777;
1515 statusp->ParentVnode = 0x1;
1516 statusp->ParentUnique = 0x1;
1517 statusp->ResidencyMask = 0;
1518 statusp->ClientModTime = FakeFreelanceModTime;
1519 statusp->ServerModTime = FakeFreelanceModTime;
1521 statusp->SyncCounter = 0;
1522 statusp->dataVersionHigh = (afs_uint32)(cm_data.fakeDirVersion >> 32);
1523 statusp->errorCode = 0;
1525 buf_ForceDataVersion(scp, scp->dataVersion, cm_data.fakeDirVersion);
1527 #endif /* AFS_FREELANCE_CLIENT */
1529 if (statusp->errorCode != 0) {
1530 scp->flags |= CM_SCACHEFLAG_EACCESS;
1531 osi_Log2(afsd_logp, "Merge, Failure scp %x code 0x%x", scp, statusp->errorCode);
1533 scp->fileType = 0; /* unknown */
1535 scp->serverModTime = 0;
1536 scp->clientModTime = 0;
1537 scp->length.LowPart = 0;
1538 scp->length.HighPart = 0;
1539 scp->serverLength.LowPart = 0;
1540 scp->serverLength.HighPart = 0;
1544 scp->unixModeBits = 0;
1546 scp->dataVersion = 0;
1547 scp->bufDataVersionLow = 0;
1550 scp->parentVnode = dscp->fid.vnode;
1551 scp->parentUnique = dscp->fid.unique;
1553 scp->parentVnode = 0;
1554 scp->parentUnique = 0;
1558 scp->flags &= ~CM_SCACHEFLAG_EACCESS;
1561 dataVersion = statusp->dataVersionHigh;
1563 dataVersion |= statusp->DataVersion;
1565 if (!(flags & CM_MERGEFLAG_FORCE) && dataVersion < scp->dataVersion) {
1566 struct cm_cell *cellp;
1568 cellp = cm_FindCellByID(scp->fid.cell, 0);
1569 if (scp->cbServerp) {
1570 struct cm_volume *volp = NULL;
1572 cm_GetVolumeByID(cellp, scp->fid.volume, userp,
1573 (cm_req_t *) NULL, CM_GETVOL_FLAG_CREATE, &volp);
1574 osi_Log2(afsd_logp, "old data from server %x volume %s",
1575 scp->cbServerp->addr.sin_addr.s_addr,
1576 volp ? volp->namep : "(unknown)");
1580 osi_Log3(afsd_logp, "Bad merge, scp %x, scp dv %I64d, RPC dv %I64d",
1581 scp, scp->dataVersion, dataVersion);
1582 /* we have a number of data fetch/store operations running
1583 * concurrently, and we can tell which one executed last at the
1584 * server by its mtime.
1585 * Choose the one with the largest mtime, and ignore the rest.
1587 * These concurrent calls are incompatible with setting the
1588 * mtime, so we won't have a locally changed mtime here.
1590 * We could also have ACL info for a different user than usual,
1591 * in which case we have to do that part of the merge, anyway.
1592 * We won't have to worry about the info being old, since we
1593 * won't have concurrent calls
1594 * that change file status running from this machine.
1596 * Added 3/17/98: if we see data version regression on an RO
1597 * file, it's probably due to a server holding an out-of-date
1598 * replica, rather than to concurrent RPC's. Failures to
1599 * release replicas are now flagged by the volserver, but only
1600 * since AFS 3.4 5.22, so there are plenty of clients getting
1601 * out-of-date replicas out there.
1603 * If we discover an out-of-date replica, by this time it's too
1604 * late to go to another server and retry. Also, we can't
1605 * reject the merge, because then there is no way for
1606 * GetAccess to do its work, and the caller gets into an
1607 * infinite loop. So we just grin and bear it.
1609 if (!(scp->flags & CM_SCACHEFLAG_RO))
1613 scp->serverModTime = statusp->ServerModTime;
1615 if (!(scp->mask & CM_SCACHEMASK_CLIENTMODTIME)) {
1616 scp->clientModTime = statusp->ClientModTime;
1618 if (!(scp->mask & CM_SCACHEMASK_LENGTH)) {
1619 scp->length.LowPart = statusp->Length;
1620 scp->length.HighPart = statusp->Length_hi;
1623 scp->serverLength.LowPart = statusp->Length;
1624 scp->serverLength.HighPart = statusp->Length_hi;
1626 scp->linkCount = statusp->LinkCount;
1627 scp->owner = statusp->Owner;
1628 scp->group = statusp->Group;
1629 scp->unixModeBits = statusp->UnixModeBits & 07777;
1631 if (statusp->FileType == File)
1632 scp->fileType = CM_SCACHETYPE_FILE;
1633 else if (statusp->FileType == Directory)
1634 scp->fileType = CM_SCACHETYPE_DIRECTORY;
1635 else if (statusp->FileType == SymbolicLink) {
1636 if ((scp->unixModeBits & 0111) == 0)
1637 scp->fileType = CM_SCACHETYPE_MOUNTPOINT;
1639 scp->fileType = CM_SCACHETYPE_SYMLINK;
1642 osi_Log2(afsd_logp, "Merge, Invalid File Type (%d), scp %x", statusp->FileType, scp);
1643 scp->fileType = CM_SCACHETYPE_INVALID; /* invalid */
1645 /* and other stuff */
1646 scp->parentVnode = statusp->ParentVnode;
1647 scp->parentUnique = statusp->ParentUnique;
1649 /* and merge in the private acl cache info, if this is more than the public
1650 * info; merge in the public stuff in any case.
1652 scp->anyAccess = statusp->AnonymousAccess;
1654 if (userp != NULL) {
1655 cm_AddACLCache(scp, userp, statusp->CallerAccess);
1658 if (scp->dataVersion != 0 &&
1659 (!(flags & CM_MERGEFLAG_DIROP) && dataVersion != scp->dataVersion ||
1660 (flags & CM_MERGEFLAG_DIROP) && dataVersion - scp->dataVersion > 1)) {
1662 * We now know that all of the data buffers that we have associated
1663 * with this scp are invalid. Subsequent operations will go faster
1664 * if the buffers are removed from the hash tables.
1666 * We do not remove directory buffers if the dataVersion delta is 1 because
1667 * those version numbers will be updated as part of the directory operation.
1672 cm_buf_t *bp, *prevBp, *nextBp;
1674 lock_ObtainWrite(&buf_globalLock);
1675 i = BUF_FILEHASH(&scp->fid);
1676 for (bp = cm_data.buf_fileHashTablepp[i]; bp; bp=nextBp)
1678 nextBp = bp->fileHashp;
1680 * if the buffer belongs to this stat cache entry
1681 * and the buffer mutex can be obtained, check the
1682 * reference count and if it is zero, remove the buffer
1683 * from the hash tables. If there are references,
1684 * the buffer might be updated to the current version
1685 * so leave it in place.
1687 if (cm_FidCmp(&scp->fid, &bp->fid) == 0 &&
1688 lock_TryMutex(&bp->mx)) {
1689 if (bp->refCount == 0 &&
1690 !(bp->flags & CM_BUF_READING | CM_BUF_WRITING | CM_BUF_DIRTY)) {
1691 prevBp = bp->fileHashBackp;
1692 bp->fileHashBackp = bp->fileHashp = NULL;
1694 prevBp->fileHashp = nextBp;
1696 cm_data.buf_fileHashTablepp[i] = nextBp;
1698 nextBp->fileHashBackp = prevBp;
1700 j = BUF_HASH(&bp->fid, &bp->offset);
1701 lbpp = &(cm_data.buf_scacheHashTablepp[j]);
1702 for(tbp = *lbpp; tbp; lbpp = &tbp->hashp, tbp = *lbpp) {
1707 *lbpp = bp->hashp; /* hash out */
1710 bp->flags &= ~CM_BUF_INHASH;
1712 lock_ReleaseMutex(&bp->mx);
1715 lock_ReleaseWrite(&buf_globalLock);
1718 /* We maintain a range of buffer dataVersion values which are considered
1719 * valid. This avoids the need to update the dataVersion on each buffer
1720 * object during an uncontested storeData operation. As a result this
1721 * merge status no longer has performance characteristics derived from
1722 * the size of the file.
1724 if (((flags & CM_MERGEFLAG_STOREDATA) && dataVersion - scp->dataVersion > 1) ||
1725 (!(flags & CM_MERGEFLAG_STOREDATA) && scp->dataVersion != dataVersion))
1726 scp->bufDataVersionLow = dataVersion;
1728 scp->dataVersion = dataVersion;
1731 /* note that our stat cache info is incorrect, so force us eventually
1732 * to stat the file again. There may be dirty data associated with
1733 * this vnode, and we want to preserve that information.
1735 * This function works by simply simulating a loss of the callback.
1737 * This function must be called with the scache locked.
1739 void cm_DiscardSCache(cm_scache_t *scp)
1741 lock_AssertMutex(&scp->mx);
1742 if (scp->cbServerp) {
1743 cm_PutServer(scp->cbServerp);
1744 scp->cbServerp = NULL;
1747 scp->flags &= ~CM_SCACHEFLAG_CALLBACK;
1748 cm_dnlcPurgedp(scp);
1749 cm_dnlcPurgevp(scp);
1750 cm_FreeAllACLEnts(scp);
1752 if (scp->fileType == CM_SCACHETYPE_DFSLINK)
1753 cm_VolStatus_Invalidate_DFS_Mapping(scp);
1755 /* Force mount points and symlinks to be re-evaluated */
1756 scp->mountPointStringp[0] = '\0';
1759 void cm_AFSFidFromFid(AFSFid *afsFidp, cm_fid_t *fidp)
1761 afsFidp->Volume = fidp->volume;
1762 afsFidp->Vnode = fidp->vnode;
1763 afsFidp->Unique = fidp->unique;
1766 #ifdef DEBUG_REFCOUNT
1767 void cm_HoldSCacheNoLockDbg(cm_scache_t *scp, char * file, long line)
1769 void cm_HoldSCacheNoLock(cm_scache_t *scp)
1774 osi_assertx(scp != NULL, "null cm_scache_t");
1775 lock_AssertAny(&cm_scacheLock);
1776 refCount = InterlockedIncrement(&scp->refCount);
1777 #ifdef DEBUG_REFCOUNT
1778 osi_Log2(afsd_logp,"cm_HoldSCacheNoLock scp 0x%p ref %d",scp, refCount);
1779 afsi_log("%s:%d cm_HoldSCacheNoLock scp 0x%p, ref %d", file, line, scp, refCount);
1783 #ifdef DEBUG_REFCOUNT
1784 void cm_HoldSCacheDbg(cm_scache_t *scp, char * file, long line)
1786 void cm_HoldSCache(cm_scache_t *scp)
1791 osi_assertx(scp != NULL, "null cm_scache_t");
1792 lock_ObtainRead(&cm_scacheLock);
1793 refCount = InterlockedIncrement(&scp->refCount);
1794 #ifdef DEBUG_REFCOUNT
1795 osi_Log2(afsd_logp,"cm_HoldSCache scp 0x%p ref %d",scp, refCount);
1796 afsi_log("%s:%d cm_HoldSCache scp 0x%p ref %d", file, line, scp, refCount);
1798 lock_ReleaseRead(&cm_scacheLock);
1801 #ifdef DEBUG_REFCOUNT
1802 void cm_ReleaseSCacheNoLockDbg(cm_scache_t *scp, char * file, long line)
1804 void cm_ReleaseSCacheNoLock(cm_scache_t *scp)
1808 osi_assertx(scp != NULL, "null cm_scache_t");
1809 lock_AssertAny(&cm_scacheLock);
1810 refCount = InterlockedDecrement(&scp->refCount);
1811 #ifdef DEBUG_REFCOUNT
1813 osi_Log1(afsd_logp,"cm_ReleaseSCacheNoLock about to panic scp 0x%x",scp);
1815 osi_assertx(refCount >= 0, "cm_scache_t refCount 0");
1816 #ifdef DEBUG_REFCOUNT
1817 osi_Log2(afsd_logp,"cm_ReleaseSCacheNoLock scp 0x%p ref %d",scp, refCount);
1818 afsi_log("%s:%d cm_ReleaseSCacheNoLock scp 0x%p ref %d", file, line, scp, refCount);
1822 #ifdef DEBUG_REFCOUNT
1823 void cm_ReleaseSCacheDbg(cm_scache_t *scp, char * file, long line)
1825 void cm_ReleaseSCache(cm_scache_t *scp)
1830 osi_assertx(scp != NULL, "null cm_scache_t");
1831 lock_ObtainRead(&cm_scacheLock);
1832 refCount = InterlockedDecrement(&scp->refCount);
1833 #ifdef DEBUG_REFCOUNT
1835 osi_Log1(afsd_logp,"cm_ReleaseSCache about to panic scp 0x%x",scp);
1837 osi_assertx(refCount >= 0, "cm_scache_t refCount 0");
1838 #ifdef DEBUG_REFCOUNT
1839 osi_Log2(afsd_logp,"cm_ReleaseSCache scp 0x%p ref %d",scp, refCount);
1840 afsi_log("%s:%d cm_ReleaseSCache scp 0x%p ref %d", file, line, scp, refCount);
1842 lock_ReleaseRead(&cm_scacheLock);
1845 /* just look for the scp entry to get filetype */
1846 /* doesn't need to be perfectly accurate, so locking doesn't matter too much */
1847 int cm_FindFileType(cm_fid_t *fidp)
1852 hash = CM_SCACHE_HASH(fidp);
1854 osi_assertx(fidp->cell != 0, "unassigned cell value");
1856 lock_ObtainWrite(&cm_scacheLock);
1857 for (scp=cm_data.scacheHashTablep[hash]; scp; scp=scp->nextp) {
1858 if (cm_FidCmp(fidp, &scp->fid) == 0) {
1859 lock_ReleaseWrite(&cm_scacheLock);
1860 return scp->fileType;
1863 lock_ReleaseWrite(&cm_scacheLock);
1867 /* dump all scp's that have reference count > 0 to a file.
1868 * cookie is used to identify this batch for easy parsing,
1869 * and it a string provided by a caller
1871 int cm_DumpSCache(FILE *outputFile, char *cookie, int lock)
1879 lock_ObtainRead(&cm_scacheLock);
1881 sprintf(output, "%s - dumping all scache - cm_data.currentSCaches=%d, cm_data.maxSCaches=%d\r\n", cookie, cm_data.currentSCaches, cm_data.maxSCaches);
1882 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1884 for (scp = cm_data.allSCachesp; scp; scp = scp->allNextp)
1886 sprintf(output, "%s scp=0x%p, fid (cell=%d, volume=%d, vnode=%d, unique=%d) volp=0x%p type=%d dv=%I64d len=0x%I64x mp='%s' flags=0x%x cb=0x%x refCount=%u\r\n",
1887 cookie, scp, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
1888 scp->volp, scp->fileType, scp->dataVersion, scp->length.QuadPart, scp->mountPointStringp, scp->flags,
1889 (unsigned long)scp->cbExpires, scp->refCount);
1890 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1893 sprintf(output, "%s - Done dumping all scache.\r\n", cookie);
1894 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1895 sprintf(output, "%s - dumping cm_data.scacheHashTable - cm_data.scacheHashTableSize=%d\r\n", cookie, cm_data.scacheHashTableSize);
1896 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1898 for (i = 0; i < cm_data.scacheHashTableSize; i++)
1900 for(scp = cm_data.scacheHashTablep[i]; scp; scp=scp->nextp)
1902 sprintf(output, "%s scp=0x%p, hash=%d, fid (cell=%d, volume=%d, vnode=%d, unique=%d)\r\n",
1903 cookie, scp, i, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
1904 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1908 sprintf(output, "%s - Done dumping cm_data.scacheHashTable\r\n", cookie);
1909 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
1912 lock_ReleaseRead(&cm_scacheLock);