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 <afsconfig.h>
11 #include "afs/param.h"
13 #include "afs/sysincludes.h" /* Standard vendor system headers */
14 #ifndef AFS_LINUX22_ENV
15 #include "rpc/types.h"
23 #endif /* AFS_ALPHA_ENV */
24 #include "afsincludes.h" /* Afs-based standard headers */
25 #include "afs/afs_stats.h" /* statistics */
26 #include "afs_prototypes.h"
28 extern int cacheDiskType;
33 FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
34 afs_size_t bytesToXfer, afs_size_t bytesXferred)
36 struct afs_stats_xferData *xferP;
37 osi_timeval_t xferStopTime;
38 osi_timeval_t elapsedTime;
40 xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[idx]);
41 osi_GetuTime(&xferStopTime);
44 (xferP->numSuccesses)++;
45 afs_stats_XferSumBytes[idx] += bytesXferred;
46 (xferP->sumBytes) += (afs_stats_XferSumBytes[idx] >> 10);
47 afs_stats_XferSumBytes[idx] &= 0x3FF;
48 if (bytesXferred < xferP->minBytes)
49 xferP->minBytes = bytesXferred;
50 if (bytesXferred > xferP->maxBytes)
51 xferP->maxBytes = bytesXferred;
54 * Tally the size of the object. Note: we tally the actual size,
55 * NOT the number of bytes that made it out over the wire.
57 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) (xferP->count[0])++;
58 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) (xferP->count[1])++;
59 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) (xferP->count[2])++;
60 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) (xferP->count[3])++;
61 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) (xferP->count[4])++;
62 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) (xferP->count[5])++;
63 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) (xferP->count[6])++;
64 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) (xferP->count[7])++;
68 afs_stats_GetDiff(elapsedTime, (*xferStartTime), xferStopTime);
69 afs_stats_AddTo((xferP->sumTime), elapsedTime);
70 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
71 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
72 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
74 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
75 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
79 #endif /* AFS_NOSTATS */
81 /* rock and operations for RX_FILESERVER */
83 struct rxfs_storeVariables {
89 struct AFSStoreStatus InStatus;
93 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
95 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
100 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
103 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
105 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
107 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
110 code = rx_Error(v->call);
122 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
123 afs_uint32 tlen, afs_uint32 *bytesread)
126 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
129 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
135 #if defined(KERNEL_HAVE_UERROR)
143 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
144 afs_uint32 tlen, afs_uint32 *bytesread)
147 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
148 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
151 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
159 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
162 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
165 code = rx_Writev(v->call, v->tiov, v->tnio, l);
168 code = rx_Error(v->call);
169 return (code ? code : -33);
171 *byteswritten = code;
176 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
179 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
182 code = rx_Write(v->call, v->tbuffer, l);
183 /* writing 0 bytes will
184 * push a short packet. Is that really what we want, just because the
185 * data didn't come back from the disk yet? Let's try it and see. */
188 code = rx_Error(v->call);
189 return (code ? code : -33);
191 *byteswritten = code;
196 rxfs_storePadd(void *rock, afs_uint32 size)
200 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
203 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
204 memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
207 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
209 code = rx_Write(v->call, v->tbuffer, tlen);
213 return -33; /* XXX */
220 rxfs_storeStatus(void *rock)
222 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
224 if (rx_GetRemoteStatus(v->call) & 1)
230 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
233 struct AFSVolSync tsync;
234 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
239 #ifdef AFS_64BIT_CLIENT
241 code = EndRXAFS_StoreData64(v->call, OutStatus, &tsync);
244 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
247 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
253 rxfs_storeDestroy(void **r, afs_int32 error)
255 afs_int32 code = error;
256 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
261 code = rx_EndCall(v->call, error);
267 osi_FreeLargeSpace(v->tbuffer);
269 osi_FreeSmallSpace(v->tiov);
270 osi_FreeSmallSpace(v);
275 struct storeOps rxfs_storeUfsOps = {
276 rxfs_storeUfsPrepare,
286 struct storeOps rxfs_storeMemOps = {
287 rxfs_storeMemPrepare,
297 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
298 afs_size_t bytes, afs_size_t length,
299 int sync, struct storeOps **ops, void **rock)
302 struct rxfs_storeVariables *v;
307 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
309 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
310 memset(v, 0, sizeof(struct rxfs_storeVariables));
312 v->InStatus.ClientModTime = avc->f.m.Date;
313 v->InStatus.Mask = AFS_SETMODTIME;
315 v->InStatus.Mask |= AFS_FSYNC;
317 v->call = rx_NewCall(tc->id);
319 #ifdef AFS_64BIT_CLIENT
320 if (!afs_serverHasNo64Bit(tc))
321 code = StartRXAFS_StoreData64(
322 v->call, (struct AFSFid*)&avc->f.fid.Fid,
323 &v->InStatus, base, bytes, length);
325 if (length > 0xFFFFFFFF)
328 afs_int32 t1 = base, t2 = bytes, t3 = length;
329 code = StartRXAFS_StoreData(v->call,
330 (struct AFSFid *) &avc->f.fid.Fid,
331 &v->InStatus, t1, t2, t3);
333 #else /* AFS_64BIT_CLIENT */
334 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
335 &v->InStatus, base, bytes, length);
336 #endif /* AFS_64BIT_CLIENT */
341 osi_FreeSmallSpace(v);
344 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
345 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
348 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
349 *ops = (struct storeOps *) &rxfs_storeUfsOps;
351 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
354 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
355 *ops = (struct storeOps *) &rxfs_storeMemOps;
357 /* do this at a higher level now -- it's a parameter */
358 /* for now, only do 'continue from close' code if file fits in one
359 * chunk. Could clearly do better: if only one modified chunk
360 * then can still do this. can do this on *last* modified chunk */
361 length = avc->f.m.Length - 1; /* byte position of last byte we'll store */
363 if (AFS_CHUNK(length) != 0)
375 unsigned int storeallmissing = 0;
377 * Called for each chunk upon store.
379 * \param avc Ptr to the vcache entry of the file being stored.
380 * \param dclist pointer to the list of dcaches
381 * \param bytes total number of bytes for the current operation
382 * \param anewDV Ptr to the dataversion after store
383 * \param doProcessFS pointer to the "do process FetchStatus" flag
384 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
385 * \param nchunks number of dcaches to consider
386 * \param nomore copy of the "no more data" flag
387 * \param ops pointer to the block of storeOps to be used for this operation
388 * \param rock pointer to the opaque protocol-specific data of this operation
391 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
395 struct AFSFetchStatus *OutStatus,
398 struct storeOps *ops, void *rock)
400 int *shouldwake = NULL;
405 osi_timeval_t xferStartTime; /*FS xfer start time */
406 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
407 afs_size_t bytesXferred = 10000; /* # bytes actually xferred */
408 #endif /* AFS_NOSTATS */
411 for (i = 0; i < nchunks && !code; i++) {
413 struct osi_file *tfile;
415 struct dcache *tdc = dclist[i];
416 afs_int32 size = tdc->f.chunkBytes;
418 afs_warn("afs: missing dcache!\n");
420 continue; /* panic? */
422 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
423 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
424 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
427 if (avc->asynchrony == -1) {
428 if (afs_defaultAsynchrony > (bytes - stored))
429 shouldwake = &nomore;
431 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
432 shouldwake = &nomore;
434 tfile = afs_CFileOpen(&tdc->f.inode);
436 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
437 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
438 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
440 AFS_STATCNT(CacheStoreProc);
442 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
443 avc->f.truncPos = AFS_NOTRUNC;
446 * In this case, size is *always* the amount of data we'll be trying
452 osi_GetuTime(&xferStartTime);
453 #endif /* AFS_NOSTATS */
457 afs_uint32 bytesread, byteswritten;
458 code = (*ops->prepare)(rock, size, &tlen);
462 code = (*ops->read)(rock, tfile, offset, tlen, &bytesread);
467 code = (*ops->write)(rock, tlen, &byteswritten);
471 bytesXferred += byteswritten;
472 #endif /* AFS_NOSTATS */
477 * if file has been locked on server, can allow
480 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
481 *shouldwake = 0; /* only do this once */
485 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
486 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
487 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
490 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
491 &xferStartTime, bytesToXfer, bytesXferred);
492 #endif /* AFS_NOSTATS */
494 afs_CFileClose(tfile);
495 if ((tdc->f.chunkBytes < afs_OtherCSize)
496 && (i < (nchunks - 1)) && code == 0) {
497 code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
499 stored += tdc->f.chunkBytes;
500 /* ideally, I'd like to unlock the dcache and turn
501 * off the writing bit here, but that would
502 * require being able to retry StoreAllSegments in
503 * the event of a failure. It only really matters
504 * if user can't read from a 'locked' dcache or
505 * one which has the writing bit turned on. */
509 code = (*ops->close)(rock, OutStatus, doProcessFS);
516 code = (*ops->destroy)(&rock, code);
520 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
524 * \param dclist pointer to the list of dcaches
525 * \param avc Ptr to the vcache entry.
526 * \param areq Ptr to the request structure
527 * \param sync sync flag
528 * \param minj the chunk offset for this call
529 * \param high index of last dcache to store
530 * \param moredata the moredata flag
531 * \param anewDV Ptr to the dataversion after store
532 * \param amaxStoredLength Ptr to the amount of that is actually stored
534 * \note Environment: Nothing interesting.
537 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
538 struct vrequest *areq, int sync,
539 unsigned int minj, unsigned int high,
540 unsigned int moredata,
541 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
544 struct storeOps *ops;
548 struct AFSFetchStatus OutStatus;
550 afs_size_t base, bytes, length;
552 unsigned int first = 0;
555 for (bytes = 0, j = 0; !code && j <= high; j++) {
557 ObtainSharedLock(&(dcList[j]->lock), 629);
560 bytes += dcList[j]->f.chunkBytes;
561 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
562 && (dcList[j]->f.chunk - minj < high)
564 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
568 if (bytes && (j == high || !dcList[j + 1])) {
570 struct dcache **dclist = &dcList[first];
571 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
572 base = AFS_CHUNKTOBASE(first + minj);
575 * take a list of dcache structs and send them all off to the server
576 * the list must be in order, and the chunks contiguous.
577 * Note - there is no locking done by this code currently. For
578 * safety's sake, xdcache could be locked over the entire call.
579 * However, that pretty well ties up all the threads. Meantime, all
580 * the chunks _MUST_ have their refcounts bumped.
581 * The writes done before a store back will clear setuid-ness
583 * We can permit CacheStoreProc to wake up the user process IFF we
584 * are doing the last RPC for this close, ie, storing back the last
585 * set of contiguous chunks of a file.
588 nchunks = 1 + j - first;
589 nomore = !(moredata || (j != high));
590 length = lmin(avc->f.m.Length, avc->f.truncPos);
591 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
592 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
593 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
594 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
595 ICL_HANDLE_OFFSET(length));
598 tc = afs_Conn(&avc->f.fid, areq, 0);
600 #ifdef AFS_64BIT_CLIENT
603 code = rxfs_storeInit(avc, tc, base, bytes, length,
606 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
607 &doProcessFS, &OutStatus,
608 nchunks, nomore, ops, rock);
611 #ifdef AFS_64BIT_CLIENT
612 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
613 afs_serverSetNo64Bit(tc);
616 #endif /* AFS_64BIT_CLIENT */
618 (tc, code, &avc->f.fid, areq,
619 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
622 /* put back all remaining locked dcache entries */
623 for (i = 0; i < nchunks; i++) {
624 struct dcache *tdc = dclist[i];
626 if (afs_indexFlags[tdc->index] & IFDataMod) {
628 * LOCKXXX -- should hold afs_xdcache(W) when
629 * modifying afs_indexFlags.
631 afs_indexFlags[tdc->index] &= ~IFDataMod;
632 afs_stats_cmperf.cacheCurrDirtyChunks--;
633 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
634 if (sync & AFS_VMSYNC_INVAL) {
635 /* since we have invalidated all the pages of this
636 ** vnode by calling osi_VM_TryToSmush, we can
637 ** safely mark this dcache entry as not having
638 ** any pages. This vnode now becomes eligible for
639 ** reclamation by getDownD.
641 afs_indexFlags[tdc->index] &= ~IFAnyPages;
645 UpgradeSToWLock(&tdc->lock, 628);
646 tdc->f.states &= ~DWriting; /* correct? */
647 tdc->dflags |= DFEntryMod;
648 ReleaseWriteLock(&tdc->lock);
650 /* Mark the entry as released */
655 /* Now copy out return params */
656 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
657 afs_ProcessFS(avc, &OutStatus, areq);
658 /* Keep last (max) size of file on server to see if
659 * we need to call afs_StoreMini to extend the file.
662 *amaxStoredLength = OutStatus.Length;
663 ConvertWToSLock(&avc->lock);
668 for (j++; j <= high; j++) {
670 ReleaseSharedLock(&(dcList[j]->lock));
671 afs_PutDCache(dcList[j]);
672 /* Releasing entry */
678 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
679 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
687 /* rock and operations for RX_FILESERVER */
689 struct rxfs_fetchVariables {
690 struct rx_call *call;
694 afs_int32 hasNo64bit;
700 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
704 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
707 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
709 code = rx_Read(v->call, v->tbuffer, tlen);
718 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
721 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
725 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
735 rxfs_fetchMemWrite(void *r, struct osi_file *fP,
736 afs_uint32 offset, afs_uint32 tlen,
737 afs_uint32 *byteswritten)
740 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
741 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
743 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
747 *byteswritten = code;
752 rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
753 afs_uint32 offset, afs_uint32 tlen,
754 afs_uint32 *byteswritten)
757 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
759 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
763 *byteswritten = code;
769 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
770 struct afs_FetchOutput *o)
772 afs_int32 code, code1 = 0;
773 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
779 #ifdef AFS_64BIT_CLIENT
781 code = EndRXAFS_FetchData64(v->call, &o->OutStatus, &o->CallBack,
785 code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
787 code1 = rx_EndCall(v->call, code);
798 rxfs_fetchDestroy(void **r, afs_int32 error)
800 afs_int32 code = error;
801 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
806 code = rx_EndCall(v->call, error);
812 osi_FreeLargeSpace(v->tbuffer);
814 osi_FreeSmallSpace(v->iov);
815 osi_FreeSmallSpace(v);
820 rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
823 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
826 * The fetch protocol is extended for the AFS/DFS translator
827 * to allow multiple blocks of data, each with its own length,
828 * to be returned. As long as the top bit is set, there are more
831 * We do not do this for AFS file servers because they sometimes
832 * return large negative numbers as the transfer size.
836 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
838 *length = ntohl(*length);
839 if (code != sizeof(afs_int32)) {
840 code = rx_Error(v->call);
842 return (code ? code : -1); /* try to return code, not -1 */
845 *moredata = *length & 0x80000000;
846 *length &= ~0x80000000;
851 struct fetchOps rxfs_fetchUfsOps = {
860 struct fetchOps rxfs_fetchMemOps = {
869 rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
870 afs_uint32 size, afs_int32 *alength, struct dcache *adc,
871 struct osi_file *fP, struct fetchOps **ops, void **rock)
873 struct rxfs_fetchVariables *v;
874 int code = 0, code1 = 0;
875 #ifdef AFS_64BIT_CLIENT
876 afs_uint32 length_hi = 0;
878 afs_uint32 length, bytes;
880 v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
882 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
883 memset(v, 0, sizeof(struct rxfs_fetchVariables));
886 v->call = rx_NewCall(tc->id);
889 #ifdef AFS_64BIT_CLIENT
890 afs_size_t length64; /* as returned from server */
891 if (!afs_serverHasNo64Bit(tc)) {
892 afs_uint64 llbytes = size;
894 code = StartRXAFS_FetchData64(v->call, (struct AFSFid *) &avc->f.fid.Fid,
898 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
899 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
901 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
903 if (bytes == sizeof(afs_int32)) {
904 length_hi = ntohl(length_hi);
906 code = rx_Error(v->call);
908 code1 = rx_EndCall(v->call, code);
914 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
915 if (base > 0x7FFFFFFF) {
922 v->call = rx_NewCall(tc->id);
924 StartRXAFS_FetchData(
925 v->call, (struct AFSFid*)&avc->f.fid.Fid,
929 afs_serverSetNo64Bit(tc);
933 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
935 if (bytes == sizeof(afs_int32))
936 length = ntohl(length);
939 code = rx_Error(v->call);
940 code1 = rx_EndCall(v->call, code);
945 FillInt64(length64, length_hi, length);
946 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
947 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
949 ICL_HANDLE_OFFSET(length64));
951 #else /* AFS_64BIT_CLIENT */
953 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
959 rx_Read(v->call, (char *)&length, sizeof(afs_int32));
961 if (bytes == sizeof(afs_int32)) {
962 *alength = ntohl(length);
964 code = rx_Error(v->call);
965 code1 = rx_EndCall(v->call, code);
969 #endif /* AFS_64BIT_CLIENT */
977 osi_FreeSmallSpace(v);
980 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
981 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
983 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
984 osi_Assert(WriteLocked(&adc->lock));
986 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
989 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
990 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
991 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
993 * We need to alloc the iovecs on the heap so that they are "pinned"
994 * rather than declare them on the stack - defect 11272
996 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
998 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
999 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1007 * Routine called on fetch; also tells people waiting for data
1008 * that more has arrived.
1010 * \param tc Ptr to the Rx connection structure.
1011 * \param fP File descriptor for the cache file.
1012 * \param base Base offset to fetch.
1013 * \param adc Ptr to the dcache entry for the file, write-locked.
1014 * \param avc Ptr to the vcache entry for the file.
1015 * \param size Amount of data that should be fetched.
1016 * \param tsmall Ptr to the afs_FetchOutput structure.
1018 * \note Environment: Nothing interesting.
1021 afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
1022 struct dcache *adc, struct vcache *avc, afs_int32 size,
1023 struct afs_FetchOutput *tsmall)
1027 afs_uint32 bytesread, byteswritten;
1028 struct fetchOps *ops = NULL;
1030 afs_uint32 moredata = 0;
1035 osi_timeval_t xferStartTime; /*FS xfer start time */
1036 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1039 AFS_STATCNT(CacheFetchProc);
1041 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1045 * avc->lock(R) if setLocks && !slowPass
1046 * avc->lock(W) if !setLocks || slowPass
1049 code = rxfs_fetchInit(
1050 tc, avc, base, size, &length, adc, fP, &ops, &rock);
1053 osi_GetuTime(&xferStartTime);
1054 #endif /* AFS_NOSTATS */
1057 adc->validPos = base;
1061 if (avc->f.states & CForeign) {
1062 code = (*ops->more)(rock, &length, &moredata);
1067 bytesToXfer += length;
1068 #endif /* AFS_NOSTATS */
1069 while (length > 0) {
1070 #ifdef RX_KERNEL_TRACE
1071 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1074 code = (*ops->read)(rock, length, &bytesread);
1075 #ifdef RX_KERNEL_TRACE
1076 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1080 bytesXferred += bytesread;
1081 #endif /* AFS_NOSTATS */
1083 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1084 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1085 ICL_TYPE_INT32, length);
1089 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1092 offset += bytesread;
1094 length -= bytesread;
1095 adc->validPos = base;
1096 if (afs_osi_Wakeup(&adc->validPos) == 0)
1097 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1098 __FILE__, ICL_TYPE_INT32, __LINE__,
1099 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1105 code = (*ops->close)(rock, avc, adc, tsmall);
1107 (*ops->destroy)(&rock, code);
1110 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,
1111 bytesToXfer, bytesXferred);