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