]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSSwapDir.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / ufs / UFSSwapDir.h
1 /*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 */
28
29 #ifndef SQUID_FS_UFS_UFSSWAPDIR_H
30 #define SQUID_FS_UFS_UFSSWAPDIR_H
31
32 #include "SquidString.h"
33 #include "Store.h"
34 #include "StoreIOState.h"
35 #include "StoreSearch.h"
36 #include "swap_log_op.h"
37 #include "SwapDir.h"
38 #include "UFSStrategy.h"
39
40 class HttpRequest;
41 class ConfigOptionVector;
42 class FileMap;
43 class DiskIOModule;
44
45 namespace Fs
46 {
47 namespace Ufs
48 {
49 /// \ingroup UFS
50 class UFSSwapDir : public SwapDir
51 {
52 public:
53 static bool IsUFSDir(SwapDir* sd);
54 static int DirClean(int swap_index);
55 /** check whether swapfile belongs to the specified cachedir/l1dir/l2dir
56 *
57 * \param cachedir the number of the cachedir which is being tested
58 * \param level1dir level-1 dir in the cachedir
59 * \param level2dir level-2 dir
60 */
61 static bool FilenoBelongsHere(int fn, int cachedir, int level1dir, int level2dir);
62
63 UFSSwapDir(char const *aType, const char *aModuleType);
64 /** Initial setup / end destruction */
65 virtual void init();
66 /** Create a new SwapDir (-z command-line option) */
67 virtual void create();
68 virtual void dump(StoreEntry &) const;
69 ~UFSSwapDir();
70 virtual StoreSearch *search(String const url, HttpRequest *);
71 /** double-check swap during rebuild (-S command-line option)
72 *
73 * called by storeCleanup if needed
74 */
75 virtual bool doubleCheck(StoreEntry &);
76 virtual bool unlinkdUseful() const;
77 /** unlink a file, and remove its entry from the filemap */
78 virtual void unlink(StoreEntry &);
79 virtual void statfs(StoreEntry &)const;
80 virtual void maintain();
81 /** check whether this filesystem can store the given object
82 *
83 * UFS filesystems will happily store anything as long as
84 * the LRU time isn't too small
85 */
86 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
87 /** reference an object
88 *
89 * This routine is called whenever an object is referenced, so we can
90 * maintain replacement information within the storage fs.
91 */
92 virtual void reference(StoreEntry &);
93 /** de-reference an object
94 *
95 * This routine is called whenever the last reference to an object is
96 * removed, to maintain replacement information within the storage fs.
97 */
98 virtual bool dereference(StoreEntry &, bool);
99 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
100 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
101 virtual void openLog();
102 virtual void closeLog();
103 virtual int writeCleanStart();
104 virtual void writeCleanDone();
105 virtual void logEntry(const StoreEntry & e, int op) const;
106 virtual void parse(int index, char *path); ///parse configuration and setup new SwapDir
107 virtual void reconfigure(); ///reconfigure the SwapDir
108 virtual int callback();
109 virtual void sync();
110 virtual void swappedOut(const StoreEntry &e);
111 virtual uint64_t currentSize() const { return cur_size; }
112 virtual uint64_t currentCount() const { return n_disk_objects; }
113
114 void unlinkFile(sfileno f);
115 // move down when unlink is a virtual method
116 //protected:
117 Fs::Ufs::UFSStrategy *IO;
118 char *fullPath(sfileno, char *) const;
119 /* temp */
120 void closeTmpSwapLog();
121 FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
122 char *swapSubDir(int subdirn) const;
123 int mapBitTest(sfileno filn);
124 void mapBitReset(sfileno filn);
125 void mapBitSet(sfileno filn);
126 /** Add a new object to the cache with empty memory copy and pointer to disk
127 *
128 * This method is used to rebuild a store from disk
129 */
130 StoreEntry *addDiskRestore(const cache_key * key,
131 sfileno file_number,
132 uint64_t swap_file_sz,
133 time_t expires,
134 time_t timestamp,
135 time_t lastref,
136 time_t lastmod,
137 uint32_t refcount,
138 uint16_t flags,
139 int clean);
140 /// Undo the effects of UFSSwapDir::addDiskRestore().
141 void undoAddDiskRestore(StoreEntry *e);
142 int validFileno(sfileno filn, int flag) const;
143 int mapBitAllocate();
144 virtual ConfigOption *getOptionTree() const;
145
146 void *fsdata;
147
148 bool validL2(int) const;
149 bool validL1(int) const;
150
151 /** Add and remove the given StoreEntry from the replacement policy in use */
152 void replacementAdd(StoreEntry *e);
153 void replacementRemove(StoreEntry *e);
154
155 protected:
156 FileMap *map;
157 int suggest;
158 int l1;
159 int l2;
160
161 private:
162 void parseSizeL1L2();
163 static int NumberOfUFSDirs;
164 static int * UFSDirToGlobalDirMapping;
165 bool pathIsDirectory(const char *path)const;
166 int swaplog_fd;
167 static EVH CleanEvent;
168 /** Verify that the the CacheDir exists
169 *
170 * If this returns < 0, then Squid exits, complains about swap
171 * directories not existing, and instructs the admin to run 'squid -z'
172 * Called by UFSSwapDir::init
173 */
174 bool verifyCacheDirs();
175 void rebuild();
176 int createDirectory(const char *path, int);
177 void createSwapSubDirs();
178 void dumpEntry(StoreEntry &) const;
179 char *logFile(char const *ext = NULL)const;
180 void changeIO(DiskIOModule *);
181 bool optionIOParse(char const *option, const char *value, int reconfiguring);
182 void optionIODump(StoreEntry * e) const;
183 mutable ConfigOptionVector *currentIOOptions;
184 char const *ioType;
185 uint64_t cur_size; ///< currently used space in the storage area
186 uint64_t n_disk_objects; ///< total number of objects stored
187 };
188
189 } //namespace Ufs
190 } //namespace Fs
191 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */