libafs: crash in a more useful way if nchunks is zero
[openafs.git] / src / afs / afs_fetchstore.c
index 5dcbc1a..16c0550 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))) {
@@ -93,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);
@@ -362,7 +361,8 @@ struct storeOps rxfs_storeMemOps = {
 };
 
 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)
 {
@@ -383,7 +383,7 @@ 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))
@@ -471,16 +471,19 @@ 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 +525,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)
@@ -583,6 +586,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]) {
@@ -627,12 +631,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,
@@ -647,7 +651,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));
 
@@ -896,7 +900,8 @@ struct fetchOps rxfs_fetchMemOps = {
 };
 
 afs_int32
-rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
+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)
 {
@@ -914,7 +919,7 @@ rxfs_fetchInit(struct afs_conn *tc, struct vcache *avc, afs_offs_t base,
     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
@@ -951,7 +956,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,
@@ -1055,7 +1060,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.
@@ -1066,7 +1072,8 @@ 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,
+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)
 {
@@ -1095,7 +1102,7 @@ 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);
@@ -1155,7 +1162,7 @@ afs_CacheFetchProc(struct afs_conn *tc, struct osi_file *fP, afs_size_t base,
        (*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;