]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.h
Polish on cache_dir min-size port
[thirdparty/squid.git] / src / SwapDir.h
1 /*
2 * $Id$
3 *
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32 #ifndef SQUID_SWAPDIR_H
33 #define SQUID_SWAPDIR_H
34
35 #include "Store.h"
36 #include "StoreIOState.h"
37
38 /* forward decls */
39 class RemovalPolicy;
40
41 /* Store dir configuration routines */
42 /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
43
44 class ConfigOption;
45
46 /* New class that replaces the static SwapDir methods as part of the Store overhaul */
47
48 class StoreController : public Store
49 {
50
51 public:
52 StoreController();
53 virtual ~StoreController();
54 virtual int callback();
55 virtual void create();
56
57 virtual StoreEntry * get(const cache_key *);
58
59 virtual void get(String const, STOREGETCLIENT, void * cbdata);
60
61 virtual void init();
62
63 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
64
65 virtual uint64_t maxSize() const;
66
67 virtual uint64_t minSize() const;
68
69 virtual void stat(StoreEntry &) const;
70
71 virtual void sync(); /* Sync the store prior to shutdown */
72
73 virtual StoreSearch *search(String const url, HttpRequest *);
74
75 virtual void reference(StoreEntry &); /* Reference this object */
76
77 virtual void dereference(StoreEntry &); /* Unreference this object */
78
79 virtual void updateSize(int64_t size, int sign);
80
81 /* the number of store dirs being rebuilt. */
82 static int store_dirs_rebuilding;
83
84 private:
85 void createOneStore(Store &aStore);
86
87 StorePointer swapDir;
88 };
89
90 /* migrating from the Config based list of swapdirs */
91 extern void allocate_new_swapdir(SquidConfig::_cacheSwap *);
92 extern void free_cachedir(SquidConfig::_cacheSwap * swap);
93 SQUIDCEXTERN OBJH storeDirStats;
94 SQUIDCEXTERN char *storeDirSwapLogFile(int, const char *);
95 SQUIDCEXTERN char *storeSwapFullPath(int, char *);
96 SQUIDCEXTERN char *storeSwapSubSubDir(int, char *);
97 SQUIDCEXTERN const char *storeSwapPath(int);
98 SQUIDCEXTERN int storeDirWriteCleanLogs(int reopen);
99 SQUIDCEXTERN STDIRSELECT *storeDirSelectSwapDir;
100 SQUIDCEXTERN int storeVerifySwapDirs(void);
101 SQUIDCEXTERN void storeDirCloseSwapLogs(void);
102 SQUIDCEXTERN void storeDirCloseTmpSwapLog(int dirn);
103 SQUIDCEXTERN void storeDirDiskFull(sdirno);
104 SQUIDCEXTERN void storeDirOpenSwapLogs(void);
105 SQUIDCEXTERN void storeDirSwapLog(const StoreEntry *, int op);
106 SQUIDCEXTERN void storeDirLRUDelete(StoreEntry *);
107 SQUIDCEXTERN void storeDirLRUAdd(StoreEntry *);
108 SQUIDCEXTERN int storeDirGetBlkSize(const char *path, int *blksize);
109 SQUIDCEXTERN int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
110
111
112 class SwapDir : public Store
113 {
114
115 public:
116 SwapDir(char const *aType) : theType (aType), cur_size(0), max_size(0), min_objsize(0), max_objsize(-1), cleanLog(NULL) {
117 fs.blksize = 1024;
118 path = NULL;
119 }
120
121 virtual ~SwapDir();
122 virtual void reconfigure(int, char *) = 0;
123 char const *type() const;
124
125 /* official Store interface functions */
126 virtual void diskFull();
127
128 virtual StoreEntry * get(const cache_key *);
129
130 virtual void get(String const, STOREGETCLIENT, void * cbdata);
131
132 virtual uint64_t maxSize() const { return max_size;}
133
134 virtual uint64_t minSize() const;
135 virtual void stat (StoreEntry &anEntry) const;
136 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
137
138 virtual void updateSize(int64_t size, int sign);
139
140 /* migrated from store_dir.cc */
141 bool objectSizeIsAcceptable(int64_t objsize) const;
142
143 protected:
144 void parseOptions(int reconfiguring);
145 void dumpOptions(StoreEntry * e) const;
146 virtual ConfigOption *getOptionTree() const;
147
148 private:
149 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
150 void optionReadOnlyDump(StoreEntry * e) const;
151 bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
152 void optionObjectSizeDump(StoreEntry * e) const;
153 char const *theType;
154
155 public:
156 uint64_t cur_size; ///< currently used space in the storage area
157 uint64_t max_size; ///< maximum allocatable size of the storage area
158 char *path;
159 int index; /* This entry's index into the swapDirs array */
160 int64_t min_objsize;
161 int64_t max_objsize;
162 RemovalPolicy *repl;
163 int removals;
164 int scanned;
165
166 struct Flags {
167 Flags() : selected(0), read_only(0) {}
168 unsigned int selected:1;
169 unsigned int read_only:1;
170 } flags;
171 virtual void init() = 0; /* Initialise the fs */
172 virtual void create(); /* Create a new fs */
173 virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
174 virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
175 virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
176 virtual void maintain(); /* Replacement maintainence */
177 /* <0 == error. > 1000 == error */
178 virtual int canStore(StoreEntry const &)const = 0; /* Check if the fs will store an object */
179 /* These two are notifications */
180 virtual void reference(StoreEntry &); /* Reference this object */
181 virtual void dereference(StoreEntry &); /* Unreference this object */
182 virtual int callback(); /* Handle pending callbacks */
183 virtual void sync(); /* Sync the store prior to shutdown */
184 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
185 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
186 virtual void unlink (StoreEntry &);
187 bool canLog(StoreEntry const &e)const;
188 virtual void openLog();
189 virtual void closeLog();
190 virtual void logEntry(const StoreEntry & e, int op) const;
191
192 class CleanLog
193 {
194
195 public:
196 virtual ~CleanLog() {}
197
198 virtual const StoreEntry *nextEntry() = 0;
199 virtual void write(StoreEntry const &) = 0;
200 };
201
202 CleanLog *cleanLog;
203 virtual int writeCleanStart();
204 virtual void writeCleanDone();
205 virtual void parse(int index, char *path) = 0;
206
207 struct {
208 int blksize;
209 } fs;
210 };
211
212 #endif /* SQUID_SWAPDIR_H */