]>
Commit | Line | Data |
---|---|---|
d3b3ab85 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
d3b3ab85 | 3 | * |
bbc27441 AJ |
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. | |
d3b3ab85 | 7 | */ |
bbc27441 | 8 | |
d3b3ab85 | 9 | #ifndef SQUID_SWAPDIR_H |
10 | #define SQUID_SWAPDIR_H | |
11 | ||
4d5904f7 | 12 | #include "SquidConfig.h" |
c8f4eac4 | 13 | #include "Store.h" |
d3b3ab85 | 14 | #include "StoreIOState.h" |
15 | ||
aa839030 | 16 | /* forward decls */ |
17 | class RemovalPolicy; | |
9487bae9 | 18 | class MemStore; |
9a9954ba AR |
19 | class Transients; |
20 | class RequestFlags; | |
21 | class HttpRequestMethod; | |
aa839030 | 22 | |
d3b3ab85 | 23 | /* Store dir configuration routines */ |
24 | /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */ | |
62e76326 | 25 | |
b9ae18aa | 26 | class ConfigOption; |
27 | ||
9487bae9 | 28 | /// hides memory/disk cache distinction from callers |
c8f4eac4 | 29 | class StoreController : public Store |
30 | { | |
31 | ||
32 | public: | |
33 | StoreController(); | |
34 | virtual ~StoreController(); | |
35 | virtual int callback(); | |
36 | virtual void create(); | |
37 | ||
6da430a4 | 38 | virtual StoreEntry * get(const cache_key *); |
c8f4eac4 | 39 | |
6da430a4 | 40 | virtual void get(String const, STOREGETCLIENT, void * cbdata); |
c8f4eac4 | 41 | |
9487bae9 | 42 | /* Store parent API */ |
1bfe9ade | 43 | virtual void markForUnlink(StoreEntry &e); |
9487bae9 | 44 | virtual void handleIdleEntry(StoreEntry &e); |
99921d9d | 45 | virtual void transientsCompleteWriting(StoreEntry &e); |
4475555f | 46 | virtual void transientsAbandon(StoreEntry &e); |
d366a7fa | 47 | virtual int transientReaders(const StoreEntry &e) const; |
4475555f AR |
48 | virtual void transientsDisconnect(MemObject &mem_obj); |
49 | virtual void memoryOut(StoreEntry &e, const bool preserveSwappable); | |
ce49546e | 50 | virtual void memoryUnlink(StoreEntry &e); |
29c56e41 | 51 | virtual void memoryDisconnect(StoreEntry &e); |
9a9954ba | 52 | virtual void allowCollapsing(StoreEntry *e, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod); |
6919be24 | 53 | virtual void syncCollapsed(const sfileno xitIndex); |
9487bae9 | 54 | |
c8f4eac4 | 55 | virtual void init(); |
56 | ||
57 | virtual void maintain(); /* perform regular maintenance should be private and self registered ... */ | |
58 | ||
12e11a5c | 59 | virtual uint64_t maxSize() const; |
c8f4eac4 | 60 | |
12e11a5c | 61 | virtual uint64_t minSize() const; |
c8f4eac4 | 62 | |
39c1e1d9 DK |
63 | virtual uint64_t currentSize() const; |
64 | ||
65 | virtual uint64_t currentCount() const; | |
66 | ||
af2fda07 DK |
67 | virtual int64_t maxObjectSize() const; |
68 | ||
93bc1434 | 69 | virtual void getStats(StoreInfoStats &stats) const; |
c8f4eac4 | 70 | virtual void stat(StoreEntry &) const; |
71 | ||
f53969cc | 72 | virtual void sync(); /* Sync the store prior to shutdown */ |
c8f4eac4 | 73 | |
30abd221 | 74 | virtual StoreSearch *search(String const url, HttpRequest *); |
c8f4eac4 | 75 | |
f53969cc | 76 | virtual void reference(StoreEntry &); /* Reference this object */ |
c8f4eac4 | 77 | |
f53969cc | 78 | virtual bool dereference(StoreEntry &, bool); /* Unreference this object */ |
c8f4eac4 | 79 | |
bef81ea5 | 80 | /* the number of store dirs being rebuilt. */ |
81 | static int store_dirs_rebuilding; | |
82 | ||
c8f4eac4 | 83 | private: |
84 | void createOneStore(Store &aStore); | |
1bfe9ade | 85 | StoreEntry *find(const cache_key *key); |
97754f5a | 86 | bool keepForLocalMemoryCache(StoreEntry &e) const; |
99921d9d | 87 | bool anchorCollapsed(StoreEntry &collapsed, bool &inSync); |
4475555f | 88 | bool anchorCollapsedOnDisk(StoreEntry &collapsed, bool &inSync); |
c8f4eac4 | 89 | |
9487bae9 AR |
90 | StorePointer swapDir; ///< summary view of all disk caches |
91 | MemStore *memStore; ///< memory cache | |
9a9954ba AR |
92 | |
93 | /// A shared table of public store entries that do not know whether they | |
94 | /// will belong to a memory cache, a disk cache, or will be uncachable | |
95 | /// when the response header comes. Used for SMP collapsed forwarding. | |
96 | Transients *transients; | |
c8f4eac4 | 97 | }; |
98 | ||
99 | /* migrating from the Config based list of swapdirs */ | |
8a648e8d FC |
100 | void allocate_new_swapdir(SquidConfig::_cacheSwap *); |
101 | void free_cachedir(SquidConfig::_cacheSwap * swap); | |
102 | extern OBJH storeDirStats; | |
103 | char *storeDirSwapLogFile(int, const char *); | |
104 | char *storeSwapFullPath(int, char *); | |
105 | char *storeSwapSubSubDir(int, char *); | |
106 | const char *storeSwapPath(int); | |
107 | int storeDirWriteCleanLogs(int reopen); | |
108 | extern STDIRSELECT *storeDirSelectSwapDir; | |
109 | int storeVerifySwapDirs(void); | |
110 | void storeDirCloseSwapLogs(void); | |
111 | void storeDirCloseTmpSwapLog(int dirn); | |
112 | void storeDirDiskFull(sdirno); | |
113 | void storeDirOpenSwapLogs(void); | |
114 | void storeDirSwapLog(const StoreEntry *, int op); | |
115 | void storeDirLRUDelete(StoreEntry *); | |
116 | void storeDirLRUAdd(StoreEntry *); | |
117 | int storeDirGetBlkSize(const char *path, int *blksize); | |
118 | int storeDirGetUFSStats(const char *, int *, int *, int *, int *); | |
c8f4eac4 | 119 | |
9487bae9 | 120 | /// manages a single cache_dir |
c8f4eac4 | 121 | class SwapDir : public Store |
62e76326 | 122 | { |
123 | ||
d3b3ab85 | 124 | public: |
7d3c4ca1 DK |
125 | typedef RefCount<SwapDir> Pointer; |
126 | ||
e2851fe7 | 127 | SwapDir(char const *aType); |
d3b3ab85 | 128 | virtual ~SwapDir(); |
c6059970 | 129 | virtual void reconfigure() = 0; |
59b2d47f | 130 | char const *type() const; |
131 | ||
14911a4e AR |
132 | virtual bool needsDiskStrand() const; ///< needs a dedicated kid process |
133 | virtual bool active() const; ///< may be used in this strand | |
39c1e1d9 DK |
134 | /// whether stat should be reported by this SwapDir |
135 | virtual bool doReportStat() const { return active(); } | |
c521ad17 DK |
136 | /// whether SwapDir may benefit from unlinkd |
137 | virtual bool unlinkdUseful() const = 0; | |
14911a4e | 138 | |
c8f4eac4 | 139 | /* official Store interface functions */ |
140 | virtual void diskFull(); | |
141 | ||
6da430a4 | 142 | virtual StoreEntry * get(const cache_key *); |
c8f4eac4 | 143 | |
6da430a4 | 144 | virtual void get(String const, STOREGETCLIENT, void * cbdata); |
c8f4eac4 | 145 | |
12e11a5c | 146 | virtual uint64_t maxSize() const { return max_size;} |
c8f4eac4 | 147 | |
12e11a5c | 148 | virtual uint64_t minSize() const; |
39c1e1d9 | 149 | |
b51ec8c8 AJ |
150 | /// The maximum size of object which may be stored here. |
151 | /// Larger objects will not be added and may be purged. | |
e9da3e5b | 152 | virtual int64_t maxObjectSize() const; |
b51ec8c8 AJ |
153 | |
154 | /// configure the maximum object size for this storage area. | |
155 | /// May be any size up to the total storage area. | |
156 | void maxObjectSize(int64_t newMax); | |
af2fda07 | 157 | |
93bc1434 | 158 | virtual void getStats(StoreInfoStats &stats) const; |
c8f4eac4 | 159 | virtual void stat (StoreEntry &anEntry) const; |
30abd221 | 160 | virtual StoreSearch *search(String const url, HttpRequest *) = 0; |
c8f4eac4 | 161 | |
c8f4eac4 | 162 | /* migrated from store_dir.cc */ |
3e62bd58 | 163 | bool objectSizeIsAcceptable(int64_t objsize) const; |
c8f4eac4 | 164 | |
f58bb2f4 AR |
165 | /// called when the entry is about to forget its association with cache_dir |
166 | virtual void disconnect(StoreEntry &) {} | |
167 | ||
da9d3191 DK |
168 | /// called when entry swap out is complete |
169 | virtual void swappedOut(const StoreEntry &e) = 0; | |
170 | ||
59b2d47f | 171 | protected: |
172 | void parseOptions(int reconfiguring); | |
173 | void dumpOptions(StoreEntry * e) const; | |
b9ae18aa | 174 | virtual ConfigOption *getOptionTree() const; |
24063512 | 175 | virtual bool allowOptionReconfigure(const char *const) const { return true; } |
59b2d47f | 176 | |
a86ff82a DK |
177 | int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; } |
178 | ||
59b2d47f | 179 | private: |
180 | bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring); | |
181 | void optionReadOnlyDump(StoreEntry * e) const; | |
a8a33c46 A |
182 | bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring); |
183 | void optionObjectSizeDump(StoreEntry * e) const; | |
59b2d47f | 184 | char const *theType; |
185 | ||
cc34568d DK |
186 | protected: |
187 | uint64_t max_size; ///< maximum allocatable size of the storage area | |
b51ec8c8 AJ |
188 | int64_t min_objsize; ///< minimum size of any object stored here (-1 for no limit) |
189 | int64_t max_objsize; ///< maximum size of any object stored here (-1 for no limit) | |
cc34568d | 190 | |
59b2d47f | 191 | public: |
d3b3ab85 | 192 | char *path; |
f53969cc | 193 | int index; /* This entry's index into the swapDirs array */ |
3b581957 | 194 | int disker; ///< disker kid id dedicated to this SwapDir or -1 |
d3b3ab85 | 195 | RemovalPolicy *repl; |
196 | int removals; | |
197 | int scanned; | |
62e76326 | 198 | |
26ac0430 | 199 | struct Flags { |
1a6347cd FC |
200 | Flags() : selected(false), read_only(false) {} |
201 | bool selected; | |
202 | bool read_only; | |
2fadd50d | 203 | } flags; |
f53969cc SM |
204 | virtual void init() = 0; /* Initialise the fs */ |
205 | virtual void create(); /* Create a new fs */ | |
206 | virtual void dump(StoreEntry &)const; /* Dump fs config snippet */ | |
207 | virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */ | |
208 | virtual void statfs(StoreEntry &) const; /* Dump fs statistics */ | |
209 | virtual void maintain(); /* Replacement maintainence */ | |
aa1a691e AR |
210 | /// check whether we can store the entry; if we can, report current load |
211 | virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const = 0; | |
d3b3ab85 | 212 | /* These two are notifications */ |
f53969cc SM |
213 | virtual void reference(StoreEntry &); /* Reference this object */ |
214 | virtual bool dereference(StoreEntry &, bool); /* Unreference this object */ | |
215 | virtual int callback(); /* Handle pending callbacks */ | |
216 | virtual void sync(); /* Sync the store prior to shutdown */ | |
4fcc8876 | 217 | virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0; |
218 | virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0; | |
d3b3ab85 | 219 | virtual void unlink (StoreEntry &); |
220 | bool canLog(StoreEntry const &e)const; | |
221 | virtual void openLog(); | |
222 | virtual void closeLog(); | |
223 | virtual void logEntry(const StoreEntry & e, int op) const; | |
62e76326 | 224 | |
225 | class CleanLog | |
226 | { | |
227 | ||
228 | public: | |
26ac0430 | 229 | virtual ~CleanLog() {} |
62e76326 | 230 | |
231 | virtual const StoreEntry *nextEntry() = 0; | |
232 | virtual void write(StoreEntry const &) = 0; | |
d3b3ab85 | 233 | }; |
62e76326 | 234 | |
d3b3ab85 | 235 | CleanLog *cleanLog; |
236 | virtual int writeCleanStart(); | |
237 | virtual void writeCleanDone(); | |
238 | virtual void parse(int index, char *path) = 0; | |
62e76326 | 239 | |
26ac0430 | 240 | struct { |
62e76326 | 241 | int blksize; |
2fadd50d | 242 | } fs; |
d3b3ab85 | 243 | }; |
62e76326 | 244 | |
d3b3ab85 | 245 | #endif /* SQUID_SWAPDIR_H */ |
f53969cc | 246 |