Bug 1130784 - FAT32 file create limit code is using a bad error number, r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 12 Feb 2015 11:28:50 +0100
changeset 228801 614eb0ebe557640cdb67f6f8581e4dee5592594b
parent 228800 f310a80db30d0a3d901f1e09c5fa0dc5af68597b
child 228802 11b4c8d470ab28a5298496d5b0b06c1545c9cd68
push id55529
push usermnovotny@mozilla.com
push dateThu, 12 Feb 2015 10:29:00 +0000
treeherdermozilla-inbound@614eb0ebe557 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1130784
milestone38.0a1
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 1130784 - FAT32 file create limit code is using a bad error number, r=honzab
netwerk/cache2/CacheFileIOManager.cpp
netwerk/cache2/CacheIndex.cpp
netwerk/cache2/CacheIndex.h
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -2607,17 +2607,17 @@ CacheFileIOManager::OverLimitEvictionInt
            "for higher level events."));
       mOverLimitEvicting = true;
       return NS_OK;
     }
 
     SHA1Sum::Hash hash;
     uint32_t cnt;
     static uint32_t consecutiveFailures = 0;
-    rv = CacheIndex::GetEntryForEviction(&hash, &cnt);
+    rv = CacheIndex::GetEntryForEviction(false, &hash, &cnt);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = DoomFileByKeyInternal(&hash, true);
     if (NS_SUCCEEDED(rv)) {
       consecutiveFailures = 0;
     } else if (rv == NS_ERROR_NOT_AVAILABLE) {
       LOG(("CacheFileIOManager::OverLimitEvictionInternal() - "
            "DoomFileByKeyInternal() failed. [rv=0x%08x]", rv));
@@ -3595,25 +3595,26 @@ CacheFileIOManager::OpenNSPRHandle(Cache
     // close handle that hasn't been used for the longest time
     rv = ReleaseNSPRHandleInternal(mHandlesByLastUsed[0]);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aCreate) {
     rv = aHandle->mFile->OpenNSPRFileDesc(
            PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0600, &aHandle->mFD);
-    if (rv == NS_ERROR_FILE_NO_DEVICE_SPACE) {
+    if (rv == NS_ERROR_FILE_ALREADY_EXISTS ||  // error from nsLocalFileWin
+        rv == NS_ERROR_FILE_NO_DEVICE_SPACE) { // error from nsLocalFileUnix
       LOG(("CacheFileIOManager::OpenNSPRHandle() - Cannot create a new file, we"
            " might reached a limit on FAT32. Will evict a single entry and try "
            "again. [hash=%08x%08x%08x%08x%08x]", LOGSHA1(aHandle->Hash())));
 
       SHA1Sum::Hash hash;
       uint32_t cnt;
 
-      rv = CacheIndex::GetEntryForEviction(&hash, &cnt);
+      rv = CacheIndex::GetEntryForEviction(true, &hash, &cnt);
       if (NS_SUCCEEDED(rv)) {
         rv = DoomFileByKeyInternal(&hash, true);
       }
       if (NS_SUCCEEDED(rv)) {
         rv = aHandle->mFile->OpenNSPRFileDesc(
                PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE, 0600, &aHandle->mFD);
         LOG(("CacheFileIOManager::OpenNSPRHandle() - Successfully evicted entry"
              " with hash %08x%08x%08x%08x%08x. %s to create the new file.",
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -1166,17 +1166,17 @@ CacheIndex::HasEntry(const nsACString &a
   }
 
   LOG(("CacheIndex::HasEntry() - result is %u", *_retval));
   return NS_OK;
 }
 
 // static
 nsresult
-CacheIndex::GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt)
+CacheIndex::GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash, uint32_t *aCnt)
 {
   LOG(("CacheIndex::GetEntryForEviction()"));
 
   nsRefPtr<CacheIndex> index = gInstance;
 
   if (!index)
     return NS_ERROR_NOT_INITIALIZED;
 
@@ -1199,21 +1199,27 @@ CacheIndex::GetEntryForEviction(SHA1Sum:
   uint32_t i = 0, j = 0;
   uint32_t now = PR_Now() / PR_USEC_PER_SEC;
 
   // find the first expired, non-forced valid entry
   for (i = 0; i < index->mExpirationArray.Length(); i++) {
     if (index->mExpirationArray[i]->mExpirationTime < now) {
       memcpy(&hash, &index->mExpirationArray[i]->mHash, sizeof(SHA1Sum::Hash));
 
-      if (!IsForcedValidEntry(&hash)) {
-        foundEntry = true;
-        break;
+      if (IsForcedValidEntry(&hash)) {
+        continue;
       }
 
+      if (aIgnoreEmptyEntries &&
+          !CacheIndexEntry::GetFileSize(index->mExpirationArray[i])) {
+        continue;
+      }
+
+      foundEntry = true;
+      break;
     } else {
       // all further entries have not expired yet
       break;
     }
   }
 
   if (foundEntry) {
     *aCnt = index->mExpirationArray.Length() - i;
@@ -1228,20 +1234,27 @@ CacheIndex::GetEntryForEviction(SHA1Sum:
     // check if we've already tried all the entries
     if (i == index->mExpirationArray.Length())
       return NS_ERROR_NOT_AVAILABLE;
 
     // find first non-forced valid entry with the lowest frecency
     for (j = 0; j < index->mFrecencyArray.Length(); j++) {
       memcpy(&hash, &index->mFrecencyArray[j]->mHash, sizeof(SHA1Sum::Hash));
 
-      if (!IsForcedValidEntry(&hash)) {
-        foundEntry = true;
-        break;
+      if (IsForcedValidEntry(&hash)) {
+        continue;
       }
+
+      if (aIgnoreEmptyEntries &&
+          !CacheIndexEntry::GetFileSize(index->mFrecencyArray[j])) {
+        continue;
+      }
+
+      foundEntry = true;
+      break;
     }
 
     if (!foundEntry)
       return NS_ERROR_NOT_AVAILABLE;
 
     // forced valid entries skipped in both arrays could overlap, just use max
     *aCnt = index->mFrecencyArray.Length() - std::max(i, j);
 
--- a/netwerk/cache2/CacheIndex.h
+++ b/netwerk/cache2/CacheIndex.h
@@ -636,17 +636,17 @@ public:
   // Returns status of the entry in index for the given key. It can be called
   // on any thread.
   static nsresult HasEntry(const nsACString &aKey, EntryStatus *_retval);
 
   // Returns a hash of the least important entry that should be evicted if the
   // cache size is over limit and also returns a total number of all entries in
   // the index minus the number of forced valid entries that we encounter
   // when searching (see below)
-  static nsresult GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt);
+  static nsresult GetEntryForEviction(bool aIgnoreEmptyEntries, SHA1Sum::Hash *aHash, uint32_t *aCnt);
 
   // Checks if a cache entry is currently forced valid. Used to prevent an entry
   // (that has been forced valid) from being evicted when the cache size reaches
   // its limit.
   static bool IsForcedValidEntry(const SHA1Sum::Hash *aHash);
 
   // Returns cache size in kB.
   static nsresult GetCacheSize(uint32_t *_retval);