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"
22 #endif /* AFS_ALPHA_ENV */
23 #include "afsincludes.h" /* Afs-based standard headers */
24 #include "afs/afs_stats.h" /* statistics */
25 #include "afs_prototypes.h"
27 extern int cacheDiskType;
31 FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
32 afs_size_t bytesToXfer, afs_size_t bytesXferred)
34 struct afs_stats_xferData *xferP;
35 osi_timeval_t xferStopTime;
36 osi_timeval_t elapsedTime;
38 xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[idx]);
39 osi_GetuTime(&xferStopTime);
42 (xferP->numSuccesses)++;
43 afs_stats_XferSumBytes[idx] += bytesXferred;
44 (xferP->sumBytes) += (afs_stats_XferSumBytes[idx] >> 10);
45 afs_stats_XferSumBytes[idx] &= 0x3FF;
46 if (bytesXferred < xferP->minBytes)
47 xferP->minBytes = bytesXferred;
48 if (bytesXferred > xferP->maxBytes)
49 xferP->maxBytes = bytesXferred;
52 * Tally the size of the object. Note: we tally the actual size,
53 * NOT the number of bytes that made it out over the wire.
55 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) (xferP->count[0])++;
56 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) (xferP->count[1])++;
57 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) (xferP->count[2])++;
58 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) (xferP->count[3])++;
59 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) (xferP->count[4])++;
60 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) (xferP->count[5])++;
61 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) (xferP->count[6])++;
62 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) (xferP->count[7])++;
66 afs_stats_GetDiff(elapsedTime, (*xferStartTime), xferStopTime);
67 afs_stats_AddTo((xferP->sumTime), elapsedTime);
68 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
69 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
70 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
72 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
73 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
77 #endif /* AFS_NOSTATS */
79 /* rock and operations for RX_FILESERVER */
84 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
86 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
91 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
94 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
96 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
98 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
101 code = rx_Error(v->call);
113 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
114 afs_uint32 tlen, afs_uint32 *bytesread)
117 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
120 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
126 #if defined(KERNEL_HAVE_UERROR)
134 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
135 afs_uint32 tlen, afs_uint32 *bytesread)
138 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
139 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
142 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
150 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
153 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
156 code = rx_Writev(v->call, v->tiov, v->tnio, l);
159 code = rx_Error(v->call);
160 return (code ? code : -33);
162 *byteswritten = code;
167 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
170 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
173 code = rx_Write(v->call, v->tbuffer, l);
174 /* writing 0 bytes will
175 * push a short packet. Is that really what we want, just because the
176 * data didn't come back from the disk yet? Let's try it and see. */
179 code = rx_Error(v->call);
180 return (code ? code : -33);
182 *byteswritten = code;
187 rxfs_storePadd(void *rock, afs_uint32 size)
191 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
194 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
195 memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
198 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
200 code = rx_Write(v->call, v->tbuffer, tlen);
204 return -33; /* XXX */
211 rxfs_storeStatus(void *rock)
213 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
215 if (rx_GetRemoteStatus(v->call) & 1)
221 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
224 struct AFSVolSync tsync;
225 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
230 #ifdef AFS_64BIT_CLIENT
232 code = EndRXAFS_StoreData64(v->call, OutStatus, &tsync);
235 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
238 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
244 rxfs_storeDestroy(void **r, afs_int32 error)
246 afs_int32 code = error;
247 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
252 code = rx_EndCall(v->call, error);
258 osi_FreeLargeSpace(v->tbuffer);
260 osi_FreeSmallSpace(v->tiov);
261 osi_FreeSmallSpace(v);
266 afs_GenericStoreProc(struct storeOps *ops, void *rock,
267 struct dcache *tdc, int *shouldwake,
268 afs_size_t *bytesXferred)
270 struct rxfs_storeVariables *svar = rock;
271 afs_uint32 tlen, bytesread, byteswritten;
275 struct osi_file *tfile;
277 size = tdc->f.chunkBytes;
279 tfile = afs_CFileOpen(&tdc->f.inode);
282 code = (*ops->prepare)(rock, size, &tlen);
286 code = (*ops->read)(rock, tfile, offset, tlen, &bytesread);
291 code = (*ops->write)(rock, tlen, &byteswritten);
295 *bytesXferred += byteswritten;
296 #endif /* AFS_NOSTATS */
301 * if file has been locked on server, can allow
304 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
305 *shouldwake = 0; /* only do this once */
306 afs_wakeup(svar->vcache);
309 afs_CFileClose(tfile);
315 struct storeOps rxfs_storeUfsOps = {
316 #ifndef HAVE_STRUCT_LABEL_SUPPORT
317 rxfs_storeUfsPrepare,
326 .prepare = rxfs_storeUfsPrepare,
327 .read = rxfs_storeUfsRead,
328 .write = rxfs_storeUfsWrite,
329 .status = rxfs_storeStatus,
330 .padd = rxfs_storePadd,
331 .close = rxfs_storeClose,
332 .destroy = rxfs_storeDestroy,
333 #ifdef AFS_LINUX26_ENV
334 .storeproc = afs_linux_storeproc
336 .storeproc = afs_GenericStoreProc
342 struct storeOps rxfs_storeMemOps = {
343 #ifndef HAVE_STRUCT_LABEL_SUPPORT
344 rxfs_storeMemPrepare,
353 .prepare = rxfs_storeMemPrepare,
354 .read = rxfs_storeMemRead,
355 .write = rxfs_storeMemWrite,
356 .status = rxfs_storeStatus,
357 .padd = rxfs_storePadd,
358 .close = rxfs_storeClose,
359 .destroy = rxfs_storeDestroy,
360 .storeproc = afs_GenericStoreProc
365 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
366 afs_size_t bytes, afs_size_t length,
367 int sync, struct storeOps **ops, void **rock)
370 struct rxfs_storeVariables *v;
375 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
377 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
378 memset(v, 0, sizeof(struct rxfs_storeVariables));
380 v->InStatus.ClientModTime = avc->f.m.Date;
381 v->InStatus.Mask = AFS_SETMODTIME;
384 v->InStatus.Mask |= AFS_FSYNC;
386 v->call = rx_NewCall(tc->id);
388 #ifdef AFS_64BIT_CLIENT
389 if (!afs_serverHasNo64Bit(tc))
390 code = StartRXAFS_StoreData64(
391 v->call, (struct AFSFid*)&avc->f.fid.Fid,
392 &v->InStatus, base, bytes, length);
394 if (length > 0xFFFFFFFF)
397 afs_int32 t1 = base, t2 = bytes, t3 = length;
398 code = StartRXAFS_StoreData(v->call,
399 (struct AFSFid *) &avc->f.fid.Fid,
400 &v->InStatus, t1, t2, t3);
402 #else /* AFS_64BIT_CLIENT */
403 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
404 &v->InStatus, base, bytes, length);
405 #endif /* AFS_64BIT_CLIENT */
410 osi_FreeSmallSpace(v);
413 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
414 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
417 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
418 *ops = (struct storeOps *) &rxfs_storeUfsOps;
420 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
423 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
424 *ops = (struct storeOps *) &rxfs_storeMemOps;
426 /* do this at a higher level now -- it's a parameter */
427 /* for now, only do 'continue from close' code if file fits in one
428 * chunk. Could clearly do better: if only one modified chunk
429 * then can still do this. can do this on *last* modified chunk */
430 length = avc->f.m.Length - 1; /* byte position of last byte we'll store */
432 if (AFS_CHUNK(length) != 0)
443 unsigned int storeallmissing = 0;
445 * Called for each chunk upon store.
447 * \param avc Ptr to the vcache entry of the file being stored.
448 * \param dclist pointer to the list of dcaches
449 * \param bytes total number of bytes for the current operation
450 * \param anewDV Ptr to the dataversion after store
451 * \param doProcessFS pointer to the "do process FetchStatus" flag
452 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
453 * \param nchunks number of dcaches to consider
454 * \param nomore copy of the "no more data" flag
455 * \param ops pointer to the block of storeOps to be used for this operation
456 * \param rock pointer to the opaque protocol-specific data of this operation
459 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
460 afs_size_t bytes, afs_hyper_t *anewDV, int *doProcessFS,
461 struct AFSFetchStatus *OutStatus, afs_uint32 nchunks,
462 int nomore, struct storeOps *ops, void *rock)
464 int *shouldwake = NULL;
467 afs_size_t bytesXferred;
470 osi_timeval_t xferStartTime; /*FS xfer start time */
471 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
472 #endif /* AFS_NOSTATS */
475 for (i = 0; i < nchunks && !code; i++) {
477 struct dcache *tdc = dclist[i];
478 afs_int32 size = tdc->f.chunkBytes;
480 afs_warn("afs: missing dcache!\n");
482 continue; /* panic? */
484 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
485 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
486 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
489 if (avc->asynchrony == -1) {
490 if (afs_defaultAsynchrony > (bytes - stored))
491 shouldwake = &nomore;
493 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
494 shouldwake = &nomore;
497 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
498 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
499 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
501 AFS_STATCNT(CacheStoreProc);
503 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
504 avc->f.truncPos = AFS_NOTRUNC;
507 * In this case, size is *always* the amount of data we'll be trying
512 osi_GetuTime(&xferStartTime);
513 #endif /* AFS_NOSTATS */
516 code = (*ops->storeproc)(ops, rock, tdc, shouldwake,
519 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
520 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
521 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
524 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
525 &xferStartTime, bytesToXfer, bytesXferred);
526 #endif /* AFS_NOSTATS */
528 if ((tdc->f.chunkBytes < afs_OtherCSize)
529 && (i < (nchunks - 1)) && code == 0) {
530 code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
532 stored += tdc->f.chunkBytes;
533 /* ideally, I'd like to unlock the dcache and turn
534 * off the writing bit here, but that would
535 * require being able to retry StoreAllSegments in
536 * the event of a failure. It only really matters
537 * if user can't read from a 'locked' dcache or
538 * one which has the writing bit turned on. */
542 code = (*ops->close)(rock, OutStatus, doProcessFS);
549 code = (*ops->destroy)(&rock, code);
553 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
557 * \param dclist pointer to the list of dcaches
558 * \param avc Ptr to the vcache entry.
559 * \param areq Ptr to the request structure
560 * \param sync sync flag
561 * \param minj the chunk offset for this call
562 * \param high index of last dcache to store
563 * \param moredata the moredata flag
564 * \param anewDV Ptr to the dataversion after store
565 * \param amaxStoredLength Ptr to the amount of that is actually stored
567 * \note Environment: Nothing interesting.
570 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
571 struct vrequest *areq, int sync, unsigned int minj,
572 unsigned int high, unsigned int moredata,
573 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
576 struct storeOps *ops;
580 struct AFSFetchStatus OutStatus;
582 afs_size_t base, bytes, length;
584 unsigned int first = 0;
587 for (bytes = 0, j = 0; !code && j <= high; j++) {
589 ObtainSharedLock(&(dcList[j]->lock), 629);
592 bytes += dcList[j]->f.chunkBytes;
593 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
594 && (dcList[j]->f.chunk - minj < high)
596 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
600 if (bytes && (j == high || !dcList[j + 1])) {
602 struct dcache **dclist = &dcList[first];
603 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
604 base = AFS_CHUNKTOBASE(first + minj);
607 * take a list of dcache structs and send them all off to the server
608 * the list must be in order, and the chunks contiguous.
609 * Note - there is no locking done by this code currently. For
610 * safety's sake, xdcache could be locked over the entire call.
611 * However, that pretty well ties up all the threads. Meantime, all
612 * the chunks _MUST_ have their refcounts bumped.
613 * The writes done before a store back will clear setuid-ness
615 * We can permit CacheStoreProc to wake up the user process IFF we
616 * are doing the last RPC for this close, ie, storing back the last
617 * set of contiguous chunks of a file.
620 nchunks = 1 + j - first;
621 nomore = !(moredata || (j != high));
622 length = lmin(avc->f.m.Length, avc->f.truncPos);
623 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
624 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
625 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
626 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
627 ICL_HANDLE_OFFSET(length));
630 tc = afs_Conn(&avc->f.fid, areq, 0);
632 #ifdef AFS_64BIT_CLIENT
635 code = rxfs_storeInit(avc, tc, base, bytes, length,
638 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
639 &doProcessFS, &OutStatus,
640 nchunks, nomore, ops, rock);
643 #ifdef AFS_64BIT_CLIENT
644 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
645 afs_serverSetNo64Bit(tc);
648 #endif /* AFS_64BIT_CLIENT */
650 (tc, code, &avc->f.fid, areq,
651 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
654 /* put back all remaining locked dcache entries */
655 for (i = 0; i < nchunks; i++) {
656 struct dcache *tdc = dclist[i];
658 if (afs_indexFlags[tdc->index] & IFDataMod) {
660 * LOCKXXX -- should hold afs_xdcache(W) when
661 * modifying afs_indexFlags.
663 afs_indexFlags[tdc->index] &= ~IFDataMod;
664 afs_stats_cmperf.cacheCurrDirtyChunks--;
665 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
666 if (sync & AFS_VMSYNC_INVAL) {
667 /* since we have invalidated all the pages of this
668 ** vnode by calling osi_VM_TryToSmush, we can
669 ** safely mark this dcache entry as not having
670 ** any pages. This vnode now becomes eligible for
671 ** reclamation by getDownD.
673 afs_indexFlags[tdc->index] &= ~IFAnyPages;
677 UpgradeSToWLock(&tdc->lock, 628);
678 tdc->f.states &= ~DWriting; /* correct? */
679 tdc->dflags |= DFEntryMod;
680 ReleaseWriteLock(&tdc->lock);
682 /* Mark the entry as released */
687 /* Now copy out return params */
688 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
689 afs_ProcessFS(avc, &OutStatus, areq);
690 /* Keep last (max) size of file on server to see if
691 * we need to call afs_StoreMini to extend the file.
694 *amaxStoredLength = OutStatus.Length;
695 ConvertWToSLock(&avc->lock);
700 for (j++; j <= high; j++) {
702 ReleaseSharedLock(&(dcList[j]->lock));
703 afs_PutDCache(dcList[j]);
704 /* Releasing entry */
710 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
711 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
719 /* rock and operations for RX_FILESERVER */
721 struct rxfs_fetchVariables {
722 struct rx_call *call;
726 afs_int32 hasNo64bit;
732 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
736 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
739 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
741 code = rx_Read(v->call, v->tbuffer, tlen);
750 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
753 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
757 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
767 rxfs_fetchMemWrite(void *r, struct osi_file *fP, afs_uint32 offset,
768 afs_uint32 tlen, afs_uint32 *byteswritten)
771 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
772 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
774 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
778 *byteswritten = code;
783 rxfs_fetchUfsWrite(void *r, struct osi_file *fP, afs_uint32 offset,
784 afs_uint32 tlen, afs_uint32 *byteswritten)
787 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
789 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
793 *byteswritten = code;
799 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
800 struct afs_FetchOutput *o)
802 afs_int32 code, code1 = 0;
803 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
809 #ifdef AFS_64BIT_CLIENT
811 code = EndRXAFS_FetchData64(v->call, &o->OutStatus, &o->CallBack,
815 code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
817 code1 = rx_EndCall(v->call, code);
828 rxfs_fetchDestroy(void **r, afs_int32 error)
830 afs_int32 code = error;
831 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
836 code = rx_EndCall(v->call, error);
842 osi_FreeLargeSpace(v->tbuffer);
844 osi_FreeSmallSpace(v->iov);
845 osi_FreeSmallSpace(v);
850 rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
853 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
856 * The fetch protocol is extended for the AFS/DFS translator
857 * to allow multiple blocks of data, each with its own length,
858 * to be returned. As long as the top bit is set, there are more
861 * We do not do this for AFS file servers because they sometimes
862 * return large negative numbers as the transfer size.
866 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
868 *length = ntohl(*length);
869 if (code != sizeof(afs_int32)) {
870 code = rx_Error(v->call);
872 return (code ? code : -1); /* try to return code, not -1 */
875 *moredata = *length & 0x80000000;
876 *length &= ~0x80000000;
881 struct fetchOps rxfs_fetchUfsOps = {
890 struct fetchOps rxfs_fetchMemOps = {
899 rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
900 afs_uint32 size, afs_int32 *alength, struct dcache *adc,
901 struct osi_file *fP, struct fetchOps **ops, void **rock)
903 struct rxfs_fetchVariables *v;
904 int code = 0, code1 = 0;
905 #ifdef AFS_64BIT_CLIENT
906 afs_uint32 length_hi = 0;
908 afs_uint32 length, bytes;
910 v = (struct rxfs_fetchVariables *)
911 osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
913 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
914 memset(v, 0, sizeof(struct rxfs_fetchVariables));
917 v->call = rx_NewCall(tc->id);
920 #ifdef AFS_64BIT_CLIENT
921 afs_size_t length64; /* as returned from server */
922 if (!afs_serverHasNo64Bit(tc)) {
923 afs_uint64 llbytes = size;
925 code = StartRXAFS_FetchData64(v->call,
926 (struct AFSFid *) &avc->f.fid.Fid,
930 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
931 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
933 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
935 if (bytes == sizeof(afs_int32)) {
936 length_hi = ntohl(length_hi);
938 code = rx_Error(v->call);
940 code1 = rx_EndCall(v->call, code);
946 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
947 if (base > 0x7FFFFFFF) {
954 v->call = rx_NewCall(tc->id);
956 StartRXAFS_FetchData(
957 v->call, (struct AFSFid*)&avc->f.fid.Fid,
961 afs_serverSetNo64Bit(tc);
965 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
967 if (bytes == sizeof(afs_int32))
968 length = ntohl(length);
971 code = rx_Error(v->call);
972 code1 = rx_EndCall(v->call, code);
977 FillInt64(length64, length_hi, length);
978 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
979 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
981 ICL_HANDLE_OFFSET(length64));
983 #else /* AFS_64BIT_CLIENT */
985 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
991 rx_Read(v->call, (char *)&length, sizeof(afs_int32));
993 if (bytes == sizeof(afs_int32)) {
994 *alength = ntohl(length);
996 code = rx_Error(v->call);
997 code1 = rx_EndCall(v->call, code);
1001 #endif /* AFS_64BIT_CLIENT */
1005 /* We need to cast here, in order to avoid issues if *alength is
1006 * negative. Some, older, fileservers can return a negative length,
1007 * which the rest of the code deals correctly with. */
1008 if (code == 0 && *alength > (afs_int32) size) {
1009 /* The fileserver told us it is going to send more data than we
1010 * requested. It shouldn't do that, and accepting that much data
1011 * can make us take up more cache space than we're supposed to,
1013 code = rx_Error(v->call);
1015 code1 = rx_EndCall(v->call, code);
1025 osi_FreeSmallSpace(v);
1028 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
1029 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1031 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
1032 osi_Assert(WriteLocked(&adc->lock));
1034 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
1037 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
1038 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
1039 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
1041 * We need to alloc the iovecs on the heap so that they are "pinned"
1042 * rather than declare them on the stack - defect 11272
1044 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
1046 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
1047 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1055 * Routine called on fetch; also tells people waiting for data
1056 * that more has arrived.
1058 * \param tc Ptr to the Rx connection structure.
1059 * \param fP File descriptor for the cache file.
1060 * \param base Base offset to fetch.
1061 * \param adc Ptr to the dcache entry for the file, write-locked.
1062 * \param avc Ptr to the vcache entry for the file.
1063 * \param size Amount of data that should be fetched.
1064 * \param tsmall Ptr to the afs_FetchOutput structure.
1066 * \note Environment: Nothing interesting.
1069 afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
1070 struct dcache *adc, struct vcache *avc, afs_int32 size,
1071 struct afs_FetchOutput *tsmall)
1075 afs_uint32 bytesread, byteswritten;
1076 struct fetchOps *ops = NULL;
1078 afs_uint32 moredata = 0;
1083 osi_timeval_t xferStartTime; /*FS xfer start time */
1084 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1087 AFS_STATCNT(CacheFetchProc);
1089 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1093 * avc->lock(R) if setLocks && !slowPass
1094 * avc->lock(W) if !setLocks || slowPass
1097 code = rxfs_fetchInit(
1098 tc, avc, base, size, &length, adc, fP, &ops, &rock);
1101 osi_GetuTime(&xferStartTime);
1102 #endif /* AFS_NOSTATS */
1105 adc->validPos = base;
1109 if (avc->f.states & CForeign) {
1110 code = (*ops->more)(rock, &length, &moredata);
1115 bytesToXfer += length;
1116 #endif /* AFS_NOSTATS */
1117 while (length > 0) {
1118 #ifdef RX_KERNEL_TRACE
1119 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1122 code = (*ops->read)(rock, length, &bytesread);
1123 #ifdef RX_KERNEL_TRACE
1124 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1128 bytesXferred += bytesread;
1129 #endif /* AFS_NOSTATS */
1131 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1132 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1133 ICL_TYPE_INT32, length);
1137 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1140 offset += bytesread;
1142 length -= bytesread;
1143 adc->validPos = base;
1144 if (afs_osi_Wakeup(&adc->validPos) == 0)
1145 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1146 __FILE__, ICL_TYPE_INT32, __LINE__,
1147 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1153 code = (*ops->close)(rock, avc, adc, tsmall);
1155 (*ops->destroy)(&rock, code);
1158 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,
1159 bytesToXfer, bytesXferred);