]>
Commit | Line | Data |
---|---|---|
58373ff8 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 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" | |
2745fea5 | 14 | #include "store/Disk.h" |
58373ff8 FC |
15 | #include "StoreIOState.h" |
16 | #include "StoreSearch.h" | |
58373ff8 FC |
17 | #include "swap_log_op.h" |
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); | |
fd9cca25 | 44 | virtual ~UFSSwapDir(); |
2745fea5 | 45 | |
fd9cca25 AR |
46 | /* Store::Disk API */ |
47 | virtual void create() override; | |
48 | virtual void init() override; | |
49 | virtual void dump(StoreEntry &) const override; | |
50 | virtual bool doubleCheck(StoreEntry &) override; | |
51 | virtual bool unlinkdUseful() const override; | |
fd9cca25 AR |
52 | virtual void statfs(StoreEntry &) const override; |
53 | virtual void maintain() override; | |
4310f8b0 EB |
54 | virtual void evictCached(StoreEntry &) override; |
55 | virtual void evictIfFound(const cache_key *) override; | |
fd9cca25 AR |
56 | virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const override; |
57 | virtual void reference(StoreEntry &) override; | |
58 | virtual bool dereference(StoreEntry &) override; | |
59 | virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) override; | |
60 | virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *) override; | |
61 | virtual void openLog() override; | |
62 | virtual void closeLog() override; | |
63 | virtual int writeCleanStart() override; | |
64 | virtual void writeCleanDone() override; | |
65 | virtual void logEntry(const StoreEntry & e, int op) const override; | |
66 | virtual void parse(int index, char *path) override; | |
67 | virtual void reconfigure() override; | |
68 | virtual int callback() override; | |
69 | virtual void sync() override; | |
4310f8b0 EB |
70 | virtual void finalizeSwapoutSuccess(const StoreEntry &) override; |
71 | virtual void finalizeSwapoutFailure(StoreEntry &) override; | |
fd9cca25 AR |
72 | virtual uint64_t currentSize() const override { return cur_size; } |
73 | virtual uint64_t currentCount() const override { return n_disk_objects; } | |
74 | virtual ConfigOption *getOptionTree() const override; | |
1a210de4 | 75 | virtual bool smpAware() const override { return false; } |
4310f8b0 EB |
76 | /// as long as ufs relies on the global store_table to index entries, |
77 | /// it is wrong to ask individual ufs cache_dirs whether they have an entry | |
78 | virtual bool hasReadableEntry(const StoreEntry &) const override { return false; } | |
58373ff8 FC |
79 | |
80 | void unlinkFile(sfileno f); | |
81 | // move down when unlink is a virtual method | |
82 | //protected: | |
83 | Fs::Ufs::UFSStrategy *IO; | |
84 | char *fullPath(sfileno, char *) const; | |
85 | /* temp */ | |
86 | void closeTmpSwapLog(); | |
87 | FILE *openTmpSwapLog(int *clean_flag, int *zero_flag); | |
88 | char *swapSubDir(int subdirn) const; | |
89 | int mapBitTest(sfileno filn); | |
90 | void mapBitReset(sfileno filn); | |
91 | void mapBitSet(sfileno filn); | |
92 | /** Add a new object to the cache with empty memory copy and pointer to disk | |
93 | * | |
94 | * This method is used to rebuild a store from disk | |
95 | */ | |
96 | StoreEntry *addDiskRestore(const cache_key * key, | |
97 | sfileno file_number, | |
98 | uint64_t swap_file_sz, | |
99 | time_t expires, | |
100 | time_t timestamp, | |
101 | time_t lastref, | |
102 | time_t lastmod, | |
103 | uint32_t refcount, | |
104 | uint16_t flags, | |
105 | int clean); | |
58373ff8 FC |
106 | int validFileno(sfileno filn, int flag) const; |
107 | int mapBitAllocate(); | |
58373ff8 FC |
108 | |
109 | void *fsdata; | |
110 | ||
111 | bool validL2(int) const; | |
112 | bool validL1(int) const; | |
113 | ||
114 | /** Add and remove the given StoreEntry from the replacement policy in use */ | |
115 | void replacementAdd(StoreEntry *e); | |
116 | void replacementRemove(StoreEntry *e); | |
117 | ||
118 | protected: | |
119 | FileMap *map; | |
120 | int suggest; | |
121 | int l1; | |
122 | int l2; | |
123 | ||
124 | private: | |
125 | void parseSizeL1L2(); | |
126 | static int NumberOfUFSDirs; | |
127 | static int * UFSDirToGlobalDirMapping; | |
128 | bool pathIsDirectory(const char *path)const; | |
129 | int swaplog_fd; | |
130 | static EVH CleanEvent; | |
7c44eb08 | 131 | static int HandleCleanEvent(); |
58373ff8 FC |
132 | /** Verify that the the CacheDir exists |
133 | * | |
134 | * If this returns < 0, then Squid exits, complains about swap | |
135 | * directories not existing, and instructs the admin to run 'squid -z' | |
136 | * Called by UFSSwapDir::init | |
137 | */ | |
138 | bool verifyCacheDirs(); | |
139 | void rebuild(); | |
140 | int createDirectory(const char *path, int); | |
141 | void createSwapSubDirs(); | |
142 | void dumpEntry(StoreEntry &) const; | |
b56b37cf | 143 | SBuf logFile(char const *ext = nullptr) const; |
58373ff8 FC |
144 | void changeIO(DiskIOModule *); |
145 | bool optionIOParse(char const *option, const char *value, int reconfiguring); | |
146 | void optionIODump(StoreEntry * e) const; | |
147 | mutable ConfigOptionVector *currentIOOptions; | |
148 | char const *ioType; | |
149 | uint64_t cur_size; ///< currently used space in the storage area | |
150 | uint64_t n_disk_objects; ///< total number of objects stored | |
7c44eb08 | 151 | bool rebuilding_; ///< whether RebuildState is writing the new swap.state |
58373ff8 FC |
152 | }; |
153 | ||
154 | } //namespace Ufs | |
155 | } //namespace Fs | |
156 | #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */ | |
f53969cc | 157 |