]>
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.
37 #include "compat/strtoll.h"
38 #include "ConfigOption.h"
41 #include "StoreFileSystem.h"
44 SwapDir::SwapDir(char const *aType
): theType(aType
),
46 path(NULL
), index(-1), disker(-1), min_objsize(0), max_objsize (-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::reference(StoreEntry
&) {}
121 SwapDir::dereference(StoreEntry
&)
123 return true; // keep in global store_table
133 SwapDir::canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const
135 debugs(47,8, HERE
<< "cache_dir[" << index
<< "]: needs " <<
136 diskSpaceNeeded
<< " <? " << max_objsize
);
138 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
139 return false; // we do not store Squid-generated entries
141 if (!objectSizeIsAcceptable(diskSpaceNeeded
))
142 return false; // does not satisfy size limits
145 return false; // cannot write at all
147 if (currentSize() > maxSize())
148 return false; // already overflowing
150 /* Return 999 (99.9%) constant load; TODO: add a named constant for this */
152 return true; // kids may provide more tests and should report true load
159 /* Move to StoreEntry ? */
161 SwapDir::canLog(StoreEntry
const &e
)const
163 if (e
.swap_filen
< 0)
166 if (e
.swap_status
!= SWAPOUT_DONE
)
169 if (e
.swap_file_sz
<= 0)
172 if (EBIT_TEST(e
.flags
, RELEASE_REQUEST
))
175 if (EBIT_TEST(e
.flags
, KEY_PRIVATE
))
178 if (EBIT_TEST(e
.flags
, ENTRY_SPECIAL
))
185 SwapDir::openLog() {}
188 SwapDir::closeLog() {}
191 SwapDir::writeCleanStart()
197 SwapDir::writeCleanDone() {}
200 SwapDir::logEntry(const StoreEntry
& e
, int op
) const {}
203 SwapDir::type() const
209 SwapDir::active() const
211 if (IamWorkerProcess())
214 // we are inside a disker dedicated to this disk
215 if (KidIdentifier
== disker
)
218 return false; // Coordinator, wrong disker, etc.
222 SwapDir::needsDiskStrand() const
227 /* NOT performance critical. Really. Don't bother optimising for speed
231 SwapDir::getOptionTree() const
233 ConfigOptionVector
*result
= new ConfigOptionVector
;
234 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionReadOnlyParse
, &SwapDir::optionReadOnlyDump
));
235 result
->options
.push_back(new ConfigOptionAdapter
<SwapDir
>(*const_cast<SwapDir
*>(this), &SwapDir::optionObjectSizeParse
, &SwapDir::optionObjectSizeDump
));
240 SwapDir::parseOptions(int isaReconfig
)
242 unsigned int old_read_only
= flags
.read_only
;
245 ConfigOption
*newOption
= getOptionTree();
247 while ((name
= strtok(NULL
, w_space
)) != NULL
) {
248 value
= strchr(name
, '=');
251 *value
= '\0'; /* cut on = */
255 debugs(3,2, "SwapDir::parseOptions: parsing store option '" << name
<< "'='" << (value
? value
: "") << "'");
258 if (!newOption
->parse(name
, value
, isaReconfig
))
265 * Handle notifications about reconfigured single-options with no value
266 * where the removal of the option cannot be easily detected in the
271 if (old_read_only
!= flags
.read_only
) {
272 debugs(3, DBG_IMPORTANT
, "Cache dir '" << path
<< "' now " << (flags
.read_only
? "No-Store" : "Read-Write"));
278 SwapDir::dumpOptions(StoreEntry
* entry
) const
280 ConfigOption
*newOption
= getOptionTree();
283 newOption
->dump(entry
);
289 SwapDir::optionReadOnlyParse(char const *option
, const char *value
, int isaReconfig
)
291 if (strcmp(option
, "no-store") != 0 && strcmp(option
, "read-only") != 0)
297 read_only
= xatoi(value
);
301 flags
.read_only
= read_only
;
307 SwapDir::optionReadOnlyDump(StoreEntry
* e
) const
310 storeAppendPrintf(e
, " no-store");
314 SwapDir::optionObjectSizeParse(char const *option
, const char *value
, int isaReconfig
)
317 if (strcmp(option
, "max-size") == 0) {
319 } else if (strcmp(option
, "min-size") == 0) {
327 int64_t size
= strtoll(value
, NULL
, 10);
329 if (isaReconfig
&& *val
!= size
) {
330 if (allowOptionReconfigure(option
)) {
331 debugs(3, DBG_IMPORTANT
, "cache_dir '" << path
<< "' object " <<
332 option
<< " now " << size
<< " Bytes");
334 debugs(3, DBG_IMPORTANT
, "WARNING: cache_dir '" << path
<< "' "
335 "object " << option
<< " cannot be changed dynamically, " <<
336 "value left unchanged (" << *val
<< " Bytes)");
347 SwapDir::optionObjectSizeDump(StoreEntry
* e
) const
349 if (min_objsize
!= 0)
350 storeAppendPrintf(e
, " min-size=%" PRId64
, min_objsize
);
352 if (max_objsize
!= -1)
353 storeAppendPrintf(e
, " max-size=%" PRId64
, max_objsize
);
356 // some SwapDirs may maintain their indexes and be able to lookup an entry key
358 SwapDir::get(const cache_key
*key
)
364 SwapDir::get(String
const key
, STOREGETCLIENT aCallback
, void *aCallbackData
)
366 fatal("not implemented");