]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fs/rock/RockSwapDir.h
Allow HITs on entries backed by a shared memory cache only.
[thirdparty/squid.git] / src / fs / rock / RockSwapDir.h
CommitLineData
e2851fe7
AR
1#ifndef SQUID_FS_ROCK_SWAP_DIR_H
2#define SQUID_FS_ROCK_SWAP_DIR_H
3
43ebbac3 4#include "DiskIO/DiskFile.h"
e2851fe7 5#include "DiskIO/IORequestor.h"
fcd789da 6#include "fs/rock/RockDbCell.h"
50dc81ec 7#include "fs/rock/RockForward.h"
93910d5c
AR
8#include "ipc/mem/Page.h"
9#include "ipc/mem/PageStack.h"
9d4e9cfb 10#include "ipc/StoreMap.h"
602d9612 11#include "SwapDir.h"
e2851fe7
AR
12
13class DiskIOStrategy;
e2851fe7
AR
14class ReadRequest;
15class WriteRequest;
16
9199139f
AR
17namespace Rock
18{
e2851fe7 19
e2851fe7 20/// \ingroup Rock
93910d5c 21class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
e2851fe7
AR
22{
23public:
50dc81ec
AR
24 typedef RefCount<SwapDir> Pointer;
25 typedef Ipc::StoreMap DirMap;
26
e2851fe7
AR
27 SwapDir();
28 virtual ~SwapDir();
29
30 /* public ::SwapDir API */
c6059970 31 virtual void reconfigure();
e2851fe7 32 virtual StoreSearch *search(String const url, HttpRequest *);
44def0f9 33 virtual StoreEntry *get(const cache_key *key);
79672f4f 34 virtual void get(String const, STOREGETCLIENT, void * cbdata);
1bfe9ade 35 virtual void markForUnlink(StoreEntry &e);
f58bb2f4 36 virtual void disconnect(StoreEntry &e);
39c1e1d9
DK
37 virtual uint64_t currentSize() const;
38 virtual uint64_t currentCount() const;
39 virtual bool doReportStat() const;
da9d3191 40 virtual void swappedOut(const StoreEntry &e);
9bb01611
AR
41 virtual void create();
42 virtual void parse(int index, char *path);
6d8d05b5 43
300fd297
AR
44 // temporary path to the shared memory map of first slots of cached entries
45 const char *inodeMapPath() const;
46 // temporary path to the shared memory stack of free slots
50dc81ec 47 const char *freeSlotsPath() const;
300fd297 48
36c84e19
AR
49 int64_t entryLimitAbsolute() const { return SwapFilenMax+1; } ///< Core limit
50 int64_t entryLimitActual() const; ///< max number of possible entries in db
51 int64_t slotLimitAbsolute() const; ///< Rock store implementation limit
52 int64_t slotLimitActual() const; ///< total number of slots in this db
b3165da6 53
50dc81ec
AR
54 /// removes a slot from a list of free slots or returns false
55 bool useFreeSlot(Ipc::Mem::PageId &pageId);
56 /// whether the given slot ID may point to a slot in this db
57 bool validSlotId(const SlotId slotId) const;
58 /// purges one or more entries to make full() false and free some slots
59 void purgeSome();
93910d5c
AR
60
61 int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
50dc81ec 62 int64_t diskOffset(int filen) const;
4475555f 63 void writeError(StoreEntry &e);
93910d5c 64
50dc81ec 65 /* StoreMapCleaner API */
36c84e19 66 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
902df398 67
e51ce7da
AR
68 uint64_t slotSize; ///< all db slots are of this size
69
e2851fe7 70protected:
ce49546e 71 /* Store API */
4475555f 72 virtual bool anchorCollapsed(StoreEntry &collapsed, bool &inSync);
ce49546e
AR
73 virtual bool updateCollapsed(StoreEntry &collapsed);
74
e2851fe7 75 /* protected ::SwapDir API */
14911a4e 76 virtual bool needsDiskStrand() const;
e2851fe7 77 virtual void init();
43ebbac3 78 virtual ConfigOption *getOptionTree() const;
24063512 79 virtual bool allowOptionReconfigure(const char *const option) const;
c728b6f9 80 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
e2851fe7
AR
81 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
82 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
83 virtual void maintain();
e2851fe7
AR
84 virtual void diskFull();
85 virtual void reference(StoreEntry &e);
54347cbd 86 virtual bool dereference(StoreEntry &e, bool);
c521ad17 87 virtual bool unlinkdUseful() const;
e2851fe7
AR
88 virtual void unlink(StoreEntry &e);
89 virtual void statfs(StoreEntry &e) const;
90
91 /* IORequestor API */
92 virtual void ioCompletedNotification();
93 virtual void closeCompleted();
94 virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
95 virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
96
24063512 97 void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option
e2851fe7 98 void validateOptions(); ///< warns of configuration problems; may quit
43ebbac3
AR
99 bool parseTimeOption(char const *option, const char *value, int reconfiguring);
100 void dumpTimeOption(StoreEntry * e) const;
df881a0f
AR
101 bool parseRateOption(char const *option, const char *value, int reconfiguring);
102 void dumpRateOption(StoreEntry * e) const;
e51ce7da
AR
103 bool parseSizeOption(char const *option, const char *value, int reconfiguring);
104 void dumpSizeOption(StoreEntry * e) const;
e2851fe7
AR
105
106 void rebuild(); ///< starts loading and validating stored entry metadata
e2851fe7
AR
107
108 bool full() const; ///< no more entries can be stored without purging
109 void trackReferences(StoreEntry &e); ///< add to replacement policy scope
110 void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
111
e2851fe7 112 int64_t diskOffsetLimit() const;
e2851fe7 113
ce49546e
AR
114 void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
115 bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor);
116
e2851fe7 117 friend class Rebuild;
50dc81ec 118 friend class IoState;
e2851fe7 119 const char *filePath; ///< location of cache storage file inside path/
50dc81ec 120 DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping
e2851fe7
AR
121
122private:
413f00bd
AR
123 void createError(const char *const msg);
124
e2851fe7
AR
125 DiskIOStrategy *io;
126 RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
6d68a230
AR
127 Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< all unused slots
128 Ipc::Mem::PageId *waitingForPage; ///< one-page cache for a "hot" free slot
b3165da6 129
43ebbac3
AR
130 /* configurable options */
131 DiskFile::Config fileConfig; ///< file-level configuration options
132
b3165da6 133 static const int64_t HeaderSize; ///< on-disk db header size
e2851fe7
AR
134};
135
9bb01611
AR
136/// initializes shared memory segments used by Rock::SwapDir
137class SwapDirRr: public Ipc::Mem::RegisteredRunner
138{
139public:
140 /* ::RegisteredRunner API */
141 virtual ~SwapDirRr();
142
143protected:
144 /* Ipc::Mem::RegisteredRunner API */
21b7990f 145 virtual void create();
9bb01611
AR
146
147private:
b84330d1
AR
148 Vector<SwapDir::DirMap::Owner *> mapOwners;
149 Vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
9bb01611
AR
150};
151
e2851fe7
AR
152} // namespace Rock
153
154#endif /* SQUID_FS_ROCK_SWAP_DIR_H */