From: Amos Jeffries Date: Fri, 1 Oct 2010 05:29:18 +0000 (-0600) Subject: Bug 3068: cache_dir capacity and usage overflows X-Git-Tag: take1~217 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6da430a4640e07dfae7ef7a4451acc2854817014;p=thirdparty%2Fsquid.git Bug 3068: cache_dir capacity and usage overflows Makes usage calculations use size_t instead of int and updates the relevant fields storing the cache_dir capacity and usage fields as well. This fixes Squid filling cache_dir with files >2GB in size. Also allows Squid to store more than 2TB of data total in one dir. --- diff --git a/src/SwapDir.h b/src/SwapDir.h index e4a6205d7b..a3930158b1 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -54,11 +54,9 @@ public: virtual int callback(); virtual void create(); - virtual StoreEntry * get - (const cache_key *); + virtual StoreEntry * get(const cache_key *); - virtual void get - (String const, STOREGETCLIENT, void * cbdata); + virtual void get(String const, STOREGETCLIENT, void * cbdata); virtual void init(); @@ -115,7 +113,7 @@ class SwapDir : public Store { public: - SwapDir(char const *aType) : theType (aType), cur_size (0), max_size(0), max_objsize (-1), cleanLog(NULL) { + SwapDir(char const *aType) : theType (aType), cur_size(0), max_size(0), max_objsize (-1), cleanLog(NULL) { fs.blksize = 1024; path = NULL; } @@ -127,11 +125,9 @@ public: /* official Store interface functions */ virtual void diskFull(); - virtual StoreEntry * get - (const cache_key *); + virtual StoreEntry * get(const cache_key *); - virtual void get - (String const, STOREGETCLIENT, void * cbdata); + virtual void get(String const, STOREGETCLIENT, void * cbdata); virtual size_t maxSize() const { return max_size;} @@ -157,8 +153,8 @@ private: char const *theType; public: - int cur_size; - int max_size; + size_t cur_size; + size_t max_size; char *path; int index; /* This entry's index into the swapDirs array */ int64_t max_objsize; diff --git a/src/fs/coss/store_dir_coss.cc b/src/fs/coss/store_dir_coss.cc index 64db7fe206..e3e2fe443c 100644 --- a/src/fs/coss/store_dir_coss.cc +++ b/src/fs/coss/store_dir_coss.cc @@ -997,10 +997,10 @@ void CossSwapDir::statfs(StoreEntry & sentry) const { storeAppendPrintf(&sentry, "\n"); - storeAppendPrintf(&sentry, "Maximum Size: %d KB\n", max_size); - storeAppendPrintf(&sentry, "Current Size: %d KB\n", cur_size); + storeAppendPrintf(&sentry, "Maximum Size: %Zu KB\n", max_size); + storeAppendPrintf(&sentry, "Current Size: %Zu KB\n", cur_size); storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n", - 100.0 * cur_size / max_size); + (100.0 * (double)cur_size / (double)max_size) ); storeAppendPrintf(&sentry, "Number of object collisions: %d\n", (int) numcollisions); #if 0 /* is this applicable? I Hope not .. */ @@ -1096,7 +1096,7 @@ CossSwapDir::reconfigure(int index, char *path) void CossSwapDir::dump(StoreEntry &entry)const { - storeAppendPrintf(&entry, " %d", max_size >> 10); + storeAppendPrintf(&entry, " %Zu", (max_size >> 10)); dumpOptions(&entry); } diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 51df97615c..cdd0259f56 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -72,15 +72,12 @@ UFSSwapDir::canStore(StoreEntry const &e)const void UFSSwapDir::parseSizeL1L2() { - int i; - int size; - - i = GetInteger(); - size = i << 10; /* Mbytes to kbytes */ - - if (size <= 0) + int i = GetInteger(); + if (i <= 0) fatal("UFSSwapDir::parseSizeL1L2: invalid size value"); + size_t size = i << 10; /* Mbytes to kbytes */ + /* just reconfigure it */ if (reconfiguring) { if (size == max_size) @@ -315,10 +312,10 @@ UFSSwapDir::statfs(StoreEntry & sentry) const int x; storeAppendPrintf(&sentry, "First level subdirectories: %d\n", l1); storeAppendPrintf(&sentry, "Second level subdirectories: %d\n", l2); - storeAppendPrintf(&sentry, "Maximum Size: %d KB\n", max_size); - storeAppendPrintf(&sentry, "Current Size: %d KB\n", cur_size); + storeAppendPrintf(&sentry, "Maximum Size: %Zu KB\n", max_size); + storeAppendPrintf(&sentry, "Current Size: %Zu KB\n", cur_size); storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n", - 100.0 * cur_size / max_size); + (double)(100.0 * cur_size) / (double)max_size); storeAppendPrintf(&sentry, "Filemap bits in use: %d of %d (%d%%)\n", map->n_files_in_map, map->max_n_files, Math::intPercent(map->n_files_in_map, map->max_n_files)); @@ -381,7 +378,7 @@ UFSSwapDir::maintain() walker = repl->PurgeInit(repl, max_scan); while (1) { - if (cur_size < (int) minSize()) /* cur_size should be unsigned */ + if (cur_size < minSize()) break; if (removed >= max_remove) @@ -1326,10 +1323,7 @@ UFSSwapDir::replacementRemove(StoreEntry * e) void UFSSwapDir::dump(StoreEntry & entry) const { - storeAppendPrintf(&entry, " %d %d %d", - max_size >> 10, - l1, - l2); + storeAppendPrintf(&entry, " %Zu %d %d", (max_size >> 10), l1, l2); dumpOptions(&entry); } diff --git a/src/store_dir.cc b/src/store_dir.cc index f95cab81f2..a6d220dbd4 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -344,8 +344,8 @@ StoreController::updateSize(int64_t size, int sign) void SwapDir::updateSize(int64_t size, int sign) { - int blks = (size + fs.blksize - 1) / fs.blksize; - int k = (blks * fs.blksize >> 10) * sign; + int64_t blks = (size + fs.blksize - 1) / fs.blksize; + int64_t k = ((blks * fs.blksize) >> 10) * sign; cur_size += k; store_swap_size += k; @@ -365,6 +365,7 @@ StoreController::stat(StoreEntry &output) const (long int) maxSize()); storeAppendPrintf(&output, "Current Store Swap Size: %8lu KB\n", store_swap_size); + // XXX : below capacity display calculation breaks with int overflow on 64-bit systems storeAppendPrintf(&output, "Current Capacity : %d%% used, %d%% free\n", Math::intPercent((int) store_swap_size, (int) maxSize()), Math::intPercent((int) (maxSize() - store_swap_size), (int) maxSize()));