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;
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;
237 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
240 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
246 rxfs_storeDestroy(void **r, afs_int32 error)
248 afs_int32 code = error;
249 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
255 code2 = rx_EndCall(v->call, code);
261 osi_FreeLargeSpace(v->tbuffer);
263 osi_FreeSmallSpace(v->tiov);
264 osi_FreeSmallSpace(v);
269 struct storeOps rxfs_storeUfsOps = {
270 rxfs_storeUfsPrepare,
280 struct storeOps rxfs_storeMemOps = {
281 rxfs_storeMemPrepare,
291 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t tlen,
292 afs_size_t bytes, afs_size_t base,
293 int sync, struct storeOps **ops, void **rock)
296 struct rxfs_storeVariables *v;
301 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
303 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
304 memset(v, 0, sizeof(struct rxfs_storeVariables));
306 v->InStatus.ClientModTime = avc->f.m.Date;
307 v->InStatus.Mask = AFS_SETMODTIME;
309 v->InStatus.Mask |= AFS_FSYNC;
311 v->call = rx_NewCall(tc->id);
313 #ifdef AFS_64BIT_CLIENT
314 if (!afs_serverHasNo64Bit(tc))
315 code = StartRXAFS_StoreData64(v->call,(struct AFSFid*)&avc->f.fid.Fid,
316 &v->InStatus, base, bytes, tlen);
318 if (tlen > 0xFFFFFFFF)
321 afs_int32 t1 = base, t2 = bytes, t3 = tlen;
322 code = StartRXAFS_StoreData(v->call,
323 (struct AFSFid *) &avc->f.fid.Fid,
324 &v->InStatus, t1, t2, t3);
326 #else /* AFS_64BIT_CLIENT */
327 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
328 &v->InStatus, base, bytes, tlen);
329 #endif /* AFS_64BIT_CLIENT */
334 osi_FreeSmallSpace(v);
337 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
338 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
341 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
342 *ops = (struct storeOps *) &rxfs_storeUfsOps;
344 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
347 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
348 *ops = (struct storeOps *) &rxfs_storeMemOps;
350 /* do this at a higher level now -- it's a parameter */
351 /* for now, only do 'continue from close' code if file fits in one
352 * chunk. Could clearly do better: if only one modified chunk
353 * then can still do this. can do this on *last* modified chunk */
354 tlen = avc->f.m.Length - 1; /* byte position of last byte we'll store */
356 if (AFS_CHUNK(tlen) != 0)
368 unsigned int storeallmissing = 0;
370 * Called for each chunk upon store.
372 * \param avc Ptr to the vcache entry of the file being stored.
373 * \param dclist pointer to the list of dcaches
374 * \param bytes total number of bytes for the current operation
375 * \param anewDV Ptr to the dataversion after store
376 * \param doProcessFS pointer to the "do process FetchStatus" flag
377 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
378 * \param nchunks number of dcaches to consider
379 * \param nomore copy of the "no more data" flag
380 * \param ops pointer to the block of storeOps to be used for this operation
381 * \param rock pointer to the opaque protocol-specific data of this operation
384 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
388 struct AFSFetchStatus *OutStatus,
391 struct storeOps *ops, void *rock)
393 int *shouldwake = NULL;
398 osi_timeval_t xferStartTime; /*FS xfer start time */
399 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
400 afs_size_t bytesXferred = 10000; /* # bytes actually xferred */
401 #endif /* AFS_NOSTATS */
404 for (i = 0; i < nchunks && !code; i++) {
408 struct dcache *tdc = dclist[i];
409 afs_int32 alen = tdc->f.chunkBytes;
411 afs_warn("afs: missing dcache!\n");
413 continue; /* panic? */
415 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
416 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
417 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
420 if (avc->asynchrony == -1) {
421 if (afs_defaultAsynchrony > (bytes - stored))
422 shouldwake = &nomore;
424 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
425 shouldwake = &nomore;
427 fP = afs_CFileOpen(&tdc->f.inode);
429 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
430 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
431 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
433 AFS_STATCNT(CacheStoreProc);
435 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
436 avc->f.truncPos = AFS_NOTRUNC;
439 * In this case, alen is *always* the amount of data we'll be trying
445 osi_GetuTime(&xferStartTime);
446 #endif /* AFS_NOSTATS */
450 afs_int32 bytesread, byteswritten;
451 code = (*ops->prepare)(rock, alen, &tlen);
455 code = (*ops->read)(rock, fP, offset, tlen, &bytesread);
460 code = (*ops->write)(rock, tlen, &byteswritten);
464 bytesXferred += byteswritten;
465 #endif /* AFS_NOSTATS */
470 * if file has been locked on server, can allow
473 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
474 *shouldwake = 0; /* only do this once */
478 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
479 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
480 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
483 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
484 &xferStartTime, bytesToXfer, bytesXferred);
485 #endif /* AFS_NOSTATS */
488 if ((tdc->f.chunkBytes < afs_OtherCSize)
489 && (i < (nchunks - 1)) && code == 0) {
490 int bsent, tlen, sbytes = afs_OtherCSize - tdc->f.chunkBytes;
491 char *tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
494 tlen = (sbytes > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : sbytes);
495 memset(tbuffer, 0, tlen);
498 ((struct rxfs_storeVariables*)rock)->call, tbuffer, tlen);
502 code = -33; /* XXX */
507 osi_FreeLargeSpace(tbuffer);
509 stored += tdc->f.chunkBytes;
510 /* ideally, I'd like to unlock the dcache and turn
511 * off the writing bit here, but that would
512 * require being able to retry StoreAllSegments in
513 * the event of a failure. It only really matters
514 * if user can't read from a 'locked' dcache or
515 * one which has the writing bit turned on. */
519 code = (*ops->close)(rock, OutStatus, doProcessFS);
525 code = (*ops->destroy)(&rock, code);
529 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
533 * \param dclist pointer to the list of dcaches
534 * \param avc Ptr to the vcache entry.
535 * \param areq Ptr to the request structure
536 * \param sync sync flag
537 * \param minj the chunk offset for this call
538 * \param high index of last dcache to store
539 * \param moredata the moredata flag
540 * \param anewDV Ptr to the dataversion after store
541 * \param amaxStoredLength Ptr to the amount of that is actually stored
543 * \note Environment: Nothing interesting.
546 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
547 struct vrequest *areq, int sync,
548 unsigned int minj, unsigned int high,
549 unsigned int moredata,
550 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
553 struct storeOps *ops;
557 struct AFSStoreStatus InStatus;
558 struct AFSFetchStatus OutStatus;
560 afs_size_t base, bytes, length;
563 unsigned int first = 0;
566 for (bytes = 0, j = 0; !code && j <= high; j++) {
568 ObtainSharedLock(&(dcList[j]->lock), 629);
571 bytes += dcList[j]->f.chunkBytes;
572 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
573 && (dcList[j]->f.chunk - minj < high)
575 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
579 if (bytes && (j == high || !dcList[j + 1])) {
580 struct dcache **dclist = &dcList[first];
581 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
582 base = AFS_CHUNKTOBASE(first + minj);
585 * take a list of dcache structs and send them all off to the server
586 * the list must be in order, and the chunks contiguous.
587 * Note - there is no locking done by this code currently. For
588 * safety's sake, xdcache could be locked over the entire call.
589 * However, that pretty well ties up all the threads. Meantime, all
590 * the chunks _MUST_ have their refcounts bumped.
591 * The writes done before a store back will clear setuid-ness
593 * We can permit CacheStoreProc to wake up the user process IFF we
594 * are doing the last RPC for this close, ie, storing back the last
595 * set of contiguous chunks of a file.
598 nchunks = 1 + j - first;
599 nomore = !(moredata || (j != high));
600 length = lmin(avc->f.m.Length, avc->f.truncPos);
601 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
602 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
603 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
604 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
605 ICL_HANDLE_OFFSET(length));
608 tc = afs_Conn(&avc->f.fid, areq, 0);
610 #ifdef AFS_64BIT_CLIENT
613 code = rxfs_storeInit(avc, tc, length, bytes, base,
618 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
619 &doProcessFS, &OutStatus, nchunks, nomore, ops, rock);
622 #ifdef AFS_64BIT_CLIENT
623 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
624 afs_serverSetNo64Bit(tc);
628 continue; /* dummy, label before block end won't work */
629 #endif /* AFS_64BIT_CLIENT */
631 (tc, code, &avc->f.fid, areq,
632 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
635 /* put back all remaining locked dcache entries */
636 for (i = 0; i < nchunks; i++) {
637 struct dcache *tdc = dclist[i];
639 if (afs_indexFlags[tdc->index] & IFDataMod) {
641 * LOCKXXX -- should hold afs_xdcache(W) when
642 * modifying afs_indexFlags.
644 afs_indexFlags[tdc->index] &= ~IFDataMod;
645 afs_stats_cmperf.cacheCurrDirtyChunks--;
646 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
647 if (sync & AFS_VMSYNC_INVAL) {
648 /* since we have invalidated all the pages of this
649 ** vnode by calling osi_VM_TryToSmush, we can
650 ** safely mark this dcache entry as not having
651 ** any pages. This vnode now becomes eligible for
652 ** reclamation by getDownD.
654 afs_indexFlags[tdc->index] &= ~IFAnyPages;
658 UpgradeSToWLock(&tdc->lock, 628);
659 tdc->f.states &= ~DWriting; /* correct? */
660 tdc->dflags |= DFEntryMod;
661 ReleaseWriteLock(&tdc->lock);
663 /* Mark the entry as released */
668 /* Now copy out return params */
669 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
670 afs_ProcessFS(avc, &OutStatus, areq);
671 /* Keep last (max) size of file on server to see if
672 * we need to call afs_StoreMini to extend the file.
675 *amaxStoredLength = OutStatus.Length;
676 ConvertWToSLock(&avc->lock);
681 for (j++; j <= high; j++) {
683 ReleaseSharedLock(&(dcList[j]->lock));
684 afs_PutDCache(dcList[j]);
685 /* Releasing entry */
691 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
692 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
700 /* rock and operations for RX_FILESERVER */
702 struct rxfs_fetchVariables {
703 struct rx_call *call;
707 afs_int32 hasNo64bit;
713 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
717 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
720 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
722 code = rx_Read(v->call, v->tbuffer, tlen);
731 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
734 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
738 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
748 rxfs_fetchMemWrite(void *r, struct osi_file *fP,
749 afs_uint32 offset, afs_uint32 tlen,
750 afs_uint32 *byteswritten)
753 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
754 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
756 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
760 *byteswritten = code;
765 rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
766 afs_uint32 offset, afs_uint32 tlen,
767 afs_uint32 *byteswritten)
770 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
772 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
776 *byteswritten = code;
782 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
783 struct afs_FetchOutput *tsmall)
785 afs_int32 code, code1 = 0;
786 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
792 code = EndRXAFS_FetchData(v->call, &tsmall->OutStatus,
799 code1 = rx_EndCall(v->call, code);
810 rxfs_fetchDestroy(void **r, afs_int32 error)
812 afs_int32 code = error;
813 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
817 osi_FreeLargeSpace(v->tbuffer);
819 osi_FreeSmallSpace(v->iov);
820 osi_FreeSmallSpace(v);
825 rxfs_fetchMore(void *r, afs_uint32 *length, afs_uint32 *moredata)
828 register struct rxfs_fetchVariables *v
829 = (struct rxfs_fetchVariables *)r;
832 * The fetch protocol is extended for the AFS/DFS translator
833 * to allow multiple blocks of data, each with its own length,
834 * to be returned. As long as the top bit is set, there are more
837 * We do not do this for AFS file servers because they sometimes
838 * return large negative numbers as the transfer size.
841 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
843 *length = ntohl(*length);
844 if (code != sizeof(afs_int32)) {
845 code = rx_Error(v->call);
847 return (code ? code : -1); /* try to return code, not -1 */
849 *moredata = *length & 0x80000000;
850 *length &= ~0x80000000;
855 struct fetchOps rxfs_fetchUfsOps = {
864 struct fetchOps rxfs_fetchMemOps = {
873 rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
874 afs_uint32 size, afs_uint32 *alength, afs_uint32 *moredata,
876 struct osi_file *fP, struct fetchOps **ops, void **rock)
878 struct rxfs_fetchVariables *v;
880 afs_uint32 length_hi = 0, length, bytes;
881 #ifdef AFS_64BIT_CLIENT
882 afs_size_t length64; /* as returned from server */
883 #endif /* AFS_64BIT_CLIENT */
885 v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
887 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
888 memset(v, 0, sizeof(struct rxfs_fetchVariables));
891 v->call = rx_NewCall(tc->id);
894 #ifdef AFS_64BIT_CLIENT
895 if (!afs_serverHasNo64Bit(tc)) {
896 afs_uint64 llbytes = size;
898 code = StartRXAFS_FetchData64(v->call, (struct AFSFid *)&avc->f.fid.Fid,
902 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
903 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
905 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
907 if (bytes == sizeof(afs_int32)) {
908 length_hi = ntohl(length_hi);
910 code = rx_Error(v->call);
912 code1 = rx_EndCall(v->call, code);
918 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
919 if (base > 0x7FFFFFFF) {
926 v->call = rx_NewCall(tc->id);
928 StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
932 afs_serverSetNo64Bit(tc);
936 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
938 if (bytes == sizeof(afs_int32))
939 length = ntohl(length);
941 code = rx_Error(v->call);
944 FillInt64(length64, length_hi, length);
945 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
946 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
948 ICL_HANDLE_OFFSET(length64));
949 #else /* AFS_64BIT_CLIENT */
951 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
956 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
958 if (bytes == sizeof(afs_int32))
959 length = ntohl(length);
961 code = rx_Error(v->call);
963 #endif /* AFS_64BIT_CLIENT */
965 osi_FreeSmallSpace(v);
969 * The fetch protocol is extended for the AFS/DFS translator
970 * to allow multiple blocks of data, each with its own length,
971 * to be returned. As long as the top bit is set, there are more
974 * We do not do this for AFS file servers because they sometimes
975 * return large negative numbers as the transfer size.
977 * Also omit if length > 2^32, as bit 31 is part of the number then.
978 * Known to never be the case ifndef AFS_64BIT_CLIENT.
980 if (avc->f.states & CForeign && !length_hi) {
981 *moredata = length & 0x80000000;
982 length &= ~0x80000000;
984 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
985 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
987 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
988 osi_Assert(WriteLocked(&adc->lock));
990 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
993 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
994 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
995 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
997 * We need to alloc the iovecs on the heap so that they are "pinned"
998 * rather than declare them on the stack - defect 11272
1000 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
1002 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
1003 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1012 * Routine called on fetch; also tells people waiting for data
1013 * that more has arrived.
1015 * \param tc Ptr to the Rx connection structure.
1016 * \param fP File descriptor for the cache file.
1017 * \param base Base offset to fetch.
1018 * \param adc Ptr to the dcache entry for the file, write-locked.
1019 * \param avc Ptr to the vcache entry for the file.
1020 * \param size Amount of data that should be fetched.
1021 * \param tsmall Ptr to the afs_FetchOutput structure.
1023 * \note Environment: Nothing interesting.
1026 afs_CacheFetchProc(register struct afs_conn *tc,
1027 register struct osi_file *fP, afs_size_t base,
1028 struct dcache *adc, struct vcache *avc,
1030 struct afs_FetchOutput *tsmall)
1032 register afs_int32 code;
1034 afs_uint32 bytesread, byteswritten;
1035 struct fetchOps *ops = NULL;
1038 register int offset = 0;
1042 osi_timeval_t xferStartTime; /*FS xfer start time */
1043 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1046 AFS_STATCNT(CacheFetchProc);
1048 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1050 code = rxfs_fetchInit(
1051 tc, avc, base, size, &length, &moredata, adc, fP, &ops, &rock);
1054 osi_GetuTime(&xferStartTime);
1055 #endif /* AFS_NOSTATS */
1058 adc->validPos = base;
1062 if ((avc->f.states & CForeign) && moredata && !length) {
1063 code = (*ops->more)(rock, &length, &moredata);
1068 bytesToXfer += length;
1069 #endif /* AFS_NOSTATS */
1070 while (length > 0) {
1071 #ifdef RX_KERNEL_TRACE
1072 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1075 code = (*ops->read)(rock, length, &bytesread);
1076 #ifdef RX_KERNEL_TRACE
1077 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1081 bytesXferred += bytesread;
1082 #endif /* AFS_NOSTATS */
1084 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1085 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1086 ICL_TYPE_INT32, length);
1090 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1093 offset += bytesread;
1095 length -= bytesread;
1096 adc->validPos = base;
1097 if (afs_osi_Wakeup(&adc->validPos) == 0)
1098 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1099 __FILE__, ICL_TYPE_INT32, __LINE__,
1100 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1106 code = (*ops->close)(rock, avc, adc, tsmall);
1107 (*ops->destroy)(&rock, code);
1110 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA,&xferStartTime,
1111 bytesToXfer, bytesXferred);