]>
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 "SquidConfig.h"
40 #include "StoreFileSystem.h"
44 SwapDir::SwapDir(char const *aType
): theType(aType
),
45 max_size(0), min_objsize(0), max_objsize (-1),
46 path(NULL
), index(-1), disker(-1),
47 repl(NULL
), removals(0), scanned(0),
55 // TODO: should we delete repl?
63 SwapDir::dump(StoreEntry
&)const {}
66 SwapDir::doubleCheck(StoreEntry
&)
72 SwapDir::unlink(StoreEntry
&) {}
75 SwapDir::getStats(StoreInfoStats
&stats
) const
80 stats
.swap
.size
= currentSize();
81 stats
.swap
.capacity
= maxSize();
82 stats
.swap
.count
= currentCount();
86 SwapDir::stat(StoreEntry
&output
) const
91 storeAppendPrintf(&output
, "Store Directory #%d (%s): %s\n", index
, type(),
93 storeAppendPrintf(&output
, "FS Block Size %d Bytes\n",
98 storeAppendPrintf(&output
, "Removal policy: %s\n", repl
->_type
);
101 repl
->Stats(repl
, &output
);
106 SwapDir::statfs(StoreEntry
&)const {}
109 SwapDir::maintain() {}
112 SwapDir::minSize() const
114 return ((maxSize() * Config
.Swap
.lowWaterMark
) / 100);
118 SwapDir::maxObjectSize() const
120 // per-store max-size=N value is authoritative
121 if (max_objsize
> -1)
124 // store with no individual max limit is limited by configured maximum_object_size
125 // or the total store size, whichever is smaller
126 return min(static_cast<int64_t>(maxSize()), Config
.Store
.maxObjectSize
);
130 SwapDir::maxObjectSize(int64_t newMax
)
132 // negative values mean no limit (-1)
134 max_objsize
= -1; // set explicitly in case it had a non-default value previously
138 // prohibit values greater than total storage area size
139 // but set max_objsize to the maximum allowed to override maximum_object_size global config
140 if (static_cast<uint64_t>(newMax
) > maxSize()) {
141 debugs(47, DBG_PARSE_NOTE(2), "WARNING: Ignoring 'max-size' option for " << path
<<
142 " which is larger than total cache_dir size of " << maxSize() << " bytes.");
143 max_objsize
= maxSize();
147 max_objsize
= newMax
;
151 SwapDir::reference(StoreEntry
&) {}
154 SwapDir::dereference(StoreEntry
&, bool)
156 return true; // keep in global store_table
166 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
168 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
169 diskSpaceNeeded
<< " <? " << max_objsize
);
171 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
172 return false; // we do not store Squid-generated entries
174 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
175 return false; // does not satisfy size limits
178 return false; // cannot write at all
180 if (currentSize() > maxSize())
181 return false; // already overflowing
183 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
185 return true; // kids may provide more tests and should report true load
191 /* Move to StoreEntry ? */
193 SwapDir::canLog(StoreEntry
const &e
)const
195 if (e
.swap_filen
< 0)
198 if (e
.swap_status
!= SWAPOUT_DONE
)
201 if (e
.swap_file_sz
<= 0)
204 if (EBIT_TEST(e
.flags
, RELEASE_REQUEST
))
207 if (EBIT_TEST(e
.flags
, KEY_PRIVATE
))
210 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
217 SwapDir::openLog() {}
220 SwapDir::closeLog() {}
223 SwapDir::writeCleanStart()
229 SwapDir::writeCleanDone() {}
232 SwapDir::logEntry(const StoreEntry
& e
, int op
) const {}
235 SwapDir::type() const
241 SwapDir::active() const
243 if (IamWorkerProcess())
246 // we are inside a disker dedicated to this disk
247 if (KidIdentifier
== disker
)
250 return false; // Coordinator, wrong disker, etc.
254 SwapDir::needsDiskStrand() const
259 /* NOT performance critical. Really. Don't bother optimising for speed
263 SwapDir::getOptionTree() const
265 ConfigOptionVector
*result
= new ConfigOptionVector
;
266 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionReadOnlyParse
, &SwapDir::optionReadOnlyDump
));
267 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionObjectSizeParse
, &SwapDir::optionObjectSizeDump
));
272 SwapDir::parseOptions(int isaReconfig
)
274 const bool old_read_only
= flags
.read_only
;
277 ConfigOption
*newOption
= getOptionTree();
279 while ((name
= strtok(NULL
, w_space
)) != NULL
) {
280 value
= strchr(name
, '=');
283 *value
= '\0'; /* cut on = */
287 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
290 if (!newOption
->parse(name
, value
, isaReconfig
))
297 * Handle notifications about reconfigured single-options with no value
298 * where the removal of the option cannot be easily detected in the
303 if (old_read_only
!= flags
.read_only
) {
304 debugs(3, DBG_IMPORTANT
, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
310 SwapDir::dumpOptions(StoreEntry
* entry
) const
312 ConfigOption
*newOption
= getOptionTree();
315 newOption
->dump(entry
);
321 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
323 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
326 if (strcmp(option
, "read-only") == 0) {
327 debugs(3, DBG_PARSE_NOTE(3), "UPGRADE WARNING: Replace cache_dir option 'read-only' with 'no-store'.");
333 read_only
= (xatoi(value
) != 0);
337 flags
.read_only
= read_only
;
343 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
346 storeAppendPrintf(e
, " no-store");
350 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
353 if (strcmp(option
, "max-size") == 0) {
355 } else if (strcmp(option
, "min-size") == 0) {
363 int64_t size
= strtoll(value
, NULL
, 10);
365 if (isaReconfig
&& *val
!= size
) {
366 if (allowOptionReconfigure(option
)) {
367 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
368 option
<< " now " << size
<< " Bytes");
370 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
371 "object " << option
<< " cannot be changed dynamically, " <<
372 "value left unchanged (" << *val
<< " Bytes)");
383 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
385 if (min_objsize
!= 0)
386 storeAppendPrintf(e
, " min-size=%" PRId64
, min_objsize
);
388 if (max_objsize
!= -1)
389 storeAppendPrintf(e
, " max-size=%" PRId64
, max_objsize
);
392 // some SwapDirs may maintain their indexes and be able to lookup an entry key
394 SwapDir::get(const cache_key
*key
)
400 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
402 fatal("not implemented");