afs_fetchstore: avoid use of uninitialized variable
[openafs.git] / src / afs / afs_fetchstore.c
index 0f794f3..8db6697 100644 (file)
@@ -27,8 +27,8 @@
 extern int cacheDiskType;
 
 #ifndef AFS_NOSTATS
-void
-FillStoreStats(int code, int idx, osi_timeval_t *xferStartTime,
+static void
+FillStoreStats(int code, int idx, osi_timeval_t xferStartTime,
               afs_size_t bytesToXfer, afs_size_t bytesXferred)
 {
     struct afs_stats_xferData *xferP;
@@ -63,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))) {
@@ -372,7 +372,7 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc,
     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));
@@ -388,9 +388,9 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc,
 #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 +399,8 @@ rxfs_storeInit(struct vcache *avc, struct afs_conn *tc,
                                        (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);
@@ -463,6 +465,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
 {
     int *shouldwake = NULL;
     unsigned int i;
+    int stored = 0;
     afs_int32 code = 0;
     afs_size_t bytesXferred;
 
@@ -471,16 +474,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));
@@ -522,7 +527,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)
@@ -540,6 +545,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);
        }
@@ -547,6 +553,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;
 }
 
@@ -961,8 +972,11 @@ rxfs_fetchInit(struct afs_conn *tc, struct rx_connection *rxconn,
                RX_AFS_GLOCK();
            }
            afs_serverSetNo64Bit(tc);
+           v->hasNo64bit = 1;
        }
-       if (!code) {
+       if (code) {
+           goto err;
+       } else {
            RX_AFS_GUNLOCK();
            bytes = rx_Read(v->call, (char *)&length, sizeof(afs_int32));
            RX_AFS_GLOCK();
@@ -1020,6 +1034,7 @@ rxfs_fetchInit(struct afs_conn *tc, struct rx_connection *rxconn,
        code = EIO;
     }
 
+err:
     if (!code && code1)
        code = code1;
 
@@ -1105,9 +1120,7 @@ afs_CacheFetchProc(struct afs_conn *tc, struct rx_connection *rxconn,
     osi_GetuTime(&xferStartTime);
 #endif /* AFS_NOSTATS */
 
-    if (adc) {
-       adc->validPos = base;
-    }
+    adc->validPos = base;
 
     if ( !code ) do {
        if (avc->f.states & CForeign) {
@@ -1159,7 +1172,7 @@ afs_CacheFetchProc(struct afs_conn *tc, struct rx_connection *rxconn,
        (*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;