Bug 617123 - Images are randomly corrupted with fallocate. r=jduell
authorMichal Novotny <michal.novotny@gmail.com>
Wed, 12 Jan 2011 04:38:12 +0200
changeset 67724 473ec8c05215f2ed6c1dd8e4c1084cb680cc7a68
parent 67723 33a01f08bbf31dc9a3fabe7341b90d66523417ca
child 67725 ab290352e31698ddee5f352031157e6edb86edba
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs617123
milestone2.2a1pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 617123 - Images are randomly corrupted with fallocate. r=jduell
netwerk/cache/nsDiskCacheStreams.cpp
--- a/netwerk/cache/nsDiskCacheStreams.cpp
+++ b/netwerk/cache/nsDiskCacheStreams.cpp
@@ -143,29 +143,29 @@ nsDiskCacheInputStream::Read(char * buff
     *bytesRead = 0;
 
     if (mClosed)
         return NS_OK;
     
     if (mPos == mStreamEnd)  return NS_OK;
     if (mPos > mStreamEnd)   return NS_ERROR_UNEXPECTED;
     
+    if (count > mStreamEnd - mPos)
+        count = mStreamEnd - mPos;
+
     if (mFD) {
         // just read from file
         PRInt32  result = PR_Read(mFD, buffer, count);
         if (result < 0)  return  NS_ErrorAccordingToNSPR();
         
         mPos += (PRUint32)result;
         *bytesRead = (PRUint32)result;
         
     } else if (mBuffer) {
         // read data from mBuffer
-        if (count > mStreamEnd - mPos)
-            count = mStreamEnd - mPos;
-    
         memcpy(buffer, mBuffer + mPos, count);
         mPos += count;
         *bytesRead = count;
     } else {
         // no data source for input stream
     }
 
     return NS_OK;
@@ -752,22 +752,19 @@ nsDiskCacheStreamIO::FlushBufferToFile()
             if (NS_FAILED(rv))  return rv;
         }
         record->SetDataFileGeneration(mBinding->mGeneration);
         
         // allocate file
         rv = OpenCacheFile(PR_RDWR | PR_CREATE_FILE, &mFD);
         if (NS_FAILED(rv))  return rv;
 
-#if 0
         PRInt64 dataSize = mBinding->mCacheEntry->PredictedDataSize();
-// Appears to cause bug 617123?  Disabled for now.
         if (dataSize != -1)
             mozilla::fallocate(mFD, PR_MIN(dataSize, kPreallocateLimit));
-#endif
     }
     
     // write buffer
     PRInt32 bytesWritten = PR_Write(mFD, mBuffer, mBufEnd);
     if (PRUint32(bytesWritten) != mBufEnd) {
         NS_WARNING("failed to flush all data");
         return NS_ERROR_UNEXPECTED;     // NS_ErrorAccordingToNSPR()
     }