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;
30 /* rock and operations for RX_FILESERVER */
32 struct rxfs_storeVariables {
38 struct AFSStoreStatus InStatus;
42 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
44 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
49 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
52 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
54 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
56 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
59 code = rx_Error(v->call);
71 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
72 afs_uint32 tlen, afs_uint32 *bytesread)
75 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
78 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
84 #if defined(KERNEL_HAVE_UERROR)
92 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
93 afs_uint32 tlen, afs_uint32 *bytesread)
96 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
97 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
100 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
108 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
111 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
114 code = rx_Writev(v->call, v->tiov, v->tnio, l);
117 code = rx_Error(v->call);
118 return (code ? code : -33);
120 *byteswritten = code;
125 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
128 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
131 code = rx_Write(v->call, v->tbuffer, l);
132 /* writing 0 bytes will
133 * push a short packet. Is that really what we want, just because the
134 * data didn't come back from the disk yet? Let's try it and see. */
137 code = rx_Error(v->call);
138 return (code ? code : -33);
140 *byteswritten = code;
145 rxfs_storeStatus(void *rock)
147 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
149 if (rx_GetRemoteStatus(v->call) & 1)
155 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
158 struct AFSVolSync tsync;
159 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
162 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
165 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
171 rxfs_storeDestroy(void **r, afs_int32 error)
173 afs_int32 code = error;
174 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
180 code2 = rx_EndCall(v->call, code);
186 osi_FreeLargeSpace(v->tbuffer);
188 osi_FreeSmallSpace(v->tiov);
189 osi_FreeSmallSpace(v);
194 struct storeOps rxfs_storeUfsOps = {
195 rxfs_storeUfsPrepare,
204 struct storeOps rxfs_storeMemOps = {
205 rxfs_storeMemPrepare,
214 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t tlen,
215 afs_size_t bytes, afs_size_t base,
216 struct storeOps **ops, void **rock)
219 struct rxfs_storeVariables *v;
220 struct rx_call *tcall;
225 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
227 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
228 memset(v, 0, sizeof(struct rxfs_storeVariables));
230 v->InStatus.ClientModTime = avc->f.m.Date;
231 v->InStatus.Mask = AFS_SETMODTIME;
234 tcall = rx_NewCall(tc->id);
235 #ifdef AFS_64BIT_CLIENT
236 if (!afs_serverHasNo64Bit(tc))
237 code = StartRXAFS_StoreData64(tcall, (struct AFSFid *) &avc->f.fid.Fid,
238 &v->InStatus, base, bytes, tlen);
240 if (tlen > 0xFFFFFFFF) {
244 afs_int32 t1, t2, t3;
248 code = StartRXAFS_StoreData(tcall, (struct AFSFid *)&avc->f.fid.Fid,
249 &v->InStatus, t1, t2, t3);
252 #else /* AFS_64BIT_CLIENT */
253 code = StartRXAFS_StoreData(tcall, (struct AFSFid *)&avc->f.fid.Fid,
254 &v->InStatus, base, bytes, tlen);
255 #endif /* AFS_64BIT_CLIENT */
258 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
259 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
262 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
263 *ops = (struct storeOps *) &rxfs_storeUfsOps;
265 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
268 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
269 *ops = (struct storeOps *) &rxfs_storeMemOps;
271 /* do this at a higher level now -- it's a parameter */
272 /* for now, only do 'continue from close' code if file fits in one
273 * chunk. Could clearly do better: if only one modified chunk
274 * then can still do this. can do this on *last* modified chunk */
275 tlen = avc->f.m.Length - 1; /* byte position of last byte we'll store */
277 if (AFS_CHUNK(tlen) != 0)
290 unsigned int storeallmissing = 0;
292 * Called for each chunk upon store.
294 * \param avc Ptr to the vcache entry of the file being stored.
295 * \param dclist pointer to the list of dcaches
296 * \param bytes total number of bytes for the current operation
297 * \param anewDV Ptr to the dataversion after store
298 * \param doProcessFS pointer to the "do process FetchStatus" flag
299 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
300 * \param nchunks number of dcaches to consider
301 * \param nomore copy of the "no more data" flag
302 * \param ops pointer to the block of storeOps to be used for this operation
303 * \param rock pointer to the opaque protocol-specific data of this operation
306 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
310 struct AFSFetchStatus *OutStatus,
313 struct storeOps *ops, void *rock)
315 int *shouldwake = NULL;
320 struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */
321 osi_timeval_t xferStartTime, /*FS xfer start time */
322 xferStopTime; /*FS xfer stop time */
323 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
324 afs_size_t bytesXferred = 10000; /* # bytes actually xferred */
325 #endif /* AFS_NOSTATS */
328 for (i = 0; i < nchunks && !code; i++) {
332 struct dcache *tdc = dclist[i];
333 afs_int32 alen = tdc->f.chunkBytes;
335 afs_warn("afs: missing dcache!\n");
337 continue; /* panic? */
339 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
340 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
341 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
344 if (avc->asynchrony == -1) {
345 if (afs_defaultAsynchrony > (bytes - stored))
346 shouldwake = &nomore;
348 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
349 shouldwake = &nomore;
351 fP = afs_CFileOpen(&tdc->f.inode);
353 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
354 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
355 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
357 AFS_STATCNT(CacheStoreProc);
359 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
360 avc->f.truncPos = AFS_NOTRUNC;
363 * In this case, alen is *always* the amount of data we'll be trying
369 xferP = &(afs_stats_cmfullperf.rpc.
370 fsXferTimes[AFS_STATS_FS_XFERIDX_STOREDATA]);
371 osi_GetuTime(&xferStartTime);
372 #endif /* AFS_NOSTATS */
376 afs_int32 bytesread, byteswritten;
377 code = (*ops->prepare)(rock, alen, &tlen);
381 code = (*ops->read)(rock, fP, offset, tlen, &bytesread);
386 code = (*ops->write)(rock, tlen, &byteswritten);
390 bytesXferred += byteswritten;
391 #endif /* AFS_NOSTATS */
396 * if file has been locked on server, can allow
399 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
400 *shouldwake = 0; /* only do this once */
404 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
405 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
406 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
409 osi_GetuTime(&xferStopTime);
412 (xferP->numSuccesses)++;
413 afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] +=
416 (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] >> 10);
417 afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] &= 0x3FF;
418 if (bytesXferred < xferP->minBytes)
419 xferP->minBytes = bytesXferred;
420 if (bytesXferred > xferP->maxBytes)
421 xferP->maxBytes = bytesXferred;
424 * Tally the size of the object. Note: we tally the actual size,
425 * NOT the number of bytes that made it out over the wire.
427 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0)
429 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1)
431 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2)
433 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3)
435 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4)
437 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5)
439 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6)
441 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7)
446 afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
447 afs_stats_AddTo((xferP->sumTime), elapsedTime);
448 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
449 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime)))
450 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
451 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime)))
452 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
454 #endif /* AFS_NOSTATS */
457 if ((tdc->f.chunkBytes < afs_OtherCSize)
458 && (i < (nchunks - 1)) && code == 0) {
459 int bsent, tlen, sbytes = afs_OtherCSize - tdc->f.chunkBytes;
460 char *tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
463 tlen = (sbytes > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : sbytes);
464 memset(tbuffer, 0, tlen);
467 ((struct rxfs_storeVariables*)rock)->call, tbuffer, tlen);
471 code = -33; /* XXX */
476 osi_FreeLargeSpace(tbuffer);
478 stored += tdc->f.chunkBytes;
479 /* ideally, I'd like to unlock the dcache and turn
480 * off the writing bit here, but that would
481 * require being able to retry StoreAllSegments in
482 * the event of a failure. It only really matters
483 * if user can't read from a 'locked' dcache or
484 * one which has the writing bit turned on. */
488 code = (*ops->close)(rock, OutStatus, doProcessFS);
494 code = (*ops->destroy)(&rock, code);
498 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
502 * \param dclist pointer to the list of dcaches
503 * \param avc Ptr to the vcache entry.
504 * \param areq Ptr to the request structure
505 * \param sync sync flag
506 * \param minj the chunk offset for this call
507 * \param high index of last dcache to store
508 * \param moredata the moredata flag
509 * \param anewDV Ptr to the dataversion after store
510 * \param amaxStoredLength Ptr to the amount of that is actually stored
512 * \note Environment: Nothing interesting.
515 afs_CacheStoreVCache(struct dcache **dcList,
517 struct vrequest *areq,
521 unsigned int moredata,
523 afs_size_t *amaxStoredLength)
526 struct storeOps *ops;
530 struct AFSStoreStatus InStatus;
531 struct AFSFetchStatus OutStatus;
533 afs_size_t base, bytes, length;
536 unsigned int first = 0;
539 for (bytes = 0, j = 0; !code && j <= high; j++) {
541 ObtainSharedLock(&(dcList[j]->lock), 629);
544 bytes += dcList[j]->f.chunkBytes;
545 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
546 && (dcList[j]->f.chunk - minj < high)
548 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
552 if (bytes && (j == high || !dcList[j + 1])) {
553 struct dcache **dclist = &dcList[first];
554 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
555 base = AFS_CHUNKTOBASE(first + minj);
558 * take a list of dcache structs and send them all off to the server
559 * the list must be in order, and the chunks contiguous.
560 * Note - there is no locking done by this code currently. For
561 * safety's sake, xdcache could be locked over the entire call.
562 * However, that pretty well ties up all the threads. Meantime, all
563 * the chunks _MUST_ have their refcounts bumped.
564 * The writes done before a store back will clear setuid-ness
566 * We can permit CacheStoreProc to wake up the user process IFF we
567 * are doing the last RPC for this close, ie, storing back the last
568 * set of contiguous chunks of a file.
571 nchunks = 1 + j - first;
572 nomore = !(moredata || (j != high));
573 InStatus.ClientModTime = avc->f.m.Date;
574 InStatus.Mask = AFS_SETMODTIME;
575 if (sync & AFS_SYNC) {
576 InStatus.Mask |= AFS_FSYNC;
578 length = lmin(avc->f.m.Length, avc->f.truncPos);
579 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
580 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
581 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
582 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
583 ICL_HANDLE_OFFSET(length));
586 tc = afs_Conn(&avc->f.fid, areq, 0);
588 #ifdef AFS_64BIT_CLIENT
591 code = rxfs_storeInit(avc,tc,length,bytes,base,&ops,&rock);
594 "afs_CacheStoreProc: rxfs_storeInit failed with %d", code);
597 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
598 &doProcessFS, &OutStatus, nchunks, nomore, ops, rock);
600 #ifdef AFS_64BIT_CLIENT
601 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
602 afs_serverSetNo64Bit(tc);
605 #endif /* AFS_64BIT_CLIENT */
607 (tc, code, &avc->f.fid, areq,
608 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
611 /* put back all remaining locked dcache entries */
612 for (i = 0; i < nchunks; i++) {
613 struct dcache *tdc = dclist[i];
615 if (afs_indexFlags[tdc->index] & IFDataMod) {
617 * LOCKXXX -- should hold afs_xdcache(W) when
618 * modifying afs_indexFlags.
620 afs_indexFlags[tdc->index] &= ~IFDataMod;
621 afs_stats_cmperf.cacheCurrDirtyChunks--;
622 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
623 if (sync & AFS_VMSYNC_INVAL) {
624 /* since we have invalidated all the pages of this
625 ** vnode by calling osi_VM_TryToSmush, we can
626 ** safely mark this dcache entry as not having
627 ** any pages. This vnode now becomes eligible for
628 ** reclamation by getDownD.
630 afs_indexFlags[tdc->index] &= ~IFAnyPages;
634 UpgradeSToWLock(&tdc->lock, 628);
635 tdc->f.states &= ~DWriting; /* correct? */
636 tdc->dflags |= DFEntryMod;
637 ReleaseWriteLock(&tdc->lock);
639 /* Mark the entry as released */
644 /* Now copy out return params */
645 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
646 afs_ProcessFS(avc, &OutStatus, areq);
647 /* Keep last (max) size of file on server to see if
648 * we need to call afs_StoreMini to extend the file.
651 *amaxStoredLength = OutStatus.Length;
652 ConvertWToSLock(&avc->lock);
657 for (j++; j <= high; j++) {
659 ReleaseSharedLock(&(dcList[j]->lock));
660 afs_PutDCache(dcList[j]);
661 /* Releasing entry */
667 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
668 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
676 /* rock and operations for RX_FILESERVER */
678 struct rxfs_fetchVariables {
679 struct rx_call *call;
683 afs_int32 hasNo64bit;
689 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
693 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
696 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
698 code = rx_Read(v->call, v->tbuffer, tlen);
707 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
710 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
714 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
724 rxfs_fetchMemWrite(void *r, struct osi_file *fP,
725 afs_uint32 offset, afs_uint32 tlen,
726 afs_uint32 *byteswritten)
729 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
730 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
732 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
736 *byteswritten = code;
741 rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
742 afs_uint32 offset, afs_uint32 tlen,
743 afs_uint32 *byteswritten)
746 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
748 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
752 *byteswritten = code;
758 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
759 struct afs_FetchOutput *tsmall)
761 afs_int32 code, code1 = 0;
762 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
768 code = EndRXAFS_FetchData(v->call, &tsmall->OutStatus,
775 code1 = rx_EndCall(v->call, code);
786 rxfs_fetchDestroy(void **r, afs_int32 error)
788 afs_int32 code = error;
789 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
793 osi_FreeLargeSpace(v->tbuffer);
795 osi_FreeSmallSpace(v->iov);
796 osi_FreeSmallSpace(v);
801 rxfs_fetchMore(void *r, afs_uint32 *length, afs_uint32 *moredata)
804 register struct rxfs_fetchVariables *v
805 = (struct rxfs_fetchVariables *)r;
808 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
809 *length = ntohl(*length);
811 if (code != sizeof(afs_int32)) {
812 code = rx_Error(v->call);
813 return (code ? code : -1); /* try to return code, not -1 */
819 struct fetchOps rxfs_fetchUfsOps = {
828 struct fetchOps rxfs_fetchMemOps = {
837 rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
838 afs_uint32 size, afs_uint32 *out_length, struct dcache *adc,
839 struct osi_file *fP, struct fetchOps **ops, void **rock)
841 struct rxfs_fetchVariables *v;
843 afs_int32 length_hi, length, bytes;
844 #ifdef AFS_64BIT_CLIENT
846 afs_size_t lengthFound; /* as returned from server */
847 #endif /* AFS_64BIT_CLIENT */
849 v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
851 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
852 memset(v, 0, sizeof(struct rxfs_fetchVariables));
855 v->call = rx_NewCall(tc->id);
858 #ifdef AFS_64BIT_CLIENT
859 length_hi = code = 0;
860 if (!afs_serverHasNo64Bit(tc)) {
863 code = StartRXAFS_FetchData64(v->call, (struct AFSFid *)&avc->f.fid.Fid,
867 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
868 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
870 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
872 if (bytes == sizeof(afs_int32)) {
873 length_hi = ntohl(length_hi);
876 code = rx_Error(v->call);
878 code1 = rx_EndCall(v->call, code);
884 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
885 if (base > 0x7FFFFFFF) {
892 v->call = rx_NewCall(tc->id);
894 StartRXAFS_FetchData(v->call, (struct AFSFid *)
895 &avc->f.fid.Fid, pos,
899 afs_serverSetNo64Bit(tc);
903 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
905 if (bytes == sizeof(afs_int32))
906 length = ntohl(length);
908 code = rx_Error(v->call);
911 FillInt64(lengthFound, length_hi, length);
912 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
913 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
915 ICL_HANDLE_OFFSET(lengthFound));
916 #else /* AFS_64BIT_CLIENT */
918 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
923 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
925 if (bytes == sizeof(afs_int32))
926 length = ntohl(length);
928 code = rx_Error(v->call);
930 #endif /* AFS_64BIT_CLIENT */
932 osi_FreeSmallSpace(v);
936 if ( cacheDiskType == AFS_FCACHE_TYPE_UFS ) {
937 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
939 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
940 osi_Assert(WriteLocked(&adc->lock));
942 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
945 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
946 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
947 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
949 * We need to alloc the iovecs on the heap so that they are "pinned"
950 * rather than declare them on the stack - defect 11272
952 v->iov = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec) *
955 osi_Panic("afs_CacheFetchProc: osi_AllocSmallSpace for iovecs returned NULL\n");
956 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
959 *out_length = length;
965 * Routine called on fetch; also tells people waiting for data
966 * that more has arrived.
968 * \param tc Ptr to the Rx connection structure.
969 * \param fP File descriptor for the cache file.
970 * \param abase Base offset to fetch.
971 * \param adc Ptr to the dcache entry for the file, write-locked.
972 * \param avc Ptr to the vcache entry for the file.
973 * \param size Amount of data that should be fetched.
974 * \param tsmall Ptr to the afs_FetchOutput structure.
976 * \note Environment: Nothing interesting.
979 afs_CacheFetchProc(register struct afs_conn *tc,
980 register struct osi_file *fP, afs_size_t abase,
981 struct dcache *adc, struct vcache *avc,
983 struct afs_FetchOutput *tsmall)
985 register afs_int32 code;
987 afs_uint32 bytesread, byteswritten;
988 struct fetchOps *ops = NULL;
991 register int offset = 0;
995 struct afs_stats_xferData *xferP; /* Ptr to this op's xfer struct */
996 osi_timeval_t xferStartTime, /*FS xfer start time */
997 xferStopTime; /*FS xfer stop time */
998 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1001 AFS_STATCNT(CacheFetchProc);
1003 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1005 code = rxfs_fetchInit(tc, avc, abase, size, &length, adc, fP, &ops, &rock);
1009 &(afs_stats_cmfullperf.rpc.fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]);
1010 osi_GetuTime(&xferStartTime);
1011 #endif /* AFS_NOSTATS */
1013 adc->validPos = abase;
1017 code = (*ops->more)(rock, &length, &moredata);
1022 * The fetch protocol is extended for the AFS/DFS translator
1023 * to allow multiple blocks of data, each with its own length,
1024 * to be returned. As long as the top bit is set, there are more
1027 * We do not do this for AFS file servers because they sometimes
1028 * return large negative numbers as the transfer size.
1030 if (avc->f.states & CForeign) {
1031 moredata = length & 0x80000000;
1032 length &= ~0x80000000;
1037 bytesToXfer += length;
1038 #endif /* AFS_NOSTATS */
1039 while (length > 0) {
1040 #ifdef RX_KERNEL_TRACE
1041 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1044 code = (*ops->read)(rock, length, &bytesread);
1045 #ifdef RX_KERNEL_TRACE
1046 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1050 bytesXferred += bytesread;
1051 #endif /* AFS_NOSTATS */
1053 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1054 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1055 ICL_TYPE_INT32, length);
1059 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1062 offset += bytesread;
1064 length -= bytesread;
1065 adc->validPos = abase;
1066 if (afs_osi_Wakeup(&adc->validPos) == 0)
1067 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1068 __FILE__, ICL_TYPE_INT32, __LINE__,
1069 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1075 code = (*ops->close)(rock, avc, adc, tsmall);
1076 (*ops->destroy)(&rock, code);
1079 osi_GetuTime(&xferStopTime);
1080 (xferP->numXfers)++;
1082 (xferP->numSuccesses)++;
1083 afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] += bytesXferred;
1084 (xferP->sumBytes) +=
1085 (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10);
1086 afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF;
1087 if (bytesXferred < xferP->minBytes)
1088 xferP->minBytes = bytesXferred;
1089 if (bytesXferred > xferP->maxBytes)
1090 xferP->maxBytes = bytesXferred;
1093 * Tally the size of the object. Note: we tally the actual size,
1094 * NOT the number of bytes that made it out over the wire.
1096 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0)
1097 (xferP->count[0])++;
1098 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1)
1099 (xferP->count[1])++;
1100 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2)
1101 (xferP->count[2])++;
1102 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3)
1103 (xferP->count[3])++;
1104 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4)
1105 (xferP->count[4])++;
1106 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5)
1107 (xferP->count[5])++;
1108 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6)
1109 (xferP->count[6])++;
1110 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7)
1111 (xferP->count[7])++;
1113 (xferP->count[8])++;
1115 afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
1116 afs_stats_AddTo((xferP->sumTime), elapsedTime);
1117 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
1118 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
1119 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
1121 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
1122 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);