]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 20 Swap Dir base object */
13 #include "compat/strtoll.h"
14 #include "ConfigOption.h"
15 #include "ConfigParser.h"
18 #include "SquidConfig.h"
19 #include "StoreFileSystem.h"
23 SwapDir::SwapDir(char const *aType
): theType(aType
),
24 max_size(0), min_objsize(0), max_objsize (-1),
25 path(NULL
), index(-1), disker(-1),
26 repl(NULL
), removals(0), scanned(0),
34 // TODO: should we delete repl?
42 SwapDir::dump(StoreEntry
&)const {}
45 SwapDir::doubleCheck(StoreEntry
&)
51 SwapDir::unlink(StoreEntry
&) {}
54 SwapDir::getStats(StoreInfoStats
&stats
) const
59 stats
.swap
.size
= currentSize();
60 stats
.swap
.capacity
= maxSize();
61 stats
.swap
.count
= currentCount();
65 SwapDir::stat(StoreEntry
&output
) const
70 storeAppendPrintf(&output
, "Store Directory #%d (%s): %s\n", index
, type(),
72 storeAppendPrintf(&output
, "FS Block Size %d Bytes\n",
77 storeAppendPrintf(&output
, "Removal policy: %s\n", repl
->_type
);
80 repl
->Stats(repl
, &output
);
85 SwapDir::statfs(StoreEntry
&)const {}
88 SwapDir::maintain() {}
91 SwapDir::minSize() const
93 return ((maxSize() * Config
.Swap
.lowWaterMark
) / 100);
97 SwapDir::maxObjectSize() const
99 // per-store max-size=N value is authoritative
100 if (max_objsize
> -1)
103 // store with no individual max limit is limited by configured maximum_object_size
104 // or the total store size, whichever is smaller
105 return min(static_cast<int64_t>(maxSize()), Config
.Store
.maxObjectSize
);
109 SwapDir::maxObjectSize(int64_t newMax
)
111 // negative values mean no limit (-1)
113 max_objsize
= -1; // set explicitly in case it had a non-default value previously
117 // prohibit values greater than total storage area size
118 // but set max_objsize to the maximum allowed to override maximum_object_size global config
119 if (static_cast<uint64_t>(newMax
) > maxSize()) {
120 debugs(47, DBG_PARSE_NOTE(2), "WARNING: Ignoring 'max-size' option for " << path
<<
121 " which is larger than total cache_dir size of " << maxSize() << " bytes.");
122 max_objsize
= maxSize();
126 max_objsize
= newMax
;
130 SwapDir::reference(StoreEntry
&) {}
133 SwapDir::dereference(StoreEntry
&, bool)
135 return true; // keep in global store_table
145 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
147 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
148 diskSpaceNeeded
<< " <? " << max_objsize
);
150 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
151 return false; // we do not store Squid-generated entries
153 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
154 return false; // does not satisfy size limits
157 return false; // cannot write at all
159 if (currentSize() > maxSize())
160 return false; // already overflowing
162 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
164 return true; // kids may provide more tests and should report true load
170 /* Move to StoreEntry ? */
172 SwapDir::canLog(StoreEntry
const &e
)const
174 if (e
.swap_filen
< 0)
177 if (e
.swap_status
!= SWAPOUT_DONE
)
180 if (e
.swap_file_sz
<= 0)
183 if (EBIT_TEST(e
.flags
, RELEASE_REQUEST
))
186 if (EBIT_TEST(e
.flags
, KEY_PRIVATE
))
189 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
196 SwapDir::openLog() {}
199 SwapDir::closeLog() {}
202 SwapDir::writeCleanStart()
208 SwapDir::writeCleanDone() {}
211 SwapDir::logEntry(const StoreEntry
& e
, int op
) const {}
214 SwapDir::type() const
220 SwapDir::active() const
222 if (IamWorkerProcess())
225 // we are inside a disker dedicated to this disk
226 if (KidIdentifier
== disker
)
229 return false; // Coordinator, wrong disker, etc.
233 SwapDir::needsDiskStrand() const
238 /* NOT performance critical. Really. Don't bother optimising for speed
242 SwapDir::getOptionTree() const
244 ConfigOptionVector
*result
= new ConfigOptionVector
;
245 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionReadOnlyParse
, &SwapDir::optionReadOnlyDump
));
246 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionObjectSizeParse
, &SwapDir::optionObjectSizeDump
));
251 SwapDir::parseOptions(int isaReconfig
)
253 const bool old_read_only
= flags
.read_only
;
256 ConfigOption
*newOption
= getOptionTree();
258 while ((name
= ConfigParser::NextToken()) != NULL
) {
259 value
= strchr(name
, '=');
262 *value
= '\0'; /* cut on = */
266 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
269 if (!newOption
->parse(name
, value
, isaReconfig
))
276 * Handle notifications about reconfigured single-options with no value
277 * where the removal of the option cannot be easily detected in the
282 if (old_read_only
!= flags
.read_only
) {
283 debugs(3, DBG_IMPORTANT
, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
289 SwapDir::dumpOptions(StoreEntry
* entry
) const
291 ConfigOption
*newOption
= getOptionTree();
294 newOption
->dump(entry
);
300 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
302 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
305 if (strcmp(option
, "read-only") == 0) {
306 debugs(3, DBG_PARSE_NOTE(3), "UPGRADE WARNING: Replace cache_dir option 'read-only' with 'no-store'.");
312 read_only
= (xatoi(value
) != 0);
316 flags
.read_only
= read_only
;
322 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
325 storeAppendPrintf(e
, " no-store");
329 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
332 if (strcmp(option
, "max-size") == 0) {
334 } else if (strcmp(option
, "min-size") == 0) {
342 int64_t size
= strtoll(value
, NULL
, 10);
344 if (isaReconfig
&& *val
!= size
) {
345 if (allowOptionReconfigure(option
)) {
346 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
347 option
<< " now " << size
<< " Bytes");
349 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
350 "object " << option
<< " cannot be changed dynamically, " <<
351 "value left unchanged (" << *val
<< " Bytes)");
362 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
364 if (min_objsize
!= 0)
365 storeAppendPrintf(e
, " min-size=%" PRId64
, min_objsize
);
367 if (max_objsize
!= -1)
368 storeAppendPrintf(e
, " max-size=%" PRId64
, max_objsize
);
371 // some SwapDirs may maintain their indexes and be able to lookup an entry key
373 SwapDir::get(const cache_key
*key
)
379 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
381 fatal("not implemented");