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 #endif /* AFS_NOSTATS */
449 afs_int32 bytesread, byteswritten;
450 code = (*ops->prepare)(rock, alen, &tlen);
454 code = (*ops->read)(rock, fP, offset, tlen, &bytesread);
459 code = (*ops->write)(rock, tlen, &byteswritten);
463 bytesXferred += byteswritten;
464 #endif /* AFS_NOSTATS */
469 * if file has been locked on server, can allow
472 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
473 *shouldwake = 0; /* only do this once */
477 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
478 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
479 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
482 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
483 &xferStartTime, bytesToXfer, bytesXferred);
484 #endif /* AFS_NOSTATS */
487 if ((tdc->f.chunkBytes < afs_OtherCSize)
488 && (i < (nchunks - 1)) && code == 0) {
489 int bsent, tlen, sbytes = afs_OtherCSize - tdc->f.chunkBytes;
490 char *tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
493 tlen = (sbytes > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : sbytes);
494 memset(tbuffer, 0, tlen);
497 ((struct rxfs_storeVariables*)rock)->call, tbuffer, tlen);
501 code = -33; /* XXX */
506 osi_FreeLargeSpace(tbuffer);
508 stored += tdc->f.chunkBytes;
509 /* ideally, I'd like to unlock the dcache and turn
510 * off the writing bit here, but that would
511 * require being able to retry StoreAllSegments in
512 * the event of a failure. It only really matters
513 * if user can't read from a 'locked' dcache or
514 * one which has the writing bit turned on. */
518 code = (*ops->close)(rock, OutStatus, doProcessFS);
524 code = (*ops->destroy)(&rock, code);
528 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
532 * \param dclist pointer to the list of dcaches
533 * \param avc Ptr to the vcache entry.
534 * \param areq Ptr to the request structure
535 * \param sync sync flag
536 * \param minj the chunk offset for this call
537 * \param high index of last dcache to store
538 * \param moredata the moredata flag
539 * \param anewDV Ptr to the dataversion after store
540 * \param amaxStoredLength Ptr to the amount of that is actually stored
542 * \note Environment: Nothing interesting.
545 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
546 struct vrequest *areq, int sync,
547 unsigned int minj, unsigned int high,
548 unsigned int moredata,
549 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
552 struct storeOps *ops;
556 struct AFSStoreStatus InStatus;
557 struct AFSFetchStatus OutStatus;
559 afs_size_t base, bytes, length;
562 unsigned int first = 0;
565 for (bytes = 0, j = 0; !code && j <= high; j++) {
567 ObtainSharedLock(&(dcList[j]->lock), 629);
570 bytes += dcList[j]->f.chunkBytes;
571 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
572 && (dcList[j]->f.chunk - minj < high)
574 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
578 if (bytes && (j == high || !dcList[j + 1])) {
579 struct dcache **dclist = &dcList[first];
580 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
581 base = AFS_CHUNKTOBASE(first + minj);
584 * take a list of dcache structs and send them all off to the server
585 * the list must be in order, and the chunks contiguous.
586 * Note - there is no locking done by this code currently. For
587 * safety's sake, xdcache could be locked over the entire call.
588 * However, that pretty well ties up all the threads. Meantime, all
589 * the chunks _MUST_ have their refcounts bumped.
590 * The writes done before a store back will clear setuid-ness
592 * We can permit CacheStoreProc to wake up the user process IFF we
593 * are doing the last RPC for this close, ie, storing back the last
594 * set of contiguous chunks of a file.
597 nchunks = 1 + j - first;
598 nomore = !(moredata || (j != high));
599 length = lmin(avc->f.m.Length, avc->f.truncPos);
600 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
601 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
602 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
603 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
604 ICL_HANDLE_OFFSET(length));
607 tc = afs_Conn(&avc->f.fid, areq, 0);
609 #ifdef AFS_64BIT_CLIENT
612 code = rxfs_storeInit(avc, tc, length, bytes, base,
616 "afs_CacheStoreProc: rxfs_storeInit failed with %d", code);
619 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
620 &doProcessFS, &OutStatus, nchunks, nomore, ops, rock);
622 #ifdef AFS_64BIT_CLIENT
623 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
624 afs_serverSetNo64Bit(tc);
627 #endif /* AFS_64BIT_CLIENT */
629 (tc, code, &avc->f.fid, areq,
630 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
633 /* put back all remaining locked dcache entries */
634 for (i = 0; i < nchunks; i++) {
635 struct dcache *tdc = dclist[i];
637 if (afs_indexFlags[tdc->index] & IFDataMod) {
639 * LOCKXXX -- should hold afs_xdcache(W) when
640 * modifying afs_indexFlags.
642 afs_indexFlags[tdc->index] &= ~IFDataMod;
643 afs_stats_cmperf.cacheCurrDirtyChunks--;
644 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
645 if (sync & AFS_VMSYNC_INVAL) {
646 /* since we have invalidated all the pages of this
647 ** vnode by calling osi_VM_TryToSmush, we can
648 ** safely mark this dcache entry as not having
649 ** any pages. This vnode now becomes eligible for
650 ** reclamation by getDownD.
652 afs_indexFlags[tdc->index] &= ~IFAnyPages;
656 UpgradeSToWLock(&tdc->lock, 628);
657 tdc->f.states &= ~DWriting; /* correct? */
658 tdc->dflags |= DFEntryMod;
659 ReleaseWriteLock(&tdc->lock);
661 /* Mark the entry as released */
666 /* Now copy out return params */
667 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
668 afs_ProcessFS(avc, &OutStatus, areq);
669 /* Keep last (max) size of file on server to see if
670 * we need to call afs_StoreMini to extend the file.
673 *amaxStoredLength = OutStatus.Length;
674 ConvertWToSLock(&avc->lock);
679 for (j++; j <= high; j++) {
681 ReleaseSharedLock(&(dcList[j]->lock));
682 afs_PutDCache(dcList[j]);
683 /* Releasing entry */
689 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
690 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
698 /* rock and operations for RX_FILESERVER */
700 struct rxfs_fetchVariables {
701 struct rx_call *call;
705 afs_int32 hasNo64bit;
711 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
715 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
718 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
720 code = rx_Read(v->call, v->tbuffer, tlen);
729 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
732 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
736 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
746 rxfs_fetchMemWrite(void *r, struct osi_file *fP,
747 afs_uint32 offset, afs_uint32 tlen,
748 afs_uint32 *byteswritten)
751 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
752 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
754 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
758 *byteswritten = code;
763 rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
764 afs_uint32 offset, afs_uint32 tlen,
765 afs_uint32 *byteswritten)
768 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
770 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
774 *byteswritten = code;
780 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
781 struct afs_FetchOutput *tsmall)
783 afs_int32 code, code1 = 0;
784 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
790 code = EndRXAFS_FetchData(v->call, &tsmall->OutStatus,
797 code1 = rx_EndCall(v->call, code);
808 rxfs_fetchDestroy(void **r, afs_int32 error)
810 afs_int32 code = error;
811 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
815 osi_FreeLargeSpace(v->tbuffer);
817 osi_FreeSmallSpace(v->iov);
818 osi_FreeSmallSpace(v);
823 rxfs_fetchMore(void *r, afs_uint32 *length, afs_uint32 *moredata)
826 register struct rxfs_fetchVariables *v
827 = (struct rxfs_fetchVariables *)r;
830 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
831 *length = ntohl(*length);
833 if (code != sizeof(afs_int32)) {
834 code = rx_Error(v->call);
835 return (code ? code : -1); /* try to return code, not -1 */
841 struct fetchOps rxfs_fetchUfsOps = {
850 struct fetchOps rxfs_fetchMemOps = {
859 rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
860 afs_uint32 size, afs_uint32 *alength, struct dcache *adc,
861 struct osi_file *fP, struct fetchOps **ops, void **rock)
863 struct rxfs_fetchVariables *v;
865 afs_int32 length_hi, length, bytes;
866 #ifdef AFS_64BIT_CLIENT
868 afs_size_t lengthFound; /* as returned from server */
869 #endif /* AFS_64BIT_CLIENT */
871 v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
873 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
874 memset(v, 0, sizeof(struct rxfs_fetchVariables));
877 v->call = rx_NewCall(tc->id);
880 #ifdef AFS_64BIT_CLIENT
881 length_hi = code = 0;
882 if (!afs_serverHasNo64Bit(tc)) {
885 code = StartRXAFS_FetchData64(v->call, (struct AFSFid *)&avc->f.fid.Fid,
889 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
890 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
892 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
894 if (bytes == sizeof(afs_int32)) {
895 length_hi = ntohl(length_hi);
898 code = rx_Error(v->call);
900 code1 = rx_EndCall(v->call, code);
906 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
907 if (base > 0x7FFFFFFF) {
914 v->call = rx_NewCall(tc->id);
916 StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
920 afs_serverSetNo64Bit(tc);
924 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
926 if (bytes == sizeof(afs_int32))
927 length = ntohl(length);
929 code = rx_Error(v->call);
932 FillInt64(lengthFound, length_hi, length);
933 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
934 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
936 ICL_HANDLE_OFFSET(lengthFound));
937 #else /* AFS_64BIT_CLIENT */
939 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
944 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
946 if (bytes == sizeof(afs_int32))
947 length = ntohl(length);
949 code = rx_Error(v->call);
951 #endif /* AFS_64BIT_CLIENT */
953 osi_FreeSmallSpace(v);
957 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
958 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
960 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
961 osi_Assert(WriteLocked(&adc->lock));
963 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
966 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
967 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
968 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
970 * We need to alloc the iovecs on the heap so that they are "pinned"
971 * rather than declare them on the stack - defect 11272
973 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
975 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
976 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
985 * Routine called on fetch; also tells people waiting for data
986 * that more has arrived.
988 * \param tc Ptr to the Rx connection structure.
989 * \param fP File descriptor for the cache file.
990 * \param abase Base offset to fetch.
991 * \param adc Ptr to the dcache entry for the file, write-locked.
992 * \param avc Ptr to the vcache entry for the file.
993 * \param size Amount of data that should be fetched.
994 * \param tsmall Ptr to the afs_FetchOutput structure.
996 * \note Environment: Nothing interesting.
999 afs_CacheFetchProc(register struct afs_conn *tc,
1000 register struct osi_file *fP, afs_size_t abase,
1001 struct dcache *adc, struct vcache *avc,
1003 struct afs_FetchOutput *tsmall)
1005 register afs_int32 code;
1007 afs_uint32 bytesread, byteswritten;
1008 struct fetchOps *ops = NULL;
1011 register int offset = 0;
1015 osi_timeval_t xferStartTime; /*FS xfer start time */
1016 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1019 AFS_STATCNT(CacheFetchProc);
1021 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1023 code = rxfs_fetchInit(tc, avc, abase, size, &length, adc, fP, &ops, &rock);
1026 osi_GetuTime(&xferStartTime);
1027 #endif /* AFS_NOSTATS */
1029 adc->validPos = abase;
1033 code = (*ops->more)(rock, &length, &moredata);
1038 * The fetch protocol is extended for the AFS/DFS translator
1039 * to allow multiple blocks of data, each with its own length,
1040 * to be returned. As long as the top bit is set, there are more
1043 * We do not do this for AFS file servers because they sometimes
1044 * return large negative numbers as the transfer size.
1046 if (avc->f.states & CForeign) {
1047 moredata = length & 0x80000000;
1048 length &= ~0x80000000;
1053 bytesToXfer += length;
1054 #endif /* AFS_NOSTATS */
1055 while (length > 0) {
1056 #ifdef RX_KERNEL_TRACE
1057 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1060 code = (*ops->read)(rock, length, &bytesread);
1061 #ifdef RX_KERNEL_TRACE
1062 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1066 bytesXferred += bytesread;
1067 #endif /* AFS_NOSTATS */
1069 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1070 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1071 ICL_TYPE_INT32, length);
1075 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1078 offset += bytesread;
1080 length -= bytesread;
1081 adc->validPos = abase;
1082 if (afs_osi_Wakeup(&adc->validPos) == 0)
1083 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1084 __FILE__, ICL_TYPE_INT32, __LINE__,
1085 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1091 code = (*ops->close)(rock, avc, adc, tsmall);
1092 (*ops->destroy)(&rock, code);
1095 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA,&xferStartTime,
1096 bytesToXfer, bytesXferred);