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;
32 FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
33 afs_size_t bytesToXfer, afs_size_t bytesXferred)
35 struct afs_stats_xferData *xferP;
36 osi_timeval_t xferStopTime;
37 osi_timeval_t elapsedTime;
39 xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[idx]);
40 osi_GetuTime(&xferStopTime);
43 (xferP->numSuccesses)++;
44 afs_stats_XferSumBytes[idx] += bytesXferred;
45 (xferP->sumBytes) += (afs_stats_XferSumBytes[idx] >> 10);
46 afs_stats_XferSumBytes[idx] &= 0x3FF;
47 if (bytesXferred < xferP->minBytes)
48 xferP->minBytes = bytesXferred;
49 if (bytesXferred > xferP->maxBytes)
50 xferP->maxBytes = bytesXferred;
53 * Tally the size of the object. Note: we tally the actual size,
54 * NOT the number of bytes that made it out over the wire.
56 if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) (xferP->count[0])++;
57 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) (xferP->count[1])++;
58 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) (xferP->count[2])++;
59 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) (xferP->count[3])++;
60 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) (xferP->count[4])++;
61 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) (xferP->count[5])++;
62 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) (xferP->count[6])++;
63 else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) (xferP->count[7])++;
67 afs_stats_GetDiff(elapsedTime, (*xferStartTime), xferStopTime);
68 afs_stats_AddTo((xferP->sumTime), elapsedTime);
69 afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
70 if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
71 afs_stats_TimeAssign((xferP->minTime), elapsedTime);
73 if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
74 afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
78 #endif /* AFS_NOSTATS */
80 /* rock and operations for RX_FILESERVER */
85 rxfs_storeUfsPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
87 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
92 rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
95 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
97 *tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
99 code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
102 code = rx_Error(v->call);
114 rxfs_storeUfsRead(void *r, struct osi_file *tfile, afs_uint32 offset,
115 afs_uint32 tlen, afs_uint32 *bytesread)
118 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
121 code = afs_osi_Read(tfile, -1, v->tbuffer, tlen);
127 #if defined(KERNEL_HAVE_UERROR)
135 rxfs_storeMemRead(void *r, struct osi_file *tfile, afs_uint32 offset,
136 afs_uint32 tlen, afs_uint32 *bytesread)
139 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
140 struct memCacheEntry *mceP = (struct memCacheEntry *)tfile;
143 code = afs_MemReadvBlk(mceP, offset, v->tiov, v->tnio, tlen);
151 rxfs_storeMemWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
154 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
157 code = rx_Writev(v->call, v->tiov, v->tnio, l);
160 code = rx_Error(v->call);
161 return (code ? code : -33);
163 *byteswritten = code;
168 rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
171 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
174 code = rx_Write(v->call, v->tbuffer, l);
175 /* writing 0 bytes will
176 * push a short packet. Is that really what we want, just because the
177 * data didn't come back from the disk yet? Let's try it and see. */
180 code = rx_Error(v->call);
181 return (code ? code : -33);
183 *byteswritten = code;
188 rxfs_storePadd(void *rock, afs_uint32 size)
192 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
195 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
196 memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
199 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
201 code = rx_Write(v->call, v->tbuffer, tlen);
205 return -33; /* XXX */
212 rxfs_storeStatus(void *rock)
214 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
216 if (rx_GetRemoteStatus(v->call) & 1)
222 rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
225 struct AFSVolSync tsync;
226 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)r;
231 #ifdef AFS_64BIT_CLIENT
233 code = EndRXAFS_StoreData64(v->call, OutStatus, &tsync);
236 code = EndRXAFS_StoreData(v->call, OutStatus, &tsync);
239 *doProcessFS = 1; /* Flag to run afs_ProcessFS() later on */
245 rxfs_storeDestroy(void **r, afs_int32 error)
247 afs_int32 code = error;
248 struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
253 code = rx_EndCall(v->call, error);
259 osi_FreeLargeSpace(v->tbuffer);
261 osi_FreeSmallSpace(v->tiov);
262 osi_FreeSmallSpace(v);
267 afs_GenericStoreProc(struct storeOps *ops, void *rock,
268 struct dcache *tdc, int *shouldwake,
269 afs_size_t *bytesXferred)
271 struct rxfs_storeVariables *svar = rock;
272 afs_uint32 tlen, bytesread, byteswritten;
276 struct osi_file *tfile;
278 size = tdc->f.chunkBytes;
280 tfile = afs_CFileOpen(&tdc->f.inode);
283 code = (*ops->prepare)(rock, size, &tlen);
287 code = (*ops->read)(rock, tfile, offset, tlen, &bytesread);
292 code = (*ops->write)(rock, tlen, &byteswritten);
296 *bytesXferred += byteswritten;
297 #endif /* AFS_NOSTATS */
302 * if file has been locked on server, can allow
305 if (shouldwake && *shouldwake && ((*ops->status)(rock) == 0)) {
306 *shouldwake = 0; /* only do this once */
307 afs_wakeup(svar->vcache);
310 afs_CFileClose(tfile);
316 struct storeOps rxfs_storeUfsOps = {
317 #if (defined(AFS_SGI_ENV) && !defined(__c99))
318 rxfs_storeUfsPrepare,
327 .prepare = rxfs_storeUfsPrepare,
328 .read = rxfs_storeUfsRead,
329 .write = rxfs_storeUfsWrite,
330 .status = rxfs_storeStatus,
331 .padd = rxfs_storePadd,
332 .close = rxfs_storeClose,
333 .destroy = rxfs_storeDestroy,
334 #ifdef AFS_LINUX26_ENV
335 .storeproc = afs_linux_storeproc
337 .storeproc = afs_GenericStoreProc
343 struct storeOps rxfs_storeMemOps = {
344 #if (defined(AFS_SGI_ENV) && !defined(__c99))
345 rxfs_storeMemPrepare,
354 .prepare = rxfs_storeMemPrepare,
355 .read = rxfs_storeMemRead,
356 .write = rxfs_storeMemWrite,
357 .status = rxfs_storeStatus,
358 .padd = rxfs_storePadd,
359 .close = rxfs_storeClose,
360 .destroy = rxfs_storeDestroy,
361 #ifdef AFS_LINUX26_ENV
362 .storeproc = afs_linux_storeproc
364 .storeproc = afs_GenericStoreProc
370 rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
371 afs_size_t bytes, afs_size_t length,
372 int sync, struct storeOps **ops, void **rock)
375 struct rxfs_storeVariables *v;
380 v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
382 osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
383 memset(v, 0, sizeof(struct rxfs_storeVariables));
385 v->InStatus.ClientModTime = avc->f.m.Date;
386 v->InStatus.Mask = AFS_SETMODTIME;
389 v->InStatus.Mask |= AFS_FSYNC;
391 v->call = rx_NewCall(tc->id);
393 #ifdef AFS_64BIT_CLIENT
394 if (!afs_serverHasNo64Bit(tc))
395 code = StartRXAFS_StoreData64(
396 v->call, (struct AFSFid*)&avc->f.fid.Fid,
397 &v->InStatus, base, bytes, length);
399 if (length > 0xFFFFFFFF)
402 afs_int32 t1 = base, t2 = bytes, t3 = length;
403 code = StartRXAFS_StoreData(v->call,
404 (struct AFSFid *) &avc->f.fid.Fid,
405 &v->InStatus, t1, t2, t3);
407 #else /* AFS_64BIT_CLIENT */
408 code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
409 &v->InStatus, base, bytes, length);
410 #endif /* AFS_64BIT_CLIENT */
415 osi_FreeSmallSpace(v);
418 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
419 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
422 ("rxfs_storeInit: osi_AllocLargeSpace for iovecs returned NULL\n");
423 *ops = (struct storeOps *) &rxfs_storeUfsOps;
425 v->tiov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
428 ("rxfs_storeInit: osi_AllocSmallSpace for iovecs returned NULL\n");
429 *ops = (struct storeOps *) &rxfs_storeMemOps;
431 /* do this at a higher level now -- it's a parameter */
432 /* for now, only do 'continue from close' code if file fits in one
433 * chunk. Could clearly do better: if only one modified chunk
434 * then can still do this. can do this on *last* modified chunk */
435 length = avc->f.m.Length - 1; /* byte position of last byte we'll store */
437 if (AFS_CHUNK(length) != 0)
448 unsigned int storeallmissing = 0;
450 * Called for each chunk upon store.
452 * \param avc Ptr to the vcache entry of the file being stored.
453 * \param dclist pointer to the list of dcaches
454 * \param bytes total number of bytes for the current operation
455 * \param anewDV Ptr to the dataversion after store
456 * \param doProcessFS pointer to the "do process FetchStatus" flag
457 * \param OutStatus pointer to the FetchStatus as returned by the fileserver
458 * \param nchunks number of dcaches to consider
459 * \param nomore copy of the "no more data" flag
460 * \param ops pointer to the block of storeOps to be used for this operation
461 * \param rock pointer to the opaque protocol-specific data of this operation
464 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
465 afs_size_t bytes, afs_hyper_t *anewDV, int *doProcessFS,
466 struct AFSFetchStatus *OutStatus, afs_uint32 nchunks,
467 int nomore, struct storeOps *ops, void *rock)
469 int *shouldwake = NULL;
472 afs_size_t bytesXferred;
475 osi_timeval_t xferStartTime; /*FS xfer start time */
476 afs_size_t bytesToXfer = 10000; /* # bytes to xfer */
477 #endif /* AFS_NOSTATS */
480 for (i = 0; i < nchunks && !code; i++) {
482 struct dcache *tdc = dclist[i];
483 afs_int32 size = tdc->f.chunkBytes;
485 afs_warn("afs: missing dcache!\n");
487 continue; /* panic? */
489 afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
490 ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
491 ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
494 if (avc->asynchrony == -1) {
495 if (afs_defaultAsynchrony > (bytes - stored))
496 shouldwake = &nomore;
498 else if ((afs_uint32) avc->asynchrony >= (bytes - stored))
499 shouldwake = &nomore;
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);
506 AFS_STATCNT(CacheStoreProc);
508 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STOREDATA);
509 avc->f.truncPos = AFS_NOTRUNC;
512 * In this case, size is *always* the amount of data we'll be trying
517 osi_GetuTime(&xferStartTime);
518 #endif /* AFS_NOSTATS */
521 code = (*ops->storeproc)(ops, rock, tdc, shouldwake,
524 afs_Trace4(afs_iclSetp, CM_TRACE_STOREPROC, ICL_TYPE_POINTER, avc,
525 ICL_TYPE_FID, &(avc->f.fid), ICL_TYPE_OFFSET,
526 ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, size);
529 FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
530 &xferStartTime, bytesToXfer, bytesXferred);
531 #endif /* AFS_NOSTATS */
533 if ((tdc->f.chunkBytes < afs_OtherCSize)
534 && (i < (nchunks - 1)) && code == 0) {
535 code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
537 stored += tdc->f.chunkBytes;
538 /* ideally, I'd like to unlock the dcache and turn
539 * off the writing bit here, but that would
540 * require being able to retry StoreAllSegments in
541 * the event of a failure. It only really matters
542 * if user can't read from a 'locked' dcache or
543 * one which has the writing bit turned on. */
547 code = (*ops->close)(rock, OutStatus, doProcessFS);
554 code = (*ops->destroy)(&rock, code);
558 #define lmin(a,b) (((a) < (b)) ? (a) : (b))
562 * \param dclist pointer to the list of dcaches
563 * \param avc Ptr to the vcache entry.
564 * \param areq Ptr to the request structure
565 * \param sync sync flag
566 * \param minj the chunk offset for this call
567 * \param high index of last dcache to store
568 * \param moredata the moredata flag
569 * \param anewDV Ptr to the dataversion after store
570 * \param amaxStoredLength Ptr to the amount of that is actually stored
572 * \note Environment: Nothing interesting.
575 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
576 struct vrequest *areq, int sync, unsigned int minj,
577 unsigned int high, unsigned int moredata,
578 afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
581 struct storeOps *ops;
585 struct AFSFetchStatus OutStatus;
587 afs_size_t base, bytes, length;
589 unsigned int first = 0;
592 for (bytes = 0, j = 0; !code && j <= high; j++) {
594 ObtainSharedLock(&(dcList[j]->lock), 629);
597 bytes += dcList[j]->f.chunkBytes;
598 if ((dcList[j]->f.chunkBytes < afs_OtherCSize)
599 && (dcList[j]->f.chunk - minj < high)
601 int sbytes = afs_OtherCSize - dcList[j]->f.chunkBytes;
605 if (bytes && (j == high || !dcList[j + 1])) {
607 struct dcache **dclist = &dcList[first];
608 /* base = AFS_CHUNKTOBASE(dcList[first]->f.chunk); */
609 base = AFS_CHUNKTOBASE(first + minj);
612 * take a list of dcache structs and send them all off to the server
613 * the list must be in order, and the chunks contiguous.
614 * Note - there is no locking done by this code currently. For
615 * safety's sake, xdcache could be locked over the entire call.
616 * However, that pretty well ties up all the threads. Meantime, all
617 * the chunks _MUST_ have their refcounts bumped.
618 * The writes done before a store back will clear setuid-ness
620 * We can permit CacheStoreProc to wake up the user process IFF we
621 * are doing the last RPC for this close, ie, storing back the last
622 * set of contiguous chunks of a file.
625 nchunks = 1 + j - first;
626 nomore = !(moredata || (j != high));
627 length = lmin(avc->f.m.Length, avc->f.truncPos);
628 afs_Trace4(afs_iclSetp, CM_TRACE_STOREDATA64,
629 ICL_TYPE_FID, &avc->f.fid.Fid, ICL_TYPE_OFFSET,
630 ICL_HANDLE_OFFSET(base), ICL_TYPE_OFFSET,
631 ICL_HANDLE_OFFSET(bytes), ICL_TYPE_OFFSET,
632 ICL_HANDLE_OFFSET(length));
635 tc = afs_Conn(&avc->f.fid, areq, 0);
637 #ifdef AFS_64BIT_CLIENT
640 code = rxfs_storeInit(avc, tc, base, bytes, length,
643 code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
644 &doProcessFS, &OutStatus,
645 nchunks, nomore, ops, rock);
648 #ifdef AFS_64BIT_CLIENT
649 if (code == RXGEN_OPCODE && !afs_serverHasNo64Bit(tc)) {
650 afs_serverSetNo64Bit(tc);
653 #endif /* AFS_64BIT_CLIENT */
655 (tc, code, &avc->f.fid, areq,
656 AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
659 /* put back all remaining locked dcache entries */
660 for (i = 0; i < nchunks; i++) {
661 struct dcache *tdc = dclist[i];
663 if (afs_indexFlags[tdc->index] & IFDataMod) {
665 * LOCKXXX -- should hold afs_xdcache(W) when
666 * modifying afs_indexFlags.
668 afs_indexFlags[tdc->index] &= ~IFDataMod;
669 afs_stats_cmperf.cacheCurrDirtyChunks--;
670 afs_indexFlags[tdc->index] &= ~IFDirtyPages;
671 if (sync & AFS_VMSYNC_INVAL) {
672 /* since we have invalidated all the pages of this
673 ** vnode by calling osi_VM_TryToSmush, we can
674 ** safely mark this dcache entry as not having
675 ** any pages. This vnode now becomes eligible for
676 ** reclamation by getDownD.
678 afs_indexFlags[tdc->index] &= ~IFAnyPages;
682 UpgradeSToWLock(&tdc->lock, 628);
683 tdc->f.states &= ~DWriting; /* correct? */
684 tdc->dflags |= DFEntryMod;
685 ReleaseWriteLock(&tdc->lock);
687 /* Mark the entry as released */
692 /* Now copy out return params */
693 UpgradeSToWLock(&avc->lock, 28); /* keep out others for a while */
694 afs_ProcessFS(avc, &OutStatus, areq);
695 /* Keep last (max) size of file on server to see if
696 * we need to call afs_StoreMini to extend the file.
699 *amaxStoredLength = OutStatus.Length;
700 ConvertWToSLock(&avc->lock);
705 for (j++; j <= high; j++) {
707 ReleaseSharedLock(&(dcList[j]->lock));
708 afs_PutDCache(dcList[j]);
709 /* Releasing entry */
715 afs_Trace2(afs_iclSetp, CM_TRACE_STOREALLDCDONE,
716 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
724 /* rock and operations for RX_FILESERVER */
726 struct rxfs_fetchVariables {
727 struct rx_call *call;
731 afs_int32 hasNo64bit;
737 rxfs_fetchUfsRead(void *r, afs_uint32 size, afs_uint32 *bytesread)
741 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
744 tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
746 code = rx_Read(v->call, v->tbuffer, tlen);
755 rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
758 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
762 code = rx_Readv(v->call, v->iov, &v->nio, RX_MAXIOVECS, tlen);
772 rxfs_fetchMemWrite(void *r, struct osi_file *fP, afs_uint32 offset,
773 afs_uint32 tlen, afs_uint32 *byteswritten)
776 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
777 struct memCacheEntry *mceP = (struct memCacheEntry *)fP;
779 code = afs_MemWritevBlk(mceP, offset, v->iov, v->nio, tlen);
783 *byteswritten = code;
788 rxfs_fetchUfsWrite(void *r, struct osi_file *fP, afs_uint32 offset,
789 afs_uint32 tlen, afs_uint32 *byteswritten)
792 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
794 code = afs_osi_Write(fP, -1, v->tbuffer, tlen);
798 *byteswritten = code;
804 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
805 struct afs_FetchOutput *o)
807 afs_int32 code, code1 = 0;
808 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
814 #ifdef AFS_64BIT_CLIENT
816 code = EndRXAFS_FetchData64(v->call, &o->OutStatus, &o->CallBack,
820 code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
822 code1 = rx_EndCall(v->call, code);
833 rxfs_fetchDestroy(void **r, afs_int32 error)
835 afs_int32 code = error;
836 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
841 code = rx_EndCall(v->call, error);
847 osi_FreeLargeSpace(v->tbuffer);
849 osi_FreeSmallSpace(v->iov);
850 osi_FreeSmallSpace(v);
855 rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
858 struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
861 * The fetch protocol is extended for the AFS/DFS translator
862 * to allow multiple blocks of data, each with its own length,
863 * to be returned. As long as the top bit is set, there are more
866 * We do not do this for AFS file servers because they sometimes
867 * return large negative numbers as the transfer size.
871 code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
873 *length = ntohl(*length);
874 if (code != sizeof(afs_int32)) {
875 code = rx_Error(v->call);
877 return (code ? code : -1); /* try to return code, not -1 */
880 *moredata = *length & 0x80000000;
881 *length &= ~0x80000000;
886 struct fetchOps rxfs_fetchUfsOps = {
895 struct fetchOps rxfs_fetchMemOps = {
904 rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
905 afs_uint32 size, afs_int32 *alength, struct dcache *adc,
906 struct osi_file *fP, struct fetchOps **ops, void **rock)
908 struct rxfs_fetchVariables *v;
909 int code = 0, code1 = 0;
910 #ifdef AFS_64BIT_CLIENT
911 afs_uint32 length_hi = 0;
913 afs_uint32 length, bytes;
915 v = (struct rxfs_fetchVariables *)
916 osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
918 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
919 memset(v, 0, sizeof(struct rxfs_fetchVariables));
922 v->call = rx_NewCall(tc->id);
925 #ifdef AFS_64BIT_CLIENT
926 afs_size_t length64; /* as returned from server */
927 if (!afs_serverHasNo64Bit(tc)) {
928 afs_uint64 llbytes = size;
930 code = StartRXAFS_FetchData64(v->call,
931 (struct AFSFid *) &avc->f.fid.Fid,
935 afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
936 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code);
938 bytes = rx_Read(v->call, (char *)&length_hi, sizeof(afs_int32));
940 if (bytes == sizeof(afs_int32)) {
941 length_hi = ntohl(length_hi);
943 code = rx_Error(v->call);
945 code1 = rx_EndCall(v->call, code);
951 if (code == RXGEN_OPCODE || afs_serverHasNo64Bit(tc)) {
952 if (base > 0x7FFFFFFF) {
959 v->call = rx_NewCall(tc->id);
961 StartRXAFS_FetchData(
962 v->call, (struct AFSFid*)&avc->f.fid.Fid,
966 afs_serverSetNo64Bit(tc);
970 bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
972 if (bytes == sizeof(afs_int32))
973 length = ntohl(length);
976 code = rx_Error(v->call);
977 code1 = rx_EndCall(v->call, code);
982 FillInt64(length64, length_hi, length);
983 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
984 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
986 ICL_HANDLE_OFFSET(length64));
988 #else /* AFS_64BIT_CLIENT */
990 code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
996 rx_Read(v->call, (char *)&length, sizeof(afs_int32));
998 if (bytes == sizeof(afs_int32)) {
999 *alength = ntohl(length);
1001 code = rx_Error(v->call);
1002 code1 = rx_EndCall(v->call, code);
1006 #endif /* AFS_64BIT_CLIENT */
1010 /* We need to cast here, in order to avoid issues if *alength is
1011 * negative. Some, older, fileservers can return a negative length,
1012 * which the rest of the code deals correctly with. */
1013 if (code == 0 && *alength > (afs_int32) size) {
1014 /* The fileserver told us it is going to send more data than we
1015 * requested. It shouldn't do that, and accepting that much data
1016 * can make us take up more cache space than we're supposed to,
1018 code = rx_Error(v->call);
1020 code1 = rx_EndCall(v->call, code);
1030 osi_FreeSmallSpace(v);
1033 if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
1034 v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
1036 osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
1037 osi_Assert(WriteLocked(&adc->lock));
1039 *ops = (struct fetchOps *) &rxfs_fetchUfsOps;
1042 afs_Trace4(afs_iclSetp, CM_TRACE_MEMFETCH, ICL_TYPE_POINTER, avc,
1043 ICL_TYPE_POINTER, fP, ICL_TYPE_OFFSET,
1044 ICL_HANDLE_OFFSET(base), ICL_TYPE_INT32, length);
1046 * We need to alloc the iovecs on the heap so that they are "pinned"
1047 * rather than declare them on the stack - defect 11272
1049 v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
1051 osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
1052 *ops = (struct fetchOps *) &rxfs_fetchMemOps;
1060 * Routine called on fetch; also tells people waiting for data
1061 * that more has arrived.
1063 * \param tc Ptr to the Rx connection structure.
1064 * \param fP File descriptor for the cache file.
1065 * \param base Base offset to fetch.
1066 * \param adc Ptr to the dcache entry for the file, write-locked.
1067 * \param avc Ptr to the vcache entry for the file.
1068 * \param size Amount of data that should be fetched.
1069 * \param tsmall Ptr to the afs_FetchOutput structure.
1071 * \note Environment: Nothing interesting.
1074 afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
1075 struct dcache *adc, struct vcache *avc, afs_int32 size,
1076 struct afs_FetchOutput *tsmall)
1080 afs_uint32 bytesread, byteswritten;
1081 struct fetchOps *ops = NULL;
1083 afs_uint32 moredata = 0;
1088 osi_timeval_t xferStartTime; /*FS xfer start time */
1089 afs_size_t bytesToXfer = 0, bytesXferred = 0;
1092 AFS_STATCNT(CacheFetchProc);
1094 XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHDATA);
1098 * avc->lock(R) if setLocks && !slowPass
1099 * avc->lock(W) if !setLocks || slowPass
1102 code = rxfs_fetchInit(
1103 tc, avc, base, size, &length, adc, fP, &ops, &rock);
1106 osi_GetuTime(&xferStartTime);
1107 #endif /* AFS_NOSTATS */
1110 adc->validPos = base;
1114 if (avc->f.states & CForeign) {
1115 code = (*ops->more)(rock, &length, &moredata);
1120 bytesToXfer += length;
1121 #endif /* AFS_NOSTATS */
1122 while (length > 0) {
1123 #ifdef RX_KERNEL_TRACE
1124 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1127 code = (*ops->read)(rock, length, &bytesread);
1128 #ifdef RX_KERNEL_TRACE
1129 afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
1133 bytesXferred += bytesread;
1134 #endif /* AFS_NOSTATS */
1136 afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64READ,
1137 ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
1138 ICL_TYPE_INT32, length);
1142 code = (*ops->write)(rock, fP, offset, bytesread, &byteswritten);
1145 offset += bytesread;
1147 length -= bytesread;
1148 adc->validPos = base;
1149 if (afs_osi_Wakeup(&adc->validPos) == 0)
1150 afs_Trace4(afs_iclSetp, CM_TRACE_DCACHEWAKE, ICL_TYPE_STRING,
1151 __FILE__, ICL_TYPE_INT32, __LINE__,
1152 ICL_TYPE_POINTER, adc, ICL_TYPE_INT32,
1158 code = (*ops->close)(rock, avc, adc, tsmall);
1160 (*ops->destroy)(&rock, code);
1163 FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,
1164 bytesToXfer, bytesXferred);