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