]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.cc
2 * DEBUG: section 20 Swap Dir base object
3 * AUTHOR: Robert Collins
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
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.
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.
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.
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.
35 #include "compat/strtoll.h"
36 #include "ConfigOption.h"
39 #include "StoreFileSystem.h"
43 SwapDir::SwapDir(char const *aType
): theType(aType
),
45 path(NULL
), index(-1), disker(-1), min_objsize(0), max_objsize (-1),
46 repl(NULL
), removals(0), scanned(0),
54 // TODO: should we delete repl?
62 SwapDir::dump(StoreEntry
&)const {}
65 SwapDir::doubleCheck(StoreEntry
&)
71 SwapDir::unlink(StoreEntry
&) {}
74 SwapDir::getStats(StoreInfoStats
&stats
) const
79 stats
.swap
.size
= currentSize();
80 stats
.swap
.capacity
= maxSize();
81 stats
.swap
.count
= currentCount();
85 SwapDir::stat(StoreEntry
&output
) const
90 storeAppendPrintf(&output
, "Store Directory #%d (%s): %s\n", index
, type(),
92 storeAppendPrintf(&output
, "FS Block Size %d Bytes\n",
97 storeAppendPrintf(&output
, "Removal policy: %s\n", repl
->_type
);
100 repl
->Stats(repl
, &output
);
105 SwapDir::statfs(StoreEntry
&)const {}
108 SwapDir::maintain() {}
111 SwapDir::minSize() const
113 return ((maxSize() * Config
.Swap
.lowWaterMark
) / 100);
117 SwapDir::reference(StoreEntry
&) {}
120 SwapDir::dereference(StoreEntry
&)
122 return true; // keep in global store_table
132 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
134 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
135 diskSpaceNeeded
<< " <? " << max_objsize
);
137 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
138 return false; // we do not store Squid-generated entries
140 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
141 return false; // does not satisfy size limits
144 return false; // cannot write at all
146 if (currentSize() > maxSize())
147 return false; // already overflowing
149 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
151 return true; // kids may provide more tests and should report true load
157 /* Move to StoreEntry ? */
159 SwapDir::canLog(StoreEntry
const &e
)const
161 if (e
.swap_filen
< 0)
164 if (e
.swap_status
!= SWAPOUT_DONE
)
167 if (e
.swap_file_sz
<= 0)
170 if (EBIT_TEST(e
.flags
, RELEASE_REQUEST
))
173 if (EBIT_TEST(e
.flags
, KEY_PRIVATE
))
176 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
183 SwapDir::openLog() {}
186 SwapDir::closeLog() {}
189 SwapDir::writeCleanStart()
195 SwapDir::writeCleanDone() {}
198 SwapDir::logEntry(const StoreEntry
& e
, int op
) const {}
201 SwapDir::type() const
207 SwapDir::active() const
209 if (IamWorkerProcess())
212 // we are inside a disker dedicated to this disk
213 if (KidIdentifier
== disker
)
216 return false; // Coordinator, wrong disker, etc.
220 SwapDir::needsDiskStrand() const
225 /* NOT performance critical. Really. Don't bother optimising for speed
229 SwapDir::getOptionTree() const
231 ConfigOptionVector
*result
= new ConfigOptionVector
;
232 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionReadOnlyParse
, &SwapDir::optionReadOnlyDump
));
233 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionObjectSizeParse
, &SwapDir::optionObjectSizeDump
));
238 SwapDir::parseOptions(int isaReconfig
)
240 unsigned int old_read_only
= flags
.read_only
;
243 ConfigOption
*newOption
= getOptionTree();
245 while ((name
= strtok(NULL
, w_space
)) != NULL
) {
246 value
= strchr(name
, '=');
249 *value
= '\0'; /* cut on = */
253 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
256 if (!newOption
->parse(name
, value
, isaReconfig
))
263 * Handle notifications about reconfigured single-options with no value
264 * where the removal of the option cannot be easily detected in the
269 if (old_read_only
!= flags
.read_only
) {
270 debugs(3, DBG_IMPORTANT
, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
276 SwapDir::dumpOptions(StoreEntry
* entry
) const
278 ConfigOption
*newOption
= getOptionTree();
281 newOption
->dump(entry
);
287 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
289 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
295 read_only
= xatoi(value
);
299 flags
.read_only
= read_only
;
305 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
308 storeAppendPrintf(e
, " no-store");
312 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
315 if (strcmp(option
, "max-size") == 0) {
317 } else if (strcmp(option
, "min-size") == 0) {
325 int64_t size
= strtoll(value
, NULL
, 10);
327 if (isaReconfig
&& *val
!= size
) {
328 if (allowOptionReconfigure(option
)) {
329 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
330 option
<< " now " << size
<< " Bytes");
332 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
333 "object " << option
<< " cannot be changed dynamically, " <<
334 "value left unchanged (" << *val
<< " Bytes)");
345 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
347 if (min_objsize
!= 0)
348 storeAppendPrintf(e
, " min-size=%" PRId64
, min_objsize
);
350 if (max_objsize
!= -1)
351 storeAppendPrintf(e
, " max-size=%" PRId64
, max_objsize
);
354 // some SwapDirs may maintain their indexes and be able to lookup an entry key
356 SwapDir::get(const cache_key
*key
)
362 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
364 fatal("not implemented");