afs: Log weird 'size' fetchdata errors
[openafs.git] / src / afs / afs_fetchstore.c
index 048c0c2..f65f40c 100644 (file)
@@ -19,7 +19,6 @@
 #undef kmem_free
 #undef mem_alloc
 #undef mem_free
-#undef register
 #endif /* AFS_ALPHA_ENV */
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* statistics */
 
 extern int cacheDiskType;
 
-
 #ifndef AFS_NOSTATS
-void
-FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
-                 afs_size_t bytesToXfer, afs_size_t bytesXferred)
+static void
+FillStoreStats(int code, int idx, osi_timeval_t xferStartTime,
+              afs_size_t bytesToXfer, afs_size_t bytesXferred)
 {
     struct afs_stats_xferData *xferP;
     osi_timeval_t xferStopTime;
@@ -65,7 +63,7 @@ FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
        else
            (xferP->count[8])++;
 
-       afs_stats_GetDiff(elapsedTime, (*xferStartTime), xferStopTime);
+       afs_stats_GetDiff(elapsedTime, xferStartTime, xferStopTime);
        afs_stats_AddTo((xferP->sumTime), elapsedTime);
        afs_stats_SquareAddTo((xferP->sqrTime), elapsedTime);
        if (afs_stats_TimeLessThan(elapsedTime, (xferP->minTime))) {
@@ -95,9 +93,8 @@ rxfs_storeMemPrepare(void *r, afs_uint32 size, afs_uint32 *tlen)
     afs_int32 code;
     struct rxfs_storeVariables *v = (struct rxfs_storeVariables *) r;
 
-    *tlen = (size > AFS_LRALLOCSIZ ?  AFS_LRALLOCSIZ : size);
     RX_AFS_GUNLOCK();
-    code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, *tlen);
+    code = rx_WritevAlloc(v->call, v->tiov, &v->tnio, RX_MAXIOVECS, size);
     RX_AFS_GLOCK();
     if (code <= 0) {
        code = rx_Error(v->call);
@@ -243,18 +240,15 @@ rxfs_storeClose(void *r, struct AFSFetchStatus *OutStatus, int *doProcessFS)
 }
 
 afs_int32
-rxfs_storeDestroy(void **r, afs_int32 error)
+rxfs_storeDestroy(void **r, afs_int32 code)
 {
-    afs_int32 code = error;
     struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)*r;
 
     *r = NULL;
     if (v->call) {
        RX_AFS_GUNLOCK();
-       code = rx_EndCall(v->call, error);
+       code = rx_EndCall(v->call, code);
        RX_AFS_GLOCK();
-       if (!code && error)
-           code = error;
     }
     if (v->tbuffer)
        osi_FreeLargeSpace(v->tbuffer);
@@ -271,7 +265,7 @@ afs_GenericStoreProc(struct storeOps *ops, void *rock,
 {
     struct rxfs_storeVariables *svar = rock;
     afs_uint32 tlen, bytesread, byteswritten;
-    afs_int32 code;
+    afs_int32 code = 0;
     int offset = 0;
     afs_size_t size;
     struct osi_file *tfile;
@@ -315,7 +309,7 @@ afs_GenericStoreProc(struct storeOps *ops, void *rock,
 
 static
 struct storeOps rxfs_storeUfsOps = {
-#if (defined(AFS_SGI_ENV) && !defined(__c99))
+#ifndef HAVE_STRUCT_LABEL_SUPPORT
     rxfs_storeUfsPrepare,
     rxfs_storeUfsRead,
     rxfs_storeUfsWrite,
@@ -342,14 +336,15 @@ struct storeOps rxfs_storeUfsOps = {
 
 static
 struct storeOps rxfs_storeMemOps = {
-#if (defined(AFS_SGI_ENV) && !defined(__c99))
+#ifndef HAVE_STRUCT_LABEL_SUPPORT
     rxfs_storeMemPrepare,
     rxfs_storeMemRead,
     rxfs_storeMemWrite,
     rxfs_storeStatus,
     rxfs_storePadd,
     rxfs_storeClose,
-    rxfs_storeDestroy
+    rxfs_storeDestroy,
+    afs_GenericStoreProc
 #else
     .prepare = rxfs_storeMemPrepare,
     .read =    rxfs_storeMemRead,
@@ -357,12 +352,14 @@ struct storeOps rxfs_storeMemOps = {
     .status =  rxfs_storeStatus,
     .padd =    rxfs_storePadd,
     .close =   rxfs_storeClose,
-    .destroy = rxfs_storeDestroy
+    .destroy = rxfs_storeDestroy,
+    .storeproc = afs_GenericStoreProc
 #endif
 };
 
 afs_int32
-rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
+rxfs_storeInit(struct vcache *avc, struct afs_conn *tc,
+                struct rx_connection *rxconn, afs_size_t base,
                afs_size_t bytes, afs_size_t length,
                int sync, struct storeOps **ops, void **rock)
 {
@@ -372,7 +369,7 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
     if ( !tc )
        return -1;
 
-    v = (struct rxfs_storeVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
+    v = osi_AllocSmallSpace(sizeof(struct rxfs_storeVariables));
     if (!v)
         osi_Panic("rxfs_storeInit: osi_AllocSmallSpace returned NULL\n");
     memset(v, 0, sizeof(struct rxfs_storeVariables));
@@ -383,14 +380,14 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
     if (sync & AFS_SYNC)
         v->InStatus.Mask |= AFS_FSYNC;
     RX_AFS_GUNLOCK();
-    v->call = rx_NewCall(tc->id);
+    v->call = rx_NewCall(rxconn);
     if (v->call) {
 #ifdef AFS_64BIT_CLIENT
        if (!afs_serverHasNo64Bit(tc))
            code = StartRXAFS_StoreData64(
-                               v->call, (struct AFSFid*)&avc->f.fid.Fid,
-                               &v->InStatus, base, bytes, length);
-       else
+               v->call, (struct AFSFid*)&avc->f.fid.Fid,
+               &v->InStatus, base, bytes, length);
+       else {
            if (length > 0xFFFFFFFF)
                code = EFBIG;
            else {
@@ -399,6 +396,8 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc, afs_size_t base,
                                        (struct AFSFid *) &avc->f.fid.Fid,
                                         &v->InStatus, t1, t2, t3);
            }
+           v->hasNo64bit = 1;
+       }
 #else /* AFS_64BIT_CLIENT */
        code = StartRXAFS_StoreData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
                                    &v->InStatus, base, bytes, length);
@@ -457,16 +456,13 @@ unsigned int storeallmissing = 0;
  */
 afs_int32
 afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
-                       afs_size_t bytes,
-                       afs_hyper_t *anewDV,
-                       int *doProcessFS,
-                       struct AFSFetchStatus *OutStatus,
-                       afs_uint32 nchunks,
-                       int nomore,
-                       struct storeOps *ops, void *rock)
+                     afs_size_t bytes, afs_hyper_t *anewDV, int *doProcessFS,
+                     struct AFSFetchStatus *OutStatus, afs_uint32 nchunks,
+                     int nomore, struct storeOps *ops, void *rock)
 {
     int *shouldwake = NULL;
     unsigned int i;
+    int stored = 0;
     afs_int32 code = 0;
     afs_size_t bytesXferred;
 
@@ -475,16 +471,18 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
     afs_size_t bytesToXfer = 10000;    /* # bytes to xfer */
 #endif /* AFS_NOSTATS */
     XSTATS_DECLS;
+    osi_Assert(nchunks != 0);
 
     for (i = 0; i < nchunks && !code; i++) {
-       int stored = 0;
        struct dcache *tdc = dclist[i];
-       afs_int32 size = tdc->f.chunkBytes;
+       afs_int32 size;
+
        if (!tdc) {
            afs_warn("afs: missing dcache!\n");
            storeallmissing++;
            continue;   /* panic? */
        }
+       size = tdc->f.chunkBytes;
        afs_Trace4(afs_iclSetp, CM_TRACE_STOREALL2, ICL_TYPE_POINTER, avc,
                    ICL_TYPE_INT32, tdc->f.chunk, ICL_TYPE_INT32, tdc->index,
                    ICL_TYPE_INT32, afs_inode2trace(&tdc->f.inode));
@@ -526,7 +524,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
 
 #ifndef AFS_NOSTATS
        FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
-                   &xferStartTime, bytesToXfer, bytesXferred);
+                   xferStartTime, bytesToXfer, bytesXferred);
 #endif /* AFS_NOSTATS */
 
        if ((tdc->f.chunkBytes < afs_OtherCSize)
@@ -544,6 +542,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
 
     if (!code) {
        code = (*ops->close)(rock, OutStatus, doProcessFS);
+       /* if this succeeds, dv has been bumped. */
        if (*doProcessFS) {
            hadd32(*anewDV, 1);
        }
@@ -551,6 +550,11 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
     }
     if (ops)
        code = (*ops->destroy)(&rock, code);
+
+    /* if we errored, can't trust this. */
+    if (code)
+       *doProcessFS = 0;
+
     return code;
 }
 
@@ -572,10 +576,9 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
  */
 int
 afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
-                       struct vrequest *areq, int sync,
-                       unsigned int minj, unsigned int high,
-                       unsigned int moredata,
-                       afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
+                    struct vrequest *areq, int sync, unsigned int minj,
+                    unsigned int high, unsigned int moredata,
+                    afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
 {
     afs_int32 code = 0;
     struct storeOps *ops;
@@ -588,6 +591,7 @@ afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
     int nomore;
     unsigned int first = 0;
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
 
     for (bytes = 0, j = 0; !code && j <= high; j++) {
        if (dcList[j]) {
@@ -632,12 +636,12 @@ afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
                       ICL_HANDLE_OFFSET(length));
 
            do {
-               tc = afs_Conn(&avc->f.fid, areq, 0);
+               tc = afs_Conn(&avc->f.fid, areq, 0, &rxconn);
 
 #ifdef AFS_64BIT_CLIENT
              restart:
 #endif
-               code = rxfs_storeInit(avc, tc, base, bytes, length,
+               code = rxfs_storeInit(avc, tc, rxconn, base, bytes, length,
                                      sync, &ops, &rock);
                if ( !code ) {
                    code = afs_CacheStoreDCaches(avc, dclist, bytes, anewDV,
@@ -652,7 +656,7 @@ afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
                }
 #endif /* AFS_64BIT_CLIENT */
            } while (afs_Analyze
-                    (tc, code, &avc->f.fid, areq,
+                    (tc, rxconn, code, &avc->f.fid, areq,
                      AFS_STATS_FS_RPCIDX_STOREDATA, SHARED_LOCK,
                      NULL));
 
@@ -769,9 +773,8 @@ rxfs_fetchMemRead(void *r, afs_uint32 tlen, afs_uint32 *bytesread)
 
 
 afs_int32
-rxfs_fetchMemWrite(void *r, struct osi_file *fP,
-                       afs_uint32 offset, afs_uint32 tlen,
-                       afs_uint32 *byteswritten)
+rxfs_fetchMemWrite(void *r, struct osi_file *fP, afs_uint32 offset,
+                  afs_uint32 tlen, afs_uint32 *byteswritten)
 {
     afs_int32 code;
     struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
@@ -786,9 +789,8 @@ rxfs_fetchMemWrite(void *r, struct osi_file *fP,
 }
 
 afs_int32
-rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
-                       afs_uint32 offset, afs_uint32 tlen,
-                       afs_uint32 *byteswritten)
+rxfs_fetchUfsWrite(void *r, struct osi_file *fP, afs_uint32 offset,
+                  afs_uint32 tlen, afs_uint32 *byteswritten)
 {
     afs_int32 code;
     struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
@@ -804,9 +806,9 @@ rxfs_fetchUfsWrite(void *r, struct osi_file *fP,
 
 afs_int32
 rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
-                                       struct afs_FetchOutput *o)
+               struct afs_FetchOutput *o)
 {
-    afs_int32 code, code1 = 0;
+    afs_int32 code;
     struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
 
     if (!v->call)
@@ -821,10 +823,8 @@ rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
 #endif
         code = EndRXAFS_FetchData(v->call, &o->OutStatus, &o->CallBack,
                                &o->tsync);
-    code1 = rx_EndCall(v->call, code);
+    code = rx_EndCall(v->call, code);
     RX_AFS_GLOCK();
-    if (!code && code1)
-       code = code1;
 
     v->call = NULL;
 
@@ -832,18 +832,15 @@ rxfs_fetchClose(void *r, struct vcache *avc, struct dcache * adc,
 }
 
 afs_int32
-rxfs_fetchDestroy(void **r, afs_int32 error)
+rxfs_fetchDestroy(void **r, afs_int32 code)
 {
-    afs_int32 code = error;
     struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)*r;
 
     *r = NULL;
     if (v->call) {
         RX_AFS_GUNLOCK();
-       code = rx_EndCall(v->call, error);
+       code = rx_EndCall(v->call, code);
         RX_AFS_GLOCK();
-       if (error)
-           code = error;
     }
     if (v->tbuffer)
        osi_FreeLargeSpace(v->tbuffer);
@@ -903,24 +900,26 @@ struct fetchOps rxfs_fetchMemOps = {
 };
 
 afs_int32
-rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
-               afs_uint32 size, afs_int32 *alength, struct dcache *adc,
-               struct osi_file *fP, struct fetchOps **ops, void **rock)
+rxfs_fetchInit(struct afs_conn *tc, struct rx_connection *rxconn,
+               struct vcache *avc, afs_offs_t base,
+              afs_uint32 size, afs_int32 *alength, struct dcache *adc,
+              struct osi_file *fP, struct fetchOps **ops, void **rock)
 {
     struct rxfs_fetchVariables *v;
-    int code = 0, code1 = 0;
+    int code = 0;
 #ifdef AFS_64BIT_CLIENT
     afs_uint32 length_hi = 0;
 #endif
-    afs_uint32 length, bytes;
+    afs_uint32 length = 0, bytes;
 
-    v = (struct rxfs_fetchVariables *) osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
+    v = (struct rxfs_fetchVariables *)
+           osi_AllocSmallSpace(sizeof(struct rxfs_fetchVariables));
     if (!v)
         osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace returned NULL\n");
     memset(v, 0, sizeof(struct rxfs_fetchVariables));
 
     RX_AFS_GUNLOCK();
-    v->call = rx_NewCall(tc->id);
+    v->call = rx_NewCall(rxconn);
     RX_AFS_GLOCK();
     if (v->call) {
 #ifdef AFS_64BIT_CLIENT
@@ -928,8 +927,9 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
        if (!afs_serverHasNo64Bit(tc)) {
            afs_uint64 llbytes = size;
            RX_AFS_GUNLOCK();
-           code = StartRXAFS_FetchData64(v->call, (struct AFSFid *) &avc->f.fid.Fid,
-                                              base, llbytes);
+           code = StartRXAFS_FetchData64(v->call,
+                                         (struct AFSFid *) &avc->f.fid.Fid,
+                                         base, llbytes);
            if (code != 0) {
                RX_AFS_GLOCK();
                afs_Trace2(afs_iclSetp, CM_TRACE_FETCH64CODE,
@@ -940,9 +940,8 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
                if (bytes == sizeof(afs_int32)) {
                    length_hi = ntohl(length_hi);
                } else {
-                   code = rx_Error(v->call);
                    RX_AFS_GUNLOCK();
-                   code1 = rx_EndCall(v->call, code);
+                   code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
                    RX_AFS_GLOCK();
                    v->call = NULL;
                }
@@ -956,7 +955,7 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
                pos = base;
                RX_AFS_GUNLOCK();
                if (!v->call)
-                   v->call = rx_NewCall(tc->id);
+                   v->call = rx_NewCall(rxconn);
                code =
                    StartRXAFS_FetchData(
                                v->call, (struct AFSFid*)&avc->f.fid.Fid,
@@ -964,6 +963,7 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
                RX_AFS_GLOCK();
            }
            afs_serverSetNo64Bit(tc);
+           v->hasNo64bit = 1;
        }
        if (!code) {
            RX_AFS_GUNLOCK();
@@ -973,18 +973,55 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
                length = ntohl(length);
            else {
                RX_AFS_GUNLOCK();
-               code = rx_Error(v->call);
-                code1 = rx_EndCall(v->call, code);
+                code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
                v->call = NULL;
+               length = 0;
                RX_AFS_GLOCK();
            }
        }
        FillInt64(length64, length_hi, length);
+
+        if (!code) {
+            /* Check if the fileserver said our length is bigger than can fit
+             * in a signed 32-bit integer. If it is, we can't handle that, so
+             * error out. */
+           if (length64 > MAX_AFS_INT32) {
+                static int warned;
+                if (!warned) {
+                    warned = 1;
+                    afs_warn("afs: Warning: FetchData64 returned too much data "
+                             "(length64 %u.%u); this should not happen! "
+                             "Aborting fetch request.\n",
+                             length_hi, length);
+                }
+               RX_AFS_GUNLOCK();
+                code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
+               v->call = NULL;
+               length = 0;
+               RX_AFS_GLOCK();
+                code = code != 0 ? code : EIO;
+            }
+        }
+
+        if (!code) {
+            /* Check if the fileserver said our length was negative. If it
+             * is, just treat it as a 0 length, since some older fileservers
+             * returned negative numbers when they meant to return 0. Note
+             * that we must do this in this 64-bit-specific block, since
+             * length64 being negative will screw up our conversion to the
+             * 32-bit 'alength' below. */
+            if (length64 < 0) {
+                length_hi = length = 0;
+                FillInt64(length64, 0, 0);
+            }
+        }
+
        afs_Trace3(afs_iclSetp, CM_TRACE_FETCH64LENG,
                   ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
                   ICL_TYPE_OFFSET,
                   ICL_HANDLE_OFFSET(length64));
-       *alength = length;
+       if (!code)
+           *alength = length;
 #else /* AFS_64BIT_CLIENT */
        RX_AFS_GUNLOCK();
        code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
@@ -997,9 +1034,14 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
            RX_AFS_GLOCK();
            if (bytes == sizeof(afs_int32)) {
                 *alength = ntohl(length);
+                if (*alength < 0) {
+                    /* Older fileservers can return a negative length when they
+                     * meant to return 0; just assume negative lengths were
+                     * meant to be 0 lengths. */
+                    *alength = 0;
+                }
            } else {
-               code = rx_Error(v->call);
-                code1 = rx_EndCall(v->call, code);
+                code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
                v->call = NULL;
            }
        }
@@ -1015,17 +1057,21 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
         * requested. It shouldn't do that, and accepting that much data
         * can make us take up more cache space than we're supposed to,
         * so error. */
-       code = rx_Error(v->call);
+        static int warned;
+        if (!warned) {
+            warned = 1;
+            afs_warn("afs: Warning: FetchData64 returned more data than "
+                     "requested (requested %ld, got %ld); this should not "
+                     "happen! Aborting fetch request.\n",
+                     (long)size, (long)*alength);
+        }
        RX_AFS_GUNLOCK();
-       code1 = rx_EndCall(v->call, code);
+       code = rx_EndCall(v->call, RX_PROTOCOL_ERROR);
        RX_AFS_GLOCK();
        v->call = NULL;
        code = EIO;
     }
 
-    if (!code && code1)
-       code = code1;
-
     if (code) {
        osi_FreeSmallSpace(v);
         return code;
@@ -1060,7 +1106,8 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
  * Routine called on fetch; also tells people waiting for data
  *     that more has arrived.
  *
- * \param tc Ptr to the Rx connection structure.
+ * \param tc Ptr to the AFS connection structure.
+ * \param rxconn Ptr to the Rx connection structure.
  * \param fP File descriptor for the cache file.
  * \param base Base offset to fetch.
  * \param adc Ptr to the dcache entry for the file, write-locked.
@@ -1071,9 +1118,10 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
  * \note Environment: Nothing interesting.
  */
 int
-afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
-                   struct dcache *adc, struct vcache *avc, afs_int32 size,
-                   struct afs_FetchOutput *tsmall)
+afs_CacheFetchProc(struct afs_conn *tc, struct rx_connection *rxconn,
+                   struct osi_file *fP, afs_size_t base,
+                  struct dcache *adc, struct vcache *avc, afs_int32 size,
+                  struct afs_FetchOutput *tsmall)
 {
     afs_int32 code;
     afs_int32 length;
@@ -1100,15 +1148,13 @@ afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
      * adc->lock(W)
      */
     code = rxfs_fetchInit(
-               tc, avc, base, size, &length, adc, fP, &ops, &rock);
+               tc, rxconn, avc, base, size, &length, adc, fP, &ops, &rock);
 
 #ifndef AFS_NOSTATS
     osi_GetuTime(&xferStartTime);
 #endif /* AFS_NOSTATS */
 
-    if (adc) {
-       adc->validPos = base;
-    }
+    adc->validPos = base;
 
     if ( !code ) do {
        if (avc->f.states & CForeign) {
@@ -1157,10 +1203,10 @@ afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
     if (!code)
        code = (*ops->close)(rock, avc, adc, tsmall);
     if (ops)
-       (*ops->destroy)(&rock, code);
+       code = (*ops->destroy)(&rock, code);
 
 #ifndef AFS_NOSTATS
-    FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,
+    FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, xferStartTime,
                        bytesToXfer, bytesXferred);
 #endif
     XSTATS_END_TIME;