]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / SwapDir.h
1 /*
2 * Copyright (C) 1996-2014 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_SWAPDIR_H
10 #define SQUID_SWAPDIR_H
11
12 #include "SquidConfig.h"
13 #include "Store.h"
14 #include "StoreIOState.h"
15
16 /* forward decls */
17 class RemovalPolicy;
18 class MemStore;
19 class Transients;
20 class RequestFlags;
21 class HttpRequestMethod;
22
23 /* Store dir configuration routines */
24 /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
25
26 class ConfigOption;
27
28 /// hides memory/disk cache distinction from callers
29 class StoreController : public Store
30 {
31
32 public:
33 StoreController();
34 virtual ~StoreController();
35 virtual int callback();
36 virtual void create();
37
38 virtual StoreEntry * get(const cache_key *);
39
40 virtual void get(String const, STOREGETCLIENT, void * cbdata);
41
42 /* Store parent API */
43 virtual void markForUnlink(StoreEntry &e);
44 virtual void handleIdleEntry(StoreEntry &e);
45 virtual void transientsCompleteWriting(StoreEntry &e);
46 virtual void transientsAbandon(StoreEntry &e);
47 virtual int transientReaders(const StoreEntry &e) const;
48 virtual void transientsDisconnect(MemObject &mem_obj);
49 virtual void memoryOut(StoreEntry &e, const bool preserveSwappable);
50 virtual void memoryUnlink(StoreEntry &e);
51 virtual void memoryDisconnect(StoreEntry &e);
52 virtual void allowCollapsing(StoreEntry *e, const RequestFlags &reqFlags, const HttpRequestMethod &reqMethod);
53 virtual void syncCollapsed(const sfileno xitIndex);
54
55 virtual void init();
56
57 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
58
59 virtual uint64_t maxSize() const;
60
61 virtual uint64_t minSize() const;
62
63 virtual uint64_t currentSize() const;
64
65 virtual uint64_t currentCount() const;
66
67 virtual int64_t maxObjectSize() const;
68
69 virtual void getStats(StoreInfoStats &stats) const;
70 virtual void stat(StoreEntry &) const;
71
72 virtual void sync(); /* Sync the store prior to shutdown */
73
74 virtual StoreSearch *search(String const url, HttpRequest *);
75
76 virtual void reference(StoreEntry &); /* Reference this object */
77
78 virtual bool dereference(StoreEntry &, bool); /* Unreference this object */
79
80 /* the number of store dirs being rebuilt. */
81 static int store_dirs_rebuilding;
82
83 private:
84 void createOneStore(Store &aStore);
85 StoreEntry *find(const cache_key *key);
86 bool keepForLocalMemoryCache(StoreEntry &e) const;
87 bool anchorCollapsed(StoreEntry &collapsed, bool &inSync);
88 bool anchorCollapsedOnDisk(StoreEntry &collapsed, bool &inSync);
89
90 StorePointer swapDir; ///< summary view of all disk caches
91 MemStore *memStore; ///< memory cache
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;
97 };
98
99 /* migrating from the Config based list of swapdirs */
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 *);
119
120 /// manages a single cache_dir
121 class SwapDir : public Store
122 {
123
124 public:
125 typedef RefCount<SwapDir> Pointer;
126
127 SwapDir(char const *aType);
128 virtual ~SwapDir();
129 virtual void reconfigure() = 0;
130 char const *type() const;
131
132 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
133 virtual bool active() const; ///< may be used in this strand
134 /// whether stat should be reported by this SwapDir
135 virtual bool doReportStat() const { return active(); }
136 /// whether SwapDir may benefit from unlinkd
137 virtual bool unlinkdUseful() const = 0;
138
139 /* official Store interface functions */
140 virtual void diskFull();
141
142 virtual StoreEntry * get(const cache_key *);
143
144 virtual void get(String const, STOREGETCLIENT, void * cbdata);
145
146 virtual uint64_t maxSize() const { return max_size;}
147
148 virtual uint64_t minSize() const;
149
150 /// The maximum size of object which may be stored here.
151 /// Larger objects will not be added and may be purged.
152 virtual int64_t maxObjectSize() const;
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);
157
158 virtual void getStats(StoreInfoStats &stats) const;
159 virtual void stat (StoreEntry &anEntry) const;
160 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
161
162 /* migrated from store_dir.cc */
163 bool objectSizeIsAcceptable(int64_t objsize) const;
164
165 /// called when the entry is about to forget its association with cache_dir
166 virtual void disconnect(StoreEntry &) {}
167
168 /// called when entry swap out is complete
169 virtual void swappedOut(const StoreEntry &e) = 0;
170
171 protected:
172 void parseOptions(int reconfiguring);
173 void dumpOptions(StoreEntry * e) const;
174 virtual ConfigOption *getOptionTree() const;
175 virtual bool allowOptionReconfigure(const char *const) const { return true; }
176
177 int64_t sizeInBlocks(const int64_t size) const { return (size + fs.blksize - 1) / fs.blksize; }
178
179 private:
180 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
181 void optionReadOnlyDump(StoreEntry * e) const;
182 bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
183 void optionObjectSizeDump(StoreEntry * e) const;
184 char const *theType;
185
186 protected:
187 uint64_t max_size; ///< maximum allocatable size of the storage area
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)
190
191 public:
192 char *path;
193 int index; /* This entry's index into the swapDirs array */
194 int disker; ///< disker kid id dedicated to this SwapDir or -1
195 RemovalPolicy *repl;
196 int removals;
197 int scanned;
198
199 struct Flags {
200 Flags() : selected(false), read_only(false) {}
201 bool selected;
202 bool read_only;
203 } flags;
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 */
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;
212 /* These two are notifications */
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 */
217 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
218 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
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;
224
225 class CleanLog
226 {
227
228 public:
229 virtual ~CleanLog() {}
230
231 virtual const StoreEntry *nextEntry() = 0;
232 virtual void write(StoreEntry const &) = 0;
233 };
234
235 CleanLog *cleanLog;
236 virtual int writeCleanStart();
237 virtual void writeCleanDone();
238 virtual void parse(int index, char *path) = 0;
239
240 struct {
241 int blksize;
242 } fs;
243 };
244
245 #endif /* SQUID_SWAPDIR_H */