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 if (filePos >= avc->m.Length) {
122 len = sizeof(afs_zeros); /* and in 0 buffer */
124 #ifdef AFS_DARWIN80_ENV
126 tuiop = afsio_darwin_partialcopy(auio, trimlen);
128 afsio_copy(auio, &tuio, tvec);
130 afsio_trim(&tuio, trimlen);
132 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
135 while (avc->m.Length > 0 && totalLength > 0) {
136 /* read all of the cached info */
137 if (filePos >= avc->m.Length)
138 break; /* all done */
141 ReleaseReadLock(&tdc->lock);
144 tdc = afs_FindDCache(avc, filePos);
146 ObtainReadLock(&tdc->lock);
147 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
148 len = tdc->f.chunkBytes - offset;
151 /* a tricky question: does the presence of the DFFetching flag
152 * mean that we're fetching the latest version of the file? No.
153 * The server could update the file as soon as the fetch responsible
154 * for the setting of the DFFetching flag completes.
156 * However, the presence of the DFFetching flag (visible under
157 * a dcache read lock since it is set and cleared only under a
158 * dcache write lock) means that we're fetching as good a version
159 * as was known to this client at the time of the last call to
160 * afs_VerifyVCache, since the latter updates the stat cache's
161 * m.DataVersion field under a vcache write lock, and from the
162 * time that the DFFetching flag goes on in afs_GetDCache (before
163 * the fetch starts), to the time it goes off (after the fetch
164 * completes), afs_GetDCache keeps at least a read lock on the
167 * This means that if the DFFetching flag is set, we can use that
168 * data for any reads that must come from the current version of
169 * the file (current == m.DataVersion).
171 * Another way of looking at this same point is this: if we're
172 * fetching some data and then try do an afs_VerifyVCache, the
173 * VerifyVCache operation will not complete until after the
174 * DFFetching flag is turned off and the dcache entry's f.versionNo
177 * Note, by the way, that if DFFetching is set,
178 * m.DataVersion > f.versionNo (the latter is not updated until
179 * after the fetch completes).
182 ReleaseReadLock(&tdc->lock);
183 afs_PutDCache(tdc); /* before reusing tdc */
185 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2);
186 ObtainReadLock(&tdc->lock);
187 /* now, first try to start transfer, if we'll need the data. If
188 * data already coming, we don't need to do this, obviously. Type
189 * 2 requests never return a null dcache entry, btw.
191 if (!(tdc->dflags & DFFetching)
192 && !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
193 /* have cache entry, it is not coming in now,
194 * and we'll need new data */
196 if (trybusy && !afs_BBusy()) {
198 /* daemon is not busy */
199 ObtainSharedLock(&tdc->mflock, 665);
200 if (!(tdc->mflags & DFFetchReq)) {
201 /* start the daemon (may already be running, however) */
202 UpgradeSToWLock(&tdc->mflock, 666);
203 tdc->mflags |= DFFetchReq;
204 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
205 (afs_size_t) filePos, (afs_size_t) 0,
208 tdc->mflags &= ~DFFetchReq;
209 trybusy = 0; /* Avoid bkg daemon since they're too busy */
210 ReleaseWriteLock(&tdc->mflock);
213 ConvertWToSLock(&tdc->mflock);
214 /* don't use bp pointer! */
217 ConvertSToRLock(&tdc->mflock);
218 while (!code && tdc->mflags & DFFetchReq) {
219 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT,
220 ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32,
221 __LINE__, ICL_TYPE_POINTER, tdc,
222 ICL_TYPE_INT32, tdc->dflags);
223 /* don't need waiting flag on this one */
224 ReleaseReadLock(&tdc->mflock);
225 ReleaseReadLock(&tdc->lock);
226 ReleaseReadLock(&avc->lock);
227 code = afs_osi_SleepSig(&tdc->validPos);
228 ObtainReadLock(&avc->lock);
229 ObtainReadLock(&tdc->lock);
230 ObtainReadLock(&tdc->mflock);
232 ReleaseReadLock(&tdc->mflock);
239 /* now data may have started flowing in (if DFFetching is on). If
240 * data is now streaming in, then wait for some interesting stuff.
243 while (!code && (tdc->dflags & DFFetching)
244 && tdc->validPos <= filePos) {
245 /* too early: wait for DFFetching flag to vanish,
246 * or data to appear */
247 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
248 __FILE__, ICL_TYPE_INT32, __LINE__,
249 ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32,
251 ReleaseReadLock(&tdc->lock);
252 ReleaseReadLock(&avc->lock);
253 code = afs_osi_SleepSig(&tdc->validPos);
254 ObtainReadLock(&avc->lock);
255 ObtainReadLock(&tdc->lock);
261 /* fetching flag gone, data is here, or we never tried
262 * (BBusy for instance) */
263 if (tdc->dflags & DFFetching) {
264 /* still fetching, some new data is here:
265 * compute length and offset */
266 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
267 len = tdc->validPos - filePos;
269 /* no longer fetching, verify data version
270 * (avoid new GetDCache call) */
271 if (hsame(avc->m.DataVersion, tdc->f.versionNo)
272 && ((len = tdc->validPos - filePos) > 0)) {
273 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
275 /* don't have current data, so get it below */
276 afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO,
277 ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos),
278 ICL_TYPE_HYPER, &avc->m.DataVersion,
279 ICL_TYPE_HYPER, &tdc->f.versionNo);
280 ReleaseReadLock(&tdc->lock);
287 /* If we get, it was not possible to start the
288 * background daemon. With flag == 1 afs_GetDCache
289 * does the FetchData rpc synchronously.
291 ReleaseReadLock(&avc->lock);
292 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
293 ObtainReadLock(&avc->lock);
295 ObtainReadLock(&tdc->lock);
299 afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc,
300 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset),
301 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len));
313 if (len > totalLength)
314 len = totalLength; /* will read len bytes */
315 if (len <= 0) { /* shouldn't get here if DFFetching is on */
316 /* read past the end of a chunk, may not be at next chunk yet, and yet
317 * also not at eof, so may have to supply fake zeros */
318 len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */
319 if (len > totalLength)
320 len = totalLength; /* and still within xfr request */
321 tlen = avc->m.Length - offset; /* and still within file */
325 len = sizeof(afs_zeros); /* and in 0 buffer */
326 #ifdef AFS_DARWIN80_ENV
328 tuiop = afsio_darwin_partialcopy(auio, trimlen);
330 afsio_copy(auio, &tuio, tvec);
332 afsio_trim(&tuio, trimlen);
334 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
340 /* get the data from the mem cache */
342 /* mung uio structure to be right for this transfer */
343 #ifdef AFS_DARWIN80_ENV
345 tuiop = afsio_darwin_partialcopy(auio, trimlen);
346 uio_setoffset(tuiop, offset);
348 afsio_copy(auio, &tuio, tvec);
350 afsio_trim(&tuio, trimlen);
351 tuio.afsio_offset = offset;
354 code = afs_MemReadUIO(tdc->f.inode, tuiop);
361 /* otherwise we've read some, fixup length, etc and continue with next seg */
362 len = len - AFS_UIO_RESID(tuiop); /* compute amount really transferred */
364 afsio_skip(auio, trimlen); /* update input uio structure */
366 transferLength += len;
370 break; /* surprise eof */
371 #ifdef AFS_DARWIN80_ENV
377 } /* the whole while loop */
382 * tdc->lock(R) if tdc
385 /* if we make it here with tdc non-zero, then it is the last chunk we
386 * dealt with, and we have to release it when we're done. We hold on
387 * to it in case we need to do a prefetch.
390 ReleaseReadLock(&tdc->lock);
391 /* try to queue prefetch, if needed */
393 #ifndef AFS_VM_RDWR_ENV
399 afs_PrefetchChunk(avc, tdc, acred, &treq);
404 ReleaseReadLock(&avc->lock);
405 #ifdef AFS_DARWIN80_ENV
409 osi_FreeSmallSpace(tvec);
411 error = afs_CheckCode(error, &treq, 10);
415 /* called with the dcache entry triggering the fetch, the vcache entry involved,
416 * and a vrequest for the read call. Marks the dcache entry as having already
417 * triggered a prefetch, starts the prefetch going and sets the DFFetchReq
418 * flag in the prefetched block, so that the next call to read knows to wait
419 * for the daemon to start doing things.
421 * This function must be called with the vnode at least read-locked, and
422 * no locks on the dcache, because it plays around with dcache entries.
425 afs_PrefetchChunk(struct vcache *avc, struct dcache *adc,
426 struct AFS_UCRED *acred, struct vrequest *areq)
428 register struct dcache *tdc;
430 afs_size_t j1, j2; /* junk vbls for GetDCache to trash */
432 offset = adc->f.chunk + 1; /* next chunk we'll need */
433 offset = AFS_CHUNKTOBASE(offset); /* base of next chunk */
434 ObtainReadLock(&adc->lock);
435 ObtainSharedLock(&adc->mflock, 662);
436 if (offset < avc->m.Length && !(adc->mflags & DFNextStarted)
440 UpgradeSToWLock(&adc->mflock, 663);
441 adc->mflags |= DFNextStarted; /* we've tried to prefetch for this guy */
442 ReleaseWriteLock(&adc->mflock);
443 ReleaseReadLock(&adc->lock);
445 tdc = afs_GetDCache(avc, offset, areq, &j1, &j2, 2); /* type 2 never returns 0 */
446 ObtainSharedLock(&tdc->mflock, 651);
447 if (!(tdc->mflags & DFFetchReq)) {
448 /* ask the daemon to do the work */
449 UpgradeSToWLock(&tdc->mflock, 652);
450 tdc->mflags |= DFFetchReq; /* guaranteed to be cleared by BKG or GetDCache */
451 /* last parm (1) tells bkg daemon to do an afs_PutDCache when it is done,
452 * since we don't want to wait for it to finish before doing so ourselves.
454 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
455 (afs_size_t) offset, (afs_size_t) 1, tdc);
457 /* Bkg table full; just abort non-important prefetching to avoid deadlocks */
458 tdc->mflags &= ~DFFetchReq;
459 ReleaseWriteLock(&tdc->mflock);
463 * DCLOCKXXX: This is a little sketchy, since someone else
464 * could have already started a prefetch.. In practice,
465 * this probably doesn't matter; at most it would cause an
466 * extra slot in the BKG table to be used up when someone
467 * prefetches this for the second time.
469 ObtainReadLock(&adc->lock);
470 ObtainWriteLock(&adc->mflock, 664);
471 adc->mflags &= ~DFNextStarted;
472 ReleaseWriteLock(&adc->mflock);
473 ReleaseReadLock(&adc->lock);
475 ReleaseWriteLock(&tdc->mflock);
478 ReleaseSharedLock(&tdc->mflock);
482 ReleaseSharedLock(&adc->mflock);
483 ReleaseReadLock(&adc->lock);
488 afs_UFSRead(register struct vcache *avc, struct uio *auio,
489 struct AFS_UCRED *acred, daddr_t albn, struct buf **abpp,
492 afs_size_t totalLength;
493 afs_size_t transferLength;
495 afs_size_t offset, len, tlen;
497 struct dcache *tdc = 0;
499 #ifdef AFS_DARWIN80_ENV
503 struct uio *tuiop = &tuio;
506 struct osi_file *tfile;
509 struct vrequest treq;
511 AFS_STATCNT(afs_UFSRead);
512 if (avc && avc->vc_error)
515 /* check that we have the latest status info in the vnode cache */
516 if ((code = afs_InitReq(&treq, acred)))
520 osi_Panic("null avc in afs_UFSRead");
522 code = afs_VerifyVCache(avc, &treq);
524 code = afs_CheckCode(code, &treq, 11); /* failed to get it */
529 #ifndef AFS_VM_RDWR_ENV
530 if (AFS_NFSXLATORREQ(acred)) {
532 (avc, PRSFS_READ, &treq,
533 CHECK_MODE_BITS | CMB_ALLOW_EXEC_AS_READ)) {
534 return afs_CheckCode(EACCES, &treq, 12);
539 #ifndef AFS_DARWIN80_ENV
540 tvec = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec));
542 totalLength = AFS_UIO_RESID(auio);
543 filePos = AFS_UIO_OFFSET(auio);
544 afs_Trace4(afs_iclSetp, CM_TRACE_READ, ICL_TYPE_POINTER, avc,
545 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(filePos), ICL_TYPE_INT32,
546 totalLength, ICL_TYPE_OFFSET,
547 ICL_HANDLE_OFFSET(avc->m.Length));
551 ObtainReadLock(&avc->lock);
552 #if defined(AFS_TEXT_ENV) && !defined(AFS_VM_RDWR_ENV)
553 if (avc->flushDV.high == AFS_MAXDV && avc->flushDV.low == AFS_MAXDV) {
554 hset(avc->flushDV, avc->m.DataVersion);
558 if (filePos >= avc->m.Length) {
560 len = sizeof(afs_zeros); /* and in 0 buffer */
562 #ifdef AFS_DARWIN80_ENV
564 tuiop = afsio_darwin_partialcopy(auio, trimlen);
566 afsio_copy(auio, &tuio, tvec);
568 afsio_trim(&tuio, trimlen);
570 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
573 while (avc->m.Length > 0 && totalLength > 0) {
574 /* read all of the cached info */
575 if (filePos >= avc->m.Length)
576 break; /* all done */
579 ReleaseReadLock(&tdc->lock);
582 tdc = afs_FindDCache(avc, filePos);
584 ObtainReadLock(&tdc->lock);
585 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
586 len = tdc->validPos - filePos;
589 /* a tricky question: does the presence of the DFFetching flag
590 * mean that we're fetching the latest version of the file? No.
591 * The server could update the file as soon as the fetch responsible
592 * for the setting of the DFFetching flag completes.
594 * However, the presence of the DFFetching flag (visible under
595 * a dcache read lock since it is set and cleared only under a
596 * dcache write lock) means that we're fetching as good a version
597 * as was known to this client at the time of the last call to
598 * afs_VerifyVCache, since the latter updates the stat cache's
599 * m.DataVersion field under a vcache write lock, and from the
600 * time that the DFFetching flag goes on in afs_GetDCache (before
601 * the fetch starts), to the time it goes off (after the fetch
602 * completes), afs_GetDCache keeps at least a read lock on the
605 * This means that if the DFFetching flag is set, we can use that
606 * data for any reads that must come from the current version of
607 * the file (current == m.DataVersion).
609 * Another way of looking at this same point is this: if we're
610 * fetching some data and then try do an afs_VerifyVCache, the
611 * VerifyVCache operation will not complete until after the
612 * DFFetching flag is turned off and the dcache entry's f.versionNo
615 * Note, by the way, that if DFFetching is set,
616 * m.DataVersion > f.versionNo (the latter is not updated until
617 * after the fetch completes).
620 ReleaseReadLock(&tdc->lock);
621 afs_PutDCache(tdc); /* before reusing tdc */
623 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 2);
624 ObtainReadLock(&tdc->lock);
625 /* now, first try to start transfer, if we'll need the data. If
626 * data already coming, we don't need to do this, obviously. Type
627 * 2 requests never return a null dcache entry, btw. */
628 if (!(tdc->dflags & DFFetching)
629 && !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
630 /* have cache entry, it is not coming in now, and we'll need new data */
632 if (trybusy && !afs_BBusy()) {
634 /* daemon is not busy */
635 ObtainSharedLock(&tdc->mflock, 667);
636 if (!(tdc->mflags & DFFetchReq)) {
637 UpgradeSToWLock(&tdc->mflock, 668);
638 tdc->mflags |= DFFetchReq;
639 bp = afs_BQueue(BOP_FETCH, avc, B_DONTWAIT, 0, acred,
640 (afs_size_t) filePos, (afs_size_t) 0,
643 /* Bkg table full; retry deadlocks */
644 tdc->mflags &= ~DFFetchReq;
645 trybusy = 0; /* Avoid bkg daemon since they're too busy */
646 ReleaseWriteLock(&tdc->mflock);
649 ConvertWToSLock(&tdc->mflock);
652 ConvertSToRLock(&tdc->mflock);
653 while (!code && tdc->mflags & DFFetchReq) {
654 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT,
655 ICL_TYPE_STRING, __FILE__, ICL_TYPE_INT32,
656 __LINE__, ICL_TYPE_POINTER, tdc,
657 ICL_TYPE_INT32, tdc->dflags);
658 /* don't need waiting flag on this one */
659 ReleaseReadLock(&tdc->mflock);
660 ReleaseReadLock(&tdc->lock);
661 ReleaseReadLock(&avc->lock);
662 code = afs_osi_SleepSig(&tdc->validPos);
663 ObtainReadLock(&avc->lock);
664 ObtainReadLock(&tdc->lock);
665 ObtainReadLock(&tdc->mflock);
667 ReleaseReadLock(&tdc->mflock);
674 /* now data may have started flowing in (if DFFetching is on). If
675 * data is now streaming in, then wait for some interesting stuff.
678 while (!code && (tdc->dflags & DFFetching)
679 && tdc->validPos <= filePos) {
680 /* too early: wait for DFFetching flag to vanish,
681 * or data to appear */
682 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAIT, ICL_TYPE_STRING,
683 __FILE__, ICL_TYPE_INT32, __LINE__,
684 ICL_TYPE_POINTER, tdc, ICL_TYPE_INT32,
686 ReleaseReadLock(&tdc->lock);
687 ReleaseReadLock(&avc->lock);
688 code = afs_osi_SleepSig(&tdc->validPos);
689 ObtainReadLock(&avc->lock);
690 ObtainReadLock(&tdc->lock);
696 /* fetching flag gone, data is here, or we never tried
697 * (BBusy for instance) */
698 if (tdc->dflags & DFFetching) {
699 /* still fetching, some new data is here:
700 * compute length and offset */
701 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
702 len = tdc->validPos - filePos;
704 /* no longer fetching, verify data version (avoid new
706 if (hsame(avc->m.DataVersion, tdc->f.versionNo)
707 && ((len = tdc->validPos - filePos) > 0)) {
708 offset = filePos - AFS_CHUNKTOBASE(tdc->f.chunk);
710 /* don't have current data, so get it below */
711 afs_Trace3(afs_iclSetp, CM_TRACE_VERSIONNO,
712 ICL_TYPE_INT64, ICL_HANDLE_OFFSET(filePos),
713 ICL_TYPE_HYPER, &avc->m.DataVersion,
714 ICL_TYPE_HYPER, &tdc->f.versionNo);
715 ReleaseReadLock(&tdc->lock);
722 /* If we get, it was not possible to start the
723 * background daemon. With flag == 1 afs_GetDCache
724 * does the FetchData rpc synchronously.
726 ReleaseReadLock(&avc->lock);
727 tdc = afs_GetDCache(avc, filePos, &treq, &offset, &len, 1);
728 ObtainReadLock(&avc->lock);
730 ObtainReadLock(&tdc->lock);
738 len = tdc->validPos - filePos;
739 afs_Trace3(afs_iclSetp, CM_TRACE_VNODEREAD, ICL_TYPE_POINTER, tdc,
740 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(offset),
741 ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(len));
742 if (len > totalLength)
743 len = totalLength; /* will read len bytes */
744 if (len <= 0) { /* shouldn't get here if DFFetching is on */
745 afs_Trace4(afs_iclSetp, CM_TRACE_VNODEREAD2, ICL_TYPE_POINTER,
746 tdc, ICL_TYPE_OFFSET, ICL_HANDLE_OFFSET(tdc->validPos),
747 ICL_TYPE_INT32, tdc->f.chunkBytes, ICL_TYPE_INT32,
749 /* read past the end of a chunk, may not be at next chunk yet, and yet
750 * also not at eof, so may have to supply fake zeros */
751 len = AFS_CHUNKTOSIZE(tdc->f.chunk) - offset; /* bytes left in chunk addr space */
752 if (len > totalLength)
753 len = totalLength; /* and still within xfr request */
754 tlen = avc->m.Length - offset; /* and still within file */
758 len = sizeof(afs_zeros); /* and in 0 buffer */
759 #ifdef AFS_DARWIN80_ENV
761 tuiop = afsio_darwin_partialcopy(auio, trimlen);
763 afsio_copy(auio, &tuio, tvec);
765 afsio_trim(&tuio, trimlen);
767 AFS_UIOMOVE(afs_zeros, trimlen, UIO_READ, tuiop, code);
773 /* get the data from the file */
775 if (tfile = tdc->ihint) {
776 if (tdc->f.inode != tfile->inum) {
777 afs_warn("afs_UFSRead: %x hint mismatch tdc %d inum %d\n",
778 tdc, tdc->f.inode, tfile->inum);
780 tdc->ihint = tfile = 0;
789 tfile = (struct osi_file *)osi_UFSOpen(tdc->f.inode);
790 #ifdef AFS_DARWIN80_ENV
792 tuiop = afsio_darwin_partialcopy(auio, trimlen);
793 uio_setoffset(tuiop, offset);
795 /* mung uio structure to be right for this transfer */
796 afsio_copy(auio, &tuio, tvec);
798 afsio_trim(&tuio, trimlen);
799 tuio.afsio_offset = offset;
802 #if defined(AFS_AIX41_ENV)
805 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL,
806 NULL, afs_osi_credp);
808 #elif defined(AFS_AIX32_ENV)
810 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, &tuio, NULL, NULL);
811 /* Flush all JFS pages now for big performance gain in big file cases
812 * If we do something like this, must check to be sure that AFS file
813 * isn't mmapped... see afs_gn_map() for why.
816 if (tfile->vnode->v_gnode && tfile->vnode->v_gnode->gn_seg) {
817 many different ways to do similar things:
818 so far, the best performing one is #2, but #1 might match it if we
819 straighten out the confusion regarding which pages to flush. It
821 1. vm_flushp(tfile->vnode->v_gnode->gn_seg, 0, len/PAGESIZE - 1);
822 2. vm_releasep(tfile->vnode->v_gnode->gn_seg, offset/PAGESIZE,
823 (len + PAGESIZE-1)/PAGESIZE);
824 3. vms_inactive(tfile->vnode->v_gnode->gn_seg) Doesn't work correctly
825 4. vms_delete(tfile->vnode->v_gnode->gn_seg) probably also fails
826 tfile->vnode->v_gnode->gn_seg = NULL;
830 Unfortunately, this seems to cause frequent "cache corruption" episodes.
831 vm_releasep(tfile->vnode->v_gnode->gn_seg, offset/PAGESIZE,
832 (len + PAGESIZE-1)/PAGESIZE);
835 #elif defined(AFS_AIX_ENV)
837 VNOP_RDWR(tfile->vnode, UIO_READ, FREAD, (off_t) & offset,
838 &tuio, NULL, NULL, -1);
839 #elif defined(AFS_SUN5_ENV)
841 #ifdef AFS_SUN510_ENV
845 VOP_RWLOCK(tfile->vnode, 0, &ct);
846 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, &ct);
847 VOP_RWUNLOCK(tfile->vnode, 0, &ct);
850 VOP_RWLOCK(tfile->vnode, 0);
851 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
852 VOP_RWUNLOCK(tfile->vnode, 0);
855 #elif defined(AFS_SGI_ENV)
857 AFS_VOP_RWLOCK(tfile->vnode, VRWLOCK_READ);
858 AFS_VOP_READ(tfile->vnode, &tuio, IO_ISLOCKED, afs_osi_credp,
860 AFS_VOP_RWUNLOCK(tfile->vnode, VRWLOCK_READ);
862 #elif defined(AFS_OSF_ENV)
863 tuio.uio_rw = UIO_READ;
865 VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp, code);
867 #elif defined(AFS_HPUX100_ENV)
869 code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
871 #elif defined(AFS_LINUX20_ENV)
873 code = osi_rdwr(tfile, &tuio, UIO_READ);
875 #elif defined(AFS_DARWIN80_ENV)
877 code = VNOP_READ(tfile->vnode, tuiop, 0, afs_osi_ctxtp);
879 #elif defined(AFS_DARWIN_ENV)
881 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, current_proc());
882 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
883 VOP_UNLOCK(tfile->vnode, 0, current_proc());
885 #elif defined(AFS_FBSD50_ENV)
887 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curthread);
888 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
889 VOP_UNLOCK(tfile->vnode, 0, curthread);
891 #elif defined(AFS_XBSD_ENV)
893 VOP_LOCK(tfile->vnode, LK_EXCLUSIVE, curproc);
894 code = VOP_READ(tfile->vnode, &tuio, 0, afs_osi_credp);
895 VOP_UNLOCK(tfile->vnode, 0, curproc);
898 code = VOP_RDWR(tfile->vnode, &tuio, UIO_READ, 0, afs_osi_credp);
902 if (!tdc->ihint && nihints < maxIHint) {
914 /* otherwise we've read some, fixup length, etc and continue with next seg */
915 len = len - AFS_UIO_RESID(tuiop); /* compute amount really transferred */
917 afsio_skip(auio, trimlen); /* update input uio structure */
919 transferLength += len;
922 break; /* surprise eof */
923 #ifdef AFS_DARWIN80_ENV
931 /* if we make it here with tdc non-zero, then it is the last chunk we
932 * dealt with, and we have to release it when we're done. We hold on
933 * to it in case we need to do a prefetch, obviously.
936 ReleaseReadLock(&tdc->lock);
937 #if !defined(AFS_VM_RDWR_ENV)
938 /* try to queue prefetch, if needed */
940 if (!(tdc->mflags & DFNextStarted))
941 afs_PrefetchChunk(avc, tdc, acred, &treq);
947 ReleaseReadLock(&avc->lock);
949 #ifdef AFS_DARWIN80_ENV
953 osi_FreeSmallSpace(tvec);
955 error = afs_CheckCode(error, &treq, 13);