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