]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.h
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 #ifndef SQUID_SWAPDIR_H
31 #define SQUID_SWAPDIR_H
33 #include "SquidConfig.h"
35 #include "StoreIOState.h"
42 class HttpRequestMethod
;
44 /* Store dir configuration routines */
45 /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
49 /// hides memory/disk cache distinction from callers
50 class StoreController
: public Store
55 virtual ~StoreController();
56 virtual int callback();
57 virtual void create();
59 virtual StoreEntry
* get(const cache_key
*);
61 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
63 /* Store parent API */
64 virtual void markForUnlink(StoreEntry
&e
);
65 virtual void handleIdleEntry(StoreEntry
&e
);
66 virtual void transientsCompleteWriting(StoreEntry
&e
);
67 virtual void transientsAbandon(StoreEntry
&e
);
68 virtual int transientReaders(const StoreEntry
&e
) const;
69 virtual void transientsDisconnect(MemObject
&mem_obj
);
70 virtual void memoryOut(StoreEntry
&e
, const bool preserveSwappable
);
71 virtual void memoryUnlink(StoreEntry
&e
);
72 virtual void memoryDisconnect(StoreEntry
&e
);
73 virtual void allowCollapsing(StoreEntry
*e
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
74 virtual void syncCollapsed(const sfileno xitIndex
);
78 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
80 virtual uint64_t maxSize() const;
82 virtual uint64_t minSize() const;
84 virtual uint64_t currentSize() const;
86 virtual uint64_t currentCount() const;
88 virtual int64_t maxObjectSize() const;
90 virtual void getStats(StoreInfoStats
&stats
) const;
91 virtual void stat(StoreEntry
&) const;
93 virtual void sync(); /* Sync the store prior to shutdown */
95 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
97 virtual void reference(StoreEntry
&); /* Reference this object */
99 virtual bool dereference(StoreEntry
&, bool); /* Unreference this object */
101 /* the number of store dirs being rebuilt. */
102 static int store_dirs_rebuilding
;
105 void createOneStore(Store
&aStore
);
106 StoreEntry
*find(const cache_key
*key
);
107 bool keepForLocalMemoryCache(const StoreEntry
&e
) const;
108 bool anchorCollapsed(StoreEntry
&collapsed
, bool &inSync
);
109 bool anchorCollapsedOnDisk(StoreEntry
&collapsed
, bool &inSync
);
111 StorePointer swapDir
; ///< summary view of all disk caches
112 MemStore
*memStore
; ///< memory cache
114 /// A shared table of public store entries that do not know whether they
115 /// will belong to a memory cache, a disk cache, or will be uncachable
116 /// when the response header comes. Used for SMP collapsed forwarding.
117 Transients
*transients
;
120 /* migrating from the Config based list of swapdirs */
121 void allocate_new_swapdir(SquidConfig::_cacheSwap
*);
122 void free_cachedir(SquidConfig::_cacheSwap
* swap
);
123 extern OBJH storeDirStats
;
124 char *storeDirSwapLogFile(int, const char *);
125 char *storeSwapFullPath(int, char *);
126 char *storeSwapSubSubDir(int, char *);
127 const char *storeSwapPath(int);
128 int storeDirWriteCleanLogs(int reopen
);
129 extern STDIRSELECT
*storeDirSelectSwapDir
;
130 int storeVerifySwapDirs(void);
131 void storeDirCloseSwapLogs(void);
132 void storeDirCloseTmpSwapLog(int dirn
);
133 void storeDirDiskFull(sdirno
);
134 void storeDirOpenSwapLogs(void);
135 void storeDirSwapLog(const StoreEntry
*, int op
);
136 void storeDirLRUDelete(StoreEntry
*);
137 void storeDirLRUAdd(StoreEntry
*);
138 int storeDirGetBlkSize(const char *path
, int *blksize
);
139 int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
141 /// manages a single cache_dir
142 class SwapDir
: public Store
146 typedef RefCount
<SwapDir
> Pointer
;
148 SwapDir(char const *aType
);
150 virtual void reconfigure() = 0;
151 char const *type() const;
153 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
154 virtual bool active() const; ///< may be used in this strand
155 /// whether stat should be reported by this SwapDir
156 virtual bool doReportStat() const { return active(); }
157 /// whether SwapDir may benefit from unlinkd
158 virtual bool unlinkdUseful() const = 0;
160 /* official Store interface functions */
161 virtual void diskFull();
163 virtual StoreEntry
* get(const cache_key
*);
165 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
167 virtual uint64_t maxSize() const { return max_size
;}
169 virtual uint64_t minSize() const;
171 /// The maximum size of object which may be stored here.
172 /// Larger objects will not be added and may be purged.
173 virtual int64_t maxObjectSize() const;
175 /// configure the maximum object size for this storage area.
176 /// May be any size up to the total storage area.
177 void maxObjectSize(int64_t newMax
);
179 virtual void getStats(StoreInfoStats
&stats
) const;
180 virtual void stat (StoreEntry
&anEntry
) const;
181 virtual StoreSearch
*search(String
const url
, HttpRequest
*) = 0;
183 /* migrated from store_dir.cc */
184 bool objectSizeIsAcceptable(int64_t objsize
) const;
186 /// called when the entry is about to forget its association with cache_dir
187 virtual void disconnect(StoreEntry
&) {}
189 /// called when entry swap out is complete
190 virtual void swappedOut(const StoreEntry
&e
) = 0;
193 void parseOptions(int reconfiguring
);
194 void dumpOptions(StoreEntry
* e
) const;
195 virtual ConfigOption
*getOptionTree() const;
196 virtual bool allowOptionReconfigure(const char *const) const { return true; }
198 int64_t sizeInBlocks(const int64_t size
) const { return (size
+ fs
.blksize
- 1) / fs
.blksize
; }
201 bool optionReadOnlyParse(char const *option
, const char *value
, int reconfiguring
);
202 void optionReadOnlyDump(StoreEntry
* e
) const;
203 bool optionObjectSizeParse(char const *option
, const char *value
, int reconfiguring
);
204 void optionObjectSizeDump(StoreEntry
* e
) const;
208 uint64_t max_size
; ///< maximum allocatable size of the storage area
209 int64_t min_objsize
; ///< minimum size of any object stored here (-1 for no limit)
210 int64_t max_objsize
; ///< maximum size of any object stored here (-1 for no limit)
214 int index
; /* This entry's index into the swapDirs array */
215 int disker
; ///< disker kid id dedicated to this SwapDir or -1
221 Flags() : selected(false), read_only(false) {}
225 virtual void init() = 0; /* Initialise the fs */
226 virtual void create(); /* Create a new fs */
227 virtual void dump(StoreEntry
&)const; /* Dump fs config snippet */
228 virtual bool doubleCheck(StoreEntry
&); /* Double check the obj integrity */
229 virtual void statfs(StoreEntry
&) const; /* Dump fs statistics */
230 virtual void maintain(); /* Replacement maintainence */
231 /// check whether we can store the entry; if we can, report current load
232 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const = 0;
233 /* These two are notifications */
234 virtual void reference(StoreEntry
&); /* Reference this object */
235 virtual bool dereference(StoreEntry
&, bool); /* Unreference this object */
236 virtual int callback(); /* Handle pending callbacks */
237 virtual void sync(); /* Sync the store prior to shutdown */
238 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
239 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
240 virtual void unlink (StoreEntry
&);
241 bool canLog(StoreEntry
const &e
)const;
242 virtual void openLog();
243 virtual void closeLog();
244 virtual void logEntry(const StoreEntry
& e
, int op
) const;
250 virtual ~CleanLog() {}
252 virtual const StoreEntry
*nextEntry() = 0;
253 virtual void write(StoreEntry
const &) = 0;
257 virtual int writeCleanStart();
258 virtual void writeCleanDone();
259 virtual void parse(int index
, char *path
) = 0;
266 #endif /* SQUID_SWAPDIR_H */