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
18 #include <afsconfig.h>
19 #include "afs/param.h"
24 #include "afs/sysincludes.h" /* Standard vendor system headers */
25 #include "afsincludes.h" /* Afs-based standard headers */
26 #include "afs/afs_stats.h" /* statistics */
27 #include "afs/afs_cbqueue.h"
28 #include "afs/nfsclient.h"
29 #include "afs/afs_osidnlc.h"
30 #include "afs/afs_osi.h"
33 extern char afs_zeros[AFS_ZEROS];
36 afs_int32 nihints; /* # of above actually in-use */
40 /* Imported variables */
41 extern afs_rwlock_t afs_xdcache;
42 extern unsigned char *afs_indexFlags;
43 extern afs_hyper_t *afs_indexTimes; /* Dcache entry Access times */
44 extern afs_hyper_t afs_indexCounter; /* Fake time for marking index */
47 /* Forward declarations */
48 void afs_PrefetchChunk(struct vcache *avc, struct dcache *adc,
49 struct AFS_UCRED *acred, struct vrequest *areq);
52 afs_MemRead(register struct vcache *avc, struct uio *auio,
53 struct AFS_UCRED *acred, daddr_t albn, struct buf **abpp,
56 afs_size_t totalLength;
57 afs_size_t transferLength;
59 afs_size_t offset, len, tlen;
61 struct dcache *tdc = 0;
62 afs_int32 error, trybusy = 1;
63 #ifdef AFS_DARWIN80_ENV
67 struct uio *tuiop = &tuio;
73 AFS_STATCNT(afs_MemRead);
77 /* check that we have the latest status info in the vnode cache */
78 if ((code = afs_InitReq(&treq, acred)))
81 code = afs_VerifyVCache(avc, &treq);
83 code = afs_CheckCode(code, &treq, 8); /* failed to get it */
87 #ifndef AFS_VM_RDWR_ENV
88 if (AFS_NFSXLATORREQ(acred)) {
90 (avc, PRSFS_READ, &treq,
91 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) {
92 return afs_CheckCode(EACCES, &treq, 9);
97 #ifndef AFS_DARWIN80_ENV
98 tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec));
100 totalLength = AFS_UIO_RESID(auio);
101 filePos = AFS_UIO_OFFSET(auio);
102 afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc,
103 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_INT32,
104 totalLength, ICL_TYPE_OFFSET,
105 ICL_HANDLE_OFFSET(avc->m.Length));
109 ObtainReadLock(&avc->lock);
110 #if defined(AFS_TEXT_ENV) && !defined(AFS_VM_RDWR_ENV)
111 if (avc->flushDV.high == AFS_MAXDV && avc->flushDV.low == AFS_MAXDV) {
112 hset(avc->flushDV, avc->m.DataVersion);
120 while (totalLength > 0) {
121 /* read all of the cached info */
122 if (filePos >= avc->m.Length)
123 break; /* all done */
126 ReleaseReadLock(&tdc->lock);
129 tdc = afs_FindDCache(avc, filePos);
131 ObtainReadLock(&tdc->lock);
132 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
133 len = tdc->f.chunkBytes - offset;
136 /* a tricky question: does the presence of the DFFetching flag
137 * mean that we're fetching the latest version of the file? No.
138 * The server could update the file as soon as the fetch responsible
139 * for the setting of the DFFetching flag completes.
141 * However, the presence of the DFFetching flag (visible under
142 * a dcache read lock since it is set and cleared only under a
143 * dcache write lock) means that we're fetching as good a version
144 * as was known to this client at the time of the last call to
145 * afs_VerifyVCache, since the latter updates the stat cache's
146 * m.DataVersion field under a vcache write lock, and from the
147 * time that the DFFetching flag goes on in afs_GetDCache (before
148 * the fetch starts), to the time it goes off (after the fetch
149 * completes), afs_GetDCache keeps at least a read lock on the
152 * This means that if the DFFetching flag is set, we can use that
153 * data for any reads that must come from the current version of
154 * the file (current == m.DataVersion).
156 * Another way of looking at this same point is this: if we're
157 * fetching some data and then try do an afs_VerifyVCache, the
158 * VerifyVCache operation will not complete until after the
159 * DFFetching flag is turned off and the dcache entry's f.versionNo
162 * Note, by the way, that if DFFetching is set,
163 * m.DataVersion > f.versionNo (the latter is not updated until
164 * after the fetch completes).
167 ReleaseReadLock(&tdc->lock);
168 afs_PutDCache(tdc); /* before reusing tdc */
170 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2);
171 ObtainReadLock(&tdc->lock);
172 /* now, first try to start transfer, if we'll need the data. If
173 * data already coming, we don't need to do this, obviously. Type
174 * 2 requests never return a null dcache entry, btw.
176 if (!(tdc->dflags & DFFetching)
177 && !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
178 /* have cache entry, it is not coming in now,
179 * and we'll need new data */
181 if (trybusy && !afs_BBusy()) {
183 /* daemon is not busy */
184 ObtainSharedLock(&tdc->mflock, 665);
185 if (!(tdc->mflags & DFFetchReq)) {
186 /* start the daemon (may already be running, however) */
187 UpgradeSToWLock(&tdc->mflock, 666);
188 tdc->mflags |= DFFetchReq;
189 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
190 (afs_size_t) filePos, (afs_size_t) 0,
193 tdc->mflags &= ~DFFetchReq;
194 trybusy = 0; /* Avoid bkg daemon since they're too busy */
195 ReleaseWriteLock(&tdc->mflock);
198 ConvertWToSLock(&tdc->mflock);
199 /* don't use bp pointer! */
202 ConvertSToRLock(&tdc->mflock);
203 while (!code && tdc->mflags & DFFetchReq) {
204 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT,
205 ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32,
206 __LINE__, ICL_TYPE_POINTER, tdc,
207 ICL_TYPE_INT32, tdc->dflags);
208 /* don't need waiting flag on this one */
209 ReleaseReadLock(&tdc->mflock);
210 ReleaseReadLock(&tdc->lock);
211 ReleaseReadLock(&avc->lock);
212 code = afs_osi_SleepSig(&tdc->validPos);
213 ObtainReadLock(&avc->lock);
214 ObtainReadLock(&tdc->lock);
215 ObtainReadLock(&tdc->mflock);
217 ReleaseReadLock(&tdc->mflock);
224 /* now data may have started flowing in (if DFFetching is on). If
225 * data is now streaming in, then wait for some interesting stuff.
228 while (!code && (tdc->dflags & DFFetching)
229 && tdc->validPos <= filePos) {
230 /* too early: wait for DFFetching flag to vanish,
231 * or data to appear */
232 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
233 __FILE__, ICL_TYPE_INT32, __LINE__,
234 ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32,
236 ReleaseReadLock(&tdc->lock);
237 ReleaseReadLock(&avc->lock);
238 code = afs_osi_SleepSig(&tdc->validPos);
239 ObtainReadLock(&avc->lock);
240 ObtainReadLock(&tdc->lock);
246 /* fetching flag gone, data is here, or we never tried
247 * (BBusy for instance) */
248 if (tdc->dflags & DFFetching) {
249 /* still fetching, some new data is here:
250 * compute length and offset */
251 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
252 len = tdc->validPos - filePos;
254 /* no longer fetching, verify data version
255 * (avoid new GetDCache call) */
256 if (hsame(avc->m.DataVersion, tdc->f.versionNo)
257 && ((len = tdc->validPos - filePos) > 0)) {
258 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
260 /* don't have current data, so get it below */
261 afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO,
262 ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos),
263 ICL_TYPE_HYPER, &avc->m.DataVersion,
264 ICL_TYPE_HYPER, &tdc->f.versionNo);
265 ReleaseReadLock(&tdc->lock);
272 /* If we get, it was not possible to start the
273 * background daemon. With flag == 1 afs_GetDCache
274 * does the FetchData rpc synchronously.
276 ReleaseReadLock(&avc->lock);
277 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
278 ObtainReadLock(&avc->lock);
280 ObtainReadLock(&tdc->lock);
284 afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc,
285 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset),
286 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len));
298 if (len > totalLength)
299 len = totalLength; /* will read len bytes */
300 if (len <= 0) { /* shouldn't get here if DFFetching is on */
301 /* read past the end of a chunk, may not be at next chunk yet, and yet
302 * also not at eof, so may have to supply fake zeros */
303 len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */
304 if (len > totalLength)
305 len = totalLength; /* and still within xfr request */
306 tlen = avc->m.Length - offset; /* and still within file */
310 len = sizeof(afs_zeros); /* and in 0 buffer */
311 #ifdef AFS_DARWIN80_ENV
313 tuiop = afsio_darwin_partialcopy(auio, trimlen);
315 afsio_copy(auio, &tuio, tvec);
317 afsio_trim(&tuio, trimlen);
319 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
325 /* get the data from the mem cache */
327 /* mung uio structure to be right for this transfer */
328 #ifdef AFS_DARWIN80_ENV
330 tuiop = afsio_darwin_partialcopy(auio, trimlen);
331 uio_setoffset(tuiop, offset);
333 afsio_copy(auio, &tuio, tvec);
335 afsio_trim(&tuio, trimlen);
336 tuio.afsio_offset = offset;
339 code = afs_MemReadUIO(tdc->f.inode, tuiop);
346 /* otherwise we've read some, fixup length, etc and continue with next seg */
347 len = len - AFS_UIO_RESID(tuiop); /* compute amount really transferred */
349 afsio_skip(auio, trimlen); /* update input uio structure */
351 transferLength += len;
355 break; /* surprise eof */
356 #ifdef AFS_DARWIN80_ENV
362 } /* the whole while loop */
367 * tdc->lock(R) if tdc
370 /* if we make it here with tdc non-zero, then it is the last chunk we
371 * dealt with, and we have to release it when we're done. We hold on
372 * to it in case we need to do a prefetch.
375 ReleaseReadLock(&tdc->lock);
376 #if !defined(AFS_VM_RDWR_ENV)
377 /* try to queue prefetch, if needed */
379 afs_PrefetchChunk(avc, tdc, acred, &treq);
385 ReleaseReadLock(&avc->lock);
386 #ifdef AFS_DARWIN80_ENV
390 osi_FreeSmallSpace(tvec);
392 error = afs_CheckCode(error, &treq, 10);
396 /* called with the dcache entry triggering the fetch, the vcache entry involved,
397 * and a vrequest for the read call. Marks the dcache entry as having already
398 * triggered a prefetch, starts the prefetch going and sets the DFFetchReq
399 * flag in the prefetched block, so that the next call to read knows to wait
400 * for the daemon to start doing things.
402 * This function must be called with the vnode at least read-locked, and
403 * no locks on the dcache, because it plays around with dcache entries.
406 afs_PrefetchChunk(struct vcache *avc, struct dcache *adc,
407 struct AFS_UCRED *acred, struct vrequest *areq)
409 register struct dcache *tdc;
411 afs_size_t j1, j2; /* junk vbls for GetDCache to trash */
413 offset = adc->f.chunk + 1; /* next chunk we'll need */
414 offset = AFS_CHUNKTOBASE(offset); /* base of next chunk */
415 ObtainReadLock(&adc->lock);
416 ObtainSharedLock(&adc->mflock, 662);
417 if (offset < avc->m.Length && !(adc->mflags & DFNextStarted)
421 UpgradeSToWLock(&adc->mflock, 663);
422 adc->mflags |= DFNextStarted; /* we've tried to prefetch for this guy */
423 ReleaseWriteLock(&adc->mflock);
424 ReleaseReadLock(&adc->lock);
426 tdc = afs_GetDCache(avc, offset, areq, &j1, &j2, 2); /* type 2 never returns 0 */
427 ObtainSharedLock(&tdc->mflock, 651);
428 if (!(tdc->mflags & DFFetchReq)) {
429 /* ask the daemon to do the work */
430 UpgradeSToWLock(&tdc->mflock, 652);
431 tdc->mflags |= DFFetchReq; /* guaranteed to be cleared by BKG or GetDCache */
432 /* last parm (1) tells bkg daemon to do an afs_PutDCache when it is done,
433 * since we don't want to wait for it to finish before doing so ourselves.
435 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
436 (afs_size_t) offset, (afs_size_t) 1, tdc);
438 /* Bkg table full; just abort non-important prefetching to avoid deadlocks */
439 tdc->mflags &= ~DFFetchReq;
440 ReleaseWriteLock(&tdc->mflock);
444 * DCLOCKXXX: This is a little sketchy, since someone else
445 * could have already started a prefetch.. In practice,
446 * this probably doesn't matter; at most it would cause an
447 * extra slot in the BKG table to be used up when someone
448 * prefetches this for the second time.
450 ObtainReadLock(&adc->lock);
451 ObtainWriteLock(&adc->mflock, 664);
452 adc->mflags &= ~DFNextStarted;
453 ReleaseWriteLock(&adc->mflock);
454 ReleaseReadLock(&adc->lock);
456 ReleaseWriteLock(&tdc->mflock);
459 ReleaseSharedLock(&tdc->mflock);
463 ReleaseSharedLock(&adc->mflock);
464 ReleaseReadLock(&adc->lock);
469 afs_UFSRead(register struct vcache *avc, struct uio *auio,
470 struct AFS_UCRED *acred, daddr_t albn, struct buf **abpp,
473 afs_size_t totalLength;
474 afs_size_t transferLength;
476 afs_size_t offset, len, tlen;
478 struct dcache *tdc = 0;
480 #ifdef AFS_DARWIN80_ENV
484 struct uio *tuiop = &tuio;
487 struct osi_file *tfile;
490 struct vrequest treq;
492 AFS_STATCNT(afs_UFSRead);
493 if (avc && avc->vc_error)
496 /* check that we have the latest status info in the vnode cache */
497 if ((code = afs_InitReq(&treq, acred)))
501 osi_Panic("null avc in afs_UFSRead");
503 code = afs_VerifyVCache(avc, &treq);
505 code = afs_CheckCode(code, &treq, 11); /* failed to get it */
510 #ifndef AFS_VM_RDWR_ENV
511 if (AFS_NFSXLATORREQ(acred)) {
513 (avc, PRSFS_READ, &treq,
514 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) {
515 return afs_CheckCode(EACCES, &treq, 12);
520 #ifndef AFS_DARWIN80_ENV
521 tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec));
523 totalLength = AFS_UIO_RESID(auio);
524 filePos = AFS_UIO_OFFSET(auio);
525 afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc,
526 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_INT32,
527 totalLength, ICL_TYPE_OFFSET,
528 ICL_HANDLE_OFFSET(avc->m.Length));
532 ObtainReadLock(&avc->lock);
533 #if defined(AFS_TEXT_ENV) && !defined(AFS_VM_RDWR_ENV)
534 if (avc->flushDV.high == AFS_MAXDV && avc->flushDV.low == AFS_MAXDV) {
535 hset(avc->flushDV, avc->m.DataVersion);
539 while (totalLength > 0) {
540 /* read all of the cached info */
541 if (filePos >= avc->m.Length)
542 break; /* all done */
545 ReleaseReadLock(&tdc->lock);
548 tdc = afs_FindDCache(avc, filePos);
550 ObtainReadLock(&tdc->lock);
551 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
552 len = tdc->validPos - filePos;
555 /* a tricky question: does the presence of the DFFetching flag
556 * mean that we're fetching the latest version of the file? No.
557 * The server could update the file as soon as the fetch responsible
558 * for the setting of the DFFetching flag completes.
560 * However, the presence of the DFFetching flag (visible under
561 * a dcache read lock since it is set and cleared only under a
562 * dcache write lock) means that we're fetching as good a version
563 * as was known to this client at the time of the last call to
564 * afs_VerifyVCache, since the latter updates the stat cache's
565 * m.DataVersion field under a vcache write lock, and from the
566 * time that the DFFetching flag goes on in afs_GetDCache (before
567 * the fetch starts), to the time it goes off (after the fetch
568 * completes), afs_GetDCache keeps at least a read lock on the
571 * This means that if the DFFetching flag is set, we can use that
572 * data for any reads that must come from the current version of
573 * the file (current == m.DataVersion).
575 * Another way of looking at this same point is this: if we're
576 * fetching some data and then try do an afs_VerifyVCache, the
577 * VerifyVCache operation will not complete until after the
578 * DFFetching flag is turned off and the dcache entry's f.versionNo
581 * Note, by the way, that if DFFetching is set,
582 * m.DataVersion > f.versionNo (the latter is not updated until
583 * after the fetch completes).
586 ReleaseReadLock(&tdc->lock);
587 afs_PutDCache(tdc); /* before reusing tdc */
589 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2);
590 ObtainReadLock(&tdc->lock);
591 /* now, first try to start transfer, if we'll need the data. If
592 * data already coming, we don't need to do this, obviously. Type
593 * 2 requests never return a null dcache entry, btw. */
594 if (!(tdc->dflags & DFFetching)
595 && !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
596 /* have cache entry, it is not coming in now, and we'll need new data */
598 if (trybusy && !afs_BBusy()) {
600 /* daemon is not busy */
601 ObtainSharedLock(&tdc->mflock, 667);
602 if (!(tdc->mflags & DFFetchReq)) {
603 UpgradeSToWLock(&tdc->mflock, 668);
604 tdc->mflags |= DFFetchReq;
605 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
606 (afs_size_t) filePos, (afs_size_t) 0,
609 /* Bkg table full; retry deadlocks */
610 tdc->mflags &= ~DFFetchReq;
611 trybusy = 0; /* Avoid bkg daemon since they're too busy */
612 ReleaseWriteLock(&tdc->mflock);
615 ConvertWToSLock(&tdc->mflock);
618 ConvertSToRLock(&tdc->mflock);
619 while (!code && tdc->mflags & DFFetchReq) {
620 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT,
621 ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32,
622 __LINE__, ICL_TYPE_POINTER, tdc,
623 ICL_TYPE_INT32, tdc->dflags);
624 /* don't need waiting flag on this one */
625 ReleaseReadLock(&tdc->mflock);
626 ReleaseReadLock(&tdc->lock);
627 ReleaseReadLock(&avc->lock);
628 code = afs_osi_SleepSig(&tdc->validPos);
629 ObtainReadLock(&avc->lock);
630 ObtainReadLock(&tdc->lock);
631 ObtainReadLock(&tdc->mflock);
633 ReleaseReadLock(&tdc->mflock);
640 /* now data may have started flowing in (if DFFetching is on). If
641 * data is now streaming in, then wait for some interesting stuff.
644 while (!code && (tdc->dflags & DFFetching)
645 && tdc->validPos <= filePos) {
646 /* too early: wait for DFFetching flag to vanish,
647 * or data to appear */
648 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
649 __FILE__, ICL_TYPE_INT32, __LINE__,
650 ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32,
652 ReleaseReadLock(&tdc->lock);
653 ReleaseReadLock(&avc->lock);
654 code = afs_osi_SleepSig(&tdc->validPos);
655 ObtainReadLock(&avc->lock);
656 ObtainReadLock(&tdc->lock);
662 /* fetching flag gone, data is here, or we never tried
663 * (BBusy for instance) */
664 if (tdc->dflags & DFFetching) {
665 /* still fetching, some new data is here:
666 * compute length and offset */
667 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
668 len = tdc->validPos - filePos;
670 /* no longer fetching, verify data version (avoid new
672 if (hsame(avc->m.DataVersion, tdc->f.versionNo)
673 && ((len = tdc->validPos - filePos) > 0)) {
674 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
676 /* don't have current data, so get it below */
677 afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO,
678 ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos),
679 ICL_TYPE_HYPER, &avc->m.DataVersion,
680 ICL_TYPE_HYPER, &tdc->f.versionNo);
681 ReleaseReadLock(&tdc->lock);
688 /* If we get, it was not possible to start the
689 * background daemon. With flag == 1 afs_GetDCache
690 * does the FetchData rpc synchronously.
692 ReleaseReadLock(&avc->lock);
693 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
694 ObtainReadLock(&avc->lock);
696 ObtainReadLock(&tdc->lock);
704 len = tdc->validPos - filePos;
705 afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc,
706 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset),
707 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len));
708 if (len > totalLength)
709 len = totalLength; /* will read len bytes */
710 if (len <= 0) { /* shouldn't get here if DFFetching is on */
711 afs_Trace4(afs_iclSetp, CM_TRACE_VNODEREAD2, ICL_TYPE_POINTER,
712 tdc, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(tdc->validPos),
713 ICL_TYPE_INT32, tdc->f.chunkBytes, ICL_TYPE_INT32,
715 /* read past the end of a chunk, may not be at next chunk yet, and yet
716 * also not at eof, so may have to supply fake zeros */
717 len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */
718 if (len > totalLength)
719 len = totalLength; /* and still within xfr request */
720 tlen = avc->m.Length - offset; /* and still within file */
724 len = sizeof(afs_zeros); /* and in 0 buffer */
725 #ifdef AFS_DARWIN80_ENV
727 tuiop = afsio_darwin_partialcopy(auio, trimlen);
729 afsio_copy(auio, &tuio, tvec);
731 afsio_trim(&tuio, trimlen);
733 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
739 /* get the data from the file */
741 if (tfile = tdc->ihint) {
742 if (tdc->f.inode != tfile->inum) {
743 afs_warn("afs_UFSRead: %x hint mismatch tdc %d inum %d\n",
744 tdc, tdc->f.inode, tfile->inum);
746 tdc->ihint = tfile = 0;
755 tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode);
756 #ifdef AFS_DARWIN80_ENV
758 tuiop = afsio_darwin_partialcopy(auio, trimlen);
759 uio_setoffset(tuiop, offset);
761 /* mung uio structure to be right for this transfer */
762 afsio_copy(auio, &tuio, tvec);
764 afsio_trim(&tuio, trimlen);
765 tuio.afsio_offset = offset;
768 #if defined(AFS_AIX41_ENV)
771 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL,
772 NULL, afs_osi_credp);
774 #elif defined(AFS_AIX32_ENV)
776 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL);
777 /* Flush all JFS pages now for big performance gain in big file cases
778 * If we do something like this, must check to be sure that AFS file
779 * isn't mmapped... see afs_gn_map() for why.
782 if (tfile->vnode->v_gnode && tfile->vnode->v_gnode->gn_seg) {
783 many different ways to do similar things:
784 so far, the best performing one is #2, but #1 might match it if we
785 straighten out the confusion regarding which pages to flush. It
787 1. vm_flushp(tfile->vnode->v_gnode->gn_seg, 0, len/PAGESIZE - 1);
788 2. vm_releasep(tfile->vnode->v_gnode->gn_seg, offset/PAGESIZE,
789 (len + PAGESIZE-1)/PAGESIZE);
790 3. vms_inactive(tfile->vnode->v_gnode->gn_seg) Doesn't work correctly
791 4. vms_delete(tfile->vnode->v_gnode->gn_seg) probably also fails
792 tfile->vnode->v_gnode->gn_seg = NULL;
796 Unfortunately, this seems to cause frequent "cache corruption" episodes.
797 vm_releasep(tfile->vnode->v_gnode->gn_seg, offset/PAGESIZE,
798 (len + PAGESIZE-1)/PAGESIZE);
801 #elif defined(AFS_AIX_ENV)
803 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, (off_t) & offset,
804 &tuio, NULL, NULL, -1);
805 #elif defined(AFS_SUN5_ENV)
807 #ifdef AFS_SUN510_ENV
811 VOP_RWLOCK(tfile->vnode, 0, &ct);
812 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, &ct);
813 VOP_RWUNLOCK(tfile->vnode, 0, &ct);
816 VOP_RWLOCK(tfile->vnode, 0);
817 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
818 VOP_RWUNLOCK(tfile->vnode, 0);
821 #elif defined(AFS_SGI_ENV)
823 AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_READ);
824 AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp,
826 AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_READ);
828 #elif defined(AFS_OSF_ENV)
829 tuio.uio_rw = UIO_READ;
831 VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, code);
833 #elif defined(AFS_HPUX100_ENV)
835 code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
837 #elif defined(AFS_LINUX20_ENV)
839 code = osi_rdwr(tfile, &tuio, UIO_READ);
841 #elif defined(AFS_DARWIN80_ENV)
843 code = VNOP_READ(tfile->vnode, tuiop, 0, afs_osi_ctxtp);
845 #elif defined(AFS_DARWIN_ENV)
847 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc());
848 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
849 VOP_UNLOCK(tfile->vnode, 0, current_proc());
851 #elif defined(AFS_FBSD50_ENV)
853 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curthread);
854 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
855 VOP_UNLOCK(tfile->vnode, 0, curthread);
857 #elif defined(AFS_XBSD_ENV)
859 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
860 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
861 VOP_UNLOCK(tfile->vnode, 0, curproc);
864 code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
868 if (!tdc->ihint && nihints < maxIHint) {
880 /* otherwise we've read some, fixup length, etc and continue with next seg */
881 len = len - AFS_UIO_RESID(tuiop); /* compute amount really transferred */
883 afsio_skip(auio, trimlen); /* update input uio structure */
885 transferLength += len;
888 break; /* surprise eof */
889 #ifdef AFS_DARWIN80_ENV
897 /* if we make it here with tdc non-zero, then it is the last chunk we
898 * dealt with, and we have to release it when we're done. We hold on
899 * to it in case we need to do a prefetch, obviously.
902 ReleaseReadLock(&tdc->lock);
903 #if !defined(AFS_VM_RDWR_ENV)
904 /* try to queue prefetch, if needed */
906 if (!(tdc->mflags & DFNextStarted))
907 afs_PrefetchChunk(avc, tdc, acred, &treq);
913 ReleaseReadLock(&avc->lock);
915 #ifdef AFS_DARWIN80_ENV
919 osi_FreeSmallSpace(tvec);
921 error = afs_CheckCode(error, &treq, 13);