]>
Commit | Line | Data |
---|---|---|
58373ff8 | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
58373ff8 | 3 | * |
bbc27441 AJ |
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. | |
58373ff8 FC |
7 | */ |
8 | ||
9 | #ifndef SQUID_FS_UFS_UFSSWAPDIR_H | |
10 | #define SQUID_FS_UFS_UFSSWAPDIR_H | |
11 | ||
12 | #include "SquidString.h" | |
13 | #include "Store.h" | |
14 | #include "StoreIOState.h" | |
15 | #include "StoreSearch.h" | |
58373ff8 | 16 | #include "swap_log_op.h" |
602d9612 | 17 | #include "SwapDir.h" |
58373ff8 FC |
18 | #include "UFSStrategy.h" |
19 | ||
20 | class HttpRequest; | |
21 | class ConfigOptionVector; | |
22 | class FileMap; | |
23 | class DiskIOModule; | |
24 | ||
25 | namespace Fs | |
26 | { | |
27 | namespace Ufs | |
28 | { | |
29 | /// \ingroup UFS | |
30 | class UFSSwapDir : public SwapDir | |
31 | { | |
32 | public: | |
33 | static bool IsUFSDir(SwapDir* sd); | |
34 | static int DirClean(int swap_index); | |
35 | /** check whether swapfile belongs to the specified cachedir/l1dir/l2dir | |
36 | * | |
37 | * \param cachedir the number of the cachedir which is being tested | |
38 | * \param level1dir level-1 dir in the cachedir | |
39 | * \param level2dir level-2 dir | |
40 | */ | |
41 | static bool FilenoBelongsHere(int fn, int cachedir, int level1dir, int level2dir); | |
42 | ||
43 | UFSSwapDir(char const *aType, const char *aModuleType); | |
44 | /** Initial setup / end destruction */ | |
45 | virtual void init(); | |
46 | /** Create a new SwapDir (-z command-line option) */ | |
47 | virtual void create(); | |
48 | virtual void dump(StoreEntry &) const; | |
49 | ~UFSSwapDir(); | |
50 | virtual StoreSearch *search(String const url, HttpRequest *); | |
51 | /** double-check swap during rebuild (-S command-line option) | |
52 | * | |
53 | * called by storeCleanup if needed | |
54 | */ | |
55 | virtual bool doubleCheck(StoreEntry &); | |
56 | virtual bool unlinkdUseful() const; | |
57 | /** unlink a file, and remove its entry from the filemap */ | |
58 | virtual void unlink(StoreEntry &); | |
59 | virtual void statfs(StoreEntry &)const; | |
60 | virtual void maintain(); | |
61 | /** check whether this filesystem can store the given object | |
62 | * | |
63 | * UFS filesystems will happily store anything as long as | |
64 | * the LRU time isn't too small | |
65 | */ | |
66 | virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const; | |
67 | /** reference an object | |
68 | * | |
69 | * This routine is called whenever an object is referenced, so we can | |
70 | * maintain replacement information within the storage fs. | |
71 | */ | |
72 | virtual void reference(StoreEntry &); | |
73 | /** de-reference an object | |
74 | * | |
75 | * This routine is called whenever the last reference to an object is | |
76 | * removed, to maintain replacement information within the storage fs. | |
77 | */ | |
54347cbd | 78 | virtual bool dereference(StoreEntry &, bool); |
58373ff8 FC |
79 | virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *); |
80 | virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *); | |
81 | virtual void openLog(); | |
82 | virtual void closeLog(); | |
83 | virtual int writeCleanStart(); | |
84 | virtual void writeCleanDone(); | |
85 | virtual void logEntry(const StoreEntry & e, int op) const; | |
86 | virtual void parse(int index, char *path); ///parse configuration and setup new SwapDir | |
87 | virtual void reconfigure(); ///reconfigure the SwapDir | |
88 | virtual int callback(); | |
89 | virtual void sync(); | |
90 | virtual void swappedOut(const StoreEntry &e); | |
91 | virtual uint64_t currentSize() const { return cur_size; } | |
92 | virtual uint64_t currentCount() const { return n_disk_objects; } | |
93 | ||
94 | void unlinkFile(sfileno f); | |
95 | // move down when unlink is a virtual method | |
96 | //protected: | |
97 | Fs::Ufs::UFSStrategy *IO; | |
98 | char *fullPath(sfileno, char *) const; | |
99 | /* temp */ | |
100 | void closeTmpSwapLog(); | |
101 | FILE *openTmpSwapLog(int *clean_flag, int *zero_flag); | |
102 | char *swapSubDir(int subdirn) const; | |
103 | int mapBitTest(sfileno filn); | |
104 | void mapBitReset(sfileno filn); | |
105 | void mapBitSet(sfileno filn); | |
106 | /** Add a new object to the cache with empty memory copy and pointer to disk | |
107 | * | |
108 | * This method is used to rebuild a store from disk | |
109 | */ | |
110 | StoreEntry *addDiskRestore(const cache_key * key, | |
111 | sfileno file_number, | |
112 | uint64_t swap_file_sz, | |
113 | time_t expires, | |
114 | time_t timestamp, | |
115 | time_t lastref, | |
116 | time_t lastmod, | |
117 | uint32_t refcount, | |
118 | uint16_t flags, | |
119 | int clean); | |
120 | /// Undo the effects of UFSSwapDir::addDiskRestore(). | |
121 | void undoAddDiskRestore(StoreEntry *e); | |
122 | int validFileno(sfileno filn, int flag) const; | |
123 | int mapBitAllocate(); | |
124 | virtual ConfigOption *getOptionTree() const; | |
125 | ||
126 | void *fsdata; | |
127 | ||
128 | bool validL2(int) const; | |
129 | bool validL1(int) const; | |
130 | ||
131 | /** Add and remove the given StoreEntry from the replacement policy in use */ | |
132 | void replacementAdd(StoreEntry *e); | |
133 | void replacementRemove(StoreEntry *e); | |
134 | ||
135 | protected: | |
136 | FileMap *map; | |
137 | int suggest; | |
138 | int l1; | |
139 | int l2; | |
140 | ||
141 | private: | |
142 | void parseSizeL1L2(); | |
143 | static int NumberOfUFSDirs; | |
144 | static int * UFSDirToGlobalDirMapping; | |
145 | bool pathIsDirectory(const char *path)const; | |
146 | int swaplog_fd; | |
147 | static EVH CleanEvent; | |
148 | /** Verify that the the CacheDir exists | |
149 | * | |
150 | * If this returns < 0, then Squid exits, complains about swap | |
151 | * directories not existing, and instructs the admin to run 'squid -z' | |
152 | * Called by UFSSwapDir::init | |
153 | */ | |
154 | bool verifyCacheDirs(); | |
155 | void rebuild(); | |
156 | int createDirectory(const char *path, int); | |
157 | void createSwapSubDirs(); | |
158 | void dumpEntry(StoreEntry &) const; | |
159 | char *logFile(char const *ext = NULL)const; | |
160 | void changeIO(DiskIOModule *); | |
161 | bool optionIOParse(char const *option, const char *value, int reconfiguring); | |
162 | void optionIODump(StoreEntry * e) const; | |
163 | mutable ConfigOptionVector *currentIOOptions; | |
164 | char const *ioType; | |
165 | uint64_t cur_size; ///< currently used space in the storage area | |
166 | uint64_t n_disk_objects; ///< total number of objects stored | |
167 | }; | |
168 | ||
169 | } //namespace Ufs | |
170 | } //namespace Fs | |
171 | #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */ |