]> git.ipfire.org Git - thirdparty/squid.git/blame - src/fs/rock/RockSwapDir.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / fs / rock / RockSwapDir.h
CommitLineData
bbc27441 1/*
f70aedc4 2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
bbc27441
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
e2851fe7
AR
9#ifndef SQUID_FS_ROCK_SWAP_DIR_H
10#define SQUID_FS_ROCK_SWAP_DIR_H
11
43ebbac3 12#include "DiskIO/DiskFile.h"
e2851fe7 13#include "DiskIO/IORequestor.h"
aac0df40 14#include "fs/rock/forward.h"
fcd789da 15#include "fs/rock/RockDbCell.h"
8ecbe78d 16#include "fs/rock/RockRebuild.h"
93910d5c
AR
17#include "ipc/mem/Page.h"
18#include "ipc/mem/PageStack.h"
9d4e9cfb 19#include "ipc/StoreMap.h"
2745fea5 20#include "store/Disk.h"
8ecbe78d 21#include "store_rebuild.h"
d8a6ec7f 22#include <vector>
e2851fe7
AR
23
24class DiskIOStrategy;
e2851fe7
AR
25class ReadRequest;
26class WriteRequest;
27
9199139f
AR
28namespace Rock
29{
e2851fe7 30
e2851fe7 31/// \ingroup Rock
93910d5c 32class SwapDir: public ::SwapDir, public IORequestor, public Ipc::StoreMapCleaner
e2851fe7
AR
33{
34public:
50dc81ec
AR
35 typedef RefCount<SwapDir> Pointer;
36 typedef Ipc::StoreMap DirMap;
37
e2851fe7
AR
38 SwapDir();
39 virtual ~SwapDir();
40
41 /* public ::SwapDir API */
c6059970 42 virtual void reconfigure();
44def0f9 43 virtual StoreEntry *get(const cache_key *key);
4310f8b0
EB
44 virtual void evictCached(StoreEntry &);
45 virtual void evictIfFound(const cache_key *);
f58bb2f4 46 virtual void disconnect(StoreEntry &e);
39c1e1d9
DK
47 virtual uint64_t currentSize() const;
48 virtual uint64_t currentCount() const;
49 virtual bool doReportStat() const;
4310f8b0
EB
50 virtual void finalizeSwapoutSuccess(const StoreEntry &);
51 virtual void finalizeSwapoutFailure(StoreEntry &);
9bb01611
AR
52 virtual void create();
53 virtual void parse(int index, char *path);
1a210de4 54 virtual bool smpAware() const { return true; }
4310f8b0 55 virtual bool hasReadableEntry(const StoreEntry &) const;
6d8d05b5 56
300fd297 57 // temporary path to the shared memory map of first slots of cached entries
1860fbac 58 SBuf inodeMapPath() const;
300fd297 59 // temporary path to the shared memory stack of free slots
50dc81ec 60 const char *freeSlotsPath() const;
300fd297 61
36c84e19
AR
62 int64_t entryLimitAbsolute() const { return SwapFilenMax+1; } ///< Core limit
63 int64_t entryLimitActual() const; ///< max number of possible entries in db
64 int64_t slotLimitAbsolute() const; ///< Rock store implementation limit
65 int64_t slotLimitActual() const; ///< total number of slots in this db
b3165da6 66
50dc81ec
AR
67 /// whether the given slot ID may point to a slot in this db
68 bool validSlotId(const SlotId slotId) const;
c2037547
EB
69
70 /// finds and returns a free db slot to fill or throws
71 SlotId reserveSlotForWriting();
72
50dc81ec
AR
73 /// purges one or more entries to make full() false and free some slots
74 void purgeSome();
93910d5c
AR
75
76 int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
50dc81ec 77 int64_t diskOffset(int filen) const;
abf396ec 78 void writeError(StoreIOState &sio);
93910d5c 79
50dc81ec 80 /* StoreMapCleaner API */
36c84e19 81 virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
902df398 82
e51ce7da
AR
83 uint64_t slotSize; ///< all db slots are of this size
84
e2851fe7 85protected:
ce49546e 86 /* Store API */
4310f8b0
EB
87 virtual bool anchorToCache(StoreEntry &entry, bool &inSync);
88 virtual bool updateAnchored(StoreEntry &);
ce49546e 89
e2851fe7 90 /* protected ::SwapDir API */
14911a4e 91 virtual bool needsDiskStrand() const;
e2851fe7 92 virtual void init();
43ebbac3 93 virtual ConfigOption *getOptionTree() const;
24063512 94 virtual bool allowOptionReconfigure(const char *const option) const;
c728b6f9 95 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
e2851fe7
AR
96 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
97 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
98 virtual void maintain();
e2851fe7
AR
99 virtual void diskFull();
100 virtual void reference(StoreEntry &e);
2745fea5 101 virtual bool dereference(StoreEntry &e);
abf396ec 102 virtual void updateHeaders(StoreEntry *e);
c521ad17 103 virtual bool unlinkdUseful() const;
e2851fe7
AR
104 virtual void statfs(StoreEntry &e) const;
105
106 /* IORequestor API */
107 virtual void ioCompletedNotification();
108 virtual void closeCompleted();
109 virtual void readCompleted(const char *buf, int len, int errflag, RefCount< ::ReadRequest>);
110 virtual void writeCompleted(int errflag, size_t len, RefCount< ::WriteRequest>);
111
24063512 112 void parseSize(const bool reconfiguring); ///< parses anonymous cache_dir size option
e2851fe7 113 void validateOptions(); ///< warns of configuration problems; may quit
43ebbac3
AR
114 bool parseTimeOption(char const *option, const char *value, int reconfiguring);
115 void dumpTimeOption(StoreEntry * e) const;
df881a0f
AR
116 bool parseRateOption(char const *option, const char *value, int reconfiguring);
117 void dumpRateOption(StoreEntry * e) const;
e51ce7da
AR
118 bool parseSizeOption(char const *option, const char *value, int reconfiguring);
119 void dumpSizeOption(StoreEntry * e) const;
e2851fe7 120
e2851fe7
AR
121 bool full() const; ///< no more entries can be stored without purging
122 void trackReferences(StoreEntry &e); ///< add to replacement policy scope
123 void ignoreReferences(StoreEntry &e); ///< delete from repl policy scope
124
e2851fe7 125 int64_t diskOffsetLimit() const;
e2851fe7 126
abf396ec
AR
127 void updateHeadersOrThrow(Ipc::StoreMapUpdate &update);
128 StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
129
ce49546e 130 void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
4310f8b0 131 bool updateAnchoredWith(StoreEntry &, const Ipc::StoreMapAnchor &);
ce49546e 132
e2851fe7 133 friend class Rebuild;
50dc81ec 134 friend class IoState;
abf396ec 135 friend class HeaderUpdater;
e2851fe7 136 const char *filePath; ///< location of cache storage file inside path/
50dc81ec 137 DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping
e2851fe7
AR
138
139private:
413f00bd 140 void createError(const char *const msg);
a12f1a4c
EB
141 void handleWriteCompletionSuccess(const WriteRequest &request);
142 void handleWriteCompletionProblem(const int errflag, const WriteRequest &request);
413f00bd 143
e2851fe7
AR
144 DiskIOStrategy *io;
145 RefCount<DiskFile> theFile; ///< cache storage for this cache_dir
6d68a230
AR
146 Ipc::Mem::Pointer<Ipc::Mem::PageStack> freeSlots; ///< all unused slots
147 Ipc::Mem::PageId *waitingForPage; ///< one-page cache for a "hot" free slot
b3165da6 148
43ebbac3
AR
149 /* configurable options */
150 DiskFile::Config fileConfig; ///< file-level configuration options
151
b3165da6 152 static const int64_t HeaderSize; ///< on-disk db header size
e2851fe7
AR
153};
154
9bb01611
AR
155/// initializes shared memory segments used by Rock::SwapDir
156class SwapDirRr: public Ipc::Mem::RegisteredRunner
157{
158public:
159 /* ::RegisteredRunner API */
160 virtual ~SwapDirRr();
161
162protected:
163 /* Ipc::Mem::RegisteredRunner API */
21b7990f 164 virtual void create();
9bb01611
AR
165
166private:
8ecbe78d 167 std::vector<Ipc::Mem::Owner<Rebuild::Stats> *> rebuildStatsOwners;
cfb88efb
AR
168 std::vector<SwapDir::DirMap::Owner *> mapOwners;
169 std::vector< Ipc::Mem::Owner<Ipc::Mem::PageStack> *> freeSlotsOwners;
9bb01611
AR
170};
171
e2851fe7
AR
172} // namespace Rock
173
174#endif /* SQUID_FS_ROCK_SWAP_DIR_H */
f53969cc 175