]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.cc
4 * DEBUG: section 20 Swap Dir base object
5 * AUTHOR: Robert Collins
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
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.
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.
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.
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.
36 #include "compat/strtoll.h"
37 #include "ConfigOption.h"
39 #include "StoreFileSystem.h"
42 SwapDir::SwapDir(char const *aType
): theType(aType
),
44 path(NULL
), index(-1), disker(-1), min_objsize(0), max_objsize (-1),
45 repl(NULL
), removals(0), scanned(0),
53 // TODO: should we delete repl?
61 SwapDir::dump(StoreEntry
&)const {}
64 SwapDir::doubleCheck(StoreEntry
&)
70 SwapDir::unlink(StoreEntry
&) {}
73 SwapDir::getStats(StoreInfoStats
&stats
) const
78 stats
.swap
.size
= currentSize();
79 stats
.swap
.capacity
= maxSize();
80 stats
.swap
.count
= currentCount();
84 SwapDir::stat(StoreEntry
&output
) const
89 storeAppendPrintf(&output
, "Store Directory #%d (%s): %s\n", index
, type(),
91 storeAppendPrintf(&output
, "FS Block Size %d Bytes\n",
96 storeAppendPrintf(&output
, "Removal policy: %s\n", repl
->_type
);
99 repl
->Stats(repl
, &output
);
104 SwapDir::statfs(StoreEntry
&)const {}
107 SwapDir::maintain() {}
110 SwapDir::minSize() const
112 return ((maxSize() * Config
.Swap
.lowWaterMark
) / 100);
116 SwapDir::reference(StoreEntry
&) {}
119 SwapDir::dereference(StoreEntry
&)
121 return true; // keep in global store_table
131 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
133 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
134 diskSpaceNeeded
<< " <? " << max_objsize
);
136 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
137 return false; // we do not store Squid-generated entries
139 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
140 return false; // does not satisfy size limits
143 return false; // cannot write at all
145 if (currentSize() > maxSize())
146 return false; // already overflowing
148 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
150 return true; // kids may provide more tests and should report true load
156 /* Move to StoreEntry ? */
158 SwapDir::canLog(StoreEntry
const &e
)const
160 if (e
.swap_filen
< 0)
163 if (e
.swap_status
!= SWAPOUT_DONE
)
166 if (e
.swap_file_sz
<= 0)
169 if (EBIT_TEST(e
.flags
, RELEASE_REQUEST
))
172 if (EBIT_TEST(e
.flags
, KEY_PRIVATE
))
175 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
182 SwapDir::openLog() {}
185 SwapDir::closeLog() {}
188 SwapDir::writeCleanStart()
194 SwapDir::writeCleanDone() {}
197 SwapDir::logEntry(const StoreEntry
& e
, int op
) const {}
200 SwapDir::type() const
206 SwapDir::active() const
208 if (IamWorkerProcess())
211 // we are inside a disker dedicated to this disk
212 if (KidIdentifier
== disker
)
215 return false; // Coordinator, wrong disker, etc.
219 SwapDir::needsDiskStrand() const
224 /* NOT performance critical. Really. Don't bother optimising for speed
228 SwapDir::getOptionTree() const
230 ConfigOptionVector
*result
= new ConfigOptionVector
;
231 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionReadOnlyParse
, &SwapDir::optionReadOnlyDump
));
232 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionObjectSizeParse
, &SwapDir::optionObjectSizeDump
));
237 SwapDir::parseOptions(int isaReconfig
)
239 unsigned int old_read_only
= flags
.read_only
;
242 ConfigOption
*newOption
= getOptionTree();
244 while ((name
= strtok(NULL
, w_space
)) != NULL
) {
245 value
= strchr(name
, '=');
248 *value
= '\0'; /* cut on = */
252 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
255 if (!newOption
->parse(name
, value
, isaReconfig
))
262 * Handle notifications about reconfigured single-options with no value
263 * where the removal of the option cannot be easily detected in the
268 if (old_read_only
!= flags
.read_only
) {
269 debugs(3, DBG_IMPORTANT
, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
275 SwapDir::dumpOptions(StoreEntry
* entry
) const
277 ConfigOption
*newOption
= getOptionTree();
280 newOption
->dump(entry
);
286 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
288 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
294 read_only
= xatoi(value
);
298 flags
.read_only
= read_only
;
304 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
307 storeAppendPrintf(e
, " no-store");
311 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
314 if (strcmp(option
, "max-size") == 0) {
316 } else if (strcmp(option
, "min-size") == 0) {
324 int64_t size
= strtoll(value
, NULL
, 10);
326 if (isaReconfig
&& *val
!= size
) {
327 if (allowOptionReconfigure(option
)) {
328 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
329 option
<< " now " << size
<< " Bytes");
331 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
332 "object " << option
<< " cannot be changed dynamically, " <<
333 "value left unchanged (" << *val
<< " Bytes)");
344 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
346 if (min_objsize
!= 0)
347 storeAppendPrintf(e
, " min-size=%" PRId64
, min_objsize
);
349 if (max_objsize
!= -1)
350 storeAppendPrintf(e
, " max-size=%" PRId64
, max_objsize
);
353 // some SwapDirs may maintain their indexes and be able to lookup an entry key
355 SwapDir::get(const cache_key
*key
)
361 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
363 fatal("not implemented");