]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SwapDir.h
Polish on cache_dir min-size port
[thirdparty/squid.git] / src / SwapDir.h
CommitLineData
d3b3ab85 1/*
262a0e14 2 * $Id$
d3b3ab85 3 *
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
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.
16 *
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.
26ac0430 21 *
d3b3ab85 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.
26ac0430 26 *
d3b3ab85 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.
30 *
31 */
d3b3ab85 32#ifndef SQUID_SWAPDIR_H
33#define SQUID_SWAPDIR_H
34
c8f4eac4 35#include "Store.h"
d3b3ab85 36#include "StoreIOState.h"
37
aa839030 38/* forward decls */
39class RemovalPolicy;
40
d3b3ab85 41/* Store dir configuration routines */
42/* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
62e76326 43
b9ae18aa 44class ConfigOption;
45
c8f4eac4 46/* New class that replaces the static SwapDir methods as part of the Store overhaul */
47
48class StoreController : public Store
49{
50
51public:
52 StoreController();
53 virtual ~StoreController();
54 virtual int callback();
55 virtual void create();
56
6da430a4 57 virtual StoreEntry * get(const cache_key *);
c8f4eac4 58
6da430a4 59 virtual void get(String const, STOREGETCLIENT, void * cbdata);
c8f4eac4 60
61 virtual void init();
62
63 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
64
12e11a5c 65 virtual uint64_t maxSize() const;
c8f4eac4 66
12e11a5c 67 virtual uint64_t minSize() const;
c8f4eac4 68
69 virtual void stat(StoreEntry &) const;
70
71 virtual void sync(); /* Sync the store prior to shutdown */
72
30abd221 73 virtual StoreSearch *search(String const url, HttpRequest *);
c8f4eac4 74
75 virtual void reference(StoreEntry &); /* Reference this object */
76
77 virtual void dereference(StoreEntry &); /* Unreference this object */
78
47f6e231 79 virtual void updateSize(int64_t size, int sign);
c8f4eac4 80
bef81ea5 81 /* the number of store dirs being rebuilt. */
82 static int store_dirs_rebuilding;
83
c8f4eac4 84private:
85 void createOneStore(Store &aStore);
86
87 StorePointer swapDir;
88};
89
90/* migrating from the Config based list of swapdirs */
e1f7507e
AJ
91extern void allocate_new_swapdir(SquidConfig::_cacheSwap *);
92extern void free_cachedir(SquidConfig::_cacheSwap * swap);
c8f4eac4 93SQUIDCEXTERN OBJH storeDirStats;
94SQUIDCEXTERN char *storeDirSwapLogFile(int, const char *);
95SQUIDCEXTERN char *storeSwapFullPath(int, char *);
96SQUIDCEXTERN char *storeSwapSubSubDir(int, char *);
97SQUIDCEXTERN const char *storeSwapPath(int);
98SQUIDCEXTERN int storeDirWriteCleanLogs(int reopen);
99SQUIDCEXTERN STDIRSELECT *storeDirSelectSwapDir;
100SQUIDCEXTERN int storeVerifySwapDirs(void);
101SQUIDCEXTERN void storeDirCloseSwapLogs(void);
102SQUIDCEXTERN void storeDirCloseTmpSwapLog(int dirn);
103SQUIDCEXTERN void storeDirDiskFull(sdirno);
104SQUIDCEXTERN void storeDirOpenSwapLogs(void);
105SQUIDCEXTERN void storeDirSwapLog(const StoreEntry *, int op);
106SQUIDCEXTERN void storeDirLRUDelete(StoreEntry *);
107SQUIDCEXTERN void storeDirLRUAdd(StoreEntry *);
108SQUIDCEXTERN int storeDirGetBlkSize(const char *path, int *blksize);
109SQUIDCEXTERN int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
110
111
112class SwapDir : public Store
62e76326 113{
114
d3b3ab85 115public:
b6662ffd 116 SwapDir(char const *aType) : theType (aType), cur_size(0), max_size(0), min_objsize(0), max_objsize(-1), cleanLog(NULL) {
62e76326 117 fs.blksize = 1024;
c8f4eac4 118 path = NULL;
d3b3ab85 119 }
62e76326 120
d3b3ab85 121 virtual ~SwapDir();
122 virtual void reconfigure(int, char *) = 0;
59b2d47f 123 char const *type() const;
124
c8f4eac4 125 /* official Store interface functions */
126 virtual void diskFull();
127
6da430a4 128 virtual StoreEntry * get(const cache_key *);
c8f4eac4 129
6da430a4 130 virtual void get(String const, STOREGETCLIENT, void * cbdata);
c8f4eac4 131
12e11a5c 132 virtual uint64_t maxSize() const { return max_size;}
c8f4eac4 133
12e11a5c 134 virtual uint64_t minSize() const;
c8f4eac4 135 virtual void stat (StoreEntry &anEntry) const;
30abd221 136 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
c8f4eac4 137
47f6e231 138 virtual void updateSize(int64_t size, int sign);
c8f4eac4 139
140 /* migrated from store_dir.cc */
3e62bd58 141 bool objectSizeIsAcceptable(int64_t objsize) const;
c8f4eac4 142
59b2d47f 143protected:
144 void parseOptions(int reconfiguring);
145 void dumpOptions(StoreEntry * e) const;
b9ae18aa 146 virtual ConfigOption *getOptionTree() const;
59b2d47f 147
148private:
149 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
150 void optionReadOnlyDump(StoreEntry * e) const;
a8a33c46
A
151 bool optionObjectSizeParse(char const *option, const char *value, int reconfiguring);
152 void optionObjectSizeDump(StoreEntry * e) const;
59b2d47f 153 char const *theType;
154
155public:
12e11a5c
AJ
156 uint64_t cur_size; ///< currently used space in the storage area
157 uint64_t max_size; ///< maximum allocatable size of the storage area
d3b3ab85 158 char *path;
159 int index; /* This entry's index into the swapDirs array */
a8a33c46 160 int64_t min_objsize;
47f6e231 161 int64_t max_objsize;
d3b3ab85 162 RemovalPolicy *repl;
163 int removals;
164 int scanned;
62e76326 165
26ac0430
AJ
166 struct Flags {
167 Flags() : selected(0), read_only(0) {}
3d0ac046
HN
168 unsigned int selected:1;
169 unsigned int read_only:1;
2fadd50d 170 } flags;
d3b3ab85 171 virtual void init() = 0; /* Initialise the fs */
c8f4eac4 172 virtual void create(); /* Create a new fs */
d3b3ab85 173 virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
174 virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
175 virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
c8f4eac4 176 virtual void maintain(); /* Replacement maintainence */
d3b3ab85 177 /* <0 == error. > 1000 == error */
178 virtual int canStore(StoreEntry const &)const = 0; /* Check if the fs will store an object */
179 /* These two are notifications */
180 virtual void reference(StoreEntry &); /* Reference this object */
181 virtual void dereference(StoreEntry &); /* Unreference this object */
182 virtual int callback(); /* Handle pending callbacks */
183 virtual void sync(); /* Sync the store prior to shutdown */
4fcc8876 184 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
185 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
d3b3ab85 186 virtual void unlink (StoreEntry &);
187 bool canLog(StoreEntry const &e)const;
188 virtual void openLog();
189 virtual void closeLog();
190 virtual void logEntry(const StoreEntry & e, int op) const;
62e76326 191
192 class CleanLog
193 {
194
195 public:
26ac0430 196 virtual ~CleanLog() {}
62e76326 197
198 virtual const StoreEntry *nextEntry() = 0;
199 virtual void write(StoreEntry const &) = 0;
d3b3ab85 200 };
62e76326 201
d3b3ab85 202 CleanLog *cleanLog;
203 virtual int writeCleanStart();
204 virtual void writeCleanDone();
205 virtual void parse(int index, char *path) = 0;
62e76326 206
26ac0430 207 struct {
62e76326 208 int blksize;
2fadd50d 209 } fs;
d3b3ab85 210};
62e76326 211
d3b3ab85 212#endif /* SQUID_SWAPDIR_H */