]> git.ipfire.org Git - thirdparty/squid.git/blame - src/SwapDir.h
Author: wessels & Christos Tsantilas
[thirdparty/squid.git] / src / SwapDir.h
CommitLineData
d3b3ab85 1
2/*
47f6e231 3 * $Id: SwapDir.h,v 1.14 2007/08/13 17:20:51 hno Exp $
d3b3ab85 4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34#ifndef SQUID_SWAPDIR_H
35#define SQUID_SWAPDIR_H
36
c8f4eac4 37#include "Store.h"
d3b3ab85 38#include "StoreIOState.h"
39
aa839030 40/* forward decls */
41class RemovalPolicy;
42
d3b3ab85 43/* Store dir configuration routines */
44/* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
62e76326 45
b9ae18aa 46class ConfigOption;
47
c8f4eac4 48/* New class that replaces the static SwapDir methods as part of the Store overhaul */
49
50class StoreController : public Store
51{
52
53public:
54 StoreController();
55 virtual ~StoreController();
56 virtual int callback();
57 virtual void create();
58
59 virtual StoreEntry * get
60 (const cache_key *);
61
62 virtual void get
30abd221 63 (String const, STOREGETCLIENT, void * cbdata);
c8f4eac4 64
65 virtual void init();
66
67 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
68
69 virtual size_t maxSize() const;
70
71 virtual size_t minSize() const;
72
73 virtual void stat(StoreEntry &) const;
74
75 virtual void sync(); /* Sync the store prior to shutdown */
76
30abd221 77 virtual StoreSearch *search(String const url, HttpRequest *);
c8f4eac4 78
79 virtual void reference(StoreEntry &); /* Reference this object */
80
81 virtual void dereference(StoreEntry &); /* Unreference this object */
82
47f6e231 83 virtual void updateSize(int64_t size, int sign);
c8f4eac4 84
bef81ea5 85 /* the number of store dirs being rebuilt. */
86 static int store_dirs_rebuilding;
87
c8f4eac4 88private:
89 void createOneStore(Store &aStore);
90
91 StorePointer swapDir;
92};
93
94/* migrating from the Config based list of swapdirs */
95extern void allocate_new_swapdir(_SquidConfig::_cacheSwap *);
96extern void free_cachedir(_SquidConfig::_cacheSwap * swap);
97SQUIDCEXTERN OBJH storeDirStats;
98SQUIDCEXTERN char *storeDirSwapLogFile(int, const char *);
99SQUIDCEXTERN char *storeSwapFullPath(int, char *);
100SQUIDCEXTERN char *storeSwapSubSubDir(int, char *);
101SQUIDCEXTERN const char *storeSwapPath(int);
102SQUIDCEXTERN int storeDirWriteCleanLogs(int reopen);
103SQUIDCEXTERN STDIRSELECT *storeDirSelectSwapDir;
104SQUIDCEXTERN int storeVerifySwapDirs(void);
105SQUIDCEXTERN void storeDirCloseSwapLogs(void);
106SQUIDCEXTERN void storeDirCloseTmpSwapLog(int dirn);
107SQUIDCEXTERN void storeDirDiskFull(sdirno);
108SQUIDCEXTERN void storeDirOpenSwapLogs(void);
109SQUIDCEXTERN void storeDirSwapLog(const StoreEntry *, int op);
110SQUIDCEXTERN void storeDirLRUDelete(StoreEntry *);
111SQUIDCEXTERN void storeDirLRUAdd(StoreEntry *);
112SQUIDCEXTERN int storeDirGetBlkSize(const char *path, int *blksize);
113SQUIDCEXTERN int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
114
115
116class SwapDir : public Store
62e76326 117{
118
d3b3ab85 119public:
c8f4eac4 120 SwapDir(char const *aType) : theType (aType), cur_size (0), max_size(0), max_objsize (-1), cleanLog(NULL)
62e76326 121 {
122 fs.blksize = 1024;
c8f4eac4 123 path = NULL;
d3b3ab85 124 }
62e76326 125
d3b3ab85 126 virtual ~SwapDir();
127 virtual void reconfigure(int, char *) = 0;
59b2d47f 128 char const *type() const;
129
c8f4eac4 130 /* official Store interface functions */
131 virtual void diskFull();
132
133 virtual StoreEntry * get
134 (const cache_key *);
135
136 virtual void get
30abd221 137 (String const, STOREGETCLIENT, void * cbdata);
c8f4eac4 138
139virtual size_t maxSize() const { return max_size;}
140
141 virtual size_t minSize() const;
142 virtual void stat (StoreEntry &anEntry) const;
30abd221 143 virtual StoreSearch *search(String const url, HttpRequest *) = 0;
c8f4eac4 144
47f6e231 145 virtual void updateSize(int64_t size, int sign);
c8f4eac4 146
147 /* migrated from store_dir.cc */
148 bool objectSizeIsAcceptable(ssize_t objsize) const;
149
59b2d47f 150protected:
151 void parseOptions(int reconfiguring);
152 void dumpOptions(StoreEntry * e) const;
b9ae18aa 153 virtual ConfigOption *getOptionTree() const;
59b2d47f 154
155private:
156 bool optionReadOnlyParse(char const *option, const char *value, int reconfiguring);
157 void optionReadOnlyDump(StoreEntry * e) const;
158 bool optionMaxSizeParse(char const *option, const char *value, int reconfiguring);
159 void optionMaxSizeDump(StoreEntry * e) const;
160 char const *theType;
161
162public:
d3b3ab85 163 int cur_size;
d3b3ab85 164 int max_size;
165 char *path;
166 int index; /* This entry's index into the swapDirs array */
47f6e231 167 int64_t max_objsize;
d3b3ab85 168 RemovalPolicy *repl;
169 int removals;
170 int scanned;
62e76326 171
650c4b88 172 struct Flags
62e76326 173 {
650c4b88 174 Flags() : selected(0), read_only(0){}
62e76326 175
176unsigned int selected:
177 1;
178
179unsigned int read_only:
180 1;
181 }
182
183 flags;
d3b3ab85 184 virtual void init() = 0; /* Initialise the fs */
c8f4eac4 185 virtual void create(); /* Create a new fs */
d3b3ab85 186 virtual void dump(StoreEntry &)const; /* Dump fs config snippet */
187 virtual bool doubleCheck(StoreEntry &); /* Double check the obj integrity */
188 virtual void statfs(StoreEntry &) const; /* Dump fs statistics */
c8f4eac4 189 virtual void maintain(); /* Replacement maintainence */
d3b3ab85 190 /* <0 == error. > 1000 == error */
191 virtual int canStore(StoreEntry const &)const = 0; /* Check if the fs will store an object */
192 /* These two are notifications */
193 virtual void reference(StoreEntry &); /* Reference this object */
194 virtual void dereference(StoreEntry &); /* Unreference this object */
195 virtual int callback(); /* Handle pending callbacks */
196 virtual void sync(); /* Sync the store prior to shutdown */
4fcc8876 197 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
198 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) = 0;
d3b3ab85 199 virtual void unlink (StoreEntry &);
200 bool canLog(StoreEntry const &e)const;
201 virtual void openLog();
202 virtual void closeLog();
203 virtual void logEntry(const StoreEntry & e, int op) const;
62e76326 204
205 class CleanLog
206 {
207
208 public:
209 virtual ~CleanLog(){}
210
211 virtual const StoreEntry *nextEntry() = 0;
212 virtual void write(StoreEntry const &) = 0;
d3b3ab85 213 };
62e76326 214
d3b3ab85 215 CleanLog *cleanLog;
216 virtual int writeCleanStart();
217 virtual void writeCleanDone();
218 virtual void parse(int index, char *path) = 0;
62e76326 219
220 struct
221 {
222 int blksize;
223 }
224
225 fs;
d3b3ab85 226};
62e76326 227
d3b3ab85 228#endif /* SQUID_SWAPDIR_H */