]> 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 * Copyright (C) 1996-2017 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 virtual ~UFSSwapDir();
45
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;
52 virtual void unlink(StoreEntry &) override;
53 virtual void statfs(StoreEntry &) const override;
54 virtual void maintain() override;
55 virtual void markForUnlink(StoreEntry &) override {}
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;
70 virtual void swappedOut(const StoreEntry &e) override;
71 virtual uint64_t currentSize() const override { return cur_size; }
72 virtual uint64_t currentCount() const override { return n_disk_objects; }
73 virtual ConfigOption *getOptionTree() const override;
74 virtual bool smpAware() const override { return false; }
75
76 void unlinkFile(sfileno f);
77 // move down when unlink is a virtual method
78 //protected:
79 Fs::Ufs::UFSStrategy *IO;
80 char *fullPath(sfileno, char *) const;
81 /* temp */
82 void closeTmpSwapLog();
83 FILE *openTmpSwapLog(int *clean_flag, int *zero_flag);
84 char *swapSubDir(int subdirn) const;
85 int mapBitTest(sfileno filn);
86 void mapBitReset(sfileno filn);
87 void mapBitSet(sfileno filn);
88 /** Add a new object to the cache with empty memory copy and pointer to disk
89 *
90 * This method is used to rebuild a store from disk
91 */
92 StoreEntry *addDiskRestore(const cache_key * key,
93 sfileno file_number,
94 uint64_t swap_file_sz,
95 time_t expires,
96 time_t timestamp,
97 time_t lastref,
98 time_t lastmod,
99 uint32_t refcount,
100 uint16_t flags,
101 int clean);
102 /// Undo the effects of UFSSwapDir::addDiskRestore().
103 void undoAddDiskRestore(StoreEntry *e);
104 int validFileno(sfileno filn, int flag) const;
105 int mapBitAllocate();
106
107 void *fsdata;
108
109 bool validL2(int) const;
110 bool validL1(int) const;
111
112 /** Add and remove the given StoreEntry from the replacement policy in use */
113 void replacementAdd(StoreEntry *e);
114 void replacementRemove(StoreEntry *e);
115
116 protected:
117 FileMap *map;
118 int suggest;
119 int l1;
120 int l2;
121
122 private:
123 void parseSizeL1L2();
124 static int NumberOfUFSDirs;
125 static int * UFSDirToGlobalDirMapping;
126 bool pathIsDirectory(const char *path)const;
127 int swaplog_fd;
128 static EVH CleanEvent;
129 static int HandleCleanEvent();
130 /** Verify that the the CacheDir exists
131 *
132 * If this returns < 0, then Squid exits, complains about swap
133 * directories not existing, and instructs the admin to run 'squid -z'
134 * Called by UFSSwapDir::init
135 */
136 bool verifyCacheDirs();
137 void rebuild();
138 int createDirectory(const char *path, int);
139 void createSwapSubDirs();
140 void dumpEntry(StoreEntry &) const;
141 char *logFile(char const *ext = NULL)const;
142 void changeIO(DiskIOModule *);
143 bool optionIOParse(char const *option, const char *value, int reconfiguring);
144 void optionIODump(StoreEntry * e) const;
145 mutable ConfigOptionVector *currentIOOptions;
146 char const *ioType;
147 uint64_t cur_size; ///< currently used space in the storage area
148 uint64_t n_disk_objects; ///< total number of objects stored
149 bool rebuilding_; ///< whether RebuildState is writing the new swap.state
150 };
151
152 } //namespace Ufs
153 } //namespace Fs
154 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */
155