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 */
19 #endif /* AFS_ALPHA_ENV */
20 #include "afsincludes.h" /* Afs-based standard headers */
21 #include "afs/afs_stats.h" /* statistics */
22 #include "afs_prototypes.h"
24 extern int cacheDiskType;
28 FillStoreStats(int code, int idx, osi_timeval32_t xferStartTime,
29 afs_size_t bytesToXfer, afs_size_t bytesXferred)
31 struct afs_stats_xferData *xferP;
32 osi_timeval32_t xferStopTime;
33 osi_timeval32_t elapsedTime;
35 xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[idx]);
36 osi_GetTime(&xferStopTime);
39 (xferP->numSuccesses)++;
40 afs_stats_XferSumBytes[idx] += bytesXferred;
41 (xferP->sumBytes) += (afs_stats_XferSumBytes[idx] >> 10);
42 afs_stats_XferSumBytes[idx] &= 0x3FF;
43 if (bytesXferred < xferP->minBytes)
44 xferP->minBytes = bytesXferred;
45 if (bytesXferred > xferP->maxBytes)
46 xferP->maxBytes = bytesXferred;
49 * Tally the size of the object. Note: we tally the actual size,
50 * NOT the number of bytes that made it out over the wire.
52 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) (xferP->count[0])++;
53 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) (xferP->count[1])++;
54 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) (xferP->count[2])++;
55 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) (xferP->count[3])++;
56 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) (xferP->count[4])++;
57 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) (xferP->count[5])++;
58 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) (xferP->count[6])++;
59 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) (xferP->count[7])++;
63 afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
64 afs_stats_AddTo((xferP->sumTime), elapsedTime);
65 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
66 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
67 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
69 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
70 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
74 #endif /* AFS_NOSTATS */
76 /* rock and operations for RX_FILESERVER */
81 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
83 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
88 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
91 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
94 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, size);
97 code = rx_Error(v->call);
109 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
110 afs_uint32 tlen, afs_uint32 *bytesread)
113 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
116 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
122 #if defined(KERNEL_HAVE_UERROR)
130 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
131 afs_uint32 tlen, afs_uint32 *bytesread)
134 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
135 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
138 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
146 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
149 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
152 code = rx_Writev(v->call, v->tiov, v->tnio, l);
155 code = rx_Error(v->call);
156 return (code ? code : -33);
158 *byteswritten = code;
163 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
166 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
169 code = rx_Write(v->call, v->tbuffer, l);
170 /* writing 0 bytes will
171 * push a short packet. Is that really what we want, just because the
172 * data didn't come back from the disk yet? Let's try it and see. */
175 code = rx_Error(v->call);
176 return (code ? code : -33);
178 *byteswritten = code;
183 rxfs_storePadd(void *rock, afs_uint32 size)
187 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
190 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
191 memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
194 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
196 code = rx_Write(v->call, v->tbuffer, tlen);
200 return -33; /* XXX */
207 rxfs_storeStatus(void *rock)
209 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
211 if (rx_GetRemoteStatus(v->call) & 1)
217 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
220 struct AFSVolSync tsync;
221 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
226 #ifdef AFS_64BIT_CLIENT
228 code = EndRXAFS_StoreData64(v->call, OutStatus, &tsync);
231 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
234 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
240 rxfs_storeDestroy(void **r, afs_int32 code)
242 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
247 code = rx_EndCall(v->call, code);
251 osi_FreeLargeSpace(v->tbuffer);
253 osi_FreeSmallSpace(v->tiov);
254 osi_FreeSmallSpace(v);
259 afs_GenericStoreProc(struct storeOps *ops, void *rock,
260 struct dcache *tdc, int *shouldwake,
261 afs_size_t *bytesXferred)
263 struct rxfs_storeVariables *svar = rock;
264 afs_uint32 tlen, bytesread, byteswritten;
268 struct osi_file *tfile;
270 size = tdc->f.chunkBytes;
272 tfile = afs_CFileOpen(&tdc->f.inode);
276 code = (*ops->prepare)(rock, size, &tlen);
280 code = (*ops->read)(rock, tfile, offset, tlen, &bytesread);
285 code = (*ops->write)(rock, tlen, &byteswritten);
289 *bytesXferred += byteswritten;
290 #endif /* AFS_NOSTATS */
295 * if file has been locked on server, can allow
298 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
299 *shouldwake = 0; /* only do this once */
300 afs_wakeup(svar->vcache);
303 afs_CFileClose(tfile);
309 struct storeOps rxfs_storeUfsOps = {
310 #ifndef HAVE_STRUCT_LABEL_SUPPORT
311 rxfs_storeUfsPrepare,
320 .prepare = rxfs_storeUfsPrepare,
321 .read = rxfs_storeUfsRead,
322 .write = rxfs_storeUfsWrite,
323 .status = rxfs_storeStatus,
324 .padd = rxfs_storePadd,
325 .close = rxfs_storeClose,
326 .destroy = rxfs_storeDestroy,
327 .storeproc = afs_GenericStoreProc
332 struct storeOps rxfs_storeMemOps = {
333 #ifndef HAVE_STRUCT_LABEL_SUPPORT
334 rxfs_storeMemPrepare,
343 .prepare = rxfs_storeMemPrepare,
344 .read = rxfs_storeMemRead,
345 .write = rxfs_storeMemWrite,
346 .status = rxfs_storeStatus,
347 .padd = rxfs_storePadd,
348 .close = rxfs_storeClose,
349 .destroy = rxfs_storeDestroy,
350 .storeproc = afs_GenericStoreProc
355 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc,
356 struct rx_connection *rxconn, afs_size_t base,
357 afs_size_t bytes, afs_size_t length,
358 int sync, struct storeOps **ops, void **rock)
361 struct rxfs_storeVariables *v;
366 v = osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
368 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
369 memset(v, 0, sizeof(struct rxfs_storeVariables));
371 v->InStatus.ClientModTime = avc->f.m.Date;
372 v->InStatus.Mask = AFS_SETMODTIME;
375 v->InStatus.Mask |= AFS_FSYNC;
377 v->call = rx_NewCall(rxconn);
379 #ifdef AFS_64BIT_CLIENT
380 if (!afs_serverHasNo64Bit(tc))
381 code = StartRXAFS_StoreData64(
382 v->call, (struct AFSFid*)&avc->f.fid.Fid,
383 &v->InStatus, base, bytes, length);
385 if (length > 0xFFFFFFFF)
388 afs_int32 t1 = base, t2 = bytes, t3 = length;
389 code = StartRXAFS_StoreData(v->call,
390 (struct AFSFid *) &avc->f.fid.Fid,
391 &v->InStatus, t1, t2, t3);
395 #else /* AFS_64BIT_CLIENT */
396 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
397 &v->InStatus, base, bytes, length);
398 #endif /* AFS_64BIT_CLIENT */
404 return rxfs_storeDestroy(rock, code);
406 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
407 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
410 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
411 *ops = (struct storeOps *) &rxfs_storeUfsOps;
413 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
416 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
417 *ops = (struct storeOps *) &rxfs_storeMemOps;
423 unsigned int storeallmissing = 0;
425 * Called for each chunk upon store.
427 * \param avc Ptr to the vcache entry of the file being stored.
428 * \param dclist pointer to the list of dcaches
429 * \param bytes total number of bytes for the current operation
430 * \param anewDV Ptr to the dataversion after store
431 * \param doProcessFS pointer to the "do process FetchStatus" flag
432 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
433 * \param nchunks number of dcaches to consider
434 * \param nomore copy of the "no more data" flag
435 * \param ops pointer to the block of storeOps to be used for this operation
436 * \param rock pointer to the opaque protocol-specific data of this operation
439 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
440 afs_size_t bytes, afs_hyper_t *anewDV, int *doProcessFS,
441 struct AFSFetchStatus *OutStatus, afs_uint32 nchunks,
442 int nomore, struct storeOps *ops, void *rock)
444 int *shouldwake = NULL;
448 afs_size_t bytesXferred;
451 osi_timeval32_t xferStartTime; /*FS xfer start time */
452 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
453 #endif /* AFS_NOSTATS */
455 osi_Assert(nchunks != 0);
457 for (i = 0; i < nchunks && !code; i++) {
458 struct dcache *tdc = dclist[i];
462 afs_warn("afs: missing dcache!\n");
464 continue; /* panic? */
466 size = tdc->f.chunkBytes;
467 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
468 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
469 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
472 if (avc->asynchrony == -1) {
473 if (afs_defaultAsynchrony > (bytes - stored))
474 shouldwake = &nomore;
476 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
477 shouldwake = &nomore;
480 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
481 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
482 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
484 AFS_STATCNT(CacheStoreProc);
486 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
487 avc->f.truncPos = AFS_NOTRUNC;
490 * In this case, size is *always* the amount of data we'll be trying
495 osi_GetTime(&xferStartTime);
496 #endif /* AFS_NOSTATS */
499 code = (*ops->storeproc)(ops, rock, tdc, shouldwake,
502 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
503 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
504 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
507 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
508 xferStartTime, bytesToXfer, bytesXferred);
509 #endif /* AFS_NOSTATS */
511 if ((tdc->f.chunkBytes < afs_OtherCSize)
512 && (i < (nchunks - 1)) && code == 0) {
513 code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
515 stored += tdc->f.chunkBytes;
516 /* ideally, I'd like to unlock the dcache and turn
517 * off the writing bit here, but that would
518 * require being able to retry StoreAllSegments in
519 * the event of a failure. It only really matters
520 * if user can't read from a 'locked' dcache or
521 * one which has the writing bit turned on. */
525 code = (*ops->close)(rock, OutStatus, doProcessFS);
526 /* if this succeeds, dv has been bumped. */
533 code = (*ops->destroy)(&rock, code);
535 /* if we errored, can't trust this. */
542 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
546 * \param dclist pointer to the list of dcaches
547 * \param avc Ptr to the vcache entry.
548 * \param areq Ptr to the request structure
549 * \param sync sync flag
550 * \param minj the chunk offset for this call
551 * \param high index of last dcache to store
552 * \param moredata the moredata flag
553 * \param anewDV Ptr to the dataversion after store
554 * \param amaxStoredLength Ptr to the amount of that is actually stored
556 * \note Environment: Nothing interesting.
559 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
560 struct vrequest *areq, int sync, unsigned int minj,
561 unsigned int high, unsigned int moredata,
562 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
565 struct storeOps *ops;
569 struct AFSFetchStatus OutStatus;
571 afs_size_t base, bytes, length;
573 unsigned int first = 0;
575 struct rx_connection *rxconn;
577 for (bytes = 0, j = 0; !code && j <= high; j++) {
579 ObtainSharedLock(&(dcList[j]->lock), 629);
582 bytes += dcList[j]->f.chunkBytes;
583 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
584 && (dcList[j]->f.chunk - minj < high)
586 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
590 if (bytes && (j == high || !dcList[j + 1])) {
592 struct dcache **dclist = &dcList[first];
593 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
594 base = AFS_CHUNKTOBASE(first + minj);
597 * take a list of dcache structs and send them all off to the server
598 * the list must be in order, and the chunks contiguous.
599 * Note - there is no locking done by this code currently. For
600 * safety's sake, xdcache could be locked over the entire call.
601 * However, that pretty well ties up all the threads. Meantime, all
602 * the chunks _MUST_ have their refcounts bumped.
603 * The writes done before a store back will clear setuid-ness
605 * We can permit CacheStoreProc to wake up the user process IFF we
606 * are doing the last RPC for this close, ie, storing back the last
607 * set of contiguous chunks of a file.
610 nchunks = 1 + j - first;
611 nomore = !(moredata || (j != high));
612 length = lmin(avc->f.m.Length, avc->f.truncPos);
613 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
614 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
615 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
616 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
617 ICL_HANDLE_OFFSET(length));
620 tc = afs_Conn(&avc->f.fid, areq, 0, &rxconn);
622 #ifdef AFS_64BIT_CLIENT
625 code = rxfs_storeInit(avc, tc, rxconn, base, bytes, length,
628 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
629 &doProcessFS, &OutStatus,
630 nchunks, nomore, ops, rock);
633 #ifdef AFS_64BIT_CLIENT
634 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
635 afs_serverSetNo64Bit(tc);
638 #endif /* AFS_64BIT_CLIENT */
640 (tc, rxconn, code, &avc->f.fid, areq,
641 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
644 /* put back all remaining locked dcache entries */
645 for (i = 0; i < nchunks; i++) {
646 struct dcache *tdc = dclist[i];
648 if (afs_indexFlags[tdc->index] & IFDataMod) {
650 * LOCKXXX -- should hold afs_xdcache(W) when
651 * modifying afs_indexFlags.
653 afs_indexFlags[tdc->index] &= ~IFDataMod;
654 afs_stats_cmperf.cacheCurrDirtyChunks--;
655 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
656 if (sync & AFS_VMSYNC_INVAL) {
657 /* since we have invalidated all the pages of this
658 ** vnode by calling osi_VM_TryToSmush, we can
659 ** safely mark this dcache entry as not having
660 ** any pages. This vnode now becomes eligible for
661 ** reclamation by getDownD.
663 afs_indexFlags[tdc->index] &= ~IFAnyPages;
667 UpgradeSToWLock(&tdc->lock, 628);
668 tdc->f.states &= ~DWriting; /* correct? */
669 tdc->dflags |= DFEntryMod;
670 ReleaseWriteLock(&tdc->lock);
672 /* Mark the entry as released */
677 /* Now copy out return params */
678 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
679 afs_ProcessFS(avc, &OutStatus, areq);
680 /* Keep last (max) size of file on server to see if
681 * we need to call afs_StoreMini to extend the file.
684 *amaxStoredLength = OutStatus.Length;
685 ConvertWToSLock(&avc->lock);
690 for (j++; j <= high; j++) {
692 ReleaseSharedLock(&(dcList[j]->lock));
693 afs_PutDCache(dcList[j]);
694 /* Releasing entry */
700 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
701 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
709 /* rock and operations for RX_FILESERVER */
711 struct rxfs_fetchVariables {
712 struct rx_call *call;
716 afs_int32 hasNo64bit;
722 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
726 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
729 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
731 code = rx_Read(v->call, v->tbuffer, tlen);
740 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
743 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
747 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
757 rxfs_fetchMemWrite(void *r, struct osi_file *fP, afs_uint32 offset,
758 afs_uint32 tlen, afs_uint32 *byteswritten)
761 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
762 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
764 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
768 *byteswritten = code;
773 rxfs_fetchUfsWrite(void *r, struct osi_file *fP, afs_uint32 offset,
774 afs_uint32 tlen, afs_uint32 *byteswritten)
777 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
779 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
783 *byteswritten = code;
789 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
790 struct afs_FetchOutput *o)
793 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
799 #ifdef AFS_64BIT_CLIENT
801 code = EndRXAFS_FetchData64(v->call, &o->OutStatus, &o->CallBack,
805 code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
807 code = rx_EndCall(v->call, code);
816 rxfs_fetchDestroy(void **r, afs_int32 code)
818 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
823 code = rx_EndCall(v->call, code);
827 osi_FreeLargeSpace(v->tbuffer);
829 osi_FreeSmallSpace(v->iov);
830 osi_FreeSmallSpace(v);
835 rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
838 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
841 * The fetch protocol is extended for the AFS/DFS translator
842 * to allow multiple blocks of data, each with its own length,
843 * to be returned. As long as the top bit is set, there are more
846 * We do not do this for AFS file servers because they sometimes
847 * return large negative numbers as the transfer size.
851 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
853 *length = ntohl(*length);
854 if (code != sizeof(afs_int32)) {
855 code = rx_Error(v->call);
857 return (code ? code : -1); /* try to return code, not -1 */
860 *moredata = *length & 0x80000000;
861 *length &= ~0x80000000;
866 struct fetchOps rxfs_fetchUfsOps = {
875 struct fetchOps rxfs_fetchMemOps = {
884 rxfs_fetchInit(struct afs_conn *tc, struct rx_connection *rxconn,
885 struct vcache *avc, afs_offs_t base,
886 afs_uint32 size, afs_int32 *alength, struct dcache *adc,
887 struct osi_file *fP, struct fetchOps **ops, void **rock)
889 struct rxfs_fetchVariables *v;
891 #ifdef AFS_64BIT_CLIENT
892 afs_uint32 length_hi = 0;
894 afs_uint32 length = 0, bytes;
896 v = (struct rxfs_fetchVariables *)
897 osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
899 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
900 memset(v, 0, sizeof(struct rxfs_fetchVariables));
903 v->call = rx_NewCall(rxconn);
906 #ifdef AFS_64BIT_CLIENT
907 afs_size_t length64; /* as returned from server */
908 if (!afs_serverHasNo64Bit(tc)) {
909 afs_uint64 llbytes = size;
911 code = StartRXAFS_FetchData64(v->call,
912 (struct AFSFid *) &avc->f.fid.Fid,
916 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
917 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
919 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
921 if (bytes == sizeof(afs_int32)) {
922 length_hi = ntohl(length_hi);
925 code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
931 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
932 if (base > 0x7FFFFFFF) {
939 v->call = rx_NewCall(rxconn);
941 StartRXAFS_FetchData(
942 v->call, (struct AFSFid*)&avc->f.fid.Fid,
946 afs_serverSetNo64Bit(tc);
951 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
953 if (bytes == sizeof(afs_int32))
954 length = ntohl(length);
957 code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
963 FillInt64(length64, length_hi, length);
966 /* Check if the fileserver said our length is bigger than can fit
967 * in a signed 32-bit integer. If it is, we can't handle that, so
969 if (length64 > MAX_AFS_INT32) {
973 afs_warn("afs: Warning: FetchData64 returned too much data "
974 "(length64 %u.%u); this should not happen! "
975 "Aborting fetch request.\n",
979 code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
983 code = code != 0 ? code : EIO;
988 /* Check if the fileserver said our length was negative. If it
989 * is, just treat it as a 0 length, since some older fileservers
990 * returned negative numbers when they meant to return 0. Note
991 * that we must do this in this 64-bit-specific block, since
992 * length64 being negative will screw up our conversion to the
993 * 32-bit 'alength' below. */
995 length_hi = length = 0;
996 FillInt64(length64, 0, 0);
1000 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
1001 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1003 ICL_HANDLE_OFFSET(length64));
1006 #else /* AFS_64BIT_CLIENT */
1008 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
1014 rx_Read(v->call, (char *)&length, sizeof(afs_int32));
1016 if (bytes == sizeof(afs_int32)) {
1017 *alength = ntohl(length);
1019 /* Older fileservers can return a negative length when they
1020 * meant to return 0; just assume negative lengths were
1021 * meant to be 0 lengths. */
1025 code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
1029 #endif /* AFS_64BIT_CLIENT */
1033 /* We need to cast here, in order to avoid issues if *alength is
1034 * negative. Some, older, fileservers can return a negative length,
1035 * which the rest of the code deals correctly with. */
1036 if (code == 0 && *alength > (afs_int32) size) {
1037 /* The fileserver told us it is going to send more data than we
1038 * requested. It shouldn't do that, and accepting that much data
1039 * can make us take up more cache space than we're supposed to,
1044 afs_warn("afs: Warning: FetchData64 returned more data than "
1045 "requested (requested %ld, got %ld); this should not "
1046 "happen! Aborting fetch request.\n",
1047 (long)size, (long)*alength);
1050 code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
1058 return rxfs_fetchDestroy(rock, code);
1060 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
1061 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1063 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
1064 osi_Assert(WriteLocked(&adc->lock));
1066 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
1069 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
1070 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
1071 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
1073 * We need to alloc the iovecs on the heap so that they are "pinned"
1074 * rather than declare them on the stack - defect 11272
1076 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
1078 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
1079 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1087 * Routine called on fetch; also tells people waiting for data
1088 * that more has arrived.
1090 * \param tc Ptr to the AFS connection structure.
1091 * \param rxconn Ptr to the Rx connection structure.
1092 * \param fP File descriptor for the cache file.
1093 * \param base Base offset to fetch.
1094 * \param adc Ptr to the dcache entry for the file, write-locked.
1095 * \param avc Ptr to the vcache entry for the file.
1096 * \param size Amount of data that should be fetched.
1097 * \param tsmall Ptr to the afs_FetchOutput structure.
1099 * \note Environment: Nothing interesting.
1102 afs_CacheFetchProc(struct afs_conn *tc, struct rx_connection *rxconn,
1103 struct osi_file *fP, afs_size_t base,
1104 struct dcache *adc, struct vcache *avc, afs_int32 size,
1105 struct afs_FetchOutput *tsmall)
1109 afs_uint32 bytesread, byteswritten;
1110 struct fetchOps *ops = NULL;
1112 afs_uint32 moredata = 0;
1117 osi_timeval32_t xferStartTime; /*FS xfer start time */
1118 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1121 AFS_STATCNT(CacheFetchProc);
1123 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1127 * avc->lock(R) if setLocks && !slowPass
1128 * avc->lock(W) if !setLocks || slowPass
1131 code = rxfs_fetchInit(
1132 tc, rxconn, avc, base, size, &length, adc, fP, &ops, &rock);
1135 osi_GetTime(&xferStartTime);
1136 #endif /* AFS_NOSTATS */
1138 adc->validPos = base;
1145 if (avc->f.states & CForeign) {
1146 code = (*ops->more)(rock, &length, &moredata);
1151 bytesToXfer += length;
1152 #endif /* AFS_NOSTATS */
1153 while (length > 0) {
1154 #ifdef RX_KERNEL_TRACE
1155 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1158 code = (*ops->read)(rock, length, &bytesread);
1159 #ifdef RX_KERNEL_TRACE
1160 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1164 bytesXferred += bytesread;
1165 #endif /* AFS_NOSTATS */
1167 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1168 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1169 ICL_TYPE_INT32, length);
1173 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1176 offset += bytesread;
1178 length -= bytesread;
1179 adc->validPos = base;
1180 if (afs_osi_Wakeup(&adc->validPos) == 0)
1181 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1182 __FILE__, ICL_TYPE_INT32, __LINE__,
1183 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1190 code = (*ops->close)(rock, avc, adc, tsmall);
1192 code = (*ops->destroy)(&rock, code);
1195 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, xferStartTime,
1196 bytesToXfer, bytesXferred);