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 */
86 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
88 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
93 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
96 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
98 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
100 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
103 code = rx_Error(v->call);
115 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
116 afs_uint32 tlen, afs_uint32 *bytesread)
119 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
122 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
128 #if defined(KERNEL_HAVE_UERROR)
136 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
137 afs_uint32 tlen, afs_uint32 *bytesread)
140 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
141 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
144 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
152 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
155 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
158 code = rx_Writev(v->call, v->tiov, v->tnio, l);
161 code = rx_Error(v->call);
162 return (code ? code : -33);
164 *byteswritten = code;
169 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
172 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
175 code = rx_Write(v->call, v->tbuffer, l);
176 /* writing 0 bytes will
177 * push a short packet. Is that really what we want, just because the
178 * data didn't come back from the disk yet? Let's try it and see. */
181 code = rx_Error(v->call);
182 return (code ? code : -33);
184 *byteswritten = code;
189 rxfs_storePadd(void *rock, afs_uint32 size)
193 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
196 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
197 memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
200 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
202 code = rx_Write(v->call, v->tbuffer, tlen);
206 return -33; /* XXX */
213 rxfs_storeStatus(void *rock)
215 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
217 if (rx_GetRemoteStatus(v->call) & 1)
223 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
226 struct AFSVolSync tsync;
227 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
232 #ifdef AFS_64BIT_CLIENT
234 code = EndRXAFS_StoreData64(v->call, OutStatus, &tsync);
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;
254 code = rx_EndCall(v->call, error);
260 osi_FreeLargeSpace(v->tbuffer);
262 osi_FreeSmallSpace(v->tiov);
263 osi_FreeSmallSpace(v);
268 struct storeOps rxfs_storeUfsOps = {
269 .prepare = rxfs_storeUfsPrepare,
270 .read = rxfs_storeUfsRead,
271 .write = rxfs_storeUfsWrite,
272 .status = rxfs_storeStatus,
273 .padd = rxfs_storePadd,
274 .close = rxfs_storeClose,
275 .destroy = rxfs_storeDestroy,
276 #ifdef AFS_LINUX26_ENV
277 .storeproc = afs_linux_storeproc
282 struct storeOps rxfs_storeMemOps = {
283 .prepare = rxfs_storeMemPrepare,
284 .read = rxfs_storeMemRead,
285 .write = rxfs_storeMemWrite,
286 .status = rxfs_storeStatus,
287 .padd = rxfs_storePadd,
288 .close = rxfs_storeClose,
289 .destroy = rxfs_storeDestroy
293 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
294 afs_size_t bytes, afs_size_t length,
295 int sync, struct storeOps **ops, void **rock)
298 struct rxfs_storeVariables *v;
303 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
305 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
306 memset(v, 0, sizeof(struct rxfs_storeVariables));
308 v->InStatus.ClientModTime = avc->f.m.Date;
309 v->InStatus.Mask = AFS_SETMODTIME;
312 v->InStatus.Mask |= AFS_FSYNC;
314 v->call = rx_NewCall(tc->id);
316 #ifdef AFS_64BIT_CLIENT
317 if (!afs_serverHasNo64Bit(tc))
318 code = StartRXAFS_StoreData64(
319 v->call, (struct AFSFid*)&avc->f.fid.Fid,
320 &v->InStatus, base, bytes, length);
322 if (length > 0xFFFFFFFF)
325 afs_int32 t1 = base, t2 = bytes, t3 = length;
326 code = StartRXAFS_StoreData(v->call,
327 (struct AFSFid *) &avc->f.fid.Fid,
328 &v->InStatus, t1, t2, t3);
330 #else /* AFS_64BIT_CLIENT */
331 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
332 &v->InStatus, base, bytes, length);
333 #endif /* AFS_64BIT_CLIENT */
338 osi_FreeSmallSpace(v);
341 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
342 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
345 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
346 *ops = (struct storeOps *) &rxfs_storeUfsOps;
348 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
351 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
352 *ops = (struct storeOps *) &rxfs_storeMemOps;
354 /* do this at a higher level now -- it's a parameter */
355 /* for now, only do 'continue from close' code if file fits in one
356 * chunk. Could clearly do better: if only one modified chunk
357 * then can still do this. can do this on *last* modified chunk */
358 length = avc->f.m.Length - 1; /* byte position of last byte we'll store */
360 if (AFS_CHUNK(length) != 0)
373 afs_GenericStoreProc(struct storeOps *ops, void *rock,
374 struct dcache *tdc, int *shouldwake,
375 afs_size_t *bytesXferred)
377 struct rxfs_storeVariables *svar = rock;
378 afs_uint32 tlen, bytesread, byteswritten;
382 struct osi_file *tfile;
384 size = tdc->f.chunkBytes;
386 tfile = afs_CFileOpen(&tdc->f.inode);
389 code = (*ops->prepare)(rock, size, &tlen);
393 code = (*ops->read)(rock, tfile, offset, tlen, &bytesread);
398 code = (*ops->write)(rock, tlen, &byteswritten);
402 *bytesXferred += byteswritten;
403 #endif /* AFS_NOSTATS */
408 * if file has been locked on server, can allow
411 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
412 *shouldwake = 0; /* only do this once */
413 afs_wakeup(svar->vcache);
416 afs_CFileClose(tfile);
421 unsigned int storeallmissing = 0;
423 * Called for each chunk upon store.
425 * \param avc Ptr to the vcache entry of the file being stored.
426 * \param dclist pointer to the list of dcaches
427 * \param bytes total number of bytes for the current operation
428 * \param anewDV Ptr to the dataversion after store
429 * \param doProcessFS pointer to the "do process FetchStatus" flag
430 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
431 * \param nchunks number of dcaches to consider
432 * \param nomore copy of the "no more data" flag
433 * \param ops pointer to the block of storeOps to be used for this operation
434 * \param rock pointer to the opaque protocol-specific data of this operation
437 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
441 struct AFSFetchStatus *OutStatus,
444 struct storeOps *ops, void *rock)
446 int *shouldwake = NULL;
449 afs_size_t bytesXferred;
452 osi_timeval_t xferStartTime; /*FS xfer start time */
453 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
454 #endif /* AFS_NOSTATS */
457 for (i = 0; i < nchunks && !code; i++) {
459 struct dcache *tdc = dclist[i];
460 afs_int32 size = tdc->f.chunkBytes;
462 afs_warn("afs: missing dcache!\n");
464 continue; /* panic? */
466 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
467 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
468 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
471 if (avc->asynchrony == -1) {
472 if (afs_defaultAsynchrony > (bytes - stored))
473 shouldwake = &nomore;
475 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
476 shouldwake = &nomore;
479 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
480 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
481 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
483 AFS_STATCNT(CacheStoreProc);
485 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
486 avc->f.truncPos = AFS_NOTRUNC;
489 * In this case, size is *always* the amount of data we'll be trying
494 osi_GetuTime(&xferStartTime);
495 #endif /* AFS_NOSTATS */
499 code = (*ops->storeproc)(ops, rock, tdc, shouldwake,
502 code = afs_GenericStoreProc(ops, rock, tdc, shouldwake,
505 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
506 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
507 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
510 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
511 &xferStartTime, bytesToXfer, bytesXferred);
512 #endif /* AFS_NOSTATS */
514 if ((tdc->f.chunkBytes < afs_OtherCSize)
515 && (i < (nchunks - 1)) && code == 0) {
516 code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
518 stored += tdc->f.chunkBytes;
519 /* ideally, I'd like to unlock the dcache and turn
520 * off the writing bit here, but that would
521 * require being able to retry StoreAllSegments in
522 * the event of a failure. It only really matters
523 * if user can't read from a 'locked' dcache or
524 * one which has the writing bit turned on. */
528 code = (*ops->close)(rock, OutStatus, doProcessFS);
535 code = (*ops->destroy)(&rock, code);
539 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
543 * \param dclist pointer to the list of dcaches
544 * \param avc Ptr to the vcache entry.
545 * \param areq Ptr to the request structure
546 * \param sync sync flag
547 * \param minj the chunk offset for this call
548 * \param high index of last dcache to store
549 * \param moredata the moredata flag
550 * \param anewDV Ptr to the dataversion after store
551 * \param amaxStoredLength Ptr to the amount of that is actually stored
553 * \note Environment: Nothing interesting.
556 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
557 struct vrequest *areq, int sync,
558 unsigned int minj, unsigned int high,
559 unsigned int moredata,
560 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
563 struct storeOps *ops;
567 struct AFSFetchStatus OutStatus;
569 afs_size_t base, bytes, length;
571 unsigned int first = 0;
574 for (bytes = 0, j = 0; !code && j <= high; j++) {
576 ObtainSharedLock(&(dcList[j]->lock), 629);
579 bytes += dcList[j]->f.chunkBytes;
580 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
581 && (dcList[j]->f.chunk - minj < high)
583 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
587 if (bytes && (j == high || !dcList[j + 1])) {
589 struct dcache **dclist = &dcList[first];
590 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
591 base = AFS_CHUNKTOBASE(first + minj);
594 * take a list of dcache structs and send them all off to the server
595 * the list must be in order, and the chunks contiguous.
596 * Note - there is no locking done by this code currently. For
597 * safety's sake, xdcache could be locked over the entire call.
598 * However, that pretty well ties up all the threads. Meantime, all
599 * the chunks _MUST_ have their refcounts bumped.
600 * The writes done before a store back will clear setuid-ness
602 * We can permit CacheStoreProc to wake up the user process IFF we
603 * are doing the last RPC for this close, ie, storing back the last
604 * set of contiguous chunks of a file.
607 nchunks = 1 + j - first;
608 nomore = !(moredata || (j != high));
609 length = lmin(avc->f.m.Length, avc->f.truncPos);
610 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
611 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
612 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
613 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
614 ICL_HANDLE_OFFSET(length));
617 tc = afs_Conn(&avc->f.fid, areq, 0);
619 #ifdef AFS_64BIT_CLIENT
622 code = rxfs_storeInit(avc, tc, base, bytes, length,
625 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
626 &doProcessFS, &OutStatus,
627 nchunks, nomore, ops, rock);
630 #ifdef AFS_64BIT_CLIENT
631 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
632 afs_serverSetNo64Bit(tc);
635 #endif /* AFS_64BIT_CLIENT */
637 (tc, code, &avc->f.fid, areq,
638 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
641 /* put back all remaining locked dcache entries */
642 for (i = 0; i < nchunks; i++) {
643 struct dcache *tdc = dclist[i];
645 if (afs_indexFlags[tdc->index] & IFDataMod) {
647 * LOCKXXX -- should hold afs_xdcache(W) when
648 * modifying afs_indexFlags.
650 afs_indexFlags[tdc->index] &= ~IFDataMod;
651 afs_stats_cmperf.cacheCurrDirtyChunks--;
652 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
653 if (sync & AFS_VMSYNC_INVAL) {
654 /* since we have invalidated all the pages of this
655 ** vnode by calling osi_VM_TryToSmush, we can
656 ** safely mark this dcache entry as not having
657 ** any pages. This vnode now becomes eligible for
658 ** reclamation by getDownD.
660 afs_indexFlags[tdc->index] &= ~IFAnyPages;
664 UpgradeSToWLock(&tdc->lock, 628);
665 tdc->f.states &= ~DWriting; /* correct? */
666 tdc->dflags |= DFEntryMod;
667 ReleaseWriteLock(&tdc->lock);
669 /* Mark the entry as released */
674 /* Now copy out return params */
675 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
676 afs_ProcessFS(avc, &OutStatus, areq);
677 /* Keep last (max) size of file on server to see if
678 * we need to call afs_StoreMini to extend the file.
681 *amaxStoredLength = OutStatus.Length;
682 ConvertWToSLock(&avc->lock);
687 for (j++; j <= high; j++) {
689 ReleaseSharedLock(&(dcList[j]->lock));
690 afs_PutDCache(dcList[j]);
691 /* Releasing entry */
697 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
698 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
706 /* rock and operations for RX_FILESERVER */
708 struct rxfs_fetchVariables {
709 struct rx_call *call;
713 afs_int32 hasNo64bit;
719 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
723 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
726 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
728 code = rx_Read(v->call, v->tbuffer, tlen);
737 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
740 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
744 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
754 rxfs_fetchMemWrite(void *r, struct osi_file *fP,
755 afs_uint32 offset, afs_uint32 tlen,
756 afs_uint32 *byteswritten)
759 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
760 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
762 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
766 *byteswritten = code;
771 rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
772 afs_uint32 offset, afs_uint32 tlen,
773 afs_uint32 *byteswritten)
776 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
778 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
782 *byteswritten = code;
788 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
789 struct afs_FetchOutput *o)
791 afs_int32 code, code1 = 0;
792 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
798 #ifdef AFS_64BIT_CLIENT
800 code = EndRXAFS_FetchData64(v->call, &o->OutStatus, &o->CallBack,
804 code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
806 code1 = rx_EndCall(v->call, code);
817 rxfs_fetchDestroy(void **r, afs_int32 error)
819 afs_int32 code = error;
820 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
825 code = rx_EndCall(v->call, error);
831 osi_FreeLargeSpace(v->tbuffer);
833 osi_FreeSmallSpace(v->iov);
834 osi_FreeSmallSpace(v);
839 rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
842 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
845 * The fetch protocol is extended for the AFS/DFS translator
846 * to allow multiple blocks of data, each with its own length,
847 * to be returned. As long as the top bit is set, there are more
850 * We do not do this for AFS file servers because they sometimes
851 * return large negative numbers as the transfer size.
855 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
857 *length = ntohl(*length);
858 if (code != sizeof(afs_int32)) {
859 code = rx_Error(v->call);
861 return (code ? code : -1); /* try to return code, not -1 */
864 *moredata = *length & 0x80000000;
865 *length &= ~0x80000000;
870 struct fetchOps rxfs_fetchUfsOps = {
879 struct fetchOps rxfs_fetchMemOps = {
888 rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
889 afs_uint32 size, afs_int32 *alength, struct dcache *adc,
890 struct osi_file *fP, struct fetchOps **ops, void **rock)
892 struct rxfs_fetchVariables *v;
893 int code = 0, code1 = 0;
894 #ifdef AFS_64BIT_CLIENT
895 afs_uint32 length_hi = 0;
897 afs_uint32 length, bytes;
899 v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
901 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
902 memset(v, 0, sizeof(struct rxfs_fetchVariables));
905 v->call = rx_NewCall(tc->id);
908 #ifdef AFS_64BIT_CLIENT
909 afs_size_t length64; /* as returned from server */
910 if (!afs_serverHasNo64Bit(tc)) {
911 afs_uint64 llbytes = size;
913 code = StartRXAFS_FetchData64(v->call, (struct AFSFid *) &avc->f.fid.Fid,
917 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
918 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
920 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
922 if (bytes == sizeof(afs_int32)) {
923 length_hi = ntohl(length_hi);
925 code = rx_Error(v->call);
927 code1 = rx_EndCall(v->call, code);
933 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
934 if (base > 0x7FFFFFFF) {
941 v->call = rx_NewCall(tc->id);
943 StartRXAFS_FetchData(
944 v->call, (struct AFSFid*)&avc->f.fid.Fid,
948 afs_serverSetNo64Bit(tc);
952 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
954 if (bytes == sizeof(afs_int32))
955 length = ntohl(length);
958 code = rx_Error(v->call);
959 code1 = rx_EndCall(v->call, code);
964 FillInt64(length64, length_hi, length);
965 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
966 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
968 ICL_HANDLE_OFFSET(length64));
970 #else /* AFS_64BIT_CLIENT */
972 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
978 rx_Read(v->call, (char *)&length, sizeof(afs_int32));
980 if (bytes == sizeof(afs_int32)) {
981 *alength = ntohl(length);
983 code = rx_Error(v->call);
984 code1 = rx_EndCall(v->call, code);
988 #endif /* AFS_64BIT_CLIENT */
992 /* We need to cast here, in order to avoid issues if *alength is
993 * negative. Some, older, fileservers can return a negative length,
994 * which the rest of the code deals correctly with. */
995 if (code == 0 && *alength > (afs_int32) size) {
996 /* The fileserver told us it is going to send more data than we
997 * requested. It shouldn't do that, and accepting that much data
998 * can make us take up more cache space than we're supposed to,
1000 code = rx_Error(v->call);
1002 code1 = rx_EndCall(v->call, code);
1012 osi_FreeSmallSpace(v);
1015 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
1016 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1018 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
1019 osi_Assert(WriteLocked(&adc->lock));
1021 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
1024 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
1025 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
1026 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
1028 * We need to alloc the iovecs on the heap so that they are "pinned"
1029 * rather than declare them on the stack - defect 11272
1031 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
1033 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
1034 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1042 * Routine called on fetch; also tells people waiting for data
1043 * that more has arrived.
1045 * \param tc Ptr to the Rx connection structure.
1046 * \param fP File descriptor for the cache file.
1047 * \param base Base offset to fetch.
1048 * \param adc Ptr to the dcache entry for the file, write-locked.
1049 * \param avc Ptr to the vcache entry for the file.
1050 * \param size Amount of data that should be fetched.
1051 * \param tsmall Ptr to the afs_FetchOutput structure.
1053 * \note Environment: Nothing interesting.
1056 afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
1057 struct dcache *adc, struct vcache *avc, afs_int32 size,
1058 struct afs_FetchOutput *tsmall)
1062 afs_uint32 bytesread, byteswritten;
1063 struct fetchOps *ops = NULL;
1065 afs_uint32 moredata = 0;
1070 osi_timeval_t xferStartTime; /*FS xfer start time */
1071 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1074 AFS_STATCNT(CacheFetchProc);
1076 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1080 * avc->lock(R) if setLocks && !slowPass
1081 * avc->lock(W) if !setLocks || slowPass
1084 code = rxfs_fetchInit(
1085 tc, avc, base, size, &length, adc, fP, &ops, &rock);
1088 osi_GetuTime(&xferStartTime);
1089 #endif /* AFS_NOSTATS */
1092 adc->validPos = base;
1096 if (avc->f.states & CForeign) {
1097 code = (*ops->more)(rock, &length, &moredata);
1102 bytesToXfer += length;
1103 #endif /* AFS_NOSTATS */
1104 while (length > 0) {
1105 #ifdef RX_KERNEL_TRACE
1106 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1109 code = (*ops->read)(rock, length, &bytesread);
1110 #ifdef RX_KERNEL_TRACE
1111 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1115 bytesXferred += bytesread;
1116 #endif /* AFS_NOSTATS */
1118 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1119 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1120 ICL_TYPE_INT32, length);
1124 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1127 offset += bytesread;
1129 length -= bytesread;
1130 adc->validPos = base;
1131 if (afs_osi_Wakeup(&adc->validPos) == 0)
1132 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1133 __FILE__, ICL_TYPE_INT32, __LINE__,
1134 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1140 code = (*ops->close)(rock, avc, adc, tsmall);
1142 (*ops->destroy)(&rock, code);
1145 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,
1146 bytesToXfer, bytesXferred);