Initialize xferStartTime for StoreData timings
[openafs.git] / src / afs / afs_fetchstore.c
index 959b39e..5688449 100644 (file)
 
 extern int cacheDiskType;
 
+
+#ifndef AFS_NOSTATS
+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;
+    XSTATS_DECLS;
+
+    xferP = &(afs_stats_cmfullperf.rpc.fsXferTimes[idx]);
+    osi_GetuTime(&xferStopTime);
+    (xferP->numXfers)++;
+    if (!code) {
+       (xferP->numSuccesses)++;
+       afs_stats_XferSumBytes[idx] += bytesXferred;
+       (xferP->sumBytes) += (afs_stats_XferSumBytes[idx] >> 10);
+       afs_stats_XferSumBytes[idx] &= 0x3FF;
+       if (bytesXferred < xferP->minBytes)
+           xferP->minBytes = bytesXferred;
+       if (bytesXferred > xferP->maxBytes)
+           xferP->maxBytes = bytesXferred;
+
+       /*
+        * Tally the size of the object.  Note: we tally the actual size,
+        * NOT the number of bytes that made it out over the wire.
+        */
+       if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0) (xferP->count[0])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1) (xferP->count[1])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2) (xferP->count[2])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3) (xferP->count[3])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4) (xferP->count[4])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5) (xferP->count[5])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6) (xferP->count[6])++;
+       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7) (xferP->count[7])++;
+       else
+           (xferP->count[8])++;
+
+       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))) {
+           afs_stats_TimeAssign((xferP->minTime), elapsedTime);
+       }
+       if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
+           afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
+       }
+    }
+}
+#endif /* AFS_NOSTATS */
+
 /* rock and operations for RX_FILESERVER */
 
 struct rxfs_storeVariables {
@@ -142,6 +193,30 @@ rxfs_storeUfsWrite(void *r, afs_uint32 l, afs_uint32 *byteswritten)
 }
 
 afs_int32
+rxfs_storePadd(void *rock, afs_uint32 size)
+{
+    afs_int32 code = 0;
+    int bsent, tlen;
+    struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
+
+    if ( !v->tbuffer )
+       v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
+    memset(v->tbuffer, 0, AFS_LRALLOCSIZ);
+
+    while (size > 0) {
+       tlen = (size > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : size);
+       RX_AFS_GUNLOCK();
+       code = rx_Write(v->call, v->tbuffer, tlen);
+       RX_AFS_GLOCK();
+
+       if (code != tlen)
+           return -33; /* XXX */
+       size -= tlen;
+    }
+    return code;
+}
+
+afs_int32
 rxfs_storeStatus(void *rock)
 {
     struct rxfs_storeVariables *v = (struct rxfs_storeVariables *)rock;
@@ -196,6 +271,7 @@ struct storeOps rxfs_storeUfsOps = {
     rxfs_storeUfsRead,
     rxfs_storeUfsWrite,
     rxfs_storeStatus,
+    rxfs_storePadd,
     rxfs_storeClose,
     rxfs_storeDestroy
 };
@@ -206,6 +282,7 @@ struct storeOps rxfs_storeMemOps = {
     rxfs_storeMemRead,
     rxfs_storeMemWrite,
     rxfs_storeStatus,
+    rxfs_storePadd,
     rxfs_storeClose,
     rxfs_storeDestroy
 };
@@ -318,9 +395,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
     afs_int32 code = 0;
 
 #ifndef AFS_NOSTATS
-    struct afs_stats_xferData *xferP;  /* Ptr to this op's xfer struct */
-    osi_timeval_t xferStartTime,       /*FS xfer start time */
-      xferStopTime;                    /*FS xfer stop time */
+    osi_timeval_t xferStartTime;       /*FS xfer start time */
     afs_size_t bytesToXfer = 10000;    /* # bytes to xfer */
     afs_size_t bytesXferred = 10000;   /* # bytes actually xferred */
 #endif /* AFS_NOSTATS */
@@ -367,9 +442,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
        bytesToXfer = alen;
        bytesXferred = 0;
 
-       xferP = &(afs_stats_cmfullperf.rpc.
-                       fsXferTimes[AFS_STATS_FS_XFERIDX_STOREDATA]);
-       osi_GetuTime(&xferStartTime);
+       GetuTime(&xferStartTime);
 #endif /* AFS_NOSTATS */
 
        while ( alen > 0 ) {
@@ -407,51 +480,8 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
                    ICL_HANDLE_OFFSET(avc->f.m.Length), ICL_TYPE_INT32, alen);
 
 #ifndef AFS_NOSTATS
-       osi_GetuTime(&xferStopTime);
-       (xferP->numXfers)++;
-       if (!code) {
-           (xferP->numSuccesses)++;
-           afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] +=
-               bytesXferred;
-           (xferP->sumBytes) +=
-               (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] >> 10);
-           afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_STOREDATA] &= 0x3FF;
-           if (bytesXferred < xferP->minBytes)
-               xferP->minBytes = bytesXferred;
-           if (bytesXferred > xferP->maxBytes)
-               xferP->maxBytes = bytesXferred;
-
-           /*
-            * Tally the size of the object.  Note: we tally the actual size,
-            * NOT the number of bytes that made it out over the wire.
-            */
-           if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0)
-               (xferP->count[0])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1)
-               (xferP->count[1])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2)
-               (xferP->count[2])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3)
-               (xferP->count[3])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4)
-               (xferP->count[4])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5)
-               (xferP->count[5])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6)
-               (xferP->count[6])++;
-           else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7)
-               (xferP->count[7])++;
-           else
-               (xferP->count[8])++;
-
-           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)))
-               afs_stats_TimeAssign((xferP->minTime), elapsedTime);
-           if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime)))
-               afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
-       }
+       FillStoreStats(code, AFS_STATS_FS_XFERIDX_STOREDATA,
+                   &xferStartTime, bytesToXfer, bytesXferred);
 #endif /* AFS_NOSTATS */
 
        afs_CFileClose(fP);
@@ -513,15 +543,11 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
  * \note Environment: Nothing interesting.
  */
 int
-afs_CacheStoreVCache(struct dcache **dcList,
-                       struct vcache *avc,
-                       struct vrequest *areq,
-                       int sync,
-                       unsigned int minj,
-                       unsigned int high,
+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)
+                       afs_hyper_t *anewDV, afs_size_t *amaxStoredLength)
 {
     afs_int32 code = 0;
     struct storeOps *ops;
@@ -832,7 +858,7 @@ struct fetchOps rxfs_fetchMemOps = {
 
 afs_int32
 rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
-               afs_uint32 size, afs_uint32 *out_length, struct dcache *adc,
+               afs_uint32 size, afs_uint32 *alength, struct dcache *adc,
                struct osi_file *fP, struct fetchOps **ops, void **rock)
 {
     struct rxfs_fetchVariables *v;
@@ -888,9 +914,8 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
            if (!v->call)
                v->call = rx_NewCall(tc->id);
            code =
-               StartRXAFS_FetchData(v->call, (struct AFSFid *)
-                                    &avc->f.fid.Fid, pos,
-                                    size);
+               StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
+                                       pos, size);
            RX_AFS_GLOCK();
        }
        afs_serverSetNo64Bit(tc);
@@ -930,7 +955,7 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
         return code;
     }
 
-    if ( cacheDiskType == AFS_FCACHE_TYPE_UFS ) {
+    if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
        v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
        if (!v->tbuffer)
            osi_Panic("rxfs_fetchInit: osi_AllocLargeSpace for iovecs returned NULL\n");
@@ -946,14 +971,13 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
         * We need to alloc the iovecs on the heap so that they are "pinned"
         * rather than declare them on the stack - defect 11272
         */
-       v->iov = (struct iovec *)osi_AllocSmallSpace(sizeof(struct iovec) *
-                                               RX_MAXIOVECS);
+       v->iov = osi_AllocSmallSpace(sizeof(struct iovec) * RX_MAXIOVECS);
        if (!v->iov)
-           osi_Panic("afs_CacheFetchProc: osi_AllocSmallSpace for iovecs returned NULL\n");
+           osi_Panic("rxfs_fetchInit: osi_AllocSmallSpace for iovecs returned NULL\n");
        *ops = (struct fetchOps *) &rxfs_fetchMemOps;
     }
     *rock = (void *)v;
-    *out_length = length;
+    *alength = length;
     return 0;
 }
 
@@ -989,9 +1013,7 @@ afs_CacheFetchProc(register struct afs_conn *tc,
 
     XSTATS_DECLS;
 #ifndef AFS_NOSTATS
-    struct afs_stats_xferData *xferP;  /* Ptr to this op's xfer struct */
-    osi_timeval_t xferStartTime,       /*FS xfer start time */
-                   xferStopTime;       /*FS xfer stop time */
+    osi_timeval_t xferStartTime;       /*FS xfer start time */
     afs_size_t bytesToXfer = 0, bytesXferred = 0;
 #endif
 
@@ -1002,8 +1024,6 @@ afs_CacheFetchProc(register struct afs_conn *tc,
     code = rxfs_fetchInit(tc, avc, abase, size, &length, adc, fP, &ops, &rock);
 
 #ifndef AFS_NOSTATS
-    xferP =
-       &(afs_stats_cmfullperf.rpc.fsXferTimes[AFS_STATS_FS_XFERIDX_FETCHDATA]);
     osi_GetuTime(&xferStartTime);
 #endif /* AFS_NOSTATS */
 
@@ -1073,52 +1093,8 @@ afs_CacheFetchProc(register struct afs_conn *tc,
     (*ops->destroy)(&rock, code);
 
 #ifndef AFS_NOSTATS
-    osi_GetuTime(&xferStopTime);
-    (xferP->numXfers)++;
-    if (!code) {
-       (xferP->numSuccesses)++;
-       afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] += bytesXferred;
-       (xferP->sumBytes) +=
-               (afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] >> 10);
-       afs_stats_XferSumBytes[AFS_STATS_FS_XFERIDX_FETCHDATA] &= 0x3FF;
-       if (bytesXferred < xferP->minBytes)
-           xferP->minBytes = bytesXferred;
-       if (bytesXferred > xferP->maxBytes)
-           xferP->maxBytes = bytesXferred;
-
-       /*
-        * Tally the size of the object.  Note: we tally the actual size,
-        * NOT the number of bytes that made it out over the wire.
-        */
-       if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET0)
-           (xferP->count[0])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET1)
-           (xferP->count[1])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET2)
-           (xferP->count[2])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET3)
-           (xferP->count[3])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET4)
-           (xferP->count[4])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET5)
-           (xferP->count[5])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET6)
-           (xferP->count[6])++;
-       else if (bytesToXfer <= AFS_STATS_MAXBYTES_BUCKET7)
-           (xferP->count[7])++;
-       else
-           (xferP->count[8])++;
-
-       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))) {
-           afs_stats_TimeAssign((xferP->minTime), elapsedTime);
-       }
-       if (afs_stats_TimeGreaterThan(elapsedTime, (xferP->maxTime))) {
-           afs_stats_TimeAssign((xferP->maxTime), elapsedTime);
-       }
-    }
+    FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA,&xferStartTime,
+                       bytesToXfer, bytesXferred);
 #endif
     XSTATS_END_TIME;
     return code;