]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Move max_size and n_disk_objects to specific SwapDirs, remove updateSize().
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Thu, 28 Apr 2011 12:23:55 +0000 (16:23 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Thu, 28 Apr 2011 12:23:55 +0000 (16:23 +0400)
src/SwapDir.cc
src/SwapDir.h
src/fs/coss/CossSwapDir.h
src/fs/coss/store_dir_coss.cc
src/fs/coss/store_io_coss.cc
src/fs/ufs/store_dir_ufs.cc
src/fs/ufs/ufscommon.h
src/store_dir.cc

index 251fc73717762156d25980eb61de82160d95da14..913c4e673d913941ad1e1e2917318b51456468e3 100644 (file)
@@ -39,7 +39,7 @@
 #include "ConfigOption.h"
 
 SwapDir::SwapDir(char const *aType): theType(aType),
-        cur_size (0), max_size(0), n_disk_objects(0),
+        max_size(0),
         path(NULL), index(-1), min_objsize(0), max_objsize (-1),
         repl(NULL), removals(0), scanned(0),
         cleanLog(NULL)
index e0d77aa9c56ca667a81376fd2f9e685fb7af5cdf..a92f7079a066ab2bff422e29442260906f84d37a 100644 (file)
@@ -144,17 +144,11 @@ public:
 
     virtual uint64_t minSize() const;
 
-    virtual uint64_t currentSize() const { return cur_size; }
-
-    virtual uint64_t currentCount() const { return n_disk_objects; }
-
     virtual int64_t maxObjectSize() const { return max_objsize; }
 
     virtual void stat (StoreEntry &anEntry) const;
     virtual StoreSearch *search(String const url, HttpRequest *) = 0;
 
-    virtual void updateSize(int64_t size, int sign);
-
     /* migrated from store_dir.cc */
     bool objectSizeIsAcceptable(int64_t objsize) const;
 
@@ -169,6 +163,8 @@ protected:
     void dumpOptions(StoreEntry * e) const;
     virtual ConfigOption *getOptionTree() const;
 
+    int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
+
 private:
     bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
     void optionReadOnlyDump(StoreEntry * e) const;
@@ -176,14 +172,10 @@ private:
     void optionObjectSizeDump(StoreEntry * e) const;
     char const *theType;
 
-private:
-    uint64_t cur_size;        ///< currently used space in the storage area
-
 protected:
     uint64_t max_size;        ///< maximum allocatable size of the storage area
 
 public:
-    uint64_t n_disk_objects;  ///< total number of objects stored
     char *path;
     int index;                 /* This entry's index into the swapDirs array */
     int64_t min_objsize;
index 5e6b89018448ac28afb496aec46474c0d3685df7..1a74fcb9e1859f82d2a728a6259ab2fc06f30c01 100644 (file)
@@ -50,6 +50,8 @@ public:
     virtual void parse (int index, char *path);
     virtual void reconfigure (int, char *);
     virtual void swappedOut(const StoreEntry &e);
+    virtual uint64_t currentSize() const { return cur_size; }
+    virtual uint64_t currentCount() const { return n_disk_objects; }
     /* internals */
     virtual off_t storeCossFilenoToDiskOffset(sfileno);
     virtual sfileno storeCossDiskOffsetToFileno(off_t);
@@ -77,6 +79,16 @@ public:
     CossMemBuf *createMemBuf(off_t start, sfileno curfn, int *collision);
     sfileno allocate(const StoreEntry * e, int which);
     void startMembuf();
+    StoreEntry *addDiskRestore(const cache_key *const key,
+                               int file_number,
+                               uint64_t swap_file_sz,
+                               time_t expires,
+                               time_t timestamp,
+                               time_t lastref,
+                               time_t lastmod,
+                               uint32_t refcount,
+                               uint16_t flags,
+                               int clean);
 
 private:
     void changeIO(DiskIOModule *module);
@@ -89,6 +101,8 @@ private:
     const char *ioModule;
     mutable ConfigOptionVector *currentIOOptions;
     const char *stripe_path;
+    uint64_t cur_size; ///< currently used space in the storage area
+    uint64_t n_disk_objects; ///< total number of objects stored
 };
 
 /// \ingroup COSS
index 2a075eb7cfb9da04925822203e5bacbcd26527a0..dd9c07111e8a526c5fc96534765812b0e6de1c70 100644 (file)
@@ -74,16 +74,6 @@ struct _RebuildState {
 
 static char *storeCossDirSwapLogFile(SwapDir *, const char *);
 static EVH storeCossRebuildFromSwapLog;
-static StoreEntry *storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
-        int file_number,
-        uint64_t swap_file_sz,
-        time_t expires,
-        time_t timestamp,
-        time_t lastref,
-        time_t lastmod,
-        uint32_t refcount,
-        uint16_t flags,
-        int clean);
 static void storeCossDirRebuild(CossSwapDir * sd);
 static void storeCossDirCloseTmpSwapLog(CossSwapDir * sd);
 static FILE *storeCossDirOpenTmpSwapLog(CossSwapDir *, int *, int *);
@@ -482,7 +472,7 @@ storeCossRebuildFromSwapLog(void *data)
 
         rb->counts.objcount++;
 
-        e = storeCossAddDiskRestore(rb->sd, s.key,
+        e = rb->sd->addDiskRestore(s.key,
                                     s.swap_filen,
                                     s.swap_file_sz,
                                     s.expires,
@@ -501,8 +491,8 @@ storeCossRebuildFromSwapLog(void *data)
 
 /* Add a new object to the cache with empty memory copy and pointer to disk
  * use to rebuild store from disk. */
-static StoreEntry *
-storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
+StoreEntry *
+CossSwapDir::addDiskRestore(const cache_key *const key,
                         int file_number,
                         uint64_t swap_file_sz,
                         time_t expires,
@@ -522,7 +512,7 @@ storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
      * already in use! */
     e = new StoreEntry();
     e->store_status = STORE_OK;
-    e->swap_dirn = SD->index;
+    e->swap_dirn = index;
     e->setMemStatus(NOT_IN_MEMORY);
     e->swap_status = SWAPOUT_DONE;
     e->swap_filen = file_number;
@@ -539,9 +529,10 @@ storeCossAddDiskRestore(CossSwapDir * SD, const cache_key * key,
     EBIT_CLR(e->flags, KEY_PRIVATE);
     e->ping_status = PING_NONE;
     EBIT_CLR(e->flags, ENTRY_VALIDATED);
-    SD->updateSize(e->swap_file_sz, 1);
+    cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz);
+    ++n_disk_objects;
     e->hashInsert(key);        /* do it after we clear KEY_PRIVATE */
-    storeCossAdd(SD, e);
+    storeCossAdd(this, e);
     assert(e->swap_filen >= 0);
     return e;
 }
@@ -1072,7 +1063,8 @@ CossSwapDir::reconfigure(int index, char *path)
 void
 CossSwapDir::swappedOut(const StoreEntry &e)
 {
-    updateSize(e.swap_file_sz, 1);
+    cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz);
+    ++n_disk_objects;
 }
 
 void
@@ -1082,7 +1074,7 @@ CossSwapDir::dump(StoreEntry &entry)const
     dumpOptions(&entry);
 }
 
-CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0),  blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL)
+CossSwapDir::CossSwapDir() : SwapDir ("coss"), swaplog_fd(-1), count(0), current_membuf (NULL), current_offset(0), numcollisions(0),  blksz_bits(0), io (NULL), ioModule(NULL), currentIOOptions(new ConfigOptionVector()), stripe_path(NULL), cur_size(0), n_disk_objects(0)
 {
     membufs.head = NULL;
     membufs.tail = NULL;
index 4be22ed9da808c09091165605d4755397ac79cbb..bb4c09db4e4e338b8ca6fa3cc686f96949c7a2da 100644 (file)
@@ -133,8 +133,10 @@ void
 CossSwapDir::unlink(StoreEntry & e)
 {
     debugs(79, 3, "storeCossUnlink: offset " << e.swap_filen);
-    if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED))
-        updateSize(e.swap_file_sz, -1);
+    if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) {
+        cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz);
+        --n_disk_objects;
+    }
     StoreFScoss::GetInstance().stats.unlink.ops++;
     StoreFScoss::GetInstance().stats.unlink.success++;
     storeCossRemove(this, &e);
index 35e1bc6baaf6cb29dae1982f99f0caa6564f8de6..da36b6396c987d48a5656661b8e277bf49312288 100644 (file)
@@ -246,7 +246,7 @@ UFSSwapDir::create()
     createSwapSubDirs();
 }
 
-UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType))
+UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)), cur_size(0), n_disk_objects(0)
 {
     /* modulename is only set to disk modules that are built, by configure,
      * so the Find call should never return NULL here.
@@ -717,7 +717,8 @@ UFSSwapDir::addDiskRestore(const cache_key * key,
     e->ping_status = PING_NONE;
     EBIT_CLR(e->flags, ENTRY_VALIDATED);
     mapBitSet(e->swap_filen);
-    updateSize(e->swap_file_sz, 1);
+    cur_size += fs.blksize * sizeInBlocks(e->swap_file_sz);
+    ++n_disk_objects;
     e->hashInsert(key);        /* do it after we clear KEY_PRIVATE */
     replacementAdd (e);
     return e;
@@ -1289,8 +1290,10 @@ UFSSwapDir::unlink(StoreEntry & e)
 {
     debugs(79, 3, "storeUfsUnlink: dirno " << index  << ", fileno "<<
            std::setfill('0') << std::hex << std::uppercase << std::setw(8) << e.swap_filen);
-    if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED))
-        updateSize(e.swap_file_sz, -1);
+    if (e.swap_status == SWAPOUT_DONE && EBIT_TEST(e.flags, ENTRY_VALIDATED)) {
+        cur_size -= fs.blksize * sizeInBlocks(e.swap_file_sz);
+        --n_disk_objects;
+    }
     replacementRemove(&e);
     mapBitReset(e.swap_filen);
     UFSSwapDir::unlinkFile(e.swap_filen);
@@ -1369,7 +1372,8 @@ UFSSwapDir::sync()
 void
 UFSSwapDir::swappedOut(const StoreEntry &e)
 {
-    updateSize(e.swap_file_sz, 1);
+    cur_size += fs.blksize * sizeInBlocks(e.swap_file_sz);
+    ++n_disk_objects;
 }
 
 StoreSearch *
index dfa9235c81b327629799df06496734f0037c4592..883c99f9d4a60d24153e6424923ce900bb7ade8f 100644 (file)
@@ -77,6 +77,8 @@ public:
     virtual int callback();
     virtual void sync();
     virtual void swappedOut(const StoreEntry &e);
+    virtual uint64_t currentSize() const { return cur_size; }
+    virtual uint64_t currentCount() const { return n_disk_objects; }
 
     void unlinkFile(sfileno f);
     // move down when unlink is a virtual method
@@ -136,7 +138,8 @@ private:
     void optionIODump(StoreEntry * e) const;
     mutable ConfigOptionVector *currentIOOptions;
     char const *ioType;
-
+    uint64_t cur_size; ///< currently used space in the storage area
+    uint64_t n_disk_objects; ///< total number of objects stored
 };
 
 #include "RefCount.h"
index dd4390491d851811df3f8abf02908f1a50503440..4f414b31831fee3736d4cc07dfd7e15116f01824 100644 (file)
@@ -323,19 +323,6 @@ storeDirSwapLog(const StoreEntry * e, int op)
     dynamic_cast<SwapDir *>(INDEXSD(e->swap_dirn))->logEntry(*e, op);
 }
 
-void
-SwapDir::updateSize(int64_t size, int sign)
-{
-    const int64_t blks = (size + fs.blksize - 1) / fs.blksize;
-    const int64_t k = blks * fs.blksize * sign;
-    cur_size += k;
-
-    if (sign > 0)
-        n_disk_objects++;
-    else if (sign < 0)
-        n_disk_objects--;
-}
-
 void
 StoreController::stat(StoreEntry &output) const
 {