]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.h
Prep for 3.3.12 and 3.4.4
[thirdparty/squid.git] / src / SwapDir.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30 #ifndef SQUID_SWAPDIR_H
31 #define SQUID_SWAPDIR_H
32
33 #include "SquidConfig.h"
34 #include "Store.h"
35 #include "StoreIOState.h"
36
37 /* forward decls */
38 class RemovalPolicy;
39 class MemStore;
40 class Transients;
41 class RequestFlags;
42 class HttpRequestMethod;
43
44 /* Store dir configuration routines */
45 /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
46
47 class ConfigOption;
48
49 /// hides memory/disk cache distinction from callers
50 class StoreController : public Store
51 {
52
53 public:
54 StoreController();
55 virtual ~StoreController();
56 virtual int callback();
57 virtual void create();
58
59 virtual StoreEntry * get(const cache_key *);
60
61 virtual void get(String const, STOREGETCLIENT, void * cbdata);
62
63 /* Store parent API */
64 virtual void markForUnlink(StoreEntry &e);
65 virtual void handleIdleEntry(StoreEntry &e);
66 virtual void transientsCompleteWriting(StoreEntry &e);
67 virtual void transientsAbandon(StoreEntry &e);
68 virtual int transientReaders(const StoreEntry &e) const;
69 virtual void transientsDisconnect(MemObject &mem_obj);
70 virtual void memoryOut(StoreEntry &e, const bool preserveSwappable);
71 virtual void memoryUnlink(StoreEntry &e);
72 virtual void memoryDisconnect(StoreEntry &e);
73 virtual void allowCollapsing(StoreEntry *e, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod);
74 virtual void syncCollapsed(const sfileno xitIndex);
75
76 virtual void init();
77
78 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
79
80 virtual uint64_t maxSize() const;
81
82 virtual uint64_t minSize() const;
83
84 virtual uint64_t currentSize() const;
85
86 virtual uint64_t currentCount() const;
87
88 virtual int64_t maxObjectSize() const;
89
90 virtual void getStats(StoreInfoStats &stats) const;
91 virtual void stat(StoreEntry &) const;
92
93 virtual void sync(); /* Sync the store prior to shutdown */
94
95 virtual StoreSearch *search(String const url, HttpRequest *);
96
97 virtual void reference(StoreEntry &); /* Reference this object */
98
99 virtual bool dereference(StoreEntry &, bool); /* Unreference this object */
100
101 /* the number of store dirs being rebuilt. */
102 static int store_dirs_rebuilding;
103
104 private:
105 void createOneStore(Store &aStore);
106 StoreEntry *find(const cache_key *key);
107 bool keepForLocalMemoryCache(const StoreEntry &e) const;
108 bool anchorCollapsed(StoreEntry &collapsed, bool &inSync);
109 bool anchorCollapsedOnDisk(StoreEntry &collapsed, bool &inSync);
110
111 StorePointer swapDir; ///< summary view of all disk caches
112 MemStore *memStore; ///< memory cache
113
114 /// A shared table of public store entries that do not know whether they
115 /// will belong to a memory cache, a disk cache, or will be uncachable
116 /// when the response header comes. Used for SMP collapsed forwarding.
117 Transients *transients;
118 };
119
120 /* migrating from the Config based list of swapdirs */
121 void allocate_new_swapdir(SquidConfig::_cacheSwap *);
122 void free_cachedir(SquidConfig::_cacheSwap * swap);
123 extern OBJH storeDirStats;
124 char *storeDirSwapLogFile(int, const char *);
125 char *storeSwapFullPath(int, char *);
126 char *storeSwapSubSubDir(int, char *);
127 const char *storeSwapPath(int);
128 int storeDirWriteCleanLogs(int reopen);
129 extern STDIRSELECT *storeDirSelectSwapDir;
130 int storeVerifySwapDirs(void);
131 void storeDirCloseSwapLogs(void);
132 void storeDirCloseTmpSwapLog(int dirn);
133 void storeDirDiskFull(sdirno);
134 void storeDirOpenSwapLogs(void);
135 void storeDirSwapLog(const StoreEntry *, int op);
136 void storeDirLRUDelete(StoreEntry *);
137 void storeDirLRUAdd(StoreEntry *);
138 int storeDirGetBlkSize(const char *path, int *blksize);
139 int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
140
141 /// manages a single cache_dir
142 class SwapDir : public Store
143 {
144
145 public:
146 typedef RefCount<SwapDir> Pointer;
147
148 SwapDir(char const *aType);
149 virtual ~SwapDir();
150 virtual void reconfigure() = 0;
151 char const *type() const;
152
153 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
154 virtual bool active() const; ///< may be used in this strand
155 /// whether stat should be reported by this SwapDir
156 virtual bool doReportStat() const { return active(); }
157 /// whether SwapDir may benefit from unlinkd
158 virtual bool unlinkdUseful() const = 0;
159
160 /* official Store interface functions */
161 virtual void diskFull();
162
163 virtual StoreEntry * get(const cache_key *);
164
165 virtual void get(String const, STOREGETCLIENT, void * cbdata);
166
167 virtual uint64_t maxSize() const { return max_size;}
168
169 virtual uint64_t minSize() const;
170
171 /// The maximum size of object which may be stored here.
172 /// Larger objects will not be added and may be purged.
173 virtual int64_t maxObjectSize() const;
174
175 /// configure the maximum object size for this storage area.
176 /// May be any size up to the total storage area.
177 void maxObjectSize(int64_t newMax);
178
179 virtual void getStats(StoreInfoStats &stats) const;
180 virtual void stat (StoreEntry &anEntry) const;
181 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
182
183 /* migrated from store_dir.cc */
184 bool objectSizeIsAcceptable(int64_t objsize) const;
185
186 /// called when the entry is about to forget its association with cache_dir
187 virtual void disconnect(StoreEntry &) {}
188
189 /// called when entry swap out is complete
190 virtual void swappedOut(const StoreEntry &e) = 0;
191
192 protected:
193 void parseOptions(int reconfiguring);
194 void dumpOptions(StoreEntry * e) const;
195 virtual ConfigOption *getOptionTree() const;
196 virtual bool allowOptionReconfigure(const char *const) const { return true; }
197
198 int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
199
200 private:
201 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
202 void optionReadOnlyDump(StoreEntry * e) const;
203 bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
204 void optionObjectSizeDump(StoreEntry * e) const;
205 char const *theType;
206
207 protected:
208 uint64_t max_size; ///< maximum allocatable size of the storage area
209 int64_t min_objsize; ///< minimum size of any object stored here (-1 for no limit)
210 int64_t max_objsize; ///< maximum size of any object stored here (-1 for no limit)
211
212 public:
213 char *path;
214 int index; /* This entry's index into the swapDirs array */
215 int disker; ///< disker kid id dedicated to this SwapDir or -1
216 RemovalPolicy *repl;
217 int removals;
218 int scanned;
219
220 struct Flags {
221 Flags() : selected(false), read_only(false) {}
222 bool selected;
223 bool read_only;
224 } flags;
225 virtual void init() = 0; /* Initialise the fs */
226 virtual void create(); /* Create a new fs */
227 virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
228 virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
229 virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
230 virtual void maintain(); /* Replacement maintainence */
231 /// check whether we can store the entry; if we can, report current load
232 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const = 0;
233 /* These two are notifications */
234 virtual void reference(StoreEntry &); /* Reference this object */
235 virtual bool dereference(StoreEntry &, bool); /* Unreference this object */
236 virtual int callback(); /* Handle pending callbacks */
237 virtual void sync(); /* Sync the store prior to shutdown */
238 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
239 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
240 virtual void unlink (StoreEntry &);
241 bool canLog(StoreEntry const &e)const;
242 virtual void openLog();
243 virtual void closeLog();
244 virtual void logEntry(const StoreEntry & e, int op) const;
245
246 class CleanLog
247 {
248
249 public:
250 virtual ~CleanLog() {}
251
252 virtual const StoreEntry *nextEntry() = 0;
253 virtual void write(StoreEntry const &) = 0;
254 };
255
256 CleanLog *cleanLog;
257 virtual int writeCleanStart();
258 virtual void writeCleanDone();
259 virtual void parse(int index, char *path) = 0;
260
261 struct {
262 int blksize;
263 } fs;
264 };
265
266 #endif /* SQUID_SWAPDIR_H */