]> git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSSwapDir.h
Store API and layout polishing. No functionality changes intended.
[thirdparty/squid.git] / src / fs / ufs / UFSSwapDir.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
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 "store/Disk.h"
15 #include "StoreIOState.h"
16 #include "StoreSearch.h"
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);
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 /** double-check swap during rebuild (-S command-line option)
51 *
52 * called by storeCleanup if needed
53 */
54 virtual bool doubleCheck(StoreEntry &);
55 virtual bool unlinkdUseful() const;
56 /** unlink a file, and remove its entry from the filemap */
57 virtual void unlink(StoreEntry &);
58 virtual void statfs(StoreEntry &)const;
59 virtual void maintain();
60 virtual bool anchorCollapsed(StoreEntry &, bool &) override { return false; }
61 virtual bool updateCollapsed(StoreEntry &) override { return false; }
62 virtual void markForUnlink(StoreEntry &) override {}
63
64 /** check whether this filesystem can store the given object
65 *
66 * UFS filesystems will happily store anything as long as
67 * the LRU time isn't too small
68 */
69 virtual bool canStore(const StoreEntry &e, int64_t diskSpaceNeeded, int &load) const;
70 /** reference an object
71 *
72 * This routine is called whenever an object is referenced, so we can
73 * maintain replacement information within the storage fs.
74 */
75 virtual void reference(StoreEntry &);
76 /** de-reference an object
77 *
78 * This routine is called whenever the last reference to an object is
79 * removed, to maintain replacement information within the storage fs.
80 */
81 virtual bool dereference(StoreEntry &);
82 virtual StoreIOState::Pointer createStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
83 virtual StoreIOState::Pointer openStoreIO(StoreEntry &, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
84 virtual void openLog();
85 virtual void closeLog();
86 virtual int writeCleanStart();
87 virtual void writeCleanDone();
88 virtual void logEntry(const StoreEntry & e, int op) const;
89 virtual void parse(int index, char *path); ///parse configuration and setup new SwapDir
90 virtual void reconfigure(); ///reconfigure the SwapDir
91 virtual int callback();
92 virtual void sync();
93 virtual void swappedOut(const StoreEntry &e);
94 virtual uint64_t currentSize() const { return cur_size; }
95 virtual uint64_t currentCount() const { return n_disk_objects; }
96
97 void unlinkFile(sfileno f);
98 // move down when unlink is a virtual method
99 //protected:
100 Fs::Ufs::UFSStrategy *IO;
101 char *fullPath(sfileno, char *) const;
102 /* temp */
103 void closeTmpSwapLog();
104 FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
105 char *swapSubDir(int subdirn) const;
106 int mapBitTest(sfileno filn);
107 void mapBitReset(sfileno filn);
108 void mapBitSet(sfileno filn);
109 /** Add a new object to the cache with empty memory copy and pointer to disk
110 *
111 * This method is used to rebuild a store from disk
112 */
113 StoreEntry *addDiskRestore(const cache_key * key,
114 sfileno file_number,
115 uint64_t swap_file_sz,
116 time_t expires,
117 time_t timestamp,
118 time_t lastref,
119 time_t lastmod,
120 uint32_t refcount,
121 uint16_t flags,
122 int clean);
123 /// Undo the effects of UFSSwapDir::addDiskRestore().
124 void undoAddDiskRestore(StoreEntry *e);
125 int validFileno(sfileno filn, int flag) const;
126 int mapBitAllocate();
127 virtual ConfigOption *getOptionTree() const;
128
129 void *fsdata;
130
131 bool validL2(int) const;
132 bool validL1(int) const;
133
134 /** Add and remove the given StoreEntry from the replacement policy in use */
135 void replacementAdd(StoreEntry *e);
136 void replacementRemove(StoreEntry *e);
137
138 protected:
139 FileMap *map;
140 int suggest;
141 int l1;
142 int l2;
143
144 private:
145 void parseSizeL1L2();
146 static int NumberOfUFSDirs;
147 static int * UFSDirToGlobalDirMapping;
148 bool pathIsDirectory(const char *path)const;
149 int swaplog_fd;
150 static EVH CleanEvent;
151 /** Verify that the the CacheDir exists
152 *
153 * If this returns < 0, then Squid exits, complains about swap
154 * directories not existing, and instructs the admin to run 'squid -z'
155 * Called by UFSSwapDir::init
156 */
157 bool verifyCacheDirs();
158 void rebuild();
159 int createDirectory(const char *path, int);
160 void createSwapSubDirs();
161 void dumpEntry(StoreEntry &) const;
162 char *logFile(char const *ext = NULL)const;
163 void changeIO(DiskIOModule *);
164 bool optionIOParse(char const *option, const char *value, int reconfiguring);
165 void optionIODump(StoreEntry * e) const;
166 mutable ConfigOptionVector *currentIOOptions;
167 char const *ioType;
168 uint64_t cur_size; ///< currently used space in the storage area
169 uint64_t n_disk_objects; ///< total number of objects stored
170 };
171
172 } //namespace Ufs
173 } //namespace Fs
174 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */
175