]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/fs/rock/RockSwapDir.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / rock / RockSwapDir.h
index 00ff9d2c4dda80f911ae47f76620a464d2be5842..36a910b21fca74433b2ebaa8bee17415deb7eb11 100644 (file)
@@ -1,45 +1,98 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #ifndef SQUID_FS_ROCK_SWAP_DIR_H
 #define SQUID_FS_ROCK_SWAP_DIR_H
 
-#include "SwapDir.h"
+#include "DiskIO/DiskFile.h"
 #include "DiskIO/IORequestor.h"
-#include "fs/rock/RockDirMap.h"
+#include "fs/rock/RockDbCell.h"
+#include "fs/rock/RockForward.h"
+#include "ipc/mem/Page.h"
+#include "ipc/mem/PageStack.h"
+#include "ipc/StoreMap.h"
+#include "SwapDir.h"
 
 class DiskIOStrategy;
-class DiskFile;
 class ReadRequest;
 class WriteRequest;
 
-namespace Rock {
-
-class Rebuild;
+namespace Rock
+{
 
 /// \ingroup Rock
-class SwapDir: public ::SwapDir, public IORequestor
+class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
 {
 public:
+    typedef RefCount<SwapDir> Pointer;
+    typedef Ipc::StoreMap DirMap;
+
     SwapDir();
     virtual ~SwapDir();
 
     /* public ::SwapDir API */
-    virtual void reconfigure(int, char *);
+    virtual void reconfigure();
     virtual StoreSearch *search(String const url, HttpRequest *);
     virtual StoreEntry *get(const cache_key *key);
+    virtual void get(String const, STOREGETCLIENT, void * cbdata);
+    virtual void markForUnlink(StoreEntry &e);
     virtual void disconnect(StoreEntry &e);
+    virtual uint64_t currentSize() const;
+    virtual uint64_t currentCount() const;
+    virtual bool doReportStat() const;
+    virtual void swappedOut(const StoreEntry &e);
+    virtual void create();
+    virtual void parse(int index, char *path);
+
+    // temporary path to the shared memory map of first slots of cached entries
+    SBuf inodeMapPath() const;
+    // temporary path to the shared memory stack of free slots
+    const char *freeSlotsPath() const;
+
+    int64_t entryLimitAbsolute() const { return SwapFilenMax+1; } ///< Core limit
+    int64_t entryLimitActual() const; ///< max number of possible entries in db
+    int64_t slotLimitAbsolute() const; ///< Rock store implementation limit
+    int64_t slotLimitActual() const; ///< total number of slots in this db
+
+    /// removes a slot from a list of free slots or returns false
+    bool useFreeSlot(Ipc::Mem::PageId &pageId);
+    /// whether the given slot ID may point to a slot in this db
+    bool validSlotId(const SlotId slotId) const;
+    /// purges one or more entries to make full() false and free some slots
+    void purgeSome();
+
+    int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
+    int64_t diskOffset(int filen) const;
+    void writeError(StoreEntry &e);
+
+    /* StoreMapCleaner API */
+    virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
+
+    uint64_t slotSize; ///< all db slots are of this size
 
 protected:
+    /* Store API */
+    virtual bool anchorCollapsed(StoreEntry &collapsed, bool &inSync);
+    virtual bool updateCollapsed(StoreEntry &collapsed);
+
     /* protected ::SwapDir API */
     virtual bool needsDiskStrand() const;
-    virtual void create();
     virtual void init();
+    virtual ConfigOption *getOptionTree() const;
+    virtual bool allowOptionReconfigure(const char *const option) const;
     virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
     virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
     virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
     virtual void maintain();
-    virtual void updateSize(int64_t size, int sign);
     virtual void diskFull();
     virtual void reference(StoreEntry &e);
-    virtual void dereference(StoreEntry &e);
+    virtual bool dereference(StoreEntry &e, bool);
+    virtual bool unlinkdUseful() const;
     virtual void unlink(StoreEntry &e);
     virtual void statfs(StoreEntry &e) const;
 
@@ -49,36 +102,62 @@ protected:
     virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
     virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
 
-    virtual void parse(int index, char *path);
-    void parseSize(); ///< parses anonymous cache_dir size option
+    void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option
     void validateOptions(); ///< warns of configuration problems; may quit
+    bool parseTimeOption(char const *option, const char *value, int reconfiguring);
+    void dumpTimeOption(StoreEntry * e) const;
+    bool parseRateOption(char const *option, const char *value, int reconfiguring);
+    void dumpRateOption(StoreEntry * e) const;
+    bool parseSizeOption(char const *option, const char *value, int reconfiguring);
+    void dumpSizeOption(StoreEntry * e) const;
 
     void rebuild(); ///< starts loading and validating stored entry metadata
-    ///< used to add entries successfully loaded during rebuild
-    bool addEntry(const int fileno, const DbCellHeader &header, const StoreEntry &from);
 
     bool full() const; ///< no more entries can be stored without purging
     void trackReferences(StoreEntry &e); ///< add to replacement policy scope
     void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
 
-    // TODO: change cur_size and max_size type to stop this madness
-    int64_t currentSize() const { return static_cast<int64_t>(cur_size) << 10;}
-    int64_t maximumSize() const { return static_cast<int64_t>(max_size) << 10;}
-    int64_t diskOffset(int filen) const;
     int64_t diskOffsetLimit() const;
-    int entryLimit() const { return map->entryLimit(); }
+
+    void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
+    bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor);
 
     friend class Rebuild;
+    friend class IoState;
     const char *filePath; ///< location of cache storage file inside path/
+    DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping
 
 private:
+    void createError(const char *const msg);
+
     DiskIOStrategy *io;
     RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
-    DirMap *map;
+    Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< all unused slots
+    Ipc::Mem::PageId *waitingForPage; ///< one-page cache for a "hot" free slot
+
+    /* configurable options */
+    DiskFile::Config fileConfig; ///< file-level configuration options
 
     static const int64_t HeaderSize; ///< on-disk db header size
 };
 
+/// initializes shared memory segments used by Rock::SwapDir
+class SwapDirRr: public Ipc::Mem::RegisteredRunner
+{
+public:
+    /* ::RegisteredRunner API */
+    virtual ~SwapDirRr();
+
+protected:
+    /* Ipc::Mem::RegisteredRunner API */
+    virtual void create();
+
+private:
+    std::vector<SwapDir::DirMap::Owner *> mapOwners;
+    std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
+};
+
 } // namespace Rock
 
 #endif /* SQUID_FS_ROCK_SWAP_DIR_H */
+