]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/fs/ufs/UFSSwapDir.h
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_FS_UFS_UFSSWAPDIR_H
10 #define SQUID_FS_UFS_UFSSWAPDIR_H
12 #include "SquidString.h"
14 #include "store/Disk.h"
15 #include "StoreIOState.h"
16 #include "StoreSearch.h"
17 #include "swap_log_op.h"
18 #include "UFSStrategy.h"
21 class ConfigOptionVector
;
30 class UFSSwapDir
: public SwapDir
33 static bool IsUFSDir(SwapDir
* sd
);
34 static int DirClean(int swap_index
);
35 /** check whether swapfile belongs to the specified cachedir/l1dir/l2dir
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
41 static bool FilenoBelongsHere(int fn
, int cachedir
, int level1dir
, int level2dir
);
43 UFSSwapDir(char const *aType
, const char *aModuleType
);
44 /** Initial setup / end destruction */
46 /** Create a new SwapDir (-z command-line option) */
47 virtual void create();
48 virtual void dump(StoreEntry
&) const;
50 /** double-check swap during rebuild (-S command-line option)
52 * called by storeCleanup if needed
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
{}
64 /** check whether this filesystem can store the given object
66 * UFS filesystems will happily store anything as long as
67 * the LRU time isn't too small
69 virtual bool canStore(const StoreEntry
&e
, int64_t diskSpaceNeeded
, int &load
) const;
70 /** reference an object
72 * This routine is called whenever an object is referenced, so we can
73 * maintain replacement information within the storage fs.
75 virtual void reference(StoreEntry
&);
76 /** de-reference an object
78 * This routine is called whenever the last reference to an object is
79 * removed, to maintain replacement information within the storage fs.
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();
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
; }
97 void unlinkFile(sfileno f
);
98 // move down when unlink is a virtual method
100 Fs::Ufs::UFSStrategy
*IO
;
101 char *fullPath(sfileno
, char *) const;
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
111 * This method is used to rebuild a store from disk
113 StoreEntry
*addDiskRestore(const cache_key
* key
,
115 uint64_t swap_file_sz
,
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;
131 bool validL2(int) const;
132 bool validL1(int) const;
134 /** Add and remove the given StoreEntry from the replacement policy in use */
135 void replacementAdd(StoreEntry
*e
);
136 void replacementRemove(StoreEntry
*e
);
145 void parseSizeL1L2();
146 static int NumberOfUFSDirs
;
147 static int * UFSDirToGlobalDirMapping
;
148 bool pathIsDirectory(const char *path
)const;
150 static EVH CleanEvent
;
151 /** Verify that the the CacheDir exists
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
157 bool verifyCacheDirs();
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
;
168 uint64_t cur_size
; ///< currently used space in the storage area
169 uint64_t n_disk_objects
; ///< total number of objects stored
174 #endif /* SQUID_FS_UFS_UFSSWAPDIR_H */