Attempt to fix CForeign moredata behaviour
[openafs.git] / src / afs / afs_fetchstore.c
index 5e61355..bd6f47c 100644 (file)
@@ -494,24 +494,7 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
        afs_CFileClose(tfile);
        if ((tdc->f.chunkBytes < afs_OtherCSize)
                && (i < (nchunks - 1)) && code == 0) {
-           int bsent, tlen, sbytes = afs_OtherCSize - tdc->f.chunkBytes;
-           char *tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
-
-           while (sbytes > 0) {
-               tlen = (sbytes > AFS_LRALLOCSIZ ? AFS_LRALLOCSIZ : sbytes);
-               memset(tbuffer, 0, tlen);
-               RX_AFS_GUNLOCK();
-               bsent = rx_Write(
-                       ((struct rxfs_storeVariables*)rock)->call, tbuffer, tlen);
-               RX_AFS_GLOCK();
-
-               if (bsent != tlen) {
-                   code = -33; /* XXX */
-                   break;
-               }
-               sbytes -= tlen;
-           }
-           osi_FreeLargeSpace(tbuffer);
+           code = (*ops->padd)(rock, afs_OtherCSize - tdc->f.chunkBytes);
        }
        stored += tdc->f.chunkBytes;
        /* ideally, I'd like to unlock the dcache and turn
@@ -529,7 +512,8 @@ afs_CacheStoreDCaches(struct vcache *avc, struct dcache **dclist,
        }
        XSTATS_END_TIME;
     }
-    code = (*ops->destroy)(&rock, code);
+    if (ops)
+       code = (*ops->destroy)(&rock, code);
     return code;
 }
 
@@ -561,7 +545,6 @@ afs_CacheStoreVCache(struct dcache **dcList, struct vcache *avc,
     void * rock = NULL;
     unsigned int i, j;
 
-    struct AFSStoreStatus InStatus;
     struct AFSFetchStatus OutStatus;
     int doProcessFS = 0;
     afs_size_t base, bytes, length;
@@ -836,11 +819,10 @@ rxfs_fetchDestroy(void **r, afs_int32 error)
 }
 
 afs_int32
-rxfs_fetchMore(void *r, afs_uint32 *length, afs_uint32 *moredata)
+rxfs_fetchMore(void *r, afs_int32 *length, afs_uint32 *moredata)
 {
     afs_int32 code;
-    register struct rxfs_fetchVariables *v
-           = (struct rxfs_fetchVariables *)r;
+    struct rxfs_fetchVariables *v = (struct rxfs_fetchVariables *)r;
 
     /*
      * The fetch protocol is extended for the AFS/DFS translator
@@ -851,14 +833,16 @@ rxfs_fetchMore(void *r, afs_uint32 *length, afs_uint32 *moredata)
      * We do not do this for AFS file servers because they sometimes
      * return large negative numbers as the transfer size.
      */
-    RX_AFS_GUNLOCK();
-    code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
-    RX_AFS_GLOCK();
-    *length = ntohl(*length);
-    if (code != sizeof(afs_int32)) {
-       code = rx_Error(v->call);
-       *moredata = 0;
-       return (code ? code : -1);      /* try to return code, not -1 */
+    if (*moredata) {
+       RX_AFS_GUNLOCK();
+       code = rx_Read(v->call, (void *)length, sizeof(afs_int32));
+       RX_AFS_GLOCK();
+       *length = ntohl(*length);
+       if (code != sizeof(afs_int32)) {
+           code = rx_Error(v->call);
+           *moredata = 0;
+           return (code ? code : -1);  /* try to return code, not -1 */
+        }
     }
     *moredata = *length & 0x80000000;
     *length &= ~0x80000000;
@@ -884,9 +868,8 @@ 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 *alength, afs_uint32 *moredata,
-               struct dcache *adc,
+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)
 {
     struct rxfs_fetchVariables *v;
@@ -963,7 +946,7 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
                   ICL_TYPE_POINTER, avc, ICL_TYPE_INT32, code,
                   ICL_TYPE_OFFSET,
                   ICL_HANDLE_OFFSET(length64));
-       *alength = length64;
+       *alength = length;
 #else /* AFS_64BIT_CLIENT */
        RX_AFS_GUNLOCK();
        code = StartRXAFS_FetchData(v->call, (struct AFSFid *)&avc->f.fid.Fid,
@@ -989,22 +972,6 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
        osi_FreeSmallSpace(v);
         return code;
     }
-    /*
-     * The fetch protocol is extended for the AFS/DFS translator
-     * to allow multiple blocks of data, each with its own length,
-     * to be returned. As long as the top bit is set, there are more
-     * blocks expected.
-     *
-     * We do not do this for AFS file servers because they sometimes
-     * return large negative numbers as the transfer size.
-     *
-     * Also omit if length > 2^32, as bit 31 is part of the number then.
-     * Known to never be the case ifndef AFS_64BIT_CLIENT.
-     */
-    if (avc->f.states & CForeign && !length_hi) {
-       *moredata = length & 0x80000000;
-       length &= ~0x80000000;
-    }
     if (cacheDiskType == AFS_FCACHE_TYPE_UFS) {
        v->tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
        if (!v->tbuffer)
@@ -1046,19 +1013,17 @@ rxfs_fetchInit(register struct afs_conn *tc, struct vcache *avc,afs_offs_t base,
  * \note Environment: Nothing interesting.
  */
 int
-afs_CacheFetchProc(register struct afs_conn *tc,
-                   register struct osi_file *fP, afs_size_t base,
-                   struct dcache *adc, struct vcache *avc,
-                   afs_int32 size,
+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)
 {
-    register afs_int32 code;
-    afs_uint32 length;
+    afs_int32 code;
+    afs_int32 length;
     afs_uint32 bytesread, byteswritten;
     struct fetchOps *ops = NULL;
     void *rock = NULL;
     int moredata = 0;
-    register int offset = 0;
+    int offset = 0;
 
     XSTATS_DECLS;
 #ifndef AFS_NOSTATS
@@ -1077,7 +1042,7 @@ afs_CacheFetchProc(register struct afs_conn *tc,
      * adc->lock(W)
      */
     code = rxfs_fetchInit(
-               tc, avc, base, size, &length, &moredata, adc, fP, &ops, &rock);
+               tc, avc, base, size, &length, adc, fP, &ops, &rock);
 
 #ifndef AFS_NOSTATS
     osi_GetuTime(&xferStartTime);
@@ -1088,7 +1053,7 @@ afs_CacheFetchProc(register struct afs_conn *tc,
     }
 
     if ( !code ) do {
-       if ((avc->f.states & CForeign) && moredata && !length) {
+       if (avc->f.states & CForeign) {
            code = (*ops->more)(rock, &length, &moredata);
            if ( code )
                break;
@@ -1096,7 +1061,7 @@ afs_CacheFetchProc(register struct afs_conn *tc,
 #ifndef AFS_NOSTATS
        bytesToXfer += length;
 #endif /* AFS_NOSTATS */
-       while (length) {
+       while (length > 0) {
 #ifdef RX_KERNEL_TRACE
            afs_Trace1(afs_iclSetp, CM_TRACE_TIMESTAMP, ICL_TYPE_STRING,
                       "before rx_Read");
@@ -1133,7 +1098,8 @@ afs_CacheFetchProc(register struct afs_conn *tc,
     } while (moredata);
     if (!code)
        code = (*ops->close)(rock, avc, adc, tsmall);
-    (*ops->destroy)(&rock, code);
+    if (ops)
+       (*ops->destroy)(&rock, code);
 
 #ifndef AFS_NOSTATS
     FillStoreStats(code, AFS_STATS_FS_XFERIDX_FETCHDATA, &xferStartTime,