]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3068: cache_dir capacity and usage overflows
authorAmos Jeffries <amosjeffries@squid-cache.org>
Fri, 1 Oct 2010 05:29:18 +0000 (23:29 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Fri, 1 Oct 2010 05:29:18 +0000 (23:29 -0600)
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.

src/SwapDir.h
src/fs/coss/store_dir_coss.cc
src/fs/ufs/store_dir_ufs.cc
src/store_dir.cc

index e4a6205d7b57041ed79608e01ba3baa01c4bf9da..a3930158b10148bff0b41023399178986f2869ca 100644 (file)
@@ -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;
index 64db7fe2066d838516540ae18298dc43a96e3400..e3e2fe443c241cae56233cf8d9cb3112ff6c932b 100644 (file)
@@ -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);
 }
 
index 51df97615c88b9ed96957b49217859caa70719a1..cdd0259f561677ebeefb4658889d3dd0662b1f5f 100644 (file)
@@ -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);
 }
 
index f95cab81f218fd1670292ca0fe759974ae39b5e1..a6d220dbd42fe06ecf2c9bbdafc9271d3f3989ed 100644 (file)
@@ -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()));