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