]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/SwapDir.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_SWAPDIR_H
10 #define SQUID_SWAPDIR_H
12 #include "SquidConfig.h"
14 #include "StoreIOState.h"
21 class HttpRequestMethod
;
23 /* Store dir configuration routines */
24 /* SwapDir *sd, char *path ( + char *opt later when the strtok mess is gone) */
28 /// hides memory/disk cache distinction from callers
29 class StoreController
: public Store
34 virtual ~StoreController();
35 virtual int callback();
36 virtual void create();
38 virtual StoreEntry
* get(const cache_key
*);
40 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
42 /* Store parent API */
43 virtual void markForUnlink(StoreEntry
&e
);
44 virtual void handleIdleEntry(StoreEntry
&e
);
45 virtual void transientsCompleteWriting(StoreEntry
&e
);
46 virtual void transientsAbandon(StoreEntry
&e
);
47 virtual int transientReaders(const StoreEntry
&e
) const;
48 virtual void transientsDisconnect(MemObject
&mem_obj
);
49 virtual void memoryOut(StoreEntry
&e
, const bool preserveSwappable
);
50 virtual void memoryUnlink(StoreEntry
&e
);
51 virtual void memoryDisconnect(StoreEntry
&e
);
52 virtual void allowCollapsing(StoreEntry
*e
, const RequestFlags
&reqFlags
, const HttpRequestMethod
&reqMethod
);
53 virtual void syncCollapsed(const sfileno xitIndex
);
57 virtual void maintain(); /* perform regular maintenance should be private and self registered ... */
59 virtual uint64_t maxSize() const;
61 virtual uint64_t minSize() const;
63 virtual uint64_t currentSize() const;
65 virtual uint64_t currentCount() const;
67 virtual int64_t maxObjectSize() const;
69 virtual void getStats(StoreInfoStats
&stats
) const;
70 virtual void stat(StoreEntry
&) const;
72 virtual void sync(); /* Sync the store prior to shutdown */
74 virtual StoreSearch
*search(String
const url
, HttpRequest
*);
76 virtual void reference(StoreEntry
&); /* Reference this object */
78 virtual bool dereference(StoreEntry
&, bool); /* Unreference this object */
80 /* the number of store dirs being rebuilt. */
81 static int store_dirs_rebuilding
;
84 void createOneStore(Store
&aStore
);
85 StoreEntry
*find(const cache_key
*key
);
86 bool keepForLocalMemoryCache(StoreEntry
&e
) const;
87 bool anchorCollapsed(StoreEntry
&collapsed
, bool &inSync
);
88 bool anchorCollapsedOnDisk(StoreEntry
&collapsed
, bool &inSync
);
90 StorePointer swapDir
; ///< summary view of all disk caches
91 MemStore
*memStore
; ///< memory cache
93 /// A shared table of public store entries that do not know whether they
94 /// will belong to a memory cache, a disk cache, or will be uncachable
95 /// when the response header comes. Used for SMP collapsed forwarding.
96 Transients
*transients
;
99 /* migrating from the Config based list of swapdirs */
100 void allocate_new_swapdir(SquidConfig::_cacheSwap
*);
101 void free_cachedir(SquidConfig::_cacheSwap
* swap
);
102 extern OBJH storeDirStats
;
103 char *storeDirSwapLogFile(int, const char *);
104 char *storeSwapFullPath(int, char *);
105 char *storeSwapSubSubDir(int, char *);
106 const char *storeSwapPath(int);
107 int storeDirWriteCleanLogs(int reopen
);
108 extern STDIRSELECT
*storeDirSelectSwapDir
;
109 int storeVerifySwapDirs(void);
110 void storeDirCloseSwapLogs(void);
111 void storeDirCloseTmpSwapLog(int dirn
);
112 void storeDirDiskFull(sdirno
);
113 void storeDirOpenSwapLogs(void);
114 void storeDirSwapLog(const StoreEntry
*, int op
);
115 void storeDirLRUDelete(StoreEntry
*);
116 void storeDirLRUAdd(StoreEntry
*);
117 int storeDirGetBlkSize(const char *path
, int *blksize
);
118 int storeDirGetUFSStats(const char *, int *, int *, int *, int *);
120 /// manages a single cache_dir
121 class SwapDir
: public Store
125 typedef RefCount
<SwapDir
> Pointer
;
127 SwapDir(char const *aType
);
129 virtual void reconfigure() = 0;
130 char const *type() const;
132 virtual bool needsDiskStrand() const; ///< needs a dedicated kid process
133 virtual bool active() const; ///< may be used in this strand
134 /// whether stat should be reported by this SwapDir
135 virtual bool doReportStat() const { return active(); }
136 /// whether SwapDir may benefit from unlinkd
137 virtual bool unlinkdUseful() const = 0;
139 /* official Store interface functions */
140 virtual void diskFull();
142 virtual StoreEntry
* get(const cache_key
*);
144 virtual void get(String
const, STOREGETCLIENT
, void * cbdata
);
146 virtual uint64_t maxSize() const { return max_size
;}
148 virtual uint64_t minSize() const;
150 /// The maximum size of object which may be stored here.
151 /// Larger objects will not be added and may be purged.
152 virtual int64_t maxObjectSize() const;
154 /// configure the maximum object size for this storage area.
155 /// May be any size up to the total storage area.
156 void maxObjectSize(int64_t newMax
);
158 virtual void getStats(StoreInfoStats
&stats
) const;
159 virtual void stat (StoreEntry
&anEntry
) const;
160 virtual StoreSearch
*search(String
const url
, HttpRequest
*) = 0;
162 /* migrated from store_dir.cc */
163 bool objectSizeIsAcceptable(int64_t objsize
) const;
165 /// called when the entry is about to forget its association with cache_dir
166 virtual void disconnect(StoreEntry
&) {}
168 /// called when entry swap out is complete
169 virtual void swappedOut(const StoreEntry
&e
) = 0;
172 void parseOptions(int reconfiguring
);
173 void dumpOptions(StoreEntry
* e
) const;
174 virtual ConfigOption
*getOptionTree() const;
175 virtual bool allowOptionReconfigure(const char *const) const { return true; }
177 int64_t sizeInBlocks(const int64_t size
) const { return (size
+ fs
.blksize
- 1) / fs
.blksize
; }
180 bool optionReadOnlyParse(char const *option
, const char *value
, int reconfiguring
);
181 void optionReadOnlyDump(StoreEntry
* e
) const;
182 bool optionObjectSizeParse(char const *option
, const char *value
, int reconfiguring
);
183 void optionObjectSizeDump(StoreEntry
* e
) const;
187 uint64_t max_size
; ///< maximum allocatable size of the storage area
188 int64_t min_objsize
; ///< minimum size of any object stored here (-1 for no limit)
189 int64_t max_objsize
; ///< maximum size of any object stored here (-1 for no limit)
193 int index
; /* This entry's index into the swapDirs array */
194 int disker
; ///< disker kid id dedicated to this SwapDir or -1
200 Flags() : selected(false), read_only(false) {}
204 virtual void init() = 0; /* Initialise the fs */
205 virtual void create(); /* Create a new fs */
206 virtual void dump(StoreEntry
&)const; /* Dump fs config snippet */
207 virtual bool doubleCheck(StoreEntry
&); /* Double check the obj integrity */
208 virtual void statfs(StoreEntry
&) const; /* Dump fs statistics */
209 virtual void maintain(); /* Replacement maintainence */
210 /// check whether we can store the entry; if we can, report current load
211 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const = 0;
212 /* These two are notifications */
213 virtual void reference(StoreEntry
&); /* Reference this object */
214 virtual bool dereference(StoreEntry
&, bool); /* Unreference this object */
215 virtual int callback(); /* Handle pending callbacks */
216 virtual void sync(); /* Sync the store prior to shutdown */
217 virtual StoreIOState::Pointer
createStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
218 virtual StoreIOState::Pointer
openStoreIO(StoreEntry
&, StoreIOState::STFNCB
*, StoreIOState::STIOCB
*, void *) = 0;
219 virtual void unlink (StoreEntry
&);
220 bool canLog(StoreEntry
const &e
)const;
221 virtual void openLog();
222 virtual void closeLog();
223 virtual void logEntry(const StoreEntry
& e
, int op
) const;
229 virtual ~CleanLog() {}
231 virtual const StoreEntry
*nextEntry() = 0;
232 virtual void write(StoreEntry
const &) = 0;
236 virtual int writeCleanStart();
237 virtual void writeCleanDone();
238 virtual void parse(int index
, char *path
) = 0;
245 #endif /* SQUID_SWAPDIR_H */