]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / SwapDir.cc
1
2 /*
3 * $Id$
4 *
5 * DEBUG: section 20 Swap Dir base object
6 * AUTHOR: Robert Collins
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37 #include "SwapDir.h"
38 #include "StoreFileSystem.h"
39 #include "ConfigOption.h"
40
41 SwapDir::~SwapDir()
42 {
43 xfree(path);
44 }
45
46 void
47 SwapDir::create() {}
48
49 void
50 SwapDir::dump(StoreEntry &)const {}
51
52 bool
53 SwapDir::doubleCheck(StoreEntry &)
54 {
55 return false;
56 }
57
58 void
59 SwapDir::unlink(StoreEntry &) {}
60
61 void
62 SwapDir::stat(StoreEntry &output) const
63 {
64 storeAppendPrintf(&output, "Store Directory #%d (%s): %s\n", index, type(),
65 path);
66 storeAppendPrintf(&output, "FS Block Size %d Bytes\n",
67 fs.blksize);
68 statfs(output);
69
70 if (repl) {
71 storeAppendPrintf(&output, "Removal policy: %s\n", repl->_type);
72
73 if (repl->Stats)
74 repl->Stats(repl, &output);
75 }
76 }
77
78 void
79 SwapDir::statfs(StoreEntry &)const {}
80
81 void
82 SwapDir::maintain() {}
83
84 size_t
85 SwapDir::minSize() const
86 {
87 return (size_t) (((float) maxSize() *
88 (float) Config.Swap.lowWaterMark) / 100.0);
89 }
90
91 void
92 SwapDir::reference(StoreEntry &) {}
93
94 void
95 SwapDir::dereference(StoreEntry &) {}
96
97 int
98 SwapDir::callback()
99 {
100 return 0;
101 }
102
103 void
104 SwapDir::sync() {}
105
106 /* Move to StoreEntry ? */
107 bool
108 SwapDir::canLog(StoreEntry const &e)const
109 {
110 if (e.swap_filen < 0)
111 return false;
112
113 if (e.swap_status != SWAPOUT_DONE)
114 return false;
115
116 if (e.swap_file_sz <= 0)
117 return false;
118
119 if (EBIT_TEST(e.flags, RELEASE_REQUEST))
120 return false;
121
122 if (EBIT_TEST(e.flags, KEY_PRIVATE))
123 return false;
124
125 if (EBIT_TEST(e.flags, ENTRY_SPECIAL))
126 return false;
127
128 return true;
129 }
130
131 void
132 SwapDir::openLog() {}
133
134 void
135 SwapDir::closeLog() {}
136
137 int
138 SwapDir::writeCleanStart()
139 {
140 return 0;
141 }
142
143 void
144 SwapDir::writeCleanDone() {}
145
146 void
147 SwapDir::logEntry(const StoreEntry & e, int op) const {}
148
149 char const *
150 SwapDir::type() const
151 {
152 return theType;
153 }
154
155 /* NOT performance critical. Really. Don't bother optimising for speed
156 * - RBC 20030718
157 */
158 ConfigOption *
159 SwapDir::getOptionTree() const
160 {
161 ConfigOptionVector *result = new ConfigOptionVector;
162 result->options.push_back(new ConfigOptionAdapter<SwapDir>(*const_cast<SwapDir *>(this), &SwapDir::optionReadOnlyParse, &SwapDir::optionReadOnlyDump));
163 result->options.push_back(new ConfigOptionAdapter<SwapDir>(*const_cast<SwapDir *>(this), &SwapDir::optionMaxSizeParse, &SwapDir::optionMaxSizeDump));
164 return result;
165 }
166
167 void
168 SwapDir::parseOptions(int reconfiguring)
169 {
170 unsigned int old_read_only = flags.read_only;
171 char *name, *value;
172
173 ConfigOption *newOption = getOptionTree();
174
175 while ((name = strtok(NULL, w_space)) != NULL) {
176 value = strchr(name, '=');
177
178 if (value)
179 *value++ = '\0'; /* cut on = */
180
181 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name << "'='" << (value ? value : "") << "'");
182
183 if (newOption)
184 if (!newOption->parse(name, value, reconfiguring))
185 self_destruct();
186 }
187
188 delete newOption;
189
190 /*
191 * Handle notifications about reconfigured single-options with no value
192 * where the removal of the option cannot be easily detected in the
193 * parsing...
194 */
195
196 if (reconfiguring) {
197 if (old_read_only != flags.read_only) {
198 debugs(3, 1, "Cache dir '" << path << "' now " << (flags.read_only ? "No-Store" : "Read-Write"));
199 }
200 }
201 }
202
203 void
204 SwapDir::dumpOptions(StoreEntry * entry) const
205 {
206 ConfigOption *newOption = getOptionTree();
207
208 if (newOption)
209 newOption->dump(entry);
210
211 delete newOption;
212 }
213
214 bool
215 SwapDir::optionReadOnlyParse(char const *option, const char *value, int reconfiguring)
216 {
217 if (strcmp(option, "no-store") != 0 && strcmp(option, "read-only") != 0)
218 return false;
219
220 int read_only = 0;
221
222 if (value)
223 read_only = xatoi(value);
224 else
225 read_only = 1;
226
227 flags.read_only = read_only;
228
229 return true;
230 }
231
232 void
233 SwapDir::optionReadOnlyDump(StoreEntry * e) const
234 {
235 if (flags.read_only)
236 storeAppendPrintf(e, " no-store");
237 }
238
239 bool
240 SwapDir::optionMaxSizeParse(char const *option, const char *value, int reconfiguring)
241 {
242 if (strcmp(option, "max-size") != 0)
243 return false;
244
245 if (!value)
246 self_destruct();
247
248 int64_t size = strtoll(value, NULL, 10);
249
250 if (reconfiguring && max_objsize != size)
251 debugs(3, 1, "Cache dir '" << path << "' max object size now " << size);
252
253 max_objsize = size;
254
255 return true;
256 }
257
258 void
259 SwapDir::optionMaxSizeDump(StoreEntry * e) const
260 {
261 if (max_objsize != -1)
262 storeAppendPrintf(e, " max-size=%"PRId64, max_objsize);
263 }
264
265 /* Swapdirs do not have an index of their own - thus they ask their parent..
266 * but the parent child relationship isn't implemented yet
267 */
268 StoreEntry *
269
270 SwapDir::get
271 (const cache_key *key)
272 {
273 return Store::Root().get(key);
274 }
275
276 void
277
278 SwapDir::get
279 (String const key, STOREGETCLIENT callback, void *cbdata)
280 {
281 fatal("not implemented");
282 }