regain glock on storedata error exit
[openafs.git] / src / afs / afs_segments.c
index d124a86..e673030 100644 (file)
@@ -35,14 +35,14 @@ afs_uint32 afs_stampValue = 0;
  *     We're write-locked upon entry.
  */
 
-int
+static int
 afs_StoreMini(register struct vcache *avc, struct vrequest *areq)
 {
     register struct afs_conn *tc;
     struct AFSStoreStatus InStatus;
     struct AFSFetchStatus OutStatus;
     struct AFSVolSync tsync;
-    register afs_int32 code;
+    register afs_int32 code, code2;
     register struct rx_call *tcall;
     afs_size_t tlen, xlen = 0;
     XSTATS_DECLS;
@@ -94,8 +94,10 @@ afs_StoreMini(register struct vcache *avc, struct vrequest *areq)
                l2 = tlen;
                if ((avc->f.m.Length > 0x7fffffff) ||
                    (tlen > 0x7fffffff) ||
-                   ((0x7fffffff - tlen) < avc->f.m.Length))
+                   ((0x7fffffff - tlen) < avc->f.m.Length)) {
+                   RX_AFS_GLOCK();
                    return EFBIG;
+               }
                code =
                    StartRXAFS_StoreData(tcall,
                                         (struct AFSFid *)&avc->f.fid.Fid,
@@ -109,7 +111,9 @@ afs_StoreMini(register struct vcache *avc, struct vrequest *areq)
            if (code == 0) {
                code = EndRXAFS_StoreData(tcall, &OutStatus, &tsync);
            }
-           code = rx_EndCall(tcall, code);
+           code2 = rx_EndCall(tcall, code);
+           if (code2 && !code)
+               code = code2;
            RX_AFS_GLOCK();
            XSTATS_END_TIME;
 #ifdef AFS_64BIT_CLIENT
@@ -124,14 +128,10 @@ afs_StoreMini(register struct vcache *avc, struct vrequest *areq)
             (tc, code, &avc->f.fid, areq, AFS_STATS_FS_RPCIDX_STOREDATA,
              SHARED_LOCK, NULL));
 
-    if (code == 0) {
+    if (code == 0)
        afs_ProcessFS(avc, &OutStatus, areq);
-    } else {
-       /* blew it away */
-       afs_InvalidateAllSegments(avc);
-    }
-    return code;
 
+    return code;
 }                              /*afs_StoreMini */
 
 /*
@@ -169,7 +169,7 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
     unsigned int i, j, minj, moredata, high, off;
     afs_size_t tlen;
     afs_size_t maxStoredLength;        /* highest offset we've written to server. */
-    int safety;
+    int safety, marineronce = 0;
 
     AFS_STATCNT(afs_StoreAllSegments);
 
@@ -238,13 +238,13 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
     minj = 0;
 
     do {
-       memset((char *)dcList, 0, NCHUNKSATONCE * sizeof(struct dcache *));
+       memset(dcList, 0, NCHUNKSATONCE * sizeof(struct dcache *));
        high = 0;
        moredata = FALSE;
 
        /* lock and start over from beginning of hash chain 
         * in order to avoid a race condition. */
-       MObtainWriteLock(&afs_xdcache, 284);
+       ObtainWriteLock(&afs_xdcache, 284);
        index = afs_dvhashTbl[hash];
 
        for (j = 0; index != NULLIDX;) {
@@ -257,6 +257,11 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
                    if (off < NCHUNKSATONCE) {
                        if (dcList[off])
                            osi_Panic("dclist slot already in use!");
+                       if (afs_mariner && !marineronce) {
+                           /* first chunk only */
+                           afs_MarinerLog("store$Storing", avc);
+                           marineronce++;
+                       }
                        dcList[off] = tdc;
                        if (off > high)
                            high = off;
@@ -282,7 +287,7 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
            }
            index = afs_dvnextTbl[index];
        }
-       MReleaseWriteLock(&afs_xdcache);
+       ReleaseWriteLock(&afs_xdcache);
 
        /* this guy writes chunks, puts back dcache structs, and bumps newDV */
        /* "moredata" just says "there are more dirty chunks yet to come".
@@ -339,11 +344,11 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
 
        do {
            moredata = FALSE;
-           memset((char *)dcList, 0,
+           memset(dcList, 0,
                   NCHUNKSATONCE * sizeof(struct dcache *));
 
            /* overkill, but it gets the lock in case GetDSlot needs it */
-           MObtainWriteLock(&afs_xdcache, 285);
+           ObtainWriteLock(&afs_xdcache, 285);
 
            for (j = 0, safety = 0, index = afs_dvhashTbl[hash];
                 index != NULLIDX && safety < afs_cacheFiles + 2;) {
@@ -374,7 +379,7 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
 
                index = afs_dvnextTbl[index];
            }
-           MReleaseWriteLock(&afs_xdcache);
+           ReleaseWriteLock(&afs_xdcache);
 
            for (i = 0; i < j; i++) {
                /* Iterate over the dcache entries we collected above */
@@ -424,7 +429,7 @@ afs_StoreAllSegments(register struct vcache *avc, struct vrequest *areq,
         * invalidated. Also discard data if it's a permanent error from the
         * fileserver.
         */
-       if (areq->permWriteError || (avc->f.states & (CCore1 | CCore))) {
+       if (areq->permWriteError || (avc->f.states & CCore)) {
            afs_InvalidateAllSegments(avc);
        }
     }
@@ -502,13 +507,13 @@ afs_InvalidateAllSegments(struct vcache *avc)
     /* Blow away pages; for now, only for Solaris */
 #if    (defined(AFS_SUN5_ENV))
     if (WriteLocked(&avc->lock))
-       osi_ReleaseVM(avc, (struct AFS_UCRED *)0);
+       osi_ReleaseVM(avc, (afs_ucred_t *)0);
 #endif
     /*
      * Block out others from screwing with this table; is a read lock
      * sufficient?
      */
-    MObtainWriteLock(&afs_xdcache, 286);
+    ObtainWriteLock(&afs_xdcache, 286);
     dcListMax = 0;
 
     for (index = afs_dvhashTbl[hash]; index != NULLIDX;) {
@@ -547,7 +552,7 @@ afs_InvalidateAllSegments(struct vcache *avc)
        }
        index = afs_dvnextTbl[index];
     }
-    MReleaseWriteLock(&afs_xdcache);
+    ReleaseWriteLock(&afs_xdcache);
 
     for (i = 0; i < dcListCount; i++) {
        tdc = dcList[i];
@@ -641,12 +646,12 @@ afs_ExtendSegments(struct vcache *avc, afs_size_t alen, struct vrequest *areq) {
  */
 int
 afs_TruncateAllSegments(register struct vcache *avc, afs_size_t alen,
-                       struct vrequest *areq, struct AFS_UCRED *acred)
+                       struct vrequest *areq, afs_ucred_t *acred)
 {
     register struct dcache *tdc;
     register afs_int32 code;
     register afs_int32 index;
-    afs_int32 newSize;
+    afs_size_t newSize;
 
     int dcCount, dcPos;
     struct dcache **tdcArray;
@@ -699,7 +704,7 @@ afs_TruncateAllSegments(register struct vcache *avc, afs_size_t alen,
     code = DVHash(&avc->f.fid);
 
     /* block out others from screwing with this table */
-    MObtainWriteLock(&afs_xdcache, 287);
+    ObtainWriteLock(&afs_xdcache, 287);
 
     dcCount = 0;
     for (index = afs_dvhashTbl[code]; index != NULLIDX;) {
@@ -738,7 +743,7 @@ afs_TruncateAllSegments(register struct vcache *avc, afs_size_t alen,
        index = afs_dvnextTbl[index];
     }
 
-    MReleaseWriteLock(&afs_xdcache);
+    ReleaseWriteLock(&afs_xdcache);
 
     /* Now we loop over the array of dcache entries and truncate them */
     for (index = 0; index < dcPos; index++) {
@@ -750,12 +755,12 @@ afs_TruncateAllSegments(register struct vcache *avc, afs_size_t alen,
        if (newSize < 0)
            newSize = 0;
        ObtainSharedLock(&tdc->lock, 672);
-       if (newSize < tdc->f.chunkBytes) {
+       if (newSize < tdc->f.chunkBytes && newSize < MAX_AFS_UINT32) {
            UpgradeSToWLock(&tdc->lock, 673);
            tfile = afs_CFileOpen(&tdc->f.inode);
-           afs_CFileTruncate(tfile, newSize);
+           afs_CFileTruncate(tfile, (afs_int32)newSize);
            afs_CFileClose(tfile);
-           afs_AdjustSize(tdc, newSize);
+           afs_AdjustSize(tdc, (afs_int32)newSize);
            if (alen < tdc->validPos) {
                 if (alen < AFS_CHUNKTOBASE(tdc->f.chunk))
                     tdc->validPos = 0;