]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.cc
33b5a4dadae6ce06e706412a3570c560c2487a86
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"
38 #include "StoreFileSystem.h"
39 #include "ConfigOption.h"
41 SwapDir::SwapDir(char const *aType
): theType(aType
),
43 path(NULL
), index(-1), disker(-1), min_objsize(0), max_objsize (-1),
44 repl(NULL
), removals(0), scanned(0),
52 // TODO: should we delete repl?
60 SwapDir::dump(StoreEntry
&)const {}
63 SwapDir::doubleCheck(StoreEntry
&)
69 SwapDir::unlink(StoreEntry
&) {}
72 SwapDir::getStats(StoreInfoStats
&stats
) const
77 stats
.swap
.size
= currentSize();
78 stats
.swap
.capacity
= maxSize();
79 stats
.swap
.count
= currentCount();
83 SwapDir::stat(StoreEntry
&output
) const
88 storeAppendPrintf(&output
, "Store Directory #%d (%s): %s\n", index
, type(),
90 storeAppendPrintf(&output
, "FS Block Size %d Bytes\n",
95 storeAppendPrintf(&output
, "Removal policy: %s\n", repl
->_type
);
98 repl
->Stats(repl
, &output
);
103 SwapDir::statfs(StoreEntry
&)const {}
106 SwapDir::maintain() {}
109 SwapDir::minSize() const
111 return ((maxSize() * Config
.Swap
.lowWaterMark
) / 100);
115 SwapDir::reference(StoreEntry
&) {}
118 SwapDir::dereference(StoreEntry
&)
120 return true; // keep in global store_table
130 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
132 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
133 diskSpaceNeeded
<< " <? " << max_objsize
);
135 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
136 return false; // we do not store Squid-generated entries
138 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
139 return false; // does not satisfy size limits
142 return false; // cannot write at all
144 if (currentSize() > maxSize())
145 return false; // already overflowing
147 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
149 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 = */
250 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
253 if (!newOption
->parse(name
, value
, isaReconfig
))
260 * Handle notifications about reconfigured single-options with no value
261 * where the removal of the option cannot be easily detected in the
266 if (old_read_only
!= flags
.read_only
) {
267 debugs(3, 1, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
273 SwapDir::dumpOptions(StoreEntry
* entry
) const
275 ConfigOption
*newOption
= getOptionTree();
278 newOption
->dump(entry
);
284 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
286 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
292 read_only
= xatoi(value
);
296 flags
.read_only
= read_only
;
302 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
305 storeAppendPrintf(e
, " no-store");
309 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
312 if (strcmp(option
, "max-size") == 0) {
314 } else if (strcmp(option
, "min-size") == 0) {
322 int64_t size
= strtoll(value
, NULL
, 10);
324 if (isaReconfig
&& *val
!= size
) {
325 if (allowOptionReconfigure(option
)) {
326 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
327 option
<< " now " << size
<< " Bytes");
329 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
330 "object " << option
<< " cannot be changed dynamically, " <<
331 "value left unchanged (" << *val
<< " Bytes)");
342 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
344 if (min_objsize
!= 0)
345 storeAppendPrintf(e
, " min-size=%"PRId64
, min_objsize
);
347 if (max_objsize
!= -1)
348 storeAppendPrintf(e
, " max-size=%"PRId64
, max_objsize
);
351 // some SwapDirs may maintain their indexes and be able to lookup an entry key
353 SwapDir::get(const cache_key
*key
)
359 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
361 fatal("not implemented");